From 5eb0717179334e92bcc7a14cd729306b6fc86510 Mon Sep 17 00:00:00 2001 From: "panagiotis.kanakakis" Date: Thu, 8 Feb 2018 14:43:47 +0000 Subject: [PATCH] Changes for new api. --- .../service/controllers/MonitorApi.java | 18 +++---- .../service/controllers/MonitorApiImpl.java | 20 +++++--- .../controllers/RepositoryApiImpl.java | 50 +++++++++---------- .../service/controllers/ValidatorApiImpl.java | 11 +++- .../repo/manager/service/utils/Converter.java | 20 ++++---- .../manager/service/utils/RequestFilter.java | 9 ++++ 6 files changed, 71 insertions(+), 57 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/MonitorApi.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/MonitorApi.java index 6c25b83..3d2fe70 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/controllers/MonitorApi.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/MonitorApi.java @@ -13,17 +13,17 @@ import org.springframework.web.bind.annotation.*; @Api(description = "Monitor API", tags = {"monitor"}) public interface MonitorApi { - @RequestMapping(value = "/getJobsOfUser" , method = RequestMethod.GET,consumes = MediaType.APPLICATION_JSON_VALUE, + @RequestMapping(value = "/getJobsOfUser" , method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody - JobsOfUser getJobsOfUser(@RequestBody String user, - @RequestBody String jobType, - @RequestBody String offset, - @RequestBody String limit, - @RequestBody String dateFrom, - @RequestBody String dateTo, - @RequestBody String validationStatus, - @RequestBody String includeJobsTotal) throws JSONException, ValidatorServiceException; + JobsOfUser getJobsOfUser(@RequestParam String user, + @RequestParam String jobType, + @RequestParam String offset, + @RequestParam String limit, + @RequestParam String dateFrom, + @RequestParam String dateTo, + @RequestParam String validationStatus, + @RequestParam String includeJobsTotal) throws JSONException, ValidatorServiceException; @RequestMapping(value = "/getJobsOfUserPerValidationStatus" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/MonitorApiImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/MonitorApiImpl.java index 1a761ee..db9c3f1 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/controllers/MonitorApiImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/MonitorApiImpl.java @@ -10,7 +10,11 @@ import io.swagger.annotations.ApiParam; import org.apache.log4j.Logger; import org.json.JSONException; import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; + import javax.annotation.Resource; +import java.util.Date; @Component public class MonitorApiImpl implements MonitorApi { @@ -35,14 +39,14 @@ public class MonitorApiImpl implements MonitorApi { .getLogger(MonitorApiImpl.class); @Override - public JobsOfUser getJobsOfUser(@ApiParam(value = "User email", required = true) String user, - @ApiParam(value = "Equals to filter job type on validation history page", required = true) String jobType, - @ApiParam(value = "Page number", required = true) String offset, - @ApiParam(value = "Null value", required = true) String limit, - @ApiParam(value = "Null value", required = true) String dateFrom, - @ApiParam(value = "Null value", required = true) String dateTo, - @ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus, - @ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException { + public JobsOfUser getJobsOfUser(@RequestParam("user") @ApiParam(value = "User email", required = true) String user, + @RequestParam("jobType") @ApiParam(value = "Equals to filter job type on validation history page", required = true) String jobType, + @RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset, + @RequestParam(value = "limit", required = false, defaultValue = "10") @ApiParam(value = "Null value") String limit, + @RequestParam(value = "dateFrom", required = false, defaultValue = "2018-02-08") @ApiParam(value = "Null value") String dateFrom, + @RequestParam(value = "dateTo", required = false, defaultValue = "2018-02-08") @ApiParam(value = "Null value") String dateTo, + @RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus, + @RequestParam("includeJobsTotal") @ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException { LOGGER.debug("Getting jobs of user : " + user); LOGGER.debug(user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApiImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApiImpl.java index e2daf49..23a3690 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApiImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApiImpl.java @@ -150,6 +150,7 @@ public class RepositoryApiImpl implements RepositoryApi { LOGGER.debug("Getting repositories by country!"); int page = 0; int size = 100; + List resultSet = new ArrayList<>(); String countryCode = countriesMap.get(country); String filterKey = "UNKNOWN"; @@ -163,17 +164,12 @@ public class RepositoryApiImpl implements RepositoryApi { LOGGER.debug("Country code equals : " + countryCode); LOGGER.debug("Filter mode equals : " + filterKey); - UriComponents uriComponents = UriComponentsBuilder - .fromHttpUrl(baseAddress + "/ds/search/country/") - .path("/{page}/{size}/") - .queryParam("country", countryCode) - .queryParam("managed", managed) - .build().expand(page, size).encode(); + UriComponents uriComponents = searchDatasource(String.valueOf(page),String.valueOf(size)); + RequestFilter requestFilter = new RequestFilter(); + requestFilter.setCountry(countryCode); - String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); + String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); - - List resultSet = new ArrayList<>(); while (jsonArray.length() > 0 ) { List rep = Converter.jsonToRepositoryList(new JSONObject(rs)); @@ -181,13 +177,9 @@ public class RepositoryApiImpl implements RepositoryApi { resultSet.addAll(repos); page += 1; - uriComponents = UriComponentsBuilder - .fromHttpUrl(baseAddress + "/ds/search/country/") - .path("/{page}/{size}/") - .queryParam("country", countryCode) - .queryParam("managed", managed) - .build().expand(page, size).encode(); - rs = restTemplate.getForObject(uriComponents.toUri(), String.class); + uriComponents = searchDatasource(String.valueOf(page),String.valueOf(size)); + + rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); } for (Repository r : resultSet) @@ -207,7 +199,8 @@ public class RepositoryApiImpl implements RepositoryApi { List reps = new ArrayList<>(); for (Repository r : rs) { - if (r.getCollectedFrom().equals(mode)) + LOGGER.debug(r.getCollectedFrom()); + if (r.getCollectedFrom() != null && r.getCollectedFrom().equals(mode)) reps.add(r); } return reps; @@ -219,18 +212,11 @@ public class RepositoryApiImpl implements RepositoryApi { @PathVariable("size") String size) throws JSONException { LOGGER.debug("Retreiving repositories of user : " + userEmail ); - UriComponents uriComponents = UriComponentsBuilder - .fromHttpUrl(baseAddress + "/ds/search/") - .path("/{page}/{size}/") - .queryParam("requestSortBy","id") - .queryParam("order","ASCENDING") - .build().expand(page, size).encode(); - + UriComponents uriComponents = searchDatasource(page,size); RequestFilter requestFilter = new RequestFilter(); requestFilter.setRegisteredby(userEmail); - String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); - + LOGGER.debug(rs); List repos = Converter.jsonToRepositoryList(new JSONObject(rs)); for (Repository r : repos) this.getRepositoryInfo(r); @@ -305,7 +291,7 @@ public class RepositoryApiImpl implements RepositoryApi { .build().expand(id).encode(); String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); - return Converter.jsonToRepositoryInterfaceList(new JSONArray(rs)); + return Converter.jsonToRepositoryInterfaceList(new JSONObject(rs)); } @Override @@ -828,5 +814,15 @@ public class RepositoryApiImpl implements RepositoryApi { return null; } + private UriComponents searchDatasource(String page,String size){ + + return UriComponentsBuilder + .fromHttpUrl(baseAddress + "/ds/search/") + .path("/{page}/{size}/") + .queryParam("requestSortBy","id") + .queryParam("order","ASCENDING") + .build().expand(page, size).encode(); + } + } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApiImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApiImpl.java index f49a1d9..52912ba 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApiImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/ValidatorApiImpl.java @@ -13,11 +13,13 @@ import eu.dnetlib.repo.manager.shared.Constants; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import eu.dnetlib.api.functionality.ValidatorService; +import io.swagger.annotations.ApiParam; import org.apache.log4j.Logger; import org.json.JSONException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; import javax.annotation.PostConstruct; import javax.annotation.Resource; @@ -165,8 +167,13 @@ public class ValidatorApiImpl implements ValidatorApi{ } @Override - public List getStoredJobsNew(String user, String jobType, Integer offset, Integer limit, String dateFrom, - String dateTo, String validationStatus) throws ValidatorServiceException { + public List getStoredJobsNew(@RequestParam("user") @ApiParam(value = "User email", required = true) String user, + @RequestParam("jobType") @ApiParam(value = "Equals to filter job type on validation history page", required = true) String jobType, + @RequestParam("offset") @ApiParam(value = "Page number", required = true) Integer offset, + @RequestParam(value = "limit", required = false, defaultValue = "10") @ApiParam(value = "Null value") Integer limit, + @RequestParam(value = "dateFrom", required = false, defaultValue = "2018-02-08") @ApiParam(value = "Null value") String dateFrom, + @RequestParam(value = "dateTo", required = false, defaultValue = "2018-02-08") @ApiParam(value = "Null value") String dateTo, + @RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus) throws ValidatorServiceException { return getValidationService().getStoredJobsNew(user, jobType, offset, limit, dateFrom, dateTo, validationStatus); } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/utils/Converter.java b/src/main/java/eu/dnetlib/repo/manager/service/utils/Converter.java index 84d95fe..d87364b 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/utils/Converter.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/utils/Converter.java @@ -33,7 +33,7 @@ public class Converter { repository.setAggregator(datasource.get("aggregator").toString()); // repository.setCertificates(datasource.get("certificates").toString()); // repository.setCitationGuidelineUrl(datasource.get("citationguidelineurl").toString()); -// repository.setCollectedFrom( datasource.get("collectedfrom").toString()); + repository.setCollectedFrom( datasource.get("collectedfrom").toString()); repository.setContactEmail(datasource.get("contactemail").toString()); if(repository.getContactEmail().equals("null")) @@ -102,7 +102,7 @@ public class Converter { repository.setCountryCode(countryCode); - /* String collectedFrom = datasource.get("collectedfrom").toString(); + String collectedFrom = datasource.get("collectedfrom").toString(); //TODO check data consistency String type = "UNKNOWN"; if (collectedFrom.equalsIgnoreCase("openaire____::opendoar")) { @@ -111,11 +111,8 @@ public class Converter { type = "re3data"; } else if (collectedFrom.equalsIgnoreCase("infrastruct_::openaire")) { type = "journal"; - }*/ - -// repository.setDatasourceType(type); - - + } + repository.setDatasourceType(type); return repository; } @@ -160,9 +157,10 @@ public class Converter { return resultSet; } - public static List jsonToRepositoryInterfaceList(JSONArray rs) throws JSONException { + public static List jsonToRepositoryInterfaceList(JSONObject json) throws JSONException { List resultSet = new ArrayList<>(); + JSONArray rs = json.getJSONArray("api"); for(int i=0;i extraFields = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - JSONArray apiparams = repositoryInterfaceObject.getJSONArray("apiparam"); + JSONArray apiparams = repositoryInterfaceObject.getJSONArray("apiParams"); for(int i=0;i