argos/dmp-backend/src/main/java/eu/eudat/controllers/Organisations.java

52 lines
2.4 KiB
Java
Raw Normal View History

2017-12-15 00:01:26 +01:00
package eu.eudat.controllers;
2017-10-06 19:20:05 +02:00
import java.util.List;
import java.util.Map;
2017-10-12 14:02:41 +02:00
2017-12-19 15:09:49 +01:00
import eu.eudat.models.external.OrganisationsExternalSourcesModel;
import eu.eudat.models.helpers.responses.ResponseItem;
2018-01-04 10:32:39 +01:00
import eu.eudat.services.ApiContext;
2018-01-23 16:21:38 +01:00
import eu.eudat.types.ApiMessageCode;
2017-10-06 19:20:05 +02:00
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
2017-12-15 00:01:26 +01:00
import eu.eudat.proxy.config.exceptions.HugeResultSet;
import eu.eudat.proxy.config.exceptions.NoURLFound;
2017-10-06 19:20:05 +02:00
@RestController
@CrossOrigin
2018-01-04 10:32:39 +01:00
public class Organisations extends BaseController{
@Autowired
public Organisations(ApiContext apiContext) {
super(apiContext);
}
2017-11-22 11:14:10 +01:00
@RequestMapping(method = RequestMethod.GET, value = { "/external/organisations" }, produces="application/json")
2018-01-22 08:41:31 +01:00
public @ResponseBody ResponseEntity<ResponseItem<OrganisationsExternalSourcesModel>> listExternalOrganisations(@RequestParam(value="query", required=false) String query ){
try {
2018-01-04 10:32:39 +01:00
List<Map<String,String>> remoteRepos = this.getApiContext().getRemoteFetcher().getOrganisations(query);
2017-12-19 15:09:49 +01:00
OrganisationsExternalSourcesModel projectsExternalSourcesModel = new OrganisationsExternalSourcesModel().fromExternalItem(remoteRepos);
2018-01-23 16:21:38 +01:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<OrganisationsExternalSourcesModel>().payload(projectsExternalSourcesModel).status(ApiMessageCode.SUCCESS_MESSAGE));
}
catch(NoURLFound ex) {
2018-01-23 16:21:38 +01:00
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<OrganisationsExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("External Url Not Found"));
}
catch(HugeResultSet ex) {
2018-01-23 16:21:38 +01:00
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<OrganisationsExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("Huge Result Set"));
2017-12-19 15:09:49 +01:00
}catch (Exception ex){
2018-01-23 16:21:38 +01:00
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<OrganisationsExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()));
}
}
2017-10-06 19:20:05 +02:00
}