use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType in project midpoint by Evolveum.
the class AssignmentCollector method evaluateAssignments.
private <AH extends AssignmentHolderType> Collection<EvaluatedAssignment<AH>> evaluateAssignments(AH focus, Collection<AssignmentType> assignments, AssignmentOrigin origin, AssignmentEvaluator<AH> assignmentEvaluator, Task task, OperationResult result) {
List<EvaluatedAssignment<AH>> evaluatedAssignments = new ArrayList<>();
RepositoryCache.enterLocalCaches(cacheConfigurationManager);
try {
PrismContainerDefinition<AssignmentType> standardAssignmentDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(AssignmentHolderType.class).findContainerDefinition(AssignmentHolderType.F_ASSIGNMENT);
for (AssignmentType assignmentType : emptyIfNull(assignments)) {
try {
// noinspection unchecked
PrismContainerDefinition<AssignmentType> definition = defaultIfNull(assignmentType.asPrismContainerValue().getDefinition(), standardAssignmentDefinition);
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(assignmentType), definition);
EvaluatedAssignment<AH> assignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, focus, focus.toString(), origin, task, result);
evaluatedAssignments.add(assignment);
} catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException | PolicyViolationException | SecurityViolationException | ConfigurationException | CommunicationException e) {
LOGGER.error("Error while processing assignment of {}: {}; assignment: {}", focus, e.getMessage(), assignmentType, e);
}
}
} finally {
RepositoryCache.exitLocalCaches();
}
return evaluatedAssignments;
}
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(Class<T> type, String archetypeOid) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
Set<PrismReferenceValue> membership = getMembership();
List<PrismReferenceValue> assignedWithMemberRelation = membership.stream().filter(ref -> relationRegistry.isMember(ref.getRelation()) && objectTypeMatches(ref, type)).collect(Collectors.toList());
// TODO deduplicate w.r.t. member/manager
// TODO optimize matching
List<T> objects = new ArrayList<>(assignedWithMemberRelation.size());
for (PrismReferenceValue reference : assignedWithMemberRelation) {
ObjectReferenceType ort = new ObjectReferenceType();
ort.setupReferenceValue(reference);
T object = midpointFunctions.resolveReferenceInternal(ort, true);
if (objectMatches(object, type, archetypeOid)) {
objects.add(object);
}
}
return objects;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType in project midpoint by Evolveum.
the class AutoAssignMappingCollector method collectAutoassignMappings.
<AH extends AssignmentHolderType> void collectAutoassignMappings(LensContext<AH> context, List<FocalMappingEvaluationRequest<?, ?>> mappings, OperationResult result) throws SchemaException {
if (!autoassignEnabled(context.getSystemConfiguration())) {
return;
}
ObjectQuery query = prismContext.queryFor(AbstractRoleType.class).item(SchemaConstants.PATH_AUTOASSIGN_ENABLED).eq(true).build();
ResultHandler<AbstractRoleType> handler = (role, objectResult) -> {
AutoassignSpecificationType autoassign = role.asObjectable().getAutoassign();
if (autoassign == null) {
return true;
}
if (!isTrue(autoassign.isEnabled())) {
return true;
}
FocalAutoassignSpecificationType focalAutoassignSpec = autoassign.getFocus();
if (focalAutoassignSpec == null) {
return true;
}
if (!isApplicableFor(focalAutoassignSpec.getSelector(), context.getFocusContext(), objectResult)) {
return true;
}
for (AutoassignMappingType autoMapping : focalAutoassignSpec.getMapping()) {
AutoassignMappingType mapping = LensUtil.setMappingTarget(autoMapping, new ItemPathType(SchemaConstants.PATH_ASSIGNMENT));
mappings.add(new AutoassignRoleMappingEvaluationRequest(mapping, role.asObjectable()));
LOGGER.trace("Collected autoassign mapping {} from {}", mapping.getName(), role);
}
return true;
};
cacheRepositoryService.searchObjectsIterative(AbstractRoleType.class, query, handler, createReadOnlyCollection(), true, result);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType in project midpoint by Evolveum.
the class ExclusionConstraintEvaluator method evaluate.
@Override
public <AH extends AssignmentHolderType> EvaluatedExclusionTrigger evaluate(@NotNull JAXBElement<ExclusionPolicyConstraintType> constraint, @NotNull PolicyRuleEvaluationContext<AH> rctx, OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
OperationResult result = parentResult.subresult(OP_EVALUATE).setMinor().build();
try {
LOGGER.trace("Evaluating exclusion constraint {} on {}", lazy(() -> PolicyRuleTypeUtil.toShortString(constraint)), rctx);
if (!(rctx instanceof AssignmentPolicyRuleEvaluationContext)) {
return null;
}
AssignmentPolicyRuleEvaluationContext<AH> ctx = (AssignmentPolicyRuleEvaluationContext<AH>) rctx;
if (!ctx.isAdded && !ctx.isKept) {
LOGGER.trace("Assignment not being added nor kept, skipping evaluation.");
return null;
}
if (sourceOrderConstraintsDoNotMatch(constraint, ctx)) {
// logged in the called method body
return null;
}
/*
* Now let us check the exclusions.
*
* Assignment A is the current evaluated assignment. It has directly or indirectly attached the exclusion policy rule.
* We now go through all other assignments B and check the exclusions.
*/
List<OrderConstraintsType> targetOrderConstraints = defaultIfEmpty(constraint.getValue().getTargetOrderConstraint());
List<EvaluatedAssignmentTargetImpl> nonNegativeTargetsA = ctx.evaluatedAssignment.getNonNegativeTargets();
ConstraintReferenceMatcher<AH> refMatcher = new ConstraintReferenceMatcher<>(ctx, constraint.getValue().getTargetRef(), expressionFactory, result, LOGGER);
for (EvaluatedAssignmentImpl<AH> assignmentB : ctx.evaluatedAssignmentTriple.getNonNegativeValues()) {
// MID-6403
if (assignmentB == ctx.evaluatedAssignment) {
// currently there is no other way of comparing the evaluated assignments
continue;
}
targetB: for (EvaluatedAssignmentTargetImpl targetB : assignmentB.getNonNegativeTargets()) {
if (!pathMatches(targetB.getAssignmentPath(), targetOrderConstraints)) {
LOGGER.trace("Skipping considering exclusion target {} because it does not match target path constraints." + " Path={}, constraints={}", targetB, targetB.getAssignmentPath(), targetOrderConstraints);
continue;
}
if (!refMatcher.refMatchesTarget(targetB.getTarget(), "exclusion constraint")) {
LOGGER.trace("Target {} OID does not match exclusion filter", targetB);
continue;
}
// To avoid false positives let us check if this target is not already covered by assignment being evaluated
for (EvaluatedAssignmentTargetImpl targetA : nonNegativeTargetsA) {
if (targetIsAlreadyCovered(targetB, targetA)) {
continue targetB;
}
}
EvaluatedExclusionTrigger rv = createTrigger(ctx.evaluatedAssignment, assignmentB, targetB, constraint, ctx.policyRule, ctx, result);
result.addReturn("trigger", rv.toDiagShortcut());
return rv;
}
}
return null;
} catch (Throwable t) {
result.recordFatalError(t.getMessage(), t);
throw t;
} finally {
result.computeStatusIfUnknown();
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType 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