2017-12-15 00:01:26 +01:00
|
|
|
package eu.eudat.controllers;
|
2017-09-14 12:37:36 +02:00
|
|
|
|
2017-10-27 12:52:12 +02:00
|
|
|
|
2018-08-31 16:12:31 +02:00
|
|
|
import eu.eudat.configurations.dynamicproject.DynamicProjectConfiguration;
|
2018-03-28 15:24:47 +02:00
|
|
|
import eu.eudat.data.dao.criteria.DynamicFieldsCriteria;
|
|
|
|
import eu.eudat.data.dao.criteria.RequestItem;
|
2019-02-06 11:46:14 +01:00
|
|
|
import eu.eudat.data.dao.entities.DMPDao;
|
2018-03-21 11:57:56 +01:00
|
|
|
import eu.eudat.data.entities.DMP;
|
2018-03-28 15:24:47 +02:00
|
|
|
import eu.eudat.data.query.items.item.dmp.DataManagementPlanCriteriaRequest;
|
|
|
|
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
|
2019-03-26 15:52:19 +01:00
|
|
|
import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException;
|
2018-11-30 15:57:20 +01:00
|
|
|
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.logic.managers.DataManagementPlanManager;
|
2018-10-18 11:33:13 +02:00
|
|
|
import eu.eudat.logic.managers.DatasetManager;
|
2019-03-05 12:59:34 +01:00
|
|
|
import eu.eudat.logic.managers.FileManager;
|
2018-08-31 16:12:31 +02:00
|
|
|
import eu.eudat.logic.services.ApiContext;
|
2019-02-06 11:46:14 +01:00
|
|
|
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
2018-10-08 17:14:27 +02:00
|
|
|
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.models.data.dmp.DataManagementPlan;
|
2019-03-05 12:59:34 +01:00
|
|
|
import eu.eudat.models.data.files.ContentFile;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.models.data.helpermodels.Tuple;
|
|
|
|
import eu.eudat.models.data.helpers.common.DataTableData;
|
|
|
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
|
|
|
import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel;
|
|
|
|
import eu.eudat.models.data.security.Principal;
|
2018-01-23 16:21:38 +01:00
|
|
|
import eu.eudat.types.ApiMessageCode;
|
2018-10-08 17:14:27 +02:00
|
|
|
import org.apache.commons.io.IOUtils;
|
2017-09-14 12:37:36 +02:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2018-10-18 11:33:13 +02:00
|
|
|
import org.springframework.core.env.Environment;
|
2018-10-08 17:14:27 +02:00
|
|
|
import org.springframework.http.HttpHeaders;
|
2017-09-14 12:37:36 +02:00
|
|
|
import org.springframework.http.HttpStatus;
|
2018-10-08 17:14:27 +02:00
|
|
|
import org.springframework.http.MediaType;
|
2018-01-22 08:41:31 +01:00
|
|
|
import org.springframework.http.ResponseEntity;
|
2018-02-07 10:56:30 +01:00
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2017-12-23 16:56:05 +01:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
2019-03-05 12:59:34 +01:00
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
2017-09-14 12:37:36 +02:00
|
|
|
|
2018-10-08 17:14:27 +02:00
|
|
|
import javax.activation.MimetypesFileTypeMap;
|
2018-02-16 11:34:02 +01:00
|
|
|
import javax.validation.Valid;
|
2019-03-05 12:59:34 +01:00
|
|
|
import javax.xml.bind.JAXBException;
|
2018-10-18 11:33:13 +02:00
|
|
|
import java.io.File;
|
2018-10-08 17:14:27 +02:00
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
2018-02-16 11:34:02 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
2017-09-14 12:37:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
2018-10-18 11:33:13 +02:00
|
|
|
@RequestMapping(value = {"/api/dmps/"})
|
2018-01-03 11:44:54 +01:00
|
|
|
public class DMPs extends BaseController {
|
2018-01-04 10:32:39 +01:00
|
|
|
|
2018-03-28 15:24:47 +02:00
|
|
|
private DynamicProjectConfiguration dynamicProjectConfiguration;
|
2018-10-18 11:33:13 +02:00
|
|
|
private Environment environment;
|
2019-01-29 12:05:36 +01:00
|
|
|
private DataManagementPlanManager dataManagementPlanManager;
|
2019-03-05 16:33:59 +01:00
|
|
|
private DatasetManager datasetManager;
|
2018-01-23 16:21:38 +01:00
|
|
|
@Autowired
|
2019-03-05 16:33:59 +01:00
|
|
|
public DMPs(ApiContext apiContext, DynamicProjectConfiguration dynamicProjectConfiguration, Environment environment,
|
|
|
|
DataManagementPlanManager dataManagementPlanManager, DatasetManager datasetManager) {
|
2018-01-23 16:21:38 +01:00
|
|
|
super(apiContext);
|
2018-03-28 15:24:47 +02:00
|
|
|
this.dynamicProjectConfiguration = dynamicProjectConfiguration;
|
2018-10-18 11:33:13 +02:00
|
|
|
this.environment = environment;
|
2019-01-29 12:05:36 +01:00
|
|
|
this.dataManagementPlanManager = dataManagementPlanManager;
|
2019-03-05 16:33:59 +01:00
|
|
|
this.datasetManager = datasetManager;
|
2018-01-23 16:21:38 +01:00
|
|
|
}
|
|
|
|
|
2018-10-12 10:22:23 +02:00
|
|
|
@Transactional
|
2018-10-18 11:33:13 +02:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = {"{id}/unlock"}, produces = "application/json")
|
2018-10-12 10:22:23 +02:00
|
|
|
public @ResponseBody
|
|
|
|
ResponseEntity<ResponseItem<DMP>> unlock(@PathVariable(value = "id") UUID id, Principal principal) throws Exception {
|
2019-03-05 16:33:59 +01:00
|
|
|
this.dataManagementPlanManager.unlock(id);
|
2018-10-12 10:22:23 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Unlocked"));
|
|
|
|
}
|
|
|
|
|
2019-01-29 12:05:36 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/paged"}, consumes = "application/json", produces = "application/json")
|
2018-01-23 16:21:38 +01:00
|
|
|
public @ResponseBody
|
2019-01-31 14:56:53 +01:00
|
|
|
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest,@RequestParam String fieldsGroup, Principal principal) throws Exception {
|
2019-03-05 16:33:59 +01:00
|
|
|
DataTableData<DataManagementPlanListingModel> dataTable = this.dataManagementPlanManager.getPaged(dataManagementPlanTableRequest, principal, fieldsGroup);
|
2018-08-31 16:12:31 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
|
2018-01-23 16:21:38 +01:00
|
|
|
}
|
|
|
|
|
2019-02-06 11:46:14 +01:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = {"{id}"})
|
2018-01-23 16:21:38 +01:00
|
|
|
public @ResponseBody
|
2019-04-05 11:20:06 +02:00
|
|
|
ResponseEntity getSingle(@PathVariable String id,@RequestHeader("Content-Type") String contentType, Principal principal) throws IllegalAccessException,InterruptedException, InstantiationException, IOException {
|
|
|
|
if(contentType.equals("application/xml") || contentType.equals("application/msword")){ //|| contentType.equals("application/pdf")
|
2019-02-06 11:46:14 +01:00
|
|
|
DMPDao dmpDao = this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao();
|
|
|
|
VisibilityRuleService visibilityRuleService = this.getApiContext().getUtilitiesService().getVisibilityRuleService();
|
2019-03-05 16:33:59 +01:00
|
|
|
ResponseEntity<byte[]> document = this.dataManagementPlanManager.getDocument(id, contentType);
|
2019-02-06 11:46:14 +01:00
|
|
|
return document;
|
|
|
|
}
|
|
|
|
else{
|
2019-03-05 16:33:59 +01:00
|
|
|
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(id, principal, this.dynamicProjectConfiguration);
|
2019-02-06 11:46:14 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
|
|
|
|
}
|
2018-01-23 16:21:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Transactional
|
2019-01-30 17:37:49 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
2018-01-23 16:21:38 +01:00
|
|
|
public @ResponseBody
|
2018-08-31 16:12:31 +02:00
|
|
|
ResponseEntity<ResponseItem<DMP>> createOrUpdate(@RequestBody eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan, Principal principal) throws Exception {
|
2019-01-29 12:05:36 +01:00
|
|
|
this.dataManagementPlanManager.createOrUpdate(this.getApiContext(), dataManagementPlan, principal);
|
2018-08-31 16:12:31 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
|
2018-01-23 16:21:38 +01:00
|
|
|
}
|
|
|
|
|
2018-10-18 11:33:13 +02:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/new/{id}"}, consumes = "application/json", produces = "application/json")
|
2018-01-23 16:21:38 +01:00
|
|
|
public @ResponseBody
|
2018-08-31 16:12:31 +02:00
|
|
|
ResponseEntity<ResponseItem<DMP>> newVersion(@PathVariable UUID id, @Valid @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
2019-03-26 15:52:19 +01:00
|
|
|
try {
|
|
|
|
this.dataManagementPlanManager.newVersion(id, dataManagementPlan, principal);
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.NO_MESSAGE));
|
|
|
|
} catch (DMPNewVersionException exception) {
|
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
|
|
|
|
}
|
2018-01-23 16:21:38 +01:00
|
|
|
}
|
|
|
|
|
2018-10-18 11:33:13 +02:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/clone/{id}"}, consumes = "application/json", produces = "application/json")
|
2018-02-08 09:42:02 +01:00
|
|
|
public @ResponseBody
|
2018-08-31 16:12:31 +02:00
|
|
|
ResponseEntity<ResponseItem<DMP>> clone(@PathVariable UUID id, @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
2019-03-05 16:33:59 +01:00
|
|
|
this.dataManagementPlanManager.clone(id, dataManagementPlan, principal);
|
2018-08-31 16:12:31 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.NO_MESSAGE));
|
2018-02-08 09:42:02 +01:00
|
|
|
}
|
2018-01-23 16:21:38 +01:00
|
|
|
|
2018-02-07 10:56:30 +01:00
|
|
|
@Transactional
|
2019-01-29 12:05:36 +01:00
|
|
|
@RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json")
|
2018-02-07 10:56:30 +01:00
|
|
|
public @ResponseBody
|
|
|
|
ResponseEntity<ResponseItem<DMP>> delete(@PathVariable UUID id, Principal principal) {
|
2018-11-30 15:57:20 +01:00
|
|
|
try{
|
2019-03-05 16:33:59 +01:00
|
|
|
this.dataManagementPlanManager.delete(id);
|
2018-11-30 15:57:20 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Deleted Datamanagement Plan"));
|
|
|
|
}catch (DMPWithDatasetsDeleteException exception){
|
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
|
|
|
|
}
|
2018-02-07 10:56:30 +01:00
|
|
|
}
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2018-10-18 11:33:13 +02:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/dynamic"}, consumes = "application/json", produces = "application/json")
|
2018-03-28 15:24:47 +02:00
|
|
|
public @ResponseBody
|
2018-08-31 16:12:31 +02:00
|
|
|
ResponseEntity<ResponseItem<List<Tuple<String, String>>>> getWithCriteria(@RequestBody RequestItem<DynamicFieldsCriteria> criteriaRequestItem, Principal principal) throws InstantiationException, IllegalAccessException {
|
2019-01-29 12:05:36 +01:00
|
|
|
List<Tuple<String, String>> dataTable = this.dataManagementPlanManager.getDynamicFields(criteriaRequestItem.getCriteria().getId(), this.dynamicProjectConfiguration, criteriaRequestItem.getCriteria());
|
2018-08-31 16:12:31 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Tuple<String, String>>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
|
2018-03-28 15:24:47 +02:00
|
|
|
}
|
|
|
|
|
2018-10-22 09:48:56 +02:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"})
|
|
|
|
public @ResponseBody
|
2019-02-06 11:46:14 +01:00
|
|
|
ResponseEntity<byte[]> getPDFDocument(@PathVariable String id, @RequestHeader("Content-Type") String contentType) throws IllegalAccessException, IOException, InstantiationException, InterruptedException {
|
|
|
|
System.out.println(contentType);
|
2019-03-05 16:33:59 +01:00
|
|
|
File file = this.dataManagementPlanManager.getWordDocument(id);
|
|
|
|
File pdffile = datasetManager.convertToPDF(file, environment, file.getName());
|
2018-10-22 09:48:56 +02:00
|
|
|
InputStream resource = new FileInputStream(pdffile);
|
|
|
|
System.out.println("Mime Type of " + file.getName() + " is " +
|
|
|
|
new MimetypesFileTypeMap().getContentType(file));
|
|
|
|
HttpHeaders responseHeaders = new HttpHeaders();
|
|
|
|
responseHeaders.setContentLength(pdffile.length());
|
|
|
|
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
|
|
|
responseHeaders.set("Content-Disposition", "attachment;filename=" + pdffile.getName());
|
|
|
|
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
|
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
|
|
|
|
|
|
|
|
byte[] content = org.apache.poi.util.IOUtils.toByteArray(resource);
|
|
|
|
return new ResponseEntity<>(content,
|
|
|
|
responseHeaders,
|
|
|
|
HttpStatus.OK);
|
|
|
|
}
|
2019-03-05 12:59:34 +01:00
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/upload"})
|
|
|
|
public ResponseEntity<ResponseItem> dmpXmlUpload(@RequestParam("file") MultipartFile[] files, Principal principal) throws IOException, JAXBException, Exception {
|
|
|
|
this.dataManagementPlanManager.createDmpFromXml(this.getApiContext(), files, principal);
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List>()
|
2019-04-05 11:20:06 +02:00
|
|
|
.status(ApiMessageCode.SUCCESS_MESSAGE));
|
2019-03-05 12:59:34 +01:00
|
|
|
}
|
2017-09-14 12:37:36 +02:00
|
|
|
}
|
|
|
|
|