add section id to DmpUser

This commit is contained in:
amentis 2024-02-21 12:46:24 +02:00
parent a1394e6629
commit 4738a92f6e
10 changed files with 116 additions and 3 deletions

View File

@ -36,6 +36,10 @@ public class DmpUserEntity extends TenantScopedBaseEntity {
public static final String _role = "role"; public static final String _role = "role";
@Column(name = "section_id", columnDefinition = "uuid", nullable = true)
private UUID sectionId;
public static final String _sectionId = "sectionId";
@Column(name = "created_at", nullable = false) @Column(name = "created_at", nullable = false)
private Instant createdAt; private Instant createdAt;
@ -84,6 +88,14 @@ public class DmpUserEntity extends TenantScopedBaseEntity {
this.role = role; this.role = role;
} }
public UUID getSectionId() {
return sectionId;
}
public void setSectionId(UUID sectionId) {
this.sectionId = sectionId;
}
public Instant getCreatedAt() { public Instant getCreatedAt() {
return createdAt; return createdAt;
} }

View File

@ -30,6 +30,9 @@ public class DmpUser {
public static final String _role = "role"; public static final String _role = "role";
private UUID sectionId;
public static final String _sectionId = "sectionId";
private Instant createdAt; private Instant createdAt;
public static final String _createdAt = "createdAt"; public static final String _createdAt = "createdAt";
@ -73,6 +76,14 @@ public class DmpUser {
this.role = role; this.role = role;
} }
public UUID getSectionId() {
return sectionId;
}
public void setSectionId(UUID sectionId) {
this.sectionId = sectionId;
}
public Instant getCreatedAt() { public Instant getCreatedAt() {
return createdAt; return createdAt;
} }

View File

@ -64,6 +64,7 @@ public class DmpUserBuilder extends BaseBuilder<DmpUser, DmpUserEntity>{
DmpUser m = new DmpUser(); DmpUser m = new DmpUser();
if (fields.hasField(this.asIndexer(DmpUser._id))) m.setId(d.getId()); if (fields.hasField(this.asIndexer(DmpUser._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(DmpUser._role))) m.setRole(d.getRole()); if (fields.hasField(this.asIndexer(DmpUser._role))) m.setRole(d.getRole());
if (fields.hasField(this.asIndexer(DmpUser._sectionId))) m.setSectionId(d.getSectionId());
if (fields.hasField(this.asIndexer(DmpUser._createdAt))) m.setCreatedAt(d.getCreatedAt()); if (fields.hasField(this.asIndexer(DmpUser._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(DmpUser._updatedAt))) m.setUpdatedAt(d.getUpdatedAt()); if (fields.hasField(this.asIndexer(DmpUser._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(DmpReference._hash))) m.setHash(this.hashValue(d.getUpdatedAt())); if (fields.hasField(this.asIndexer(DmpReference._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));

View File

@ -21,6 +21,12 @@ public class DmpUserPersist {
public static final String _user = "user"; public static final String _user = "user";
private String email;
public static final String _email = "email";
private UUID sectionId;
public static final String _sectionId = "sectionId";
private DmpUserRole role; private DmpUserRole role;
public static final String _role = "role"; public static final String _role = "role";
@ -33,6 +39,22 @@ public class DmpUserPersist {
this.user = user; this.user = user;
} }
public UUID getSectionId() {
return sectionId;
}
public void setSectionId(UUID sectionId) {
this.sectionId = sectionId;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public DmpUserRole getRole() { public DmpUserRole getRole() {
return role; return role;
} }
@ -63,11 +85,20 @@ public class DmpUserPersist {
protected List<Specification> specifications(DmpUserPersist item) { protected List<Specification> specifications(DmpUserPersist item) {
return Arrays.asList( return Arrays.asList(
this.spec() this.spec()
.iff(() -> this.isEmpty(item.getEmail()))
.must(() -> this.isValidGuid(item.getUser())) .must(() -> this.isValidGuid(item.getUser()))
.failOn(DmpUserPersist._user).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserPersist._user}, LocaleContextHolder.getLocale())), .failOn(DmpUserPersist._user).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserPersist._user}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getUser()))
.must(() -> !this.isEmpty(item.getEmail()))
.failOn(DmpUserPersist._email).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserPersist._email}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.must(() -> !this.isNull(item.getRole())) .must(() -> !this.isNull(item.getRole()))
.failOn(DmpUserPersist._role).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserPersist._role}, LocaleContextHolder.getLocale())) .failOn(DmpUserPersist._role).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserPersist._role}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isNull(item.getSectionId()))
.must(() -> this.isValidGuid(item.getSectionId()))
.failOn(DmpUserPersist._sectionId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpUserPersist._sectionId}, LocaleContextHolder.getLocale()))
); );
} }
} }

