diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java index 30e69539b..e0e84e232 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java @@ -40,6 +40,8 @@ public class DmpCensor extends BaseCensor { this.authService.authorizeForce(Permission.BrowseDmp); + FieldSet dmpUsersFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._dmpUsers)); + this.censorFactory.censor(DmpUserCensor.class).censor(dmpUsersFields, userId); FieldSet dmpReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._dmpReferences)); this.censorFactory.censor(DmpReferenceCensor.class).censor(dmpReferencesFields, userId); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java index fe7850b6a..9cc220d52 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java @@ -5,7 +5,9 @@ import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.Permission; import eu.eudat.commons.JsonHandlingService; import eu.eudat.commons.XmlHandlingService; +import eu.eudat.commons.enums.DmpUserRole; import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.types.reference.DefinitionEntity; import eu.eudat.commons.types.reference.FieldEntity; import eu.eudat.convention.ConventionService; @@ -83,6 +85,8 @@ public class DmpServiceImpl implements DmpService { private final JsonHandlingService jsonHandlingService; + private final UserScope userScope; + private final EventBroker eventBroker; @Autowired @@ -91,11 +95,13 @@ public class DmpServiceImpl implements DmpService { AuthorizationService authorizationService, DeleterFactory deleterFactory, BuilderFactory builderFactory, - QueryFactory queryFactory, ConventionService conventionService, + QueryFactory queryFactory, + ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, - XmlHandlingService xmlHandlingService, JsonHandlingService jsonHandlingService, - EventBroker eventBroker) { + XmlHandlingService xmlHandlingService, + JsonHandlingService jsonHandlingService, + UserScope userScope, EventBroker eventBroker) { this.entityManager = entityManager; this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; @@ -106,6 +112,7 @@ public class DmpServiceImpl implements DmpService { this.messageSource = messageSource; this.xmlHandlingService = xmlHandlingService; this.jsonHandlingService = jsonHandlingService; + this.userScope = userScope; this.eventBroker = eventBroker; } @@ -173,6 +180,7 @@ public class DmpServiceImpl implements DmpService { Boolean isUpdate = this.conventionService.isValidGuid(model.getId()); DmpEntity data; + DmpUserEntity dmpUserEntity = new DmpUserEntity(); if (isUpdate) { data = this.entityManager.find(DmpEntity.class, model.getId()); if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -184,6 +192,14 @@ public class DmpServiceImpl implements DmpService { data.setVersion((short) 1); data.setIsActive(IsActive.Active); data.setCreatedAt(Instant.now()); + + dmpUserEntity.setId(UUID.randomUUID()); + dmpUserEntity.setDmp(data.getId()); + dmpUserEntity.setUser(userScope.getUserIdSafe()); + dmpUserEntity.setRole(DmpUserRole.Owner); + dmpUserEntity.setCreatedAt(Instant.now()); + dmpUserEntity.setUpdatedAt(Instant.now()); + dmpUserEntity.setIsActive(IsActive.Active); } data.setLabel(model.getLabel()); @@ -193,8 +209,10 @@ public class DmpServiceImpl implements DmpService { data.setUpdatedAt(Instant.now()); if (isUpdate) this.entityManager.merge(data); - else + else { this.entityManager.persist(data); + this.entityManager.persist(dmpUserEntity); + } this.entityManager.flush();