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

61 lines
2.8 KiB
Java
Raw Normal View History

2017-12-15 00:01:26 +01:00
package eu.eudat.controllers;
2018-03-21 11:57:56 +01:00
import eu.eudat.data.entities.Dataset;
2017-12-15 13:25:21 +01:00
import eu.eudat.managers.DatasetManager;
2018-03-21 13:11:02 +01:00
import eu.eudat.data.query.items.table.dataset.DatasetTableRequest;
2018-01-25 16:24:21 +01:00
import eu.eudat.models.helpers.common.DataTableData;
2018-02-16 11:34:02 +01:00
import eu.eudat.models.helpers.responses.ResponseItem;
2017-12-19 17:22:30 +01:00
import eu.eudat.models.listingmodels.DatasetListingModel;
2018-01-08 12:44:48 +01:00
import eu.eudat.models.security.Principal;
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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
2018-01-19 12:11:22 +01:00
import org.springframework.transaction.annotation.Transactional;
2018-02-16 11:34:02 +01:00
import org.springframework.web.bind.annotation.*;
import java.util.Locale;
import java.util.UUID;
@RestController
@CrossOrigin
2018-02-09 16:54:41 +01:00
@RequestMapping(value = {"/api"})
2018-01-12 09:05:44 +01:00
public class Datasets extends BaseController {
2017-12-15 13:25:21 +01:00
2018-01-12 09:05:44 +01:00
@Autowired
public Datasets(ApiContext apiContext) {
super(apiContext);
}
2017-12-15 13:25:21 +01:00
2018-01-12 09:05:44 +01:00
@RequestMapping(method = RequestMethod.POST, value = {"/datasets/getPaged"}, consumes = "application/json", produces = "application/json")
2018-01-24 15:11:09 +01:00
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DatasetListingModel>>> getPaged(@RequestBody DatasetTableRequest datasetTableRequest, Principal principal) {
2018-01-12 09:05:44 +01:00
try {
DataTableData<DatasetListingModel> dataTable = new DatasetManager().getPaged(this.getApiContext(), datasetTableRequest, principal);
2018-01-23 16:21:38 +01:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
2018-01-12 09:05:44 +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<DatasetListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
2018-01-12 09:05:44 +01:00
}
}
2017-12-15 13:25:21 +01:00
2018-01-19 12:11:22 +01:00
@Transactional
@RequestMapping(method = RequestMethod.GET, value = {"/datasets/makepublic/{id}"}, produces = "application/json")
2018-01-24 15:11:09 +01:00
public @ResponseBody
ResponseEntity<ResponseItem<Dataset>> makePublic(@PathVariable UUID id, Principal principal, Locale locale) {
2018-01-19 12:11:22 +01:00
try {
2018-03-05 17:18:45 +01:00
DatasetManager.makePublic(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message(this.getApiContext().getHelpersService().getMessageSource().getMessage("dataset.public", new Object[]{}, locale)));
2018-01-19 12:11:22 +01:00
} catch (Exception ex) {
ex.printStackTrace();
2018-01-23 16:21:38 +01:00
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Dataset>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
2018-01-19 12:11:22 +01:00
}
}
}