Search in sources :

Example 21 with EvaluatedPolicyRule

use of com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule in project midpoint by Evolveum.

the class PolicyRuleCounterUpdater method updateCounters.

@ProcessorMethod
public <AH extends AssignmentHolderType> void updateCounters(LensContext<AH> context, @SuppressWarnings("unused") XMLGregorianCalendar now, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
    ExecutionSupport executionSupport = task.getExecutionSupport();
    if (executionSupport == null) {
        return;
    }
    /*
         * We update the counters in rules with thresholds in the following ways:
         *
         * 1) If a rule counter was already incremented in this clockwork run, we copy the counter value into the rule.
         * (Regardless of whether it has been triggered during the latest evaluation.)
         *
         * 2) All remaining rules are incremented - if they are triggered.
         *
         * All of this is needed because the rules are quite temporary; they are recreated on each projector run,
         * currently even on each focus iteration (which is maybe unnecessary). We certainly do not want to increase
         * the counters each time. But we need to have the current counter value in the rules even on further projector
         * runs.
         */
    LensFocusContext<AH> focusContext = context.getFocusContextRequired();
    List<EvaluatedPolicyRule> rulesToIncrement = new ArrayList<>();
    for (EvaluatedPolicyRuleImpl rule : focusContext.getObjectPolicyRules()) {
        if (!rule.hasThreshold()) {
            continue;
        }
        Integer alreadyIncrementedValue = focusContext.getPolicyRuleCounter(rule.getPolicyRuleIdentifier());
        if (alreadyIncrementedValue != null) {
            rule.setCount(alreadyIncrementedValue);
            continue;
        }
        if (!rule.isTriggered()) {
            continue;
        }
        rulesToIncrement.add(rule);
    }
    if (rulesToIncrement.isEmpty()) {
        return;
    }
    Map<String, EvaluatedPolicyRule> rulesByIdentifier = rulesToIncrement.stream().collect(Collectors.toMap(EvaluatedPolicyRule::getPolicyRuleIdentifier, Function.identity()));
    ExecutionSupport.CountersGroup group = executionSupport.getExecutionMode() == ExecutionModeType.FULL ? FULL_EXECUTION_MODE_POLICY_RULES : PREVIEW_MODE_POLICY_RULES;
    Map<String, Integer> currentValues = executionSupport.incrementCounters(group, rulesByIdentifier.keySet(), result);
    currentValues.forEach((id, value) -> {
        rulesByIdentifier.get(id).setCount(value);
        focusContext.setPolicyRuleCounter(id, value);
    });
}
Also used : EvaluatedPolicyRule(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule) ExecutionSupport(com.evolveum.midpoint.task.api.ExecutionSupport) EvaluatedPolicyRuleImpl(com.evolveum.midpoint.model.impl.lens.EvaluatedPolicyRuleImpl) CountersGroup(com.evolveum.midpoint.task.api.ExecutionSupport.CountersGroup) ProcessorMethod(com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorMethod)

Example 22 with EvaluatedPolicyRule

use of com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule in project midpoint by Evolveum.

the class PolicySituationConstraintEvaluator method createMessage.

private LocalizableMessage createMessage(Collection<EvaluatedPolicyRule> sourceRules, JAXBElement<PolicySituationPolicyConstraintType> constraintElement, PolicyRuleEvaluationContext<?> ctx, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
    // determine if there's a single message that could be retrieved
    List<TreeNode<LocalizableMessage>> messageTrees = sourceRules.stream().flatMap(r -> r.extractMessages().stream()).collect(Collectors.toList());
    LocalizableMessage builtInMessage;
    if (messageTrees.size() == 1) {
        builtInMessage = messageTrees.get(0).getUserObject();
    } else {
        builtInMessage = new LocalizableMessageBuilder().key(SchemaConstants.DEFAULT_POLICY_CONSTRAINT_KEY_PREFIX + CONSTRAINT_KEY).build();
    }
    return evaluatorHelper.createLocalizableMessage(constraintElement, ctx, builtInMessage, result);
}
Also used : SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Autowired(org.springframework.beans.factory.annotation.Autowired) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) EvaluatedPolicyRule(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule) EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) EvaluatedSituationTrigger(com.evolveum.midpoint.model.api.context.EvaluatedSituationTrigger) AssignmentHolderType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) JAXBElement(javax.xml.bind.JAXBElement) Collection(java.util.Collection) AssignmentPolicyRuleEvaluationContext(com.evolveum.midpoint.model.impl.lens.projector.policy.AssignmentPolicyRuleEvaluationContext) PolicyRuleEvaluationContext(com.evolveum.midpoint.model.impl.lens.projector.policy.PolicyRuleEvaluationContext) PolicySituationPolicyConstraintType(com.evolveum.midpoint.xml.ns._public.common.common_3.PolicySituationPolicyConstraintType) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) TreeNode(com.evolveum.midpoint.util.TreeNode) Collectors(java.util.stream.Collectors) Component(org.springframework.stereotype.Component) List(java.util.List) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) NotNull(org.jetbrains.annotations.NotNull) TreeNode(com.evolveum.midpoint.util.TreeNode) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder)

