Add suchilite-R5 support.
This commit is contained in:
parent
7cab17c133
commit
97e85c2a75
Binary file not shown.
11
pom.xml
11
pom.xml
|
@ -118,6 +118,13 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>eu.dnetlib</groupId>
|
||||
<artifactId>dnet-openaire-usage-stats-sushilite-r5</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/libs/openaire-usage-stats-sushilite-r5-1.0.0.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>eu.dnetlib</groupId>
|
||||
<artifactId>dnet-openaire-usage-stats-sushilite</artifactId>
|
||||
|
@ -421,6 +428,10 @@
|
|||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>libs</id>
|
||||
<url>file:///${project.basedir}/libs</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package eu.dnetlib.repo.manager.controllers;
|
||||
|
||||
import eu.dnetlib.repo.manager.service.sushilite.SushiliteR5Service;
|
||||
import eu.dnetlib.repo.manager.service.sushilite.SushiliteR5ServiceImpl;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.json.JSONException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/sushiliteR5")
|
||||
@Api(description = "Sushi-Lite R5 API", tags = {"sushiliteR5"})
|
||||
public class SushiliteR5Controller {
|
||||
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SushiliteR5Controller.class);
|
||||
|
||||
|
||||
@Autowired
|
||||
private SushiliteR5ServiceImpl sushiliteR5Service;
|
||||
|
||||
@RequestMapping(value = "/getReportResults", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('REGISTERED_USER')")
|
||||
public ResponseEntity<?> getReportResults(@RequestParam(value = "Report") String report,
|
||||
@RequestParam(value = "Release", required=false, defaultValue="5") String release,
|
||||
@RequestParam(value = "RequestorID",required=false, defaultValue="anonymous") String requestorID,
|
||||
@RequestParam(value = "BeginDate",required=false, defaultValue="") String beginDate,
|
||||
@RequestParam(value = "EndDate",required=false, defaultValue="") String endDate,
|
||||
@RequestParam(value = "RepositoryIdentifier", required=false, defaultValue="") String repositoryIdentifier,
|
||||
@RequestParam(value = "DatasetIdentifier", required=false, defaultValue="") String datasetIdentifier,
|
||||
@RequestParam(value = "ItemIdentifier",required=false, defaultValue="") String itemIdentifier,
|
||||
@RequestParam(value = "MetricType",required=false) List<String> metricTypes,
|
||||
@RequestParam(value = "dataType",required=false, defaultValue="") String dataType,
|
||||
@RequestParam(value = "Granularity", required = false, defaultValue ="Monthly") String granularity,
|
||||
@RequestParam(value = "Pretty",required=false, defaultValue="") String pretty) {
|
||||
|
||||
try {
|
||||
return sushiliteR5Service.getReportResults(report, release, requestorID, beginDate, endDate, repositoryIdentifier, datasetIdentifier, itemIdentifier, metricTypes, dataType, granularity, pretty);
|
||||
} catch (JSONException je) {
|
||||
logger.error("", je);
|
||||
return ResponseEntity.internalServerError().build();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package eu.dnetlib.repo.manager.service.sushilite;
|
||||
|
||||
import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper;
|
||||
import org.json.JSONException;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SushiliteR5Service {
|
||||
|
||||
|
||||
ResponseEntity<?> getReportResults(String Report,
|
||||
String release,
|
||||
String requestorID,
|
||||
String beginDate,
|
||||
String endDate,
|
||||
String repositoryIdentifier,
|
||||
String datasetIdentifier,
|
||||
String itemIdentifier,
|
||||
List<String> metricTypes,
|
||||
String dataType,
|
||||
String granularity,
|
||||
String pretty) throws JSONException;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
package eu.dnetlib.repo.manager.service.sushilite;
|
||||
|
||||
//import eu.dnetlib.usagestats.sushilite.domain.COUNTER_Item_Report;
|
||||
import org.json.JSONException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
@Service("sushiliteR5Service")
|
||||
public class SushiliteR5ServiceImpl implements SushiliteR5Service {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SushiliteR5ServiceImpl.class);
|
||||
|
||||
|
||||
@Value("${services.provide.usagestats.sushiliteR5Endpoint}")
|
||||
private String usagestatsSushiliteR5Endpoint;
|
||||
|
||||
|
||||
public ResponseEntity<?> getReportResults(String report,
|
||||
String release,
|
||||
String requestorID,
|
||||
String beginDate,
|
||||
String endDate,
|
||||
String repositoryIdentifier,
|
||||
String datasetIdentifier,
|
||||
String itemIdentifier,
|
||||
List<String> metricTypes,
|
||||
String dataType,
|
||||
String granularity,
|
||||
String pretty) throws JSONException
|
||||
{
|
||||
//build the uri params
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usagestatsSushiliteR5Endpoint + "reports/" + report.toLowerCase())
|
||||
.queryParam("Report", report)
|
||||
.queryParam("Release", release)
|
||||
.queryParam("RequestorID", requestorID)
|
||||
.queryParam("BeginDate", beginDate)
|
||||
.queryParam("EndDate", endDate)
|
||||
.queryParam("RepositoryIdentifier", repositoryIdentifier)
|
||||
.queryParam("DatasetIdentifier", datasetIdentifier)
|
||||
.queryParam("ItemIdentifier", itemIdentifier);
|
||||
if ( metricTypes != null ) {
|
||||
for ( String metricType : metricTypes )
|
||||
builder.queryParam("MetricType", metricType);
|
||||
}
|
||||
builder.queryParam("DataType", dataType)
|
||||
.queryParam("Granularity", granularity)
|
||||
.queryParam("Pretty", pretty);
|
||||
|
||||
URI uri = builder.build().encode().toUri();
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
||||
|
||||
ResponseEntity<?> resp;
|
||||
try {
|
||||
resp = restTemplate.exchange(
|
||||
uri,
|
||||
HttpMethod.GET,
|
||||
null,
|
||||
new ParameterizedTypeReference<Object>() {});
|
||||
} catch (RestClientException rce) {
|
||||
String errorMsg = "Failed to get a response from sushiliteR5!";
|
||||
logger.error(errorMsg + " URI was:\n" + uri + "\n" + rce.getMessage());
|
||||
return ResponseEntity.internalServerError().body(errorMsg);
|
||||
}
|
||||
|
||||
HttpStatus httpStatus = resp.getStatusCode();
|
||||
if ( httpStatus != HttpStatus.OK ) {
|
||||
logger.warn("Sushi cannot give us data! Responded status: " + httpStatus);
|
||||
return ResponseEntity.status(httpStatus).build();
|
||||
}
|
||||
|
||||
Object reportResult = resp.getBody();
|
||||
if ( reportResult == null ) {
|
||||
logger.error("The \"reportResponseWrapper\" for sushi was null!");
|
||||
return ResponseEntity.internalServerError().build();
|
||||
}
|
||||
|
||||
logger.trace(reportResult.toString());
|
||||
|
||||
return ResponseEntity.ok(reportResult);
|
||||
|
||||
|
||||
|
||||
// TODO - Depending on the "report-type", map the "object" to the right Report-type class.
|
||||
// TODO - This will be useful, in case we add preprocessing steps, like pagination.
|
||||
/* try {
|
||||
switch ( report ) {
|
||||
case "PR":
|
||||
|
||||
break;
|
||||
case "PR_P1":
|
||||
|
||||
break;
|
||||
case "IR":
|
||||
COUNTER_Item_Report counterItemReport = (COUNTER_Item_Report) resp.getBody();
|
||||
if ( counterItemReport == null ) {
|
||||
logger.error("The \"reportResponseWrapper\" for sushi was null!");
|
||||
return ResponseEntity.internalServerError().build();
|
||||
} else {
|
||||
logger.debug(counterItemReport.toString());
|
||||
return ResponseEntity.ok(counterItemReport);
|
||||
}
|
||||
case "DSR":
|
||||
|
||||
break;
|
||||
default:
|
||||
String errorMsg = "Invalid report type was given: " + report;
|
||||
logger.error(errorMsg);
|
||||
return ResponseEntity.badRequest().body(errorMsg);
|
||||
}
|
||||
} catch (ClassCastException cce) {
|
||||
logger.error("The report object could not be mapped to the repo-type-object of \"" + report + "\"!", cce);
|
||||
return ResponseEntity.internalServerError().build();
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue