use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTreeDeltasType in project midpoint by Evolveum.
the class ObjectTreeDeltas method fromObjectTreeDeltasType.
public static ObjectTreeDeltas fromObjectTreeDeltasType(ObjectTreeDeltasType deltasType, PrismContext prismContext) throws SchemaException {
Validate.notNull(prismContext, "prismContext");
if (deltasType == null) {
return null;
}
ObjectTreeDeltas deltas = new ObjectTreeDeltas(prismContext);
if (deltasType.getFocusPrimaryDelta() != null) {
deltas.setFocusChange(DeltaConvertor.createObjectDelta(deltasType.getFocusPrimaryDelta(), prismContext));
}
for (ProjectionObjectDeltaType projectionObjectDeltaType : deltasType.getProjectionPrimaryDelta()) {
ResourceShadowDiscriminator rsd = ResourceShadowDiscriminator.fromResourceShadowDiscriminatorType(projectionObjectDeltaType.getResourceShadowDiscriminator());
ObjectDelta objectDelta = DeltaConvertor.createObjectDelta(projectionObjectDeltaType.getPrimaryDelta(), prismContext);
deltas.addProjectionChange(rsd, objectDelta);
}
return deltas;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTreeDeltasType in project midpoint by Evolveum.
the class AbstractWfTestPolicy method executeTest.
protected <F extends FocusType> void executeTest(String testName, TestDetails testDetails, int expectedSubTaskCount) throws Exception {
// GIVEN
prepareNotifications();
dummyAuditService.clear();
Task modelTask = taskManager.createTaskInstance(AbstractWfTestPolicy.class.getName() + "." + testName);
modelTask.setOwner(userAdministrator);
OperationResult result = new OperationResult("execution");
LensContext<F> modelContext = testDetails.createModelContext(result);
display("Model context at test start", modelContext);
// this has problems with deleting assignments by ID
//assertFocusModificationSanity(modelContext);
// WHEN
HookOperationMode mode = clockwork.run(modelContext, modelTask, result);
// THEN
display("Model context after first clockwork.run", modelContext);
assertEquals("Unexpected state of the context", ModelState.PRIMARY, modelContext.getState());
assertEquals("Wrong mode after clockwork.run in " + modelContext.getState(), HookOperationMode.BACKGROUND, mode);
modelTask.refresh(result);
display("Model task after first clockwork.run", modelTask);
String rootTaskOid = wfTaskUtil.getRootTaskOid(modelTask);
assertNotNull("Root task OID is not set in model task", rootTaskOid);
Task rootTask = taskManager.getTask(rootTaskOid, result);
assertTrue("Root task is not persistent", rootTask.isPersistent());
UriStack uriStack = rootTask.getOtherHandlersUriStack();
if (!testDetails.executeImmediately()) {
assertEquals("Invalid handler at stack position 0", ModelOperationTaskHandler.MODEL_OPERATION_TASK_URI, uriStack.getUriStackEntry().get(0).getHandlerUri());
} else {
assertTrue("There should be no handlers for root tasks with immediate execution mode", uriStack == null || uriStack.getUriStackEntry().isEmpty());
}
ModelContext rootModelContext = testDetails.executeImmediately() ? null : wfTaskUtil.getModelContext(rootTask, result);
if (!testDetails.executeImmediately()) {
assertNotNull("Model context is not present in root task", rootModelContext);
} else {
assertNull("Model context is present in root task (execution mode = immediate)", rootModelContext);
}
List<Task> subtasks = rootTask.listSubtasks(result);
Task task0 = findAndRemoveTask0(subtasks, testDetails);
assertEquals("Incorrect number of subtasks", expectedSubTaskCount, subtasks.size());
final Collection<SelectorOptions<GetOperationOptions>> options1 = resolveItemsNamed(new ItemPath(T_PARENT, F_OBJECT_REF), new ItemPath(T_PARENT, F_TARGET_REF), F_ASSIGNEE_REF, F_ORIGINAL_ASSIGNEE_REF, new ItemPath(T_PARENT, F_REQUESTER_REF));
List<WorkItemType> workItems = modelService.searchContainers(WorkItemType.class, null, options1, modelTask, result);
testDetails.afterFirstClockworkRun(rootTask, subtasks, workItems, result);
if (testDetails.executeImmediately()) {
if (task0 != null) {
waitForTaskClose(task0, 20000);
}
testDetails.afterTask0Finishes(rootTask, result);
}
for (int i = 0; i < subtasks.size(); i++) {
Task subtask = subtasks.get(i);
PrismProperty<ObjectTreeDeltasType> deltas = subtask.getTaskPrismObject().findProperty(new ItemPath(F_WORKFLOW_CONTEXT, F_PROCESSOR_SPECIFIC_STATE, F_DELTAS_TO_PROCESS));
assertNotNull("There are no modifications in subtask #" + i + ": " + subtask, deltas);
assertEquals("Incorrect number of modifications in subtask #" + i + ": " + subtask, 1, deltas.getRealValues().size());
// todo check correctness of the modification?
// now check the workflow state
String pid = wfTaskUtil.getProcessId(subtask);
assertNotNull("Workflow process instance id not present in subtask " + subtask, pid);
List<org.activiti.engine.task.Task> tasks = activitiEngine.getTaskService().createTaskQuery().processInstanceId(pid).list();
assertFalse("activiti task not found", tasks.isEmpty());
for (org.activiti.engine.task.Task task : tasks) {
String executionId = task.getExecutionId();
display("Execution id = " + executionId);
Boolean approve = testDetails.decideOnApproval(executionId, task);
if (approve != null) {
workflowManager.completeWorkItem(task.getId(), approve, null, null, null, result);
login(userAdministrator);
break;
}
}
}
// alternative way of approvals executions
if (CollectionUtils.isNotEmpty(testDetails.getApprovalSequence())) {
List<ApprovalInstruction> instructions = new ArrayList<>(testDetails.getApprovalSequence());
while (!instructions.isEmpty()) {
List<WorkItemType> currentWorkItems = modelService.searchContainers(WorkItemType.class, null, options1, modelTask, result);
boolean matched = false;
main: for (ApprovalInstruction approvalInstruction : instructions) {
for (WorkItemType workItem : currentWorkItems) {
if (approvalInstruction.matches(workItem)) {
if (approvalInstruction.beforeApproval != null) {
approvalInstruction.beforeApproval.run();
}
login(getUserFromRepo(approvalInstruction.approverOid));
workflowManager.completeWorkItem(workItem.getExternalId(), approvalInstruction.approval, null, null, null, result);
if (approvalInstruction.afterApproval != null) {
approvalInstruction.afterApproval.run();
}
login(userAdministrator);
matched = true;
instructions.remove(approvalInstruction);
break main;
}
}
}
if (!matched) {
fail("None of approval instructions " + instructions + " matched any of current work items: " + currentWorkItems);
}
}
}
waitForTaskClose(rootTask, 60000);
subtasks = rootTask.listSubtasks(result);
findAndRemoveTask0(subtasks, testDetails);
testDetails.afterRootTaskFinishes(rootTask, subtasks, result);
notificationManager.setDisabled(true);
// Check audit
display("Audit", dummyAuditService);
display("Output context", modelContext);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTreeDeltasType in project midpoint by Evolveum.
the class SceneUtil method visualizeObjectTreeDeltas.
public static Scene visualizeObjectTreeDeltas(ObjectTreeDeltasType deltas, String displayNameKey, PrismContext prismContext, ModelInteractionService modelInteractionService, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException {
List<Scene> scenes = new ArrayList<>();
if (deltas != null) {
if (deltas.getFocusPrimaryDelta() != null) {
ObjectDelta<? extends ObjectType> delta = DeltaConvertor.createObjectDelta(deltas.getFocusPrimaryDelta(), prismContext);
scenes.add(modelInteractionService.visualizeDelta(delta, task, result));
}
for (ProjectionObjectDeltaType projectionObjectDelta : deltas.getProjectionPrimaryDelta()) {
ObjectDelta<? extends ObjectType> delta = DeltaConvertor.createObjectDelta(projectionObjectDelta.getPrimaryDelta(), prismContext);
scenes.add(modelInteractionService.visualizeDelta(delta, task, result));
}
}
return new WrapperScene(scenes, displayNameKey);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTreeDeltasType in project midpoint by Evolveum.
the class ObjectTreeDeltas method toObjectTreeDeltasType.
public ObjectTreeDeltasType toObjectTreeDeltasType() throws SchemaException {
ObjectTreeDeltasType jaxb = new ObjectTreeDeltasType();
if (getFocusChange() != null) {
jaxb.setFocusPrimaryDelta(DeltaConvertor.toObjectDeltaType(getFocusChange()));
}
Set<Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>>> entries = (Set<Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>>>) getProjectionChangeMapEntries();
for (Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>> entry : entries) {
ProjectionObjectDeltaType projChange = new ProjectionObjectDeltaType();
projChange.setResourceShadowDiscriminator(entry.getKey().toResourceShadowDiscriminatorType());
projChange.setPrimaryDelta(DeltaConvertor.toObjectDeltaType(entry.getValue()));
jaxb.getProjectionPrimaryDelta().add(projChange);
}
return jaxb;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTreeDeltasType in project midpoint by Evolveum.
the class ObjectTreeDeltas method mergeDeltas.
public static ObjectTreeDeltasType mergeDeltas(ObjectTreeDeltasType deltaTree, ObjectDeltaType deltaToMerge, PrismContext prismContext) throws SchemaException {
if (deltaToMerge == null) {
return deltaTree;
}
ObjectTreeDeltasType deltaTreeToMerge = new ObjectTreeDeltasType();
deltaTreeToMerge.setFocusPrimaryDelta(deltaToMerge);
if (deltaTree == null) {
return deltaTreeToMerge;
}
ObjectTreeDeltas tree = fromObjectTreeDeltasType(deltaTree, prismContext);
ObjectTreeDeltas treeToMerge = fromObjectTreeDeltasType(deltaTreeToMerge, prismContext);
tree.merge(treeToMerge);
return tree.toObjectTreeDeltasType();
}
Aggregations