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

48 lines
2.0 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-17 13:45:11 +02:00
2018-01-17 16:06:35 +01:00
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 DataRepositories extends BaseController{
@Autowired
public DataRepositories(ApiContext apiContext) {
super(apiContext);
}
2017-11-22 11:14:10 +01:00
@RequestMapping(method = RequestMethod.GET, value = { "/external/datarepos" }, produces="application/json")
2018-01-22 08:41:31 +01:00
public @ResponseBody ResponseEntity<ResponseItem<List<Map<String,String>>>> listExternalDataRepositories(@RequestParam(value="query", required=false) String query ){
try {
2018-01-04 10:32:39 +01:00
List<Map<String,String>> remoteRepos = this.getApiContext().getRemoteFetcher().getRepositories(query);
2018-01-23 16:21:38 +01:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Map<String,String>>>().status(ApiMessageCode.NO_MESSAGE).payload(remoteRepos));
}
catch(NoURLFound ex) {
2018-01-23 16:21:38 +01:00
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<Map<String,String>>>().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()).payload(null));
}
catch(HugeResultSet ex) {
2018-01-23 16:21:38 +01:00
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<Map<String,String>>>().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()).payload(null));
}
}
2017-10-06 19:20:05 +02:00
}