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

51 lines
2.4 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;
2018-03-21 13:11:02 +01:00
import eu.eudat.data.query.items.table.dataset.DatasetTableRequest;
2018-08-30 13:09:36 +02:00
import eu.eudat.logic.managers.DatasetManager;
import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.logic.services.ApiContext;
2018-06-27 12:29:21 +02:00
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.listingmodels.DatasetListingModel;
import eu.eudat.models.data.security.Principal;
2018-01-23 16:21:38 +01:00
import eu.eudat.types.ApiMessageCode;
2018-08-30 13:09:36 +02:00
import eu.eudat.types.Authorities;
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
2018-08-31 16:12:31 +02:00
ResponseEntity<ResponseItem<DataTableData<DatasetListingModel>>> getPaged(@RequestBody DatasetTableRequest datasetTableRequest, @ClaimedAuthorities(claims = {Authorities.ANONYMOUS}) Principal principal) throws Exception {
DataTableData<DatasetListingModel> dataTable = new DatasetManager().getPaged(this.getApiContext(), datasetTableRequest, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
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
2018-08-31 16:12:31 +02:00
ResponseEntity<ResponseItem<Dataset>> makePublic(@PathVariable UUID id, Principal principal, Locale locale) throws Exception {
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
}
}