Adding user as owner on new dmp persist
This commit is contained in:
parent
e81e6dd89a
commit
e22ba13caf
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue