Search in sources :

Example 11 with S_AtomicFilterEntry

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

Example 12 with S_AtomicFilterEntry

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();
}
Also used : S_AtomicFilterEntry(com.evolveum.midpoint.prism.query.builder.S_AtomicFilterEntry) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Aggregations

S_AtomicFilterEntry (com.evolveum.midpoint.prism.query.builder.S_AtomicFilterEntry)12 PolyStringNormalizer (com.evolveum.midpoint.prism.polystring.PolyStringNormalizer)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)2 RefinedAttributeDefinition (com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition)1 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)1 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 S_AtomicFilterExit (com.evolveum.midpoint.prism.query.builder.S_AtomicFilterExit)1 ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)1 ResourceObjectTypeDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 DropDownChoicePanel (com.evolveum.midpoint.web.component.input.DropDownChoicePanel)1 CertCampaignsSearchDto (com.evolveum.midpoint.web.page.admin.certification.dto.CertCampaignsSearchDto)1 AccountDetailsSearchDto (com.evolveum.midpoint.web.page.admin.configuration.dto.AccountDetailsSearchDto)1 ReportOutputSearchDto (com.evolveum.midpoint.web.page.admin.reports.dto.ReportOutputSearchDto)1 ReportSearchDto (com.evolveum.midpoint.web.page.admin.reports.dto.ReportSearchDto)1 FailedOperationTypeType (com.evolveum.midpoint.xml.ns._public.common.common_3.FailedOperationTypeType)1 ShadowKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)1