Search in sources :

Example 1 with S_FilterEntry

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

the class ShadowManager method lookupShadowsBySecondaryIdentifiers.

private List<PrismObject<ShadowType>> lookupShadowsBySecondaryIdentifiers(ProvisioningContext ctx, Collection<ResourceAttribute<?>> secondaryIdentifiers, OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    if (secondaryIdentifiers.size() < 1) {
        LOGGER.trace("Shadow does not contain secondary identifier. Skipping lookup shadows according to name.");
        return null;
    }
    S_FilterEntry q = QueryBuilder.queryFor(ShadowType.class, prismContext).block();
    for (ResourceAttribute<?> secondaryIdentifier : secondaryIdentifiers) {
        // There may be identifiers that come from associations and they will have parent set to association/identifiers
        // For the search to succeed we need all attribute to have "attributes" parent path.
        secondaryIdentifier = ShadowUtil.fixAttributePath(secondaryIdentifier);
        q = q.item(secondaryIdentifier.getPath(), secondaryIdentifier.getDefinition()).eq(getNormalizedValue(secondaryIdentifier, ctx.getObjectClassDefinition())).or();
    }
    ObjectQuery query = q.none().endBlock().and().item(ShadowType.F_RESOURCE_REF).ref(ctx.getResourceOid()).build();
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Searching for shadow using filter on secondary identifier:\n{}", query.debugDump());
    }
    // TODO: check for errors
    List<PrismObject<ShadowType>> results = repositoryService.searchObjects(ShadowType.class, query, null, parentResult);
    MiscSchemaUtil.reduceSearchResult(results);
    LOGGER.trace("lookupShadow found {} objects", results.size());
    if (LOGGER.isTraceEnabled() && results.size() == 1) {
        LOGGER.trace("lookupShadow found\n{}", results.get(0).debugDump(1));
    }
    return results;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) S_FilterEntry(com.evolveum.midpoint.prism.query.builder.S_FilterEntry) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 2 with S_FilterEntry

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

the class ShadowFinder method searchShadowsBySecondaryIds.

private List<PrismObject<ShadowType>> searchShadowsBySecondaryIds(ProvisioningContext ctx, Collection<ResourceAttribute<?>> secondaryIdentifiers, OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    if (secondaryIdentifiers.isEmpty()) {
        LOGGER.trace("Shadow does not contain secondary identifier. Skipping lookup shadows according to name.");
        return emptyList();
    }
    S_FilterEntry q = prismContext.queryFor(ShadowType.class).block();
    for (ResourceAttribute<?> secondaryIdentifier : secondaryIdentifiers) {
        // There may be identifiers that come from associations and they will have parent set to association/identifiers
        // For the search to succeed we need all attribute to have "attributes" parent path.
        secondaryIdentifier = ShadowUtil.fixAttributePath(secondaryIdentifier);
        q = q.item(secondaryIdentifier.getPath(), secondaryIdentifier.getDefinition()).eq(getNormalizedValue(secondaryIdentifier, ctx.getObjectDefinitionRequired())).or();
    }
    ObjectQuery query = q.none().endBlock().and().item(ShadowType.F_RESOURCE_REF).ref(ctx.getResourceOid()).build();
    LOGGER.trace("Searching for shadow using filter on secondary identifiers:\n{}", query.debugDumpLazily());
    // TODO: check for errors
    return searchRepoShadows(query, null, parentResult);
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) S_FilterEntry(com.evolveum.midpoint.prism.query.builder.S_FilterEntry) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 3 with S_FilterEntry

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

the class MemberOperationsHelper method createDirectMemberQuery.

// endregion
// region Query formulation
/**
 * Creates a query covering all direct (assigned) members of an abstract role.
 *
 * @param targetObject The role.
 * @param memberType Type of members to be looked for.
 * @param relations Relations (of member->target assignment) to be looked for.
 * Should not be empty (although it is not guaranteed now).
 * @param tenant Tenant to be looked for (assignment/tenantRef)
 * @param project Org to be looked for (assignment/orgRef)
 */
@NotNull
public static <R extends AbstractRoleType> ObjectQuery createDirectMemberQuery(R targetObject, @NotNull QName memberType, Collection<QName> relations, ObjectReferenceType tenant, ObjectReferenceType project) {
    // We assume tenantRef.relation and orgRef.relation are always default ones (see also MID-3581)
    S_FilterEntry q0 = PrismContext.get().queryFor(AssignmentHolderType.class);
    if (!AssignmentHolderType.COMPLEX_TYPE.equals(memberType)) {
        q0 = q0.type(memberType);
    }
    // Use exists filter to build a query like this:
    // $a/targetRef = oid1 and $a/tenantRef = oid2 and $a/orgRef = oid3
    S_AtomicFilterExit q = q0.exists(AssignmentHolderType.F_ASSIGNMENT).block().item(AssignmentType.F_TARGET_REF).ref(createReferenceValuesList(targetObject, relations));
    if (tenant != null && StringUtils.isNotEmpty(tenant.getOid())) {
        q = q.and().item(AssignmentType.F_TENANT_REF).ref(tenant.getOid());
    }
    if (project != null && StringUtils.isNotEmpty(project.getOid())) {
        q = q.and().item(AssignmentType.F_ORG_REF).ref(project.getOid());
    }
    ObjectQuery query = q.endBlock().build();
    LOGGER.trace("Searching members of role {} with query:\n{}", targetObject.getOid(), query.debugDumpLazily());
    return query;
}
Also used : S_FilterEntry(com.evolveum.midpoint.prism.query.builder.S_FilterEntry) S_AtomicFilterExit(com.evolveum.midpoint.prism.query.builder.S_AtomicFilterExit) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with S_FilterEntry

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

the class ProcessInstanceDtoProvider method getObjectQuery.

private ObjectQuery getObjectQuery() throws SchemaException {
    String currentUserOid = currentUser();
    S_FilterEntry q = QueryBuilder.queryFor(TaskType.class, getPrismContext());
    if (requestedBy) {
        q = q.item(F_WORKFLOW_CONTEXT, F_REQUESTER_REF).ref(currentUserOid).and();
    }
    if (requestedFor) {
        q = q.item(F_OBJECT_REF).ref(currentUserOid).and();
    }
    return q.not().item(F_WORKFLOW_CONTEXT, F_PROCESS_INSTANCE_ID).isNull().desc(F_WORKFLOW_CONTEXT, F_START_TIMESTAMP).build();
}
Also used : S_FilterEntry(com.evolveum.midpoint.prism.query.builder.S_FilterEntry)

Aggregations

S_FilterEntry (com.evolveum.midpoint.prism.query.builder.S_FilterEntry)4 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 S_AtomicFilterExit (com.evolveum.midpoint.prism.query.builder.S_AtomicFilterExit)1 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)1 NotNull (org.jetbrains.annotations.NotNull)1