Search in sources :

Example 6 with AssignmentHolderType

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

the class TransitionConstraintEvaluator method evaluate.

@Override
public <AH extends AssignmentHolderType> EvaluatedPolicyRuleTrigger evaluate(@NotNull JAXBElement<TransitionPolicyConstraintType> constraintElement, @NotNull PolicyRuleEvaluationContext<AH> rctx, OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    OperationResult result = parentResult.subresult(OP_EVALUATE).setMinor().build();
    try {
        TransitionPolicyConstraintType trans = constraintElement.getValue();
        List<EvaluatedPolicyRuleTrigger<?>> triggers = new ArrayList<>();
        boolean match = evaluateState(trans, rctx, ObjectState.BEFORE, trans.isStateBefore(), triggers, result) && evaluateState(trans, rctx, ObjectState.AFTER, trans.isStateAfter(), triggers, result);
        if (match) {
            return new EvaluatedTransitionTrigger(PolicyConstraintKindType.TRANSITION, trans, createMessage(constraintElement, rctx, result), createShortMessage(constraintElement, rctx, result), triggers);
        } else {
            return null;
        }
    } catch (Throwable t) {
        result.recordFatalError(t.getMessage(), t);
        throw t;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : TransitionPolicyConstraintType(com.evolveum.midpoint.xml.ns._public.common.common_3.TransitionPolicyConstraintType) EvaluatedPolicyRuleTrigger(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRuleTrigger) EvaluatedTransitionTrigger(com.evolveum.midpoint.model.api.context.EvaluatedTransitionTrigger) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 7 with AssignmentHolderType

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

the class LinkedObjectsFunctions method findLinkedTargets.

// Should be used after assignment evaluation!
@Experimental
@NotNull
<T extends AssignmentHolderType> List<T> findLinkedTargets(String linkTypeName) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
    OperationResult currentResult = midpointFunctions.getCurrentResult();
    LensFocusContext<?> focusContext = (LensFocusContext<?>) midpointFunctions.getFocusContext();
    if (focusContext == null) {
        throw new IllegalStateException("No focus context");
    }
    LinkTypeDefinitionType definition = focusContext.getTargetLinkTypeDefinition(linkTypeName, linkManager, currentResult);
    if (definition == null) {
        throw new IllegalStateException("No definition for target link type " + linkTypeName + " for " + focusContext);
    }
    Class<?> expectedClasses = getExpectedClass(definition.getSelector());
    Set<PrismReferenceValue> membership = getMembership();
    List<PrismReferenceValue> assignedWithMatchingRelation = membership.stream().filter(ref -> relationMatches(ref, definition.getSelector()) && objectTypeMatches(ref, expectedClasses)).collect(Collectors.toList());
    // TODO deduplicate w.r.t. member/manager
    // TODO optimize matching
    List<T> objects = new ArrayList<>(assignedWithMatchingRelation.size());
    for (PrismReferenceValue reference : assignedWithMatchingRelation) {
        ObjectReferenceType ort = new ObjectReferenceType();
        ort.setupReferenceValue(reference);
        T object = midpointFunctions.resolveReferenceInternal(ort, true);
        if (objectMatches(object, definition.getSelector())) {
            objects.add(object);
        }
    }
    return objects;
}
Also used : java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Trace(com.evolveum.midpoint.util.logging.Trace) ModelExpressionThreadLocalHolder(com.evolveum.midpoint.model.common.expression.ModelExpressionThreadLocalHolder) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) PrismContext(com.evolveum.midpoint.prism.PrismContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) RelationRegistry(com.evolveum.midpoint.schema.RelationRegistry) EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) LinkedSelectorToFilterTranslator(com.evolveum.midpoint.repo.common.query.LinkedSelectorToFilterTranslator) Experimental(com.evolveum.midpoint.util.annotation.Experimental) Collections.emptySet(java.util.Collections.emptySet) Objectable(com.evolveum.midpoint.prism.Objectable) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) Objects(java.util.Objects) Component(org.springframework.stereotype.Component) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) Modifier(java.lang.reflect.Modifier) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext) LinkManager(com.evolveum.midpoint.model.common.LinkManager) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) NotNull(org.jetbrains.annotations.NotNull) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext) Experimental(com.evolveum.midpoint.util.annotation.Experimental) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with AssignmentHolderType

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

