use of com.evolveum.midpoint.prism.query.builder.S_AtomicFilterEntry 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();
}
use of com.evolveum.midpoint.prism.query.builder.S_AtomicFilterEntry in project midpoint by Evolveum.
the class ObjectAlreadyExistHandler method createQueryBySecondaryIdentifier.
protected static ObjectQuery createQueryBySecondaryIdentifier(ShadowType shadow, PrismContext prismContext) {
// TODO ensure that the identifiers are normalized here
// Note that if the query is to be used against the repository, we should not provide matching rules here. See MID-5547.
Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(shadow);
S_AtomicFilterEntry q = prismContext.queryFor(ShadowType.class);
q = q.block();
if (secondaryIdentifiers.isEmpty()) {
for (ResourceAttribute<?> primaryIdentifier : ShadowUtil.getPrimaryIdentifiers(shadow)) {
q = q.itemAs(primaryIdentifier).or();
}
} else {
// secondary identifiers connected by 'or' clause
for (ResourceAttribute<?> secondaryIdentifier : secondaryIdentifiers) {
q = q.itemAs(secondaryIdentifier).or();
}
}
q = q.none().endBlock().and();
// resource + object class
q = q.item(ShadowType.F_RESOURCE_REF).ref(shadow.getResourceRef().getOid()).and();
return q.item(ShadowType.F_OBJECT_CLASS).eq(shadow.getObjectClass()).build();
}
Aggregations