Search in sources :

Example 11 with AssignmentHolderType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType in project midpoint by Evolveum.

the class AssignmentCollector method evaluateAssignments.

private <AH extends AssignmentHolderType> Collection<EvaluatedAssignment<AH>> evaluateAssignments(AH focus, Collection<AssignmentType> assignments, AssignmentOrigin origin, AssignmentEvaluator<AH> assignmentEvaluator, Task task, OperationResult result) {
    List<EvaluatedAssignment<AH>> evaluatedAssignments = new ArrayList<>();
    RepositoryCache.enterLocalCaches(cacheConfigurationManager);
    try {
        PrismContainerDefinition<AssignmentType> standardAssignmentDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(AssignmentHolderType.class).findContainerDefinition(AssignmentHolderType.F_ASSIGNMENT);
        for (AssignmentType assignmentType : emptyIfNull(assignments)) {
            try {
                // noinspection unchecked
                PrismContainerDefinition<AssignmentType> definition = defaultIfNull(assignmentType.asPrismContainerValue().getDefinition(), standardAssignmentDefinition);
                ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(assignmentType), definition);
                EvaluatedAssignment<AH> assignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, focus, focus.toString(), origin, task, result);
                evaluatedAssignments.add(assignment);
            } catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException | PolicyViolationException | SecurityViolationException | ConfigurationException | CommunicationException e) {
                LOGGER.error("Error while processing assignment of {}: {}; assignment: {}", focus, e.getMessage(), assignmentType, e);
            }
        }
    } finally {
        RepositoryCache.exitLocalCaches();
    }
    return evaluatedAssignments;
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ArrayList(java.util.ArrayList) EvaluatedAssignment(com.evolveum.midpoint.model.api.context.EvaluatedAssignment) ItemDeltaItem(com.evolveum.midpoint.prism.util.ItemDeltaItem) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) AssignmentHolderType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType)

Example 12 with AssignmentHolderType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType in project midpoint by Evolveum.

the class LinkedObjectsFunctions method findLinkedTargets.

// Should be used after assignment evaluation!
@Experimental
@NotNull
<T extends AssignmentHolderType> List<T> findLinkedTargets(Class<T> type, String archetypeOid) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
    Set<PrismReferenceValue> membership = getMembership();
    List<PrismReferenceValue> assignedWithMemberRelation = membership.stream().filter(ref -> relationRegistry.isMember(ref.getRelation()) && objectTypeMatches(ref, type)).collect(Collectors.toList());
    // TODO deduplicate w.r.t. member/manager
    // TODO optimize matching
    List<T> objects = new ArrayList<>(assignedWithMemberRelation.size());
    for (PrismReferenceValue reference : assignedWithMemberRelation) {
        ObjectReferenceType ort = new ObjectReferenceType();
        ort.setupReferenceValue(reference);
        T object = midpointFunctions.resolveReferenceInternal(ort, true);
        if (objectMatches(object, type, archetypeOid)) {
            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) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) Experimental(com.evolveum.midpoint.util.annotation.Experimental) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with AssignmentHolderType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType in project midpoint by Evolveum.

the class AutoAssignMappingCollector method collectAutoassignMappings.

