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);
});
}
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);
}
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);
}
Aggregations