use of com.evolveum.midpoint.model.common.LinkManager 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;
}
Aggregations