86 lines
5.2 KiB
Java
86 lines
5.2 KiB
Java
|
package eu.eudat.controllers;
|
||
|
|
||
|
import eu.eudat.data.entities.DMP;
|
||
|
import eu.eudat.data.entities.DMPProfile;
|
||
|
import eu.eudat.data.query.items.item.dmpprofile.DataManagementPlanProfileCriteriaRequest;
|
||
|
import eu.eudat.data.query.items.table.dmpprofile.DataManagementPlanProfileTableRequest;
|
||
|
import eu.eudat.managers.DataManagementProfileManager;
|
||
|
import eu.eudat.models.helpers.common.DataTableData;
|
||
|
import eu.eudat.models.helpers.responses.ResponseItem;
|
||
|
import eu.eudat.models.listingmodels.DataManagementPlanProfileListingModel;
|
||
|
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;
|
||
|
|
||
|
/**
|
||
|
* Created by ikalyvas on 3/21/2018.
|
||
|
*/
|
||
|
@RestController
|
||
|
@CrossOrigin
|
||
|
@RequestMapping(value = {"/api/dmpprofile"})
|
||
|
public class DMPProfileController extends BaseController {
|
||
|
|
||
|
@Autowired
|
||
|
public DMPProfileController(ApiContext apiContext) {
|
||
|
super(apiContext);
|
||
|
}
|
||
|
|
||
|
@Transactional
|
||
|
@RequestMapping(method = RequestMethod.POST, value = {"/createOrUpdate"}, consumes = "application/json", produces = "application/json")
|
||
|
public @ResponseBody
|
||
|
ResponseEntity<ResponseItem<DMPProfile>> createOrUpdate(@RequestBody DataManagementPlanProfileListingModel dataManagementPlan, Principal principal) {
|
||
|
try {
|
||
|
DataManagementProfileManager.createOrUpdate(this.getApiContext(), dataManagementPlan, principal);
|
||
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMPProfile>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
|
||
|
} catch (Exception ex) {
|
||
|
ex.printStackTrace();
|
||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMPProfile>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@RequestMapping(method = RequestMethod.GET, value = {"/getSingle/{id}"}, produces = "application/json")
|
||
|
public @ResponseBody
|
||
|
ResponseEntity<ResponseItem<DataManagementPlanProfileListingModel>> getSingle(@PathVariable String id, Principal principal) {
|
||
|
try {
|
||
|
DataManagementPlanProfileListingModel dataManagementPlanProfileListingModel = new DataManagementProfileManager().getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpProfileDao(), id, principal);
|
||
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanProfileListingModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlanProfileListingModel));
|
||
|
} catch (Exception ex) {
|
||
|
ex.printStackTrace();
|
||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlanProfileListingModel>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@RequestMapping(method = RequestMethod.POST, value = {"/getPaged"}, consumes = "application/json", produces = "application/json")
|
||
|
public @ResponseBody
|
||
|
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanProfileListingModel>>> getPaged(@Valid @RequestBody DataManagementPlanProfileTableRequest dataManagementPlanProfileTableRequest, Principal principal) {
|
||
|
try {
|
||
|
DataTableData<DataManagementPlanProfileListingModel> dataTable = new DataManagementProfileManager().getPaged(this.getApiContext(), dataManagementPlanProfileTableRequest, principal);
|
||
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
|
||
|
} catch (Exception ex) {
|
||
|
ex.printStackTrace();
|
||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<DataManagementPlanProfileListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@RequestMapping(method = RequestMethod.POST, value = {"/get"}, consumes = "application/json", produces = "application/json")
|
||
|
public @ResponseBody
|
||
|
ResponseEntity<ResponseItem<List<DataManagementPlanProfileListingModel>>> getWithCriteria(@RequestBody DataManagementPlanProfileCriteriaRequest dataManagementPlanCriteria, Principal principal) {
|
||
|
try {
|
||
|
List<DataManagementPlanProfileListingModel> dataTable = new DataManagementProfileManager().getWithCriteria(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpProfileDao(), dataManagementPlanCriteria);
|
||
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DataManagementPlanProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
|
||
|
} catch (Exception ex) {
|
||
|
ex.printStackTrace();
|
||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<DataManagementPlanProfileListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|