Fixes bug on DMP updating modified date.

This commit is contained in:
gkolokythas 2019-05-30 15:41:23 +03:00
parent ae67197818
commit 8705f916b2
2 changed files with 29 additions and 29 deletions

View File

@ -405,32 +405,41 @@ public class DataManagementPlanManager {
}
public void createOrUpdate(ApiContext apiContext, DataManagementPlan dataManagementPlan, Principal principal) throws Exception {
DMP newDmp = dataManagementPlan.toDataModel();
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao(), user);
newDmp.setCreator(user);
DMP dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId());
if (dmp.getCreator().getId().equals(principal.getId())) {
List<UserDMP> userDMPList = dmp.getUsers().stream().collect(Collectors.toList());
for (UserInfoListingModel userInfoListingModel : dataManagementPlan.getUsers()) {
for(UserDMP userDMP : userDMPList) {
if (!(userDMP.getUser().getId().equals(userInfoListingModel.getId()))) {
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().delete(userDMP);
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao(), user);
try {
DMP dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId());
newDmp.setCreated(dmp.getCreated());
if (dmp.getCreator().getId().equals(principal.getId())) {
List<UserDMP> userDMPList = dmp.getUsers().stream().collect(Collectors.toList());
for (UserInfoListingModel userInfoListingModel : dataManagementPlan.getUsers()) {
for(UserDMP userDMP : userDMPList) {
if (!(userDMP.getUser().getId().equals(userInfoListingModel.getId()))) {
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().delete(userDMP);
}
}
}
}
} catch (Exception e) {
newDmp.setCreated(new Date());
}
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
if (dataManagementPlan.getStatus() == DMP.DMPStatus.FINALISED.getValue()) {
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()
.asQueryable().where((builder, root) -> root.get("id").in(dataManagementPlan.getDatasets()
.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())))
.update(root -> root.<Integer>get("status"), Dataset.Status.FINALISED.getValue());
}
if (dataManagementPlan.getAssociatedUsers().size() == 0)
assignUser(newDmp, user, apiContext);
}

View File

@ -36,6 +36,7 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
private List<UserListingModel> associatedUsers;
private DataManagementPlanProfile definition;
private eu.eudat.models.data.userinfo.UserInfo creator;
private Date modified;
private Date created;
private List<DynamicFieldWithValue> dynamicFields;
private Map<String, Object> properties;
@ -125,6 +126,13 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.profiles = profiles;
}
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
public Date getCreated() {
return created;
}
@ -226,6 +234,7 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
}*/
}
this.datasets = entity.getDataset().stream().map(item -> new DatasetListingModel().fromDataModel(item)).collect(Collectors.toList());
this.modified = entity.getModified();
this.created = entity.getCreated();
this.description = entity.getDescription();
this.status = entity.getStatus();
@ -248,20 +257,11 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
if (this.researchers != null && !this.researchers.isEmpty())
dataManagementPlanEntity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
dataManagementPlanEntity.setVersion(this.version);
dataManagementPlanEntity.setLabel(this.label);
if (this.project != null) dataManagementPlanEntity.setProject(this.project.toDataModel());
dataManagementPlanEntity.setStatus((short) this.status);
dataManagementPlanEntity.setDescription(this.description);
if (this.profiles != null) {
/* Document associatedProfileDoc = XmlBuilder.getDocument();
Element associatedProfilesElement = associatedProfileDoc.createElement("profiles");
for (AssociatedProfile associatedProfile : this.profiles) {
associatedProfilesElement.appendChild(associatedProfile.toXml(associatedProfileDoc));
}
associatedProfileDoc.appendChild(associatedProfilesElement);
dataManagementPlanEntity.setAssociatedDmps(XmlBuilder.generateXml(associatedProfileDoc));*/
Set<DatasetProfile> datasetProfiles = new HashSet<>();
for (AssociatedProfile profile : this.profiles) {
datasetProfiles.add(profile.toData());
@ -270,20 +270,11 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
}
dataManagementPlanEntity.setProperties(this.properties != null ? JSONObject.toJSONString(this.properties) : null);
dataManagementPlanEntity.setGroupId(this.groupId != null ? this.groupId : UUID.randomUUID());
dataManagementPlanEntity.setModified(this.modified != null ? this.modified : new Date());
dataManagementPlanEntity.setCreated(this.created != null ? this.created : new Date());
if (this.dynamicFields != null)
dataManagementPlanEntity.setDmpProperties(JSONObject.toJSONString(this.dynamicFields.stream().filter(item -> item.getValue() != null).collect(Collectors.toMap(DynamicFieldWithValue::getId, DynamicFieldWithValue::getValue))));
/*if (this.associatedUsers != null && !this.associatedUsers.isEmpty()) {
List<UserDMP> userDMPList = new LinkedList<>();
for(UserListingModel userListingModel: this.associatedUsers) {
UserDMP userDMP = new UserDMP();
userDMP.setUser(userListingModel.toDataModel());
userDMPList.add(userDMP);
}
dataManagementPlanEntity.setUsers((Set<UserDMP>) userDMPList);
}*/
return dataManagementPlanEntity;
}