Search in sources :

Example 1 with ProcessorMethod

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);
}
Also used : EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl) TunnelException(com.evolveum.midpoint.util.exception.TunnelException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ProcessorMethod(com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorMethod)

Example 2 with ProcessorMethod

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;
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ProcessorMethod(com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorMethod)

Example 3 with ProcessorMethod

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();
}
Also used : ClockworkInboundsProcessing(com.evolveum.midpoint.model.impl.lens.projector.focus.inbounds.ClockworkInboundsProcessing) MappingEvaluationEnvironment(com.evolveum.midpoint.model.common.mapping.MappingEvaluationEnvironment) ProcessorMethod(com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorMethod)

Example 4 with ProcessorMethod

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();
}
Also used : SynchronizationPolicyDecision(com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision) ProcessorMethod(com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorMethod)

Example 5 with ProcessorMethod

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

Aggregations

ProcessorMethod (com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorMethod)5 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)2 EvaluatedPolicyRule (com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule)1 SynchronizationPolicyDecision (com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision)1 MappingEvaluationEnvironment (com.evolveum.midpoint.model.common.mapping.MappingEvaluationEnvironment)1 EvaluatedPolicyRuleImpl (com.evolveum.midpoint.model.impl.lens.EvaluatedPolicyRuleImpl)1 EvaluatedAssignmentImpl (com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl)1 ClockworkInboundsProcessing (com.evolveum.midpoint.model.impl.lens.projector.focus.inbounds.ClockworkInboundsProcessing)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 OperationResultStatus (com.evolveum.midpoint.schema.result.OperationResultStatus)1 ExecutionSupport (com.evolveum.midpoint.task.api.ExecutionSupport)1 CountersGroup (com.evolveum.midpoint.task.api.ExecutionSupport.CountersGroup)1 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)1 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)1 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)1 TunnelException (com.evolveum.midpoint.util.exception.TunnelException)1