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;
}
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();
}
Aggregations