Skip to content

Commit

Permalink
Fixing several issues with inbound mappings (MID-2421)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed May 27, 2016
1 parent a0059c5 commit 6723e41
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 35 deletions.
Expand Up @@ -58,6 +58,7 @@
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
Expand Down Expand Up @@ -484,10 +485,10 @@ private <A, F extends FocusType, V extends PrismValue,D extends ItemDefinition>
// the differences will be added to delta

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Inbound value construction for {} returned triple:\n{}", accountAttributeName, triple == null ? "null" : triple.debugDump());
LOGGER.trace("Inbound mapping for {} returned triple:\n{}", accountAttributeName, triple == null ? "null" : triple.debugDump());
}

if (triple != null && !triple.isEmpty()) {
if (triple != null) {

if (triple.hasPlusSet()) {

Expand Down Expand Up @@ -529,25 +530,30 @@ private <A, F extends FocusType, V extends PrismValue,D extends ItemDefinition>
}
}

if (mapping.isTolerant() != Boolean.TRUE && triple.hasZeroSet()) {
Item sourceItem = targetItemDef.instantiate();
sourceItem.addAll(PrismValue.cloneCollection(triple.getZeroSet()));
if (mapping.isTolerant() != Boolean.TRUE) {
Item shouldBeItem = targetItemDef.instantiate();
shouldBeItem.addAll(PrismValue.cloneCollection(triple.getZeroSet()));
shouldBeItem.addAll(PrismValue.cloneCollection(triple.getPlusSet()));
if (targetFocusItem != null) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Comparing focus item:\n{}\nto computed item:\n{} ",
new Object[]{targetFocusItem.debugDump(), sourceItem.debugDump()});
ItemDelta diffDelta = targetFocusItem.diff(shouldBeItem);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Comparing focus item:\n{}\nto should be item:\n{}\ndiff:\n{} ",
new Object[]{
DebugUtil.debugDump(targetFocusItem, 1),
DebugUtil.debugDump(shouldBeItem, 1),
DebugUtil.debugDump(diffDelta, 1)
});
}
ItemDelta diffDelta = targetFocusItem.diff(sourceItem);
if (diffDelta != null) {
diffDelta.setElementName(ItemPath.getName(targetFocusItemPath.last()));
diffDelta.setParentPath(targetFocusItemPath.allExceptLast());
outputFocusItemDelta.merge(diffDelta);
}
} else {
if (sourceItem != null) { // actually sourceProperty is never null here [med]
if (shouldBeItem != null) { // actually sourceProperty is never null here [med]
LOGGER.trace("Adding user property because inbound say so (account doesn't contain that value)");
//if user property doesn't exist we have to add it (as delta), because inbound say so
outputFocusItemDelta.addValuesToAdd(sourceItem.getClonedValues());
outputFocusItemDelta.addValuesToAdd(shouldBeItem.getClonedValues());
}
//we don't have to create delta, because everything is alright
LOGGER.trace("We don't have to create delta, everything is alright.");
Expand Down
Expand Up @@ -121,7 +121,6 @@ public void test101ModifyUserEmployeeTypePirate() throws Exception {
display("User after", userJack);

PrismAsserts.assertPropertyValue(userJack, UserType.F_DESCRIPTION, "Where's the rum?");
// assertAssignedAccount(userJack, RESOURCE_DUMMY_BLUE_OID);
assertAssignedRole(userJack, ROLE_PIRATE_GREEN_OID);
assertAssignments(userJack, 1);

Expand All @@ -133,17 +132,10 @@ public void test101ModifyUserEmployeeTypePirate() throws Exception {

assertEquals("Unexpected number of organizationalUnits", 1, userJackType.getOrganizationalUnit().size());
assertEquals("Wrong organizationalUnit", PrismTestUtil.createPolyStringType("The crew of pirate"), userJackType.getOrganizationalUnit().get(0));
// assertEquals("Wrong costCenter", "G001", userJackType.getCostCenter());


jackEmployeeNumber = userJackType.getEmployeeNumber();
assertNotNull("Wrong employee number. Expected not null value, got " + jackEmployeeNumber, jackEmployeeNumber);
// assertEquals("Unexpected length of employeeNumber, maybe it was not generated?",
// GenerateExpressionEvaluator.DEFAULT_LENGTH, jackEmployeeNumber.length());

// XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
// XMLGregorianCalendar monthLater = XmlTypeConverter.addDuration(now, XmlTypeConverter.createDuration("P1M"));
// assertTrigger(userJack, RecomputeTriggerHandler.HANDLER_URI, monthLater, 100000L);
}

/**
Expand Down Expand Up @@ -172,7 +164,6 @@ public void test102ModifyUserEmployeeTypeBuccaneer() throws Exception {
display("User after", userJack);

PrismAsserts.assertPropertyValue(userJack, UserType.F_DESCRIPTION, "Where's the rum?");
// assertAssignedAccount(userJack, RESOURCE_DUMMY_BLUE_OID);
assertAssignedRole(userJack, ROLE_BUCCANEER_GREEN_OID);
assertAssignments(userJack, 1);

Expand All @@ -181,9 +172,7 @@ public void test102ModifyUserEmployeeTypeBuccaneer() throws Exception {

result.computeStatus();
TestUtil.assertSuccess(result);
// assertEquals("Unexpected number of organizationalUnits", 1, userJackType.getOrganizationalUnit().size());
assertEquals("Wrong organizationalUnit", PrismTestUtil.createPolyStringType("The crew of buccaneer"), userJackType.getOrganizationalUnit().get(1));
// assertEquals("Wrong costCenter", "B666", userJackType.getCostCenter());
PrismAsserts.assertEqualsCollectionUnordered("Wrong organizationalUnit", userJackType.getOrganizationalUnit(), PrismTestUtil.createPolyStringType("The crew of buccaneer"));
assertEquals("Employee number has changed", jackEmployeeNumber, userJackType.getEmployeeNumber());
}

Expand All @@ -209,7 +198,6 @@ public void test103DeleteUserEmployeeTypeBartender() throws Exception {
display("User after", userJack);

PrismAsserts.assertPropertyValue(userJack, UserType.F_DESCRIPTION, "Where's the rum?");
// assertAssignedAccount(userJack, RESOURCE_DUMMY_BLUE_OID);
assertNotAssignedRole(userJack, ROLE_PIRATE_GREEN_OID);
assertNotAssignedRole(userJack, ROLE_BUCCANEER_GREEN_OID);
assertNoAssignments(userJack);
Expand All @@ -220,9 +208,6 @@ public void test103DeleteUserEmployeeTypeBartender() throws Exception {
result.computeStatus();
TestUtil.assertSuccess(result);

// assertEquals("Unexpected number of organizationalUnits", 0, userJackType.getOrganizationalUnit().size());
// assertEquals("Wrong organizationalUnit", PrismTestUtil.createPolyStringType("The crew of pirate"), userJackType.getOrganizationalUnit().get(0));
// assertEquals("Wrong costCenter", "G001", userJackType.getCostCenter());
assertEquals("Employee number has changed", jackEmployeeNumber, userJackType.getEmployeeNumber());
}

Expand All @@ -233,8 +218,8 @@ public void test103DeleteUserEmployeeTypeBartender() throws Exception {
* MID-2689
*/
@Test
public void test200AssignAccountOrgange() throws Exception {
final String TEST_NAME = "test200AssignAccountOrgange";
public void test200AssignAccountOrange() throws Exception {
final String TEST_NAME = "test200AssignAccountOrange";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Expand Down Expand Up @@ -276,8 +261,8 @@ public void test200AssignAccountOrgange() throws Exception {
* MID-2689
*/
@Test
public void test202ModifyAccountOrgangeGossip() throws Exception {
final String TEST_NAME = "test202ModifyAccountOrgangeGossip";
public void test202ModifyAccountOrangeGossip() throws Exception {
final String TEST_NAME = "test202ModifyAccountOrangeGossip";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Expand Down Expand Up @@ -320,8 +305,8 @@ public void test202ModifyAccountOrgangeGossip() throws Exception {
* MID-3080
*/
@Test
public void test204AssignAccountOrgangeAgain() throws Exception {
final String TEST_NAME = "test204AssignAccountOrgangeAgain";
public void test204AssignAccountOrangeAgain() throws Exception {
final String TEST_NAME = "test204AssignAccountOrangeAgain";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Expand Down Expand Up @@ -364,8 +349,8 @@ public void test204AssignAccountOrgangeAgain() throws Exception {
* MID-2689
*/
@Test
public void test209ModifyAccountOrgangeGossipRemove() throws Exception {
final String TEST_NAME = "test209ModifyAccountOrgangeGossipRemove";
public void test209ModifyAccountOrangeGossipRemove() throws Exception {
final String TEST_NAME = "test209ModifyAccountOrangeGossipRemove";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Expand Down Expand Up @@ -403,4 +388,149 @@ public void test209ModifyAccountOrgangeGossipRemove() throws Exception {

}

/**
* Modify 'quote' on account (through shadow). That attribute has an inbound
* expression that passes some values to description user property.
* This will not pass.
* MID-2421
*/
@Test
public void test210ModifyAccountOrangeQuoteMonkey() throws Exception {
final String TEST_NAME = "test210ModifyAccountOrangeQuoteMonkey";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(TestUserTemplate.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

PrismObject<UserType> userBefore = getUser(USER_GUYBRUSH_OID);
display("User before", userBefore);

// WHEN
modifyObjectReplaceProperty(ShadowType.class, guybrushShadowOrangeOid,
dummyResourceCtlOrange.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME),
task, result, "Look behind you, a Three-Headed Monkey!");

// THEN
result.computeStatus();
TestUtil.assertSuccess(result);

PrismObject<UserType> userAfter = getUser(USER_GUYBRUSH_OID);
display("User after", userAfter);
assertUser(userAfter, USER_GUYBRUSH_OID, USER_GUYBRUSH_USERNAME,
USER_GUYBRUSH_FULL_NAME, USER_GUYBRUSH_GIVEN_NAME, USER_GUYBRUSH_FAMILY_NAME);

assertEquals("Wrong description", null, userAfter.asObjectable().getDescription());

assertAssignedAccount(userAfter, RESOURCE_DUMMY_ORANGE_OID);
assertAssignedNoRole(userAfter);
assertAssignments(userAfter, 1);
assertLinks(userAfter, 2);

DummyAccount dummyAccount = assertDummyAccount(RESOURCE_DUMMY_ORANGE_NAME, USER_GUYBRUSH_USERNAME, USER_GUYBRUSH_FULL_NAME, true);
display("Orange account", dummyAccount);

guybrushShadowOrangeOid = getLinkRefOid(userAfter, RESOURCE_DUMMY_ORANGE_OID);
PrismObject<ShadowType> shadowOrange = getShadowModel(guybrushShadowOrangeOid);
display("Orange shadow", shadowOrange);

}

/**
* Modify 'quote' on account (through shadow). That attribute has an inbound
* expression that passes some values to description user property.
* This should pass.
* MID-2421
*/
@Test
public void test211ModifyAccountOrangeQuotePirate() throws Exception {
final String TEST_NAME = "test211ModifyAccountOrangeQuotePirate";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(TestUserTemplate.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

PrismObject<UserType> userBefore = getUser(USER_GUYBRUSH_OID);
display("User before", userBefore);

// WHEN
modifyObjectReplaceProperty(ShadowType.class, guybrushShadowOrangeOid,
dummyResourceCtlOrange.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME),
task, result, "I wanna be a pirrrrrrate!");

// THEN
result.computeStatus();
TestUtil.assertSuccess(result);

PrismObject<UserType> userAfter = getUser(USER_GUYBRUSH_OID);
display("User after", userAfter);
assertUser(userAfter, USER_GUYBRUSH_OID, USER_GUYBRUSH_USERNAME,
USER_GUYBRUSH_FULL_NAME, USER_GUYBRUSH_GIVEN_NAME, USER_GUYBRUSH_FAMILY_NAME);

assertEquals("Wrong description", "I wanna be a pirrrrrrate!", userAfter.asObjectable().getDescription());

assertAssignedAccount(userAfter, RESOURCE_DUMMY_ORANGE_OID);
assertAssignedNoRole(userAfter);
assertAssignments(userAfter, 1);
assertLinks(userAfter, 2);

DummyAccount dummyAccount = assertDummyAccount(RESOURCE_DUMMY_ORANGE_NAME, USER_GUYBRUSH_USERNAME, USER_GUYBRUSH_FULL_NAME, true);
display("Orange account", dummyAccount);

guybrushShadowOrangeOid = getLinkRefOid(userAfter, RESOURCE_DUMMY_ORANGE_OID);
PrismObject<ShadowType> shadowOrange = getShadowModel(guybrushShadowOrangeOid);
display("Orange shadow", shadowOrange);

}

/**
* Modify 'quote' on account (through shadow). That attribute has an inbound
* expression that passes some values to description user property.
* This will not pass. Is should remove the previous value of description.
* MID-2421
*/
@Test
public void test214ModifyAccountOrangeQuoteWoodchuck() throws Exception {
final String TEST_NAME = "test214ModifyAccountOrangeQuoteWoodchuck";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(TestUserTemplate.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

PrismObject<UserType> userBefore = getUser(USER_GUYBRUSH_OID);
display("User before", userBefore);

// WHEN
modifyObjectReplaceProperty(ShadowType.class, guybrushShadowOrangeOid,
dummyResourceCtlOrange.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME),
task, result, "How much wood could a woodchuck chuck if a woodchuck could chuck wood?");

// THEN
result.computeStatus();
TestUtil.assertSuccess(result);

PrismObject<UserType> userAfter = getUser(USER_GUYBRUSH_OID);
display("User after", userAfter);
assertUser(userAfter, USER_GUYBRUSH_OID, USER_GUYBRUSH_USERNAME,
USER_GUYBRUSH_FULL_NAME, USER_GUYBRUSH_GIVEN_NAME, USER_GUYBRUSH_FAMILY_NAME);

assertEquals("Wrong description", null, userAfter.asObjectable().getDescription());

assertAssignedAccount(userAfter, RESOURCE_DUMMY_ORANGE_OID);
assertAssignedNoRole(userAfter);
assertAssignments(userAfter, 1);
assertLinks(userAfter, 2);

DummyAccount dummyAccount = assertDummyAccount(RESOURCE_DUMMY_ORANGE_NAME, USER_GUYBRUSH_USERNAME, USER_GUYBRUSH_FULL_NAME, true);
display("Orange account", dummyAccount);

guybrushShadowOrangeOid = getLinkRefOid(userAfter, RESOURCE_DUMMY_ORANGE_OID);
PrismObject<ShadowType> shadowOrange = getShadowModel(guybrushShadowOrangeOid);
display("Orange shadow", shadowOrange);

}


}
Expand Up @@ -157,6 +157,24 @@
<ref>ri:quote</ref>
<displayName>Quote</displayName>
<tolerant>true</tolerant>
<inbound>
<expression> <!-- MID-2421 -->
<script>
<code>
if (input == null) {
return null;
}
if (input.contains("rrr")) {
return input;
}
return null;
</code>
</script>
</expression>
<target>
<path>description</path>
</target>
</inbound>
</attribute>
<attribute>
<ref>ri:gossip</ref>
Expand Down

0 comments on commit 6723e41

Please sign in to comment.