use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.
the class TestSynchronizationService method test010AddedAccountJack.
@Test
public void test010AddedAccountJack() throws Exception {
final String TEST_NAME = "test010AddedAccountJack";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestSynchronizationService.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
MockLensDebugListener mockListener = new MockLensDebugListener();
clockwork.setDebugListener(mockListener);
PrismObject<ShadowType> accountShadowJack = repoAddObjectFromFile(ACCOUNT_SHADOW_JACK_DUMMY_FILE, result);
accountShadowJackDummyOid = accountShadowJack.getOid();
provisioningService.applyDefinition(accountShadowJack, task, result);
assertNotNull("No oid in shadow", accountShadowJack.getOid());
DummyAccount dummyAccount = new DummyAccount();
dummyAccount.setName(ACCOUNT_JACK_DUMMY_USERNAME);
dummyAccount.setPassword("deadMenTellNoTales");
dummyAccount.setEnabled(true);
dummyAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Jack Sparrow");
getDummyResource().addAccount(dummyAccount);
ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
change.setCurrentShadow(accountShadowJack);
change.setResource(getDummyResourceObject());
// WHEN
synchronizationService.notifyChange(change, task, result);
// THEN
LensContext<UserType> context = mockListener.getLastSyncContext();
display("Resulting context (as seen by debug listener)", context);
assertNotNull("No resulting context (as seen by debug listener)", context);
assertNull("Unexpected user primary delta", context.getFocusContext().getPrimaryDelta());
assertSideEffectiveDeltasOnly(context.getFocusContext().getSecondaryDelta(), "user secondary delta", ActivationStatusType.ENABLED);
ResourceShadowDiscriminator rat = new ResourceShadowDiscriminator(getDummyResourceObject().getOid(), ShadowKindType.ACCOUNT, null);
LensProjectionContext accCtx = context.findProjectionContext(rat);
assertNotNull("No account sync context for " + rat, accCtx);
assertEquals("Wrong detected situation in context", SynchronizationSituationType.UNLINKED, accCtx.getSynchronizationSituationDetected());
assertEquals("Wrong resolved situation in context", SynchronizationSituationType.LINKED, accCtx.getSynchronizationSituationResolved());
PrismAsserts.assertNoDelta("Unexpected account primary delta", accCtx.getPrimaryDelta());
//it this really expected?? delta was already executed, should we expect it in the secondary delta?
// assertNotNull("Missing account secondary delta", accCtx.getSecondaryDelta());
// assertIterationDelta(accCtx.getSecondaryDelta(), 0, "");
assertLinked(context.getFocusContext().getObjectOld().getOid(), accountShadowJack.getOid());
PrismObject<ShadowType> shadow = getShadowModelNoFetch(accountShadowJackDummyOid);
assertIteration(shadow, 0, "");
assertSituation(shadow, SynchronizationSituationType.LINKED);
result.computeStatus();
TestUtil.assertSuccess(result);
}
use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.
the class WfPrepareRootOperationTaskHandler method run.
//endregion
//region run method
@Override
public TaskRunResult run(Task task) {
TaskRunResultStatus status = TaskRunResultStatus.FINISHED;
try {
OperationResult result = task.getResult();
WfTask rootWfTask = wfTaskController.recreateRootWfTask(task);
List<WfTask> children = rootWfTask.listChildren(result);
LensContext rootContext = (LensContext) rootWfTask.retrieveModelContext(result);
boolean changed = false;
for (WfTask child : children) {
if (child.getTaskExecutionStatus() != TaskExecutionStatus.CLOSED) {
throw new IllegalStateException("Child task " + child + " is not in CLOSED state; its state is " + child.getTaskExecutionStatus());
}
if (child.hasModelContext()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Child job {} has model context present - skipping fetching deltas from it.", child);
}
} else {
ObjectTreeDeltas deltas = child.retrieveResultingDeltas();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Child job {} returned {} deltas", child, deltas != null ? deltas.getDeltaList().size() : 0);
}
if (deltas != null) {
LensFocusContext focusContext = rootContext.getFocusContext();
ObjectDelta focusDelta = deltas.getFocusChange();
if (focusDelta != null) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Adding delta from job {} to root model context; delta = {}", child, focusDelta.debugDump(0));
}
if (focusContext.getPrimaryDelta() != null && !focusContext.getPrimaryDelta().isEmpty()) {
focusContext.addPrimaryDelta(focusDelta);
} else {
focusContext.setPrimaryDelta(focusDelta);
}
changed = true;
}
Set<Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>>> entries = deltas.getProjectionChangeMapEntries();
for (Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>> entry : entries) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Adding projection delta from job {} to root model context; rsd = {}, delta = {}", child, entry.getKey(), entry.getValue().debugDump());
}
ModelProjectionContext projectionContext = rootContext.findProjectionContext(entry.getKey());
if (projectionContext == null) {
// TODO more liberal treatment?
throw new IllegalStateException("No projection context for " + entry.getKey());
}
if (projectionContext.getPrimaryDelta() != null && !projectionContext.getPrimaryDelta().isEmpty()) {
projectionContext.addPrimaryDelta(entry.getValue());
} else {
projectionContext.setPrimaryDelta(entry.getValue());
}
changed = true;
}
}
}
}
if (!rootContext.hasAnyPrimaryChange()) {
// deletes the model context
rootContext = null;
// regardless of whether rootContext was changed or not
changed = true;
}
if (changed) {
rootWfTask.storeModelContext(rootContext);
rootWfTask.commitChanges(result);
}
} catch (SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | ConfigurationException | ExpressionEvaluationException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't aggregate resulting deltas from child workflow-monitoring tasks due to schema exception", e);
status = TaskRunResultStatus.PERMANENT_ERROR;
} catch (CommunicationException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't aggregate resulting deltas from child workflow-monitoring tasks", e);
status = TaskRunResultStatus.TEMPORARY_ERROR;
}
TaskRunResult runResult = new TaskRunResult();
runResult.setRunResultStatus(status);
return runResult;
}
use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.
the class PrimaryChangeProcessor method contextCopyWithDeltasReplaced.
private LensContext contextCopyWithDeltasReplaced(ModelContext context, ObjectTreeDeltas changes) throws SchemaException {
Validate.notNull(changes, "changes");
LensContext contextCopy = ((LensContext) context).clone();
contextCopy.replacePrimaryFocusDelta(changes.getFocusChange());
Map<ResourceShadowDiscriminator, ObjectDelta<ShadowType>> changeMap = changes.getProjectionChangeMap();
Collection<ModelProjectionContext> projectionContexts = contextCopy.getProjectionContexts();
for (ModelProjectionContext projectionContext : projectionContexts) {
ObjectDelta<ShadowType> projectionDelta = changeMap.get(projectionContext.getResourceShadowDiscriminator());
projectionContext.setPrimaryDelta(projectionDelta);
}
return contextCopy;
}
use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.
the class WfPrepareChildOperationTaskHandler method run.
//endregion
//region Body
@SuppressWarnings("unchecked")
@Override
public TaskRunResult run(Task task) {
TaskRunResult.TaskRunResultStatus status = TaskRunResult.TaskRunResultStatus.FINISHED;
LOGGER.trace("WfPrepareChildOperationTaskHandler starting... task = {}", task);
try {
WfTask wfTask = wfTaskController.recreateWfTask(task);
OperationResult result = task.getResult();
ModelContext<?> modelContext = wfTask.retrieveModelContext(result);
if (modelContext == null) {
throw new IllegalStateException("There's no model context in child task; task = " + task);
}
// prepare deltaOut to be used
ObjectTreeDeltas deltasOut = wfTask.retrieveResultingDeltas();
if (LOGGER.isTraceEnabled()) {
dumpDeltaOut(deltasOut);
}
if (deltasOut == null || deltasOut.isEmpty()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("There's no primary delta in focus context; we'll delete model operation context. Task = {}, model context:\n{}", task, modelContext.debugDump());
}
wfTask.deleteModelOperationContext();
} else {
// place deltaOut into model context
modelContext.getFocusContext().setPrimaryDelta(deltasOut.getFocusChange());
Set<Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>>> entries = deltasOut.getProjectionChangeMapEntries();
for (Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>> entry : entries) {
// TODO what if projection context does not exist?
modelContext.findProjectionContext(entry.getKey()).setPrimaryDelta(entry.getValue());
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Resulting model context to be stored into task {}:\n{}", task, modelContext.debugDump(0));
}
wfTask.storeModelContext(modelContext);
}
task.savePendingModifications(result);
} catch (SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | ConfigurationException | ExpressionEvaluationException | RuntimeException | Error e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't prepare child model context", e);
status = TaskRunResult.TaskRunResultStatus.PERMANENT_ERROR;
} catch (CommunicationException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't prepare child model context", e);
status = TaskRunResult.TaskRunResultStatus.TEMPORARY_ERROR;
}
TaskRunResult runResult = new TaskRunResult();
runResult.setRunResultStatus(status);
return runResult;
}
use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.
the class TestSynchronizationService method test210AddedGroupPirates.
@Test
public void test210AddedGroupPirates() throws Exception {
final String TEST_NAME = "test210AddedGroupPirates";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestSynchronizationService.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
MockLensDebugListener mockListener = new MockLensDebugListener();
clockwork.setDebugListener(mockListener);
PrismObject<ShadowType> shadowPirates = repoAddObjectFromFile(SHADOW_PIRATES_DUMMY_FILE, result);
provisioningService.applyDefinition(shadowPirates, task, result);
assertNotNull("No oid in shadow", shadowPirates.getOid());
DummyGroup dummyGroup = new DummyGroup();
dummyGroup.setName(GROUP_PIRATES_DUMMY_NAME);
dummyGroup.setEnabled(true);
dummyGroup.addAttributeValues(DummyResourceContoller.DUMMY_GROUP_ATTRIBUTE_DESCRIPTION, "Scurvy Pirates");
getDummyResource().addGroup(dummyGroup);
ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
change.setCurrentShadow(shadowPirates);
change.setResource(getDummyResourceObject());
// WHEN
TestUtil.displayWhen(TEST_NAME);
synchronizationService.notifyChange(change, task, result);
// THEN
TestUtil.displayWhen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
LensContext<UserType> context = mockListener.getLastSyncContext();
display("Resulting context (as seen by debug listener)", context);
assertNotNull("No resulting context (as seen by debug listener)", context);
assertNotNull("No focus primary delta", context.getFocusContext().getPrimaryDelta());
// assertNotNull("No focus secondary delta", context.getFocusContext().getSecondaryDelta());
assertFalse("No executed focus deltas", context.getFocusContext().getExecutedDeltas().isEmpty());
ObjectDelta<UserType> userSecondaryDelta = (ObjectDelta<UserType>) context.getFocusContext().getExecutedDeltas().iterator().next().getObjectDelta();
ResourceShadowDiscriminator rat = new ResourceShadowDiscriminator(getDummyResourceObject().getOid(), ShadowKindType.ENTITLEMENT, INTENT_GROUP);
LensProjectionContext projCtx = context.findProjectionContext(rat);
assertNotNull("No projection sync context for " + rat, projCtx);
assertEquals("Wrong detected situation in context", SynchronizationSituationType.UNMATCHED, projCtx.getSynchronizationSituationDetected());
assertEquals("Wrong resolved situation in context", SynchronizationSituationType.LINKED, projCtx.getSynchronizationSituationResolved());
PrismAsserts.assertNoDelta("Unexpected projection primary delta", projCtx.getPrimaryDelta());
//it this really expected?? delta was already executed, should we expect it in the secondary delta?
// assertNotNull("Missing account secondary delta", accCtx.getSecondaryDelta());
// assertIterationDelta(accCtx.getSecondaryDelta(), 0, "");
assertLinked(RoleType.class, context.getFocusContext().getOid(), shadowPirates.getOid());
PrismObject<ShadowType> shadow = getShadowModelNoFetch(shadowPirates.getOid());
assertIteration(shadow, 0, "");
assertSituation(shadow, SynchronizationSituationType.LINKED);
}
Aggregations