Search in sources :

Example 31 with ObjectFilter

use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.

the class ResourceObjectReferenceResolver method resolve.

PrismObject<ShadowType> resolve(ProvisioningContext ctx, ResourceObjectReferenceType resourceObjectReference, QName objectClass, final String desc, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    if (resourceObjectReference == null) {
        return null;
    }
    ObjectReferenceType shadowRef = resourceObjectReference.getShadowRef();
    if (shadowRef != null && shadowRef.getOid() != null) {
        if (resourceObjectReference.getResolutionFrequency() == null || resourceObjectReference.getResolutionFrequency() == ResourceObjectReferenceResolutionFrequencyType.ONCE) {
            PrismObject<ShadowType> shadow = repositoryService.getObject(ShadowType.class, shadowRef.getOid(), null, result);
            return shadow;
        }
    } else if (resourceObjectReference.getResolutionFrequency() == ResourceObjectReferenceResolutionFrequencyType.NEVER) {
        throw new ObjectNotFoundException("No shadowRef OID in " + desc + " and resolution frequency set to NEVER");
    }
    if (resourceObjectReference.getObjectClass() != null) {
        objectClass = resourceObjectReference.getObjectClass();
        if (objectClass.getNamespaceURI() == null) {
            objectClass = new QName(ResourceTypeUtil.getResourceNamespace(ctx.getResource()), objectClass.getLocalPart());
        }
    }
    ProvisioningContext subctx = ctx.spawn(objectClass);
    // Use "raw" definitions from the original schema to avoid endless loops
    subctx.setUseRefinedDefinition(false);
    subctx.assertDefinition();
    ObjectQuery refQuery = QueryJaxbConvertor.createObjectQuery(ShadowType.class, resourceObjectReference.getFilter(), prismContext);
    ObjectFilter baseFilter = ObjectQueryUtil.createResourceAndObjectClassFilter(ctx.getResource().getOid(), objectClass, prismContext);
    ObjectFilter filter = AndFilter.createAnd(baseFilter, refQuery.getFilter());
    ObjectQuery query = ObjectQuery.createObjectQuery(filter);
    // TODO: implement "repo" search strategies
    Collection<SelectorOptions<GetOperationOptions>> options = null;
    final Holder<ShadowType> shadowHolder = new Holder<>();
    ShadowHandler<ShadowType> handler = new ShadowHandler<ShadowType>() {

        @Override
        public boolean handle(ShadowType shadow) {
            if (shadowHolder.getValue() != null) {
                throw new IllegalStateException("More than one search results for " + desc);
            }
            shadowHolder.setValue(shadow);
            return true;
        }
    };
    shadowCache.searchObjectsIterative(subctx, query, options, handler, true, result);
    // TODO: implement storage of OID (ONCE search frequency)
    ShadowType shadowType = shadowHolder.getValue();
    return shadowType == null ? null : shadowType.asPrismObject();
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) Holder(com.evolveum.midpoint.util.Holder) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ResourceObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectReferenceType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 32 with ObjectFilter

use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.

the class NaryLogicalRestriction method updateJunction.

protected void updateJunction(List<? extends ObjectFilter> subfilters, JunctionCondition junction) throws QueryException {
    InterpretationContext context = getContext();
    QueryInterpreter2 interpreter = context.getInterpreter();
    for (ObjectFilter subfilter : subfilters) {
        Condition condition = interpreter.interpretFilter(context, subfilter, this);
        junction.add(condition);
    }
}
Also used : Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) JunctionCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.JunctionCondition) InterpretationContext(com.evolveum.midpoint.repo.sql.query2.InterpretationContext) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) QueryInterpreter2(com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2)

Example 33 with ObjectFilter

use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.

the class TestDummy method testSeachIterativeSingleAttrFilter.

protected <T> void testSeachIterativeSingleAttrFilter(final String TEST_NAME, QName attrQName, T attrVal, GetOperationOptions rootOptions, boolean fullShadow, String... expectedAccountNames) throws Exception {
    ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
    ObjectClassComplexTypeDefinition objectClassDef = resourceSchema.findObjectClassDefinition(SchemaTestConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME);
    ResourceAttributeDefinition<T> attrDef = objectClassDef.findAttributeDefinition(attrQName);
    ObjectFilter filter = QueryBuilder.queryFor(ShadowType.class, prismContext).itemWithDef(attrDef, ShadowType.F_ATTRIBUTES, attrDef.getName()).eq(attrVal).buildFilter();
    testSeachIterative(TEST_NAME, filter, rootOptions, fullShadow, true, false, expectedAccountNames);
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter)

Example 34 with ObjectFilter

use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.

the class TestDummy method testSeachIterativeAlternativeAttrFilter.

protected <T> void testSeachIterativeAlternativeAttrFilter(final String TEST_NAME, QName attr1QName, T attr1Val, QName attr2QName, T attr2Val, GetOperationOptions rootOptions, boolean fullShadow, String... expectedAccountNames) throws Exception {
    ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
    ObjectClassComplexTypeDefinition objectClassDef = resourceSchema.findObjectClassDefinition(SchemaTestConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME);
    ResourceAttributeDefinition<T> attr1Def = objectClassDef.findAttributeDefinition(attr1QName);
    ResourceAttributeDefinition<T> attr2Def = objectClassDef.findAttributeDefinition(attr2QName);
    ObjectFilter filter = QueryBuilder.queryFor(ShadowType.class, prismContext).itemWithDef(attr1Def, ShadowType.F_ATTRIBUTES, attr1Def.getName()).eq(attr1Val).or().itemWithDef(attr2Def, ShadowType.F_ATTRIBUTES, attr2Def.getName()).eq(attr2Val).buildFilter();
    testSeachIterative(TEST_NAME, filter, rootOptions, fullShadow, false, true, expectedAccountNames);
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter)

Example 35 with ObjectFilter

use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.

the class TestDummy method test190SearchNone.

@Test
public void test190SearchNone() throws Exception {
    final String TEST_NAME = "test190SearchNone";
    TestUtil.displayTestTile(TEST_NAME);
    ObjectFilter attrFilter = NoneFilter.createNone();
    testSeachIterative(TEST_NAME, attrFilter, null, true, true, false);
}
Also used : ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) Test(org.testng.annotations.Test)

Aggregations

ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)64 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)30 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)25 Task (com.evolveum.midpoint.task.api.Task)21 ArrayList (java.util.ArrayList)14 Test (org.testng.annotations.Test)13 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)12 QName (javax.xml.namespace.QName)12 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)9 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)8 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)8 NoneFilter (com.evolveum.midpoint.prism.query.NoneFilter)7 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)7 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)6 PrismContext (com.evolveum.midpoint.prism.PrismContext)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5