Search in sources :

Example 31 with ResourceObjectTypeDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition in project midpoint by Evolveum.

the class AssociationTargetSearchExpressionEvaluator method extendQuery.

@Override
protected ObjectQuery extendQuery(ObjectQuery query, ExpressionEvaluationContext params) throws SchemaException, ExpressionEvaluationException {
    @SuppressWarnings("unchecked") TypedValue<ResourceObjectTypeDefinition> rAssocTargetDefTypedValue = params.getVariables().get(ExpressionConstants.VAR_ASSOCIATION_TARGET_OBJECT_CLASS_DEFINITION);
    if (rAssocTargetDefTypedValue == null || rAssocTargetDefTypedValue.getValue() == null) {
        throw new ExpressionEvaluationException("No association target object class definition variable in " + params.getContextDescription() + "; the expression may be used in a wrong place. It is only supposed to create an association.");
    }
    ResourceObjectTypeDefinition rAssocTargetDef = (ResourceObjectTypeDefinition) rAssocTargetDefTypedValue.getValue();
    ObjectFilter resourceFilter = ObjectQueryUtil.createResourceFilter(rAssocTargetDef.getResourceOid(), prismContext);
    ObjectFilter objectClassFilter = ObjectQueryUtil.createObjectClassFilter(rAssocTargetDef.getObjectClassDefinition().getTypeName(), prismContext);
    ObjectFilter extendedFilter = prismContext.queryFactory().createAnd(resourceFilter, objectClassFilter, query.getFilter());
    query.setFilter(extendedFilter);
    return query;
}
Also used : ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter)

Example 32 with ResourceObjectTypeDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition in project midpoint by Evolveum.

the class ShadowFinder method createQueryBySelectedIds.

private ObjectQuery createQueryBySelectedIds(ProvisioningContext ctx, Collection<ResourceAttribute<?>> identifiers, boolean primaryIdentifiersOnly) throws SchemaException, ConfigurationException {
    boolean identifierFound = false;
    S_AtomicFilterEntry q = prismContext.queryFor(ShadowType.class);
    ResourceObjectDefinition objectClassDefinition = ctx.getObjectDefinition();
    for (PrismProperty<?> identifier : identifiers) {
        ResourceAttributeDefinition<?> rAttrDef;
        PrismPropertyValue<?> identifierValue = identifier.getValue();
        if (objectClassDefinition == null) {
            // If there is no specific object class definition then the identifier definition
            // must be the same in all object classes and that means that we can use
            // definition from any of them.
            ResourceObjectTypeDefinition anyDefinition = ctx.getResourceSchema().getObjectTypeDefinitions().iterator().next();
            rAttrDef = anyDefinition.findAttributeDefinition(identifier.getElementName());
            if (primaryIdentifiersOnly && !anyDefinition.isPrimaryIdentifier(identifier.getElementName())) {
                continue;
            }
        } else {
            if (primaryIdentifiersOnly && !objectClassDefinition.isPrimaryIdentifier(identifier.getElementName())) {
                continue;
            }
            rAttrDef = objectClassDefinition.findAttributeDefinition(identifier.getElementName());
        }
        if (rAttrDef == null) {
            throw new SchemaException("No definition for " + identifier.getElementName());
        }
        String normalizedIdentifierValue = (String) helper.getNormalizedAttributeValue(identifierValue, rAttrDef);
        // noinspection unchecked
        PrismPropertyDefinition<String> def = (PrismPropertyDefinition<String>) identifier.getDefinition();
        q = q.itemWithDef(def, ShadowType.F_ATTRIBUTES, def.getItemName()).eq(normalizedIdentifierValue).and();
        identifierFound = true;
    }
    if (!identifierFound) {
        throw new SchemaException("Identifiers not found. Cannot create search query by identifier.");
    }
    if (objectClassDefinition != null) {
        q = q.item(ShadowType.F_OBJECT_CLASS).eq(objectClassDefinition.getTypeName()).and();
    }
    return q.item(ShadowType.F_RESOURCE_REF).ref(ctx.getResourceOid()).build();
}
Also used : ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) S_AtomicFilterEntry(com.evolveum.midpoint.prism.query.builder.S_AtomicFilterEntry)

Aggregations

ResourceObjectTypeDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)32 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)14 QName (javax.xml.namespace.QName)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 ArrayList (java.util.ArrayList)5 Test (org.testng.annotations.Test)5 ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 Task (com.evolveum.midpoint.task.api.Task)4 ShadowKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)3 List (java.util.List)3 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)2 Definition (com.evolveum.midpoint.prism.Definition)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 ResourceAssociationDefinition (com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 NotNull (org.jetbrains.annotations.NotNull)2 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)1