package eu.eudat.controllers; import eu.eudat.authorization.Permission; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.logic.managers.DatasetManager; import eu.eudat.logic.managers.QuickWizardManager; import eu.eudat.logic.services.ApiContext; import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.quickwizard.DatasetCreateWizardModel; import eu.eudat.models.data.quickwizard.DatasetDescriptionQuickWizardModel; import eu.eudat.models.data.quickwizard.QuickWizardModel; import eu.eudat.types.ApiMessageCode; import gr.cite.commons.web.authz.service.AuthorizationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import jakarta.transaction.Transactional; import jakarta.validation.Valid; @RestController @CrossOrigin @RequestMapping(value = {"/api/quick-wizard/"}) public class QuickWizardController extends BaseController { private QuickWizardManager quickWizardManager; private DatasetManager datasetManager; private final AuthorizationService authorizationService; private final UserScope userScope; @Autowired public QuickWizardController(ApiContext apiContext, QuickWizardManager quickWizardManager, DatasetManager datasetManager, AuthorizationService authorizationService, UserScope userScope) { super(apiContext); this.quickWizardManager = quickWizardManager; this.datasetManager = datasetManager; this.authorizationService = authorizationService; this.userScope = userScope; } @Transactional @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> addQuickWizardModel(@Valid @RequestBody QuickWizardModel quickWizard) throws Exception { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); // Funder funderEntity;//TODO // //Create Funder // if (quickWizard.getFunder() == null) { // funderEntity = null; // } else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() == null) { // funderEntity = null; // } else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() != null) { // funderEntity = this.quickWizardManager.createOrUpdate(quickWizard.getFunder().toDataFunder()); // } else { // funderEntity = quickWizard.getFunder().getExistFunder().toDataModel(); // } // Grant grantEntity; //TODO // //Create Grant // if (quickWizard.getGrant() == null) { // grantEntity = null; // } else if (quickWizard.getGrant().getExistGrant() == null && quickWizard.getGrant().getLabel() == null) { // grantEntity = null; // } else if (quickWizard.getGrant().getExistGrant() == null) { // grantEntity = this.quickWizardManager.createOrUpdate(quickWizard.getGrant().toDataGrant()); // } else { // grantEntity = quickWizard.getGrant().getExistGrant().toDataModel(); // } // Project projectEntity; //TODO // //Create Project // if (quickWizard.getProject().getExistProject() == null // && quickWizard.getProject().getLabel() == null) { // projectEntity = null; // } else if (quickWizard.getProject().getExistProject() == null && quickWizard.getProject().getLabel() != null) { // projectEntity = this.quickWizardManager.createOrUpdate(quickWizard.getProject().toDataProject()); // } else { // projectEntity = quickWizard.getProject().getExistProject().toDataModel(); // } //Create Dmp // DataManagementPlan dataManagementPlan = quickWizard.getDmp().toDataDmp(/*grantEntity,*/ userScope); // DmpEntity dmpEntity = this.quickWizardManager.createOrUpdate(dataManagementPlan/*, funderEntity*/); // // //Create Datasets // quickWizard.getDmp().setId(dmpEntity.getId()); // for (DatasetDescriptionQuickWizardModel dataset : quickWizard.getDatasets().getDatasetsList()) { // DataManagementPlan dmp = quickWizard.getDmp().toDataDmp(/*grantEntity , projectEntity, */ userScope); // DescriptionTemplateEntity profile = quickWizard.getDmp().getDatasetProfile(); // DatasetWizardModel datasetWizardModel = dataset.toDataModel(dmp, profile); // this.datasetManager.createOrUpdate(datasetWizardModel); // } return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created")); } @RequestMapping(method = RequestMethod.POST, value = {"/datasetcreate"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> addDatasetWizard(@RequestBody DatasetCreateWizardModel datasetCreateWizardModel) throws Exception{ this.authorizationService.authorizeForce(Permission.AuthenticatedRole); for(DatasetDescriptionQuickWizardModel dataset : datasetCreateWizardModel.getDatasets().getDatasetsList()){ DescriptionTemplateEntity profile = new DescriptionTemplateEntity(); // profile.setId(datasetCreateWizardModel.getDmpMeta().getDatasetProfile().getId()); // profile.setLabel(datasetCreateWizardModel.getDmpMeta().getDatasetProfile().getLabel()); this.datasetManager.createOrUpdate(dataset.toDataModel(profile)); } return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Dataset added!")); } }