use of com.evolveum.midpoint.repo.sqale.qmodel.ref.QObjectReference in project midpoint by Evolveum.
the class OrgFilterProcessor method process.
@Override
public Predicate process(OrgFilter filter) throws QueryException {
// necessary for lazy refresh of org closure
context.markContainsOrgFilter();
FlexibleRelationalPathBase<?> path = context.root();
if (!(path instanceof QObject)) {
throw new QueryException("Org filter can only be used for objects," + " not for path " + path + " of type " + path.getClass());
}
QObject<?> objectPath = (QObject<?>) path;
if (filter.isRoot()) {
QObjectReference<MObject> ref = getNewRefAlias();
return subQuery(ref).where(ref.ownerOid.eq(objectPath.oid)).notExists();
}
if (filter.getOrgRef() == null) {
throw new QueryException("No organization reference defined in the search query.");
}
String oidParam = filter.getOrgRef().getOid();
if (oidParam == null) {
throw new QueryException("No oid specified in organization reference " + filter.getOrgRef().debugDump());
}
QName relation = filter.getOrgRef().getRelation();
// null means ANY (not "default") here, so we only search/normalize non-nulls
Integer relationId = relation != null ? context.repositoryContext().searchCachedRelationId(relation) : null;
if (filter.getScope() == OrgFilter.Scope.ONE_LEVEL) {
QObjectReference<MObject> ref = getNewRefAlias();
SQLQuery<?> subQuery = subQuery(ref).where(ref.ownerOid.eq(objectPath.oid).and(ref.targetOid.eq(UUID.fromString(oidParam))));
if (relationId != null) {
subQuery.where(ref.relationId.eq(relationId));
}
return subQuery.exists();
} else if (filter.getScope() == OrgFilter.Scope.SUBTREE) {
QObjectReference<MObject> ref = getNewRefAlias();
QOrgClosure oc = getNewClosureAlias();
SQLQuery<?> subQuery = subQuery(ref).join(oc).on(oc.descendantOid.eq(ref.targetOid)).where(ref.ownerOid.eq(objectPath.oid).and(oc.ancestorOid.eq(UUID.fromString(oidParam))));
if (relationId != null) {
subQuery.where(ref.relationId.eq(relationId));
}
return subQuery.exists();
} else if (filter.getScope() == OrgFilter.Scope.ANCESTORS) {
QOrgClosure oc = getNewClosureAlias();
return subQuery(oc).where(oc.ancestorOid.eq(objectPath.oid).and(oc.descendantOid.eq(UUID.fromString(oidParam))).and(oc.ancestorOid.ne(oc.descendantOid))).exists();
} else {
throw new QueryException("Unknown scope if org filter: " + filter);
}
}
Aggregations