Search in sources :

Example 11 with ItemStatus

use of com.evolveum.midpoint.gui.api.prism.ItemStatus in project midpoint by Evolveum.

the class ResourceDetailsModel method createConfigContainerWrappers.

private PrismContainerWrapper<ConnectorConfigurationType> createConfigContainerWrappers(OperationResult result) throws SchemaException {
    Task task = getModelServiceLocator().createSimpleTask(OPERATION_CREATE_CONFIGURATION_WRAPPERS);
    PrismObjectWrapper<ResourceType> resourceWrapper = getObjectWrapper();
    PrismContainerWrapper<ConnectorConfigurationType> configuration = resourceWrapper.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    PrismContainer<ConnectorConfigurationType> connectorConfigurationType = null;
    ItemStatus configurationStatus = ItemStatus.NOT_CHANGED;
    if (configuration == null || configuration.isEmpty()) {
        PrismReferenceWrapper<Referencable> connectorRef = resourceWrapper.findReference(ResourceType.F_CONNECTOR_REF);
        if (connectorRef == null || connectorRef.getValue() == null || connectorRef.getValue().getRealValue() == null) {
            return null;
        }
        PrismObject<ConnectorType> connector = WebModelServiceUtils.resolveReferenceNoFetch(connectorRef.getValue().getRealValue(), getPageBase(), task, result);
        if (connector == null) {
            return null;
        }
        ConnectorType connectorType = connector.asObjectable();
        PrismSchema schema;
        try {
            schema = ConnectorTypeUtil.parseConnectorSchema(connectorType, getPrismContext());
        } catch (SchemaException e) {
            throw new SystemException("Couldn't parse connector schema: " + e.getMessage(), e);
        }
        PrismContainerDefinition<ConnectorConfigurationType> definition = ConnectorTypeUtil.findConfigurationContainerDefinition(connectorType, schema);
        // Fixing (errorneously) set maxOccurs = unbounded. See MID-2317 and related issues.
        PrismContainerDefinition<ConnectorConfigurationType> definitionFixed = definition.clone();
        definitionFixed.toMutable().setMaxOccurs(1);
        connectorConfigurationType = definitionFixed.instantiate();
        configurationStatus = ItemStatus.ADDED;
        WrapperContext ctx = new WrapperContext(task, result);
        ctx.setShowEmpty(ItemStatus.ADDED == configurationStatus);
        configuration = getModelServiceLocator().createItemWrapper(connectorConfigurationType, configurationStatus, ctx);
    }
    return configuration;
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) Referencable(com.evolveum.midpoint.prism.Referencable) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 12 with ItemStatus

use of com.evolveum.midpoint.gui.api.prism.ItemStatus in project midpoint by Evolveum.

the class PageAdminObjectDetails method createObjectWrapper.

