Skip to content

Commit

Permalink
Fixing check for polystring norm in iteration (MID-5199)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 12, 2019
1 parent 90ebf06 commit ed15ada
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
Expand Up @@ -26,11 +26,14 @@
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.PrismValueCollectionsUtil;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.caching.AbstractCache;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
Expand Down Expand Up @@ -125,9 +128,23 @@ private <T> boolean checkPropertyUniqueness(PrismObject<AH> objectNew, ItemPath
}
String oid = objectNew.getOid();

ObjectQuery query = prismContext.queryFor(objectNew.getCompileTimeClass())
ObjectQuery query;
if (property.getDefinition() != null && QNameUtil.match(PolyStringType.COMPLEX_TYPE, property.getDefinition().getTypeName())) {
List<PrismPropertyValue<T>> clonedValues = (List<PrismPropertyValue<T>>) PrismValueCollectionsUtil.cloneCollection(property.getValues());
query = prismContext.queryFor(objectNew.getCompileTimeClass())
.item(property.getPath())
.eq(clonedValues)
.matchingOrig()
.or()
.item(property.getPath())
.eq(clonedValues)
.matchingNorm()
.build();
} else {
query = prismContext.queryFor(objectNew.getCompileTimeClass())
.itemAs(property)
.build();
}

List<PrismObject<AH>> foundObjects = repositoryService.searchObjects(objectNew.getCompileTimeClass(), query, null, result);
if (LOGGER.isTraceEnabled()) {
Expand Down
Expand Up @@ -118,6 +118,7 @@ public class TestIteration extends AbstractInitializedModelIntegrationTest {
protected static final String TASK_LIVE_SYNC_DUMMY_DARK_VIOLET_OID = "10000000-0000-0000-5555-555500da0204";

// Iteration with token expression and pre- and post-condition. Sequential suffix.
// Configured in dark-violet dummy resource as account sync template
protected static final File USER_TEMPLATE_ITERATION_FILE = new File(TEST_DIR, "user-template-iteration.xml");
protected static final String USER_TEMPLATE_ITERATION_OID = "10000000-0000-0000-0000-0000000d0002";

Expand Down Expand Up @@ -145,8 +146,10 @@ public class TestIteration extends AbstractInitializedModelIntegrationTest {

private static final String ACCOUNT_LECHUCK_USERNAME = "lechuck";
private static final String LECHUCK_FULLNAME = "LeChuck";
private static final String LE_CHUCK_FULLNAME = "Le-Chuck";
private static final String ACCOUNT_CHARLES_USERNAME = "charles";
private static final String ACCOUNT_SHINETOP_USERNAME = "shinetop";
private static final String ACCOUNT_LE_CHUCK_USERNAME = "le-chuck";
private static final String CHUCKIE_FULLNAME = "Chuckie";

private static final String ACCOUNT_MATUSALEM_USERNAME = "matusalem";
Expand Down Expand Up @@ -1866,6 +1869,43 @@ public void test722DarkVioletModifyShinetopFullName() throws Exception {
assertUserNick(ACCOUNT_SHINETOP_USERNAME, CHUCKIE_FULLNAME, CHUCKIE_FULLNAME, "Monkey Island");
assertNoUserNick(ACCOUNT_SHINETOP_USERNAME, LECHUCK_FULLNAME, LECHUCK_FULLNAME+".2");
}

/*
* Create account with fullname Le_Chuck. This does not conflict with the orig value,
* but it does conflict on polystring norm value.
* User with name le_chuck.1 should be created. This is the third conflict, but the .1
* suffix is free, therefore it is reused.
* MID-5199
*/
@Test
public void test724DarkVioletAddLe_Chuck() throws Exception {
final String TEST_NAME = "test724DarkVioletAddLe_Chuck";
displayTestTitle(TEST_NAME);

// GIVEN
dummyAuditService.clear();

DummyAccount account = new DummyAccount(ACCOUNT_LE_CHUCK_USERNAME);
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, LE_CHUCK_FULLNAME);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, "Melee Island");

// WHEN
displayWhen(TEST_NAME);

display("Adding dummy account", account.debugDump());
getDummyResource(RESOURCE_DUMMY_DARK_VIOLET_NAME).addAccount(account);

waitForTaskNextRunAssertSuccess(TASK_LIVE_SYNC_DUMMY_DARK_VIOLET_OID, true);

// THEN
displayThen(TEST_NAME);
displayAllUsers();
assertUserNick(ACCOUNT_LECHUCK_USERNAME, LECHUCK_FULLNAME, LECHUCK_FULLNAME);
assertUserNick(ACCOUNT_LE_CHUCK_USERNAME, LE_CHUCK_FULLNAME, LE_CHUCK_FULLNAME+".1", "Melee Island");
assertUserNick(ACCOUNT_SHINETOP_USERNAME, CHUCKIE_FULLNAME, CHUCKIE_FULLNAME, "Monkey Island");
assertNoUserNick(ACCOUNT_SHINETOP_USERNAME, LECHUCK_FULLNAME, LECHUCK_FULLNAME+".2");
}

/*
* Create account with fullname barbossa. But user barbossa already exists.
Expand Down
Expand Up @@ -93,7 +93,7 @@
<synchronization>
<objectSynchronization>
<enabled>true</enabled>
<objectTemplateRef oid="10000000-0000-0000-0000-0000000d0002"/>
<objectTemplateRef oid="10000000-0000-0000-0000-0000000d0002"/> <!-- Iteration User Template -->
<reaction>
<situation>linked</situation>
<synchronize>true</synchronize>
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2014-2016 Evolveum
~ Copyright (c) 2014-2019 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,9 @@
~ limitations under the License.
-->

<!-- Iteration with token expression and pre- and post-condition. Sequential suffix. -->
<!-- Iteration with token expression and pre- and post-condition. Sequential suffix.
Configured in dark-violet dummy resource as account sync template
-->

<objectTemplate oid="10000000-0000-0000-0000-0000000d0002"
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
Expand Down

0 comments on commit ed15ada

Please sign in to comment.