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