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

67 lines
3.6 KiB
Java
Raw Normal View History

2018-01-17 13:03:51 +01:00
package eu.eudat.controllers;
import eu.eudat.managers.ExternalDatasetManager;
import eu.eudat.models.externaldataset.ExternalDatasetListingModel;
import eu.eudat.models.externaldataset.ExternalDatasetTableRequest;
2018-01-25 16:24:21 +01:00
import eu.eudat.models.helpers.common.DataTableData;
2018-01-17 13:03:51 +01:00
import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.models.security.Principal;
import eu.eudat.services.ApiContext;
2018-01-23 16:21:38 +01:00
import eu.eudat.types.ApiMessageCode;
2018-01-17 13:03:51 +01:00
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
2018-01-22 08:41:31 +01:00
import org.springframework.http.ResponseEntity;
2018-01-17 13:03:51 +01:00
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.UUID;
2018-02-01 10:08:06 +01:00
2018-01-17 13:03:51 +01:00
@RestController
@CrossOrigin
2018-02-09 16:54:41 +01:00
@RequestMapping(value = {"/api"})
2018-02-16 11:34:02 +01:00
public class ExternalDatasets extends BaseController {
2018-01-17 13:03:51 +01:00
@Autowired
public ExternalDatasets(ApiContext apiContext) {
super(apiContext);
}
@RequestMapping(method = RequestMethod.POST, value = {"/externaldatasets/getPaged"}, consumes = "application/json", produces = "application/json")
2018-02-16 11:34:02 +01:00
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<ExternalDatasetListingModel>>> getPaged(@RequestBody ExternalDatasetTableRequest datasetTableRequest, Principal principal) {
2018-01-17 13:03:51 +01:00
try {
2018-02-16 08:45:18 +01:00
DataTableData<ExternalDatasetListingModel> dataTable = new ExternalDatasetManager().getPaged(this.getApiContext(), datasetTableRequest);
2018-01-23 16:21:38 +01:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<ExternalDatasetListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
2018-01-17 13:03:51 +01:00
} catch (Exception ex) {
ex.printStackTrace();
2018-01-23 16:21:38 +01:00
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<ExternalDatasetListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
2018-01-17 13:03:51 +01:00
}
}
2018-01-17 16:06:35 +01:00
@RequestMapping(method = RequestMethod.GET, value = {"/external/datasets"}, produces = "application/json")
2018-02-16 11:34:02 +01:00
public @ResponseBody
ResponseEntity<ResponseItem<List<ExternalDatasetListingModel>>> getWithExternal(@RequestParam(value = "query", required = false) String query, Principal principal) {
2018-01-17 13:03:51 +01:00
try {
2018-03-05 17:18:45 +01:00
List<ExternalDatasetListingModel> dataTable = new ExternalDatasetManager().getWithExternal(this.getApiContext(), query, this.getApiContext().getOperationsContext().getRemoteFetcher());
2018-01-23 16:21:38 +01:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalDatasetListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
2018-01-17 13:03:51 +01:00
} catch (Exception ex) {
ex.printStackTrace();
2018-01-23 16:21:38 +01:00
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<ExternalDatasetListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
2018-01-17 13:03:51 +01:00
}
}
@RequestMapping(method = RequestMethod.POST, value = {"/externaldatasets/getSingle/{id}"}, consumes = "application/json", produces = "application/json")
2018-02-16 11:34:02 +01:00
public @ResponseBody
ResponseItem<ExternalDatasetListingModel> getWithExternal(@PathVariable UUID id, Principal principal) {
2018-01-17 13:03:51 +01:00
try {
2018-03-05 17:18:45 +01:00
ExternalDatasetListingModel externalDatasetModel = new ExternalDatasetManager().getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getExternalDatasetDao(), id);
2018-02-16 11:34:02 +01:00
return new ResponseItem<ExternalDatasetListingModel>().payload(externalDatasetModel).status(ApiMessageCode.NO_MESSAGE);
2018-01-17 13:03:51 +01:00
} catch (Exception ex) {
ex.printStackTrace();
2018-01-23 16:21:38 +01:00
return new ResponseItem<ExternalDatasetListingModel>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage());
2018-01-17 13:03:51 +01:00
}
}
}