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

48 lines
2.3 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
2018-06-27 12:29:21 +02:00
import eu.eudat.models.data.external.OrganisationsExternalSourcesModel;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.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;
2018-02-16 11:34:02 +01:00
import org.springframework.web.bind.annotation.*;
2017-10-06 19:20:05 +02:00
2018-02-16 11:34:02 +01:00
import java.util.List;
import java.util.Map;
2017-10-06 19:20:05 +02:00
@RestController
@CrossOrigin
2018-02-09 16:54:41 +01:00
@RequestMapping(value = {"/api"})
2018-02-16 11:34:02 +01:00
public class Organisations extends BaseController {
@Autowired
public Organisations(ApiContext apiContext) {
super(apiContext);
}
@RequestMapping(method = RequestMethod.GET, value = {"/external/organisations"}, produces = "application/json")
public @ResponseBody
2018-05-28 11:50:42 +02:00
ResponseEntity<ResponseItem<OrganisationsExternalSourcesModel>> listExternalOrganisations(
@RequestParam(value = "query", required = false) String query,@RequestParam(value = "type", required = false) String type
) {
2018-02-16 11:34:02 +01:00
try {
2018-05-28 11:50:42 +02:00
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getOrganisations(query,type);
2018-02-16 11:34:02 +01:00
OrganisationsExternalSourcesModel projectsExternalSourcesModel = new OrganisationsExternalSourcesModel().fromExternalItem(remoteRepos);
2018-07-24 13:19:52 +02:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<OrganisationsExternalSourcesModel>().payload(projectsExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE));
2018-02-16 11:34:02 +01:00
} catch (NoURLFound ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<OrganisationsExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("External Url Not Found"));
} catch (HugeResultSet ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<OrganisationsExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("Huge Result Set"));
} catch (Exception ex) {
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
}