Changes for new api.

This commit is contained in:
Panagiotis Kanakakis 2018-02-08 14:43:47 +00:00
parent cb360ec0d8
commit 5eb0717179
6 changed files with 71 additions and 57 deletions

View File

@ -13,17 +13,17 @@ import org.springframework.web.bind.annotation.*;
@Api(description = "Monitor API", tags = {"monitor"}) @Api(description = "Monitor API", tags = {"monitor"})
public interface MonitorApi { 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) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
JobsOfUser getJobsOfUser(@RequestBody String user, JobsOfUser getJobsOfUser(@RequestParam String user,
@RequestBody String jobType, @RequestParam String jobType,
@RequestBody String offset, @RequestParam String offset,
@RequestBody String limit, @RequestParam String limit,
@RequestBody String dateFrom, @RequestParam String dateFrom,
@RequestBody String dateTo, @RequestParam String dateTo,
@RequestBody String validationStatus, @RequestParam String validationStatus,
@RequestBody String includeJobsTotal) throws JSONException, ValidatorServiceException; @RequestParam String includeJobsTotal) throws JSONException, ValidatorServiceException;
@RequestMapping(value = "/getJobsOfUserPerValidationStatus" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/getJobsOfUserPerValidationStatus" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody

View File

@ -10,7 +10,11 @@ import io.swagger.annotations.ApiParam;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.json.JSONException; import org.json.JSONException;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date;
@Component @Component
public class MonitorApiImpl implements MonitorApi { public class MonitorApiImpl implements MonitorApi {
@ -35,14 +39,14 @@ public class MonitorApiImpl implements MonitorApi {
.getLogger(MonitorApiImpl.class); .getLogger(MonitorApiImpl.class);
@Override @Override
public JobsOfUser getJobsOfUser(@ApiParam(value = "User email", required = true) String user, public JobsOfUser getJobsOfUser(@RequestParam("user") @ApiParam(value = "User email", required = true) String user,
@ApiParam(value = "Equals to filter job type on validation history page", required = true) String jobType, @RequestParam("jobType") @ApiParam(value = "Equals to filter job type on validation history page", required = true) String jobType,
@ApiParam(value = "Page number", required = true) String offset, @RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset,
@ApiParam(value = "Null value", required = true) String limit, @RequestParam(value = "limit", required = false, defaultValue = "10") @ApiParam(value = "Null value") String limit,
@ApiParam(value = "Null value", required = true) String dateFrom, @RequestParam(value = "dateFrom", required = false, defaultValue = "2018-02-08") @ApiParam(value = "Null value") String dateFrom,
@ApiParam(value = "Null value", required = true) String dateTo, @RequestParam(value = "dateTo", required = false, defaultValue = "2018-02-08") @ApiParam(value = "Null value") String dateTo,
@ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus, @RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus,
@ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException { @RequestParam("includeJobsTotal") @ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException {
LOGGER.debug("Getting jobs of user : " + user); LOGGER.debug("Getting jobs of user : " + user);
LOGGER.debug(user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal); LOGGER.debug(user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal);

View File

@ -150,6 +150,7 @@ public class RepositoryApiImpl implements RepositoryApi {
LOGGER.debug("Getting repositories by country!"); LOGGER.debug("Getting repositories by country!");
int page = 0; int page = 0;
int size = 100; int size = 100;
List<Repository> resultSet = new ArrayList<>();
String countryCode = countriesMap.get(country); String countryCode = countriesMap.get(country);
String filterKey = "UNKNOWN"; String filterKey = "UNKNOWN";
@ -163,17 +164,12 @@ public class RepositoryApiImpl implements RepositoryApi {
LOGGER.debug("Country code equals : " + countryCode); LOGGER.debug("Country code equals : " + countryCode);
LOGGER.debug("Filter mode equals : " + filterKey); LOGGER.debug("Filter mode equals : " + filterKey);
UriComponents uriComponents = UriComponentsBuilder UriComponents uriComponents = searchDatasource(String.valueOf(page),String.valueOf(size));
.fromHttpUrl(baseAddress + "/ds/search/country/") RequestFilter requestFilter = new RequestFilter();
.path("/{page}/{size}/") requestFilter.setCountry(countryCode);
.queryParam("country", countryCode)
.queryParam("managed", managed)
.build().expand(page, size).encode();
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"); JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
List<Repository> resultSet = new ArrayList<>();
while (jsonArray.length() > 0 ) { while (jsonArray.length() > 0 ) {
List<Repository> rep = Converter.jsonToRepositoryList(new JSONObject(rs)); List<Repository> rep = Converter.jsonToRepositoryList(new JSONObject(rs));
@ -181,13 +177,9 @@ public class RepositoryApiImpl implements RepositoryApi {
resultSet.addAll(repos); resultSet.addAll(repos);
page += 1; page += 1;
uriComponents = UriComponentsBuilder uriComponents = searchDatasource(String.valueOf(page),String.valueOf(size));
.fromHttpUrl(baseAddress + "/ds/search/country/")
.path("/{page}/{size}/") rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
.queryParam("country", countryCode)
.queryParam("managed", managed)
.build().expand(page, size).encode();
rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
} }
for (Repository r : resultSet) for (Repository r : resultSet)
@ -207,7 +199,8 @@ public class RepositoryApiImpl implements RepositoryApi {
List<Repository> reps = new ArrayList<>(); List<Repository> reps = new ArrayList<>();
for (Repository r : rs) { for (Repository r : rs) {
if (r.getCollectedFrom().equals(mode)) LOGGER.debug(r.getCollectedFrom());
if (r.getCollectedFrom() != null && r.getCollectedFrom().equals(mode))
reps.add(r); reps.add(r);
} }
return reps; return reps;
@ -219,18 +212,11 @@ public class RepositoryApiImpl implements RepositoryApi {
@PathVariable("size") String size) throws JSONException { @PathVariable("size") String size) throws JSONException {
LOGGER.debug("Retreiving repositories of user : " + userEmail ); LOGGER.debug("Retreiving repositories of user : " + userEmail );
UriComponents uriComponents = UriComponentsBuilder UriComponents uriComponents = searchDatasource(page,size);
.fromHttpUrl(baseAddress + "/ds/search/")
.path("/{page}/{size}/")
.queryParam("requestSortBy","id")
.queryParam("order","ASCENDING")
.build().expand(page, size).encode();
RequestFilter requestFilter = new RequestFilter(); RequestFilter requestFilter = new RequestFilter();
requestFilter.setRegisteredby(userEmail); requestFilter.setRegisteredby(userEmail);
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
LOGGER.debug(rs);
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs)); List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
for (Repository r : repos) for (Repository r : repos)
this.getRepositoryInfo(r); this.getRepositoryInfo(r);
@ -305,7 +291,7 @@ public class RepositoryApiImpl implements RepositoryApi {
.build().expand(id).encode(); .build().expand(id).encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
return Converter.jsonToRepositoryInterfaceList(new JSONArray(rs)); return Converter.jsonToRepositoryInterfaceList(new JSONObject(rs));
} }
@Override @Override
@ -828,5 +814,15 @@ public class RepositoryApiImpl implements RepositoryApi {
return null; 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();
}
} }

View File

@ -13,11 +13,13 @@ import eu.dnetlib.repo.manager.shared.Constants;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import eu.dnetlib.api.functionality.ValidatorService; import eu.dnetlib.api.functionality.ValidatorService;
import io.swagger.annotations.ApiParam;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.json.JSONException; import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -165,8 +167,13 @@ public class ValidatorApiImpl implements ValidatorApi{
} }
@Override @Override
public List<StoredJob> getStoredJobsNew(String user, String jobType, Integer offset, Integer limit, String dateFrom, public List<StoredJob> getStoredJobsNew(@RequestParam("user") @ApiParam(value = "User email", required = true) String user,
String dateTo, String validationStatus) throws ValidatorServiceException { @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); return getValidationService().getStoredJobsNew(user, jobType, offset, limit, dateFrom, dateTo, validationStatus);
} }

View File

@ -33,7 +33,7 @@ public class Converter {
repository.setAggregator(datasource.get("aggregator").toString()); repository.setAggregator(datasource.get("aggregator").toString());
// repository.setCertificates(datasource.get("certificates").toString()); // repository.setCertificates(datasource.get("certificates").toString());
// repository.setCitationGuidelineUrl(datasource.get("citationguidelineurl").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()); repository.setContactEmail(datasource.get("contactemail").toString());
if(repository.getContactEmail().equals("null")) if(repository.getContactEmail().equals("null"))
@ -102,7 +102,7 @@ public class Converter {
repository.setCountryCode(countryCode); repository.setCountryCode(countryCode);
/* String collectedFrom = datasource.get("collectedfrom").toString(); String collectedFrom = datasource.get("collectedfrom").toString();
//TODO check data consistency //TODO check data consistency
String type = "UNKNOWN"; String type = "UNKNOWN";
if (collectedFrom.equalsIgnoreCase("openaire____::opendoar")) { if (collectedFrom.equalsIgnoreCase("openaire____::opendoar")) {
@ -111,11 +111,8 @@ public class Converter {
type = "re3data"; type = "re3data";
} else if (collectedFrom.equalsIgnoreCase("infrastruct_::openaire")) { } else if (collectedFrom.equalsIgnoreCase("infrastruct_::openaire")) {
type = "journal"; type = "journal";
}*/ }
repository.setDatasourceType(type);
// repository.setDatasourceType(type);
return repository; return repository;
} }
@ -160,9 +157,10 @@ public class Converter {
return resultSet; return resultSet;
} }
public static List<RepositoryInterface> jsonToRepositoryInterfaceList(JSONArray rs) throws JSONException { public static List<RepositoryInterface> jsonToRepositoryInterfaceList(JSONObject json) throws JSONException {
List<RepositoryInterface> resultSet = new ArrayList<>(); List<RepositoryInterface> resultSet = new ArrayList<>();
JSONArray rs = json.getJSONArray("api");
for(int i=0;i<rs.length();i++) for(int i=0;i<rs.length();i++)
resultSet.add(jsonToRepositoryInterfaceObject( rs.getJSONObject(i)) ); resultSet.add(jsonToRepositoryInterfaceObject( rs.getJSONObject(i)) );
return resultSet; return resultSet;
@ -175,11 +173,11 @@ public class Converter {
repositoryInterface.setBaseUrl(repositoryInterfaceObject.get("baseurl").toString()); repositoryInterface.setBaseUrl(repositoryInterfaceObject.get("baseurl").toString());
repositoryInterface.setContentDescription(repositoryInterfaceObject.get("contentdescription").toString()); repositoryInterface.setContentDescription(repositoryInterfaceObject.get("contentdescription").toString());
repositoryInterface.setId(repositoryInterfaceObject.get("id").toString()); repositoryInterface.setId(repositoryInterfaceObject.get("id").toString());
repositoryInterface.setMetadataIdentifierPath(repositoryInterfaceObject.get("metadataIdentifierPath").toString()); // repositoryInterface.setMetadataIdentifierPath(repositoryInterfaceObject.get("metadataIdentifierPath").toString());
repositoryInterface.setAccessProtocol(repositoryInterfaceObject.get("protocol").toString()); repositoryInterface.setAccessProtocol(repositoryInterfaceObject.get("protocol").toString());
repositoryInterface.setTypology(repositoryInterfaceObject.get("typology").toString()); repositoryInterface.setTypology(repositoryInterfaceObject.get("typology").toString());
repositoryInterface.setDesiredCompatibilityLevel(repositoryInterfaceObject.get("compatibility").toString()); repositoryInterface.setDesiredCompatibilityLevel(repositoryInterfaceObject.get("compatibility").toString());
repositoryInterface.setActive(Boolean.parseBoolean(repositoryInterfaceObject.get("active").toString())); //repositoryInterface.setActive(Boolean.parseBoolean(repositoryInterfaceObject.get("active").toString()));
repositoryInterface.setRemovable(Boolean.parseBoolean(repositoryInterfaceObject.get("removable").toString())); repositoryInterface.setRemovable(Boolean.parseBoolean(repositoryInterfaceObject.get("removable").toString()));
repositoryInterface.setCompliance(repositoryInterfaceObject.get("compatibility").toString()); repositoryInterface.setCompliance(repositoryInterfaceObject.get("compatibility").toString());
@ -187,7 +185,7 @@ public class Converter {
Map<String, String> extraFields = new HashMap<>(); Map<String, String> extraFields = new HashMap<>();
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JSONArray apiparams = repositoryInterfaceObject.getJSONArray("apiparam"); JSONArray apiparams = repositoryInterfaceObject.getJSONArray("apiParams");
for(int i=0;i<apiparams.length();i++) for(int i=0;i<apiparams.length();i++)
accessParams.put(apiparams.getJSONObject(i).getString("param"),apiparams.getJSONObject(i).getString("value")); accessParams.put(apiparams.getJSONObject(i).getString("param"),apiparams.getJSONObject(i).getString("value"));

View File

@ -5,6 +5,7 @@ public class RequestFilter{
private String registeredby = ""; private String registeredby = "";
private String typology = ""; private String typology = "";
private String country = "";
public RequestFilter() { public RequestFilter() {
@ -26,4 +27,12 @@ public class RequestFilter{
public void setRegisteredby(String registeredby) { public void setRegisteredby(String registeredby) {
this.registeredby = registeredby; this.registeredby = registeredby;
} }
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
} }