2019-03-01 16:16:21 +01:00
|
|
|
package eu.eudat.controllers;
|
|
|
|
|
|
|
|
|
2020-09-04 16:00:34 +02:00
|
|
|
import eu.eudat.data.entities.Dataset;
|
|
|
|
import eu.eudat.data.entities.DatasetProfile;
|
2019-08-28 17:17:16 +02:00
|
|
|
import eu.eudat.data.entities.Funder;
|
|
|
|
import eu.eudat.data.entities.Project;
|
2019-12-12 13:02:52 +01:00
|
|
|
import eu.eudat.logic.managers.DatasetManager;
|
|
|
|
import eu.eudat.logic.managers.QuickWizardManager;
|
2019-03-01 16:16:21 +01:00
|
|
|
import eu.eudat.logic.services.ApiContext;
|
2019-03-14 19:00:02 +01:00
|
|
|
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
|
|
|
import eu.eudat.models.data.dmp.DataManagementPlan;
|
2019-03-01 16:16:21 +01:00
|
|
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
2019-12-12 13:02:52 +01:00
|
|
|
import eu.eudat.models.data.quickwizard.DatasetCreateWizardModel;
|
2019-03-01 16:16:21 +01:00
|
|
|
import eu.eudat.models.data.quickwizard.DatasetDescriptionQuickWizardModel;
|
|
|
|
import eu.eudat.models.data.quickwizard.QuickWizardModel;
|
|
|
|
import eu.eudat.models.data.security.Principal;
|
|
|
|
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.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.transaction.Transactional;
|
|
|
|
import javax.validation.Valid;
|
2019-03-14 19:00:02 +01:00
|
|
|
import java.util.UUID;
|
2019-03-05 12:21:04 +01:00
|
|
|
|
2019-03-01 16:16:21 +01:00
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
|
|
|
@RequestMapping(value = {"/api/quick-wizard/"})
|
|
|
|
public class QuickWizardController extends BaseController {
|
|
|
|
|
|
|
|
private QuickWizardManager quickWizardManager;
|
|
|
|
private DatasetManager datasetManager;
|
|
|
|
|
|
|
|
@Autowired
|
2019-08-28 17:17:16 +02:00
|
|
|
public QuickWizardController(ApiContext apiContext, QuickWizardManager quickWizardManager, DatasetManager datasetManager) {
|
2019-03-01 16:16:21 +01:00
|
|
|
super(apiContext);
|
|
|
|
this.quickWizardManager = quickWizardManager;
|
|
|
|
this.datasetManager = datasetManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
|
|
|
public @ResponseBody
|
|
|
|
ResponseEntity<ResponseItem<QuickWizardModel>> addQuickWizardModel(@Valid @RequestBody QuickWizardModel quickWizard, Principal principal) throws Exception {
|
2019-08-28 17:17:16 +02:00
|
|
|
|
|
|
|
Funder funderEntity;
|
|
|
|
//Create Funder
|
2019-10-08 09:58:02 +02:00
|
|
|
if (quickWizard.getFunder() == null) {
|
|
|
|
throw new Exception("Funder is a mandatory entity");
|
|
|
|
} else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() == null) {
|
|
|
|
throw new Exception("Funder is a mandatory entity");
|
|
|
|
} else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() != null) {
|
2019-08-28 17:17:16 +02:00
|
|
|
funderEntity = this.quickWizardManager.createOrUpdate(quickWizard.getFunder().toDataFunder(), principal);
|
|
|
|
} else {
|
|
|
|
funderEntity = quickWizard.getFunder().getExistFunder().toDataModel();
|
|
|
|
}
|
|
|
|
|
2019-07-31 16:57:34 +02:00
|
|
|
eu.eudat.data.entities.Grant grantEntity;
|
|
|
|
//Create Grant
|
2019-12-12 13:02:52 +01:00
|
|
|
if (quickWizard.getGrant() == null) {
|
|
|
|
throw new Exception("Grant is a mandatory entity");
|
|
|
|
} else if (quickWizard.getGrant().getExistGrant() == null && quickWizard.getGrant().getLabel() == null) {
|
|
|
|
throw new Exception("Grant is a mandatory entity");
|
|
|
|
} else if (quickWizard.getGrant().getExistGrant() == null) {
|
2019-07-31 16:57:34 +02:00
|
|
|
grantEntity = this.quickWizardManager.createOrUpdate(quickWizard.getGrant().toDataGrant(), principal);
|
2019-03-05 12:21:04 +01:00
|
|
|
} else {
|
2019-07-31 16:57:34 +02:00
|
|
|
grantEntity = quickWizard.getGrant().getExistGrant().toDataModel();
|
2019-03-05 12:21:04 +01:00
|
|
|
}
|
2019-08-28 17:17:16 +02:00
|
|
|
|
|
|
|
Project projectEntity;
|
|
|
|
//Create Project
|
2019-08-29 10:30:17 +02:00
|
|
|
if (quickWizard.getProject().getExistProject() == null
|
|
|
|
&& quickWizard.getProject().getLabel() == null) {
|
|
|
|
projectEntity = null;
|
2019-12-12 13:02:52 +01:00
|
|
|
} else if (quickWizard.getProject().getExistProject() == null && quickWizard.getProject().getLabel() != null) {
|
2019-08-28 17:17:16 +02:00
|
|
|
projectEntity = this.quickWizardManager.createOrUpdate(quickWizard.getProject().toDataProject(), principal);
|
|
|
|
} else {
|
|
|
|
projectEntity = quickWizard.getProject().getExistProject().toDataModel();
|
|
|
|
}
|
|
|
|
|
2019-03-01 16:16:21 +01:00
|
|
|
//Create Dmp
|
2019-12-12 13:02:52 +01:00
|
|
|
DataManagementPlan dataManagementPlan = quickWizard.getDmp().toDataDmp(grantEntity, projectEntity, principal);
|
|
|
|
eu.eudat.data.entities.DMP dmpEntity = this.quickWizardManager.createOrUpdate(dataManagementPlan, funderEntity, principal);
|
2019-03-01 16:16:21 +01:00
|
|
|
|
|
|
|
//Create Datasets
|
|
|
|
quickWizard.getDmp().setId(dmpEntity.getId());
|
2019-03-05 12:21:04 +01:00
|
|
|
for (DatasetDescriptionQuickWizardModel dataset : quickWizard.getDatasets().getDatasetsList()) {
|
2019-08-28 17:17:16 +02:00
|
|
|
DataManagementPlan dmp = quickWizard.getDmp().toDataDmp(grantEntity, projectEntity, principal);
|
2020-09-04 16:00:34 +02:00
|
|
|
DatasetProfile profile = quickWizard.getDmp().getDatasetProfile();
|
|
|
|
DatasetWizardModel datasetWizardModel = dataset.toDataModel(dmp, profile);
|
2019-03-14 19:00:02 +01:00
|
|
|
this.datasetManager.createOrUpdate(datasetWizardModel, principal);
|
2019-03-01 16:16:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<QuickWizardModel>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
|
|
|
|
}
|
|
|
|
|
2019-03-05 11:20:10 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/datasetcreate"}, consumes = "application/json", produces = "application/json")
|
|
|
|
public @ResponseBody
|
|
|
|
ResponseEntity<ResponseItem<DatasetCreateWizardModel>> addDatasetWizard(@RequestBody DatasetCreateWizardModel datasetCreateWizardModel, Principal principal) throws Exception{
|
|
|
|
for(DatasetDescriptionQuickWizardModel dataset : datasetCreateWizardModel.getDatasets().getDatasetsList()){
|
2020-09-04 16:00:34 +02:00
|
|
|
DatasetProfile profile = new DatasetProfile();
|
|
|
|
profile.setId(datasetCreateWizardModel.getDmpMeta().getDatasetProfile().getId());
|
|
|
|
profile.setLabel(datasetCreateWizardModel.getDmpMeta().getDatasetProfile().getLabel());
|
|
|
|
this.datasetManager.createOrUpdate(dataset.toDataModel(datasetCreateWizardModel.getDmpMeta().getDmp(), profile), principal);
|
2019-03-05 11:20:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetCreateWizardModel>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Dataset added!"));
|
|
|
|
}
|
2019-03-01 16:16:21 +01:00
|
|
|
}
|