2017-12-20 15:52:09 +01:00
|
|
|
package eu.eudat.controllers;
|
|
|
|
|
2018-03-21 11:57:56 +01:00
|
|
|
import eu.eudat.data.entities.Dataset;
|
2018-08-30 13:09:36 +02:00
|
|
|
import eu.eudat.data.query.items.item.dataset.DatasetWizardAutocompleteRequest;
|
|
|
|
import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileWizardAutocompleteRequest;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.logic.managers.DatasetManager;
|
|
|
|
import eu.eudat.logic.managers.DatasetWizardManager;
|
2018-08-30 13:09:36 +02:00
|
|
|
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
|
|
|
import eu.eudat.logic.services.ApiContext;
|
|
|
|
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.models.data.datasetwizard.DataManagentPlanListingModel;
|
|
|
|
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
|
|
|
import eu.eudat.models.data.dmp.AssociatedProfile;
|
|
|
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
|
|
|
import eu.eudat.models.data.security.Principal;
|
2018-01-23 16:21:38 +01:00
|
|
|
import eu.eudat.types.ApiMessageCode;
|
2018-03-05 17:18:45 +01:00
|
|
|
import org.apache.poi.util.IOUtils;
|
2017-12-20 15:52:09 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2018-03-05 17:18:45 +01:00
|
|
|
import org.springframework.core.env.Environment;
|
2018-03-01 10:14:10 +01:00
|
|
|
import org.springframework.http.HttpHeaders;
|
2017-12-20 15:52:09 +01:00
|
|
|
import org.springframework.http.HttpStatus;
|
2018-03-01 10:14:10 +01:00
|
|
|
import org.springframework.http.MediaType;
|
2018-01-22 08:41:31 +01:00
|
|
|
import org.springframework.http.ResponseEntity;
|
2017-12-20 15:52:09 +01:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
2018-03-05 17:18:45 +01:00
|
|
|
import javax.activation.MimetypesFileTypeMap;
|
2017-12-22 14:42:47 +01:00
|
|
|
import javax.transaction.Transactional;
|
2018-03-01 10:14:10 +01:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
2018-03-05 17:18:45 +01:00
|
|
|
import java.io.IOException;
|
2018-03-01 10:14:10 +01:00
|
|
|
import java.io.InputStream;
|
2017-12-20 15:52:09 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2018-08-30 13:09:36 +02:00
|
|
|
import static eu.eudat.types.Authorities.ANONYMOUS;
|
|
|
|
|
2018-02-01 10:08:06 +01:00
|
|
|
|
2017-12-20 15:52:09 +01:00
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
2018-02-09 16:54:41 +01:00
|
|
|
@RequestMapping(value = {"api/datasetwizard"})
|
2018-01-19 10:31:05 +01:00
|
|
|
public class DatasetWizardController extends BaseController {
|
2017-12-22 14:42:47 +01:00
|
|
|
|
2018-03-05 17:18:45 +01:00
|
|
|
private Environment environment;
|
|
|
|
|
2018-01-04 10:32:39 +01:00
|
|
|
@Autowired
|
2018-03-05 17:18:45 +01:00
|
|
|
public DatasetWizardController(ApiContext apiContext, Environment environment) {
|
2018-01-04 10:32:39 +01:00
|
|
|
super(apiContext);
|
2018-03-05 17:18:45 +01:00
|
|
|
this.environment = environment;
|
2018-01-04 10:32:39 +01:00
|
|
|
}
|
2017-12-20 15:52:09 +01:00
|
|
|
|
2018-01-19 10:31:05 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/userDmps"}, produces = "application/json")
|
2018-02-08 16:54:31 +01:00
|
|
|
public @ResponseBody
|
2018-08-31 16:12:31 +02:00
|
|
|
ResponseEntity<ResponseItem<List<DataManagentPlanListingModel>>> getUserDmps(@RequestBody DatasetWizardAutocompleteRequest datasetWizardAutocompleteRequest, Principal principal) throws IllegalAccessException, InstantiationException {
|
|
|
|
List<DataManagentPlanListingModel> dataManagementPlans = DatasetWizardManager.getUserDmps(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), datasetWizardAutocompleteRequest, principal);
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DataManagentPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlans));
|
2017-12-20 15:52:09 +01:00
|
|
|
}
|
2017-12-21 10:26:11 +01:00
|
|
|
|
2018-01-19 10:31:05 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/getAvailableProfiles"}, produces = "application/json")
|
2018-02-08 16:54:31 +01:00
|
|
|
public @ResponseBody
|
2018-08-31 16:12:31 +02:00
|
|
|
ResponseEntity<ResponseItem<List<AssociatedProfile>>> getAvailableProfiles(@RequestBody DatasetProfileWizardAutocompleteRequest datasetProfileWizardAutocompleteRequest, @ClaimedAuthorities(claims = {ANONYMOUS}) Principal principal) throws IllegalAccessException, InstantiationException {
|
|
|
|
List<AssociatedProfile> dataManagementPlans = DatasetWizardManager.getAvailableProfiles(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), datasetProfileWizardAutocompleteRequest);
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<AssociatedProfile>>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlans));
|
2017-12-21 10:26:11 +01:00
|
|
|
}
|
2017-12-22 14:42:47 +01:00
|
|
|
|
2018-01-19 10:31:05 +01:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = {"/getSingle/{id}"}, produces = "application/json")
|
2018-02-08 16:54:31 +01:00
|
|
|
public @ResponseBody
|
2018-08-31 16:12:31 +02:00
|
|
|
ResponseEntity<ResponseItem<DatasetWizardModel>> getSingle(@PathVariable String id, @ClaimedAuthorities(claims = {ANONYMOUS}) Principal principal) throws IllegalAccessException, IOException, InstantiationException {
|
|
|
|
DatasetWizardModel dataset = new DatasetManager().getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getOperationsContext().getDatasetRepository(), id);
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetWizardModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset));
|
2017-12-22 14:42:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Transactional
|
2018-01-19 10:31:05 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/createOrUpdate"}, consumes = "application/json", produces = "application/json")
|
2018-02-08 16:54:31 +01:00
|
|
|
public @ResponseBody
|
2018-08-31 16:12:31 +02:00
|
|
|
ResponseEntity<ResponseItem<Dataset>> createOrUpdate(@RequestBody DatasetWizardModel profile, Principal principal) throws Exception {
|
|
|
|
eu.eudat.data.entities.Dataset dataset = DatasetManager.createOrUpdate(this.getApiContext(), profile, principal);
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.data.entities.Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(null));
|
2017-12-22 14:42:47 +01:00
|
|
|
}
|
2018-03-01 10:14:10 +01:00
|
|
|
|
2018-03-06 15:58:38 +01:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"})
|
2018-03-01 10:14:10 +01:00
|
|
|
public @ResponseBody
|
2018-08-31 16:12:31 +02:00
|
|
|
ResponseEntity<byte[]> getWordDocument(@PathVariable String id) throws IllegalAccessException, IOException, InstantiationException, InterruptedException {
|
2018-10-08 09:04:59 +02:00
|
|
|
File file = new DatasetManager().getWordDocument(this.environment, this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService());
|
2018-08-31 16:12:31 +02:00
|
|
|
File pdffile = new DatasetManager().convertToPDF(file, environment, file.getName());
|
|
|
|
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 = IOUtils.toByteArray(resource);
|
|
|
|
return new ResponseEntity<>(content,
|
|
|
|
responseHeaders,
|
|
|
|
HttpStatus.OK);
|
2018-03-01 10:14:10 +01:00
|
|
|
}
|
2018-03-06 15:58:38 +01:00
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = {"/getXml/{id}"})
|
|
|
|
public @ResponseBody
|
|
|
|
ResponseEntity<byte[]> getXml(@PathVariable String id) throws IllegalAccessException, IOException, InstantiationException {
|
2018-08-31 16:12:31 +02:00
|
|
|
FileEnvelope envelope = new DatasetManager().getXmlDocument(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService());
|
|
|
|
InputStream resource = new FileInputStream(envelope.getFile());
|
|
|
|
System.out.println("Mime Type of " + envelope.getFilename() + " is " +
|
|
|
|
new MimetypesFileTypeMap().getContentType(envelope.getFile()));
|
|
|
|
HttpHeaders responseHeaders = new HttpHeaders();
|
|
|
|
responseHeaders.setContentLength(envelope.getFile().length());
|
|
|
|
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
|
|
|
responseHeaders.set("Content-Disposition", "attachment;filename=" + envelope.getFilename() + ".xml");
|
|
|
|
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
|
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
|
|
|
|
|
|
|
|
byte[] content = IOUtils.toByteArray(resource);
|
|
|
|
return new ResponseEntity<>(content,
|
|
|
|
responseHeaders,
|
|
|
|
HttpStatus.OK);
|
2018-03-06 15:58:38 +01:00
|
|
|
}
|
2017-12-20 15:52:09 +01:00
|
|
|
}
|