Search in sources :

Example 76 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class PageRequestRole method loadUser.

private void loadUser() {
    LOGGER.debug("Loading user and accounts.");
    OperationResult result = new OperationResult(OPERATION_LOAD_USER);
    try {
        String userOid = SecurityUtils.getPrincipalUser().getOid();
        Task task = createSimpleTask(OPERATION_LOAD_USER);
        user = WebModelServiceUtils.loadObject(UserType.class, userOid, null, (PageBase) getPage(), task, result);
        result.recordSuccessIfUnknown();
        result.recordSuccessIfUnknown();
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load accounts", ex);
        result.recordFatalError("Couldn't load accounts", ex);
    } finally {
        result.recomputeStatus();
    }
    if (!result.isSuccess() && !result.isHandledError()) {
        showResult(result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) SchemaException(com.evolveum.midpoint.util.exception.SchemaException)

Example 77 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class PageSelfDashboard method loadWorkItems.

private CallableResult<List<WorkItemDto>> loadWorkItems() {
    LOGGER.debug("Loading work items.");
    AccountCallableResult callableResult = new AccountCallableResult();
    List<WorkItemDto> list = new ArrayList<>();
    callableResult.setValue(list);
    if (!getWorkflowManager().isEnabled()) {
        return callableResult;
    }
    PrismObject<UserType> user = principalModel.getObject();
    if (user == null) {
        return callableResult;
    }
    Task task = createSimpleTask(OPERATION_LOAD_WORK_ITEMS);
    OperationResult result = task.getResult();
    callableResult.setResult(result);
    try {
        ObjectQuery query = QueryBuilder.queryFor(WorkItemType.class, getPrismContext()).item(WorkItemType.F_ASSIGNEE_REF).ref(user.getOid()).desc(F_CREATE_TIMESTAMP).build();
        Collection<SelectorOptions<GetOperationOptions>> options = GetOperationOptions.resolveItemsNamed(new ItemPath(T_PARENT, WfContextType.F_OBJECT_REF), new ItemPath(T_PARENT, WfContextType.F_TARGET_REF));
        List<WorkItemType> workItems = getModelService().searchContainers(WorkItemType.class, query, options, task, result);
        for (WorkItemType workItem : workItems) {
            list.add(new WorkItemDto(workItem));
        }
    } catch (Exception e) {
        result.recordFatalError("Couldn't get list of work items.", e);
    }
    result.recordSuccessIfUnknown();
    result.recomputeStatus();
    LOGGER.debug("Finished work items loading.");
    return callableResult;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) WorkItemDto(com.evolveum.midpoint.web.page.admin.workflow.dto.WorkItemDto) AccountCallableResult(com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 78 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class PageAssignmentShoppingKart method getRoleCatalogOid.

private String getRoleCatalogOid() {
    Task task = getPageBase().createAnonymousTask(OPERATION_LOAD_ROLE_CATALOG_REFERENCE);
    OperationResult result = task.getResult();
    SystemConfigurationType config;
    try {
        config = getPageBase().getModelInteractionService().getSystemConfiguration(result);
    } catch (ObjectNotFoundException | SchemaException e) {
        LOGGER.error("Error getting system configuration: {}", e.getMessage(), e);
        return null;
    }
    if (config != null && config.getRoleManagement() != null && config.getRoleManagement().getRoleCatalogRef() != null) {
        return config.getRoleManagement().getRoleCatalogRef().getOid();
    }
    return "";
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 79 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class ObjectWrapperTest method testEmptyPolyString.

@Test
public void testEmptyPolyString() throws Exception {
    PrismObject<UserType> user = prismContext.parseObject(new File("./src/test/resources/wrapper/user.xml"));
    Task task = taskManager.createTaskInstance("testEmptyPolyString");
    ObjectWrapperFactory owf = new ObjectWrapperFactory(null);
    ObjectWrapper<UserType> wrapper = owf.createObjectWrapper(null, null, user, ContainerStatus.MODIFYING, task);
    //simulate change on honorific prefix
    ContainerWrapper containerWrapper = null;
    for (ContainerWrapper container : wrapper.getContainers()) {
        if (container.isMain()) {
            containerWrapper = container;
            break;
        }
    }
    PropertyWrapper propertyWrapper = (PropertyWrapper) containerWrapper.findPropertyWrapper(UserType.F_HONORIFIC_SUFFIX);
    ValueWrapper valueWrapper = (ValueWrapper) propertyWrapper.getValues().get(0);
    PolyString value = (PolyString) ((PrismPropertyValue) valueWrapper.getValue()).getValue();
    Field orig = PolyString.class.getDeclaredField("orig");
    orig.setAccessible(true);
    orig.set(value, null);
    orig.setAccessible(false);
    ObjectDelta delta = wrapper.getObjectDelta();
    AssertJUnit.assertNotNull(delta);
}
Also used : Field(java.lang.reflect.Field) Task(com.evolveum.midpoint.task.api.Task) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) File(java.io.File) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 80 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class TestIntegrationObjectWrapperFactory method test102CreateWrapperUserEmpty.

@Test
public void test102CreateWrapperUserEmpty() throws Exception {
    final String TEST_NAME = "test102CreateWrapperUserEmpty";
    TestUtil.displayTestTile(TEST_NAME);
    PrismObject<UserType> user = getUser(USER_EMPTY_OID);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    Task task = taskManager.createTaskInstance(TEST_NAME);
    ObjectWrapperFactory factory = new ObjectWrapperFactory(getServiceLocator());
    ObjectWrapper<UserType> objectWrapper = factory.createObjectWrapper("user display name", "user description", user, ContainerStatus.MODIFYING, task);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    IntegrationTestTools.display("Wrapper after", objectWrapper);
    WrapperTestUtil.assertWrapper(objectWrapper, "user display name", "user description", user, ContainerStatus.MODIFYING);
    assertEquals("wrong number of containers in " + objectWrapper, 11, objectWrapper.getContainers().size());
    ContainerWrapper<UserType> mainContainerWrapper = objectWrapper.findContainerWrapper(null);
    WrapperTestUtil.assertWrapper(mainContainerWrapper, "prismContainer.mainPanelDisplayName", (ItemPath) null, user, ContainerStatus.MODIFYING);
    WrapperTestUtil.assertPropertyWrapper(mainContainerWrapper, UserType.F_NAME, PrismTestUtil.createPolyString(USER_EMPTY_USERNAME));
    WrapperTestUtil.assertPropertyWrapper(mainContainerWrapper, UserType.F_TIMEZONE, null);
    // Not sure about this
    //		ContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(UserType.F_ACTIVATION));
    //		assertNull("Unexpected activation "+activationContainerWrapper, activationContainerWrapper);
    assertEquals("Wrong main container wrapper readOnly", Boolean.FALSE, (Boolean) mainContainerWrapper.isReadonly());
    assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_NAME, true);
    // emphasized
    assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_GIVEN_NAME, true);
    // emphasized
    assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_FULL_NAME, true);
    // empty
    assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_ADDITIONAL_NAME, false);
    // empty
    assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_LOCALITY, false);
    // WHEN
    objectWrapper.setShowEmpty(true);
    // THEN
    assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_NAME, true);
    // emphasized
    assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_GIVEN_NAME, true);
    // emphasized
    assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_FULL_NAME, true);
    // empty
    assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_ADDITIONAL_NAME, true);
    // empty		
    assertItemWrapperFullConrol(mainContainerWrapper, UserType.F_LOCALITY, true);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ObjectWrapperFactory(com.evolveum.midpoint.web.component.prism.ObjectWrapperFactory) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Aggregations

Task (com.evolveum.midpoint.task.api.Task)4943 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4698 Test (org.testng.annotations.Test)3991 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)599 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)542 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)464 PrismObject (com.evolveum.midpoint.prism.PrismObject)327 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)323 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)290 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)282 ArrayList (java.util.ArrayList)249 QName (javax.xml.namespace.QName)208 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)199 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)193 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)175 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)159 AbstractConfiguredModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)140 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)123 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)108 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)108