package eu.eudat.controllers; import eu.eudat.entities.DMP; import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsException; import eu.eudat.managers.DataManagementPlanManager; import eu.eudat.models.dmp.DataManagementPlan; import eu.eudat.models.dmp.DataManagementPlanCriteriaRequest; import eu.eudat.models.dmp.DataManagementPlanTableRequest; import eu.eudat.models.helpers.common.DataTableData; import eu.eudat.models.helpers.responses.ResponseItem; import eu.eudat.models.listingmodels.DataManagementPlanListingModel; import eu.eudat.models.security.Principal; import eu.eudat.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.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.util.List; import java.util.UUID; @RestController @CrossOrigin @RequestMapping(value = {"/api"}) public class DMPs extends BaseController { @Autowired public DMPs(ApiContext apiContext) { super(apiContext); } @RequestMapping(method = RequestMethod.POST, value = {"/dmps/getPaged"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) { try { DataTableData dataTable = new DataManagementPlanManager().getPaged(this.getApiContext(), dataManagementPlanTableRequest, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); } catch (Exception ex) { ex.printStackTrace(); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage())); } } @RequestMapping(method = RequestMethod.GET, value = {"/dmps/getSingle/{id}"}, produces = "application/json") public @ResponseBody ResponseEntity> getSingle(@PathVariable String id, Principal principal) { try { eu.eudat.models.dmp.DataManagementPlan dataManagementPlan = new DataManagementPlanManager().getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); } catch (Exception ex) { ex.printStackTrace(); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage())); } } @Transactional @RequestMapping(method = RequestMethod.POST, value = {"/dmps/createOrUpdate"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> createOrUpdate(@RequestBody eu.eudat.models.dmp.DataManagementPlan dataManagementPlan, Principal principal) { try { DataManagementPlanManager.createOrUpdate(this.getApiContext(), dataManagementPlan, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created")); } catch (Exception ex) { ex.printStackTrace(); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage())); } } @RequestMapping(method = RequestMethod.POST, value = {"/dmps/new/{id}"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> newVersion(@PathVariable UUID id, @RequestBody eu.eudat.models.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) { try { DataManagementPlanManager.newVersion(this.getApiContext(), id, dataManagementPlan, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); } catch (Exception ex) { ex.printStackTrace(); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage())); } } @RequestMapping(method = RequestMethod.POST, value = {"/dmps/clone/{id}"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> clone(@PathVariable UUID id, @RequestBody eu.eudat.models.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) { try { DataManagementPlanManager.clone(this.getApiContext(), id, dataManagementPlan, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); } catch (Exception ex) { ex.printStackTrace(); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage())); } } @RequestMapping(method = RequestMethod.POST, value = {"/dmps/get"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getWithCriteria(@RequestBody DataManagementPlanCriteriaRequest dataManagementPlanCriteria, Principal principal) { try { List dataTable = new DataManagementPlanManager().getWithCriteria(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), dataManagementPlanCriteria); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); } catch (Exception ex) { ex.printStackTrace(); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage())); } } @Transactional @RequestMapping(method = RequestMethod.DELETE, value = {"/dmps/delete/{id}"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> delete(@PathVariable UUID id, Principal principal) { try { DataManagementPlanManager.delete(this.getApiContext(), id); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Deleted Dataset")); } catch (DMPWithDatasetsException ex) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage())); } catch (Exception ex) { ex.printStackTrace(); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage())); } } }