use of com.evolveum.midpoint.model.api.context.ModelContext in project midpoint by Evolveum.
the class TestGeneralChangeProcessor method executeTest.
private void executeTest(String testName, String oid, int subtaskCount, boolean immediate, boolean checkObjectOnSubtasks, ContextCreator contextCreator) throws Exception {
int workflowSubtaskCount = immediate ? subtaskCount - 1 : subtaskCount;
// GIVEN
prepareNotifications();
dummyAuditService.clear();
OperationResult result = new OperationResult("execution");
Task modelTask = taskManager.createTaskInstance(TestGeneralChangeProcessor.class.getName() + "." + testName);
display("Model task after creation", modelTask);
LensContext<UserType> context = (LensContext<UserType>) contextCreator.createModelContext(result);
modelTask.setOwner(repositoryService.getObject(UserType.class, USER_ADMINISTRATOR_OID, null, result));
display("Input context", context);
assertFocusModificationSanity(context);
// WHEN
HookOperationMode mode = clockwork.run(context, modelTask, result);
// THEN
contextCreator.assertsAfterClockworkRun(context, modelTask, result);
assertEquals("Wrong mode after clockwork.run in " + context.getState(), HookOperationMode.BACKGROUND, mode);
modelTask.refresh(result);
display("Model task after clockwork runs", modelTask);
Task rootTask = taskManager.getTask(wfTaskUtil.getRootTaskOid(modelTask), result);
display("Workflow root task created by clockwork run", rootTask);
assertTrue("Workflow root task is not persistent", rootTask.isPersistent());
assertEquals("Invalid current handler", ModelOperationTaskHandler.MODEL_OPERATION_TASK_URI, rootTask.getHandlerUri());
ModelContext taskModelContext = immediate ? null : wfTaskUtil.getModelContext(rootTask, result);
assertNotNull("Model context is not present in root task", taskModelContext);
List<Task> subtasks = rootTask.listSubtasks(result);
assertEquals("Incorrect number of subtasks", subtaskCount, subtasks.size());
for (int subtaskIndex = 0; subtaskIndex < subtasks.size(); subtaskIndex++) {
Task subtask = subtasks.get(subtaskIndex);
// now check the workflow state
String pid = wfTaskUtil.getProcessId(subtask);
assertNotNull("Workflow process instance id not present in subtask " + subtask, pid);
/*
WfProcessInstanceType processInstance = null; //workflowServiceImpl.getProcessInstanceById(pid, false, true, result);
assertNotNull("Process instance information cannot be retrieved", processInstance);
assertEquals("Incorrect number of work items", 1, processInstance.getWorkItems().size());
String taskId = processInstance.getWorkItems().get(0).getWorkItemId();
//WorkItemNewType workItem = workflowServiceImpl.getWorkItemDetailsById(taskId, result);
WorkItemNewType workItem = null; // TODO
org.activiti.engine.task.Task t = activitiEngine.getTaskService().createTaskQuery().taskId(taskId).singleResult();
assertNotNull("activiti task not found", t);
String executionId = t.getExecutionId();
LOGGER.trace("Task id = " + taskId + ", execution id = " + executionId);
contextCreator.completeWorkItem(workItem, taskId, result);
*/
}
waitForTaskClose(rootTask, 60000);
contextCreator.assertsRootTaskFinishes(rootTask, result);
}
use of com.evolveum.midpoint.model.api.context.ModelContext in project midpoint by Evolveum.
the class WfPropagateTaskObjectReferenceTaskHandler method run.
//endregion
//region Body
@Override
public TaskRunResult run(Task task) {
TaskRunResult.TaskRunResultStatus status = TaskRunResult.TaskRunResultStatus.FINISHED;
OperationResult result = task.getResult().createSubresult(WfPropagateTaskObjectReferenceTaskHandler.class + ".run");
WfTask wfTask = wfTaskController.recreateWfTask(task);
LOGGER.trace("WfPropagateTaskObjectReferenceTaskHandler starting... job = {}", wfTask);
ModelContext modelContext;
try {
modelContext = wfTask.retrieveModelContext(result);
if (modelContext == null) {
throw new IllegalStateException("There's no model context in the task; job = " + wfTask);
}
} catch (SchemaException | ConfigurationException | ObjectNotFoundException | ExpressionEvaluationException e) {
return reportException("Couldn't retrieve model context from job " + wfTask, task, result, e);
} catch (CommunicationException e) {
return reportException("Couldn't retrieve model context from job " + wfTask, task, result, TaskRunResult.TaskRunResultStatus.TEMPORARY_ERROR, e);
}
String oid = ((LensContext) modelContext).getFocusContext().getOid();
if (oid == null) {
LOGGER.warn("No object OID in job " + wfTask);
} else {
Class typeClass = ((LensContext) modelContext).getFocusContext().getObjectTypeClass();
QName type = typeClass != null ? JAXBUtil.getTypeQName(typeClass) : null;
if (type == null) {
LOGGER.warn("Unknown type of object " + oid + " in task " + task);
} else {
ObjectReferenceType objectReferenceType = new ObjectReferenceType();
objectReferenceType.setType(type);
objectReferenceType.setOid(oid);
if (task.getObjectRef() == null) {
task.setObjectRef(objectReferenceType);
} else {
LOGGER.warn("object reference in task " + task + " is already set, although it shouldn't be");
}
List<WfTask> dependents;
try {
dependents = wfTask.listDependents(result);
dependents.add(wfTask.getParentJob(result));
} catch (SchemaException e) {
return reportException("Couldn't get dependents from job " + wfTask, task, result, e);
} catch (ObjectNotFoundException e) {
return reportException("Couldn't get dependents from job " + wfTask, task, result, e);
}
for (WfTask dependent : dependents) {
if (dependent.getTask().getObjectRef() == null) {
try {
dependent.getTask().setObjectRefImmediate(objectReferenceType, result);
} catch (ObjectNotFoundException e) {
// note we DO NOT return, because we want to set all references we can
reportException("Couldn't set object reference on job " + dependent, task, result, e);
} catch (SchemaException e) {
reportException("Couldn't set object reference on job " + dependent, task, result, e);
} catch (ObjectAlreadyExistsException e) {
reportException("Couldn't set object reference on job " + dependent, task, result, e);
}
} else {
LOGGER.warn("object reference in job " + dependent + " is already set, although it shouldn't be");
}
}
}
}
result.computeStatusIfUnknown();
TaskRunResult runResult = new TaskRunResult();
runResult.setRunResultStatus(status);
runResult.setOperationResult(task.getResult());
return runResult;
}
use of com.evolveum.midpoint.model.api.context.ModelContext in project midpoint by Evolveum.
the class PrimaryChangeProcessor method submitTask0.
// Child task0 - in modes 2, 3 we have to prepare first child that executes all changes that do not require approval
private WfTask submitTask0(ModelContext context, ObjectTreeDeltas changesWithoutApproval, WfTask rootWfTask, ExecutionMode executionMode, WfConfigurationType wfConfigurationType, OperationResult result) throws SchemaException, ObjectNotFoundException {
if (changesWithoutApproval != null && !changesWithoutApproval.isEmpty() && executionMode != ALL_AFTERWARDS) {
ModelContext task0context = contextCopyWithDeltasReplaced(context, changesWithoutApproval);
WfTaskCreationInstruction instruction0 = WfTaskCreationInstruction.createModelOnly(rootWfTask.getChangeProcessor(), task0context);
instruction0.setTaskName("Executing changes that do not require approval");
return wfTaskController.submitWfTask(instruction0, rootWfTask, wfConfigurationType, result);
} else {
return null;
}
}
use of com.evolveum.midpoint.model.api.context.ModelContext in project midpoint by Evolveum.
the class NotificationFunctionsImpl method getContentAsFormattedList.
public String getContentAsFormattedList(Event event, boolean showSynchronizationItems, boolean showAuxiliaryAttributes) {
List<ItemPath> hiddenPaths = new ArrayList<>();
if (!showSynchronizationItems) {
hiddenPaths.addAll(SYNCHRONIZATION_PATHS);
}
if (!showAuxiliaryAttributes) {
hiddenPaths.addAll(AUXILIARY_PATHS);
}
if (event instanceof ResourceObjectEvent) {
final ResourceObjectEvent resourceObjectEvent = (ResourceObjectEvent) event;
final ObjectDelta<ShadowType> shadowDelta = resourceObjectEvent.getShadowDelta();
if (shadowDelta == null) {
return "";
}
if (shadowDelta.isAdd()) {
return getResourceObjectAttributesAsFormattedList(shadowDelta.getObjectToAdd().asObjectable(), hiddenPaths, showAuxiliaryAttributes);
} else if (shadowDelta.isModify()) {
return getResourceObjectModifiedAttributesAsFormattedList(resourceObjectEvent, shadowDelta, hiddenPaths, showAuxiliaryAttributes);
} else {
return "";
}
} else if (event instanceof ModelEvent) {
final ModelEvent modelEvent = (ModelEvent) event;
ModelContext<FocusType> modelContext = (ModelContext) modelEvent.getModelContext();
ModelElementContext<FocusType> focusContext = modelContext.getFocusContext();
ObjectDelta<? extends FocusType> summarizedDelta;
try {
summarizedDelta = modelEvent.getSummarizedFocusDeltas();
} catch (SchemaException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Unable to determine the focus change; focus context = {}", e, focusContext.debugDump());
return ("(unable to determine the change because of schema exception: " + e.getMessage() + ")\n");
}
if (summarizedDelta.isAdd()) {
return textFormatter.formatObject(summarizedDelta.getObjectToAdd(), hiddenPaths, showAuxiliaryAttributes);
} else if (summarizedDelta.isModify()) {
return textFormatter.formatObjectModificationDelta(summarizedDelta, hiddenPaths, showAuxiliaryAttributes, focusContext.getObjectOld(), focusContext.getObjectNew());
} else {
return "";
}
} else {
return "";
}
}
use of com.evolveum.midpoint.model.api.context.ModelContext in project midpoint by Evolveum.
the class PageAdminObjectDetails method finishPreviewProcessing.
private void finishPreviewProcessing(AjaxRequestTarget target, OperationResult result) {
getMainPanel().setVisible(true);
getProgressPanel().hide();
getProgressPanel().hideAbortButton(target);
getProgressPanel().hideBackButton(target);
getProgressPanel().hideContinueEditingButton(target);
showResult(result);
target.add(getFeedbackPanel());
Map<PrismObject<O>, ModelContext<? extends ObjectType>> modelContextMap = new LinkedHashMap<>();
modelContextMap.put(getObjectWrapper().getObject(), getProgressPanel().getPreviewResult());
processAdditionalFocalObjectsForPreview(modelContextMap);
navigateToNext(new PagePreviewChanges(modelContextMap, getModelInteractionService()));
}
Aggregations