View File

@ -37,6 +37,8 @@ public class DmpUserQuery extends QueryBase<DmpUserEntity> {
private Collection<DmpUserRole> userRoles; private Collection<DmpUserRole> userRoles;
private Collection<UUID> sectionIds;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
public DmpUserQuery ids(UUID value) { public DmpUserQuery ids(UUID value) {
@ -114,6 +116,21 @@ public class DmpUserQuery extends QueryBase<DmpUserEntity> {
return this; return this;
} }
public DmpUserQuery sectionIds(UUID value) {
this.sectionIds = List.of(value);
return this;
}
public DmpUserQuery sectionIds(UUID... value) {
this.sectionIds = Arrays.asList(value);
return this;
}
public DmpUserQuery sectionIds(Collection<UUID> values) {
this.sectionIds = values;
return this;
}
public DmpUserQuery authorize(EnumSet<AuthorizationFlags> values) { public DmpUserQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values; this.authorize = values;
return this; return this;
@ -194,6 +211,12 @@ public class DmpUserQuery extends QueryBase<DmpUserEntity> {
inClause.value(item); inClause.value(item);
predicates.add(inClause); predicates.add(inClause);
} }
if (this.sectionIds != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpUserEntity._sectionId));
for (UUID item : this.sectionIds)
inClause.value(item);
predicates.add(inClause);
}
if (this.userRoles != null) { if (this.userRoles != null) {
CriteriaBuilder.In<DmpUserRole> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpUserEntity._role)); CriteriaBuilder.In<DmpUserRole> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpUserEntity._role));
for (DmpUserRole item : this.userRoles) for (DmpUserRole item : this.userRoles)
@ -214,6 +237,7 @@ public class DmpUserQuery extends QueryBase<DmpUserEntity> {
item.setId(QueryBase.convertSafe(tuple, columns, DmpUserEntity._id, UUID.class)); item.setId(QueryBase.convertSafe(tuple, columns, DmpUserEntity._id, UUID.class));
item.setDmpId(QueryBase.convertSafe(tuple, columns, DmpUserEntity._dmpId, UUID.class)); item.setDmpId(QueryBase.convertSafe(tuple, columns, DmpUserEntity._dmpId, UUID.class));
item.setUserId(QueryBase.convertSafe(tuple, columns, DmpUserEntity._userId, UUID.class)); item.setUserId(QueryBase.convertSafe(tuple, columns, DmpUserEntity._userId, UUID.class));
item.setSectionId(QueryBase.convertSafe(tuple, columns, DmpUserEntity._sectionId, UUID.class));
item.setRole(QueryBase.convertSafe(tuple, columns, DmpUserEntity._role, DmpUserRole.class)); item.setRole(QueryBase.convertSafe(tuple, columns, DmpUserEntity._role, DmpUserRole.class));
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, DmpUserEntity._createdAt, Instant.class)); item.setCreatedAt(QueryBase.convertSafe(tuple, columns, DmpUserEntity._createdAt, Instant.class));
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, DmpUserEntity._updatedAt, Instant.class)); item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, DmpUserEntity._updatedAt, Instant.class));
@ -226,6 +250,7 @@ public class DmpUserQuery extends QueryBase<DmpUserEntity> {
else if (item.prefix(DmpUser._dmp) || item.prefix(PublicDmpUser._dmp)) return DmpUserEntity._dmpId; else if (item.prefix(DmpUser._dmp) || item.prefix(PublicDmpUser._dmp)) return DmpUserEntity._dmpId;
else if (item.prefix(DmpUser._user) || item.prefix(PublicDmpUser._user)) return DmpUserEntity._userId; else if (item.prefix(DmpUser._user) || item.prefix(PublicDmpUser._user)) return DmpUserEntity._userId;
else if (item.match(DmpUser._role) || item.match(PublicDmpUser._role)) return DmpUserEntity._role; else if (item.match(DmpUser._role) || item.match(PublicDmpUser._role)) return DmpUserEntity._role;
else if (item.match(DmpUser._sectionId)) return DmpUserEntity._sectionId;
else if (item.match(DmpUser._createdAt)) return DmpUserEntity._createdAt; else if (item.match(DmpUser._createdAt)) return DmpUserEntity._createdAt;
else if (item.match(DmpUser._updatedAt)) return DmpUserEntity._updatedAt; else if (item.match(DmpUser._updatedAt)) return DmpUserEntity._updatedAt;
else if (item.match(DmpUser._hash)) return DmpUserEntity._updatedAt; else if (item.match(DmpUser._hash)) return DmpUserEntity._updatedAt;

View File

@ -18,6 +18,7 @@ public class DmpUserLookup extends Lookup {
private List<UUID> dmpIds; private List<UUID> dmpIds;
private List<UUID> userIds; private List<UUID> userIds;
private List<UUID> sectionIds;
private List<IsActive> isActive; private List<IsActive> isActive;
private List<DmpUserRole> userRoles; private List<DmpUserRole> userRoles;
@ -46,6 +47,14 @@ public class DmpUserLookup extends Lookup {
this.userIds = userIds; this.userIds = userIds;
} }
public List<UUID> getSectionIds() {
return sectionIds;
}
public void setSectionIds(List<UUID> sectionIds) {
this.sectionIds = sectionIds;
}
public List<IsActive> getIsActive() { public List<IsActive> getIsActive() {
return isActive; return isActive;
} }
@ -68,6 +77,7 @@ public class DmpUserLookup extends Lookup {
if (this.dmpIds != null) query.dmpIds(this.dmpIds); if (this.dmpIds != null) query.dmpIds(this.dmpIds);
if (this.userIds != null) query.userIds(this.userIds); if (this.userIds != null) query.userIds(this.userIds);
if (this.userRoles != null) query.userRoles(this.userRoles); if (this.userRoles != null) query.userRoles(this.userRoles);
if (this.sectionIds != null) query.sectionIds(this.sectionIds);
if (this.isActive != null) query.isActives(this.isActive); if (this.isActive != null) query.isActives(this.isActive);
this.enrichCommon(query); this.enrichCommon(query);

View File

@ -457,6 +457,7 @@ public class DmpServiceImpl implements DmpService {
dmpUserEntity.setDmpId(dmpId); dmpUserEntity.setDmpId(dmpId);
dmpUserEntity.setUserId(dmpUser.getUser()); dmpUserEntity.setUserId(dmpUser.getUser());
dmpUserEntity.setRole(dmpUser.getRole()); dmpUserEntity.setRole(dmpUser.getRole());
dmpUserEntity.setSectionId(dmpUser.getSectionId());
dmpUserEntity.setCreatedAt(Instant.now()); dmpUserEntity.setCreatedAt(Instant.now());
dmpUserEntity.setUpdatedAt(Instant.now()); dmpUserEntity.setUpdatedAt(Instant.now());
dmpUserEntity.setIsActive(IsActive.Active); dmpUserEntity.setIsActive(IsActive.Active);

View File

@ -0,0 +1,12 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.01.054';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
ALTER TABLE public."DmpUser"
ADD COLUMN section_id uuid;
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.054', '2024-02-21 12:00:00.000000+02', now(), 'Add Section_id Column to DmpUser Table.');
END$$;

View File

@ -131,6 +131,7 @@ export interface NewVersionDmpPersist {
export interface DmpUserPersist { export interface DmpUserPersist {
user: Guid; user: Guid;
role: DmpUserRole; role: DmpUserRole;
email: string;
} }
export interface DmpUserRemovePersist { export interface DmpUserRemovePersist {

View File

@ -3,6 +3,7 @@ import { DmpAccessType } from "@app/core/common/enum/dmp-access-type";
import { DmpContactType } from "@app/core/common/enum/dmp-contact-type"; import { DmpContactType } from "@app/core/common/enum/dmp-contact-type";
import { DmpStatus } from "@app/core/common/enum/dmp-status"; import { DmpStatus } from "@app/core/common/enum/dmp-status";
import { DmpUserRole } from "@app/core/common/enum/dmp-user-role"; import { DmpUserRole } from "@app/core/common/enum/dmp-user-role";
import { DmpUserType } from "@app/core/common/enum/dmp-user-type";
import { IsActive } from "@app/core/common/enum/is-active.enum"; import { IsActive } from "@app/core/common/enum/is-active.enum";
import { DmpBlueprint } from "@app/core/model/dmp-blueprint/dmp-blueprint"; import { DmpBlueprint } from "@app/core/model/dmp-blueprint/dmp-blueprint";
import { Dmp, DmpBlueprintValue, DmpBlueprintValuePersist, DmpContact, DmpContactPersist, DmpDescriptionTemplate, DmpDescriptionTemplatePersist, DmpPersist, DmpProperties, DmpPropertiesPersist, DmpReferenceDataPersist, DmpReferencePersist, DmpUser, DmpUserPersist } from "@app/core/model/dmp/dmp"; import { Dmp, DmpBlueprintValue, DmpBlueprintValuePersist, DmpContact, DmpContactPersist, DmpDescriptionTemplate, DmpDescriptionTemplatePersist, DmpPersist, DmpProperties, DmpPropertiesPersist, DmpReferenceDataPersist, DmpReferencePersist, DmpUser, DmpUserPersist } from "@app/core/model/dmp/dmp";
@ -463,6 +464,8 @@ export class DmpContactEditorModel implements DmpContactPersist {
export class DmpUserEditorModel implements DmpUserPersist { export class DmpUserEditorModel implements DmpUserPersist {
user: Guid; user: Guid;
role: DmpUserRole; role: DmpUserRole;
email: string;
userType: DmpUserType= DmpUserType.Internal;
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
@ -473,6 +476,8 @@ export class DmpUserEditorModel implements DmpUserPersist {
fromModel(item: DmpUser): DmpUserEditorModel { fromModel(item: DmpUser): DmpUserEditorModel {
if(item?.user?.id) this.user = item.user.id; if(item?.user?.id) this.user = item.user.id;
this.role = item.role; this.role = item.role;
// TODO this.email = item.email;
this.userType = (item == null || this.user != null) ? DmpUserType.Internal : DmpUserType.External;
return this; return this;
} }
@ -493,6 +498,8 @@ export class DmpUserEditorModel implements DmpUserPersist {
return this.formBuilder.group({ return this.formBuilder.group({
user: [{ value: this.user, disabled: disabled }, context.getValidation('user').validators], user: [{ value: this.user, disabled: disabled }, context.getValidation('user').validators],
role: [{ value: this.role, disabled: disabled }, context.getValidation('role').validators], role: [{ value: this.role, disabled: disabled }, context.getValidation('role').validators],
email: [{ value: this.role, disabled: disabled }, context.getValidation('email').validators],
userType: [{ value: this.userType, disabled: disabled }, context.getValidation('userType').validators],
}); });
} }
@ -504,8 +511,10 @@ export class DmpUserEditorModel implements DmpUserPersist {
const baseContext: ValidationContext = new ValidationContext(); const baseContext: ValidationContext = new ValidationContext();
const baseValidationArray: Validation[] = new Array<Validation>(); const baseValidationArray: Validation[] = new Array<Validation>();
baseValidationArray.push({ key: 'user', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}user`)] }); baseValidationArray.push({ key: 'user', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}user`)] });
baseValidationArray.push({ key: 'role', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}role`)] }); baseValidationArray.push({ key: 'role', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}role`)] });
baseValidationArray.push({ key: 'email', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}email`)] });
baseValidationArray.push({ key: 'userType', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}userType`)] });
baseContext.validation = baseValidationArray; baseContext.validation = baseValidationArray;
return baseContext; return baseContext;
@ -523,7 +532,7 @@ export class DmpUserEditorModel implements DmpUserPersist {
validationErrorModel validationErrorModel
}); });
['user', 'role'].forEach(keyField => { ['user', 'role', 'email'].forEach(keyField => {
const control = formGroup?.get(keyField); const control = formGroup?.get(keyField);
control?.clearValidators(); control?.clearValidators();
control?.addValidators(context.getValidation(keyField).validators); control?.addValidators(context.getValidation(keyField).validators);