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 Mar 13, 2019
2 parents 5780350 + ed15ada commit 4c36d23
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 37 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
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* Copyright (c) 2010-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 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 @@ -230,18 +233,15 @@ public void test100JackAssignAccountDummyConflicting() throws Exception {
getDummyResource().addAccount(account);
repoAddObject(createShadow(getDummyResourceObject(), ACCOUNT_JACK_DUMMY_USERNAME), result);

Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(USER_JACK_OID, RESOURCE_DUMMY_OID, null, true);
deltas.add(accountAssignmentUserDelta);

// WHEN
displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
executeChanges(accountAssignmentUserDelta, null, task, result);

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

PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
Expand Down Expand Up @@ -288,8 +288,6 @@ public void test200JackAssignAccountDummyPinkConflicting() throws Exception {
getDummyResource(RESOURCE_DUMMY_PINK_NAME).addAccount(account);
repoAddObject(createShadow(getDummyResourceObject(RESOURCE_DUMMY_PINK_NAME), ACCOUNT_JACK_DUMMY_USERNAME), result);

Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();

// assignment with weapon := 'pistol' (test for
Collection<ItemDelta<?,?>> modifications = new ArrayList<>();
AssignmentType assignmentType = createConstructionAssignment(RESOURCE_DUMMY_PINK_OID, ShadowKindType.ACCOUNT, null);
Expand All @@ -307,16 +305,13 @@ public void test200JackAssignAccountDummyPinkConflicting() throws Exception {
ObjectDelta<UserType> accountAssignmentUserDelta = prismContext.deltaFactory().object()
.createModifyDelta(USER_JACK_OID, modifications, UserType.class);

deltas.add(accountAssignmentUserDelta);

// WHEN
displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
executeChanges(accountAssignmentUserDelta, null, task, result);

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

PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
Expand Down Expand Up @@ -369,18 +364,15 @@ public void test210GuybrushAssignAccountDummyPink() throws Exception {
OperationResult result = task.getResult();
dummyAuditService.clear();

Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(USER_GUYBRUSH_OID, RESOURCE_DUMMY_PINK_OID, null, true);
deltas.add(accountAssignmentUserDelta);

// WHEN
displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
executeChanges(accountAssignmentUserDelta, null, task, result);

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

PrismObject<UserType> userGuybrush = getUser(USER_GUYBRUSH_OID);
display("User after change execution", userGuybrush);
Expand Down Expand Up @@ -436,16 +428,14 @@ public void test220DeWattAssignAccountDummyPinkCaseIgnore() throws Exception {
// precondition
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, ACCOUNT_DEWATT_NAME, "Augustus DeWatt", true);

Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(userDeWattkOid,
RESOURCE_DUMMY_PINK_OID, null, true);
deltas.add(accountAssignmentUserDelta);

dummyAuditService.clear();

// WHEN
displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
executeChanges(accountAssignmentUserDelta, null, task, result);

// THEN
displayThen(TEST_NAME);
Expand Down Expand Up @@ -1728,8 +1718,6 @@ public void test710DarkVioletAddLeChuck() throws Exception {
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();

DummyAccount account = new DummyAccount(ACCOUNT_LECHUCK_USERNAME);
Expand Down Expand Up @@ -1758,8 +1746,6 @@ public void test712DarkVioletAddCharles() throws Exception {
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();

DummyAccount account = new DummyAccount(ACCOUNT_CHARLES_USERNAME);
Expand Down Expand Up @@ -1789,8 +1775,6 @@ public void test714DarkVioletAddShinetop() throws Exception {
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();

DummyAccount account = new DummyAccount(ACCOUNT_SHINETOP_USERNAME);
Expand Down Expand Up @@ -1819,8 +1803,6 @@ public void test716DarkVioletDeleteCharles() throws Exception {
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();

// WHEN
Expand All @@ -1843,8 +1825,6 @@ public void test720DarkVioletModifyShinetopLocation() throws Exception {
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();

DummyAccount account = getDummyResource(RESOURCE_DUMMY_DARK_VIOLET_NAME).getAccountByUsername(ACCOUNT_SHINETOP_USERNAME);
Expand All @@ -1870,8 +1850,6 @@ public void test722DarkVioletModifyShinetopFullName() throws Exception {
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();

DummyAccount account = getDummyResource(RESOURCE_DUMMY_DARK_VIOLET_NAME).getAccountByUsername(ACCOUNT_SHINETOP_USERNAME);
Expand All @@ -1891,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 4c36d23

Please sign in to comment.