Search in sources :

Example 1 with PrismSchemaImpl

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

the class TestPrismSchemaConstruction method constructSchema.

private PrismSchema constructSchema(PrismContext prismContext) {
    PrismSchemaImpl schema = new PrismSchemaImpl(NS_MY_SCHEMA, prismContext);
    ComplexTypeDefinitionImpl weaponTypeDef = (ComplexTypeDefinitionImpl) schema.createComplexTypeDefinition(WEAPON_TYPE_QNAME);
    PrismPropertyDefinitionImpl kindPropertyDef = weaponTypeDef.createPropertyDefinition(WEAPON_KIND_QNAME, DOMUtil.XSD_STRING);
    kindPropertyDef.setDisplayName("Weapon kind");
    weaponTypeDef.createPropertyDefinition(WEAPON_BRAND_LOCAL_NAME, PrismInternalTestUtil.WEAPONS_WEAPON_BRAND_TYPE_QNAME);
    weaponTypeDef.createPropertyDefinition(WEAPON_PASSWORD_LOCAL_NAME, PrismInternalTestUtil.DUMMY_PROTECTED_STRING_TYPE);
    weaponTypeDef.createPropertyDefinition(WEAPON_BLADE_LOCAL_NAME, PrismInternalTestUtil.EXTENSION_BLADE_TYPE_QNAME);
    PrismPropertyDefinitionImpl createTimestampPropertyDef = weaponTypeDef.createPropertyDefinition(WEAPON_CREATE_TIMESTAMP_QNAME, DOMUtil.XSD_DATETIME);
    createTimestampPropertyDef.setDisplayName("Create timestamp");
    createTimestampPropertyDef.setOperational(true);
    schema.createPropertyContainerDefinition(WEAPON_LOCAL_NAME, WEAPON_TYPE_LOCAL_NAME);
    return schema;
}
Also used : PrismSchemaImpl(com.evolveum.midpoint.prism.schema.PrismSchemaImpl)

Example 2 with PrismSchemaImpl

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

the class ConnectorFactoryBuiltinImpl method generateConnectorConfigurationSchema.

private PrismSchema generateConnectorConfigurationSchema(ConnectorStruct struct) {
    Class<? extends ConnectorInstance> connectorClass = struct.connectorClass;
    PropertyDescriptor connectorConfigurationProp = UcfUtil.findAnnotatedProperty(connectorClass, ManagedConnectorConfiguration.class);
    PrismSchema connectorSchema = new PrismSchemaImpl(struct.connectorObject.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);
    Class<?> configurationClass = connectorConfigurationProp.getPropertyType();
    BeanWrapper configurationClassBean = new BeanWrapperImpl(configurationClass);
    for (PropertyDescriptor prop : configurationClassBean.getPropertyDescriptors()) {
        if (!UcfUtil.hasAnnotation(prop, ConfigurationProperty.class)) {
            continue;
        }
        ItemDefinition<?> itemDef = createPropertyDefinition(configurationContainerDef, prop);
        LOGGER.trace("Configuration item definition for {}: {}", prop.getName(), itemDef);
    }
    return connectorSchema;
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ConfigurationProperty(com.evolveum.midpoint.provisioning.ucf.api.ConfigurationProperty) PrismSchemaImpl(com.evolveum.midpoint.prism.schema.PrismSchemaImpl) BeanWrapper(org.springframework.beans.BeanWrapper) PropertyDescriptor(java.beans.PropertyDescriptor) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl)

Example 3 with PrismSchemaImpl

use of com.evolveum.midpoint.prism.schema.PrismSchemaImpl 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 4 with PrismSchemaImpl

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

the class SchemaProcessorTest method testRoundTripGeneric.

