Search in sources :

Example 11 with LensContext

use of com.evolveum.midpoint.model.impl.lens.LensContext 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;
}
Also used : ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 12 with LensContext

use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.

the class MockClockworkHook method invoke.

/* (non-Javadoc)
	 * @see com.evolveum.midpoint.model.api.hooks.ChangeHook#invoke(com.evolveum.midpoint.model.api.context.ModelContext, com.evolveum.midpoint.task.api.Task, com.evolveum.midpoint.schema.result.OperationResult)
	 */
@Override
public HookOperationMode invoke(@NotNull ModelContext context, @NotNull Task task, @NotNull OperationResult result) {
    assertTrue("Unexpected INITIAL state of the context in the hook", context.getState() != ModelState.INITIAL);
    // OK to rely on implementation here. This is an implementation test.
    if (!(context instanceof LensContext)) {
        throw new IllegalArgumentException("WHOOPS! The context is of type " + context.getClass() + " which we haven't expected");
    }
    LensContext lensContext = (LensContext) context;
    if (record) {
        contexts.add(lensContext.clone());
    }
    if (asynchronous) {
        lastAsyncContext = lensContext;
        return HookOperationMode.BACKGROUND;
    }
    return HookOperationMode.FOREGROUND;
}
Also used : LensContext(com.evolveum.midpoint.model.impl.lens.LensContext)

Example 13 with LensContext

use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.

the class CheckingProgressListener method onProgressAchieved.

/* (non-Javadoc)
	 * @see com.evolveum.midpoint.model.api.ProgressListener#onProgressAchieved(com.evolveum.midpoint.model.api.context.ModelContext, com.evolveum.midpoint.model.api.ProgressInformation)
	 */
@Override
public void onProgressAchieved(ModelContext modelContext, ProgressInformation progressInformation) {
    LensContext<ObjectType> lensContext = (LensContext<ObjectType>) modelContext;
    lensContext.checkConsistence();
    for (LensProjectionContext projectionContext : lensContext.getProjectionContexts()) {
        // MID-3213
        assert projectionContext.getResourceShadowDiscriminator().getResourceOid() != null;
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext)

Example 14 with LensContext

use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.

the class NotificationChangeHook method emitPolicyRulesEvents.

private void emitPolicyRulesEvents(ModelContext<?> context, Task task, OperationResult result) {
    LensFocusContext<?> focusContext = (LensFocusContext<?>) context.getFocusContext();
    for (EvaluatedPolicyRule rule : focusContext.getPolicyRules()) {
        emitPolicyEventIfPresent(rule, context, task, result);
    }
    DeltaSetTriple<EvaluatedAssignmentImpl<?>> triple = ((LensContext<?>) context).getEvaluatedAssignmentTriple();
    if (triple != null) {
        for (EvaluatedAssignment<?> assignment : triple.getNonNegativeValues()) {
            for (EvaluatedPolicyRule rule : assignment.getAllTargetsPolicyRules()) {
                emitPolicyEventIfPresent(rule, context, task, result);
            }
        }
    }
}
Also used : EvaluatedPolicyRule(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule) EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.EvaluatedAssignmentImpl) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext)

Example 15 with LensContext

use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.

the class AbstractWfTestLegacy method executeTest.

