use of com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorMethod in project midpoint by Evolveum.
the class AssignmentProcessor method processOrgAssignments.
@SuppressWarnings("unused")
@ProcessorMethod
<F extends ObjectType> void processOrgAssignments(LensContext<F> context, XMLGregorianCalendar now, Task task, OperationResult result) throws SchemaException, PolicyViolationException {
LensFocusContext<F> focusContext = context.getFocusContext();
Collection<PrismReferenceValue> shouldBeParentOrgRefs = new ArrayList<>();
DeltaSetTriple<EvaluatedAssignmentImpl<?>> evaluatedAssignmentTriple = context.getEvaluatedAssignmentTriple();
if (evaluatedAssignmentTriple == null) {
// could be if "assignments" step is skipped
return;
}
for (EvaluatedAssignmentImpl<?> evalAssignment : evaluatedAssignmentTriple.getNonNegativeValues()) {
// MID-6403
if (evalAssignment.isValid()) {
addReferences(shouldBeParentOrgRefs, evalAssignment.getOrgRefVals());
}
}
setReferences(focusContext, ObjectType.F_PARENT_ORG_REF, shouldBeParentOrgRefs);
ObjectDelta<F> focusPrimaryDelta = focusContext.getPrimaryDelta();
if (focusPrimaryDelta != null) {
ReferenceDelta parentOrgRefDelta = focusPrimaryDelta.findReferenceModification(ObjectType.F_PARENT_ORG_REF);
if (parentOrgRefDelta != null) {
List<PrismReferenceValue> parentOrgRefCurrentValues = null;
PrismObject<F> objectCurrent = focusContext.getObjectCurrent();
if (objectCurrent != null) {
PrismReference parentOrgRefCurrent = objectCurrent.findReference(ObjectType.F_PARENT_ORG_REF);
if (parentOrgRefCurrent != null) {
parentOrgRefCurrentValues = parentOrgRefCurrent.getValues();
}
}
try {
parentOrgRefDelta.validateValues((plusMinusZero, val) -> {
switch(plusMinusZero) {
case PLUS:
case ZERO:
if (!PrismValueCollectionsUtil.containsRealValue(shouldBeParentOrgRefs, val)) {
throw new TunnelException(new PolicyViolationException("Attempt to add parentOrgRef " + val.getOid() + ", but it is not allowed by assignments"));
}
break;
case MINUS:
if (PrismValueCollectionsUtil.containsRealValue(shouldBeParentOrgRefs, val)) {
throw new TunnelException(new PolicyViolationException("Attempt to delete parentOrgRef " + val.getOid() + ", but it is mandated by assignments"));
}
break;
}
}, parentOrgRefCurrentValues);
} catch (TunnelException e) {
throw (PolicyViolationException) e.getCause();
}
}
}
computeTenantRef(context);
}
use of com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorMethod in project midpoint by Evolveum.
the class AssignmentProcessor method processAssignments.
/**
* Processing all the assignments.
*/
@ProcessorMethod
public <O extends ObjectType, AH extends AssignmentHolderType> void processAssignments(LensContext<O> context, XMLGregorianCalendar now, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, PolicyViolationException, CommunicationException, ConfigurationException, SecurityViolationException {
assert context.hasFocusOfType(AssignmentHolderType.class);
OperationResult result = parentResult.createSubresult(AssignmentProcessor.class.getName() + ".processAssignments");
try {
try {
// noinspection unchecked
processAssignmentsInternal((LensContext<AH>) context, now, task, result);
} catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException | PolicyViolationException | CommunicationException | ConfigurationException | SecurityViolationException | RuntimeException | Error e) {
result.recordFatalError(e);
throw e;
}
OperationResultStatus finalStatus = OperationResultStatus.SUCCESS;
String message = null;
int errors = 0;
for (OperationResult subresult : result.getSubresults()) {
if (subresult.isError()) {
errors++;
if (message == null) {
message = subresult.getMessage();
} else {
message = errors + " errors";
}
finalStatus = OperationResultStatus.PARTIAL_ERROR;
}
}
result.setStatus(finalStatus);
result.setMessage(message);
result.recordEnd();
result.cleanupResult();
} catch (Throwable t) {
// shouldn't occur -- just in case
result.recordFatalError(t);
throw t;
}
}
use of com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorMethod in project midpoint by Evolveum.
the class InboundProcessor method processInbounds.
@ProcessorMethod
<F extends FocusType> void processInbounds(LensContext<F> context, String activityDescription, XMLGregorianCalendar now, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, ConfigurationException, CommunicationException, SecurityViolationException {
MappingEvaluationEnvironment env = new MappingEvaluationEnvironment(activityDescription, now, task);
ClockworkInboundsProcessing<F> evaluation = new ClockworkInboundsProcessing<>(context, beans, env, result);
evaluation.collectAndEvaluateMappings();
context.checkConsistenceIfNeeded();
context.recomputeFocus();
medic.traceContext(LOGGER, activityDescription, "inbound", false, context, false);
// It's actually a bit questionable if such cross-components interactions should be treated like this
// or in some higher-level component. But let's try this approach until something nicer is found.
contextLoader.updateArchetypePolicy(context, result);
contextLoader.updateArchetype(context, task, result);
contextLoader.updateFocusTemplate(context, result);
context.checkConsistenceIfNeeded();
}
use of com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorMethod in project midpoint by Evolveum.
the class ProjectionValuesProcessor method processPostRecon.
@ProcessorMethod
<F extends FocusType> void processPostRecon(LensContext<F> context, LensProjectionContext projContext, @SuppressWarnings("unused") String activityDescription, @SuppressWarnings("unused") XMLGregorianCalendar now, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, PolicyViolationException {
SynchronizationPolicyDecision policyDecision = projContext.getSynchronizationPolicyDecision();
if (policyDecision == SynchronizationPolicyDecision.UNLINK) {
// We will not update accounts that are being unlinked.
// we cannot skip deleted accounts here as the delete delta will be skipped as well
LOGGER.trace("Skipping post-recon processing of value for {} because the decision is {}", projContext.getHumanReadableName(), policyDecision);
return;
}
consolidationProcessor.consolidateValuesPostRecon(context, projContext, task, result);
context.checkConsistenceIfNeeded();
projContext.recompute();
context.checkConsistenceIfNeeded();
}
use of com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorMethod 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);
});
}
Aggregations