<AH extends AssignmentHolderType> void collectAutoassignMappings(LensContext<AH> context, List<FocalMappingEvaluationRequest<?, ?>> mappings, OperationResult result) throws SchemaException {
    if (!autoassignEnabled(context.getSystemConfiguration())) {
        return;
    }
    ObjectQuery query = prismContext.queryFor(AbstractRoleType.class).item(SchemaConstants.PATH_AUTOASSIGN_ENABLED).eq(true).build();
    ResultHandler<AbstractRoleType> handler = (role, objectResult) -> {
        AutoassignSpecificationType autoassign = role.asObjectable().getAutoassign();
        if (autoassign == null) {
            return true;
        }
        if (!isTrue(autoassign.isEnabled())) {
            return true;
        }
        FocalAutoassignSpecificationType focalAutoassignSpec = autoassign.getFocus();
        if (focalAutoassignSpec == null) {
            return true;
        }
        if (!isApplicableFor(focalAutoassignSpec.getSelector(), context.getFocusContext(), objectResult)) {
            return true;
        }
        for (AutoassignMappingType autoMapping : focalAutoassignSpec.getMapping()) {
            AutoassignMappingType mapping = LensUtil.setMappingTarget(autoMapping, new ItemPathType(SchemaConstants.PATH_ASSIGNMENT));
            mappings.add(new AutoassignRoleMappingEvaluationRequest(mapping, role.asObjectable()));
            LOGGER.trace("Collected autoassign mapping {} from {}", mapping.getName(), role);
        }
        return true;
    };
    cacheRepositoryService.searchObjectsIterative(AbstractRoleType.class, query, handler, createReadOnlyCollection(), true, result);
}
Also used : ResultHandler(com.evolveum.midpoint.schema.ResultHandler) GetOperationOptions.createReadOnlyCollection(com.evolveum.midpoint.schema.GetOperationOptions.createReadOnlyCollection) LensUtil(com.evolveum.midpoint.model.impl.lens.LensUtil) AutoassignRoleMappingEvaluationRequest(com.evolveum.midpoint.model.impl.lens.projector.mappings.AutoassignRoleMappingEvaluationRequest) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Trace(com.evolveum.midpoint.util.logging.Trace) PrismObject(com.evolveum.midpoint.prism.PrismObject) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) BooleanUtils.isTrue(org.apache.commons.lang.BooleanUtils.isTrue) Component(org.springframework.stereotype.Component) List(java.util.List) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) FocalMappingEvaluationRequest(com.evolveum.midpoint.model.impl.lens.projector.mappings.FocalMappingEvaluationRequest) PrismContext(com.evolveum.midpoint.prism.PrismContext) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) AutoassignRoleMappingEvaluationRequest(com.evolveum.midpoint.model.impl.lens.projector.mappings.AutoassignRoleMappingEvaluationRequest)

Example 14 with AssignmentHolderType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType in project midpoint by Evolveum.

the class ExclusionConstraintEvaluator method evaluate.

@Override
public <AH extends AssignmentHolderType> EvaluatedExclusionTrigger evaluate(@NotNull JAXBElement<ExclusionPolicyConstraintType> constraint, @NotNull PolicyRuleEvaluationContext<AH> rctx, OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    OperationResult result = parentResult.subresult(OP_EVALUATE).setMinor().build();
    try {
        LOGGER.trace("Evaluating exclusion constraint {} on {}", lazy(() -> PolicyRuleTypeUtil.toShortString(constraint)), rctx);
        if (!(rctx instanceof AssignmentPolicyRuleEvaluationContext)) {
            return null;
        }
        AssignmentPolicyRuleEvaluationContext<AH> ctx = (AssignmentPolicyRuleEvaluationContext<AH>) rctx;
        if (!ctx.isAdded && !ctx.isKept) {
            LOGGER.trace("Assignment not being added nor kept, skipping evaluation.");
            return null;
        }
        if (sourceOrderConstraintsDoNotMatch(constraint, ctx)) {
            // logged in the called method body
            return null;
        }
        /*
             * Now let us check the exclusions.
             *
             * Assignment A is the current evaluated assignment. It has directly or indirectly attached the exclusion policy rule.
             * We now go through all other assignments B and check the exclusions.
             */
        List<OrderConstraintsType> targetOrderConstraints = defaultIfEmpty(constraint.getValue().getTargetOrderConstraint());
        List<EvaluatedAssignmentTargetImpl> nonNegativeTargetsA = ctx.evaluatedAssignment.getNonNegativeTargets();
        ConstraintReferenceMatcher<AH> refMatcher = new ConstraintReferenceMatcher<>(ctx, constraint.getValue().getTargetRef(), expressionFactory, result, LOGGER);
        for (EvaluatedAssignmentImpl<AH> assignmentB : ctx.evaluatedAssignmentTriple.getNonNegativeValues()) {
            // MID-6403
            if (assignmentB == ctx.evaluatedAssignment) {
                // currently there is no other way of comparing the evaluated assignments
                continue;
            }
            targetB: for (EvaluatedAssignmentTargetImpl targetB : assignmentB.getNonNegativeTargets()) {
                if (!pathMatches(targetB.getAssignmentPath(), targetOrderConstraints)) {
                    LOGGER.trace("Skipping considering exclusion target {} because it does not match target path constraints." + " Path={}, constraints={}", targetB, targetB.getAssignmentPath(), targetOrderConstraints);
                    continue;
                }
                if (!refMatcher.refMatchesTarget(targetB.getTarget(), "exclusion constraint")) {
                    LOGGER.trace("Target {} OID does not match exclusion filter", targetB);
                    continue;
                }
                // To avoid false positives let us check if this target is not already covered by assignment being evaluated
                for (EvaluatedAssignmentTargetImpl targetA : nonNegativeTargetsA) {
                    if (targetIsAlreadyCovered(targetB, targetA)) {
                        continue targetB;
                    }
                }
                EvaluatedExclusionTrigger rv = createTrigger(ctx.evaluatedAssignment, assignmentB, targetB, constraint, ctx.policyRule, ctx, result);
                result.addReturn("trigger", rv.toDiagShortcut());
                return rv;
            }
        }
        return null;
    } catch (Throwable t) {
        result.recordFatalError(t.getMessage(), t);
        throw t;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : AssignmentPolicyRuleEvaluationContext(com.evolveum.midpoint.model.impl.lens.projector.policy.AssignmentPolicyRuleEvaluationContext) EvaluatedAssignmentTargetImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentTargetImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) OrderConstraintsType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrderConstraintsType) EvaluatedExclusionTrigger(com.evolveum.midpoint.model.api.context.EvaluatedExclusionTrigger)

