2017-12-20 15:52:09 +01:00
|
|
|
package eu.eudat.controllers;
|
|
|
|
|
2018-01-22 08:41:31 +01:00
|
|
|
import eu.eudat.entities.Dataset;
|
2017-12-20 15:52:09 +01:00
|
|
|
import eu.eudat.managers.DatasetManager;
|
|
|
|
import eu.eudat.managers.DatasetWizardManager;
|
|
|
|
import eu.eudat.models.datasetwizard.DataManagentPlanListingModel;
|
2017-12-21 10:26:11 +01:00
|
|
|
import eu.eudat.models.datasetwizard.DatasetProfileWizardAutocompleteRequest;
|
2017-12-20 15:52:09 +01:00
|
|
|
import eu.eudat.models.datasetwizard.DatasetWizardAutocompleteRequest;
|
2017-12-22 14:42:47 +01:00
|
|
|
import eu.eudat.models.datasetwizard.DatasetWizardModel;
|
2017-12-21 10:26:11 +01:00
|
|
|
import eu.eudat.models.dmp.AssociatedProfile;
|
2017-12-20 15:52:09 +01:00
|
|
|
import eu.eudat.models.helpers.responses.ResponseItem;
|
|
|
|
import eu.eudat.models.security.Principal;
|
2018-01-04 10:32:39 +01:00
|
|
|
import eu.eudat.services.ApiContext;
|
2018-01-23 16:21:38 +01:00
|
|
|
import eu.eudat.types.ApiMessageCode;
|
2017-12-20 15:52:09 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2018-03-01 10:14:10 +01:00
|
|
|
import org.springframework.core.io.InputStreamResource;
|
|
|
|
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.*;
|
|
|
|
|
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;
|
|
|
|
import java.io.InputStream;
|
2017-12-20 15:52:09 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
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-01-04 10:32:39 +01:00
|
|
|
@Autowired
|
|
|
|
public DatasetWizardController(ApiContext apiContext) {
|
|
|
|
super(apiContext);
|
|
|
|
}
|
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
|
|
|
|
ResponseEntity<ResponseItem<List<DataManagentPlanListingModel>>> getUserDmps(@RequestBody DatasetWizardAutocompleteRequest datasetWizardAutocompleteRequest, Principal principal) {
|
2017-12-20 15:52:09 +01:00
|
|
|
try {
|
2018-01-19 10:31:05 +01:00
|
|
|
List<DataManagentPlanListingModel> dataManagementPlans = DatasetWizardManager.getUserDmps(this.getApiContext().getDatabaseRepository().getDmpDao(), datasetWizardAutocompleteRequest, principal);
|
2018-01-23 16:21:38 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DataManagentPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlans));
|
2017-12-20 15:52:09 +01:00
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2018-01-23 16:21:38 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<DataManagentPlanListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
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
|
|
|
|
ResponseEntity<ResponseItem<List<AssociatedProfile>>> getAvailableProfiles(@RequestBody DatasetProfileWizardAutocompleteRequest datasetProfileWizardAutocompleteRequest, Principal principal) {
|
2017-12-21 10:26:11 +01:00
|
|
|
try {
|
2018-01-19 10:31:05 +01:00
|
|
|
List<AssociatedProfile> dataManagementPlans = DatasetWizardManager.getAvailableProfiles(this.getApiContext().getDatabaseRepository().getDmpDao(), datasetProfileWizardAutocompleteRequest);
|
2018-01-23 16:21:38 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<AssociatedProfile>>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlans));
|
2017-12-21 10:26:11 +01:00
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2018-01-23 16:21:38 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<AssociatedProfile>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
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
|
|
|
|
ResponseEntity<ResponseItem<DatasetWizardModel>> getSingle(@PathVariable String id, Principal principal) {
|
2017-12-22 14:42:47 +01:00
|
|
|
try {
|
2018-01-04 10:32:39 +01:00
|
|
|
DatasetWizardModel dataset = new DatasetManager().getSingle(this.getApiContext().getDatabaseRepository().getDatasetDao(), id);
|
2018-01-23 16:21:38 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetWizardModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset));
|
2017-12-22 14:42:47 +01:00
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2018-01-23 16:21:38 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DatasetWizardModel>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
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
|
|
|
|
ResponseEntity<ResponseItem<Dataset>> createOrUpdate(@RequestBody DatasetWizardModel profile, Principal principal) {
|
2017-12-22 14:42:47 +01:00
|
|
|
try {
|
2018-02-08 16:54:31 +01:00
|
|
|
eu.eudat.entities.Dataset dataset = DatasetManager.createOrUpdate(this.getApiContext(), profile, principal);
|
2018-01-25 09:14:43 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.entities.Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(null));
|
2017-12-22 14:42:47 +01:00
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2018-01-23 16:21:38 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.entities.Dataset>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
2017-12-22 14:42:47 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-01 10:14:10 +01:00
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = {"/getWordDocument/{id}"}, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
|
public @ResponseBody
|
|
|
|
ResponseEntity<InputStreamResource> getWordDocument(@PathVariable String id) {
|
|
|
|
try {
|
|
|
|
File file = new DatasetManager().getWordDocument(this.getApiContext().getDatabaseRepository().getDatasetDao(), id);
|
|
|
|
InputStreamResource resource = new InputStreamResource(new FileInputStream(file));
|
|
|
|
|
|
|
|
return ResponseEntity.ok()
|
|
|
|
.header(HttpHeaders.CONTENT_DISPOSITION,
|
|
|
|
"attachment;filename=" + file.getName())
|
|
|
|
.contentType(MediaType.APPLICATION_PDF).contentLength(file.length())
|
|
|
|
.body(resource);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
return new ResponseEntity<InputStreamResource>(HttpStatus.BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
2017-12-20 15:52:09 +01:00
|
|
|
}
|