fix contact info query
This commit is contained in:
parent
d4dcc76391
commit
08f753bba0
|
@ -11,8 +11,11 @@ import org.opencdmp.authorization.AuthorizationFlags;
|
|||
import org.opencdmp.authorization.Permission;
|
||||
import org.opencdmp.commons.enums.ContactInfoType;
|
||||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.data.DmpUserEntity;
|
||||
import org.opencdmp.data.UserContactInfoEntity;
|
||||
import org.opencdmp.model.UserContactInfo;
|
||||
import org.opencdmp.query.utils.BuildSubQueryInput;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -31,11 +34,12 @@ public class UserContactInfoQuery extends QueryBase<UserContactInfoEntity> {
|
|||
private Collection<ContactInfoType> types;
|
||||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final UserScope userScope;
|
||||
private final AuthorizationService authService;
|
||||
public UserContactInfoQuery(UserScope userScope, AuthorizationService authService) {
|
||||
this.userScope = userScope;
|
||||
public UserContactInfoQuery(QueryUtilsService queryUtilsService, UserScope userScope, AuthorizationService authService) {
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
}
|
||||
|
||||
|
@ -168,7 +172,17 @@ public class UserContactInfoQuery extends QueryBase<UserContactInfoEntity> {
|
|||
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
if (userId != null) {
|
||||
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(UserContactInfoEntity._userId)).value(userId));
|
||||
predicates.add(queryContext.CriteriaBuilder.or(
|
||||
queryContext.CriteriaBuilder.in(queryContext.Root.get(UserContactInfoEntity._userId)).value(userId), //Creates a false query
|
||||
queryContext.CriteriaBuilder.in(queryContext.Root.get(UserContactInfoEntity._userId)).value(this.queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(new BuildSubQueryInput.Builder<>(DmpUserEntity.class, UUID.class)
|
||||
.query(queryContext.Query)
|
||||
.criteriaBuilder(queryContext.CriteriaBuilder)
|
||||
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpUserEntity._userId))
|
||||
.filterFunc((subQueryRoot, cb) ->
|
||||
cb.in(subQueryRoot.get(DmpUserEntity._dmpId)).value(this.queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, false))
|
||||
)
|
||||
)))
|
||||
));
|
||||
}
|
||||
if (!predicates.isEmpty()) {
|
||||
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
|
||||
|
@ -187,6 +201,12 @@ public class UserContactInfoQuery extends QueryBase<UserContactInfoEntity> {
|
|||
inClause.value(item);
|
||||
predicates.add(inClause);
|
||||
}
|
||||
if (this.types != null) {
|
||||
CriteriaBuilder.In<ContactInfoType> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserContactInfoEntity._type));
|
||||
for (ContactInfoType item : this.types)
|
||||
inClause.value(item);
|
||||
predicates.add(inClause);
|
||||
}
|
||||
if (this.userIds != null) {
|
||||
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserContactInfoEntity._userId));
|
||||
for (UUID item : this.userIds)
|
||||
|
|
Loading…
Reference in New Issue