private PrismObjectWrapper<O> createObjectWrapper(PrismObject<O> object, boolean isReadonly, Task task, OperationResult result) {
    ItemStatus itemStatus = computeWrapperStatus();
    PrismObjectWrapperFactory<O> factory = getRegistry().getObjectWrapperFactory(object.getDefinition());
    WrapperContext context = new WrapperContext(task, result);
    context.setCreateIfEmpty(ItemStatus.ADDED == itemStatus);
    context.setDetailsPageTypeConfiguration(getDetailsPanelsConfiguration(object));
    // Boolean instead of boolean isReadonly
    if (isReadonly) {
        context.setReadOnly(isReadonly);
    }
    try {
        PrismObjectWrapper<O> wrapper = factory.createObjectWrapper(object, itemStatus, context);
        result.recordSuccess();
        return wrapper;
    } catch (Exception ex) {
        result.recordFatalError(getString("PageAdminObjectDetails.message.loadObjectWrapper.fatalError"), ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object", ex);
        showResult(result, false);
        throw new RestartResponseException(getRestartResponsePage());
    }
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) RestartResponseException(org.apache.wicket.RestartResponseException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AuthorizationException(com.evolveum.midpoint.util.exception.AuthorizationException) RestartResponseException(org.apache.wicket.RestartResponseException)

Example 13 with ItemStatus

use of com.evolveum.midpoint.gui.api.prism.ItemStatus in project midpoint by Evolveum.

the class TestIntegrationObjectWrapperFactory method test110CreateWrapperUserNewEmpty.

/**
 * Create wrapper for brand new empty user.
 */
@Test
public void test110CreateWrapperUserNewEmpty() throws Exception {
    PrismObject<UserType> user = getUserDefinition().instantiate();
    when();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    PrismObjectWrapperFactory<UserType> factory = getServiceLocator(task).findObjectWrapperFactory(user.getDefinition());
    WrapperContext context = new WrapperContext(task, result);
    context.setCreateIfEmpty(true);
    context.setShowEmpty(true);
    PrismObjectWrapper<UserType> objectWrapper = factory.createObjectWrapper(user, ItemStatus.ADDED, context);
    then();
    displayDumpable("Wrapper after", objectWrapper);
    WrapperTestUtil.assertWrapper(objectWrapper, getString("prismContainer.mainPanelDisplayName"), "user description", user, getUserDefinition().instantiate(), ItemStatus.ADDED);
    assertContainersPaths(objectWrapper, BASIC_USER_CONTAINERS_PATHS);
    assertEquals("wrong number of containers in " + objectWrapper, 1, objectWrapper.getValues().size());
    PrismContainerValueWrapper<UserType> mainContainerValueWrapper = objectWrapper.getValue();
    WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_NAME, null);
    WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_TIMEZONE, null);
    PrismContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainer(UserType.F_ACTIVATION);
    WrapperTestUtil.assertWrapper(activationContainerWrapper, getString("ActivationType.activation"), UserType.F_ACTIVATION, user, ItemStatus.ADDED);
    assertEquals("wrong number of containers in " + activationContainerWrapper, 1, activationContainerWrapper.getValues().size());
    PrismContainerValueWrapper<ActivationType> activationContainerValueWrapper = activationContainerWrapper.getValues().iterator().next();
    WrapperTestUtil.assertPropertyWrapperByName(activationContainerValueWrapper, ActivationType.F_ADMINISTRATIVE_STATUS, null);
    WrapperTestUtil.assertPropertyWrapperByName(activationContainerValueWrapper, ActivationType.F_LOCKOUT_STATUS, null);
    assertEquals("Wrong main container wrapper readOnly", Boolean.FALSE, (Boolean) objectWrapper.isReadOnly());
    ItemStatus objectStatus = objectWrapper.getStatus();
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_NAME, true);
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_GIVEN_NAME, true);
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_FULL_NAME, true);
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_ADDITIONAL_NAME, true);
    assertItemWrapperProcessing(mainContainerValueWrapper, extensionPath(PIRACY_WEAPON), null);
    assertItemWrapperProcessing(mainContainerValueWrapper, extensionPath(PIRACY_COLORS), ItemProcessing.AUTO);
    assertItemWrapperProcessing(mainContainerValueWrapper, extensionPath(PIRACY_SECRET), ItemProcessing.IGNORE);
    assertItemWrapperProcessing(mainContainerValueWrapper, extensionPath(PIRACY_RANT), ItemProcessing.MINIMAL);
    when();
    mainContainerValueWrapper.setShowEmpty(false);
    then();
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_NAME, true);
    // emphasized
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_GIVEN_NAME, true);
    // emphasized
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_FULL_NAME, true);
    // empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_ADDITIONAL_NAME, false);
    // empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_LOCALITY, false);
    ObjectDelta<UserType> objectDelta = objectWrapper.getObjectDelta();
    displayDumpable("Delta", objectDelta);
    assertTrue("non-add delta produced from wrapper: " + objectDelta, objectDelta.isAdd());
    PrismObject<UserType> objectToAdd = objectDelta.getObjectToAdd();
    assertTrue("non-empty object in add delta produced from wrapper: " + objectDelta, objectToAdd.isEmpty());
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with ItemStatus

