Refactors DMP creator to use the intermediate table from database and not the column.

This commit is contained in:
gkolokythas 2019-05-31 11:38:04 +03:00
parent 71604b0ae1
commit 175a1e0747
4 changed files with 27 additions and 10 deletions

View File

@ -102,7 +102,7 @@ public class DataManagementPlanManager {
item.setDataset( item.setDataset(
item.getDataset().stream() item.getDataset().stream()
.filter(ds -> !ds.getStatus().equals(Dataset.Status.DELETED.getValue())).collect(Collectors.toList()).stream() .filter(ds -> !ds.getStatus().equals(Dataset.Status.DELETED.getValue())).collect(Collectors.toList()).stream()
.filter(dataset -> dataset.getDmp().getCreator().getId().equals(principalID) .filter(dataset -> dataset.getDmp().getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getId().equals(principalID)
|| dataset.isPublic() || dataset.isPublic()
|| dataset.getDmp().getUsers().stream() || dataset.getDmp().getUsers().stream()
.filter(x -> x.getUser().getId().equals(principalID)) .filter(x -> x.getUser().getId().equals(principalID))
@ -270,7 +270,7 @@ public class DataManagementPlanManager {
public eu.eudat.models.data.dmp.DataManagementPlan getSingle(String id, Principal principal, DynamicProjectConfiguration dynamicProjectConfiguration) throws InstantiationException, IllegalAccessException { public eu.eudat.models.data.dmp.DataManagementPlan getSingle(String id, Principal principal, DynamicProjectConfiguration dynamicProjectConfiguration) throws InstantiationException, IllegalAccessException {
DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
if (dataManagementPlanEntity.getCreator().getId() != principal.getId() && dataManagementPlanEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0) if (dataManagementPlanEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0)
throw new UnauthorisedException(); throw new UnauthorisedException();
eu.eudat.models.data.dmp.DataManagementPlan datamanagementPlan = new eu.eudat.models.data.dmp.DataManagementPlan(); eu.eudat.models.data.dmp.DataManagementPlan datamanagementPlan = new eu.eudat.models.data.dmp.DataManagementPlan();
datamanagementPlan.fromDataModel(dataManagementPlanEntity); datamanagementPlan.fromDataModel(dataManagementPlanEntity);
@ -296,7 +296,7 @@ public class DataManagementPlanManager {
public DataManagementPlanOverviewModel getOverviewSingle(String id, Principal principal) throws InstantiationException, IllegalAccessException { public DataManagementPlanOverviewModel getOverviewSingle(String id, Principal principal) throws InstantiationException, IllegalAccessException {
DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
if (dataManagementPlanEntity.getCreator().getId() != principal.getId() && dataManagementPlanEntity.getUsers() if (dataManagementPlanEntity.getUsers()
.stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()) .stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId())
.collect(Collectors.toList()).size() == 0) .collect(Collectors.toList()).size() == 0)
throw new UnauthorisedException(); throw new UnauthorisedException();
@ -408,7 +408,7 @@ public class DataManagementPlanManager {
DMP newDmp = dataManagementPlan.toDataModel(); DMP newDmp = dataManagementPlan.toDataModel();
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId()); UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
newDmp.setCreator(user); //newDmp.setCreator(user);
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao()); createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao()); createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
@ -417,7 +417,8 @@ public class DataManagementPlanManager {
try { try {
DMP dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId()); DMP dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId());
newDmp.setCreated(dmp.getCreated()); newDmp.setCreated(dmp.getCreated());
if (dmp.getCreator().getId().equals(principal.getId())) { if (dmp.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId())
.collect(Collectors.toList()).size() == 0) {
List<UserDMP> userDMPList = dmp.getUsers().stream().collect(Collectors.toList()); List<UserDMP> userDMPList = dmp.getUsers().stream().collect(Collectors.toList());
for (UserInfoListingModel userInfoListingModel : dataManagementPlan.getUsers()) { for (UserInfoListingModel userInfoListingModel : dataManagementPlan.getUsers()) {
for(UserDMP userDMP : userDMPList) { for(UserDMP userDMP : userDMPList) {
@ -469,11 +470,18 @@ public class DataManagementPlanManager {
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao()); createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build(); UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao(), user); createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao(), user);
newDmp.setCreator(user);
newDmp.setGroupId(oldDmp.getGroupId()); newDmp.setGroupId(oldDmp.getGroupId());
newDmp.setVersion(oldDmp.getVersion() + 1); newDmp.setVersion(oldDmp.getVersion() + 1);
newDmp.setId(null); newDmp.setId(null);
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp); newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
// Assign creator.
UserDMP userDMP = new UserDMP();
userDMP.setDmp(newDmp);
userDMP.setUser(user);
userDMP.setRole((UserDMP.UserDMPRoles.OWNER.getValue()));
copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()); copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao());
} else { } else {
throw new DMPNewVersionException("Version to update not the latest."); throw new DMPNewVersionException("Version to update not the latest.");
@ -486,11 +494,17 @@ public class DataManagementPlanManager {
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao()); createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build(); UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao(), user); createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao(), user);
newDmp.setCreator(user);
newDmp.setGroupId(UUID.randomUUID()); newDmp.setGroupId(UUID.randomUUID());
newDmp.setVersion(0); newDmp.setVersion(0);
newDmp.setId(null); newDmp.setId(null);
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp); newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
// Assign creator.
UserDMP userDMP = new UserDMP();
userDMP.setDmp(newDmp);
userDMP.setUser(user);
userDMP.setRole((UserDMP.UserDMPRoles.OWNER.getValue()));
copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()); copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao());
} }

View File

@ -1,5 +1,6 @@
package eu.eudat.logic.managers; package eu.eudat.logic.managers;
import eu.eudat.data.entities.UserDMP;
import eu.eudat.exceptions.project.ProjectWithDMPsDeleteException; import eu.eudat.exceptions.project.ProjectWithDMPsDeleteException;
import eu.eudat.logic.builders.entity.ContentBuilder; import eu.eudat.logic.builders.entity.ContentBuilder;
import eu.eudat.logic.builders.model.models.ProjectBuilder; import eu.eudat.logic.builders.model.models.ProjectBuilder;
@ -64,7 +65,8 @@ public class ProjectManager {
if (fieldsGroup.equals("listing")) { if (fieldsGroup.equals("listing")) {
projectsFuture = pagedItems.withHint(HintedModelFactory.getHint(ProjectListingModel.class)).selectAsync(item -> { projectsFuture = pagedItems.withHint(HintedModelFactory.getHint(ProjectListingModel.class)).selectAsync(item -> {
item.setDmps(item.getDmps().stream().filter( item.setDmps(item.getDmps().stream().filter(
dmp -> dmp.getCreator().getId().equals(principal.getId()) || dmp.getUsers().stream().filter(user -> user.getUser().getId().equals(principal.getId())).collect(Collectors.toList()).size() > 0) dmp -> dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getId().equals(principal.getId())
|| dmp.getUsers().stream().filter(user -> user.getUser().getId().equals(principal.getId())).collect(Collectors.toList()).size() > 0)
.collect(Collectors.groupingBy(DMP::getGroupId)) .collect(Collectors.groupingBy(DMP::getGroupId))
.values().stream() .values().stream()
.map(dmps -> dmps.stream().reduce((first, second) -> { .map(dmps -> dmps.stream().reduce((first, second) -> {

View File

@ -42,7 +42,7 @@ public class QuickWizardManager {
DMP newDmp = dataManagementPlan.toDataModel(); DMP newDmp = dataManagementPlan.toDataModel();
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId()); UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
createProjectIfItDoesntExist(newDmp, user); createProjectIfItDoesntExist(newDmp, user);
newDmp.setCreator(user); //newDmp.setCreator(user);
DMP dmpret = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp); DMP dmpret = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
if (dataManagementPlan.getAssociatedUsers().size() == 0) if (dataManagementPlan.getAssociatedUsers().size() == 0)
assignUser(newDmp, user, apiContext); assignUser(newDmp, user, apiContext);

View File

@ -211,7 +211,8 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
if (fieldOptional.isPresent()) item.setValue(fieldOptional.get().get("value")); if (fieldOptional.isPresent()) item.setValue(fieldOptional.get().get("value"));
}); });
} }
if (entity.getCreator() != null) this.creator.fromDataModel(entity.getCreator()); if (entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())))
this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser());
if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) {
this.profiles = new LinkedList<>(); this.profiles = new LinkedList<>();