You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
2.4 KiB
Java
48 lines
2.4 KiB
Java
package eu.eudat.controllers;
|
|
|
|
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;
|
|
import eu.eudat.types.ApiMessageCode;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
@CrossOrigin
|
|
@RequestMapping(value = {"/api"})
|
|
public class Organisations extends BaseController {
|
|
|
|
@Autowired
|
|
public Organisations(ApiContext apiContext) {
|
|
super(apiContext);
|
|
}
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = {"/external/organisations"}, produces = "application/json")
|
|
public @ResponseBody
|
|
ResponseEntity<ResponseItem<OrganisationsExternalSourcesModel>> listExternalOrganisations(
|
|
@RequestParam(value = "query", required = false) String query,@RequestParam(value = "type", required = false) String type
|
|
) {
|
|
try {
|
|
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getOrganisations(query,type);
|
|
OrganisationsExternalSourcesModel projectsExternalSourcesModel = new OrganisationsExternalSourcesModel().fromExternalItem(remoteRepos);
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<OrganisationsExternalSourcesModel>().payload(projectsExternalSourcesModel).status(ApiMessageCode.SUCCESS_MESSAGE));
|
|
} 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()));
|
|
}
|
|
}
|
|
|
|
}
|
|
|