Search in sources :

Example 1 with LinkManager

use of com.evolveum.midpoint.model.common.LinkManager in project midpoint by Evolveum.

the class LinkedObjectsFunctions method findLinkedTargets.

// Should be used after assignment evaluation!
@Experimental
@NotNull
<T extends AssignmentHolderType> List<T> findLinkedTargets(String linkTypeName) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
    OperationResult currentResult = midpointFunctions.getCurrentResult();
    LensFocusContext<?> focusContext = (LensFocusContext<?>) midpointFunctions.getFocusContext();
    if (focusContext == null) {
        throw new IllegalStateException("No focus context");
    }
    LinkTypeDefinitionType definition = focusContext.getTargetLinkTypeDefinition(linkTypeName, linkManager, currentResult);
    if (definition == null) {
        throw new IllegalStateException("No definition for target link type " + linkTypeName + " for " + focusContext);
    }
    Class<?> expectedClasses = getExpectedClass(definition.getSelector());
    Set<PrismReferenceValue> membership = getMembership();
    List<PrismReferenceValue> assignedWithMatchingRelation = membership.stream().filter(ref -> relationMatches(ref, definition.getSelector()) && objectTypeMatches(ref, expectedClasses)).collect(Collectors.toList());
    // TODO deduplicate w.r.t. member/manager
    // TODO optimize matching
    List<T> objects = new ArrayList<>(assignedWithMatchingRelation.size());
    for (PrismReferenceValue reference : assignedWithMatchingRelation) {
        ObjectReferenceType ort = new ObjectReferenceType();
        ort.setupReferenceValue(reference);
        T object = midpointFunctions.resolveReferenceInternal(ort, true);
        if (objectMatches(object, definition.getSelector())) {
            objects.add(object);
        }
    }
    return objects;
}
Also used : java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Trace(com.evolveum.midpoint.util.logging.Trace) ModelExpressionThreadLocalHolder(com.evolveum.midpoint.model.common.expression.ModelExpressionThreadLocalHolder) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) PrismContext(com.evolveum.midpoint.prism.PrismContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) RelationRegistry(com.evolveum.midpoint.schema.RelationRegistry) EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) LinkedSelectorToFilterTranslator(com.evolveum.midpoint.repo.common.query.LinkedSelectorToFilterTranslator) Experimental(com.evolveum.midpoint.util.annotation.Experimental) Collections.emptySet(java.util.Collections.emptySet) Objectable(com.evolveum.midpoint.prism.Objectable) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) Objects(java.util.Objects) Component(org.springframework.stereotype.Component) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) Modifier(java.lang.reflect.Modifier) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext) LinkManager(com.evolveum.midpoint.model.common.LinkManager) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) NotNull(org.jetbrains.annotations.NotNull) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext) Experimental(com.evolveum.midpoint.util.annotation.Experimental) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LinkManager (com.evolveum.midpoint.model.common.LinkManager)1 ModelExpressionThreadLocalHolder (com.evolveum.midpoint.model.common.expression.ModelExpressionThreadLocalHolder)1 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)1 LensFocusContext (com.evolveum.midpoint.model.impl.lens.LensFocusContext)1 EvaluatedAssignmentImpl (com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl)1 Objectable (com.evolveum.midpoint.prism.Objectable)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)1 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)1 ExpressionFactory (com.evolveum.midpoint.repo.common.expression.ExpressionFactory)1 LinkedSelectorToFilterTranslator (com.evolveum.midpoint.repo.common.query.LinkedSelectorToFilterTranslator)1 RelationRegistry (com.evolveum.midpoint.schema.RelationRegistry)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 ObjectTypeUtil (com.evolveum.midpoint.schema.util.ObjectTypeUtil)1 Task (com.evolveum.midpoint.task.api.Task)1 MiscUtil (com.evolveum.midpoint.util.MiscUtil)1 Experimental (com.evolveum.midpoint.util.annotation.Experimental)1 com.evolveum.midpoint.util.exception (com.evolveum.midpoint.util.exception)1