Search in sources :

Example 26 with PrismSchema

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

the class TestUcfDummy method test002ConnectorSchema.

@Test
public void test002ConnectorSchema() throws Exception {
    final String TEST_NAME = "test002ConnectorSchema";
    TestUtil.displayTestTile(TEST_NAME);
    PrismSchema connectorSchema = connectorFactory.generateConnectorConfigurationSchema(connectorType);
    IntegrationTestTools.assertConnectorSchemaSanity(connectorSchema, "generated", true);
    assertEquals("Unexpected number of definitions", 3, connectorSchema.getDefinitions().size());
    Document xsdSchemaDom = connectorSchema.serializeToXsd();
    assertNotNull("No serialized connector schema", xsdSchemaDom);
    display("Serialized XSD connector schema", DOMUtil.serializeDOMToString(xsdSchemaDom));
    // Try to re-parse
    PrismSchema reparsedConnectorSchema = PrismSchemaImpl.parse(DOMUtil.getFirstChildElement(xsdSchemaDom), true, "schema fetched from " + cc, PrismTestUtil.getPrismContext());
    IntegrationTestTools.assertConnectorSchemaSanity(reparsedConnectorSchema, "re-parsed", true);
    // TODO: 3 definitions would be cleaner. But we can live with this
    assertEquals("Unexpected number of definitions in re-parsed schema", 6, reparsedConnectorSchema.getDefinitions().size());
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) Document(org.w3c.dom.Document) Test(org.testng.annotations.Test)

Example 27 with PrismSchema

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

the class TestUcfDummyMulti 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)

Example 28 with PrismSchema

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

the class ConnectorFactoryConnIdImpl method generateConnectorConfigurationSchema.

