Search in sources :

Example 6 with ModelContext

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);
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) Task(com.evolveum.midpoint.task.api.Task) HookOperationMode(com.evolveum.midpoint.model.api.hooks.HookOperationMode) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext)

Example 7 with ModelContext

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;
}
Also used : QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WfTask(com.evolveum.midpoint.wf.impl.tasks.WfTask) ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)

Example 8 with ModelContext

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;
    }
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) WfTaskCreationInstruction(com.evolveum.midpoint.wf.impl.tasks.WfTaskCreationInstruction)

Example 9 with ModelContext

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 "";
    }
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceObjectEvent(com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent) ModelElementContext(com.evolveum.midpoint.model.api.context.ModelElementContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ModelEvent(com.evolveum.midpoint.notifications.api.events.ModelEvent) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 10 with ModelContext

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()));
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) PrismObject(com.evolveum.midpoint.prism.PrismObject) PagePreviewChanges(com.evolveum.midpoint.web.component.prism.show.PagePreviewChanges)

Aggregations

ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)23 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)13 Task (com.evolveum.midpoint.task.api.Task)11 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)8 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)8 JAXBException (javax.xml.bind.JAXBException)6 Test (org.testng.annotations.Test)6 ModelInteractionService (com.evolveum.midpoint.model.api.ModelInteractionService)4 ModelService (com.evolveum.midpoint.model.api.ModelService)4 CommonException (com.evolveum.midpoint.util.exception.CommonException)4 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)4 HookOperationMode (com.evolveum.midpoint.model.api.hooks.HookOperationMode)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)3 ModelEvent (com.evolveum.midpoint.notifications.api.events.ModelEvent)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)2 HttpConnectionInformation (com.evolveum.midpoint.security.api.HttpConnectionInformation)2 SecurityContextManager (com.evolveum.midpoint.security.api.SecurityContextManager)2