Skip to content

Commit

Permalink
ANCESTORS scope for org query.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Aug 16, 2016
1 parent 26b0644 commit efa792f
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 3 deletions.
Expand Up @@ -24,7 +24,11 @@

public class OrgFilter extends ObjectFilter {

public enum Scope {ONE_LEVEL, SUBTREE}
public enum Scope {
ONE_LEVEL,
SUBTREE,
ANCESTORS // EXPERIMENTAL; OID has to belong to an OrgType!
}

private PrismReferenceValue baseOrgRef;
private Scope scope;
Expand Down
Expand Up @@ -208,6 +208,12 @@ public S_AtomicFilterExit isChildOf(PrismReferenceValue value) throws SchemaExce
return addSubfilter(orgFilter);
}

@Override
public S_AtomicFilterExit isParentOf(PrismReferenceValue value) throws SchemaException {
OrgFilter orgFilter = OrgFilter.createOrg(value, OrgFilter.Scope.ANCESTORS);
return addSubfilter(orgFilter);
}

@Override
public S_AtomicFilterExit isDirectChildOf(String oid) throws SchemaException {
OrgFilter orgFilter = OrgFilter.createOrg(oid, OrgFilter.Scope.ONE_LEVEL);
Expand All @@ -220,6 +226,12 @@ public S_AtomicFilterExit isChildOf(String oid) throws SchemaException {
return addSubfilter(orgFilter);
}

@Override
public S_AtomicFilterExit isParentOf(String oid) throws SchemaException {
OrgFilter orgFilter = OrgFilter.createOrg(oid, OrgFilter.Scope.ANCESTORS);
return addSubfilter(orgFilter);
}

@Override
public S_AtomicFilterExit isRoot() throws SchemaException {
OrgFilter orgFilter = OrgFilter.createRootOrg();
Expand Down
Expand Up @@ -44,6 +44,8 @@ public interface S_AtomicFilterEntry {
S_AtomicFilterExit isChildOf(PrismReferenceValue value) throws SchemaException;
S_AtomicFilterExit isDirectChildOf(String oid) throws SchemaException;
S_AtomicFilterExit isChildOf(String oid) throws SchemaException;
S_AtomicFilterExit isParentOf(PrismReferenceValue value) throws SchemaException; // reference should point to OrgType
S_AtomicFilterExit isParentOf(String oid) throws SchemaException; // oid should be of an OrgType
S_AtomicFilterExit isRoot() throws SchemaException;
S_FilterEntryOrEmpty block();
S_FilterEntry type(Class<? extends Containerable> type) throws SchemaException;
Expand Down
Expand Up @@ -452,7 +452,7 @@ <T extends ObjectType> void applyDefinition(ObjectDelta<T> delta, Objectable obj
/**
* Applies appropriate definition to the shadow.
*/
<T extends ObjectType> void applyDefinition(PrismObject<T> shadow, OperationResult parentResult)
<T extends ObjectType> void applyDefinition(PrismObject<T> object, OperationResult parentResult)
throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException;

/**
Expand Down
Expand Up @@ -2027,6 +2027,15 @@ public void test500OrgQuery() throws Exception {
checkQueryResult(UserType.class, "00000000-8888-6666-0000-200000000002", OrgFilter.Scope.SUBTREE, 2);
checkQueryResult(UserType.class, "00000000-8888-6666-0000-200000000001", OrgFilter.Scope.ONE_LEVEL, 1);
checkQueryResult(UserType.class, "00000000-8888-6666-0000-200000000001", OrgFilter.Scope.SUBTREE, 1);
checkQueryResult(OrgType.class, "00000000-8888-6666-0000-100000000001", OrgFilter.Scope.ANCESTORS, 0);
checkQueryResult(OrgType.class, "00000000-8888-6666-0000-100000000002", OrgFilter.Scope.ANCESTORS, 1);
checkQueryResult(OrgType.class, "00000000-8888-6666-0000-100000000003", OrgFilter.Scope.ANCESTORS, 1);
checkQueryResult(OrgType.class, "00000000-8888-6666-0000-100000000004", OrgFilter.Scope.ANCESTORS, 1);
checkQueryResult(OrgType.class, "00000000-8888-6666-0000-100000000005", OrgFilter.Scope.ANCESTORS, 2);
checkQueryResult(OrgType.class, "00000000-8888-6666-0000-100000000006", OrgFilter.Scope.ANCESTORS, 3);
checkQueryResult(OrgType.class, "00000000-8888-6666-0000-200000000000", OrgFilter.Scope.ANCESTORS, 0);
checkQueryResult(OrgType.class, "00000000-8888-6666-0000-200000000001", OrgFilter.Scope.ANCESTORS, 1);
checkQueryResult(OrgType.class, "00000000-8888-6666-0000-200000000002", OrgFilter.Scope.ANCESTORS, 1);
}

private <T extends ObjectType> void checkQueryResult(Class<T> type, String oid, OrgFilter.Scope scope, int count)
Expand Down
Expand Up @@ -81,6 +81,8 @@ public Criterion interpret() throws QueryException {
detached.setProjection(Projections.distinct(Projections.property("p.ownerOid")));
detached.add(Restrictions.eq("p.targetOid", filter.getOrgRef().getOid()));
break;
case ANCESTORS:
throw new UnsupportedOperationException("ANCESTORS query is not supported in this query interpreter");
case SUBTREE:
default:
detached = DetachedCriteria.forClass(RObjectReference.class, "p");
Expand Down
Expand Up @@ -61,6 +61,14 @@ public Condition interpret() throws QueryException {
"ref.referenceType = " + nameOf(RReferenceOwner.OBJECT_PARENT_ORG) + " and " +
"ref.targetOid = :" + orgOidParamName;
break;
case ANCESTORS:
oidQueryText =
"select c.ancestorOid " +
"from ROrgClosure c " +
"where " +
"c.ancestorOid != :" + orgOidParamName + " and " +
"c.descendantOid = :" + orgOidParamName;
break;
case SUBTREE:
default:
oidQueryText =
Expand Down
Expand Up @@ -1035,7 +1035,7 @@ private <T extends ObjectType, O extends ObjectType> ObjectFilter preProcessObje
} else if (specOrgRelation.getScope() == OrgScopeType.DIRECT_DESCENDANTS) {
orgFilter = OrgFilter.createOrg(subjectParentOrgRef.getOid(), OrgFilter.Scope.ONE_LEVEL);
} else if (specOrgRelation.getScope() == OrgScopeType.ALL_ANCESTORS) {
throw new UnsupportedOperationException("orgRelation scope "+specOrgRelation.getScope()+" is not supported yet");
orgFilter = OrgFilter.createOrg(subjectParentOrgRef.getOid(), OrgFilter.Scope.ANCESTORS);
} else {
throw new UnsupportedOperationException("Unknown orgRelation scope "+specOrgRelation.getScope());
}
Expand Down

0 comments on commit efa792f

Please sign in to comment.