Search in sources :

Example 11 with ModelContext

use of com.evolveum.midpoint.model.api.context.ModelContext in project midpoint by Evolveum.

the class PageFocusDetails method finishPreviewProcessing.

private void finishPreviewProcessing(AjaxRequestTarget target, OperationResult result) {
    showResult(result);
    target.add(getFeedbackPanel());
    Map<PrismObject<F>, ModelContext<? extends ObjectType>> modelContextMap = new LinkedHashMap<>();
    collectObjectsForPreview(modelContextMap);
    DetailsFragment detailsFragment = createDetailsFragment();
    replace(detailsFragment);
    target.add(detailsFragment);
    navigateToNext(new PageFocusPreviewChanges(modelContextMap));
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) DetailsFragment(com.evolveum.midpoint.gui.impl.page.admin.DetailsFragment) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with ModelContext

use of com.evolveum.midpoint.model.api.context.ModelContext in project midpoint by Evolveum.

the class TaskOperationPanel method initLayout.

protected void initLayout() {
    final LensContextType lensContextType = getLensContextType();
    LoadableModel<ModelOperationStatusDto> operationStatusModel = null;
    if (lensContextType != null) {
        operationStatusModel = new LoadableModel<ModelOperationStatusDto>() {

            @Override
            protected ModelOperationStatusDto load() {
                Task task = getPageBase().createSimpleTask(OPERATION_LOAD_SCENE_DTO);
                OperationResult result = task.getResult();
                ModelContext ctx;
                try {
                    ctx = ModelContextUtil.unwrapModelContext(lensContextType, getPageBase().getModelInteractionService(), task, result);
                } catch (ObjectNotFoundException e) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Unexpected error, cannot get real value for model context", e, e.getMessage());
                    return null;
                }
                return new ModelOperationStatusDto(ctx, getPageBase().getModelInteractionService(), task, result);
            }
        };
    }
    ModelOperationStatusPanel panel = new ModelOperationStatusPanel(ID_MODEL_OPERATION_STATUS_PANEL, operationStatusModel);
    panel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return lensContextType != null;
        }
    });
    add(panel);
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) Task(com.evolveum.midpoint.task.api.Task) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ModelOperationStatusDto(com.evolveum.midpoint.web.component.model.operationStatus.ModelOperationStatusDto) LensContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.LensContextType) ModelOperationStatusPanel(com.evolveum.midpoint.web.component.model.operationStatus.ModelOperationStatusPanel)

Example 13 with ModelContext

use of com.evolveum.midpoint.model.api.context.ModelContext 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)

Example 14 with ModelContext

use of com.evolveum.midpoint.model.api.context.ModelContext in project midpoint by Evolveum.

the class TestUserChangeApprovalLegacy method test040UserModifyPasswordChangeBlocked.

@Test(enabled = true)
public void test040UserModifyPasswordChangeBlocked() throws Exception {
    TestUtil.displayTestTile(this, "test040UserModifyPasswordChangeBlocked");
    login(userAdministrator);
    PrismObject<UserType> jack = getUser(USER_JACK_OID);
    final ProtectedStringType originalPasswordValue = jack.asObjectable().getCredentials().getPassword().getValue();
    LOGGER.trace("password before test = " + originalPasswordValue);
    executeTest("test040UserModifyPasswordChangeBlocked", USER_JACK_OID, new TestDetails() {

        @Override
        int subtaskCount() {
            return 1;
        }

        @Override
        boolean immediate() {
            return false;
        }

        @Override
        boolean checkObjectOnSubtasks() {
            return true;
        }

        @Override
        public LensContext createModelContext(Task task, OperationResult result) throws Exception {
            LensContext<UserType> context = createUserLensContext();
            fillContextWithUser(context, USER_JACK_OID, result);
            encryptAndAddFocusModificationToContext(context, REQ_USER_JACK_MODIFY_CHANGE_PASSWORD);
            //context.setOptions(ModelExecuteOptions.createNoCrypt());
            return context;
        }

        @Override
        public void assertsAfterClockworkRun(Task rootTask, List<Task> wfSubtasks, OperationResult result) throws Exception {
            ModelContext taskModelContext = wfTaskUtil.getModelContext(rootTask, result);
            assertEquals("There are modifications left in primary focus delta", 0, taskModelContext.getFocusContext().getPrimaryDelta().getModifications().size());
        }

        @Override
        void assertsRootTaskFinishes(Task task, List<Task> subtasks, OperationResult result) throws Exception {
            PrismObject<UserType> jack = getUser(USER_JACK_OID);
            ProtectedStringType afterTestPasswordValue = jack.asObjectable().getCredentials().getPassword().getValue();
            LOGGER.trace("password after test = " + afterTestPasswordValue);
            //assertNotNull("password was not set", afterTestPasswordValue.getEncryptedData());
            assertTrue("password was changed", originalPasswordValue.getEncryptedDataType().equals(afterTestPasswordValue.getEncryptedDataType()));
            checkDummyTransportMessages("simpleUserNotifier", 0);
        // we don't check for modifyApproverRef because in this test the value was not changed (no change was executed)
        }

        @Override
        boolean decideOnApproval(String executionId) throws Exception {
            login(getUser(USER_ADMINISTRATOR_OID));
            return false;
        }
    });
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) JAXBException(javax.xml.bind.JAXBException) ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) Test(org.testng.annotations.Test)

