Skip to content

Commit

Permalink
The test is now passing. BEWARE: changed roleMembershipRef to contain…
Browse files Browse the repository at this point in the history
… relation as well.
  • Loading branch information
mederly committed Nov 17, 2016
1 parent 53e1c86 commit a975257
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
Expand Up @@ -40,6 +40,7 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType;
import com.evolveum.prism.xml.ns._public.types_3.ModificationTypeType;
import org.apache.commons.collections4.CollectionUtils;

/**
* @author Radovan Semancik
Expand Down Expand Up @@ -662,6 +663,11 @@ public boolean isEmpty() {
return false;
}

// TODO merge with isEmpty
public boolean isInFactEmpty() {
return CollectionUtils.isEmpty(valuesToAdd) && CollectionUtils.isEmpty(valuesToDelete) && valuesToReplace == null;
}

public static boolean isEmpty(ItemDeltaType itemDeltaType) {
if (itemDeltaType == null) {
return true;
Expand Down
Expand Up @@ -1607,11 +1607,16 @@ public static boolean subtractFromModifications(Collection<? extends ItemDelta<?
return false;
}
boolean removed = false;
for (ItemDelta<?, ?> itemDelta : modifications) {
Iterator<? extends ItemDelta<?, ?>> itemDeltaIterator = modifications.iterator();
while (itemDeltaIterator.hasNext()) {
ItemDelta<?, ?> itemDelta = itemDeltaIterator.next();
if (itemPath.equivalent(itemDelta.getPath())) {
boolean removed1 = itemDelta.removeValueToAdd(value);
boolean removed2 = itemDelta.removeValueToReplace(value);
removed = removed || removed1 || removed2;
if (itemDelta.isInFactEmpty()) {
itemDeltaIterator.remove();
}
}
}
return removed;
Expand Down
Expand Up @@ -1750,14 +1750,14 @@ public <F extends ObjectType> void processMembershipRef(LensContext<F> context,
for (PrismReferenceValue membershipRefVal: evalAssignment.getMembershipRefVals()) {
boolean found = false;
for (PrismReferenceValue exVal: newValues) {
if (exVal.getOid().equals(membershipRefVal.getOid())) {
if (exVal.getOid().equals(membershipRefVal.getOid())
&& QNameUtil.match(exVal.getRelation(), membershipRefVal.getRelation())) {
found = true;
break;
}
}
if (!found) {
PrismReferenceValue ref = membershipRefVal.clone();
ref.setRelation(null);
newValues.add(ref);
}
}
Expand All @@ -1775,12 +1775,9 @@ public <F extends ObjectType> void processMembershipRef(LensContext<F> context,
return;
}
} else {
Comparator<PrismReferenceValue> comparator = new Comparator<PrismReferenceValue>() {
@Override
public int compare(PrismReferenceValue a, PrismReferenceValue b) {
return a.getOid().compareTo(b.getOid());
}
};
Comparator<PrismReferenceValue> comparator =
(a, b) -> 2*a.getOid().compareTo(b.getOid())
+ (QNameUtil.match(a.getRelation(), b.getRelation()) ? 0 : 1);
if (MiscUtil.unorderedCollectionEquals(newValues, roleMemPrismRef.getValues(), comparator)) {
return;
}
Expand Down
Expand Up @@ -280,8 +280,9 @@ private Collection<? extends ObjectReferenceType> findApproversByReference(Prism
.build();
LOGGER.trace("Looking for approvers for {} using query:\n{}", target, DebugUtil.debugDumpLazily(query));
List<PrismObject<FocusType>> objects = repositoryService.searchObjects(FocusType.class, query, null, result);
LOGGER.trace("Found {} approver(s): {}", objects.size(), DebugUtil.toStringLazily(objects));
return objects.stream()
Set<PrismObject<FocusType>> distinctObjects = new HashSet<>(objects);
LOGGER.trace("Found {} approver(s): {}", distinctObjects.size(), DebugUtil.toStringLazily(distinctObjects));
return distinctObjects.stream()
.map(ObjectTypeUtil::createObjectRef)
.collect(Collectors.toList());
}
Expand Down
Expand Up @@ -34,6 +34,7 @@
import org.testng.annotations.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static com.evolveum.midpoint.schema.util.ObjectTypeUtil.createAssignmentTo;
Expand Down Expand Up @@ -89,14 +90,14 @@ protected void afterFirstClockworkRun(Task rootTask, List<Task> subtasks, Operat
@Override
protected void afterRootTaskFinishes(Task rootTask, List<Task> subtasks, OperationResult result) throws Exception {
assertAssignedRole(USER_JACK_OID, ROLE_ROLE1_OID, rootTask, result);
checkDummyTransportMessages("simpleUserNotifier", 1);
checkWorkItemAuditRecords(createResultMap(ROLE_ROLE1_OID, WorkflowResult.APPROVED));
checkUserApprovers(USER_JACK_OID, Arrays.asList(USER_LEAD1_OID), result);
checkUserApprovers(USER_JACK_OID, Collections.singletonList(USER_LEAD1_OID), result);
assertWfContextAfterRootTaskFinishes(rootTask, subtasks, result, "Assigning Role1 to jack");
}

@Override
protected boolean decideOnApproval(String executionId) throws Exception {
login(getUser(USER_LEAD1_OID));
return true;
}
}, 1);
Expand Down

0 comments on commit a975257

Please sign in to comment.