Search in sources :

Example 1 with AssignmentPath

use of com.evolveum.midpoint.model.api.context.AssignmentPath in project midpoint by Evolveum.

the class AssociationFromLinkExpressionEvaluator method getSpecifiedAssignmentPathSegment.

private AssignmentPathSegment getSpecifiedAssignmentPathSegment(ExpressionEvaluationContext context, Integer assignmentPathIndex) throws ExpressionEvaluationException {
    @SuppressWarnings("unchecked") TypedValue<AssignmentPath> assignmentPathTypedValue = context.getVariables().get(ExpressionConstants.VAR_ASSIGNMENT_PATH);
    if (assignmentPathTypedValue == null || assignmentPathTypedValue.getValue() == null) {
        throw new ExpressionEvaluationException("No assignment path variable in " + context.getContextDescription() + "; the expression may be used in a wrong place. It is only supposed to work in a role.");
    }
    AssignmentPath assignmentPath = (AssignmentPath) assignmentPathTypedValue.getValue();
    if (assignmentPath.isEmpty()) {
        throw new ExpressionEvaluationException("Empty assignment path variable in " + context.getContextDescription() + "; the expression may be used in a wrong place. It is only supposed to work in a role.");
    }
    LOGGER.trace("assignmentPath {}:\n{}", expressionEvaluatorBean.getDescription(), assignmentPath.debugDumpLazily(1));
    try {
        return assignmentPath.getSegment(assignmentPathIndex);
    } catch (IndexOutOfBoundsException e) {
        throw new ExpressionEvaluationException("Wrong assignment path index in " + context.getContextDescription() + "; Index " + assignmentPathIndex + " cannot be applied to a path of length " + assignmentPath.size(), e);
    }
}
Also used : AssignmentPath(com.evolveum.midpoint.model.api.context.AssignmentPath)

Example 2 with AssignmentPath

use of com.evolveum.midpoint.model.api.context.AssignmentPath in project midpoint by Evolveum.

the class ExclusionConstraintEvaluator method createObjectInfo.

private LocalizableMessage createObjectInfo(AssignmentPath path, PrismObject<?> defaultObject, boolean startsWithUppercase) {
    if (path == null) {
        return ObjectTypeUtil.createDisplayInformation(defaultObject, startsWithUppercase);
    }
    List<ObjectType> objects = path.getFirstOrderChain();
    if (objects.isEmpty()) {
        // shouldn't occur
        return ObjectTypeUtil.createDisplayInformation(defaultObject, startsWithUppercase);
    }
    PrismObject<?> last = objects.get(objects.size() - 1).asPrismObject();
    if (objects.size() == 1) {
        return ObjectTypeUtil.createDisplayInformation(last, startsWithUppercase);
    }
    String pathString = objects.stream().map(o -> PolyString.getOrig(o.getName())).collect(Collectors.joining(" -> "));
    return ObjectTypeUtil.createDisplayInformationWithPath(last, startsWithUppercase, pathString);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Trace(com.evolveum.midpoint.util.logging.Trace) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) EvaluationOrder(com.evolveum.midpoint.model.api.context.EvaluationOrder) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) PrismContext(com.evolveum.midpoint.prism.PrismContext) Map(java.util.Map) RelationRegistry(com.evolveum.midpoint.schema.RelationRegistry) EvaluatedPolicyRule(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule) EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) ExclusionPolicyConstraintType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExclusionPolicyConstraintType) EvaluatedAssignmentTargetImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentTargetImpl) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AssignmentHolderType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType) PolicyRuleTypeUtil(com.evolveum.midpoint.schema.util.PolicyRuleTypeUtil) JAXBElement(javax.xml.bind.JAXBElement) AssignmentPath(com.evolveum.midpoint.model.api.context.AssignmentPath) AssignmentPolicyRuleEvaluationContext(com.evolveum.midpoint.model.impl.lens.projector.policy.AssignmentPolicyRuleEvaluationContext) PolicyRuleEvaluationContext(com.evolveum.midpoint.model.impl.lens.projector.policy.PolicyRuleEvaluationContext) PrismObject(com.evolveum.midpoint.prism.PrismObject) Collectors(java.util.stream.Collectors) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) OrderConstraintsType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrderConstraintsType) List(java.util.List) Component(org.springframework.stereotype.Component) DebugUtil.lazy(com.evolveum.midpoint.util.DebugUtil.lazy) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) QName(javax.xml.namespace.QName) EvaluatedExclusionTrigger(com.evolveum.midpoint.model.api.context.EvaluatedExclusionTrigger) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 3 with AssignmentPath

use of com.evolveum.midpoint.model.api.context.AssignmentPath in project midpoint by Evolveum.

the class ExclusionConstraintEvaluator method createTrigger.

private <AH extends AssignmentHolderType> EvaluatedExclusionTrigger createTrigger(EvaluatedAssignmentImpl<AH> assignmentA, @NotNull EvaluatedAssignmentImpl<AH> assignmentB, EvaluatedAssignmentTargetImpl targetB, JAXBElement<ExclusionPolicyConstraintType> constraintElement, EvaluatedPolicyRule policyRule, AssignmentPolicyRuleEvaluationContext<AH> ctx, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
    AssignmentPath pathA = policyRule.getAssignmentPath();
    AssignmentPath pathB = targetB.getAssignmentPath();
    LocalizableMessage infoA = createObjectInfo(pathA, assignmentA.getTarget(), true);
    LocalizableMessage infoB = createObjectInfo(pathB, targetB.getTarget(), false);
    ObjectType objectA = getConflictingObject(pathA, assignmentA.getTarget());
    ObjectType objectB = getConflictingObject(pathB, targetB.getTarget());
    LocalizableMessage message = createMessage(infoA, infoB, constraintElement, ctx, result);
    LocalizableMessage shortMessage = createShortMessage(infoA, infoB, constraintElement, ctx, result);
    return new EvaluatedExclusionTrigger(constraintElement.getValue(), message, shortMessage, assignmentB, objectA, objectB, pathA, pathB);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) EvaluatedExclusionTrigger(com.evolveum.midpoint.model.api.context.EvaluatedExclusionTrigger) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) AssignmentPath(com.evolveum.midpoint.model.api.context.AssignmentPath)

Aggregations

AssignmentPath (com.evolveum.midpoint.model.api.context.AssignmentPath)3 EvaluatedExclusionTrigger (com.evolveum.midpoint.model.api.context.EvaluatedExclusionTrigger)2 LocalizableMessage (com.evolveum.midpoint.util.LocalizableMessage)2 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)2 EvaluatedPolicyRule (com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule)1 EvaluationOrder (com.evolveum.midpoint.model.api.context.EvaluationOrder)1 EvaluatedAssignmentImpl (com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl)1 EvaluatedAssignmentTargetImpl (com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentTargetImpl)1 AssignmentPolicyRuleEvaluationContext (com.evolveum.midpoint.model.impl.lens.projector.policy.AssignmentPolicyRuleEvaluationContext)1 PolicyRuleEvaluationContext (com.evolveum.midpoint.model.impl.lens.projector.policy.PolicyRuleEvaluationContext)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 ExpressionFactory (com.evolveum.midpoint.repo.common.expression.ExpressionFactory)1 RelationRegistry (com.evolveum.midpoint.schema.RelationRegistry)1 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 ObjectTypeUtil (com.evolveum.midpoint.schema.util.ObjectTypeUtil)1 PolicyRuleTypeUtil (com.evolveum.midpoint.schema.util.PolicyRuleTypeUtil)1 DebugUtil.lazy (com.evolveum.midpoint.util.DebugUtil.lazy)1