Search in sources :

Example 41 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class ProjectionValuesProcessor method process.

public <O extends ObjectType> void process(LensContext<O> context, LensProjectionContext projectionContext, String activityDescription, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException, PolicyViolationException {
    LensFocusContext<O> focusContext = context.getFocusContext();
    if (focusContext == null) {
        return;
    }
    if (!FocusType.class.isAssignableFrom(focusContext.getObjectTypeClass())) {
        // We can do this only for focus types.
        return;
    }
    OperationResult processorResult = result.createMinorSubresult(ProjectionValuesProcessor.class.getName() + ".processAccountsValues");
    processorResult.recordSuccessIfUnknown();
    processProjections((LensContext<? extends FocusType>) context, projectionContext, activityDescription, task, processorResult);
}
Also used : FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 42 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class FocusProcessor method processFocusFocus.

private <F extends FocusType> void processFocusFocus(LensContext<F> context, String activityDescription, XMLGregorianCalendar now, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, PolicyViolationException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
    LensFocusContext<F> focusContext = context.getFocusContext();
    ObjectTemplateType objectTemplate = context.getFocusTemplate();
    PartialProcessingOptionsType partialProcessingOptions = context.getPartialProcessingOptions();
    // This is fixed now. TODO: make it configurable
    boolean resetOnRename = true;
    int maxIterations = 0;
    IterationSpecificationType iterationSpecificationType = null;
    if (objectTemplate != null) {
        iterationSpecificationType = objectTemplate.getIteration();
        maxIterations = LensUtil.determineMaxIterations(iterationSpecificationType);
    }
    int iteration = focusContext.getIteration();
    String iterationToken = focusContext.getIterationToken();
    boolean wasResetIterationCounter = false;
    PrismObject<F> focusCurrent = focusContext.getObjectCurrent();
    if (focusCurrent != null && iterationToken == null) {
        Integer focusIteration = focusCurrent.asObjectable().getIteration();
        if (focusIteration != null) {
            iteration = focusIteration;
        }
        iterationToken = focusCurrent.asObjectable().getIterationToken();
    }
    while (true) {
        ObjectPolicyConfigurationType objectPolicyConfigurationType = focusContext.getObjectPolicyConfigurationType();
        applyObjectPolicyConstraints(focusContext, objectPolicyConfigurationType);
        ExpressionVariables variablesPreIteration = Utils.getDefaultExpressionVariables(focusContext.getObjectNew(), null, null, null, context.getSystemConfiguration(), focusContext);
        if (iterationToken == null) {
            iterationToken = LensUtil.formatIterationToken(context, focusContext, iterationSpecificationType, iteration, expressionFactory, variablesPreIteration, task, result);
        }
        // We have to remember the token and iteration in the context.
        // The context can be recomputed several times. But we always want
        // to use the same iterationToken if possible. If there is a random
        // part in the iterationToken expression that we need to avoid recomputing
        // the token otherwise the value can change all the time (even for the same inputs).
        // Storing the token in the secondary delta is not enough because secondary deltas can be dropped
        // if the context is re-projected.
        focusContext.setIteration(iteration);
        focusContext.setIterationToken(iterationToken);
        LOGGER.trace("Focus {} processing, iteration {}, token '{}'", focusContext.getHumanReadableName(), iteration, iterationToken);
        String conflictMessage;
        if (!LensUtil.evaluateIterationCondition(context, focusContext, iterationSpecificationType, iteration, iterationToken, true, expressionFactory, variablesPreIteration, task, result)) {
            conflictMessage = "pre-iteration condition was false";
            LOGGER.debug("Skipping iteration {}, token '{}' for {} because the pre-iteration condition was false", iteration, iterationToken, focusContext.getHumanReadableName());
        } else {
            if (consistencyChecks)
                context.checkConsistence();
            LensUtil.partialExecute("inbound", () -> {
                // Loop through the account changes, apply inbound expressions
                inboundProcessor.processInbound(context, now, task, result);
                if (consistencyChecks)
                    context.checkConsistence();
                context.recomputeFocus();
                LensUtil.traceContext(LOGGER, activityDescription, "inbound", false, context, false);
                if (consistencyChecks)
                    context.checkConsistence();
            }, partialProcessingOptions::getInbound);
            // ACTIVATION
            LensUtil.partialExecute("focusActivation", () -> processActivation(context, now, result), partialProcessingOptions::getFocusActivation);
            // OBJECT TEMPLATE (before assignments)
            LensUtil.partialExecute("objectTemplateBeforeAssignments", () -> objectTemplateProcessor.processTemplate(context, ObjectTemplateMappingEvaluationPhaseType.BEFORE_ASSIGNMENTS, now, task, result), partialProcessingOptions::getObjectTemplateBeforeAssignments);
            // process activation again. Object template might have changed it.
            context.recomputeFocus();
            LensUtil.partialExecute("focusActivation", () -> processActivation(context, now, result), partialProcessingOptions::getFocusActivation);
            // ASSIGNMENTS
            LensUtil.partialExecute("assignments", () -> assignmentProcessor.processAssignmentsProjections(context, now, task, result), partialProcessingOptions::getAssignments);
            LensUtil.partialExecute("assignmentsOrg", () -> assignmentProcessor.processOrgAssignments(context, result), partialProcessingOptions::getAssignmentsOrg);
            LensUtil.partialExecute("assignmentsMembershipAndDelegate", () -> assignmentProcessor.processMembershipAndDelegatedRefs(context, result), partialProcessingOptions::getAssignmentsMembershipAndDelegate);
            context.recompute();
            LensUtil.partialExecute("assignmentsConflicts", () -> assignmentProcessor.checkForAssignmentConflicts(context, result), partialProcessingOptions::getAssignmentsConflicts);
            // OBJECT TEMPLATE (after assignments)
            LensUtil.partialExecute("objectTemplateAfterAssignments", () -> objectTemplateProcessor.processTemplate(context, ObjectTemplateMappingEvaluationPhaseType.AFTER_ASSIGNMENTS, now, task, result), partialProcessingOptions::getObjectTemplateBeforeAssignments);
            context.recompute();
            // process activation again. Second pass through object template might have changed it.
            context.recomputeFocus();
            LensUtil.partialExecute("focusActivation", () -> processActivation(context, now, result), partialProcessingOptions::getFocusActivation);
            // CREDENTIALS (including PASSWORD POLICY)
            LensUtil.partialExecute("focusCredentials", () -> credentialsProcessor.processFocusCredentials(context, now, task, result), partialProcessingOptions::getFocusCredentials);
            // We need to evaluate this as a last step. We need to make sure we have all the
            // focus deltas so we can properly trigger the rules.
            LensUtil.partialExecute("focusPolicyRules", () -> evaluateFocusPolicyRules(context, activityDescription, now, task, result), partialProcessingOptions::getFocusPolicyRules);
            if (resetOnRename && !wasResetIterationCounter && willResetIterationCounter(focusContext)) {
                // Make sure this happens only the very first time during the first recompute.
                // Otherwise it will always change the token (especially if the token expression has a random part)
                // hence the focusContext.getIterationToken() == null
                wasResetIterationCounter = true;
                if (iteration != 0) {
                    iteration = 0;
                    iterationToken = null;
                    LOGGER.trace("Resetting iteration counter and token because rename was detected");
                    cleanupContext(focusContext);
                    continue;
                }
            }
            PrismObject<F> previewObjectNew = focusContext.getObjectNew();
            if (previewObjectNew == null) {
            // this must be delete
            } else {
                // Explicitly check for name. The checker would check for this also. But checking it here
                // will produce better error message
                PolyStringType objectName = previewObjectNew.asObjectable().getName();
                if (objectName == null || objectName.getOrig().isEmpty()) {
                    throw new NoFocusNameSchemaException("No name in new object " + objectName + " as produced by template " + objectTemplate + " in iteration " + iteration + ", we cannot process an object without a name");
                }
            }
            // Check if iteration constraints are OK
            FocusConstraintsChecker<F> checker = new FocusConstraintsChecker<>();
            checker.setPrismContext(prismContext);
            checker.setContext(context);
            checker.setRepositoryService(cacheRepositoryService);
            checker.check(previewObjectNew, result);
            if (checker.isSatisfiesConstraints()) {
                LOGGER.trace("Current focus satisfies uniqueness constraints. Iteration {}, token '{}'", iteration, iterationToken);
                ExpressionVariables variablesPostIteration = Utils.getDefaultExpressionVariables(focusContext.getObjectNew(), null, null, null, context.getSystemConfiguration(), focusContext);
                if (LensUtil.evaluateIterationCondition(context, focusContext, iterationSpecificationType, iteration, iterationToken, false, expressionFactory, variablesPostIteration, task, result)) {
                    // stop the iterations
                    break;
                } else {
                    conflictMessage = "post-iteration condition was false";
                    LOGGER.debug("Skipping iteration {}, token '{}' for {} because the post-iteration condition was false", iteration, iterationToken, focusContext.getHumanReadableName());
                }
            } else {
                LOGGER.trace("Current focus does not satisfy constraints. Conflicting object: {}; iteration={}, maxIterations={}", checker.getConflictingObject(), iteration, maxIterations);
                conflictMessage = checker.getMessages();
            }
            if (!wasResetIterationCounter) {
                wasResetIterationCounter = true;
                if (iteration != 0) {
                    iterationToken = null;
                    iteration = 0;
                    LOGGER.trace("Resetting iteration counter and token after conflict");
                    cleanupContext(focusContext);
                    continue;
                }
            }
        }
        // Next iteration
        iteration++;
        iterationToken = null;
        LensUtil.checkMaxIterations(iteration, maxIterations, conflictMessage, focusContext.getHumanReadableName());
        cleanupContext(focusContext);
    }
    addIterationTokenDeltas(focusContext, iteration, iterationToken);
    if (consistencyChecks)
        context.checkConsistence();
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) PartialProcessingOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.PartialProcessingOptionsType) NoFocusNameSchemaException(com.evolveum.midpoint.util.exception.NoFocusNameSchemaException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) IterationSpecificationType(com.evolveum.midpoint.xml.ns._public.common.common_3.IterationSpecificationType) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) ObjectPolicyConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectPolicyConfigurationType)

