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

95 lines
5.9 KiB
Java
Raw Normal View History

2018-03-28 15:24:47 +02:00
package eu.eudat.controllers;
import eu.eudat.data.dao.criteria.RequestItem;
2018-03-28 15:24:47 +02:00
import eu.eudat.data.entities.DMPProfile;
import eu.eudat.data.query.items.table.dmpprofile.DataManagementPlanProfileTableRequest;
2018-06-27 12:29:21 +02:00
import eu.eudat.logic.managers.DataManagementProfileManager;
2019-02-25 17:53:36 +01:00
import eu.eudat.logic.security.claims.ClaimedAuthorities;
2018-08-31 16:12:31 +02:00
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.helpermodels.Tuple;
import eu.eudat.models.data.helpers.common.AutoCompleteLookupItem;
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.DataManagementPlanProfileListingModel;
import eu.eudat.models.data.security.Principal;
2018-03-28 15:24:47 +02:00
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.*;
2019-02-25 17:53:36 +01:00
import org.springframework.web.multipart.MultipartFile;
2018-03-28 15:24:47 +02:00
import javax.validation.Valid;
import javax.xml.xpath.XPathExpressionException;
2019-02-25 17:53:36 +01:00
import java.io.IOException;
2018-03-28 15:24:47 +02:00
import java.util.List;
2019-02-25 17:53:36 +01:00
import static eu.eudat.types.Authorities.ADMIN;
2018-03-28 15:24:47 +02:00
/**
* Created by ikalyvas on 3/21/2018.
*/
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/dmpprofile"})
public class DMPProfileController extends BaseController {
private DataManagementProfileManager dataManagementProfileManager;
2018-03-28 15:24:47 +02:00
@Autowired
public DMPProfileController(ApiContext apiContext, DataManagementProfileManager dataManagementProfileManager) {
2018-03-28 15:24:47 +02:00
super(apiContext);
this.dataManagementProfileManager = dataManagementProfileManager;
2018-03-28 15:24:47 +02:00
}
@Transactional
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
2018-03-28 15:24:47 +02:00
public @ResponseBody
ResponseEntity<ResponseItem<DMPProfile>> createOrUpdate(@RequestBody DataManagementPlanProfileListingModel dataManagementPlan, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception {
this.dataManagementProfileManager.createOrUpdate(dataManagementPlan, principal);
2018-08-31 16:12:31 +02:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMPProfile>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
2018-03-28 15:24:47 +02:00
}
@RequestMapping(method = RequestMethod.GET, value = {"/getSingle/{id}"}, produces = "application/json")
public @ResponseBody
2018-08-31 16:12:31 +02:00
ResponseEntity<ResponseItem<DataManagementPlanProfileListingModel>> getSingle(@PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException {
DataManagementPlanProfileListingModel dataManagementPlanProfileListingModel = this.dataManagementProfileManager.getSingle(id, principal);
2018-08-31 16:12:31 +02:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanProfileListingModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlanProfileListingModel));
2018-03-28 15:24:47 +02:00
}
@RequestMapping(method = RequestMethod.POST, value = {"/getPaged"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
2018-08-31 16:12:31 +02:00
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanProfileListingModel>>> getPaged(@Valid @RequestBody DataManagementPlanProfileTableRequest dataManagementPlanProfileTableRequest, Principal principal) throws Exception {
DataTableData<DataManagementPlanProfileListingModel> dataTable = this.dataManagementProfileManager.getPaged(dataManagementPlanProfileTableRequest, principal);
2018-08-31 16:12:31 +02:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
2018-03-28 15:24:47 +02:00
}
2019-02-25 17:53:36 +01:00
@RequestMapping(method = RequestMethod.GET, value = {"/getXml/{id}"}, produces = "application/json")
public @ResponseBody
ResponseEntity getXml( @RequestHeader("Content-Type") String contentType, @PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException, IOException {
if (contentType.equals("application/xml")) {
DataManagementPlanProfileListingModel dataManagementPlanProfileListingModel = this.dataManagementProfileManager.getSingle(id, principal);
2019-02-25 17:53:36 +01:00
return this.dataManagementProfileManager.getDocument(dataManagementPlanProfileListingModel,dataManagementPlanProfileListingModel.getLabel());
}else {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlanProfileListingModel>().status(ApiMessageCode.ERROR_MESSAGE).message("NOT AUTHORIZE"));
}
}
@RequestMapping(method = RequestMethod.POST, value = {"/upload"})
public ResponseEntity<Object> setDatasetProfileXml(@RequestParam("file") MultipartFile file,
@ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws IllegalAccessException,IOException,Exception{
eu.eudat.logic.utilities.documents.xml.dmpXml.dmpProfileModel.DmpProfile dmpProfileModel = this.dataManagementProfileManager.createDmpProfileFromXml(file);
DataManagementPlanProfileListingModel dataManagementPlan = dmpProfileModel.toDmpProfileCompositeModel(file.getOriginalFilename());
this.dataManagementProfileManager.createOrUpdate(dataManagementPlan, principal);
2019-02-25 17:53:36 +01:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.data.entities.DatasetProfile>>()
.status(ApiMessageCode.SUCCESS_MESSAGE).message(""));
}
@RequestMapping(method = RequestMethod.POST, value = {"/search/autocomplete"})
public ResponseEntity<Object> getExternalAutocomplete(@RequestBody RequestItem<AutoCompleteLookupItem> lookupItem) throws XPathExpressionException {
List<Tuple<String, String>> items = this.dataManagementProfileManager.getExternalAutocomplete(lookupItem);
return ResponseEntity.status(HttpStatus.OK).body(items);
}
2018-03-28 15:24:47 +02:00
}