added sushilite service
This commit is contained in:
parent
5a38abef64
commit
db481624d8
|
@ -0,0 +1,30 @@
|
|||
package eu.dnetlib.repo.manager.service.controllers;
|
||||
|
||||
import eu.dnetlib.usagestats.sushilite.ReportResponseWrapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.json.JSONException;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/sushilite")
|
||||
@Api(description = "Sushi-Lite API", tags = {"sushilite"})
|
||||
public interface SushiliteApi {
|
||||
|
||||
@RequestMapping(value = "/getReportResults", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
ReportResponseWrapper getReportResults(String Report,
|
||||
String Release,
|
||||
String RequestorID,
|
||||
String BeginDate,
|
||||
String EndDate,
|
||||
String RepositoryIdentifier,
|
||||
String ItemIdentifier,
|
||||
String ItemDataType,
|
||||
String Granularity,
|
||||
String Pretty) throws JSONException;
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package eu.dnetlib.repo.manager.service.controllers;
|
||||
|
||||
import eu.dnetlib.usagestats.sushilite.ReportResponseWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
public class SushiliteApiImpl implements SushiliteApi {
|
||||
|
||||
|
||||
@Value("${services.repomanager.usagestats.sushiliteEndoint}")
|
||||
private String usagestatsSushiliteEndpoint;
|
||||
|
||||
@Autowired
|
||||
private EmailUtils emailUtils;
|
||||
|
||||
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
|
||||
.getLogger(SushiliteApiImpl.class);
|
||||
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasRole('ROLE_USER')")
|
||||
public ReportResponseWrapper getReportResults(@RequestParam(value = "Report") String Report,
|
||||
@RequestParam(value = "Release",defaultValue="4") String Release,
|
||||
@RequestParam(value = "RequestorID",required=false) String RequestorID,
|
||||
@RequestParam(value = "BeginDate",required=false) String BeginDate,
|
||||
@RequestParam(value = "EndDate",required=false) String EndDate,
|
||||
@RequestParam(value = "RepositoryIdentifier") String RepositoryIdentifier,
|
||||
@RequestParam(value = "ItemIdentifier",required=false) String ItemIdentifier,
|
||||
@RequestParam(value = "ItemDataType",required=false) String ItemDataType,
|
||||
@RequestParam(value = "Granularity") String Granularity,
|
||||
@RequestParam(value = "Pretty",required=false) String Pretty) {
|
||||
|
||||
//build the uri params
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usagestatsSushiliteEndpoint + "GetReport/")
|
||||
.queryParam("Report", Report)
|
||||
.queryParam("Release", Release)
|
||||
.queryParam("RequestorID", RequestorID)
|
||||
.queryParam("BeginDate", BeginDate)
|
||||
.queryParam("EndDate", EndDate)
|
||||
.queryParam("RepositoryIdentifier", RepositoryIdentifier)
|
||||
.queryParam("ItemIdentifier", ItemIdentifier)
|
||||
.queryParam("ItemDataType", ItemDataType)
|
||||
.queryParam("Granularity", Granularity)
|
||||
.queryParam("Pretty", Pretty);
|
||||
|
||||
//create new template engine
|
||||
RestTemplate template = new RestTemplate();
|
||||
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
||||
ResponseEntity<ReportResponseWrapper> resp;
|
||||
try {
|
||||
//communicate with endpoint
|
||||
resp = template.exchange(
|
||||
builder.build().encode().toUri(),
|
||||
HttpMethod.GET,
|
||||
null,
|
||||
new ParameterizedTypeReference<ReportResponseWrapper>() {
|
||||
});
|
||||
} catch (RestClientException e) {
|
||||
LOGGER.debug("Exception on getReportResults" , e);
|
||||
emailUtils.reportException(e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
return resp.getBody();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue