Search in sources :

Example 6 with OrderConstraintsType

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

the class TargetInducementEvaluation method applyResetForRelations.

private OrderAdjustment applyResetForRelations(EvaluationOrder currentOrder, EvaluationOrder currentTargetOrder, List<OrderConstraintsType> constraints) {
    EvaluationOrder updatedOrder = currentOrder;
    for (OrderConstraintsType constraint : constraints) {
        if (constraint.getResetOrder() != null) {
            // already processed above
            assert constraint.getRelation() != null;
            int currentOrderForRelation = updatedOrder.getMatchingRelationOrder(constraint.getRelation());
            int newOrderForRelation = constraint.getResetOrder();
            if (newOrderForRelation > currentOrderForRelation) {
                LOGGER.warn("Cannot increase evaluation order for {} from {} to {}: {}", constraint.getRelation(), currentOrderForRelation, newOrderForRelation, constraint);
            } else if (newOrderForRelation < currentOrderForRelation) {
                updatedOrder = updatedOrder.resetOrder(constraint.getRelation(), newOrderForRelation);
                LOGGER.trace("Reset order for {} from {} to {} -> {}", constraint.getRelation(), currentOrderForRelation, newOrderForRelation, updatedOrder);
            } else {
                LOGGER.trace("Keeping order for {} at {} -> {}", constraint.getRelation(), currentOrderForRelation, updatedOrder);
            }
        }
    }
    Map<QName, Integer> difference = currentOrder.diff(updatedOrder);
    EvaluationOrder updatedTargetOrder = currentTargetOrder.applyDifference(difference);
    return new OrderAdjustment(updatedOrder, updatedTargetOrder);
}
Also used : OrderConstraintsType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrderConstraintsType) EvaluationOrder(com.evolveum.midpoint.model.api.context.EvaluationOrder) QName(javax.xml.namespace.QName)

Example 7 with OrderConstraintsType

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

the class EvaluationOrderImpl method matches.

@Override
public boolean matches(Integer assignmentOrder, List<OrderConstraintsType> assignmentOrderConstraint) {
    boolean rv;
    List<QName> extraRelations = new ArrayList<>(getExtraRelations());
    if (assignmentOrder == null && assignmentOrderConstraint.isEmpty()) {
        // compatibility
        rv = getSummaryOrder() == 1;
    } else {
        rv = true;
        if (assignmentOrder != null) {
            if (getSummaryOrder() != assignmentOrder) {
                rv = false;
            }
        }
        for (OrderConstraintsType orderConstraint : assignmentOrderConstraint) {
            if (!isMatchingConstraint(orderConstraint)) {
                rv = false;
                break;
            }
            extraRelations.removeIf(r -> QNameUtil.match(r, orderConstraint.getRelation()));
        }
    }
    // TODO this is to be reconsidered -- why do we consider assignment of relation e.g. approver non-matching?
    if (!extraRelations.isEmpty()) {
        rv = false;
    }
    LOGGER.trace("computeMatchingOrder => {}, for assignment.order={}, assignment.orderConstraint={}, evaluationOrder={}, remainingExtraRelations={}", rv, assignmentOrder, assignmentOrderConstraint, this, extraRelations);
    return rv;
}
Also used : OrderConstraintsType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrderConstraintsType) QName(javax.xml.namespace.QName)

Example 8 with OrderConstraintsType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OrderConstraintsType 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)

Aggregations

OrderConstraintsType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrderConstraintsType)8 QName (javax.xml.namespace.QName)3 EvaluationOrder (com.evolveum.midpoint.model.api.context.EvaluationOrder)2 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)2 ArrayList (java.util.ArrayList)2 EvaluatedExclusionTrigger (com.evolveum.midpoint.model.api.context.EvaluatedExclusionTrigger)1 EvaluatedAssignmentTargetImpl (com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentTargetImpl)1 AssignmentPolicyRuleEvaluationContext (com.evolveum.midpoint.model.impl.lens.projector.policy.AssignmentPolicyRuleEvaluationContext)1 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)1 AccessDecision (com.evolveum.midpoint.schema.AccessDecision)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)1 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)1