the class AssignmentCollector method createAuthenticationLensContext.

private <AH extends AssignmentHolderType> LensContext<AH> createAuthenticationLensContext(PrismObject<AH> user, OperationResult result) throws SchemaException {
    LensContext<AH> lensContext = new LensContextPlaceholder<>(user);
    ArchetypePolicyType policyConfigurationType = determineObjectPolicyConfiguration(user, result);
    lensContext.getFocusContext().setArchetypePolicy(policyConfigurationType);
    return lensContext;
}
Also used : ArchetypePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ArchetypePolicyType)

Example 9 with AssignmentHolderType

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

the class AssignmentProcessor method evaluateFocusMappings.

private <AH extends AssignmentHolderType> void evaluateFocusMappings(LensContext<AH> context, XMLGregorianCalendar now, LensFocusContext<AH> focusContext, DeltaSetTriple<EvaluatedAssignmentImpl<AH>> evaluatedAssignmentTriple, Task task, OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, PolicyViolationException, ConfigurationException, SecurityViolationException, ObjectNotFoundException, CommunicationException {
    OperationResult result = parentResult.subresult(OP_EVALUATE_FOCUS_MAPPINGS).setMinor().build();
    try {
        LOGGER.trace("Starting evaluation of assignment-held mappings");
        ObjectDeltaObject<AH> focusOdoRelative = focusContext.getObjectDeltaObjectRelative();
        List<AssignedFocusMappingEvaluationRequest> allRequests = new ArrayList<>();
        for (EvaluatedAssignmentImpl<AH> evaluatedAssignment : evaluatedAssignmentTriple.getAllValues()) {
            allRequests.addAll(evaluatedAssignment.getFocusMappingEvaluationRequests());
        }
        FocalMappingSetEvaluation.TripleCustomizer<?, ?> customizer = (triple, abstractRequest) -> {
            if (triple == null) {
                return null;
            }
            DeltaSetTriple<ItemValueWithOrigin<PrismValue, ItemDefinition<?>>> rv = prismContext.deltaFactory().createDeltaSetTriple();
            AssignedFocusMappingEvaluationRequest request = (AssignedFocusMappingEvaluationRequest) abstractRequest;
            // noinspection unchecked
            EvaluatedAssignmentImpl<AH> evaluatedAssignment = (EvaluatedAssignmentImpl<AH>) request.getEvaluatedAssignment();
            PlusMinusZero relativeMode = request.getRelativeMode();
            Set<PlusMinusZero> presence = new HashSet<>();
            PlusMinusZero resultingMode = null;
            if (evaluatedAssignmentTriple.presentInPlusSet(evaluatedAssignment)) {
                resultingMode = PlusMinusZero.compute(PlusMinusZero.PLUS, relativeMode);
                presence.add(PlusMinusZero.PLUS);
            }
            if (evaluatedAssignmentTriple.presentInMinusSet(evaluatedAssignment)) {
                resultingMode = PlusMinusZero.compute(PlusMinusZero.MINUS, relativeMode);
                presence.add(PlusMinusZero.MINUS);
            }
            if (evaluatedAssignmentTriple.presentInZeroSet(evaluatedAssignment)) {
                resultingMode = PlusMinusZero.compute(PlusMinusZero.ZERO, relativeMode);
                presence.add(PlusMinusZero.ZERO);
            }
            LOGGER.trace("triple customizer: presence = {}, relativeMode = {}, resultingMode = {}", presence, relativeMode, resultingMode);
            if (presence.isEmpty()) {
                throw new IllegalStateException("Evaluated assignment is not present in any of plus/minus/zero sets " + "of the triple. Assignment = " + evaluatedAssignment + ", triple = " + triple);
            } else if (presence.size() > 1) {
                // TODO think about this
                throw new IllegalStateException("Evaluated assignment is present in more than one plus/minus/zero sets " + "of the triple: " + presence + ". Assignment = " + evaluatedAssignment + ", triple = " + triple);
            }
            if (resultingMode != null) {
                switch(resultingMode) {
                    case PLUS:
                        // MID-6403
                        rv.addAllToPlusSet(triple.getNonNegativeValues());
                        break;
                    case MINUS:
                        // MID-6403
                        rv.addAllToMinusSet(triple.getNonPositiveValues());
                        break;
                    case ZERO:
                        rv = triple;
                        break;
                }
            }
            return rv;
        };
        FocalMappingSetEvaluation.EvaluatedMappingConsumer mappingConsumer = (mapping, abstractRequest) -> {
            AssignedFocusMappingEvaluationRequest request = (AssignedFocusMappingEvaluationRequest) abstractRequest;
            request.getEvaluatedAssignment().addFocusMapping(mapping);
        };
        TargetObjectSpecification<AH> targetSpecification = new FixedTargetSpecification<>(focusOdoRelative.getNewObject(), true);
        MappingEvaluationEnvironment env = new MappingEvaluationEnvironment("focus mappings in assignments of " + focusContext.getHumanReadableName(), now, task);
        FocalMappingSetEvaluation<AH, AH> mappingSetEvaluation = new FocalMappingSetEvaluationBuilder<AH, AH>().context(context).evaluationRequests(allRequests).phase(null).focusOdo(focusOdoRelative).targetSpecification(targetSpecification).tripleCustomizer(customizer).mappingConsumer(mappingConsumer).iteration(focusContext.getIteration()).iterationToken(focusContext.getIterationToken()).beans(beans).env(env).result(result).build();
        mappingSetEvaluation.evaluateMappingsToTriples();
        PathKeyedMap<DeltaSetTriple<ItemValueWithOrigin<?, ?>>> focusOutputTripleMap = mappingSetEvaluation.getOutputTripleMap();
        logOutputTripleMap(focusOutputTripleMap);
        DeltaSetTripleMapConsolidation<AH> consolidation = new DeltaSetTripleMapConsolidation<>(focusOutputTripleMap, focusOdoRelative.getNewObject(), focusOdoRelative.getObjectDelta(), context::primaryFocusItemDeltaExists, null, null, focusContext.getObjectDefinition(), env, beans, context, result);
        consolidation.computeItemDeltas();
        Collection<ItemDelta<?, ?>> focusDeltas = consolidation.getItemDeltas();
        LOGGER.trace("Computed focus deltas: {}", focusDeltas);
        focusContext.swallowToSecondaryDelta(focusDeltas);
        focusContext.recompute();
    } catch (Throwable t) {
        result.recordFatalError(t.getMessage(), t);
        throw t;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) BooleanUtils(org.apache.commons.lang.BooleanUtils) MappingFactory(com.evolveum.midpoint.model.common.mapping.MappingFactory) QNameUtil(com.evolveum.midpoint.util.QNameUtil) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) ProcessorExecution(com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorExecution) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ActivationComputer(com.evolveum.midpoint.common.ActivationComputer) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Task(com.evolveum.midpoint.task.api.Task) Objects(java.util.Objects) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ComplexConstructionConsumer(com.evolveum.midpoint.model.impl.lens.projector.ComplexConstructionConsumer) SystemObjectCache(com.evolveum.midpoint.model.common.SystemObjectCache) ProvisioningService(com.evolveum.midpoint.provisioning.api.ProvisioningService) Entry(java.util.Map.Entry) com.evolveum.midpoint.prism.delta(com.evolveum.midpoint.prism.delta) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) ProcessorMethod(com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorMethod) FocusTypeUtil(com.evolveum.midpoint.schema.util.FocusTypeUtil) ContextLoader(com.evolveum.midpoint.model.impl.lens.projector.ContextLoader) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) ModelBeans(com.evolveum.midpoint.model.impl.ModelBeans) ObjectDeltaObject(com.evolveum.midpoint.prism.util.ObjectDeltaObject) EvaluatedConstructionPack(com.evolveum.midpoint.model.impl.lens.construction.EvaluatedConstructionPack) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ModelImplUtils(com.evolveum.midpoint.model.impl.util.ModelImplUtils) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) SchemaDebugUtil(com.evolveum.midpoint.schema.util.SchemaDebugUtil) MappingEvaluationEnvironment(com.evolveum.midpoint.model.common.mapping.MappingEvaluationEnvironment) com.evolveum.midpoint.model.impl.lens.projector.mappings(com.evolveum.midpoint.model.impl.lens.projector.mappings) RelationRegistry(com.evolveum.midpoint.schema.RelationRegistry) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PathKeyedMap(com.evolveum.midpoint.prism.path.PathKeyedMap) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl) EvaluatedAssignedResourceObjectConstructionImpl(com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl) ProjectorProcessor(com.evolveum.midpoint.model.impl.lens.projector.ProjectorProcessor) ItemValueWithOrigin(com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin) DeltaSetTripleMapConsolidation(com.evolveum.midpoint.model.impl.lens.projector.focus.consolidation.DeltaSetTripleMapConsolidation) LensUtil(com.evolveum.midpoint.model.impl.lens.LensUtil) ConstructionProcessor(com.evolveum.midpoint.model.impl.lens.projector.ConstructionProcessor) AssignmentEvaluator(com.evolveum.midpoint.model.impl.lens.assignments.AssignmentEvaluator) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ObjectResolver(com.evolveum.midpoint.repo.common.ObjectResolver) SynchronizationPolicyDecision(com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision) TunnelException(com.evolveum.midpoint.util.exception.TunnelException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) ReferenceResolver(com.evolveum.midpoint.model.api.util.ReferenceResolver) Component(org.springframework.stereotype.Component) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ItemName(com.evolveum.midpoint.prism.path.ItemName) PolicyRuleProcessor(com.evolveum.midpoint.model.impl.lens.projector.policy.PolicyRuleProcessor) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MappingEvaluationEnvironment(com.evolveum.midpoint.model.common.mapping.MappingEvaluationEnvironment) EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl) DeltaSetTripleMapConsolidation(com.evolveum.midpoint.model.impl.lens.projector.focus.consolidation.DeltaSetTripleMapConsolidation)

