Search in sources :

Example 1 with ContainerWrapperFactory

use of com.evolveum.midpoint.web.component.prism.ContainerWrapperFactory in project midpoint by Evolveum.

the class ConfigurationStep method createConfigContainerWrappers.

@NotNull
private List<ContainerWrapper> createConfigContainerWrappers() throws SchemaException {
    PrismObject<ResourceType> resource = resourceModelNoFetch.getObject();
    PrismContainer<ConnectorConfigurationType> configuration = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    List<ContainerWrapper> containerWrappers = new ArrayList<>();
    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();
        ((PrismContainerDefinitionImpl) definitionFixed).setMaxOccurs(1);
        configuration = definitionFixed.instantiate();
    }
    List<PrismContainerDefinition> containerDefinitions = getSortedConfigContainerDefinitions(configuration);
    for (PrismContainerDefinition<?> containerDef : containerDefinitions) {
        ItemPath containerPath = new ItemPath(ResourceType.F_CONNECTOR_CONFIGURATION, containerDef.getName());
        PrismContainer container = configuration.findContainer(containerDef.getName());
        ContainerWrapperFactory cwf = new ContainerWrapperFactory(parentPage);
        ContainerWrapper containerWrapper;
        if (container != null) {
            containerWrapper = cwf.createContainerWrapper(container, ContainerStatus.MODIFYING, containerPath, parentPage.isReadOnly());
        } else {
            container = containerDef.instantiate();
            containerWrapper = cwf.createContainerWrapper(container, ContainerStatus.ADDING, containerPath, parentPage.isReadOnly());
        }
        containerWrappers.add(containerWrapper);
    }
    return containerWrappers;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) ArrayList(java.util.ArrayList) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ContainerWrapper(com.evolveum.midpoint.web.component.prism.ContainerWrapper) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ContainerWrapperFactory(com.evolveum.midpoint.web.component.prism.ContainerWrapperFactory) SystemException(com.evolveum.midpoint.util.exception.SystemException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 ContainerWrapper (com.evolveum.midpoint.web.component.prism.ContainerWrapper)1 ContainerWrapperFactory (com.evolveum.midpoint.web.component.prism.ContainerWrapperFactory)1 ConnectorConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType)1 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)1 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1