notification remove tenant from contact and cred
This commit is contained in:
parent
a5160d3ecd
commit
871c3bc166
|
@ -12,7 +12,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"UserContactInfo\"")
|
@Table(name = "\"UserContactInfo\"")
|
||||||
public class UserContactInfoEntity extends TenantScopedBaseEntity {
|
public class UserContactInfoEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
|
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
|
||||||
|
|
|
@ -10,7 +10,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"UserCredential\"")
|
@Table(name = "\"UserCredential\"")
|
||||||
public class UserCredentialEntity extends TenantScopedBaseEntity {
|
public class UserCredentialEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
|
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
|
||||||
|
|
|
@ -28,10 +28,6 @@ public class UserContactInfo {
|
||||||
|
|
||||||
public static final String _ordinal = "ordinal";
|
public static final String _ordinal = "ordinal";
|
||||||
|
|
||||||
private Tenant tenant;
|
|
||||||
|
|
||||||
public static final String _tenant = "tenant";
|
|
||||||
|
|
||||||
private Instant createdAt;
|
private Instant createdAt;
|
||||||
|
|
||||||
public static final String _createdAt = "createdAt";
|
public static final String _createdAt = "createdAt";
|
||||||
|
@ -84,14 +80,6 @@ public class UserContactInfo {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tenant getTenant() {
|
|
||||||
return tenant;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTenant(Tenant tenant) {
|
|
||||||
this.tenant = tenant;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Instant getCreatedAt() {
|
public Instant getCreatedAt() {
|
||||||
return createdAt;
|
return createdAt;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,6 @@ public class UserContactInfoBuilder extends BaseBuilder<UserContactInfo, UserCon
|
||||||
FieldSet userFields = fields.extractPrefixed(this.asPrefix(UserContactInfo._user));
|
FieldSet userFields = fields.extractPrefixed(this.asPrefix(UserContactInfo._user));
|
||||||
Map<UUID, User> userMap = this.collectUsers(userFields, data);
|
Map<UUID, User> userMap = this.collectUsers(userFields, data);
|
||||||
|
|
||||||
FieldSet tenantFields = fields.extractPrefixed(this.asPrefix(UserContactInfo._tenant));
|
|
||||||
Map<UUID, Tenant> tenantMap = this.collectTenants(tenantFields, data);
|
|
||||||
|
|
||||||
List<UserContactInfo> models = new ArrayList<>();
|
List<UserContactInfo> models = new ArrayList<>();
|
||||||
|
|
||||||
for (UserContactInfoEntity d : data) {
|
for (UserContactInfoEntity d : data) {
|
||||||
|
@ -66,7 +63,6 @@ public class UserContactInfoBuilder extends BaseBuilder<UserContactInfo, UserCon
|
||||||
if (fields.hasField(this.asIndexer(UserContactInfo._value))) m.setValue(d.getValue());
|
if (fields.hasField(this.asIndexer(UserContactInfo._value))) m.setValue(d.getValue());
|
||||||
if (fields.hasField(this.asIndexer(UserContactInfo._type))) m.setType(d.getType());
|
if (fields.hasField(this.asIndexer(UserContactInfo._type))) m.setType(d.getType());
|
||||||
if (!userFields.isEmpty() && userMap != null && userMap.containsKey(d.getUserId())) m.setUser(userMap.get(d.getUserId()));
|
if (!userFields.isEmpty() && userMap != null && userMap.containsKey(d.getUserId())) m.setUser(userMap.get(d.getUserId()));
|
||||||
if (!tenantFields.isEmpty() && tenantMap != null && tenantMap.containsKey(d.getTenantId())) m.setTenant(tenantMap.get(d.getTenantId()));
|
|
||||||
models.add(m);
|
models.add(m);
|
||||||
}
|
}
|
||||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||||
|
@ -99,30 +95,4 @@ public class UserContactInfoBuilder extends BaseBuilder<UserContactInfo, UserCon
|
||||||
return itemMap;
|
return itemMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<UUID, Tenant> collectTenants(FieldSet fields, List<UserContactInfoEntity> data) throws MyApplicationException {
|
|
||||||
if (fields.isEmpty() || data.isEmpty()) return null;
|
|
||||||
this.logger.debug("checking related - {}", Tenant.class.getSimpleName());
|
|
||||||
|
|
||||||
Map<UUID, Tenant> itemMap;
|
|
||||||
if (!fields.hasOtherField(this.asIndexer(Tenant._id))) {
|
|
||||||
itemMap = this.asEmpty(
|
|
||||||
data.stream().map(TenantScopedBaseEntity::getTenantId).distinct().collect(Collectors.toList()),
|
|
||||||
x -> {
|
|
||||||
Tenant item = new Tenant();
|
|
||||||
item.setId(x);
|
|
||||||
return item;
|
|
||||||
},
|
|
||||||
Tenant::getId);
|
|
||||||
} else {
|
|
||||||
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Tenant._id);
|
|
||||||
TenantQuery q = this.queryFactory.query(TenantQuery.class).authorize(this.authorize).ids(data.stream().map(TenantScopedBaseEntity::getTenantId).distinct().collect(Collectors.toList()));
|
|
||||||
itemMap = this.builderFactory.builder(TenantBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Tenant::getId);
|
|
||||||
}
|
|
||||||
if (!fields.hasField(Tenant._id)) {
|
|
||||||
itemMap = itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toMap(Tenant::getId, Function.identity()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return itemMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,8 +43,6 @@ public class UserContactInfoCensor extends BaseCensor {
|
||||||
logger.debug(new DataLogEntry("censoring fields", fields));
|
logger.debug(new DataLogEntry("censoring fields", fields));
|
||||||
if (this.isEmpty(fields)) return;
|
if (this.isEmpty(fields)) return;
|
||||||
this.authService.authorizeAtLeastOneForce(userId != null ? List.of(new OwnedResource(userId)) : null, Permission.BrowseUserContactInfo);
|
this.authService.authorizeAtLeastOneForce(userId != null ? List.of(new OwnedResource(userId)) : null, Permission.BrowseUserContactInfo);
|
||||||
FieldSet tenantFields = fields.extractPrefixed(this.asIndexerPrefix(UserContactInfo._tenant));
|
|
||||||
this.censorFactory.censor(TenantCensor.class).censor(tenantFields);
|
|
||||||
FieldSet userFields = fields.extractPrefixed(this.asIndexerPrefix(UserContactInfo._user));
|
FieldSet userFields = fields.extractPrefixed(this.asIndexerPrefix(UserContactInfo._user));
|
||||||
this.censorFactory.censor(UserCensor.class).censor(userFields, userId);
|
this.censorFactory.censor(UserCensor.class).censor(userFields, userId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,6 @@ public class UserContactInfoQuery extends QueryBase<UserContactInfoEntity> {
|
||||||
|
|
||||||
private Collection<UUID> excludedUserIds;
|
private Collection<UUID> excludedUserIds;
|
||||||
|
|
||||||
private Collection<UUID> tenantIds;
|
|
||||||
|
|
||||||
private Collection<IsActive> isActives;
|
private Collection<IsActive> isActives;
|
||||||
|
|
||||||
private Collection<ContactInfoType> type;
|
private Collection<ContactInfoType> type;
|
||||||
|
@ -101,21 +99,6 @@ public class UserContactInfoQuery extends QueryBase<UserContactInfoEntity> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserContactInfoQuery tenantIds(UUID value) {
|
|
||||||
this.tenantIds = List.of(value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserContactInfoQuery tenantIds(UUID... value) {
|
|
||||||
this.tenantIds = Arrays.asList(value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserContactInfoQuery tenantIds(Collection<UUID> values) {
|
|
||||||
this.tenantIds = values;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserContactInfoQuery isActive(IsActive value) {
|
public UserContactInfoQuery isActive(IsActive value) {
|
||||||
this.isActives = List.of(value);
|
this.isActives = List.of(value);
|
||||||
return this;
|
return this;
|
||||||
|
@ -173,7 +156,7 @@ public class UserContactInfoQuery extends QueryBase<UserContactInfoEntity> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean isFalseQuery() {
|
protected Boolean isFalseQuery() {
|
||||||
return this.isEmpty(this.userIds) || this.isEmpty(this.excludedUserIds) || this.isEmpty(this.tenantIds) || this.isEmpty(this.isActives)
|
return this.isEmpty(this.userIds) || this.isEmpty(this.excludedUserIds) || this.isEmpty(this.isActives)
|
||||||
|| this.isEmpty(this.type) || this.isEmpty(this.excludedUserIds) || this.isFalseQuery(this.userQuery);
|
|| this.isEmpty(this.type) || this.isEmpty(this.excludedUserIds) || this.isFalseQuery(this.userQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,12 +205,6 @@ public class UserContactInfoQuery extends QueryBase<UserContactInfoEntity> {
|
||||||
notInClause.value(item);
|
notInClause.value(item);
|
||||||
predicates.add(notInClause.not());
|
predicates.add(notInClause.not());
|
||||||
}
|
}
|
||||||
if (this.tenantIds != null) {
|
|
||||||
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserContactInfoEntity._tenantId));
|
|
||||||
for (UUID item : this.tenantIds)
|
|
||||||
inClause.value(item);
|
|
||||||
predicates.add(inClause);
|
|
||||||
}
|
|
||||||
if (this.type != null) {
|
if (this.type != null) {
|
||||||
CriteriaBuilder.In<ContactInfoType> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserContactInfoEntity._type));
|
CriteriaBuilder.In<ContactInfoType> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserContactInfoEntity._type));
|
||||||
for (ContactInfoType item : this.type)
|
for (ContactInfoType item : this.type)
|
||||||
|
@ -257,8 +234,6 @@ public class UserContactInfoQuery extends QueryBase<UserContactInfoEntity> {
|
||||||
protected String fieldNameOf(FieldResolver item) {
|
protected String fieldNameOf(FieldResolver item) {
|
||||||
if (item.match(UserContactInfo._id))
|
if (item.match(UserContactInfo._id))
|
||||||
return UserContactInfoEntity._id;
|
return UserContactInfoEntity._id;
|
||||||
else if (item.prefix(UserContactInfo._tenant))
|
|
||||||
return UserContactInfoEntity._tenantId;
|
|
||||||
else if (item.match(UserContactInfo._type))
|
else if (item.match(UserContactInfo._type))
|
||||||
return UserContactInfoEntity._type;
|
return UserContactInfoEntity._type;
|
||||||
else if (item.match(UserContactInfo._value))
|
else if (item.match(UserContactInfo._value))
|
||||||
|
@ -287,7 +262,6 @@ public class UserContactInfoQuery extends QueryBase<UserContactInfoEntity> {
|
||||||
item.setValue(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._value, String.class));
|
item.setValue(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._value, String.class));
|
||||||
item.setOrdinal(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._ordinal, Integer.class));
|
item.setOrdinal(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._ordinal, Integer.class));
|
||||||
item.setUserId(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._userId, UUID.class));
|
item.setUserId(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._userId, UUID.class));
|
||||||
item.setTenantId(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._tenantId, UUID.class));
|
|
||||||
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._createdAt, Instant.class));
|
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._createdAt, Instant.class));
|
||||||
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._updatedAt, Instant.class));
|
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._updatedAt, Instant.class));
|
||||||
item.setIsActive(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._isActive, IsActive.class));
|
item.setIsActive(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._isActive, IsActive.class));
|
||||||
|
|
|
@ -12,10 +12,6 @@ public class UserContactInfoLookup extends Lookup {
|
||||||
|
|
||||||
private List<IsActive> isActive;
|
private List<IsActive> isActive;
|
||||||
private List<UUID> userIds;
|
private List<UUID> userIds;
|
||||||
private List<UUID> tenantIds;
|
|
||||||
|
|
||||||
private UserLookup userSubQuery;
|
|
||||||
|
|
||||||
public List<IsActive> getIsActive() {
|
public List<IsActive> getIsActive() {
|
||||||
return isActive;
|
return isActive;
|
||||||
}
|
}
|
||||||
|
@ -32,21 +28,11 @@ public class UserContactInfoLookup extends Lookup {
|
||||||
this.userIds = userIds;
|
this.userIds = userIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UUID> getTenantIds() {
|
|
||||||
return tenantIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTenantIds(List<UUID> tenantIds) {
|
|
||||||
this.tenantIds = tenantIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserContactInfoQuery enrich(QueryFactory queryFactory) {
|
public UserContactInfoQuery enrich(QueryFactory queryFactory) {
|
||||||
UserContactInfoQuery query = queryFactory.query(UserContactInfoQuery.class);
|
UserContactInfoQuery query = queryFactory.query(UserContactInfoQuery.class);
|
||||||
if (this.isActive != null) query.isActive(this.isActive);
|
if (this.isActive != null) query.isActive(this.isActive);
|
||||||
if (this.userIds != null) query.userIds(this.userIds);
|
if (this.userIds != null) query.userIds(this.userIds);
|
||||||
if (this.tenantIds != null) query.tenantIds(this.tenantIds);
|
|
||||||
if (this.userSubQuery != null) query.userSubQuery(this.userSubQuery.enrich(queryFactory));
|
|
||||||
|
|
||||||
this.enrichCommon(query);
|
this.enrichCommon(query);
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
|
|
Loading…
Reference in New Issue