Example 15 with ModelContext

use of com.evolveum.midpoint.model.api.context.ModelContext in project midpoint by Evolveum.

the class TestUserChangeApprovalLegacy method test095UserModifyModifyResourceAssignmentConstruction.

/**
     * User modification: modifying attribute of single security-sensitive resource assignment.
     *
     * User primary delta:
     *  ObjectDelta<UserType>(UserType:377205db-33d1-47e5-bf96-bbe2a7d1222e,MODIFY):
     *  assignment/[1]/construction/attribute
     *  ADD: ResourceAttributeDefinitionType(ref=ItemPathType{itemPath=lastname}...)
     *  DELETE: ResourceAttributeDefinitionType(ref=ItemPathType{itemPath=lastname}...)
     *
     */
@Test(enabled = true)
public void test095UserModifyModifyResourceAssignmentConstruction() throws Exception {
    final String TEST_NAME = "test095UserModifyModifyResourceAssignmentConstruction";
    TestUtil.displayTestTile(this, TEST_NAME);
    login(userAdministrator);
    executeTest(TEST_NAME, USER_JACK_OID, new TestDetails() {

        @Override
        int subtaskCount() {
            return 1;
        }

        @Override
        boolean immediate() {
            return false;
        }

        @Override
        boolean checkObjectOnSubtasks() {
            return true;
        }

        @Override
        boolean removeAssignmentsBeforeTest() {
            return false;
        }

        @Override
        public LensContext createModelContext(Task task, OperationResult result) throws Exception {
            LensContext<UserType> context = createUserLensContext();
            fillContextWithUser(context, USER_JACK_OID, result);
            UserType jack = context.getFocusContext().getObjectOld().asObjectable();
            modifyAssignmentConstruction(context, jack, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, "water", true);
            return context;
        }

        @Override
        public void assertsAfterClockworkRun(Task rootTask, List<Task> wfSubtasks, OperationResult result) throws Exception {
            ModelContext taskModelContext = wfTaskUtil.getModelContext(rootTask, result);
            assertEquals("There are modifications left in primary focus delta", 0, taskModelContext.getFocusContext().getPrimaryDelta().getModifications().size());
            UserType jack = getUser(USER_JACK_OID).asObjectable();
            checkNoAssignmentConstruction(jack, "drink");
        }

        @Override
        void assertsRootTaskFinishes(Task task, List<Task> subtasks, OperationResult result) throws Exception {
            assertAssignedResource(USER_JACK_OID, RESOURCE_DUMMY_OID, task, result);
            UserType jack = getUser(USER_JACK_OID).asObjectable();
            checkAssignmentConstruction(jack, "drink", "water");
            checkDummyTransportMessages("simpleUserNotifier", 1);
            //checkWorkItemAuditRecords(createResultMap(ROLE_R1_OID, WorkflowResult.APPROVED));
            checkUserApprovers(USER_JACK_OID, Arrays.asList(DUMMYBOSS_OID), result);
        }

        @Override
        boolean decideOnApproval(String executionId) throws Exception {
            login(getUser(DUMMYBOSS_OID));
            return true;
        }
    });
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) JAXBException(javax.xml.bind.JAXBException) Test(org.testng.annotations.Test)

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