Changes for new api.
This commit is contained in:
parent
cb360ec0d8
commit
5eb0717179
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -150,6 +150,7 @@ public class RepositoryApiImpl implements RepositoryApi {
|
|||
LOGGER.debug("Getting repositories by country!");
|
||||
int page = 0;
|
||||
int size = 100;
|
||||
List<Repository> 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<Repository> resultSet = new ArrayList<>();
|
||||
while (jsonArray.length() > 0 ) {
|
||||
List<Repository> 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<Repository> 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<Repository> 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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<StoredJob> getStoredJobsNew(String user, String jobType, Integer offset, Integer limit, String dateFrom,
|
||||
String dateTo, String validationStatus) throws ValidatorServiceException {
|
||||
public List<StoredJob> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<RepositoryInterface> jsonToRepositoryInterfaceList(JSONArray rs) throws JSONException {
|
||||
public static List<RepositoryInterface> jsonToRepositoryInterfaceList(JSONObject json) throws JSONException {
|
||||
|
||||
List<RepositoryInterface> resultSet = new ArrayList<>();
|
||||
JSONArray rs = json.getJSONArray("api");
|
||||
for(int i=0;i<rs.length();i++)
|
||||
resultSet.add(jsonToRepositoryInterfaceObject( rs.getJSONObject(i)) );
|
||||
return resultSet;
|
||||
|
@ -175,11 +173,11 @@ public class Converter {
|
|||
repositoryInterface.setBaseUrl(repositoryInterfaceObject.get("baseurl").toString());
|
||||
repositoryInterface.setContentDescription(repositoryInterfaceObject.get("contentdescription").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.setTypology(repositoryInterfaceObject.get("typology").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.setCompliance(repositoryInterfaceObject.get("compatibility").toString());
|
||||
|
||||
|
@ -187,7 +185,7 @@ public class Converter {
|
|||
Map<String, String> extraFields = new HashMap<>();
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JSONArray apiparams = repositoryInterfaceObject.getJSONArray("apiparam");
|
||||
JSONArray apiparams = repositoryInterfaceObject.getJSONArray("apiParams");
|
||||
|
||||
for(int i=0;i<apiparams.length();i++)
|
||||
accessParams.put(apiparams.getJSONObject(i).getString("param"),apiparams.getJSONObject(i).getString("value"));
|
||||
|
|
|
@ -5,6 +5,7 @@ public class RequestFilter{
|
|||
|
||||
private String registeredby = "";
|
||||
private String typology = "";
|
||||
private String country = "";
|
||||
|
||||
|
||||
public RequestFilter() {
|
||||
|
@ -26,4 +27,12 @@ public class RequestFilter{
|
|||
public void setRegisteredby(String registeredby) {
|
||||
this.registeredby = registeredby;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue