use of com.evolveum.midpoint.model.impl.lens.LensFocusContext in project midpoint by Evolveum.
the class PolicyRuleBasedAspect method extractObjectBasedInstructions.
private void extractObjectBasedInstructions(@NotNull ObjectTreeDeltas objectTreeDeltas, PrismObject<UserType> requester, List<PcpChildWfTaskCreationInstruction> instructions, ModelInvocationContext ctx, @NotNull OperationResult result) throws SchemaException {
ObjectDelta<?> focusDelta = objectTreeDeltas.getFocusChange();
LensFocusContext<?> focusContext = (LensFocusContext<?>) ctx.modelContext.getFocusContext();
PrismObject<?> object = focusContext.getObjectOld() != null ? focusContext.getObjectOld() : focusContext.getObjectNew();
Map<Set<ItemPath>, ApprovalSchemaBuilder> schemaBuilders = new HashMap<>();
List<EvaluatedPolicyRule> approvalActionRules = getApprovalActionRules(focusContext.getPolicyRules());
LOGGER.trace("extractObjectBasedInstructions: approvalActionRules:\n{}", DebugUtil.debugDumpLazily(approvalActionRules));
for (EvaluatedPolicyRule rule : approvalActionRules) {
Set<ItemPath> key;
if (focusDelta.isAdd() || focusDelta.isDelete()) {
key = Collections.emptySet();
} else {
Set<ItemPath> items = getAffectedItems(rule.getTriggers());
Set<ItemPath> affectedItems;
if (!items.isEmpty()) {
// all items in triggered constraints were modified (that's how the constraints work)
affectedItems = items;
} else {
// whole object
affectedItems = new HashSet<>(focusDelta.getModifiedItems());
}
key = affectedItems;
}
ApprovalSchemaBuilder builder = schemaBuilders.computeIfAbsent(key, k -> new ApprovalSchemaBuilder(this, approvalSchemaHelper));
ApprovalPolicyActionType approvalAction = rule.getActions().getApproval();
builder.add(getSchemaFromAction(approvalAction), approvalAction.getCompositionStrategy(), object, rule);
}
// default rule
if (approvalActionRules.isEmpty() && baseConfigurationHelper.getUseDefaultApprovalPolicyRules(ctx.wfConfiguration) != DefaultApprovalPolicyRulesUsageType.NEVER) {
ApprovalSchemaBuilder builder = new ApprovalSchemaBuilder(this, approvalSchemaHelper);
if (builder.addPredefined(object, SchemaConstants.ORG_OWNER, result)) {
LOGGER.trace("Added default approval action, as no explicit one was found");
schemaBuilders.put(Collections.emptySet(), builder);
}
}
// create approval requests; also test for overlaps
Set<ItemPath> itemsProcessed = null;
for (Map.Entry<Set<ItemPath>, ApprovalSchemaBuilder> entry : schemaBuilders.entrySet()) {
ApprovalSchemaBuilder.Result builderResult = entry.getValue().buildSchema(ctx, result);
if (approvalSchemaHelper.shouldBeSkipped(builderResult.schemaType)) {
continue;
}
Set<ItemPath> items = entry.getKey();
if (itemsProcessed != null) {
if (items.isEmpty() || itemsProcessed.isEmpty() || CollectionUtils.containsAny(itemsProcessed, items)) {
throw new IllegalStateException("Overlapping modification-related policy rules. " + "Items processed = " + itemsProcessed + ", current items = " + items);
}
itemsProcessed.addAll(items);
} else {
itemsProcessed = items;
}
instructions.add(prepareObjectRelatedTaskInstruction(builderResult, focusDelta, items, ctx.modelContext, requester, result));
}
}
use of com.evolveum.midpoint.model.impl.lens.LensFocusContext in project midpoint by Evolveum.
the class NotificationChangeHook method emitPolicyRulesEvents.
private void emitPolicyRulesEvents(ModelContext<?> context, Task task, OperationResult result) {
LensFocusContext<?> focusContext = (LensFocusContext<?>) context.getFocusContext();
for (EvaluatedPolicyRule rule : focusContext.getPolicyRules()) {
emitPolicyEventIfPresent(rule, context, task, result);
}
DeltaSetTriple<EvaluatedAssignmentImpl<?>> triple = ((LensContext<?>) context).getEvaluatedAssignmentTriple();
if (triple != null) {
for (EvaluatedAssignment<?> assignment : triple.getNonNegativeValues()) {
for (EvaluatedPolicyRule rule : assignment.getAllTargetsPolicyRules()) {
emitPolicyEventIfPresent(rule, context, task, result);
}
}
}
}
Aggregations