Fixed Various issues when creating or updating DMP with datasets
This commit is contained in:
parent
70e5116879
commit
dc83a3a09c
|
@ -461,8 +461,34 @@ public class DataManagementPlanManager {
|
|||
}
|
||||
|
||||
public DMP createOrUpdateWithDatasets(DataManagementPlanEditorModel dataManagementPlan, Principal principal) throws Exception {
|
||||
if (dataManagementPlan.getId() != null) {
|
||||
DMP dmp1 = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId());
|
||||
|
||||
if (!isUserOwnerOfDmp(dmp1, principal)) {
|
||||
throw new Exception("User not being the creator is not authorized to edit this DMP.");
|
||||
}
|
||||
if (dmp1.getModified().getTime() != dataManagementPlan.getModified().getTime()) {
|
||||
throw new Exception("Another user have already edit that DMP.");
|
||||
}
|
||||
List<Dataset> datasetList = new ArrayList<>(dmp1.getDataset());
|
||||
for (Dataset dataset : datasetList) {
|
||||
if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> dataset.getProfile().getId().equals(associatedProfile.getId())).findAny().orElse(null) == null)
|
||||
throw new Exception("Dataset Template for Dataset Description is missing from the DMP.");
|
||||
}
|
||||
if (dataManagementPlan.getStatus() == (int) DMP.DMPStatus.FINALISED.getValue() && dmp1.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()))
|
||||
throw new Exception("DMP is finalized, therefore cannot be edited.");
|
||||
}
|
||||
List<Dataset> datasets = new ArrayList<>();
|
||||
DMP tempDMP = dataManagementPlan.toDataModel();
|
||||
if (tempDMP.getStatus() == (int) DMP.DMPStatus.FINALISED.getValue()) {
|
||||
checkDmpValidationRules(tempDMP);
|
||||
}
|
||||
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
|
||||
createOrganisationsIfTheyDontExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
|
||||
createResearchersIfTheyDontExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao(), user);
|
||||
createFunderIfItDoesntExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getFunderDao());
|
||||
createGrantIfItDoesntExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao());
|
||||
|
||||
for (DatasetWizardModel datasetWizardModel: dataManagementPlan.getDatasets()) {
|
||||
datasetWizardModel.setDmp(new DataManagementPlan().fromDataModel(tempDMP));
|
||||
Dataset dataset = datasetManager.createOrUpdate(datasetWizardModel, principal);
|
||||
|
|
|
@ -236,7 +236,7 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
|
|||
this.id = entity.getId();
|
||||
this.profile = entity.getProfile() != null ? new Tuple<UUID, String>(entity.getProfile().getId(), entity.getProfile().getLabel()) : null;
|
||||
this.organisations = entity.getOrganisations() != null ? entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
|
||||
this.researchers = entity.getOrganisations() != null ? entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>();
|
||||
this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>();
|
||||
this.version = entity.getVersion();
|
||||
this.groupId = this.groupId == null ? null : entity.getGroupId();
|
||||
this.label = entity.getLabel();
|
||||
|
|
|
@ -4,6 +4,7 @@ import eu.eudat.models.DataModel;
|
|||
import eu.eudat.logic.utilities.helpers.LabelGenerator;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Organisation implements DataModel<eu.eudat.data.entities.Organisation, Organisation>, LabelGenerator {
|
||||
private String label;
|
||||
|
@ -85,6 +86,9 @@ public class Organisation implements DataModel<eu.eudat.data.entities.Organisati
|
|||
organisationEntity.setReference(this.key + ":" + this.reference);
|
||||
}
|
||||
}
|
||||
if (this.id != null) {
|
||||
organisationEntity.setId(UUID.fromString(this.id));
|
||||
}
|
||||
organisationEntity.setLabel(this.name);
|
||||
organisationEntity.setUri(this.label);
|
||||
organisationEntity.setCreated(new Date());
|
||||
|
|
Loading…
Reference in New Issue