Example 15 with AssignmentHolderType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType in project midpoint by Evolveum.

the class ExclusionConstraintEvaluator method createTrigger.

private <AH extends AssignmentHolderType> EvaluatedExclusionTrigger createTrigger(EvaluatedAssignmentImpl<AH> assignmentA, @NotNull EvaluatedAssignmentImpl<AH> assignmentB, EvaluatedAssignmentTargetImpl targetB, JAXBElement<ExclusionPolicyConstraintType> constraintElement, EvaluatedPolicyRule policyRule, AssignmentPolicyRuleEvaluationContext<AH> ctx, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
    AssignmentPath pathA = policyRule.getAssignmentPath();
    AssignmentPath pathB = targetB.getAssignmentPath();
    LocalizableMessage infoA = createObjectInfo(pathA, assignmentA.getTarget(), true);
    LocalizableMessage infoB = createObjectInfo(pathB, targetB.getTarget(), false);
    ObjectType objectA = getConflictingObject(pathA, assignmentA.getTarget());
    ObjectType objectB = getConflictingObject(pathB, targetB.getTarget());
    LocalizableMessage message = createMessage(infoA, infoB, constraintElement, ctx, result);
    LocalizableMessage shortMessage = createShortMessage(infoA, infoB, constraintElement, ctx, result);
    return new EvaluatedExclusionTrigger(constraintElement.getValue(), message, shortMessage, assignmentB, objectA, objectB, pathA, pathB);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) EvaluatedExclusionTrigger(com.evolveum.midpoint.model.api.context.EvaluatedExclusionTrigger) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) AssignmentPath(com.evolveum.midpoint.model.api.context.AssignmentPath)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 NotNull (org.jetbrains.annotations.NotNull)6 LocalizableMessage (com.evolveum.midpoint.util.LocalizableMessage)5 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)4 LensFocusContext (com.evolveum.midpoint.model.impl.lens.LensFocusContext)4 Trace (com.evolveum.midpoint.util.logging.Trace)4 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)4 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Qualifier (org.springframework.beans.factory.annotation.Qualifier)4 Component (org.springframework.stereotype.Component)4 EvaluatedAssignmentImpl (com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl)3 RelationRegistry (com.evolveum.midpoint.schema.RelationRegistry)3 ArrayList (java.util.ArrayList)3 EvaluatedExclusionTrigger (com.evolveum.midpoint.model.api.context.EvaluatedExclusionTrigger)2 EvaluatedStateTrigger (com.evolveum.midpoint.model.api.context.EvaluatedStateTrigger)2 LinkManager (com.evolveum.midpoint.model.common.LinkManager)2 ModelExpressionThreadLocalHolder (com.evolveum.midpoint.model.common.expression.ModelExpressionThreadLocalHolder)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2