Commit 06012021
This commit is contained in:
parent
55e3bd2be4
commit
7b69eb9c2a
0
src/main/java/eu/dnetlib/usagestats/config/DataSourceConfiguration.java
Executable file → Normal file
0
src/main/java/eu/dnetlib/usagestats/config/DataSourceConfiguration.java
Executable file → Normal file
0
src/main/java/eu/dnetlib/usagestats/config/SpringRedisConfiguration.java
Executable file → Normal file
0
src/main/java/eu/dnetlib/usagestats/config/SpringRedisConfiguration.java
Executable file → Normal file
|
@ -23,10 +23,18 @@ class SushiLiteController {
|
|||
}
|
||||
|
||||
@RequestMapping(value = "/sushilite/r5/GetReport/", method = RequestMethod.GET)
|
||||
public String getReport(@RequestParam(value = "Report", defaultValue = "") String reportP, @RequestParam(value = "Release", defaultValue = "4") String release, @RequestParam(value = "RequestorID", defaultValue = "anonymous") String requestorId,
|
||||
@RequestParam(value = "BeginDate", defaultValue = "") String beginDate, @RequestParam(value = "EndDate", defaultValue = "") String endDate, @RequestParam(value = "RepositoryIdentifier", defaultValue = "") String repositoryIdentifier,
|
||||
@RequestParam(value = "ItemIdentifier", defaultValue = "") String itemIdentifier, @RequestParam(value = "ItemDataType", defaultValue = "") String itemDataType,
|
||||
@RequestParam(value = "hasDOI", defaultValue = "") String hasDoi, @RequestParam(value = "Granularity", defaultValue = "Monthly") String granularity, @RequestParam(value = "Callback", defaultValue = "") String callback,
|
||||
public String getReport(
|
||||
@RequestParam(value = "Report", defaultValue = "") String reportP,
|
||||
@RequestParam(value = "Release", defaultValue = "4") String release,
|
||||
@RequestParam(value = "RequestorID", defaultValue = "anonymous") String requestorId,
|
||||
@RequestParam(value = "BeginDate", defaultValue = "") String beginDate,
|
||||
@RequestParam(value = "EndDate", defaultValue = "") String endDate,
|
||||
@RequestParam(value = "RepositoryIdentifier", defaultValue = "") String repositoryIdentifier,
|
||||
@RequestParam(value = "ItemIdentifier", defaultValue = "") String itemIdentifier,
|
||||
@RequestParam(value = "ItemDataType", defaultValue = "") String itemDataType,
|
||||
@RequestParam(value = "hasDOI", defaultValue = "") String hasDoi,
|
||||
@RequestParam(value = "Granularity", defaultValue = "Monthly") String granularity,
|
||||
@RequestParam(value = "Callback", defaultValue = "") String callback,
|
||||
@RequestParam(value = "Pretty", defaultValue = "") String pretty) {
|
||||
log.info("Sushi Report request: " + reportP + " from " + requestorId);
|
||||
log.info("repository identifier: " + repositoryIdentifier + " - item identifier: " + itemIdentifier);
|
||||
|
@ -36,21 +44,32 @@ class SushiLiteController {
|
|||
|
||||
@RequestMapping(value = "/sushilite/r5/status", method = RequestMethod.GET)
|
||||
public String getReportStatus() {
|
||||
log.info("Sushi Report status request ");
|
||||
log.info("COUNTER Report status request ");
|
||||
return sushiLiteService.displayReportStatus();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/sushilite/r5/reports", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/sushilite/r5/reports", method = RequestMethod.GET)
|
||||
public String getReportSupported() {
|
||||
log.info("Sushi Supported Reports request ");
|
||||
log.info("COUNTER Supported Reports request ");
|
||||
return sushiLiteService.displayReportsSupported();
|
||||
}
|
||||
@RequestMapping(value = "/sushilite/r5/reports/pr", method = RequestMethod.GET)
|
||||
public String getReportPR(@RequestParam(value = "RepositoryIdentifier", defaultValue = "") String repositoryIdentifier,
|
||||
@RequestParam(value = "BeginDate", defaultValue = "") String beginDate, @RequestParam(value = "EndDate", defaultValue = "") String endDate,
|
||||
|
||||
@RequestMapping(value = "/sushilite/r5/reports/pr", method = RequestMethod.GET)
|
||||
public String getReportPR(
|
||||
@RequestParam(value = "RepositoryIdentifier", defaultValue = "") String repositoryIdentifier,
|
||||
@RequestParam(value = "BeginDate", defaultValue = "") String beginDate,
|
||||
@RequestParam(value = "EndDate", defaultValue = "") String endDate,
|
||||
@RequestParam(value = "Granularity", defaultValue = "Monthly") String granularity) {
|
||||
log.info("Sushi PR Report request for repository "+repositoryIdentifier);
|
||||
log.info("COUNTER PR Report request for repository " + repositoryIdentifier);
|
||||
return sushiLiteService.displayReportPR(repositoryIdentifier, beginDate, endDate, granularity);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/sushilite/r5/reports/pr_p1", method = RequestMethod.GET)
|
||||
public String getReportPR_P1(
|
||||
@RequestParam(value = "RepositoryIdentifier", defaultValue = "") String repositoryIdentifier,
|
||||
@RequestParam(value = "BeginDate", defaultValue = "") String beginDate,
|
||||
@RequestParam(value = "EndDate", defaultValue = "") String endDate) {
|
||||
log.info("COUNTER PR_P1 Report request for repository " + repositoryIdentifier);
|
||||
return sushiLiteService.displayReportPR_P1(repositoryIdentifier, beginDate, endDate);
|
||||
}
|
||||
}
|
||||
|
|
0
src/main/java/eu/dnetlib/usagestats/controllers/UsageStatsController.java
Executable file → Normal file
0
src/main/java/eu/dnetlib/usagestats/controllers/UsageStatsController.java
Executable file → Normal file
0
src/main/java/eu/dnetlib/usagestats/portal/CountryUsageStatsAll.java
Executable file → Normal file
0
src/main/java/eu/dnetlib/usagestats/portal/CountryUsageStatsAll.java
Executable file → Normal file
0
src/main/java/eu/dnetlib/usagestats/portal/TotalStatsReposViewsDownloads.java
Executable file → Normal file
0
src/main/java/eu/dnetlib/usagestats/portal/TotalStatsReposViewsDownloads.java
Executable file → Normal file
|
@ -1559,6 +1559,7 @@ public class UsageStatsRepository {
|
|||
Calendar endC = Calendar.getInstance();
|
||||
endC.setTime(postgresFormat.parse(rs.getString(2)));
|
||||
endC.set(Calendar.DATE, endC.getActualMaximum(Calendar.DATE));
|
||||
//iterate on data types
|
||||
if (!datatype.equals(rs.getString(1))) {
|
||||
if (reportItem != null) {
|
||||
reportItems.add(reportItem);
|
||||
|
@ -1575,6 +1576,7 @@ public class UsageStatsRepository {
|
|||
//if (reportItem != null) {
|
||||
//fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
|
||||
}
|
||||
//add last report item
|
||||
reportItems.add(reportItem);
|
||||
}
|
||||
|
||||
|
@ -1593,6 +1595,75 @@ public class UsageStatsRepository {
|
|||
}
|
||||
}
|
||||
|
||||
public void executeBatchItemsPR_P1(List<ReportItem> reportItems,
|
||||
String repositoryIdentifier, Date beginDate,
|
||||
Date endDate) {
|
||||
SimpleDateFormat report_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
SimpleDateFormat postgresFormat = new SimpleDateFormat("yyyy/MM");
|
||||
String beginDateStr = postgresFormat.format(beginDate);
|
||||
String endDateStr = postgresFormat.format(endDate);
|
||||
|
||||
Connection connection = null;
|
||||
PreparedStatement st = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
try {
|
||||
connection = usageStatsDB.getConnection();
|
||||
|
||||
st = connection.prepareStatement("SELECT us.`date`, sum(us.downloads) as downloads, sum(us.views) as views FROM " + usagestatsImpalaDB + ".usage_stats us "
|
||||
+ "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? GROUP BY us.`date` order by us.`date` ASC;");
|
||||
|
||||
st.setString(1, beginDateStr);
|
||||
st.setString(2, endDateStr);
|
||||
st.setString(3, repositoryIdentifier);
|
||||
|
||||
rs = st.executeQuery();
|
||||
String result = "";
|
||||
String lastDate = "";
|
||||
ReportItem reportItem = null;
|
||||
|
||||
int ft_total = 0;
|
||||
int abstr = 0;
|
||||
|
||||
Calendar endCal = Calendar.getInstance();
|
||||
endCal.setTime(postgresFormat.parse(endDateStr));
|
||||
endCal.add(Calendar.MONTH, 1);
|
||||
Date endDateForZeros = endCal.getTime();
|
||||
|
||||
lastDate = beginDateStr;
|
||||
String datatype = "";
|
||||
reportItem = new ReportItem("", "OpenAIRE", null, "Regular", "");
|
||||
|
||||
while (rs.next()) {
|
||||
Calendar endC = Calendar.getInstance();
|
||||
endC.setTime(postgresFormat.parse(rs.getString(1)));
|
||||
endC.set(Calendar.DATE, endC.getActualMaximum(Calendar.DATE));
|
||||
//iterate on data types
|
||||
reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(postgresFormat.parse(rs.getString(1))), report_dateFormat.format(endC.getTime()), rs.getString(2), rs.getString(3)));
|
||||
endC.setTime(postgresFormat.parse(rs.getString(1)));
|
||||
endC.add(Calendar.MONTH, 1);
|
||||
lastDate = postgresFormat.format(endC.getTime());
|
||||
//if (reportItem != null) {
|
||||
//fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
|
||||
}
|
||||
if(reportItem.getItemPerformances().size()>0)
|
||||
reportItems.add(reportItem);
|
||||
|
||||
/*
|
||||
jedis.put(redis_key, "persistent", "false");
|
||||
jedis.put(redis_key, "query", st.toString());
|
||||
jedis.put(redis_key, "result", toJson(reportItems));
|
||||
jedis.put(redis_key, "fetchMode", "3");
|
||||
*/
|
||||
} catch (Exception e) {
|
||||
log.error("Batch Item Report failed: ", e);
|
||||
} finally {
|
||||
DbUtils.closeQuietly(rs);
|
||||
DbUtils.closeQuietly(st);
|
||||
DbUtils.closeQuietly(connection);
|
||||
}
|
||||
}
|
||||
|
||||
private void fillWithZeros(Date from, Date to, ReportItem reportItem) {
|
||||
SimpleDateFormat report_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
|
@ -1617,7 +1688,6 @@ public class UsageStatsRepository {
|
|||
PreparedStatement st = null;
|
||||
Connection connection = null;
|
||||
ResultSet rs = null;
|
||||
log.info("database " + statsDB);
|
||||
String institutionName = "";
|
||||
try {
|
||||
connection = usageStatsDB.getConnection();
|
||||
|
|
|
@ -23,5 +23,8 @@ public interface SushiLiteService {
|
|||
|
||||
ReportPR buildReportPR(String repositoryIdentifier, String beginDate,String endDate, String granularity);
|
||||
String displayReportPR(String repositoryIdentifier, String beginDate,String endDate, String granularity);
|
||||
|
||||
ReportPR buildReportPR_P1(String repositoryIdentifier, String beginDate,String endDate);
|
||||
String displayReportPR_P1(String repositoryIdentifier, String beginDate, String endDate);
|
||||
|
||||
}
|
||||
|
|
|
@ -305,9 +305,8 @@ public class SushiLiteServiceImpl implements SushiLiteService {
|
|||
ZonedDateTime dateTime = ZonedDateTime.now(); // Gets the current date and time, with your default time-zone
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
//Display Report Created Day
|
||||
|
||||
repositoryIdentifier=usageStatsRepository.getInstitutionID(repositoryIdentifier);
|
||||
log.info("Repo Identifier "+repositoryIdentifier);
|
||||
|
||||
repositoryIdentifier = usageStatsRepository.getInstitutionID(repositoryIdentifier);
|
||||
|
||||
Date beginDateParsed;
|
||||
if (!beginDate.equals("")) {
|
||||
|
@ -361,7 +360,6 @@ public class SushiLiteServiceImpl implements SushiLiteService {
|
|||
String reportName = "Platform Master Report";
|
||||
//String insitutionName = "Insititution Name " + repositoryIdentifier;
|
||||
String insitutionName = usageStatsRepository.getInstitutionName(repositoryIdentifier);
|
||||
log.info("repo name "+insitutionName);
|
||||
List<InstitutionID> institutionIdD = new ArrayList();
|
||||
institutionIdD.add(new InstitutionID("Openaire", repositoryIdentifier));
|
||||
|
||||
|
@ -371,6 +369,89 @@ public class SushiLiteServiceImpl implements SushiLiteService {
|
|||
reportExceptions.add(new ReportException("3030", "Error", "No Usage Available for Requested Dates", "Service did not find any data"));
|
||||
}
|
||||
|
||||
if(reportExceptions.size()==0)
|
||||
reportExceptions=null;
|
||||
ReportPR reportPr = new ReportPR(dateTime.format(formatter), repositoryIdentifier, reportID, reportName, insitutionName, institutionIdD, reportExceptions, reportFilters, reportItems);
|
||||
return reportPr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReportPR buildReportPR_P1(String repositoryIdentifier,
|
||||
String beginDate,
|
||||
String endDate) {
|
||||
String granularity="monthly";
|
||||
|
||||
List<ReportException> reportExceptions = new ArrayList<>();
|
||||
ZonedDateTime dateTime = ZonedDateTime.now(); // Gets the current date and time, with your default time-zone
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
//Display Report Created Day
|
||||
|
||||
repositoryIdentifier = usageStatsRepository.getInstitutionID(repositoryIdentifier);
|
||||
|
||||
Date beginDateParsed;
|
||||
if (!beginDate.equals("")) {
|
||||
beginDateParsed = tryParse(beginDate);
|
||||
if (beginDateParsed != null && (granularity.toLowerCase().equals("monthly") || beginDate.length() == 7)) {
|
||||
Calendar temp = Calendar.getInstance();
|
||||
temp.setTime(beginDateParsed);
|
||||
temp.set(Calendar.DAY_OF_MONTH, temp.getActualMinimum(Calendar.DAY_OF_MONTH));
|
||||
beginDateParsed = temp.getTime();
|
||||
}
|
||||
} else {
|
||||
Calendar temp = Calendar.getInstance();
|
||||
temp.add(Calendar.MONTH, -1);
|
||||
temp.set(Calendar.DAY_OF_MONTH, temp.getActualMinimum(Calendar.DAY_OF_MONTH));
|
||||
beginDateParsed = temp.getTime();
|
||||
reportExceptions.add(new ReportException("3021", "Warning", "Unspecified Date Arguments", "Begin Date set to default: " + new SimpleDateFormat("yyyy-MM-dd").format(beginDateParsed)));
|
||||
}
|
||||
|
||||
Date endDateParsed;
|
||||
if (!endDate.equals("")) {
|
||||
endDateParsed = tryParse(endDate);
|
||||
if (endDateParsed != null && (granularity.toLowerCase().equals("monthly") || endDate.length() == 7)) {
|
||||
Calendar temp = Calendar.getInstance();
|
||||
temp.setTime(endDateParsed);
|
||||
temp.set(Calendar.DAY_OF_MONTH, temp.getActualMaximum(Calendar.DAY_OF_MONTH));
|
||||
endDateParsed = temp.getTime();
|
||||
}
|
||||
} else {
|
||||
Calendar temp = Calendar.getInstance();
|
||||
temp.add(Calendar.MONTH, -1);
|
||||
temp.set(Calendar.DAY_OF_MONTH, temp.getActualMaximum(Calendar.DAY_OF_MONTH));
|
||||
endDateParsed = temp.getTime();
|
||||
reportExceptions.add(new ReportException("3021", "Warning", "Unspecified Date Arguments", "End Date set to default: " + new SimpleDateFormat("yyyy-MM-dd").format(endDateParsed)));
|
||||
}
|
||||
//log.error("dates: " + beginDateParsed.toString() + " - " + endDateParsed.toString());
|
||||
|
||||
if (beginDateParsed == null) {
|
||||
reportExceptions.add(new ReportException("3020", "Error", "Invalid Date Arguments", "Begin Date: " + beginDate + " is not a valid date"));
|
||||
}
|
||||
if (endDateParsed == null) {
|
||||
reportExceptions.add(new ReportException("3020", "Error", "Invalid Date Arguments", "End Date: " + endDate + " is not a valid date"));
|
||||
}
|
||||
if (beginDateParsed != null && endDateParsed != null && !beginDateParsed.before(endDateParsed)) {
|
||||
reportExceptions.add(new ReportException("3020", "Error", "Invalid Date Arguments", "BeginDate \'" + new SimpleDateFormat("yyyy-MM-dd").format(beginDateParsed) + "\' is greater than EndDate \'" + new SimpleDateFormat("yyyy-MM-dd").format(endDateParsed) + "\'"));
|
||||
}
|
||||
|
||||
List<Filter> reportFilters = new ArrayList();
|
||||
reportFilters.add(new Filter("BeginDate", beginDate));
|
||||
reportFilters.add(new Filter("EndDate", endDate));
|
||||
String reportID = "PR";
|
||||
String reportName = "Platform Master Report";
|
||||
//String insitutionName = "Insititution Name " + repositoryIdentifier;
|
||||
String insitutionName = usageStatsRepository.getInstitutionName(repositoryIdentifier);
|
||||
List<InstitutionID> institutionIdD = new ArrayList();
|
||||
institutionIdD.add(new InstitutionID("Openaire", repositoryIdentifier));
|
||||
|
||||
List<ReportItem> reportItems = new ArrayList();
|
||||
usageStatsRepository.executeBatchItemsPR_P1(reportItems, repositoryIdentifier, beginDateParsed, endDateParsed);
|
||||
if (reportItems.isEmpty()) {
|
||||
reportExceptions.add(new ReportException("3030", "Error", "No Usage Available for Requested Dates", "Service did not find any data"));
|
||||
}
|
||||
|
||||
if(reportExceptions.size()==0)
|
||||
reportExceptions=null;
|
||||
|
||||
ReportPR reportPr = new ReportPR(dateTime.format(formatter), repositoryIdentifier, reportID, reportName, insitutionName, institutionIdD, reportExceptions, reportFilters, reportItems);
|
||||
return reportPr;
|
||||
}
|
||||
|
@ -381,10 +462,25 @@ public class SushiLiteServiceImpl implements SushiLiteService {
|
|||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
log.info((beginDate + " " + endDate));
|
||||
try {
|
||||
return "<pre>" + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(buildReportPR(repositoryIdentifier, beginDate, endDate,granularity)) + "</pre>";
|
||||
return "<pre>" + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(buildReportPR(repositoryIdentifier, beginDate, endDate, granularity)) + "</pre>";
|
||||
} catch (JsonProcessingException ex) {
|
||||
java.util.logging.Logger.getLogger(SushiLiteServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String displayReportPR_P1(String repositoryIdentifier,
|
||||
String beginDate,
|
||||
String endDate) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
log.info((beginDate + " " + endDate));
|
||||
try {
|
||||
return "<pre>" + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(buildReportPR_P1(repositoryIdentifier, beginDate, endDate)) + "</pre>";
|
||||
} catch (JsonProcessingException ex) {
|
||||
java.util.logging.Logger.getLogger(SushiLiteServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
0
src/main/java/eu/dnetlib/usagestats/services/UsageStatsServiceImpl.java
Executable file → Normal file
0
src/main/java/eu/dnetlib/usagestats/services/UsageStatsServiceImpl.java
Executable file → Normal file
|
@ -9,16 +9,16 @@ log4j.additivity.org.springframework = false
|
|||
|
||||
log4j.appender.R=org.apache.log4j.RollingFileAppender
|
||||
#log4j.appender.R.File=/var/log/dnet/usageStatsAPI/usageStatsAPI.log
|
||||
#log4j.appender.R.File=/Users/dpie/Desktop/usageStatsAPI.log
|
||||
log4j.appender.R.File=/Volumes/Zeus/dpie/Desktop/usageStatsAPI.log
|
||||
log4j.appender.R.File=/Users/dpie/Desktop/usageStatsAPI.log
|
||||
#log4j.appender.R.File=/Volumes/Zeus/dpie/Desktop/usageStatsAPI.log
|
||||
loglog4j.appender.R.MaxFileSize=10MB
|
||||
log4j.appender.R.MaxBackupIndex=10
|
||||
log4j.appender.R.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.R.layout.ConversionPattern= %d %p %t [%c] - %m%n
|
||||
log4j.appender.S=org.apache.log4j.RollingFileAppender
|
||||
#log4j.appender.S.File=/var/log/dnet/usageStatsAPI/usageStatsAPI-spring.log
|
||||
#log4j.appender.S.File=/Users/dpie/Desktop/usageStatsAPI-spring.log
|
||||
log4j.appender.S.File=/Volumes/Zeus/dpie/Desktop/usageStatsAPI-spring.log
|
||||
log4j.appender.S.File=/Users/dpie/Desktop/usageStatsAPI-spring.log
|
||||
#log4j.appender.S.File=/Volumes/Zeus/dpie/Desktop/usageStatsAPI-spring.log
|
||||
log4j.appender.S.MaxFileSize=10MB
|
||||
log4j.appender.S.MaxBackupIndex=10
|
||||
log4j.appender.S.layout=org.apache.log4j.PatternLayout
|
||||
|
|
Loading…
Reference in New Issue