Properly remove associate Collaborators from a DMP

This commit is contained in:
George Kalampokis 2020-07-02 17:08:38 +03:00
parent 710b49fc83
commit 64624ca6f1
1 changed files with 18 additions and 1 deletions

View File

@ -368,6 +368,14 @@ public class DataManagementPlanManager {
apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant());
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
if (dataManagementPlan.getUsers() != null && !dataManagementPlan.getUsers().isEmpty()) {
clearUsers(newDmp);
for (UserInfoListingModel userListing : dataManagementPlan.getUsers()) {
UserInfo tempUser = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userListing.getId());
assignUser(dmp, tempUser, UserDMP.UserDMPRoles.fromInteger(userListing.getRole()));
}
}
// Dataset manipulation for when the DMP is set to be finalized.
if (dataManagementPlan.getStatus() == DMP.DMPStatus.FINALISED.getValue()) {
if (dataManagementPlan.getDatasetsToBeFinalized() != null && !dataManagementPlan.getDatasetsToBeFinalized().isEmpty()) {
@ -1445,13 +1453,22 @@ public class DataManagementPlanManager {
* */
private void assignUser(DMP dmp, UserInfo userInfo) {
this.assignUser(dmp, userInfo, UserDMP.UserDMPRoles.OWNER);
}
private void assignUser(DMP dmp, UserInfo userInfo, UserDMP.UserDMPRoles role) {
UserDMP userDMP = new UserDMP();
userDMP.setDmp(dmp);
userDMP.setUser(userInfo);
userDMP.setRole(UserDMP.UserDMPRoles.OWNER.getValue());
userDMP.setRole(role.getValue());
databaseRepository.getUserDmpDao().createOrUpdate(userDMP);
}
private void clearUsers(DMP dmp) {
List<UserDMP> userDMPs = apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where(((builder, root) -> builder.equal(root.get("dmp").get("id"), dmp.getId()))).toList();
userDMPs.forEach(userDMP -> apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().delete(userDMP));
}
private void assignGrandUserIfInternal(DMP dmp, UserInfo user) {
if (dmp.getGrant().getCreationUser() == null && (dmp.getGrant().getReference() != null && dmp.getGrant().getReference().startsWith("dmp:"))) {
dmp.getGrant().setCreationUser(user);