2019-03-01 16:16:21 +01:00
|
|
|
package eu.eudat.controllers;
|
|
|
|
|
|
|
|
|
|
|
|
import eu.eudat.logic.managers.*;
|
|
|
|
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;
|
|
|
|
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.*;
|
2019-03-05 11:20:10 +01:00
|
|
|
import eu.eudat.models.data.quickwizard.DatasetCreateWizardModel;
|
2019-03-01 16:16:21 +01:00
|
|
|
|
|
|
|
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;
|
2019-03-05 12:21:04 +01:00
|
|
|
private ProjectManager projectManager;
|
2019-03-01 16:16:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
private DatasetManager datasetManager;
|
|
|
|
|
|
|
|
@Autowired
|
2019-03-05 12:21:04 +01:00
|
|
|
public QuickWizardController(ApiContext apiContext, QuickWizardManager quickWizardManager, DatasetManager datasetManager, ProjectManager projectManager) {
|
2019-03-01 16:16:21 +01:00
|
|
|
super(apiContext);
|
|
|
|
this.quickWizardManager = quickWizardManager;
|
|
|
|
this.datasetManager = datasetManager;
|
2019-03-05 12:21:04 +01:00
|
|
|
this.projectManager = projectManager;
|
2019-03-01 16:16:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@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-03-05 12:21:04 +01:00
|
|
|
eu.eudat.data.entities.Project projectEntity;
|
2019-03-01 16:16:21 +01:00
|
|
|
//Create Project
|
2019-03-05 12:21:04 +01:00
|
|
|
if (quickWizard.getProject().getExistProject() == null) {
|
2019-03-05 16:46:18 +01:00
|
|
|
projectEntity = this.quickWizardManager.createOrUpdate(quickWizard.getProject().toDataProject(), principal);
|
2019-03-05 12:21:04 +01:00
|
|
|
} else {
|
|
|
|
projectEntity = quickWizard.getProject().getExistProject().toDataModel();
|
|
|
|
}
|
2019-03-01 16:16:21 +01:00
|
|
|
//Create Dmp
|
2019-03-05 12:21:04 +01:00
|
|
|
eu.eudat.data.entities.DMP dmpEntity = this.quickWizardManager.createOrUpdate(
|
|
|
|
quickWizard.getDmp().toDataDmp(
|
|
|
|
projectEntity,
|
|
|
|
principal),
|
|
|
|
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-03-14 19:00:02 +01:00
|
|
|
DataManagementPlan dmp = quickWizard.getDmp().toDataDmp( projectEntity, principal);
|
|
|
|
UUID uuid = quickWizard.getDmp().getDatasetProfile().getId();
|
|
|
|
DatasetWizardModel datasetWizardModel = dataset.toDataModel(dmp, uuid);
|
|
|
|
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()){
|
2019-03-05 16:33:59 +01:00
|
|
|
this.datasetManager.createOrUpdate(dataset.toDataModel(datasetCreateWizardModel.getDmpMeta().getDmp(), datasetCreateWizardModel.getDmpMeta().getDatasetProfile().getId()), 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
|
|
|
}
|