Example 10 with AssignmentHolderType

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

the class RecomputeExecutor method recompute.

private void recompute(PrismObject<? extends AssignmentHolderType> object, boolean dryRun, ModelExecuteOptions options, TriggerCreationType triggerCreation, ExecutionContext context, OperationResult result) throws ScriptExecutionException, SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException {
    AssignmentHolderType objectable = object.asObjectable();
    if (triggerCreation == null) {
        ObjectDelta<? extends AssignmentHolderType> emptyDelta = prismContext.deltaFactory().object().createEmptyModifyDelta(objectable.getClass(), objectable.getOid());
        operationsHelper.applyDelta(emptyDelta, options, dryRun, context, result);
        context.println("Recomputed " + object.toString() + drySuffix(dryRun));
    } else if (dryRun) {
        context.println("Skipping dry run of triggered-recompute of " + object.toString());
    } else if (triggerCreation.getFireAfter() == null) {
        // direct trigger creation
        midpointFunctions.createRecomputeTrigger(objectable.getClass(), objectable.getOid());
        context.println("Triggered recompute of " + object.toString());
    } else {
        // optimized trigger creation
        long fireAfter = XmlTypeConverter.toMillis(triggerCreation.getFireAfter());
        long safetyMargin = triggerCreation.getSafetyMargin() != null ? XmlTypeConverter.toMillis(triggerCreation.getSafetyMargin()) : 0;
        boolean triggerCreated = midpointFunctions.getOptimizingTriggerCreator(fireAfter, safetyMargin).createForObject(objectable.getClass(), objectable.getOid());
        if (triggerCreated) {
            context.println("Triggered recompute of " + object.toString());
        } else {
            context.println("Skipped triggering recompute of " + object.toString() + " because a trigger was already present");
        }
    }
}
Also used : AssignmentHolderType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 NotNull (org.jetbrains.annotations.NotNull)6 LocalizableMessage (com.evolveum.midpoint.util.LocalizableMessage)5 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)4 LensFocusContext (com.evolveum.midpoint.model.impl.lens.LensFocusContext)4 Trace (com.evolveum.midpoint.util.logging.Trace)4 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)4 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Qualifier (org.springframework.beans.factory.annotation.Qualifier)4 Component (org.springframework.stereotype.Component)4 EvaluatedAssignmentImpl (com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl)3 RelationRegistry (com.evolveum.midpoint.schema.RelationRegistry)3 ArrayList (java.util.ArrayList)3 EvaluatedExclusionTrigger (com.evolveum.midpoint.model.api.context.EvaluatedExclusionTrigger)2 EvaluatedStateTrigger (com.evolveum.midpoint.model.api.context.EvaluatedStateTrigger)2 LinkManager (com.evolveum.midpoint.model.common.LinkManager)2 ModelExpressionThreadLocalHolder (com.evolveum.midpoint.model.common.expression.ModelExpressionThreadLocalHolder)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2