@Test
public void testRoundTripGeneric() throws SchemaException {
    // GIVEN
    PrismSchemaImpl schema = new PrismSchemaImpl(SCHEMA_NS, PrismTestUtil.getPrismContext());
    // Ordinary property
    schema.createPropertyDefinition("number1", DOMUtil.XSD_INT);
    // Property container
    PrismContainerDefinitionImpl containerDefinition = schema.createPropertyContainerDefinition("ContainerType");
    // ... in it ordinary property
    containerDefinition.createPropertyDefinition("login", DOMUtil.XSD_STRING);
    // ... and local property with a type from another schema
    containerDefinition.createPropertyDefinition("password", ProtectedStringType.COMPLEX_TYPE);
    // ... property reference
    containerDefinition.createPropertyDefinition(SchemaConstants.C_CREDENTIALS, CredentialsType.COMPLEX_TYPE);
    // ... read-only int property 
    PrismPropertyDefinition counterProperty = containerDefinition.createPropertyDefinition("counter", DOMUtil.XSD_INT);
    ((PrismPropertyDefinitionImpl) counterProperty).setReadOnly();
    System.out.println("Generic schema before serializing to XSD: ");
    System.out.println(schema.debugDump());
    System.out.println();
    // WHEN
    Document xsd = schema.serializeToXsd();
    String stringXmlSchema = DOMUtil.serializeDOMToString(xsd);
    System.out.println("Generic schema after serializing to XSD: ");
    System.out.println(stringXmlSchema);
    System.out.println();
    Document parsedXsd = DOMUtil.parseDocument(stringXmlSchema);
    PrismSchema newSchema = PrismSchemaImpl.parse(DOMUtil.getFirstChildElement(parsedXsd), true, "serialized schema", PrismTestUtil.getPrismContext());
    System.out.println("Generic schema after parsing from XSD: ");
    System.out.println(newSchema.debugDump());
    System.out.println();
    // THEN
    PrismPropertyDefinition number1def = newSchema.findItemDefinitionByElementName(new QName(SCHEMA_NS, "number1"), PrismPropertyDefinition.class);
    assertEquals(new QName(SCHEMA_NS, "number1"), number1def.getName());
    assertEquals(DOMUtil.XSD_INT, number1def.getTypeName());
    PrismContainerDefinition newContainerDef = schema.findContainerDefinitionByType(new QName(SCHEMA_NS, "ContainerType"));
    assertEquals(new QName(SCHEMA_NS, "ContainerType"), newContainerDef.getTypeName());
    PrismPropertyDefinition loginDef = newContainerDef.findPropertyDefinition(new QName(SCHEMA_NS, "login"));
    assertEquals(new QName(SCHEMA_NS, "login"), loginDef.getName());
    assertEquals(DOMUtil.XSD_STRING, loginDef.getTypeName());
    assertTrue("Read flag is wrong", loginDef.canRead());
    assertTrue("Create flag is wrong", loginDef.canAdd());
    assertTrue("Update flag is wrong", loginDef.canModify());
    PrismPropertyDefinition passwdDef = newContainerDef.findPropertyDefinition(new QName(SCHEMA_NS, "password"));
    assertEquals(new QName(SCHEMA_NS, "password"), passwdDef.getName());
    assertEquals(ProtectedStringType.COMPLEX_TYPE, passwdDef.getTypeName());
    PrismPropertyDefinition credDef = newContainerDef.findPropertyDefinition(new QName(SchemaConstants.NS_C, "credentials"));
    assertEquals(new QName(SchemaConstants.NS_C, "credentials"), credDef.getName());
    assertEquals(new QName(SchemaConstants.NS_C, "CredentialsType"), credDef.getTypeName());
    PrismPropertyDefinition countDef = newContainerDef.findPropertyDefinition(new QName(SCHEMA_NS, "counter"));
    assertEquals(new QName(SCHEMA_NS, "counter"), countDef.getName());
    assertEquals(DOMUtil.XSD_INT, countDef.getTypeName());
    assertTrue("Read flag is wrong", countDef.canRead());
    assertFalse("Create flag is wrong", countDef.canAdd());
    assertFalse("Update flag is wrong", countDef.canModify());
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) PrismSchemaImpl(com.evolveum.midpoint.prism.schema.PrismSchemaImpl) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PrismContainerDefinitionImpl(com.evolveum.midpoint.prism.PrismContainerDefinitionImpl) QName(javax.xml.namespace.QName) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) Document(org.w3c.dom.Document) Test(org.testng.annotations.Test)

Aggregations

PrismSchemaImpl (com.evolveum.midpoint.prism.schema.PrismSchemaImpl)4 PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)3 QName (javax.xml.namespace.QName)2 ComplexTypeDefinition (com.evolveum.midpoint.prism.ComplexTypeDefinition)1 ComplexTypeDefinitionImpl (com.evolveum.midpoint.prism.ComplexTypeDefinitionImpl)1 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)1 PrismContainerDefinitionImpl (com.evolveum.midpoint.prism.PrismContainerDefinitionImpl)1 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)1 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)1 ConfigurationProperty (com.evolveum.midpoint.provisioning.ucf.api.ConfigurationProperty)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 GuardedString (org.identityconnectors.common.security.GuardedString)1 APIConfiguration (org.identityconnectors.framework.api.APIConfiguration)1 ConfigurationProperties (org.identityconnectors.framework.api.ConfigurationProperties)1 ConfigurationProperty (org.identityconnectors.framework.api.ConfigurationProperty)1 BeanWrapper (org.springframework.beans.BeanWrapper)1 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)1 Test (org.testng.annotations.Test)1 Document (org.w3c.dom.Document)1