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);
|
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));
|
FieldSet dmpReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._dmpReferences));
|
||||||
this.censorFactory.censor(DmpReferenceCensor.class).censor(dmpReferencesFields, userId);
|
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.authorization.Permission;
|
||||||
import eu.eudat.commons.JsonHandlingService;
|
import eu.eudat.commons.JsonHandlingService;
|
||||||
import eu.eudat.commons.XmlHandlingService;
|
import eu.eudat.commons.XmlHandlingService;
|
||||||
|
import eu.eudat.commons.enums.DmpUserRole;
|
||||||
import eu.eudat.commons.enums.IsActive;
|
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.DefinitionEntity;
|
||||||
import eu.eudat.commons.types.reference.FieldEntity;
|
import eu.eudat.commons.types.reference.FieldEntity;
|
||||||
import eu.eudat.convention.ConventionService;
|
import eu.eudat.convention.ConventionService;
|
||||||
|
@ -83,6 +85,8 @@ public class DmpServiceImpl implements DmpService {
|
||||||
|
|
||||||
private final JsonHandlingService jsonHandlingService;
|
private final JsonHandlingService jsonHandlingService;
|
||||||
|
|
||||||
|
private final UserScope userScope;
|
||||||
|
|
||||||
private final EventBroker eventBroker;
|
private final EventBroker eventBroker;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -91,11 +95,13 @@ public class DmpServiceImpl implements DmpService {
|
||||||
AuthorizationService authorizationService,
|
AuthorizationService authorizationService,
|
||||||
DeleterFactory deleterFactory,
|
DeleterFactory deleterFactory,
|
||||||
BuilderFactory builderFactory,
|
BuilderFactory builderFactory,
|
||||||
QueryFactory queryFactory, ConventionService conventionService,
|
QueryFactory queryFactory,
|
||||||
|
ConventionService conventionService,
|
||||||
ErrorThesaurusProperties errors,
|
ErrorThesaurusProperties errors,
|
||||||
MessageSource messageSource,
|
MessageSource messageSource,
|
||||||
XmlHandlingService xmlHandlingService, JsonHandlingService jsonHandlingService,
|
XmlHandlingService xmlHandlingService,
|
||||||
EventBroker eventBroker) {
|
JsonHandlingService jsonHandlingService,
|
||||||
|
UserScope userScope, EventBroker eventBroker) {
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
this.deleterFactory = deleterFactory;
|
this.deleterFactory = deleterFactory;
|
||||||
|
@ -106,6 +112,7 @@ public class DmpServiceImpl implements DmpService {
|
||||||
this.messageSource = messageSource;
|
this.messageSource = messageSource;
|
||||||
this.xmlHandlingService = xmlHandlingService;
|
this.xmlHandlingService = xmlHandlingService;
|
||||||
this.jsonHandlingService = jsonHandlingService;
|
this.jsonHandlingService = jsonHandlingService;
|
||||||
|
this.userScope = userScope;
|
||||||
this.eventBroker = eventBroker;
|
this.eventBroker = eventBroker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,6 +180,7 @@ public class DmpServiceImpl implements DmpService {
|
||||||
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
|
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
|
||||||
|
|
||||||
DmpEntity data;
|
DmpEntity data;
|
||||||
|
DmpUserEntity dmpUserEntity = new DmpUserEntity();
|
||||||
if (isUpdate) {
|
if (isUpdate) {
|
||||||
data = this.entityManager.find(DmpEntity.class, model.getId());
|
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()));
|
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.setVersion((short) 1);
|
||||||
data.setIsActive(IsActive.Active);
|
data.setIsActive(IsActive.Active);
|
||||||
data.setCreatedAt(Instant.now());
|
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());
|
data.setLabel(model.getLabel());
|
||||||
|
@ -193,8 +209,10 @@ public class DmpServiceImpl implements DmpService {
|
||||||
data.setUpdatedAt(Instant.now());
|
data.setUpdatedAt(Instant.now());
|
||||||
if (isUpdate)
|
if (isUpdate)
|
||||||
this.entityManager.merge(data);
|
this.entityManager.merge(data);
|
||||||
else
|
else {
|
||||||
this.entityManager.persist(data);
|
this.entityManager.persist(data);
|
||||||
|
this.entityManager.persist(dmpUserEntity);
|
||||||
|
}
|
||||||
|
|
||||||
this.entityManager.flush();
|
this.entityManager.flush();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue