Search in sources :

Example 1 with PrismSchema

use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.

the class ObjectWrapperFactory method addResourceContainerWrapper.

private <O extends ObjectType> void addResourceContainerWrapper(List<ContainerWrapper<? extends Containerable>> containerWrappers, ObjectWrapper<O> oWrapper, PrismObject<O> object, PrismObject<ConnectorType> connector, OperationResult result) throws SchemaException {
    PrismContainer<ConnectorConfigurationType> container = object.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    ConnectorType connectorType = connector.asObjectable();
    PrismSchema schema = ConnectorTypeUtil.parseConnectorSchema(connectorType, connector.getPrismContext());
    PrismContainerDefinition<ConnectorConfigurationType> definition = ConnectorTypeUtil.findConfigurationContainerDefinition(connectorType, schema);
    // brutal hack - the definition has (errorneously) set maxOccurs =
    // unbounded. But there can be only one configuration container.
    // See MID-2317 and related issues
    PrismContainerDefinition<ConnectorConfigurationType> definitionFixed = definition.clone();
    ((PrismContainerDefinitionImpl) definitionFixed).setMaxOccurs(1);
    if (container == null) {
        container = definitionFixed.instantiate();
    } else {
        container.setDefinition(definitionFixed);
    }
    addContainerWrappers(containerWrappers, oWrapper, container, new ItemPath(ResourceType.F_CONNECTOR_CONFIGURATION), result);
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 2 with PrismSchema

use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.

the class ObjectWrapperFactory method addReportContainers.

private <O extends ObjectType> void addReportContainers(List<ContainerWrapper<? extends Containerable>> containers, ObjectWrapper<O> oWrapper, PrismObject<O> object, OperationResult result) throws SchemaException {
    PrismContainer container = object.findContainer(ReportType.F_CONFIGURATION);
    ContainerStatus status = container != null ? ContainerStatus.MODIFYING : ContainerStatus.ADDING;
    if (container == null) {
        PrismSchema schema = ReportTypeUtil.parseReportConfigurationSchema((PrismObject<ReportType>) object, object.getPrismContext());
        PrismContainerDefinition<?> definition = ReportTypeUtil.findReportConfigurationDefinition(schema);
        if (definition == null) {
            return;
        }
        container = definition.instantiate();
    }
    ContainerWrapperFactory cwf = new ContainerWrapperFactory(modelServiceLocator);
    ContainerWrapper wrapper = cwf.createContainerWrapper(oWrapper, container, status, new ItemPath(ReportType.F_CONFIGURATION));
    result.addSubresult(cwf.getResult());
    containers.add(wrapper);
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 3 with PrismSchema

use of com.evolveum.midpoint.prism.schema.PrismSchema 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)

Example 4 with PrismSchema

use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.

the class ReportTypeUtil method applyDefinition.

public static void applyDefinition(PrismObject<ReportType> report, PrismContext prismContext) throws SchemaException {
    PrismContainer<ReportConfigurationType> configuration = report.findContainer(ReportType.F_CONFIGURATION);
    if (configuration == null) {
        //nothing to apply definitions on
        return;
    }
    PrismContainer xmlSchema = report.findContainer(ReportType.F_CONFIGURATION_SCHEMA);
    Element xmlSchemaElement = ObjectTypeUtil.findXsdElement(xmlSchema);
    if (xmlSchemaElement == null) {
        //no schema definition available
        throw new SchemaException("Couldn't find schema for configuration in report type " + report + ".");
    }
    PrismSchema schema = ReportTypeUtil.parseReportConfigurationSchema(report, prismContext);
    PrismContainerDefinition<ReportConfigurationType> definition = ReportTypeUtil.findReportConfigurationDefinition(schema);
    if (definition == null) {
        //no definition found for container
        throw new SchemaException("Couldn't find definitions for report type " + report + ".");
    }
    configuration.applyDefinition(definition, true);
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Element(org.w3c.dom.Element) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) ReportConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportConfigurationType)

Example 5 with PrismSchema

use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.

the class TestPrismContext method testBasicSchemas.

@Test
public void testBasicSchemas() throws SchemaException, SAXException, IOException {
    System.out.println("===[ testBasicSchemas ]===");
    // WHEN
    PrismContext prismContext = constructInitializedPrismContext();
    // THEN
    assertNotNull("No prism context", prismContext);
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    assertNotNull("No schema registry in context", schemaRegistry);
    System.out.println("Schema registry:");
    System.out.println(schemaRegistry.debugDump());
    PrismSchema fooSchema = schemaRegistry.findSchemaByNamespace(NS_FOO);
    System.out.println("Foo schema:");
    System.out.println(fooSchema.debugDump());
    // Assert USER definition
    PrismObjectDefinition<UserType> userDefinition = fooSchema.findObjectDefinitionByElementName(new QName(NS_FOO, "user"));
    assertNotNull("No user definition", userDefinition);
    System.out.println("User definition:");
    System.out.println(userDefinition.debugDump());
    PrismObjectDefinition<UserType> userDefinitionByClass = schemaRegistry.findObjectDefinitionByCompileTimeClass(UserType.class);
    assertTrue("Different user def", userDefinition == userDefinitionByClass);
    assertUserDefinition(userDefinition);
    // Assert ACCOUNT definition
    PrismObjectDefinition<AccountType> accountDefinition = fooSchema.findObjectDefinitionByElementName(new QName(NS_FOO, "account"));
    assertNotNull("No account definition", accountDefinition);
    System.out.println("Account definition:");
    System.out.println(accountDefinition.debugDump());
    PrismObjectDefinition<AccountType> accountDefinitionByClass = schemaRegistry.findObjectDefinitionByCompileTimeClass(AccountType.class);
    assertTrue("Different user def", accountDefinition == accountDefinitionByClass);
    assertAccountDefinition(accountDefinition);
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) QName(javax.xml.namespace.QName) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) UserType(com.evolveum.midpoint.prism.foo.UserType) AccountType(com.evolveum.midpoint.prism.foo.AccountType) Test(org.testng.annotations.Test)

Aggregations

PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)44 Test (org.testng.annotations.Test)20 QName (javax.xml.namespace.QName)10 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)8 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)8 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)8 Element (org.w3c.dom.Element)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)7 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)6 Task (com.evolveum.midpoint.task.api.Task)6 ConnectorConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType)6 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 Document (org.w3c.dom.Document)4 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 PrismSchemaImpl (com.evolveum.midpoint.prism.schema.PrismSchemaImpl)3 SchemaRegistryImpl (com.evolveum.midpoint.prism.schema.SchemaRegistryImpl)3