Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jul 31, 2015
2 parents 5bebe76 + 8b83c9d commit 73bfeb6
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 15 deletions.
Expand Up @@ -766,6 +766,10 @@ public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

/**
* @return Method returns message key for translation, can be null.
*/
Expand Down
Expand Up @@ -88,6 +88,7 @@
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.schema.util.ObjectResolver;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.SchemaDebugUtil;
Expand Down Expand Up @@ -166,7 +167,7 @@ public class AssignmentProcessor {
* Generic method for all projection types (theoretically).
*/
public <O extends ObjectType> void processAssignmentsProjections(LensContext<O> context, XMLGregorianCalendar now,
Task task, OperationResult result) throws SchemaException,
Task task, OperationResult parentResult) throws SchemaException,
ObjectNotFoundException, ExpressionEvaluationException, PolicyViolationException, CommunicationException, ConfigurationException, SecurityViolationException {
LensFocusContext<O> focusContext = context.getFocusContext();
if (focusContext == null) {
Expand All @@ -180,7 +181,33 @@ public <O extends ObjectType> void processAssignmentsProjections(LensContext<O>
// //do not execute assignment if the execution was triggered by compensation mechanism and limitPropagation is set
// return;
// }
processAssignmentsProjectionsWithFocus((LensContext<? extends FocusType>)context, now, task, result);

OperationResult result = parentResult.createSubresult(AssignmentProcessor.class.getName() + ".processAssignmentsProjections");

try {
processAssignmentsProjectionsWithFocus((LensContext<? extends FocusType>)context, now, task, result);
} catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException | PolicyViolationException |
CommunicationException | ConfigurationException | SecurityViolationException e) {
result.recordFatalError(e);
throw e;
}

OperationResultStatus finalStatus = OperationResultStatus.SUCCESS;
String message = null;
int errors = 0;
for (OperationResult subresult: result.getSubresults()) {
if (subresult.isError()) {
errors++;
if (message == null) {
message = subresult.getMessage();
} else {
message = errors + " errors";
}
finalStatus = OperationResultStatus.PARTIAL_ERROR;
}
}
result.setStatus(finalStatus);
result.setMessage(message);
}

/**
Expand Down Expand Up @@ -980,23 +1007,27 @@ private Collection<PrismContainerValue<AssignmentType>> mergeAssignments(

private <F extends FocusType> EvaluatedAssignmentImpl<F> evaluateAssignment(ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> assignmentIdi,
boolean evaluateOld, LensContext<F> context, ObjectType source, AssignmentEvaluator<F> assignmentEvaluator,
String assignmentPlacementDesc, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, PolicyViolationException {
String assignmentPlacementDesc, Task task, OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, PolicyViolationException {
OperationResult result = parentResult.createSubresult(AssignmentProcessor.class+".evaluateAssignment");
result.addParam("assignmentDescription", assignmentPlacementDesc);
try{
// Evaluate assignment. This follows to the assignment targets, follows to the inducements,
// evaluates all the expressions, etc.
EvaluatedAssignmentImpl<F> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, evaluateOld, source, assignmentPlacementDesc, task, result);
context.rememberResources(evaluatedAssignment.getResources(result));
result.recordSuccess();
return evaluatedAssignment;
} catch (ObjectNotFoundException ex){
} catch (ObjectNotFoundException ex) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing of assignment resulted in error {}: {}", ex, SchemaDebugUtil.prettyPrint(LensUtil.getAssignmentType(assignmentIdi, evaluateOld)));
}
if (ModelExecuteOptions.isForce(context.getOptions())){
if (ModelExecuteOptions.isForce(context.getOptions())) {
result.recordHandledError(ex);
return null;
}
}
ModelUtils.recordFatalError(result, ex);
return null;
} catch (SchemaException ex){
} catch (SchemaException ex) {
AssignmentType assignmentType = LensUtil.getAssignmentType(assignmentIdi, evaluateOld);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing of assignment resulted in error {}: {}", ex, SchemaDebugUtil.prettyPrint(assignmentType));
Expand All @@ -1014,6 +1045,9 @@ private <F extends FocusType> EvaluatedAssignmentImpl<F> evaluateAssignment(Item
accCtx.setSynchronizationPolicyDecision(SynchronizationPolicyDecision.BROKEN);
}
return null;
} catch (ExpressionEvaluationException | PolicyViolationException e) {
result.recordFatalError(e);
throw e;
}
}

Expand Down
Expand Up @@ -119,7 +119,6 @@ public <F extends FocusType> void processOutbound(LensContext<F> context, LensPr
ObjectDeltaObject<ShadowType> projectionOdo = projCtx.getObjectDeltaObject();

Construction<F> outboundConstruction = new Construction<>(null, projCtx.getResource());
outboundConstruction.setValid(true);
outboundConstruction.setRefinedObjectClassDefinition(rOcDef);

Collection<RefinedObjectClassDefinition> auxiliaryObjectClassDefinitions = rOcDef.getAuxiliaryObjectClassDefinitions();
Expand Down
Expand Up @@ -304,7 +304,7 @@ private <F extends ObjectType> void projectInternal(LensContext<F> context, Stri

if (consistencyChecks) context.checkConsistence();

recordSuccess(now, result);
computeResultStatus(now, result);

} catch (SchemaException e) {
recordFatalError(e, now, result);
Expand Down Expand Up @@ -378,17 +378,17 @@ private void recordFatalError(Exception e, XMLGregorianCalendar projectoStartTim
if (LOGGER.isDebugEnabled()) {
long projectoStartTimestamp = XmlTypeConverter.toMillis(projectoStartTimestampCal);
long projectorEndTimestamp = clock.currentTimeMillis();
LOGGER.debug("Projector failed: {}, etime: {} ms", e.getMessage(), (projectorEndTimestamp - projectoStartTimestamp));
LOGGER.debug("Projector failed: {}. Etime: {} ms", e.getMessage(), (projectorEndTimestamp - projectoStartTimestamp));
}
}

private void recordSuccess(XMLGregorianCalendar projectoStartTimestampCal, OperationResult result) {
result.recordSuccess();
private void computeResultStatus(XMLGregorianCalendar projectoStartTimestampCal, OperationResult result) {
result.computeStatus();
result.cleanupResult();
if (LOGGER.isDebugEnabled()) {
long projectoStartTimestamp = XmlTypeConverter.toMillis(projectoStartTimestampCal);
long projectorEndTimestamp = clock.currentTimeMillis();
LOGGER.trace("Projector successful, etime: {} ms", (projectorEndTimestamp - projectoStartTimestamp));
LOGGER.trace("Projector finished ({}). Etime: {} ms", result.getStatus(), (projectorEndTimestamp - projectoStartTimestamp));
}
}

Expand Down
Expand Up @@ -589,7 +589,7 @@ public void test255ModifyUserBarbossaAssignment() throws Exception {
assertNotNull("No account secondary delta", accountSecondaryDelta);
assertEquals(ChangeType.MODIFY, accountSecondaryDelta.getChangeType());
// There is a lot of changes caused by the reconciliation. But we are only interested in the new one
assertEquals("Unexpected number of account secondary changes", 4, accountSecondaryDelta.getModifications().size());
assertEquals("Unexpected number of account secondary changes", 3, accountSecondaryDelta.getModifications().size());
PrismAsserts.assertPropertyAdd(accountSecondaryDelta,
dummyResourceCtl.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME),
"Pirate of Caribbean");
Expand Down
Expand Up @@ -109,11 +109,14 @@ public class TestStrangeCases extends AbstractInitializedModelIntegrationTest {
private static final String ROLE_RECURSION_OID = "12345678-d34d-b33f-f00d-555555550003";

private static final String NON_EXISTENT_ACCOUNT_OID = "f000f000-f000-f000-f000-f000f000f000";

private static final String RESOURCE_NONEXISTENT_OID = "00000000-f000-f000-f000-f000f000f000";;

private static final XMLGregorianCalendar USER_DEGHOULASH_FUNERAL_TIMESTAMP =
XmlTypeConverter.createXMLGregorianCalendar(1771, 1, 2, 11, 22, 33);

private static final File TREASURE_ISLAND_FILE = new File(TEST_DIR, "treasure-island.txt");

private static String treasureIsland;

private String accountGuybrushDummyRedOid;
Expand Down Expand Up @@ -351,7 +354,7 @@ public void test200ModifyUserJackBrokenAccountRefAndPolyString() throws Exceptio
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(2);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.assertExecutionSuccess();
dummyAuditService.assertExecutionOutcome(OperationResultStatus.HANDLED_ERROR);
}

// Lets test various extension magic and border cases now. This is maybe quite hight in the architecture for
Expand Down Expand Up @@ -582,6 +585,58 @@ public void test332AssignDeGhoulashRecursion() throws Exception {
assertUser(userDeGhoulash, USER_DEGHOULASH_OID, "deghoulash", "Charles DeGhoulash", "Charles", "DeGhoulash");
assertAssignedNoRole(userDeGhoulash);
}

@Test
public void test340AssignDeGhoulashConstructionNonExistentResource() throws Exception {
final String TEST_NAME = "test340AssignDeGhoulashConstructionNonExistentResource";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
dummyAuditService.clear();

// WHEN
// We have loose referential consistency. Even if the target resource is not present
// the assignment should be added. The error is indicated in the result.
assignAccount(USER_DEGHOULASH_OID, RESOURCE_NONEXISTENT_OID, null, task, result);

// THEN
result.computeStatus();
display("Result", result);
TestUtil.assertFailure(result);

PrismObject<UserType> userDeGhoulash = getUser(USER_DEGHOULASH_OID);
display("User after change execution", userDeGhoulash);
assertUser(userDeGhoulash, USER_DEGHOULASH_OID, "deghoulash", "Charles DeGhoulash", "Charles", "DeGhoulash");
assertAssignments(userDeGhoulash, 1);
}

@Test
public void test349UnAssignDeGhoulashConstructionNonExistentResource() throws Exception {
final String TEST_NAME = "test349UnAssignDeGhoulashConstructionNonExistentResource";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
dummyAuditService.clear();

// WHEN
unassignAccount(USER_DEGHOULASH_OID, RESOURCE_NONEXISTENT_OID, null, task, result);

// THEN
result.computeStatus();
display("Result", result);
TestUtil.assertFailure(result);

PrismObject<UserType> userDeGhoulash = getUser(USER_DEGHOULASH_OID);
display("User after change execution", userDeGhoulash);
assertUser(userDeGhoulash, USER_DEGHOULASH_OID, "deghoulash", "Charles DeGhoulash", "Charles", "DeGhoulash");
assertAssignments(userDeGhoulash, 0);
}

@Test
public void test400ImportJackMockTask() throws Exception {
Expand Down

0 comments on commit 73bfeb6

Please sign in to comment.