Search in sources :

Example 6 with ItemStatus

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

the class TestIntegrationObjectWrapperFactory method test800EditSchemaJackPropReadAllModifySomeUser.

/**
 * MID-3126
 */
@Test
public void test800EditSchemaJackPropReadAllModifySomeUser() throws Exception {
    given();
    cleanupAutzTest(USER_JACK_OID);
    assignRole(USER_JACK_OID, ROLE_PROP_READ_ALL_MODIFY_SOME_USER_OID);
    login(USER_JACK_USERNAME);
    PrismObject<UserType> user = getUser(USER_JACK_OID);
    display("user before", user);
    when();
    PrismObjectWrapper<UserType> objectWrapper = createObjectWrapper(getTestTask(), user, ItemStatus.NOT_CHANGED);
    then();
    displayDumpable("Wrapper after", objectWrapper);
    assertEquals("Wrong object wrapper readOnly", Boolean.FALSE, (Boolean) objectWrapper.isReadOnly());
    PrismContainerValueWrapper<UserType> mainContainerValueWrapper = objectWrapper.getValue();
    ItemStatus objectStatus = objectWrapper.getStatus();
    PrismPropertyWrapper<PolyString> nameWrapper = mainContainerValueWrapper.findProperty(UserType.F_NAME);
    // Is this OK?
    assertEquals("Wrong name readOnly", Boolean.TRUE, (Boolean) nameWrapper.isReadOnly());
    assertEquals("Wrong name visible", Boolean.TRUE, (Boolean) nameWrapper.isVisible(mainContainerValueWrapper, null));
    assertEquals("Wrong name definition.canRead", Boolean.TRUE, (Boolean) nameWrapper.canRead());
    assertEquals("Wrong name definition.canAdd", Boolean.FALSE, (Boolean) nameWrapper.canAdd());
    assertEquals("Wrong name definition.canModify", Boolean.FALSE, (Boolean) nameWrapper.canModify());
    PrismPropertyWrapper<PolyString> givenNameWrapper = mainContainerValueWrapper.findProperty(UserType.F_GIVEN_NAME);
    // Is this OK?
    assertEquals("Wrong givenName readOnly", Boolean.TRUE, (Boolean) givenNameWrapper.isReadOnly());
    assertEquals("Wrong givenName visible", Boolean.TRUE, (Boolean) givenNameWrapper.isVisible(mainContainerValueWrapper, null));
    assertEquals("Wrong givenName definition.canRead", Boolean.TRUE, (Boolean) givenNameWrapper.canRead());
    assertEquals("Wrong givenName definition.canAdd", Boolean.FALSE, (Boolean) givenNameWrapper.canAdd());
    assertEquals("Wrong givenName definition.canModify", Boolean.FALSE, (Boolean) givenNameWrapper.canModify());
    PrismPropertyWrapper<PolyString> fullNameWrapper = mainContainerValueWrapper.findProperty(UserType.F_FULL_NAME);
    assertEquals("Wrong fullName readOnly", Boolean.FALSE, (Boolean) fullNameWrapper.isReadOnly());
    assertEquals("Wrong fullName visible", Boolean.TRUE, (Boolean) fullNameWrapper.isVisible(mainContainerValueWrapper, null));
    assertEquals("Wrong fullName definition.canRead", Boolean.TRUE, (Boolean) fullNameWrapper.canRead());
    assertEquals("Wrong fullName definition.canAdd", Boolean.FALSE, (Boolean) fullNameWrapper.canAdd());
    assertEquals("Wrong fullName definition.canModify", Boolean.TRUE, (Boolean) fullNameWrapper.canModify());
    PrismPropertyWrapper<String> additionalNameWrapper = mainContainerValueWrapper.findProperty(UserType.F_ADDITIONAL_NAME);
    // Is this OK?
    assertEquals("Wrong additionalName readOnly", Boolean.TRUE, (Boolean) additionalNameWrapper.isReadOnly());
    // not visible, because it is empty
    assertEquals("Wrong additionalName visible", Boolean.FALSE, (Boolean) additionalNameWrapper.isVisible(mainContainerValueWrapper, null));
    assertEquals("Wrong additionalName definition.canRead", Boolean.TRUE, (Boolean) additionalNameWrapper.canRead());
    assertEquals("Wrong additionalName definition.canAdd", Boolean.FALSE, (Boolean) additionalNameWrapper.canAdd());
    assertEquals("Wrong additionalName definition.canModify", Boolean.FALSE, (Boolean) additionalNameWrapper.canModify());
    PrismPropertyWrapper<String> localityNameWrapper = mainContainerValueWrapper.findProperty(UserType.F_LOCALITY);
    assertEquals("Wrong locality readOnly", Boolean.TRUE, (Boolean) localityNameWrapper.isReadOnly());
    assertEquals("Wrong locality visible", Boolean.TRUE, (Boolean) localityNameWrapper.isVisible(mainContainerValueWrapper, null));
    assertEquals("Wrong locality definition.canRead", Boolean.TRUE, (Boolean) localityNameWrapper.canRead());
    assertEquals("Wrong locality definition.canAdd", Boolean.FALSE, (Boolean) localityNameWrapper.canAdd());
    assertEquals("Wrong locality definition.canModify", Boolean.FALSE, (Boolean) localityNameWrapper.canModify());
    when();
    mainContainerValueWrapper.setShowEmpty(true);
    then();
    additionalNameWrapper = mainContainerValueWrapper.findProperty(UserType.F_ADDITIONAL_NAME);
    // visible, because show empty
    assertEquals("Wrong additionalName visible", Boolean.TRUE, (Boolean) additionalNameWrapper.isVisible(mainContainerValueWrapper, null));
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with ItemStatus

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

the class ConfigurationStep method createConfigContainerWrappers.

// @NotNull
private PrismContainerWrapper<ConnectorConfigurationType> createConfigContainerWrappers() throws SchemaException {
    PrismObject<ResourceType> resource = resourceModelNoFetch.getObject();
    PrismContainer<ConnectorConfigurationType> configuration = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    if (parentPage.isNewResource()) {
        return null;
    }
    ItemStatus configurationStatus = ItemStatus.NOT_CHANGED;
    if (configuration == null) {
        PrismObject<ConnectorType> connector = ResourceTypeUtil.getConnectorIfPresent(resource);
        if (connector == null) {
            throw new IllegalStateException("No resolved connector object in resource object");
        }
        ConnectorType connectorType = connector.asObjectable();
        PrismSchema schema;
        try {
            schema = ConnectorTypeUtil.parseConnectorSchema(connectorType, parentPage.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);
        configuration = definitionFixed.instantiate();
        configurationStatus = ItemStatus.ADDED;
    }
    Task task = getPageBase().createSimpleTask(OPERATION_CREATE_CONFIGURATION_WRAPPERS);
    WrapperContext ctx = new WrapperContext(task, getResult());
    ctx.setReadOnly(parentPage.isReadOnly());
    ctx.setShowEmpty(ItemStatus.ADDED == configurationStatus);
    return getPageBase().createItemWrapper(configuration, configurationStatus, ctx);
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) 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 8 with ItemStatus

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

the class PrismObjectWrapperFactoryImpl method createValueWrapper.

@Override
public PrismContainerValueWrapper<O> createValueWrapper(PrismContainerWrapper<O> parent, PrismContainerValue<O> value, ValueStatus status, WrapperContext context) throws SchemaException {
    PrismContainerValueWrapper<O> objectValueWrapper = super.createValueWrapper(parent, value, status, context);
    if (CollectionUtils.isEmpty(context.getVirtualContainers())) {
        return objectValueWrapper;
    }
    for (VirtualContainersSpecificationType virtualContainer : context.getVirtualContainers()) {
        if (virtualContainer.getPath() != null) {
            continue;
        }
        MutableComplexTypeDefinition mCtd = getPrismContext().definitionFactory().createComplexTypeDefinition(VIRTUAL_CONTAINER_COMPLEX_TYPE);
        DisplayType display = virtualContainer.getDisplay();
        // TODO: support full polystring -> translations could be defined directly there.
        if (display == null || display.getLabel() == null) {
            mCtd.setDisplayName("N/A");
        } else {
            mCtd.setDisplayName(WebComponentUtil.getOrigStringFromPoly(display.getLabel()));
            mCtd.setHelp(WebComponentUtil.getOrigStringFromPoly(display.getHelp()));
        }
        mCtd.setRuntimeSchema(true);
        MutablePrismContainerDefinition<?> def = getPrismContext().definitionFactory().createContainerDefinition(VIRTUAL_CONTAINER, mCtd);
        def.setMaxOccurs(1);
        if (display != null && display.getLabel() != null) {
            def.setDisplayName(WebComponentUtil.getOrigStringFromPoly(display.getLabel()));
        }
        def.setDynamic(true);
        def.setRuntimeSchema(true);
        ItemWrapperFactory<?, ?, ?> factory = getRegistry().findWrapperFactory(def, null);
        if (factory == null) {
            LOGGER.warn("Cannot find factory for {}. Skipping wrapper creation.", def);
            continue;
        }
        WrapperContext ctx = context.clone();
        ctx.setVirtualItemSpecification(virtualContainer.getItem());
        PrismContainer<?> virtualPrismContainer = def.instantiate();
        ItemStatus virtualContainerStatus = context.getObjectStatus() != null ? context.getObjectStatus() : ItemStatus.NOT_CHANGED;
        ItemWrapper<?, ?> iw = factory.createWrapper(objectValueWrapper, virtualPrismContainer, virtualContainerStatus, ctx);
        if (iw == null) {
            continue;
        }
        if (iw instanceof PrismContainerWrapper) {
            PrismContainerWrapper<?> cw = (PrismContainerWrapper<?>) iw;
            cw.setIdentifier(virtualContainer.getIdentifier());
            cw.setVirtual(true);
            if (virtualContainer.isExpanded() != null) {
                cw.getValues().forEach(vw -> vw.setExpanded(virtualContainer.isExpanded()));
            }
        }
        iw.setVisibleOverwrite(virtualContainer.getVisibility());
        objectValueWrapper.addItem(iw);
    }
    return objectValueWrapper;
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)

Example 9 with ItemStatus

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

the class ItemWrapperFactoryImpl method determineReadOnly.

private boolean determineReadOnly(IW itemWrapper, WrapperContext context) {
    Boolean readOnly = context.getReadOnly();
    if (readOnly != null) {
        LOGGER.trace("Setting {} as readonly because context said so.", itemWrapper);
        return readOnly;
    }
    ItemStatus objectStatus = context.getObjectStatus();
    if (ItemStatus.NOT_CHANGED == objectStatus) {
        if (!itemWrapper.canModify()) {
            LOGGER.trace("Setting {} as readonly because authZ said so.", itemWrapper);
            return true;
        }
    }
    return false;
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus)

Example 10 with ItemStatus

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

the class ItemWrapperFactoryImpl method createWrapper.

@SuppressWarnings("unchecked")
@Override
public IW createWrapper(PrismContainerValueWrapper<?> parent, ItemDefinition<?> def, WrapperContext context) throws SchemaException {
    ItemName name = def.getItemName();
    I childItem = (I) parent.getNewValue().findItem(name);
    ItemStatus status = getStatus(childItem);
    if (skipCreateWrapper(def, status, context, childItem == null || CollectionUtils.isEmpty(childItem.getValues()))) {
        LOGGER.trace("Skipping creating wrapper for non-existent item. It is not supported for {}", def);
        return null;
    }
    if (childItem == null) {
        childItem = (I) parent.getNewValue().findOrCreateItem(name);
    }
    return createWrapper(parent, childItem, status, context);
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) ItemName(com.evolveum.midpoint.prism.path.ItemName)

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