Commit 22022021

This commit is contained in:
Dimitris 2021-02-22 19:39:27 +02:00
parent 7a3761c2c9
commit 5a2d8fe1eb
9 changed files with 1816 additions and 1154 deletions

View File

@ -10,7 +10,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.15.RELEASE</version>
<version>2.0.0.RELEASE</version>
</parent>
<dependencies>
@ -158,7 +158,12 @@
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<properties>

View File

@ -2,7 +2,6 @@ package eu.dnetlib.usagestats;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.retry.annotation.EnableRetry;
@ -13,7 +12,7 @@ import org.springframework.retry.annotation.EnableRetry;
)
@EnableRetry
@SpringBootApplication
public class UsageStatsApi extends SpringBootServletInitializer {
public class UsageStatsApi {
public static void main(String[] args) {
SpringApplication.run(UsageStatsApi.class, args);

View File

@ -1,42 +1,56 @@
package eu.dnetlib.usagestats.config;
//import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import javax.sql.DataSource;
import org.apache.log4j.Logger;
import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Created by tsampikos on 8/3/2017.
* Created by dpie on 25/01/2021.
*/
@Configuration
public class DataSourceConfiguration {
private final Logger log = Logger.getLogger(this.getClass());
@Value("${usagestats.driverClassName}")
private String driverClassName;
//@Value("${usagestats.driverClassName}")
//private String driverClassName;
@Value("${usagestats.url}")
private String dbURL;
@ConfigurationProperties(prefix = "usagestats")
//@ConfigurationProperties(prefix = "usagestats")
@Bean
@Primary
public DataSource getDataSource() {
PoolProperties poolProperties = new PoolProperties();
poolProperties.setUrl(dbURL);
poolProperties.setDriverClassName(driverClassName);
// PoolProperties poolProperties = new PoolProperties();
// poolProperties.setUrl(dbURL);
// poolProperties.setDriverClassName(driverClassName);
// log.info("dbURL " + dbURL);
// log.info("driverClassName " + driverClassName);
//
// poolProperties.setTestOnBorrow(true);
// poolProperties.setValidationQuery("SELECT 1");
// poolProperties.setValidationInterval(0);
// DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(poolProperties);
// return ds;
HikariConfig hikariConfig = new HikariConfig();
//hikariConfig.setDriverClassName("com.cloudera.impala.jdbc41.Driver");
hikariConfig.setJdbcUrl(dbURL);
log.info("dbURL " + dbURL);
log.info("driverClassName " + driverClassName);
//log.info("driverClassName " + driverClassName);
//
// hikariConfig.setMaximumPoolSize(5);
hikariConfig.setConnectionTestQuery("SELECT 1");
hikariConfig.setPoolName("UsageStats_HikariCP");
poolProperties.setTestOnBorrow(true);
poolProperties.setValidationQuery("SELECT 1");
poolProperties.setValidationInterval(0);
DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(poolProperties);
return ds;
HikariDataSource dataSource = new HikariDataSource(hikariConfig);
return dataSource;
}
}

View File

@ -3,6 +3,8 @@ package eu.dnetlib.usagestats.config;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
@ -12,7 +14,8 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* Created by tsampikos on 20/4/2017.
*/
@Configuration
@ConfigurationProperties(prefix = "usagestats")
@EnableConfigurationProperties
public class SpringRedisConfiguration {
private final Logger log = Logger.getLogger(this.getClass());

View File

@ -22,25 +22,25 @@ class SushiLiteController {
this.sushiLiteService = sushiLiteService;
}
@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,
@RequestParam(value = "Pretty", defaultValue = "") String pretty) {
log.info("Sushi Report request: " + reportP + " from " + requestorId);
log.info("repository identifier: " + repositoryIdentifier + " - item identifier: " + itemIdentifier);
return sushiLiteService.displayReport(reportP, release, requestorId, beginDate, endDate, repositoryIdentifier, itemIdentifier, itemDataType, hasDoi, granularity, callback, pretty);
}
// @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,
// @RequestParam(value = "Pretty", defaultValue = "") String pretty) {
// log.info("Sushi Report request: " + reportP + " from " + requestorId);
// log.info("repository identifier: " + repositoryIdentifier + " - item identifier: " + itemIdentifier);
//
// return sushiLiteService.displayReport(reportP, release, requestorId, beginDate, endDate, repositoryIdentifier, itemIdentifier, itemDataType, hasDoi, granularity, callback, pretty);
// }
@RequestMapping(value = "/sushilite/r5/status", method = RequestMethod.GET)
public String getReportStatus() {
@ -57,33 +57,36 @@ class SushiLiteController {
@RequestMapping(value = "/sushilite/r5/reports/pr", method = RequestMethod.GET)
public String getReportPR(
@RequestParam(value = "RepositoryIdentifier", defaultValue = "") String repositoryIdentifier,
@RequestParam(value = "RequestorID", defaultValue = "anonymous") String requestorId,
@RequestParam(value = "BeginDate", defaultValue = "") String beginDate,
@RequestParam(value = "EndDate", defaultValue = "") String endDate,
@RequestParam(value = "MetricType", defaultValue = "") String metricType,
@RequestParam(value = "DataType", defaultValue = "") String dataType,
@RequestParam(value = "Granularity", defaultValue = "Monthly") String granularity) {
log.info("COUNTER PR Report request for repository " + repositoryIdentifier);
return sushiLiteService.displayReportPR(repositoryIdentifier, beginDate, endDate, metricType, dataType, granularity);
return sushiLiteService.displayReportPR(requestorId,repositoryIdentifier, beginDate, endDate, metricType, dataType, granularity);
}
@RequestMapping(value = "/sushilite/r5/reports/pr_p1", method = RequestMethod.GET)
public String getReportPR_P1(
@RequestParam(value = "RepositoryIdentifier", defaultValue = "") String repositoryIdentifier,
@RequestParam(value = "RequestorID", defaultValue = "anonymous") String requestorId,
@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);
return sushiLiteService.displayReportPR_P1(requestorId, repositoryIdentifier, beginDate, endDate);
}
@RequestMapping(value = "/sushilite/r5/reports/tr", method = RequestMethod.GET)
public String getReportPR(
@RequestMapping(value = "/sushilite/r5/reports/ir", method = RequestMethod.GET)
public String getReportTR(
@RequestParam(value = "RepositoryIdentifier", defaultValue = "") String repositoryIdentifier,
@RequestParam(value = "ItemIdentifier", defaultValue = "") String itemIdentifier,
@RequestParam(value = "RequestorID", defaultValue = "anonymous") String requestorId,
@RequestParam(value = "BeginDate", defaultValue = "") String beginDate,
@RequestParam(value = "EndDate", defaultValue = "") String endDate,
@RequestParam(value = "MetricType", defaultValue = "") String metricType,
@RequestParam(value = "DataType", defaultValue = "") String dataType,
@RequestParam(value = "Granularity", defaultValue = "Monthly") String granularity) {
log.info("COUNTER PR Report request for repository " + repositoryIdentifier);
return sushiLiteService.displayReportTR(repositoryIdentifier, itemIdentifier, beginDate, endDate, metricType, dataType, granularity);
log.info("COUNTER TR Report request for repository " + repositoryIdentifier +" and for item "+ itemIdentifier);
return sushiLiteService.displayReportIR(requestorId, repositoryIdentifier, itemIdentifier, beginDate, endDate, metricType, dataType, granularity);
}
}

View File

@ -1,19 +1,21 @@
package eu.dnetlib.usagestats.services;
import eu.dnetlib.usagestats.sushilite.domain.COUNTER_Item_Report;
import eu.dnetlib.usagestats.sushilite.domain.COUNTER_Platform_Report;
import eu.dnetlib.usagestats.sushilite.domain.COUNTER_Title_Report;
import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper;
import eu.dnetlib.usagestats.sushilite.domain.ReportStatus;
import java.util.ArrayList;
public interface SushiLiteService {
ReportResponseWrapper buildReport(String reportName, String release, String requestorId, String beginDate,
String endDate, String repositoryIdentifier, String itemIdentifier,
String itemDataType, String hasDoi, String granularity, String callback);
String displayReport(String reportName, String release, String requestorId, String beginDate,
String endDate, String repositoryIdentifier, String itemIdentifier,
String itemDataType, String hasDoi, String granularity, String callback, String pretty);
// ReportResponseWrapper buildReport(String reportName, String release, String requestorId, String beginDate,
// String endDate, String repositoryIdentifier, String itemIdentifier,
// String itemDataType, String hasDoi, String granularity, String callback);
//
// String displayReport(String reportName, String release, String requestorId, String beginDate,
// String endDate, String repositoryIdentifier, String itemIdentifier,
// String itemDataType, String hasDoi, String granularity, String callback, String pretty);
ReportStatus buildReportStatus();
String displayReportStatus();
@ -21,13 +23,13 @@ public interface SushiLiteService {
ArrayList buildReportSupported();
String displayReportsSupported();
COUNTER_Platform_Report buildReportPR(String repositoryIdentifier, String beginDate,String endDate, String metricType, String dataType,String granularity);
String displayReportPR(String repositoryIdentifier, String beginDate,String endDate, String metricType, String dataType,String granularity);
COUNTER_Platform_Report buildReportPR(String customerID, String repositoryIdentifier, String beginDate,String endDate, String metricType, String dataType,String granularity);
String displayReportPR(String customerID, String repositoryIdentifier, String beginDate,String endDate, String metricType, String dataType,String granularity);
COUNTER_Platform_Report buildReportPR_P1(String repositoryIdentifier, String beginDate,String endDate);
String displayReportPR_P1(String repositoryIdentifier, String beginDate, String endDate);
COUNTER_Platform_Report buildReportPR_P1(String customerID, String repositoryIdentifier, String beginDate,String endDate);
String displayReportPR_P1(String customerID, String repositoryIdentifier, String beginDate, String endDate);
COUNTER_Platform_Report buildReportTR(String repositoryIdentifier, String itemIdentifier, String beginDate,String endDate, String metricType, String dataType,String granularity);
String displayReportTR(String repositoryIdentifier, String itemIdentifier, String beginDate,String endDate, String metricType, String dataType,String granularity);
COUNTER_Item_Report buildReportIR(String customerID, String repositoryIdentifier, String itemIdentifier, String beginDate,String endDate, String metricType, String dataType,String granularity);
String displayReportIR(String customerID, String repositoryIdentifier, String itemIdentifier, String beginDate,String endDate, String metricType, String dataType,String granularity);
}

View File

@ -4,11 +4,14 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.usagestats.repositories.UsageStatsRepository;
import eu.dnetlib.usagestats.sushilite.domain.Alert;
import eu.dnetlib.usagestats.sushilite.domain.COUNTER_Item_Report;
import eu.dnetlib.usagestats.sushilite.domain.COUNTER_Item_Usage;
import eu.dnetlib.usagestats.sushilite.domain.Filter;
import eu.dnetlib.usagestats.sushilite.domain.SUSHI_Org_Identifiers;
import eu.dnetlib.usagestats.sushilite.domain.COUNTER_Platform_Usage;
import eu.dnetlib.usagestats.sushilite.domain.SUSHI_Error_Model;
import eu.dnetlib.usagestats.sushilite.domain.COUNTER_Platform_Report;
import eu.dnetlib.usagestats.sushilite.domain.COUNTER_Title_Report;
import eu.dnetlib.usagestats.sushilite.domain.ReportResponse;
import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper;
import eu.dnetlib.usagestats.sushilite.domain.ReportStatus;
@ -36,204 +39,202 @@ public class SushiLiteServiceImpl implements SushiLiteService {
this.usageStatsRepository = usageStatsRepository;
}
@Override
public ReportResponseWrapper buildReport(String reportName, String release,
String requestorId, String beginDate,
String endDate, String repositoryIdentifier, String itemIdentifier,
String itemDataType, String hasDoi, String granularity,
String callback) {
List<COUNTER_Platform_Usage> reportItems = new ArrayList<>();
List<SUSHI_Error_Model> reportExceptions = new ArrayList<>();
if (!granularity.equalsIgnoreCase("totals") && !granularity.equalsIgnoreCase("monthly")) {
reportExceptions.add(new SUSHI_Error_Model("3062", "Warning", "Invalid ReportAttribute Value", "usagecounts.openaire.eu", "Granularity: \'" + granularity + "\' unknown. Defaulting to Monthly"));
granularity = "Monthly";
}
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 SUSHI_Error_Model("3021", "Warning", "Unspecified Date Arguments", "usagecounts.openaire.eu","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 SUSHI_Error_Model("3021", "Warning", "Unspecified Date Arguments", "usagecounts.openaire.eu", "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 SUSHI_Error_Model("3020", "Error", "Invalid Date Arguments", "usagecounts.openaire.eu", "Begin Date: " + beginDate + " is not a valid date"));
}
if (endDateParsed == null) {
reportExceptions.add(new SUSHI_Error_Model("3020", "Error", "Invalid Date Arguments", "usagecounts.openaire.eu", "End Date: " + endDate + " is not a valid date"));
}
if (beginDateParsed != null && endDateParsed != null && !beginDateParsed.before(endDateParsed)) {
reportExceptions.add(new SUSHI_Error_Model("3020", "Error", "Invalid Date Arguments", "usagecounts.openaire.eu", "BeginDate \'" + new SimpleDateFormat("yyyy-MM-dd").format(beginDateParsed) + "\' is greater than EndDate \'" + new SimpleDateFormat("yyyy-MM-dd").format(endDateParsed) + "\'"));
}
String repoid = "";
if (!repositoryIdentifier.equals("")) {
repoid = usageStatsRepository.executeRepoId(repositoryIdentifier, reportName.toLowerCase());
if (repoid.equals("-1")) {
reportExceptions.add(new SUSHI_Error_Model("3060", "Error", "Invalid Filter Value", "usagecounts.openaire.eu", "RepositoryIdentifier: " + repositoryIdentifier + " is not valid"));
}
}
String itemid = "";
if (!itemIdentifier.equals("")) {
String[] split = itemIdentifier.split(":");
switch (split[0].toLowerCase()) {
case "oid":
itemid = itemIdentifier;
break;
case "doi":
itemid = itemIdentifier;
break;
case "openaire":
itemid = itemIdentifier;
break;
default:
reportExceptions.add(new SUSHI_Error_Model("3060", "Error", "Invalid Filter Value", "usagecounts.openaire.eu", "ItemIdentifier: " + itemIdentifier + " is not valid"));
itemid = "-1";
}
}
if (itemid.equals("") && repoid.equals("") && !reportName.equalsIgnoreCase("rr1") && !reportName.equalsIgnoreCase("jr1")) {
reportExceptions.add(new SUSHI_Error_Model("3070", "Error", "Required Filter Missing", "usagecounts.openaire.eu", "ItemIdentifier or RepositoryIdentifier must be supplied"));
}
if (reportName.equalsIgnoreCase("ar1")) {
if (!itemid.equals("-1") && !repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
if (!itemid.equals("")) {
if (itemDataType.equalsIgnoreCase("") || itemDataType.equalsIgnoreCase("article")) {
usageStatsRepository.executeItem(reportItems, itemIdentifier, repoid, "Article", beginDateParsed, endDateParsed, granularity);
if (reportItems.isEmpty()) {
reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
}
} else {
reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
}
} else if (!repoid.equals("")) {
usageStatsRepository.executeBatchItems(reportItems, repoid, "Article", beginDateParsed, endDateParsed, granularity);
if (reportItems.isEmpty()) {
reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
}
}
}
} else if (reportName.equalsIgnoreCase("br1")) {
if (!itemid.equals("-1") && !repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
if (!itemid.equals("")) {
if (itemDataType.equalsIgnoreCase("") || itemDataType.equalsIgnoreCase("book")) {
usageStatsRepository.executeItem(reportItems, itemIdentifier, repoid, "Book", beginDateParsed, endDateParsed, granularity);
if (reportItems.isEmpty()) {
reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
}
} else {
reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
}
} else if (!repoid.equals("")) {
usageStatsRepository.executeBatchItems(reportItems, repoid, "Book", beginDateParsed, endDateParsed, granularity);
if (reportItems.isEmpty()) {
reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
}
}
}
} else if (reportName.equalsIgnoreCase("br2")) {
if (!itemid.equals("-1") && !repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
if (!itemid.equals("")) {
if (itemDataType.equalsIgnoreCase("") || itemDataType.equalsIgnoreCase("part of book or chapter of book")) {
usageStatsRepository.executeItem(reportItems, itemIdentifier, repoid, "Part of book or chapter of book", beginDateParsed, endDateParsed, granularity);
if (reportItems.isEmpty()) {
reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
}
} else {
reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
}
} else if (!repoid.equals("")) {
usageStatsRepository.executeBatchItems(reportItems, repoid, "Part of book or chapter of book", beginDateParsed, endDateParsed, granularity);
if (reportItems.isEmpty()) {
reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
}
}
}
} else if (reportName.equalsIgnoreCase("ir1")) {
if (!itemid.equals("-1") && !repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
if (!itemid.equals("")) {
usageStatsRepository.executeItem(reportItems, itemIdentifier, repoid, itemDataType, beginDateParsed, endDateParsed, granularity);
} else if (!repoid.equals("")) {
usageStatsRepository.executeBatchItems(reportItems, repoid, itemDataType, beginDateParsed, endDateParsed, granularity);
}
if (reportItems.isEmpty()) {
reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
}
}
} else if (reportName.equalsIgnoreCase("rr1")) {
if (!repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
usageStatsRepository.executeRepo(reportItems, repoid, itemDataType, beginDateParsed, endDateParsed, granularity);
}
if (reportItems.isEmpty()) {
reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
}
} else if (reportName.equalsIgnoreCase("jr1")) {
if (!repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
usageStatsRepository.executeJournal(reportItems, repoid, itemDataType, beginDateParsed, endDateParsed, granularity);
}
if (reportItems.isEmpty()) {
reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
}
} else if (reportName.equals("")) {
reportExceptions.add(new SUSHI_Error_Model("3050", "Error", "usagecounts.openaire.eu", "Report argument is missing", "You must supply a Report argument"));
} else {
reportExceptions.add(new SUSHI_Error_Model("3000", "Error", "usagecounts.openaire.eu", "Report " + reportName + " not supported", "Supported reports: AR1, IR1, RR1, BR1, BR2"));
}
ReportResponse reportResponse = new ReportResponse(reportName, release, requestorId, beginDate, endDate,
repositoryIdentifier, itemIdentifier, itemDataType, hasDoi, granularity, callback, reportItems, reportExceptions);
return new ReportResponseWrapper(reportResponse);
}
@Override
public String displayReport(String reportName, String release,
String requestorId, String beginDate, String endDate,
String repositoryIdentifier, String itemIdentifier,
String itemDataType, String hasDoi, String granularity,
String callback, String pretty) {
ObjectMapper objectMapper = new ObjectMapper();
try {
if (pretty.equalsIgnoreCase("pretty")) {
return "<pre>" + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(buildReport(reportName, release, requestorId, beginDate, endDate, repositoryIdentifier, itemIdentifier, itemDataType, hasDoi, granularity, callback)).replaceAll("/", "\\\\/") + "</pre>";
}
return objectMapper.writeValueAsString(buildReport(reportName, release, requestorId, beginDate, endDate, repositoryIdentifier, itemIdentifier, itemDataType, hasDoi, granularity, callback)).replaceAll("/", "\\\\/");
} catch (Exception e) {
e.printStackTrace();
return null;
}
//return report.getReport(reportP, release, requestorId, beginDate, endDate, repositoryIdentifier, itemIdentifier, itemDataType, hasDoi, granularity, callback, pretty);
}
// @Override
// public ReportResponseWrapper buildReport(String reportName, String release,
// String requestorId, String beginDate,
// String endDate, String repositoryIdentifier, String itemIdentifier,
// String itemDataType, String hasDoi, String granularity,
// String callback) {
//
// List<COUNTER_Platform_Usage> reportItems = new ArrayList<>();
// List<SUSHI_Error_Model> reportExceptions = new ArrayList<>();
//
// if (!granularity.equalsIgnoreCase("totals") && !granularity.equalsIgnoreCase("monthly")) {
// reportExceptions.add(new SUSHI_Error_Model("3062", "Warning", "Invalid ReportAttribute Value", "usagecounts.openaire.eu", "Granularity: \'" + granularity + "\' unknown. Defaulting to Monthly"));
// granularity = "Monthly";
// }
//
// 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 SUSHI_Error_Model("3021", "Warning", "Unspecified Date Arguments", "usagecounts.openaire.eu", "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 SUSHI_Error_Model("3021", "Warning", "Unspecified Date Arguments", "usagecounts.openaire.eu", "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 SUSHI_Error_Model("3020", "Error", "Invalid Date Arguments", "usagecounts.openaire.eu", "Begin Date: " + beginDate + " is not a valid date"));
// }
// if (endDateParsed == null) {
// reportExceptions.add(new SUSHI_Error_Model("3020", "Error", "Invalid Date Arguments", "usagecounts.openaire.eu", "End Date: " + endDate + " is not a valid date"));
// }
// if (beginDateParsed != null && endDateParsed != null && !beginDateParsed.before(endDateParsed)) {
// reportExceptions.add(new SUSHI_Error_Model("3020", "Error", "Invalid Date Arguments", "usagecounts.openaire.eu", "BeginDate \'" + new SimpleDateFormat("yyyy-MM-dd").format(beginDateParsed) + "\' is greater than EndDate \'" + new SimpleDateFormat("yyyy-MM-dd").format(endDateParsed) + "\'"));
// }
//
// String repoid = "";
// if (!repositoryIdentifier.equals("")) {
// repoid = usageStatsRepository.executeRepoId(repositoryIdentifier, reportName.toLowerCase());
// if (repoid.equals("-1")) {
// reportExceptions.add(new SUSHI_Error_Model("3060", "Error", "Invalid Filter Value", "usagecounts.openaire.eu", "RepositoryIdentifier: " + repositoryIdentifier + " is not valid"));
// }
// }
// String itemid = "";
// if (!itemIdentifier.equals("")) {
// String[] split = itemIdentifier.split(":");
// switch (split[0].toLowerCase()) {
// case "oid":
// itemid = itemIdentifier;
// break;
// case "doi":
// itemid = itemIdentifier;
// break;
// case "openaire":
// itemid = itemIdentifier;
// break;
// default:
// reportExceptions.add(new SUSHI_Error_Model("3060", "Error", "Invalid Filter Value", "usagecounts.openaire.eu", "ItemIdentifier: " + itemIdentifier + " is not valid"));
// itemid = "-1";
// }
// }
// if (itemid.equals("") && repoid.equals("") && !reportName.equalsIgnoreCase("rr1") && !reportName.equalsIgnoreCase("jr1")) {
// reportExceptions.add(new SUSHI_Error_Model("3070", "Error", "Required Filter Missing", "usagecounts.openaire.eu", "ItemIdentifier or RepositoryIdentifier must be supplied"));
// }
// if (reportName.equalsIgnoreCase("ar1")) {
// if (!itemid.equals("-1") && !repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
// if (!itemid.equals("")) {
// if (itemDataType.equalsIgnoreCase("") || itemDataType.equalsIgnoreCase("article")) {
// usageStatsRepository.executeItem(reportItems, itemIdentifier, repoid, "Article", beginDateParsed, endDateParsed, granularity);
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// } else {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// } else if (!repoid.equals("")) {
// usageStatsRepository.executeBatchItems(reportItems, repoid, "Article", beginDateParsed, endDateParsed, granularity);
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// }
// }
// } else if (reportName.equalsIgnoreCase("br1")) {
// if (!itemid.equals("-1") && !repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
// if (!itemid.equals("")) {
// if (itemDataType.equalsIgnoreCase("") || itemDataType.equalsIgnoreCase("book")) {
// usageStatsRepository.executeItem(reportItems, itemIdentifier, repoid, "Book", beginDateParsed, endDateParsed, granularity);
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// } else {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// } else if (!repoid.equals("")) {
// usageStatsRepository.executeBatchItems(reportItems, repoid, "Book", beginDateParsed, endDateParsed, granularity);
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// }
// }
// } else if (reportName.equalsIgnoreCase("br2")) {
// if (!itemid.equals("-1") && !repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
// if (!itemid.equals("")) {
// if (itemDataType.equalsIgnoreCase("") || itemDataType.equalsIgnoreCase("part of book or chapter of book")) {
// usageStatsRepository.executeItem(reportItems, itemIdentifier, repoid, "Part of book or chapter of book", beginDateParsed, endDateParsed, granularity);
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// } else {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// } else if (!repoid.equals("")) {
// usageStatsRepository.executeBatchItems(reportItems, repoid, "Part of book or chapter of book", beginDateParsed, endDateParsed, granularity);
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// }
// }
// } else if (reportName.equalsIgnoreCase("ir1")) {
// if (!itemid.equals("-1") && !repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
// if (!itemid.equals("")) {
// usageStatsRepository.executeItem(reportItems, itemIdentifier, repoid, itemDataType, beginDateParsed, endDateParsed, granularity);
// } else if (!repoid.equals("")) {
// usageStatsRepository.executeBatchItems(reportItems, repoid, itemDataType, beginDateParsed, endDateParsed, granularity);
// }
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// }
// } else if (reportName.equalsIgnoreCase("rr1")) {
// if (!repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
// usageStatsRepository.executeRepo(reportItems, repoid, itemDataType, beginDateParsed, endDateParsed, granularity);
// }
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// } else if (reportName.equalsIgnoreCase("jr1")) {
// if (!repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
// usageStatsRepository.executeJournal(reportItems, repoid, itemDataType, beginDateParsed, endDateParsed, granularity);
// }
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// } else if (reportName.equals("")) {
// reportExceptions.add(new SUSHI_Error_Model("3050", "Error", "usagecounts.openaire.eu", "Report argument is missing", "You must supply a Report argument"));
// } else {
// reportExceptions.add(new SUSHI_Error_Model("3000", "Error", "usagecounts.openaire.eu", "Report " + reportName + " not supported", "Supported reports: AR1, IR1, RR1, BR1, BR2"));
// }
//
// ReportResponse reportResponse = new ReportResponse(reportName, release, requestorId, beginDate, endDate,
// repositoryIdentifier, itemIdentifier, itemDataType, hasDoi, granularity, callback, reportItems, reportExceptions);
//
// return new ReportResponseWrapper(reportResponse);
// }
// @Override
// public String displayReport(String reportName, String release,
// String requestorId, String beginDate, String endDate,
// String repositoryIdentifier, String itemIdentifier,
// String itemDataType, String hasDoi, String granularity,
// String callback, String pretty) {
// ObjectMapper objectMapper = new ObjectMapper();
// try {
// if (pretty.equalsIgnoreCase("pretty")) {
// return "<pre>" + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(buildReport(reportName, release, requestorId, beginDate, endDate, repositoryIdentifier, itemIdentifier, itemDataType, hasDoi, granularity, callback)).replaceAll("/", "\\\\/") + "</pre>";
// }
// return objectMapper.writeValueAsString(buildReport(reportName, release, requestorId, beginDate, endDate, repositoryIdentifier, itemIdentifier, itemDataType, hasDoi, granularity, callback)).replaceAll("/", "\\\\/");
// } catch (Exception e) {
// e.printStackTrace();
// return null;
// }
// //return report.getReport(reportP, release, requestorId, beginDate, endDate, repositoryIdentifier, itemIdentifier, itemDataType, hasDoi, granularity, callback, pretty);
// }
private Date tryParse(String dateString) {
try {
if (dateString.length() == 7) {
@ -299,7 +300,7 @@ public class SushiLiteServiceImpl implements SushiLiteService {
}
@Override
public COUNTER_Platform_Report buildReportPR(String repositoryIdentifier, String beginDate,
public COUNTER_Platform_Report buildReportPR(String customerID, String repositoryIdentifier, String beginDate,
String endDate, String metricType, String dataType, String granularity) {
List<SUSHI_Error_Model> reportExceptions = new ArrayList<>();
ZonedDateTime dateTime = ZonedDateTime.now(); // Gets the current date and time, with your default time-zone
@ -358,8 +359,8 @@ public class SushiLiteServiceImpl implements SushiLiteService {
reportFilters.add(new Filter("EndDate", endDate));
String reportID = "PR";
String reportName = "Platform Master Report";
//String insitutionName = "Insititution Name " + repositoryIdentifier;
String insitutionName = usageStatsRepository.getInstitutionName(repositoryIdentifier);
//String institutionName = "Insititution Name " + repositoryIdentifier;
String institutionName = usageStatsRepository.getInstitutionName(repositoryIdentifier);
List<SUSHI_Org_Identifiers> institutionIdD = new ArrayList();
institutionIdD.add(new SUSHI_Org_Identifiers("Openaire", repositoryIdentifier));
@ -372,12 +373,12 @@ public class SushiLiteServiceImpl implements SushiLiteService {
if (reportExceptions.size() == 0) {
reportExceptions = null;
}
COUNTER_Platform_Report reportPr = new COUNTER_Platform_Report(dateTime.format(formatter), repositoryIdentifier, reportID, reportName, insitutionName, institutionIdD, reportExceptions, reportFilters, reportItems);
COUNTER_Platform_Report reportPr = new COUNTER_Platform_Report(dateTime.format(formatter), customerID, reportID, reportName, institutionName, institutionIdD, reportExceptions, reportFilters, reportItems);
return reportPr;
}
@Override
public COUNTER_Platform_Report buildReportPR_P1(String repositoryIdentifier,
public COUNTER_Platform_Report buildReportPR_P1(String customerID, String repositoryIdentifier,
String beginDate,
String endDate) {
String granularity = "monthly";
@ -439,8 +440,8 @@ public class SushiLiteServiceImpl implements SushiLiteService {
reportFilters.add(new Filter("EndDate", endDate));
String reportID = "PR";
String reportName = "Platform Master Report";
//String insitutionName = "Insititution Name " + repositoryIdentifier;
String insitutionName = usageStatsRepository.getInstitutionName(repositoryIdentifier);
//String institutionName = "Insititution Name " + repositoryIdentifier;
String institutionName = usageStatsRepository.getInstitutionName(repositoryIdentifier);
List<SUSHI_Org_Identifiers> institutionIdD = new ArrayList();
institutionIdD.add(new SUSHI_Org_Identifiers("Openaire", repositoryIdentifier));
@ -450,23 +451,37 @@ public class SushiLiteServiceImpl implements SushiLiteService {
reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
}
if (reportExceptions.size() == 0) {
reportExceptions = null;
}
COUNTER_Platform_Report reportPr = new COUNTER_Platform_Report(dateTime.format(formatter), repositoryIdentifier, reportID, reportName, insitutionName, institutionIdD, reportExceptions, reportFilters, reportItems);
COUNTER_Platform_Report reportPr = new COUNTER_Platform_Report(dateTime.format(formatter), customerID, reportID, reportName, institutionName, institutionIdD, reportExceptions, reportFilters, reportItems);
return reportPr;
}
@Override
public COUNTER_Platform_Report buildReportTR(String repositoryIdentifier, String itemIdentifier, String beginDate,
public COUNTER_Item_Report buildReportIR(String customerID, String repositoryIdentifier, String itemIdentifier, String beginDate,
String endDate, String metricType, String dataType, String granularity) {
List<SUSHI_Error_Model> 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
List<COUNTER_Item_Usage> reportItems = new ArrayList<>();
List<SUSHI_Error_Model> reportExceptions = new ArrayList<>();
List<Filter> reportFilters = new ArrayList();
List<SUSHI_Org_Identifiers> orgIdentifiers = new ArrayList<>();
reportFilters.add(new Filter("BeginDate", beginDate));
reportFilters.add(new Filter("EndDate", endDate));
repositoryIdentifier = usageStatsRepository.getInstitutionID(repositoryIdentifier);
orgIdentifiers.add(new SUSHI_Org_Identifiers("Openaire", repositoryIdentifier));
if (!granularity.equalsIgnoreCase("totals") && !granularity.equalsIgnoreCase("monthly")) {
reportExceptions.add(new SUSHI_Error_Model("3062", "Warning", "Invalid ReportAttribute Value", "usagecounts.openaire.eu", "Granularity: \'" + granularity + "\' unknown. Defaulting to Monthly"));
granularity = "Monthly";
}
Date beginDateParsed;
if (!beginDate.equals("")) {
@ -482,7 +497,7 @@ public class SushiLiteServiceImpl implements SushiLiteService {
temp.add(Calendar.MONTH, -1);
temp.set(Calendar.DAY_OF_MONTH, temp.getActualMinimum(Calendar.DAY_OF_MONTH));
beginDateParsed = temp.getTime();
reportExceptions.add(new SUSHI_Error_Model("3021", "Warning", "usagecounts.openaire.eu", "Unspecified Date Arguments", "Begin Date set to default: " + new SimpleDateFormat("yyyy-MM-dd").format(beginDateParsed)));
reportExceptions.add(new SUSHI_Error_Model("3021", "Warning", "Unspecified Date Arguments", "usagecounts.openaire.eu", "Begin Date set to default: " + new SimpleDateFormat("yyyy-MM-dd").format(beginDateParsed)));
}
Date endDateParsed;
@ -499,49 +514,230 @@ public class SushiLiteServiceImpl implements SushiLiteService {
temp.add(Calendar.MONTH, -1);
temp.set(Calendar.DAY_OF_MONTH, temp.getActualMaximum(Calendar.DAY_OF_MONTH));
endDateParsed = temp.getTime();
reportExceptions.add(new SUSHI_Error_Model("3021", "Warning", "usagecounts.openaire.eu", "Unspecified Date Arguments", "End Date set to default: " + new SimpleDateFormat("yyyy-MM-dd").format(endDateParsed)));
reportExceptions.add(new SUSHI_Error_Model("3021", "Warning", "Unspecified Date Arguments", "usagecounts.openaire.eu", "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 SUSHI_Error_Model("3020", "Error", "usagecounts.openaire.eu", "Invalid Date Arguments", "Begin Date: " + beginDate + " is not a valid date"));
reportExceptions.add(new SUSHI_Error_Model("3020", "Error", "Invalid Date Arguments", "usagecounts.openaire.eu", "Begin Date: " + beginDate + " is not a valid date"));
}
if (endDateParsed == null) {
reportExceptions.add(new SUSHI_Error_Model("3020", "Error", "usagecounts.openaire.eu", "Invalid Date Arguments", "End Date: " + endDate + " is not a valid date"));
reportExceptions.add(new SUSHI_Error_Model("3020", "Error", "Invalid Date Arguments", "usagecounts.openaire.eu", "End Date: " + endDate + " is not a valid date"));
}
if (beginDateParsed != null && endDateParsed != null && !beginDateParsed.before(endDateParsed)) {
reportExceptions.add(new SUSHI_Error_Model("3020", "Error", "usagecounts.openaire.eu", "Invalid Date Arguments", "BeginDate \'" + new SimpleDateFormat("yyyy-MM-dd").format(beginDateParsed) + "\' is greater than EndDate \'" + new SimpleDateFormat("yyyy-MM-dd").format(endDateParsed) + "\'"));
reportExceptions.add(new SUSHI_Error_Model("3020", "Error", "Invalid Date Arguments", "usagecounts.openaire.eu", "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 = "ΤR";
String reportName = "Title Master Report";
String insitutionName = usageStatsRepository.getInstitutionName(repositoryIdentifier);
List<SUSHI_Org_Identifiers> institutionIdD = new ArrayList();
institutionIdD.add(new SUSHI_Org_Identifiers("Openaire", repositoryIdentifier));
String repoid = repositoryIdentifier;
String institutionName = usageStatsRepository.getInstitutionName(repositoryIdentifier);
//if (!repositoryIdentifier.equals("")) {
// repoid = usageStatsRepository.getInstitutionID(repositoryIdentifier);
if (repoid.equals("-1")) {
reportExceptions.add(new SUSHI_Error_Model("3060", "Error", "Invalid Filter Value", "usagecounts.openaire.eu", "RepositoryIdentifier: " + repositoryIdentifier + " is not valid"));
}
//}
String itemid = "";
if (!itemIdentifier.equals("")) {
String[] split = itemIdentifier.split(":");
switch (split[0].toLowerCase()) {
case "oid":
itemid = itemIdentifier;
break;
case "doi":
itemid = itemIdentifier;
break;
// case "openaire":
// itemid = itemIdentifier;
// break;
default:
reportExceptions.add(new SUSHI_Error_Model("3060", "Error", "Invalid Filter Value", "usagecounts.openaire.eu", "ItemIdentifier: " + itemIdentifier + " is not valid"));
itemid = "-1";
}
}
if (itemid.equals("") && repoid.equals("")) {
reportExceptions.add(new SUSHI_Error_Model("3070", "Error", "Required Filter Missing", "usagecounts.openaire.eu", "ItemIdentifier or RepositoryIdentifier must be supplied"));
}
//if (reportName.equalsIgnoreCase("ar1")) {
if (!itemid.equals("-1") && !repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
// if (!itemid.equals("")) {
// if (dataType.equalsIgnoreCase("") || dataType.equalsIgnoreCase("article")) {
// usageStatsRepository.executeItem(reportItems, itemIdentifier, repoid, "Article", beginDateParsed, endDateParsed, granularity);
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// } else {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// } else if (!repoid.equals("")) {
usageStatsRepository.executeBatchItemsIR(reportItems, repoid, itemIdentifier, beginDateParsed, endDateParsed, metricType, "Article", granularity);
if (reportItems.isEmpty()) {
reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
}
}
// }
// //} else if (reportName.equalsIgnoreCase("br1")) {
// if (!itemid.equals("-1") && !repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
// if (!itemid.equals("")) {
// if (dataType.equalsIgnoreCase("") || dataType.equalsIgnoreCase("book")) {
// usageStatsRepository.executeItem(reportItems, itemIdentifier, repoid, "Book", beginDateParsed, endDateParsed, granularity);
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// } else {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// } else if (!repoid.equals("")) {
// usageStatsRepository.executeBatchItems(reportItems, repoid, "Book", beginDateParsed, endDateParsed, granularity);
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// }
// }
// //}
// if (!itemid.equals("-1") && !repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
// if (!itemid.equals("")) {
// if (dataType.equalsIgnoreCase("") || dataType.equalsIgnoreCase("part of book or chapter of book")) {
// usageStatsRepository.executeItem(reportItems, itemIdentifier, repoid, "Part of book or chapter of book", beginDateParsed, endDateParsed, granularity);
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// } else {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// } else if (!repoid.equals("")) {
// usageStatsRepository.executeBatchItems(reportItems, repoid, "Part of book or chapter of book", beginDateParsed, endDateParsed, granularity);
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// }
// }
// //else if (reportName.equalsIgnoreCase("ir1")) {
// if (!itemid.equals("-1") && !repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
// if (!itemid.equals("")) {
// usageStatsRepository.executeItem(reportItems, itemIdentifier, repoid, dataType, beginDateParsed, endDateParsed, granularity);
// } else if (!repoid.equals("")) {
// usageStatsRepository.executeBatchItems(reportItems, repoid, dataType, beginDateParsed, endDateParsed, granularity);
// }
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// }
// //} else if (reportName.equalsIgnoreCase("rr1")) {
// if (!repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
// usageStatsRepository.executeRepo(reportItems, repoid, dataType, beginDateParsed, endDateParsed, granularity);
// }
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
// //} else if (reportName.equalsIgnoreCase("jr1")) {
// if (!repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
// usageStatsRepository.executeJournal(reportItems, repoid, dataType, beginDateParsed, endDateParsed, granularity);
// }
List<COUNTER_Platform_Usage> reportItems = new ArrayList();
usageStatsRepository.executeBatchItemsPR(reportItems, repositoryIdentifier, beginDateParsed, endDateParsed, metricType, dataType, granularity);
if (reportItems.isEmpty()) {
reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
}
//} else if (reportName.equals("")) {
// reportExceptions.add(new SUSHI_Error_Model("3050", "Error", "usagecounts.openaire.eu", "Report argument is missing", "You must supply a Report argument"));
//} else {
// reportExceptions.add(new SUSHI_Error_Model("3000", "Error", "usagecounts.openaire.eu", "Report " + reportName + " not supported", "Supported reports: AR1, IR1, RR1, BR1, BR2"));
//}
if (reportExceptions.size() == 0) {
reportExceptions = null;
}
COUNTER_Platform_Report reportPr = new COUNTER_Platform_Report(dateTime.format(formatter), repositoryIdentifier, reportID, reportName, insitutionName, institutionIdD, reportExceptions, reportFilters, reportItems);
return reportPr;
COUNTER_Item_Report reportResponse = new COUNTER_Item_Report(dateTime.format(formatter), customerID, "IR", "Item Report", institutionName, orgIdentifiers,
reportExceptions, reportFilters, reportItems);
return reportResponse;
}
// @Override
// public COUNTER_Title_Report buildReportIR(String customerID, String repositoryIdentifier, String itemIdentifier, String beginDate,
// String endDate, String metricType, String dataType, String granularity) {
// List<SUSHI_Error_Model> 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 SUSHI_Error_Model("3021", "Warning", "usagecounts.openaire.eu", "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 SUSHI_Error_Model("3021", "Warning", "usagecounts.openaire.eu", "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 SUSHI_Error_Model("3020", "Error", "usagecounts.openaire.eu", "Invalid Date Arguments", "Begin Date: " + beginDate + " is not a valid date"));
// }
// if (endDateParsed == null) {
// reportExceptions.add(new SUSHI_Error_Model("3020", "Error", "usagecounts.openaire.eu", "Invalid Date Arguments", "End Date: " + endDate + " is not a valid date"));
// }
// if (beginDateParsed != null && endDateParsed != null && !beginDateParsed.before(endDateParsed)) {
// reportExceptions.add(new SUSHI_Error_Model("3020", "Error", "usagecounts.openaire.eu", "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 = "ΤR";
// String reportName = "Title Master Report";
// String institutionName = usageStatsRepository.getInstitutionName(repositoryIdentifier);
// List<SUSHI_Org_Identifiers> institutionIdD = new ArrayList();
// institutionIdD.add(new SUSHI_Org_Identifiers("Openaire", repositoryIdentifier));
//
// List<COUNTER_Platform_Usage> reportItems = new ArrayList();
// usageStatsRepository.executeBatchItemsTR(reportItems, repositoryIdentifier, itemIdentifier,beginDateParsed, endDateParsed, metricType, dataType, granularity);
//
// if (reportItems.isEmpty()) {
// reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
// }
//
// if (reportExceptions.size() == 0) {
// reportExceptions = null;
// }
// COUNTER_Title_Report reportTR = new COUNTER_Title_Report(dateTime.format(formatter), customerID, reportID, reportName, institutionName, institutionIdD, reportExceptions, reportFilters, reportItems);
// return reportTR;
// }
@Override
public String displayReportPR(String repositoryIdentifier, String beginDate,
public String displayReportPR(String customerID, String repositoryIdentifier, String beginDate,
String endDate, String metricType, String dataType, String granularity) {
ObjectMapper objectMapper = new ObjectMapper();
log.info((beginDate + " " + endDate));
try {
return "<pre>" + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(buildReportPR(repositoryIdentifier, beginDate, endDate, metricType, dataType, granularity)) + "</pre>";
return "<pre>" + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(buildReportPR(customerID, repositoryIdentifier, beginDate, endDate, metricType, dataType, granularity)) + "</pre>";
} catch (JsonProcessingException ex) {
java.util.logging.Logger.getLogger(SushiLiteServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
@ -549,26 +745,27 @@ public class SushiLiteServiceImpl implements SushiLiteService {
}
@Override
public String displayReportPR_P1(String repositoryIdentifier,
public String displayReportPR_P1(String customerID, 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>";
return "<pre>" + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(buildReportPR_P1(customerID, repositoryIdentifier, beginDate, endDate)) + "</pre>";
} catch (JsonProcessingException ex) {
java.util.logging.Logger.getLogger(SushiLiteServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
@Override
public String displayReportTR(String repositoryIdentifier, String itemIdentifier,String beginDate,
public String displayReportIR(String customerID, String repositoryIdentifier, String itemIdentifier, String beginDate,
String endDate, String metricType, String dataType, String granularity) {
ObjectMapper objectMapper = new ObjectMapper();
log.info((beginDate + " " + endDate));
try {
return "<pre>" + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(buildReportPR(repositoryIdentifier, beginDate, endDate, metricType, dataType, granularity)) + "</pre>";
return "<pre>" + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(buildReportIR(customerID, repositoryIdentifier, itemIdentifier, beginDate, endDate, metricType, dataType, granularity)) + "</pre>";
} catch (JsonProcessingException ex) {
java.util.logging.Logger.getLogger(SushiLiteServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}

View File

@ -1,10 +1,9 @@
name=usageStatsAPI
logging.config=log4j.properties
usagestats.driverClassName=com.cloudera.impala.jdbc41.Driver
#usagestats.driverClassName=com.cloudera.impala.jdbc41.Driver
spring.datasource.driverClassName=com.cloudera.impala.jdbc41.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.HSQLDialect
usagestats.url=jdbc:impala://iis-cdh5-test-gw.ocean.icm.edu.pl:21050/;UseNativeQuery=1;AutoReconnect=1
usagestats.username=sqoop
usagestats.password=sqoop
usagestats.redis.hostname=localhost
usagestats.redis.port=6379
spring.jackson.serialization.INDENT_OUTPUT=true
@ -13,7 +12,7 @@ prod.usagestatsImpalaDB=openaire_prod_usage_stats
compression.max_number_of_records=100
download.folder=/Users/dpie/Desktop/DownloadSushiLite
sushi-lite.server=http://localhost:8080/usagestats
server.context-path=/usagestats_r5
server.servlet.context-path.=/usagestats_r5
server.port=8080
#spring.datasource.testWhileIdle = true
#spring.datasource.timeBetweenEvictionRunsMillis = 60000