use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.
the class DefaultGuiProgressListener method updateStatusItemState.
private void updateStatusItemState(ProgressReportActivityDto si, ProgressInformation progressInformation, ModelContext modelContext) {
si.setActivityType(progressInformation.getActivityType());
si.setResourceShadowDiscriminator(progressInformation.getResourceShadowDiscriminator());
if (progressInformation.getResourceShadowDiscriminator() != null) {
String resourceOid = progressInformation.getResourceShadowDiscriminator().getResourceOid();
String resourceName = resourceOid != null ? getResourceName(resourceOid) : "";
si.setResourceName(resourceName);
}
if (progressInformation.getStateType() == null) {
si.setStatus(null);
} else if (progressInformation.getStateType() == ENTERING) {
si.setStatus(OperationResultStatusType.IN_PROGRESS);
} else {
OperationResult result = progressInformation.getOperationResult();
if (result != null) {
OperationResultStatus status = result.getStatus();
if (status == OperationResultStatus.UNKNOWN) {
status = result.getComputeStatus();
}
si.setStatus(status.createStatusType());
} else {
si.setStatus(OperationResultStatusType.UNKNOWN);
}
}
// information about modifications on a resource
if (progressInformation.getActivityType() == RESOURCE_OBJECT_OPERATION && progressInformation.getStateType() == EXITING && progressInformation.getResourceShadowDiscriminator() != null && progressInformation.getResourceShadowDiscriminator().getResourceOid() != null) {
ModelProjectionContext mpc = modelContext.findProjectionContext(progressInformation.getResourceShadowDiscriminator());
if (mpc != null) {
// it shouldn't be null!
// operations performed (TODO aggregate them somehow?)
List<ResourceOperationResult> resourceOperationResultList = new ArrayList<>();
List<? extends ObjectDeltaOperation> executedDeltas = mpc.getExecutedDeltas();
for (ObjectDeltaOperation executedDelta : executedDeltas) {
ObjectDelta delta = executedDelta.getObjectDelta();
if (delta != null) {
OperationResult r = executedDelta.getExecutionResult();
OperationResultStatus status = r.getStatus();
if (status == OperationResultStatus.UNKNOWN) {
status = r.getComputeStatus();
}
resourceOperationResultList.add(new ResourceOperationResult(delta.getChangeType(), status));
}
}
si.setResourceOperationResultList(resourceOperationResultList);
// object name
PrismObject<ShadowType> object = mpc.getObjectNew();
if (object == null) {
object = mpc.getObjectOld();
}
String name = null;
if (object != null) {
if (object.asObjectable().getName() != null) {
name = PolyString.getOrig(object.asObjectable().getName());
} else {
// determine from attributes
ResourceAttribute nameAttribute = ShadowUtil.getNamingAttribute(object);
if (nameAttribute != null) {
name = String.valueOf(nameAttribute.getAnyRealValue());
}
}
}
if (name != null) {
si.setResourceObjectName(name);
}
}
}
}
use of com.evolveum.midpoint.model.api.context.ModelProjectionContext 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.model.api.context.ModelProjectionContext 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.model.api.context.ModelProjectionContext in project midpoint by Evolveum.
the class TestPreviewChanges method test212ModifyUserAddAccountRef.
@Test
public void test212ModifyUserAddAccountRef() throws Exception {
final String TEST_NAME = "test212ModifyUserAddAccountRef";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestPreviewChanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_GUYBRUSH_OID, prismContext);
ReferenceDelta accountDelta = ReferenceDelta.createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), ACCOUNT_SHADOW_GUYBRUSH_OID);
userDelta.addModification(accountDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
display("Input deltas: ", userDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
ModelContext<UserType> modelContext = modelInteractionService.previewChanges(deltas, new ModelExecuteOptions(), task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
display("Preview context", modelContext);
assertNotNull("Null model context", modelContext);
result.computeStatus();
TestUtil.assertSuccess(result);
ModelElementContext<UserType> focusContext = modelContext.getFocusContext();
assertNotNull("Null model focus context", focusContext);
assertNull("Unexpected focus primary delta: " + focusContext.getPrimaryDelta(), focusContext.getPrimaryDelta());
ObjectDelta<UserType> userSecondaryDelta = focusContext.getSecondaryDelta();
assertSideEffectiveDeltasOnly("focus secondary delta", focusContext.getSecondaryDelta());
Collection<? extends ModelProjectionContext> projectionContexts = modelContext.getProjectionContexts();
assertNotNull("Null model projection context list", projectionContexts);
assertEquals("Unexpected number of projection contexts", 1, projectionContexts.size());
ModelProjectionContext accContext = projectionContexts.iterator().next();
assertNotNull("Null model projection context", accContext);
assertEquals("Wrong policy decision", SynchronizationPolicyDecision.KEEP, accContext.getSynchronizationPolicyDecision());
ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
assertNull("Unexpected account primary delta", accountPrimaryDelta);
ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
assertEquals("Unexpected size of account secondary delta: " + accountSecondaryDelta, 2, accountSecondaryDelta.getModifications().size());
PrismAsserts.assertPropertyAdd(accountSecondaryDelta, dummyResourceCtl.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME), "rum");
PrismAsserts.assertPropertyAdd(accountSecondaryDelta, dummyResourceCtl.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME), "Arr!");
}
use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.
the class TestPreviewChanges method test210GuybrushAddAccount.
@Test
public void test210GuybrushAddAccount() throws Exception {
final String TEST_NAME = "test210GuybrushAddAccount";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestPreviewChanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
ObjectDelta<ShadowType> accountDelta = ObjectDelta.createAddDelta(account);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(accountDelta);
display("Input deltas: ", deltas);
// WHEN
TestUtil.displayWhen(TEST_NAME);
ModelContext<UserType> modelContext = modelInteractionService.previewChanges(deltas, new ModelExecuteOptions(), task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
display("Preview context", modelContext);
assertNotNull("Null model context", modelContext);
result.computeStatus();
TestUtil.assertSuccess(result);
ModelElementContext<UserType> focusContext = modelContext.getFocusContext();
assertNull("Unexpected model focus context", focusContext);
Collection<? extends ModelProjectionContext> projectionContexts = modelContext.getProjectionContexts();
assertNotNull("Null model projection context list", projectionContexts);
assertEquals("Unexpected number of projection contexts", 1, projectionContexts.size());
ModelProjectionContext accContext = projectionContexts.iterator().next();
assertNotNull("Null model projection context", accContext);
// Decision does not matter now
// assertEquals("Wrong policy decision", SynchronizationPolicyDecision.ADD, accContext.getSynchronizationPolicyDecision());
ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
assertEquals(ChangeType.ADD, accountPrimaryDelta.getChangeType());
PrismObject<ShadowType> accountToAddPrimary = accountPrimaryDelta.getObjectToAdd();
assertNotNull("No object in account primary add delta", accountToAddPrimary);
assertEquals(getDummyResourceController().getAccountObjectClass(), accountToAddPrimary.findProperty(ShadowType.F_OBJECT_CLASS).getRealValue());
PrismReference resourceRef = accountToAddPrimary.findReference(ShadowType.F_RESOURCE_REF);
assertEquals(getDummyResourceObject().getOid(), resourceRef.getOid());
ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
PrismAsserts.assertModifications(accountSecondaryDelta, 1);
}
Aggregations