private PrismSchema generateConnectorConfigurationSchema(ConnectorInfo cinfo, ConnectorType connectorType) {
    LOGGER.trace("Generating configuration schema for {}", this);
    APIConfiguration defaultAPIConfiguration = cinfo.createDefaultAPIConfiguration();
    ConfigurationProperties icfConfigurationProperties = defaultAPIConfiguration.getConfigurationProperties();
    if (icfConfigurationProperties == null || icfConfigurationProperties.getPropertyNames() == null || icfConfigurationProperties.getPropertyNames().isEmpty()) {
        LOGGER.debug("No configuration schema for {}", this);
        return null;
    }
    PrismSchema connectorSchema = new PrismSchemaImpl(connectorType.getNamespace(), prismContext);
    // Create configuration type - the type used by the "configuration"
    // element
    PrismContainerDefinitionImpl<?> configurationContainerDef = ((PrismSchemaImpl) connectorSchema).createPropertyContainerDefinition(ResourceType.F_CONNECTOR_CONFIGURATION.getLocalPart(), SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_TYPE_LOCAL_NAME);
    // element with "ConfigurationPropertiesType" - the dynamic part of
    // configuration schema
    ComplexTypeDefinition configPropertiesTypeDef = ((PrismSchemaImpl) connectorSchema).createComplexTypeDefinition(new QName(connectorType.getNamespace(), ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_TYPE_LOCAL_NAME));
    // Create definition of "configurationProperties" type
    // (CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_TYPE_LOCAL_NAME)
    int displayOrder = 1;
    for (String icfPropertyName : icfConfigurationProperties.getPropertyNames()) {
        ConfigurationProperty icfProperty = icfConfigurationProperties.getProperty(icfPropertyName);
        QName propXsdType = ConnIdUtil.icfTypeToXsdType(icfProperty.getType(), icfProperty.isConfidential());
        LOGGER.trace("{}: Mapping ICF config schema property {} from {} to {}", new Object[] { this, icfPropertyName, icfProperty.getType(), propXsdType });
        PrismPropertyDefinitionImpl<?> propertyDefinifion = ((ComplexTypeDefinitionImpl) configPropertiesTypeDef).createPropertyDefinition(icfPropertyName, propXsdType);
        propertyDefinifion.setDisplayName(icfProperty.getDisplayName(null));
        propertyDefinifion.setHelp(icfProperty.getHelpMessage(null));
        if (ConnIdUtil.isMultivaluedType(icfProperty.getType())) {
            propertyDefinifion.setMaxOccurs(-1);
        } else {
            propertyDefinifion.setMaxOccurs(1);
        }
        if (icfProperty.isRequired() && icfProperty.getValue() == null) {
            // If ICF says that the property is required it may not be in fact really required if it also has a default value
            propertyDefinifion.setMinOccurs(1);
        } else {
            propertyDefinifion.setMinOccurs(0);
        }
        propertyDefinifion.setDisplayOrder(displayOrder);
        displayOrder++;
    }
    // Create common ICF configuration property containers as a references
    // to a static schema
    configurationContainerDef.createContainerDefinition(ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_ELEMENT, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_TYPE, 0, 1);
    configurationContainerDef.createPropertyDefinition(ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_PRODUCER_BUFFER_SIZE_ELEMENT, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_PRODUCER_BUFFER_SIZE_TYPE, 0, 1);
    configurationContainerDef.createContainerDefinition(ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_TIMEOUTS_ELEMENT, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_TIMEOUTS_TYPE, 0, 1);
    configurationContainerDef.createContainerDefinition(ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_ELEMENT, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_TYPE, 0, 1);
    configurationContainerDef.createPropertyDefinition(ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_LEGACY_SCHEMA_ELEMENT, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_LEGACY_SCHEMA_TYPE, 0, 1);
    // No need to create definition of "configuration" element.
    // midPoint will look for this element, but it will be generated as part
    // of the PropertyContainer serialization to schema
    configurationContainerDef.createContainerDefinition(SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_ELEMENT_QNAME, configPropertiesTypeDef, 1, 1);
    LOGGER.debug("Generated configuration schema for {}: {} definitions", this, connectorSchema.getDefinitions().size());
    return connectorSchema;
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ConfigurationProperty(org.identityconnectors.framework.api.ConfigurationProperty) ComplexTypeDefinitionImpl(com.evolveum.midpoint.prism.ComplexTypeDefinitionImpl) PrismSchemaImpl(com.evolveum.midpoint.prism.schema.PrismSchemaImpl) QName(javax.xml.namespace.QName) APIConfiguration(org.identityconnectors.framework.api.APIConfiguration) ComplexTypeDefinition(com.evolveum.midpoint.prism.ComplexTypeDefinition) ConfigurationProperties(org.identityconnectors.framework.api.ConfigurationProperties) GuardedString(org.identityconnectors.common.security.GuardedString)

Example 29 with PrismSchema

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

the class UcfUtil method getConnectorSchema.

public static PrismSchema getConnectorSchema(ConnectorType connectorType, PrismContext prismContext) throws SchemaException {
    XmlSchemaType xmlSchema = connectorType.getSchema();
    if (xmlSchema == null) {
        return null;
    }
    Element xsdElement = ObjectTypeUtil.findXsdElement(xmlSchema);
    if (xsdElement == null) {
        return null;
    }
    PrismSchema connectorSchema = PrismSchemaImpl.parse(xsdElement, true, connectorType.toString(), prismContext);
    return connectorSchema;
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) Element(org.w3c.dom.Element) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType)

Example 30 with PrismSchema

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

the class ConnectorFactoryBuiltinImpl method createConnectorStruct.

private ConnectorStruct createConnectorStruct(Class connectorClass, ManagedConnector annotation) throws ObjectNotFoundException, SchemaException {
    ConnectorStruct struct = new ConnectorStruct();
    struct.connectorClass = connectorClass;
    ConnectorType connectorType = new ConnectorType();
    String bundleName = connectorClass.getPackage().getName();
    String type = annotation.type();
    if (type == null || type.isEmpty()) {
        type = connectorClass.getSimpleName();
    }
    String version = annotation.version();
    UcfUtil.addConnectorNames(connectorType, "Built-in", bundleName, type, version, null);
    connectorType.setConnectorBundle(bundleName);
    connectorType.setConnectorType(type);
    connectorType.setVersion(version);
    connectorType.setFramework(SchemaConstants.UCF_FRAMEWORK_URI_BUILTIN);
    String namespace = CONFIGURATION_NAMESPACE_PREFIX + bundleName + "/" + type;
    connectorType.setNamespace(namespace);
    struct.connectorObject = connectorType;
    PrismSchema connectorSchema = generateConnectorConfigurationSchema(struct);
    if (connectorSchema != null) {
        LOGGER.trace("Generated connector schema for {}: {} definitions", connectorType, connectorSchema.getDefinitions().size());
        UcfUtil.setConnectorSchema(connectorType, connectorSchema);
        struct.connectorConfigurationSchema = connectorSchema;
    } else {
        LOGGER.warn("No connector schema generated for {}", connectorType);
    }
    return struct;
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)

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