1. Add swagger explanation for broker/validator paramaters

2. Change subscribe/unsubcribe methods of broker from GET to POST
This commit is contained in:
Panagiotis Kanakakis 2018-02-12 14:10:57 +00:00
parent a08eee988f
commit f62403a248
5 changed files with 39 additions and 30 deletions

View File

@ -19,7 +19,7 @@ import java.util.Map;
public interface BrokerApi {
@RequestMapping(value = "/getDatasourcesOfUser" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
DatasourcesBroker getDatasourcesOfUser(@RequestBody String params) throws BrokerException, JSONException;
DatasourcesBroker getDatasourcesOfUser(String user,String includeShared,String includeByOthers) throws BrokerException, JSONException;
@RequestMapping(value = "/getTopicsForDatasource/{datasourceName}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
List<BrowseEntry> getTopicsForDatasource(String datasourceName) throws BrokerException;
@ -36,13 +36,15 @@ public interface BrokerApi {
@RequestMapping(value = "/getSimpleSubscriptionsOfUser/{userEmail}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(String userEmail) throws BrokerException;
Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail) throws BrokerException;
@RequestMapping(value = "/subscribe" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/subscribe" , method = RequestMethod.POST,consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Subscription subscribe(@RequestBody OpenaireSubscription obj) throws BrokerException;
@RequestMapping(value = "/unsubscribe/{subscriptionId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/unsubscribe/{subscriptionId}" , method = RequestMethod.POST,consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
void unsubscribe(String subscriptionId) throws BrokerException;

View File

@ -7,6 +7,7 @@ import eu.dnetlib.repo.manager.shared.BrokerException;
import eu.dnetlib.repo.manager.shared.Term;
import eu.dnetlib.repo.manager.shared.Tuple;
import eu.dnetlib.repo.manager.shared.broker.*;
import io.swagger.annotations.ApiParam;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
@ -21,6 +22,7 @@ import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
@ -83,24 +85,22 @@ public class BrokerApiImpl implements BrokerApi {
@Override
public DatasourcesBroker getDatasourcesOfUser(String params) throws JSONException {
JSONObject json_params = new JSONObject(params);
public DatasourcesBroker getDatasourcesOfUser(@RequestParam("user") @ApiParam(value = "User email", required = true) String user,
@RequestParam("includeShared")
@ApiParam(value = "Include shared datasources", required = true) String includeShared,
@RequestParam("includeByOthers") @ApiParam(value = "Include datasources of other", required = true) String includeByOthers) throws JSONException {
DatasourcesBroker ret = new DatasourcesBroker();
String userEmail = json_params.getString("userEmail");
boolean includeShared = Boolean.parseBoolean( json_params.getString("includeShared") );
boolean includeByOthers = Boolean.parseBoolean( json_params.getString("includeByOthers") );
try {
ret.setDatasourcesOfUser(getDatasourcesOfUserType(getRepositoriesOfUser(userEmail)));
if (includeShared) {
ret.setDatasourcesOfUser(getDatasourcesOfUserType(getRepositoriesOfUser(user)));
if (Boolean.parseBoolean(includeShared)) {
//TODO whatever nikonas was saying
List<String> sharedDatasourceIds = new ArrayList<String>();
ret.setSharedDatasources(getDatasourcesOfUserType(getRepositoriesByIds(sharedDatasourceIds)));
}
if (includeByOthers) {
ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(userEmail)));
if (Boolean.parseBoolean(includeByOthers)) {
ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(user)));
}
} catch (BrokerException e) {
e.printStackTrace();
@ -251,18 +251,17 @@ public class BrokerApiImpl implements BrokerApi {
}
@Override
public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail) throws BrokerException {
public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser( String userEmail)
throws BrokerException {
final String service = "/subscriptions";
//build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
.queryParam("email", userEmail);
//create new template engine
LOGGER.debug(builder.build().encode().toUri());
ResponseEntity<Map<String, List<SimpleSubscriptionDesc>>> resp;
try {
//communicate with endpoint
resp = restTemplate.exchange(
builder.build().encode().toUri(),
HttpMethod.GET,

View File

@ -38,9 +38,10 @@ public class MonitorApiImpl implements MonitorApi {
@Override
public JobsOfUser getJobsOfUser(@RequestParam("user") @ApiParam(value = "User email", required = true) String user,
@RequestParam(value = "jobType", required = false) @ApiParam(value = "Equals to filter job type on validation history page") String jobType,
@RequestParam(value = "jobType", required = false)
@ApiParam(value = "Equals to filter job type on validation history page") 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 = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit,
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom,
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus,

View File

@ -45,8 +45,13 @@ public interface ValidatorApi {
@RequestMapping(value = "/getStoredJobsNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<StoredJob> getStoredJobsNew(String user, String jobType, Integer offset, Integer limit, String dateFrom,
String dateTo, String validationStatus) throws ValidatorServiceException;
List<StoredJob> getStoredJobsNew(String user,
String jobType,
String offset,
String limit,
String dateFrom,
String dateTo,
String validationStatus) throws ValidatorServiceException;
@RequestMapping(value = "/getStoredJobsTotalNumberNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)

View File

@ -168,13 +168,15 @@ public class ValidatorApiImpl implements ValidatorApi{
@Override
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);
@RequestParam(value = "jobType", required = false)
@ApiParam(value = "Equals to filter job type on validation history page") 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) @ApiParam(value = "Null value") String dateFrom,
@RequestParam(value = "dateTo", required = false) @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, Integer.parseInt(offset), Integer.parseInt(limit), dateFrom, dateTo, validationStatus);
}
@Override