Example 43 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class FocusProcessor method triggerRule.

private <F extends FocusType> void triggerRule(LensFocusContext<F> focusContext, EvaluatedPolicyRule policyRule) throws PolicyViolationException, SchemaException {
    PolicyConstraintsType policyConstraints = policyRule.getPolicyConstraints();
    if (policyConstraints == null) {
        return;
    }
    for (ModificationPolicyConstraintType modificationConstraintType : policyConstraints.getModification()) {
        focusContext.addPolicyRule(policyRule);
        if (modificationConstraintMatches(focusContext, policyRule, modificationConstraintType)) {
            EvaluatedPolicyRuleTrigger<?> trigger = new EvaluatedPolicyRuleTrigger<>(PolicyConstraintKindType.MODIFICATION, modificationConstraintType, "Focus " + focusContext.getHumanReadableName() + " was modified");
            focusContext.triggerConstraint(policyRule, trigger);
        }
    }
}
Also used : PolicyConstraintsType(com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyConstraintsType) EvaluatedPolicyRuleTrigger(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRuleTrigger) ModificationPolicyConstraintType(com.evolveum.midpoint.xml.ns._public.common.common_3.ModificationPolicyConstraintType)

Example 44 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method assertSideEffectiveDeltasOnly.

protected <F extends FocusType> void assertSideEffectiveDeltasOnly(String desc, ObjectDelta<F> focusDelta) {
    if (focusDelta == null) {
        return;
    }
    int expectedModifications = 0;
    // There may be metadata modification, we tolerate that
    Collection<? extends ItemDelta<?, ?>> metadataDelta = focusDelta.findItemDeltasSubPath(new ItemPath(UserType.F_METADATA));
    if (metadataDelta != null && !metadataDelta.isEmpty()) {
        expectedModifications += metadataDelta.size();
    }
    if (focusDelta.findItemDelta(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_ENABLE_TIMESTAMP)) != null) {
        expectedModifications++;
    }
    if (focusDelta.findItemDelta(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_DISABLE_TIMESTAMP)) != null) {
        expectedModifications++;
    }
    if (focusDelta.findItemDelta(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_ARCHIVE_TIMESTAMP)) != null) {
        expectedModifications++;
    }
    PropertyDelta<ActivationStatusType> effectiveStatusDelta = focusDelta.findPropertyDelta(new ItemPath(UserType.F_ACTIVATION, ActivationType.F_EFFECTIVE_STATUS));
    if (effectiveStatusDelta != null) {
        expectedModifications++;
    }
    if (focusDelta.findItemDelta(new ItemPath(FocusType.F_ITERATION)) != null) {
        expectedModifications++;
    }
    if (focusDelta.findItemDelta(new ItemPath(FocusType.F_ROLE_MEMBERSHIP_REF)) != null) {
        expectedModifications++;
    }
    if (focusDelta.findItemDelta(new ItemPath(FocusType.F_DELEGATED_REF)) != null) {
        expectedModifications++;
    }
    if (focusDelta.findItemDelta(new ItemPath(FocusType.F_ITERATION_TOKEN)) != null) {
        expectedModifications++;
    }
    assertEquals("Unexpected modifications in " + desc + ": " + focusDelta, expectedModifications, focusDelta.getModifications().size());
}
Also used : ActivationStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 45 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method assertEffectualDeltas.

