Search in sources :

Example 1 with ConnectorConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType 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 2 with ConnectorConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType in project midpoint by Evolveum.

the class TestSchemaSanity method testResourceDefinition.

@Test
public void testResourceDefinition() {
    System.out.println("===[ testResourceDefinition ]===");
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    // WHEN
    PrismObjectDefinition<ResourceType> resourceDefinition = schemaRegistry.findObjectDefinitionByElementName(new QName(SchemaConstantsGenerated.NS_COMMON, "resource"));
    assertNotNull("No resource definition", resourceDefinition);
    System.out.println("Resource definition:");
    System.out.println(resourceDefinition.debugDump());
    PrismObjectDefinition<ResourceType> resourceDefinitionByClass = schemaRegistry.findObjectDefinitionByCompileTimeClass(ResourceType.class);
    assertTrue("Different user def", resourceDefinition == resourceDefinitionByClass);
    assertEquals("Wrong compile-time class in resource definition", ResourceType.class, resourceDefinition.getCompileTimeClass());
    PrismAsserts.assertPropertyDefinition(resourceDefinition, ResourceType.F_NAME, PolyStringType.COMPLEX_TYPE, 0, 1);
    PrismAsserts.assertPropertyDefinition(resourceDefinition, ResourceType.F_DESCRIPTION, DOMUtil.XSD_STRING, 0, 1);
    assertFalse("Resource definition is marked as runtime", resourceDefinition.isRuntimeSchema());
    PrismContainerDefinition<ConnectorConfigurationType> connectorConfContainerDef = resourceDefinition.findContainerDefinition(ResourceType.F_CONNECTOR_CONFIGURATION);
    PrismAsserts.assertDefinition(connectorConfContainerDef, ResourceType.F_CONNECTOR_CONFIGURATION, ConnectorConfigurationType.COMPLEX_TYPE, 1, 1);
    assertTrue("<connectorConfiguration> is NOT dynamic", connectorConfContainerDef.isDynamic());
    //		assertFalse("<connectorConfiguration> is runtime", connectorConfContainerDef.isRuntimeSchema());
    assertEquals("Wrong compile-time class for <connectorConfiguration> in resource definition", ConnectorConfigurationType.class, connectorConfContainerDef.getCompileTimeClass());
    PrismContainerDefinition<XmlSchemaType> schemaContainerDef = resourceDefinition.findContainerDefinition(ResourceType.F_SCHEMA);
    PrismAsserts.assertDefinition(schemaContainerDef, ResourceType.F_SCHEMA, XmlSchemaType.COMPLEX_TYPE, 0, 1);
    assertFalse("Schema is runtime", schemaContainerDef.isRuntimeSchema());
    assertEquals("Wrong compile-time class for <schema> in resource definition", XmlSchemaType.class, schemaContainerDef.getCompileTimeClass());
    assertEquals("Unexpected number of definitions in <schema>", 3, schemaContainerDef.getDefinitions().size());
    PrismAsserts.assertPropertyDefinition(schemaContainerDef, XmlSchemaType.F_CACHING_METADATA, CachingMetadataType.COMPLEX_TYPE, 0, 1);
    PrismAsserts.assertPropertyDefinition(schemaContainerDef, XmlSchemaType.F_DEFINITION, SchemaDefinitionType.COMPLEX_TYPE, 0, 1);
    PrismPropertyDefinition definitionPropertyDef = schemaContainerDef.findPropertyDefinition(XmlSchemaType.F_DEFINITION);
    assertNotNull("Null <definition> definition", definitionPropertyDef);
//		assertFalse("schema/definition is NOT runtime", definitionPropertyDef.isRuntimeSchema());
}
Also used : ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PrismContext(com.evolveum.midpoint.prism.PrismContext) QName(javax.xml.namespace.QName) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) Test(org.testng.annotations.Test)

Example 3 with ConnectorConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType in project midpoint by Evolveum.

the class ConnectorTypeUtil method parseConnectorSchema.

/**
	 * Returns parsed connector schema
	 */
public static PrismSchema parseConnectorSchema(ConnectorType connectorType, PrismContext prismContext) throws SchemaException {
    Element connectorSchemaElement = ConnectorTypeUtil.getConnectorXsdSchema(connectorType);
    if (connectorSchemaElement == null) {
        return null;
    }
    PrismSchema connectorSchema = PrismSchemaImpl.parse(connectorSchemaElement, true, "schema for " + connectorType, prismContext);
    // Make sure that the config container definition has a correct compile-time class name
    QName configContainerQName = new QName(connectorType.getNamespace(), ResourceType.F_CONNECTOR_CONFIGURATION.getLocalPart());
    PrismContainerDefinition<ConnectorConfigurationType> configurationContainerDefintion = connectorSchema.findContainerDefinitionByElementName(configContainerQName);
    ((PrismContainerDefinitionImpl) configurationContainerDefintion).setCompileTimeClass(ConnectorConfigurationType.class);
    return connectorSchema;
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element)

Example 4 with ConnectorConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType in project midpoint by Evolveum.

the class TestUcfDummy method test020CreateConfiguredConnector.

@Test
public void test020CreateConfiguredConnector() throws Exception {
    final String TEST_NAME = "test020CreateConfiguredConnector";
    TestUtil.displayTestTile(TEST_NAME);
    cc = connectorFactory.createConnectorInstance(connectorType, ResourceTypeUtil.getResourceNamespace(resourceType), "test connector");
    assertNotNull("Failed to instantiate connector", cc);
    OperationResult result = new OperationResult(TestUcfDummy.class.getName() + "." + TEST_NAME);
    PrismContainerValue<ConnectorConfigurationType> configContainer = resourceType.getConnectorConfiguration().asPrismContainerValue();
    display("Configuration container", configContainer);
    // WHEN
    cc.configure(configContainer, result);
    // THEN
    result.computeStatus();
    TestUtil.assertSuccess(result);
}
Also used : ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 5 with ConnectorConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType in project midpoint by Evolveum.

the class TestUcfDummy method test000PrismContextSanity.

@Test
public void test000PrismContextSanity() throws Exception {
    final String TEST_NAME = "test000PrismContextSanity";
    TestUtil.displayTestTile(TEST_NAME);
    SchemaRegistry schemaRegistry = PrismTestUtil.getPrismContext().getSchemaRegistry();
    PrismSchema schemaIcfc = schemaRegistry.findSchemaByNamespace(SchemaConstants.NS_ICF_CONFIGURATION);
    assertNotNull("ICFC schema not found in the context (" + SchemaConstants.NS_ICF_CONFIGURATION + ")", schemaIcfc);
    PrismContainerDefinition<ConnectorConfigurationType> configurationPropertiesDef = schemaIcfc.findContainerDefinitionByElementName(SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_ELEMENT_QNAME);
    assertNotNull("icfc:configurationProperties not found in icfc schema (" + SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_ELEMENT_QNAME + ")", configurationPropertiesDef);
    PrismSchema schemaIcfs = schemaRegistry.findSchemaByNamespace(SchemaConstants.NS_ICF_SCHEMA);
    assertNotNull("ICFS schema not found in the context (" + SchemaConstants.NS_ICF_SCHEMA + ")", schemaIcfs);
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) Test(org.testng.annotations.Test)

Aggregations

ConnectorConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType)14 Test (org.testng.annotations.Test)7 PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)4 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)4 QName (javax.xml.namespace.QName)4 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)3 SystemException (com.evolveum.midpoint.util.exception.SystemException)3 Element (org.w3c.dom.Element)3 ConnectorInstance (com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance)2 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)2 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)2 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)2 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)2 ArrayList (java.util.ArrayList)2 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1