protected void executeTest(String testName, String oid, TestDetails testDetails) throws Exception {
    // GIVEN
    prepareNotifications();
    dummyAuditService.clear();
    Task modelTask = taskManager.createTaskInstance(AbstractWfTestLegacy.class.getName() + "." + testName);
    OperationResult result = new OperationResult("execution");
    modelTask.setOwner(repositoryService.getObject(UserType.class, USER_ADMINISTRATOR_OID, null, result));
    if (oid != null && testDetails.removeAssignmentsBeforeTest()) {
        removeAllAssignments(oid, result);
    }
    LensContext<UserType> context = (LensContext<UserType>) testDetails.createModelContext(modelTask, result);
    display("Input context", context);
    assertFocusModificationSanity(context);
    // WHEN
    HookOperationMode mode = clockwork.run(context, modelTask, result);
    // THEN
    assertEquals("Unexpected state of the context", ModelState.PRIMARY, context.getState());
    assertEquals("Wrong mode after clockwork.run in " + context.getState(), HookOperationMode.BACKGROUND, mode);
    modelTask.refresh(result);
    String rootTaskOid = wfTaskUtil.getRootTaskOid(modelTask);
    assertNotNull("Root task OID is not set in model task", rootTaskOid);
    Task rootTask = taskManager.getTask(rootTaskOid, result);
    // trivial ;)
    assertTrue("Root task is not persistent", rootTask.isPersistent());
    if (!testDetails.approvedAutomatically()) {
        UriStack uriStack = rootTask.getOtherHandlersUriStack();
        if (!testDetails.immediate()) {
            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 taskModelContext = testDetails.immediate() ? null : wfTaskUtil.getModelContext(rootTask, result);
        if (!testDetails.immediate()) {
            assertNotNull("Model context is not present in root task", taskModelContext);
        } else {
            assertFalse("Model context is present in root task (execution mode = immediate)", wfTaskUtil.hasModelContext(rootTask));
        }
        List<Task> subtasks = rootTask.listSubtasks(result);
        assertEquals("Incorrect number of subtasks", testDetails.subtaskCount(), subtasks.size());
        Task task0 = extractTask0(subtasks, testDetails);
        testDetails.assertsAfterClockworkRun(rootTask, subtasks, result);
        if (testDetails.immediate()) {
            waitForTaskClose(task0, 20000);
            //TestUtil.assertSuccess(task0.getResult());            // todo enable this
            testDetails.assertsAfterImmediateExecutionFinished(rootTask, result);
        }
        for (int i = 0; i < subtasks.size(); i++) {
            Task subtask = subtasks.get(i);
            //assertEquals("Subtask #" + i + " is not recurring: " + subtask, TaskRecurrence.RECURRING, subtask.getRecurrenceStatus());
            //assertEquals("Incorrect execution status of subtask #" + i + ": " + subtask, TaskExecutionStatus.RUNNABLE, subtask.getExecutionStatus());
            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);
            //                WfProcessInstanceType processInstance = 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();
            //WorkItemDetailed workItemDetailed = wfDataAccessor.getWorkItemDetailsById(taskId, result);
            org.activiti.engine.task.Task t = activitiEngine.getTaskService().createTaskQuery().processInstanceId(pid).singleResult();
            assertNotNull("activiti task not found", t);
            String executionId = t.getExecutionId();
            LOGGER.trace("Execution id = {}", executionId);
            boolean approve = testDetails.decideOnApproval(executionId);
            workflowManager.completeWorkItem(t.getId(), approve, null, null, null, result);
            login(userAdministrator);
        }
    }
    waitForTaskClose(rootTask, 60000);
    List<Task> subtasks = rootTask.listSubtasks(result);
    extractTask0(subtasks, testDetails);
    //TestUtil.assertSuccess(rootTask.getResult());
    testDetails.assertsRootTaskFinishes(rootTask, subtasks, result);
    if (oid == null) {
        oid = testDetails.getObjectOid(rootTask, result);
    }
    assertNotNull("object oid is null after operation", oid);
    if (!oid.equals(DONT_CHECK)) {
        assertObjectInTaskTree(rootTask, oid, testDetails.checkObjectOnSubtasks(), result);
    }
    if (!testDetails.approvedAutomatically()) {
    // ZZZ temporarily disabled
    //            checkDummyTransportMessages("simpleWorkflowNotifier-Processes", workflowSubtaskCount * 2);
    //            checkDummyTransportMessages("simpleWorkflowNotifier-WorkItems", workflowSubtaskCount * 2);
    }
    notificationManager.setDisabled(true);
    // Check audit
    display("Audit", dummyAuditService);
    display("Output context", context);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) HookOperationMode(com.evolveum.midpoint.model.api.hooks.HookOperationMode) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)21 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 Task (com.evolveum.midpoint.task.api.Task)13 Test (org.testng.annotations.Test)9 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)8 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 JAXBException (javax.xml.bind.JAXBException)6 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)5 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)4 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)4 ModelProjectionContext (com.evolveum.midpoint.model.api.context.ModelProjectionContext)3 LensFocusContext (com.evolveum.midpoint.model.impl.lens.LensFocusContext)3 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 SynchronizationPolicyDecision (com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision)2 HookOperationMode (com.evolveum.midpoint.model.api.hooks.HookOperationMode)2 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)2 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2