Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Jun 2, 2020
2 parents 073d05d + eb2c28c commit b493068
Show file tree
Hide file tree
Showing 32 changed files with 798 additions and 333 deletions.
Expand Up @@ -2749,7 +2749,7 @@ public <IW extends ItemWrapper> Panel initItemPanel(String panelId, QName typeNa
public <C extends Containerable> Panel initContainerValuePanel(String id, IModel<PrismContainerValueWrapper<C>> model,
ItemPanelSettings settings) {
//TODO find from registry first
return new PrismContainerValuePanel<>(id, model, settings) {
return new PrismContainerValuePanel<C, PrismContainerValueWrapper<C>>(id, model, settings) {
@Override
protected boolean isRemoveButtonVisible() {
return false;
Expand Down
Expand Up @@ -2890,7 +2890,7 @@
<xsd:element name="taskCustomizer" type="c:ExpressionType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Task customizer: an expression that takes a task and customizes its content.
An expression that takes a task and customizes its content.

Input variable: preparedTask (of TaskType).
Output: TaskType that should be used. (It is possible to modify preparedTask and return it.)
Expand Down Expand Up @@ -2922,7 +2922,7 @@
<xsd:enumeration value="iterative">
<xsd:annotation>
<xsd:documentation>
Uses iterative scripting handler. This is the default.
Uses iterative scripting handler, i.e. object query with a script that processes every object found. This is the default.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="ITERATIVE"/>
Expand Down
Expand Up @@ -13,10 +13,8 @@

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.Objects;
import java.util.stream.Collectors;

import com.evolveum.midpoint.model.common.LinkManager;
Expand Down Expand Up @@ -136,7 +134,7 @@ <T extends AssignmentHolderType> List<T> findLinkedTargets(Class<T> type, String
ConfigurationException, ExpressionEvaluationException {
Set<PrismReferenceValue> membership = getMembership();
List<PrismReferenceValue> assignedWithMemberRelation = membership.stream()
.filter(ref -> relationRegistry.isMember(ref.getRelation()))
.filter(ref -> relationRegistry.isMember(ref.getRelation()) && objectTypeMatches(ref, type))
.collect(Collectors.toList());
// TODO deduplicate w.r.t. member/manager
// TODO optimize matching
Expand All @@ -158,7 +156,6 @@ <T extends AssignmentHolderType> List<T> findLinkedTargets(Class<T> type, String
<T extends AssignmentHolderType> List<T> findLinkedTargets(String linkTypeName)
throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException,
ConfigurationException, ExpressionEvaluationException {
Task currentTask = midpointFunctions.getCurrentTask();
OperationResult currentResult = midpointFunctions.getCurrentResult();
LensFocusContext<?> focusContext = (LensFocusContext<?>) midpointFunctions.getFocusContext();
if (focusContext == null) {
Expand All @@ -169,9 +166,11 @@ <T extends AssignmentHolderType> List<T> findLinkedTargets(String linkTypeName)
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()))
.filter(ref -> relationMatches(ref, definition.getSelector()) && objectTypeMatches(ref, expectedClasses))
.collect(Collectors.toList());
// TODO deduplicate w.r.t. member/manager
// TODO optimize matching
Expand All @@ -187,6 +186,14 @@ <T extends AssignmentHolderType> List<T> findLinkedTargets(String linkTypeName)
return objects;
}

private Class<?> getExpectedClass(LinkedObjectSelectorType selector) {
if (selector == null || selector.getType() == null) {
return null;
} else {
return prismContext.getSchemaRegistry().determineClassForTypeRequired(selector.getType());
}
}

@NotNull
private Set<PrismReferenceValue> getMembership() {
if (Boolean.FALSE.equals(midpointFunctions.isEvaluateNew())) {
Expand Down Expand Up @@ -221,18 +228,29 @@ private Set<PrismReferenceValue> getMembershipOld() {
}
}

private boolean objectTypeMatches(PrismReferenceValue ref, Class<?> expectedClass) {
if (expectedClass == null) {
return true;
} else {
Class<?> refTargetClass = prismContext.getSchemaRegistry().determineClassForTypeRequired(
Objects.requireNonNull(
ref.getTargetType(), "no target type"));
return expectedClass.isAssignableFrom(refTargetClass);
}
}

private boolean relationMatches(PrismReferenceValue ref, LinkedObjectSelectorType selector) {
return selector == null ||
selector.getRelation().isEmpty() ||
prismContext.relationMatches(selector.getRelation(), ref.getRelation());
}

private <T extends AssignmentHolderType> boolean objectMatches(AssignmentHolderType targetObject, Class<T> type, String archetypeOid) {
return type.isAssignableFrom(targetObject.getClass())
return (type == null || type.isAssignableFrom(targetObject.getClass()))
&& (archetypeOid == null || hasArchetype(targetObject, archetypeOid));
}

private <T extends AssignmentHolderType> boolean objectMatches(AssignmentHolderType targetObject, ObjectSelectorType selector)
private boolean objectMatches(AssignmentHolderType targetObject, ObjectSelectorType selector)
throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException,
ConfigurationException, ExpressionEvaluationException {
return selector == null ||
Expand Down

0 comments on commit b493068

Please sign in to comment.