use of com.evolveum.midpoint.gui.api.prism.ItemStatus in project midpoint by Evolveum.

the class TestIntegrationObjectWrapperFactory method test102CreateWrapperUserEmpty.

@Test
public void test102CreateWrapperUserEmpty() throws Exception {
    PrismObject<UserType> user = getUser(USER_EMPTY_OID);
    PrismObject<UserType> userOld = user.clone();
    when();
    Task task = createTask();
    OperationResult result = task.getResult();
    ModelServiceLocator modelServiceLocator = getServiceLocator(task);
    PrismObjectWrapperFactory<UserType> factory = modelServiceLocator.findObjectWrapperFactory(user.getDefinition());
    WrapperContext context = new WrapperContext(task, result);
    PrismObjectWrapper<UserType> objectWrapper = factory.createObjectWrapper(user, ItemStatus.NOT_CHANGED, context);
    then();
    displayDumpable("Wrapper after", objectWrapper);
    WrapperTestUtil.assertWrapper(objectWrapper, getString("prismContainer.mainPanelDisplayName"), "user description", user, userOld, ItemStatus.NOT_CHANGED);
    assertContainersPaths(objectWrapper, BASIC_USER_CONTAINERS_PATHS);
    WrapperTestUtil.assertWrapper(objectWrapper, getString("prismContainer.mainPanelDisplayName"), null, user, ItemStatus.NOT_CHANGED);
    assertEquals("wrong number of containers in " + objectWrapper, 1, objectWrapper.getValues().size());
    PrismContainerValueWrapper<UserType> mainContainerValueWrapper = objectWrapper.getValue();
    WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_NAME, PrismTestUtil.createPolyString(USER_EMPTY_USERNAME));
    WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_TIMEZONE, null);
    // Not sure about this
    // ContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainer(ItemPath.create(UserType.F_ACTIVATION));
    // assertNull("Unexpected activation "+activationContainerWrapper, activationContainerWrapper);
    assertEquals("Wrong main container wrapper readOnly", Boolean.FALSE, (Boolean) objectWrapper.isReadOnly());
    ItemStatus objectStatus = objectWrapper.getStatus();
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_NAME, true);
    // emphasized
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_GIVEN_NAME, true);
    // emphasized
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_FULL_NAME, true);
    // empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_ADDITIONAL_NAME, false);
    // empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_LOCALITY, false);
    when();
    mainContainerValueWrapper.setShowEmpty(true);
    then();
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_NAME, true);
    // emphasized
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_GIVEN_NAME, true);
    // emphasized
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_FULL_NAME, true);
    // empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_ADDITIONAL_NAME, true);
    // empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_LOCALITY, true);
    ObjectDelta<UserType> objectDelta = objectWrapper.getObjectDelta();
    displayDumpable("Delta", objectDelta);
    assertTrue("non-empty delta produced from wrapper: " + objectDelta, objectDelta.isEmpty());
}
Also used : WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) Task(com.evolveum.midpoint.task.api.Task) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ItemStatus (com.evolveum.midpoint.gui.api.prism.ItemStatus)14 WrapperContext (com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)9 Task (com.evolveum.midpoint.task.api.Task)9 AbstractInitializedGuiIntegrationTest (com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 Test (org.testng.annotations.Test)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 ModelServiceLocator (com.evolveum.midpoint.gui.api.util.ModelServiceLocator)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 ConnectorConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType)2 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)2 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)2 ItemWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper)1 PrismValueWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismValueWrapper)1 Referencable (com.evolveum.midpoint.prism.Referencable)1 ItemName (com.evolveum.midpoint.prism.path.ItemName)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)1