protected <F extends FocusType> void assertEffectualDeltas(ObjectDelta<F> focusDelta, String desc, ActivationStatusType expectedEfficientActivation, int expectedEffectualModifications) {
    if (focusDelta == null) {
        return;
    }
    int expectedModifications = expectedEffectualModifications;
    // There may be metadata modification, we tolerate that
    for (ItemDelta<?, ?> modification : focusDelta.getModifications()) {
        if (modification.getPath().containsName(ObjectType.F_METADATA)) {
            expectedModifications++;
        }
    }
    if (focusDelta.findItemDelta(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_ENABLE_TIMESTAMP)) != null) {
        expectedModifications++;
    }
    if (focusDelta.findItemDelta(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_DISABLE_TIMESTAMP)) != null) {
        expectedModifications++;
    }
    if (focusDelta.findItemDelta(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_ARCHIVE_TIMESTAMP)) != null) {
        expectedModifications++;
    }
    PropertyDelta<ActivationStatusType> effectiveStatusDelta = focusDelta.findPropertyDelta(new ItemPath(UserType.F_ACTIVATION, ActivationType.F_EFFECTIVE_STATUS));
    if (effectiveStatusDelta != null) {
        expectedModifications++;
        PrismAsserts.assertReplace(effectiveStatusDelta, expectedEfficientActivation);
    }
    if (focusDelta.findItemDelta(new ItemPath(FocusType.F_ROLE_MEMBERSHIP_REF)) != null) {
        expectedModifications++;
    }
    if (focusDelta.findItemDelta(new ItemPath(FocusType.F_DELEGATED_REF)) != null) {
        expectedModifications++;
    }
    if (focusDelta.findItemDelta(new ItemPath(FocusType.F_ITERATION)) != null) {
        expectedModifications++;
    }
    if (focusDelta.findItemDelta(new ItemPath(FocusType.F_ITERATION_TOKEN)) != null) {
        expectedModifications++;
    }
    assertEquals("Unexpected modifications in " + desc + ": " + focusDelta, expectedModifications, focusDelta.getModifications().size());
}
Also used : ActivationStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)27 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)25 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)23 FocusType (com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType)22 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)21 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)18 PrismObject (com.evolveum.midpoint.prism.PrismObject)16 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)15 ArrayList (java.util.ArrayList)15 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)14 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)12 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)10 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)8 QName (javax.xml.namespace.QName)8 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)7 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)7 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)7 ActivationStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType)7