Skip to content

Commit

Permalink
Fixed MID-2242
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Mar 6, 2015
1 parent 548da2b commit 91a89f4
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 18 deletions.
Expand Up @@ -238,7 +238,16 @@ private void evaluateAssignment(EvaluatedAssignmentImpl<F> evalAssignment, Assig
if (assignmentType.getTarget() != null) {
target = assignmentType.getTarget().asPrismObject();
} else if (assignmentType.getTargetRef() != null) {
target = resolveTarget(assignmentType, source, sourceDescription, task, result);
try {
target = resolveTarget(assignmentType, source, sourceDescription, task, result);
} catch (ObjectNotFoundException ex) {
// Do not throw an exception. We don't have referential integrity. Therefore if a role is deleted then throwing
// an exception would prohibit any operations with the users that have the role, including removal of the reference.
// The failure is recorded in the result and we will log it. It should be enough.
LOGGER.error(ex.getMessage()+" in assignment target reference in "+sourceDescription,ex);
// For OrgType references we trigger the reconciliation (see MID-2242)
evalAssignment.setForceRecon(true);
}
}
if (target != null && evalAssignment.getTarget() == null) {
evalAssignment.setTarget(target);
Expand Down Expand Up @@ -390,19 +399,12 @@ private PrismObject<?> resolveTarget(AssignmentType assignmentType, ObjectType s
throw new SchemaException("Missing type in target reference in " + assignmentType + " in " + sourceDescription);
}
PrismObject<? extends ObjectType> target = null;
try {
target = repository.getObject(clazz, oid, null, result);
if (target == null) {
throw new IllegalArgumentException("Got null target from repository, oid:"+oid+", class:"+clazz+" (should not happen, probably a bug) in "+sourceDescription);
}
} catch (ObjectNotFoundException ex) {
// Do not throw an exception. We don't have referential integrity. Therefore if a role is deleted then throwing
// an exception would prohibit any operations with the users that have the role, including removal of the reference.
// The failure is recorded in the result and we will log it. It should be enough.
LOGGER.error(ex.getMessage()+" in assignment target reference in "+sourceDescription,ex);
// throw new ObjectNotFoundException(ex.getMessage()+" in assignment target reference in "+sourceDescription,ex);
}

target = repository.getObject(clazz, oid, null, result);
if (target == null) {
throw new IllegalArgumentException("Got null target from repository, oid:"+oid+", class:"+clazz+" (should not happen, probably a bug) in "+sourceDescription);
}
// Handling ObjectNotFoundException - we just pass it to the caller

return target;
}

Expand Down
Expand Up @@ -61,7 +61,7 @@ public class EvaluatedAssignmentImpl<F extends FocusType> implements EvaluatedAs
private Collection<Mapping<? extends PrismPropertyValue<?>>> focusMappings;
private PrismObject<?> target;
private boolean isValid;
private boolean forceRecon;
private boolean forceRecon; // used also to force recomputation of parentOrgRefs

public EvaluatedAssignmentImpl() {
constructions = new DeltaSetTriple<>();
Expand Down
Expand Up @@ -782,19 +782,25 @@ private <F extends ObjectType> ObjectType determineSource(LensFocusContext<F> fo

private <F extends FocusType> void collectToZero(DeltaSetTriple<EvaluatedAssignmentImpl<F>> evaluatedAssignmentTriple,
EvaluatedAssignmentImpl<F> evaluatedAssignment, boolean forceRecon) {
evaluatedAssignment.setForceRecon(forceRecon);
if (forceRecon) {
evaluatedAssignment.setForceRecon(true);
}
evaluatedAssignmentTriple.addToZeroSet(evaluatedAssignment);
}

private <F extends FocusType> void collectToPlus(DeltaSetTriple<EvaluatedAssignmentImpl<F>> evaluatedAssignmentTriple,
EvaluatedAssignmentImpl<F> evaluatedAssignment, boolean forceRecon) {
evaluatedAssignment.setForceRecon(forceRecon);
if (forceRecon) {
evaluatedAssignment.setForceRecon(true);
}
evaluatedAssignmentTriple.addToPlusSet(evaluatedAssignment);
}

private <F extends FocusType> void collectToMinus(DeltaSetTriple<EvaluatedAssignmentImpl<F>> evaluatedAssignmentTriple,
EvaluatedAssignmentImpl<F> evaluatedAssignment, boolean forceRecon) {
evaluatedAssignment.setForceRecon(forceRecon);
if (forceRecon) {
evaluatedAssignment.setForceRecon(true);
}
evaluatedAssignmentTriple.addToMinusSet(evaluatedAssignment);
}

Expand Down Expand Up @@ -1194,6 +1200,16 @@ public <F extends ObjectType> void processOrgAssignments(LensContext<F> context,
break;
}
}
// for zero and minus sets we check isForceRecon for all non-construction-related assignments (MID-2242)
if (!forceRecon) {
for (EvaluatedAssignmentImpl assignment: evaluatedAssignmentTriple.getNonPositiveValues()) {
if (assignment.isForceRecon() &&
(assignment.getConstructions() == null || assignment.getConstructions().isEmpty())) {
forceRecon = true;
break;
}
}
}

if (!forceRecon) { // if no recon, we simply add/delete values as needed

Expand Down
Expand Up @@ -78,6 +78,9 @@ public class TestOrgStruct extends AbstractInitializedModelIntegrationTest {
public static final File ROLE_DEFENDER_FILE = new File(TEST_DIR, "role-defender.xml");
public static final String ROLE_DEFENDER_OID = "12345111-1111-2222-1111-121212111567";

public static final File ORG_TEMP_FILE = new File(TEST_DIR, "org-temp.xml");
public static final String ORG_TEMP_OID = "43214321-4311-0952-4762-854392584320";

@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
Expand Down Expand Up @@ -1228,6 +1231,54 @@ public void test412JackChangeMinistryOfOffenseMemberToManagerByModifyingAssignme
}
}

// import temp org + assign to jack (preparation for the next test)
@Test
public void test420JackAssignTempOrg() throws Exception {
final String TEST_NAME = "test420JackAssignTempOrg";
TestUtil.displayTestTile(this, TEST_NAME);

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

addObject(ORG_TEMP_FILE);

// WHEN
assignOrg(USER_JACK_OID, ORG_TEMP_OID, task, result);

// THEN
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User jack after", userJack);
assertUserAssignedOrgs(userJack, ORG_MINISTRY_OF_OFFENSE_OID, ORG_TEMP_OID);
assertUserHasOrgs(userJack, ORG_MINISTRY_OF_OFFENSE_OID, ORG_TEMP_OID);

// Postcondition
assertMonkeyIslandOrgSanity();
}

// delete the org and then unassign it
@Test
public void test425JackUnassignDeletedOrg() throws Exception {
final String TEST_NAME = "test425JackUnassignDeletedOrg";
TestUtil.displayTestTile(this, TEST_NAME);

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

deleteObject(OrgType.class, ORG_TEMP_OID, task, result);

// WHEN
unassignOrg(USER_JACK_OID, ORG_TEMP_OID, task, result);

// THEN
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User jack after", userJack);
assertUserAssignedOrgs(userJack, ORG_MINISTRY_OF_OFFENSE_OID);
assertUserHasOrgs(userJack, ORG_MINISTRY_OF_OFFENSE_OID);

// Postcondition
assertMonkeyIslandOrgSanity();
}

/**
* Now let's test working with assignments when there is an object template that prescribes an org assignment
* based on organizationalUnit property.
Expand Down
26 changes: 26 additions & 0 deletions model/model-intest/src/test/resources/orgstruct/org-temp.xml
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2015 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<org oid="43214321-4311-0952-4762-854392584320" xmlns='http://midpoint.evolveum.com/xml/ns/public/common/common-3'>
<name>TEMP</name>
<description>Suddenly appearing and disappearing org</description>
<displayName>Temp Org</displayName>
<identifier>oooo</identifier>
<orgType>functional</orgType>
<costCenter>CCoooo</costCenter>
</org>

0 comments on commit 91a89f4

Please sign in to comment.