|
|
|
@ -190,7 +190,7 @@ public class DmpServiceImpl implements DmpService {
|
|
|
|
|
|
|
|
|
|
this.patchAndSaveTemplates(data.getId(), model.getDescriptionTemplates());
|
|
|
|
|
|
|
|
|
|
if (!isUpdate || userScope.isSet()) {
|
|
|
|
|
if (!isUpdate && userScope.isSet()) {
|
|
|
|
|
this.addOwner(data);
|
|
|
|
|
if (model.getUsers() == null) model.setUsers(new ArrayList<>());
|
|
|
|
|
if (model.getUsers().stream().noneMatch(x-> x.getUser() != null && x.getUser().equals(this.userScope.getUserIdSafe()) && DmpUserRole.Owner.equals(x.getRole()))) model.getUsers().add(this.createOwnerPersist());
|
|
|
|
@ -203,10 +203,7 @@ public class DmpServiceImpl implements DmpService {
|
|
|
|
|
this.annotationEntityTouchedIntegrationEventHandler.handle(AnnotationEntityTouchedIntegrationEventHandler.buildEventFromPersistModel(model));
|
|
|
|
|
|
|
|
|
|
this.sendNotification(data);
|
|
|
|
|
|
|
|
|
|
if (!this.conventionService.isListNullOrEmpty(model.getUsers())){
|
|
|
|
|
this.inviteUserOrAssignUsers(data.getId(), model.getUsers());
|
|
|
|
|
}
|
|
|
|
|
this.assignUsers(data.getId(), this.inviteUserOrAssignUsers(data.getId(), model.getUsers(), false), null, false);
|
|
|
|
|
|
|
|
|
|
this.elasticService.persistDmp(data);
|
|
|
|
|
|
|
|
|
@ -566,6 +563,8 @@ public class DmpServiceImpl implements DmpService {
|
|
|
|
|
public List<DmpUser> assignUsers(UUID dmpId, List<DmpUserPersist> model, FieldSet fieldSet, boolean disableDelete) throws InvalidApplicationException, IOException {
|
|
|
|
|
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.dmpAffiliation(dmpId)), Permission.AssignDmpUsers);
|
|
|
|
|
|
|
|
|
|
if (model == null || model.stream().noneMatch(x-> x.getUser() != null && DmpUserRole.Owner.equals(x.getRole()))) throw new MyApplicationException("At least one owner required");
|
|
|
|
|
|
|
|
|
|
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, dmpId);
|
|
|
|
|
if (dmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{dmpId, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
|
|
|
|
|
|
|
|
@ -576,7 +575,7 @@ public class DmpServiceImpl implements DmpService {
|
|
|
|
|
|
|
|
|
|
List<UUID> updatedCreatedIds = new ArrayList<>();
|
|
|
|
|
for (DmpUserPersist dmpUser : model) {
|
|
|
|
|
DmpUserEntity dmpUserEntity = existingUsers.stream().filter(x-> x.getDmpId().equals(dmpId) && x.getUserId().equals(dmpUser.getUser()) && x.getRole().equals(dmpUser.getRole())).findFirst().orElse(null);
|
|
|
|
|
DmpUserEntity dmpUserEntity = existingUsers.stream().filter(x-> x.getDmpId().equals(dmpId) && x.getUserId().equals(dmpUser.getUser()) && x.getRole().equals(dmpUser.getRole()) && Objects.equals(dmpUser.getSectionId(), x.getSectionId())).findFirst().orElse(null);
|
|
|
|
|
if (dmpUserEntity == null){
|
|
|
|
|
dmpUserEntity = new DmpUserEntity();
|
|
|
|
|
dmpUserEntity.setId(UUID.randomUUID());
|
|
|
|
@ -589,10 +588,10 @@ public class DmpServiceImpl implements DmpService {
|
|
|
|
|
dmpUserEntity.setIsActive(IsActive.Active);
|
|
|
|
|
this.entityManager.persist(dmpUserEntity);
|
|
|
|
|
}
|
|
|
|
|
updatedCreatedIds.add(dmpUserEntity.getUserId());
|
|
|
|
|
updatedCreatedIds.add(dmpUserEntity.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DmpUserEntity> toDelete = existingUsers.stream().filter(x-> updatedCreatedIds.stream().noneMatch(y-> y.equals(x.getUserId()))).collect(Collectors.toList());
|
|
|
|
|
List<DmpUserEntity> toDelete = existingUsers.stream().filter(x-> updatedCreatedIds.stream().noneMatch(y-> y.equals(x.getId()))).collect(Collectors.toList());
|
|
|
|
|
if (!toDelete.isEmpty() && !disableDelete) this.deleterFactory.deleter(DmpUserDeleter.class).delete(toDelete);
|
|
|
|
|
|
|
|
|
|
this.entityManager.flush();
|
|
|
|
@ -957,6 +956,12 @@ public class DmpServiceImpl implements DmpService {
|
|
|
|
|
|
|
|
|
|
// invites
|
|
|
|
|
public void inviteUserOrAssignUsers(UUID id, List<DmpUserPersist> users) throws InvalidApplicationException, JAXBException, IOException {
|
|
|
|
|
this.inviteUserOrAssignUsers(id, users, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<DmpUserPersist> inviteUserOrAssignUsers(UUID id, List<DmpUserPersist> users, boolean persistUsers) throws InvalidApplicationException, JAXBException, IOException {
|
|
|
|
|
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.dmpAffiliation(id)), Permission.InviteDmpUsers);
|
|
|
|
|
|
|
|
|
|
DmpEntity dmp = this.queryFactory.query(DmpQuery.class).ids(id).first();
|
|
|
|
@ -986,7 +991,8 @@ public class DmpServiceImpl implements DmpService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if(!usersToAssign.isEmpty()) this.assignUsers(id, usersToAssign, null, true);
|
|
|
|
|
if(!usersToAssign.isEmpty() && persistUsers) this.assignUsers(id, usersToAssign, null, true);
|
|
|
|
|
return usersToAssign;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendDmpInvitationExistingUser(UUID userId, DmpEntity dmp, DmpUserRole role) throws InvalidApplicationException {
|
|
|
|
|