Example 23 with EvaluatedPolicyRule

use of com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule in project midpoint by Evolveum.

the class PolicySituationConstraintEvaluator method createShortMessage.

private LocalizableMessage createShortMessage(Collection<EvaluatedPolicyRule> sourceRules, JAXBElement<PolicySituationPolicyConstraintType> constraintElement, PolicyRuleEvaluationContext<?> ctx, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
    // determine if there's a single message that could be retrieved
    List<TreeNode<LocalizableMessage>> messageTrees = sourceRules.stream().flatMap(r -> r.extractShortMessages().stream()).collect(Collectors.toList());
    LocalizableMessage builtInMessage;
    if (messageTrees.size() == 1) {
        builtInMessage = messageTrees.get(0).getUserObject();
    } else {
        builtInMessage = new LocalizableMessageBuilder().key(SchemaConstants.DEFAULT_POLICY_CONSTRAINT_SHORT_MESSAGE_KEY_PREFIX + CONSTRAINT_KEY).build();
    }
    return evaluatorHelper.createLocalizableShortMessage(constraintElement, ctx, builtInMessage, result);
}
Also used : SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Autowired(org.springframework.beans.factory.annotation.Autowired) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) EvaluatedPolicyRule(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule) EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) EvaluatedSituationTrigger(com.evolveum.midpoint.model.api.context.EvaluatedSituationTrigger) AssignmentHolderType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) JAXBElement(javax.xml.bind.JAXBElement) Collection(java.util.Collection) AssignmentPolicyRuleEvaluationContext(com.evolveum.midpoint.model.impl.lens.projector.policy.AssignmentPolicyRuleEvaluationContext) PolicyRuleEvaluationContext(com.evolveum.midpoint.model.impl.lens.projector.policy.PolicyRuleEvaluationContext) PolicySituationPolicyConstraintType(com.evolveum.midpoint.xml.ns._public.common.common_3.PolicySituationPolicyConstraintType) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) TreeNode(com.evolveum.midpoint.util.TreeNode) Collectors(java.util.stream.Collectors) Component(org.springframework.stereotype.Component) List(java.util.List) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) NotNull(org.jetbrains.annotations.NotNull) TreeNode(com.evolveum.midpoint.util.TreeNode) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder)

Aggregations

EvaluatedPolicyRule (com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule)23 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)9 Task (com.evolveum.midpoint.task.api.Task)5 Test (org.testng.annotations.Test)5 EvaluatedSituationTrigger (com.evolveum.midpoint.model.api.context.EvaluatedSituationTrigger)3 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)3 LensFocusContext (com.evolveum.midpoint.model.impl.lens.LensFocusContext)3 AssignmentPolicyRuleEvaluationContext (com.evolveum.midpoint.model.impl.lens.projector.policy.AssignmentPolicyRuleEvaluationContext)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 PolicySituationPolicyConstraintType (com.evolveum.midpoint.xml.ns._public.common.common_3.PolicySituationPolicyConstraintType)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 CompiledObjectCollectionView (com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView)2 EvaluatedAssignmentImpl (com.evolveum.midpoint.model.impl.lens.EvaluatedAssignmentImpl)2 EvaluatedPolicyRuleImpl (com.evolveum.midpoint.model.impl.lens.EvaluatedPolicyRuleImpl)2 EvaluatedAssignmentImpl (com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl)2 PolicyRuleEvaluationContext (com.evolveum.midpoint.model.impl.lens.projector.policy.PolicyRuleEvaluationContext)2 RecordingProgressListener (com.evolveum.midpoint.model.impl.util.RecordingProgressListener)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)2