Search in sources :

Example 21 with PrismSchema

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

the class IntegrationTestTools method assertConnectorSchemaSanity.

public static void assertConnectorSchemaSanity(ConnectorType conn, PrismContext prismContext) throws SchemaException {
    XmlSchemaType xmlSchemaType = conn.getSchema();
    assertNotNull("xmlSchemaType is null", xmlSchemaType);
    Element connectorXsdSchemaElement = ConnectorTypeUtil.getConnectorXsdSchema(conn);
    assertNotNull("No schema", connectorXsdSchemaElement);
    Element xsdElement = ObjectTypeUtil.findXsdElement(xmlSchemaType);
    assertNotNull("No xsd:schema element in xmlSchemaType", xsdElement);
    display("XSD schema of " + conn, DOMUtil.serializeDOMToString(xsdElement));
    // Try to parse the schema
    PrismSchema schema = null;
    try {
        schema = PrismSchemaImpl.parse(xsdElement, true, "schema of " + conn, prismContext);
    } catch (SchemaException e) {
        throw new SchemaException("Error parsing schema of " + conn + ": " + e.getMessage(), e);
    }
    assertConnectorSchemaSanity(schema, conn.toString(), SchemaConstants.ICF_FRAMEWORK_URI.equals(conn.getFramework()));
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) Element(org.w3c.dom.Element)

Example 22 with PrismSchema

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

the class ResourceManager method applyConnectorSchemaToResource.

/**
	 * Apply proper definition (connector schema) to the resource.
	 */
private void applyConnectorSchemaToResource(ConnectorSpec connectorSpec, PrismObjectDefinition<ResourceType> resourceDefinition, PrismObject<ResourceType> resource, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    ConnectorType connectorType = connectorManager.getConnectorTypeReadOnly(connectorSpec, result);
    PrismSchema connectorSchema = connectorManager.getConnectorSchema(connectorType);
    if (connectorSchema == null) {
        throw new SchemaException("No connector schema in " + connectorType);
    }
    PrismContainerDefinition<ConnectorConfigurationType> configurationContainerDefinition = ConnectorTypeUtil.findConfigurationContainerDefinition(connectorType, connectorSchema);
    if (configurationContainerDefinition == null) {
        throw new SchemaException("No configuration container definition in schema of " + connectorType);
    }
    configurationContainerDefinition = configurationContainerDefinition.clone();
    PrismContainer<ConnectorConfigurationType> configurationContainer = connectorSpec.getConnectorConfiguration();
    // the element is global in the connector schema. therefore it does not have correct maxOccurs
    if (configurationContainer != null) {
        configurationContainerDefinition.adoptElementDefinitionFrom(configurationContainer.getDefinition());
        configurationContainer.applyDefinition(configurationContainerDefinition, true);
        try {
            configurationContainer.accept(visitable -> {
                if ((visitable instanceof PrismProperty<?>)) {
                    try {
                        evaluateExpression((PrismProperty<?>) visitable, resource, task, result);
                    } catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException e) {
                        throw new TunnelException(e);
                    }
                }
            });
        } catch (TunnelException te) {
            Throwable e = te.getCause();
            if (e instanceof SchemaException) {
                throw (SchemaException) e;
            } else if (e instanceof ObjectNotFoundException) {
                throw (ObjectNotFoundException) e;
            } else if (e instanceof ExpressionEvaluationException) {
                throw (ExpressionEvaluationException) e;
            } else if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else if (e instanceof Error) {
                throw (Error) e;
            } else {
                throw new SystemException(e);
            }
        }
    } else {
        configurationContainerDefinition.adoptElementDefinitionFrom(resourceDefinition.findContainerDefinition(ResourceType.F_CONNECTOR_CONFIGURATION));
    }
    if (connectorSpec.getConnectorName() == null) {
        // Default connector, for compatibility
        // It does not make sense to update this for any other connectors.
        // We cannot have one definition for addiitionalConnector[1]/connectorConfiguraiton and
        // different definition for addiitionalConnector[2]/connectorConfiguraiton in the object definition.
        // The way to go is to set up definitions on the container level.
        resourceDefinition.replaceDefinition(ResourceType.F_CONNECTOR_CONFIGURATION, configurationContainerDefinition);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) TunnelException(com.evolveum.midpoint.util.exception.TunnelException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 23 with PrismSchema

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

the class ConnectorFactoryConnIdImpl method createConnectorInstance.

/**
	 * Creates new connector instance.
	 * 
	 * It will initialize the connector by taking the XML Resource definition,
	 * transforming it to the ICF configuration and applying that to the new
	 * connector instance.
	 * 
	 * @throws ObjectNotFoundException
	 * @throws SchemaException 
	 * 
	 */
@Override
public ConnectorInstance createConnectorInstance(ConnectorType connectorType, String namespace, String desc) throws ObjectNotFoundException, SchemaException {
    ConnectorInfo cinfo = getConnectorInfo(connectorType);
    if (cinfo == null) {
        LOGGER.error("Failed to instantiate {}", ObjectTypeUtil.toShortString(connectorType));
        LOGGER.debug("Connector key: {}, host: {}", getConnectorKey(connectorType), ObjectTypeUtil.toShortString(connectorType));
        LOGGER.trace("Connector object: {}", ObjectTypeUtil.dump(connectorType));
        LOGGER.trace("Connector host object: {}", ObjectTypeUtil.dump(connectorType.getConnectorHost()));
        throw new ObjectNotFoundException("The classes (JAR) of " + ObjectTypeUtil.toShortString(connectorType) + " were not found by the ICF framework; bundle=" + connectorType.getConnectorBundle() + " connector type=" + connectorType.getConnectorType() + ", version=" + connectorType.getConnectorVersion());
    }
    PrismSchema connectorSchema = UcfUtil.getConnectorSchema(connectorType, prismContext);
    if (connectorSchema == null) {
        connectorSchema = generateConnectorConfigurationSchema(cinfo, connectorType);
    }
    ConnectorInstanceConnIdImpl connectorImpl = new ConnectorInstanceConnIdImpl(cinfo, connectorType, namespace, connectorSchema, protector, prismContext);
    connectorImpl.setDescription(desc);
    return connectorImpl;
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ConnectorInfo(org.identityconnectors.framework.api.ConnectorInfo) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 24 with PrismSchema

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

the class ConnectorFactoryConnIdImpl method convertToConnectorType.

/**
	 * Converts ICF ConnectorInfo into a midPoint XML connector representation.
	 * 
	 * TODO: schema transformation
	 * 
	 * @param hostType
	 *            host that this connector runs on or null for local connectors
	 */
private ConnectorType convertToConnectorType(ConnectorInfo cinfo, ConnectorHostType hostType) throws SchemaException {
    ConnectorType connectorType = new ConnectorType();
    ConnectorKey key = cinfo.getConnectorKey();
    UcfUtil.addConnectorNames(connectorType, "ConnId", key.getBundleName(), key.getConnectorName(), key.getBundleVersion(), hostType);
    String stringID = keyToNamespaceSuffix(key);
    connectorType.setFramework(SchemaConstants.ICF_FRAMEWORK_URI);
    connectorType.setConnectorType(key.getConnectorName());
    connectorType.setNamespace(ICF_CONFIGURATION_NAMESPACE_PREFIX + stringID);
    connectorType.setConnectorVersion(key.getBundleVersion());
    connectorType.setConnectorBundle(key.getBundleName());
    if (hostType != null) {
        if (hostType.getOid() != null) {
            // bind using connectorHostRef and OID
            ObjectReferenceType ref = new ObjectReferenceType();
            ref.setOid(hostType.getOid());
            ref.setType(ObjectTypes.CONNECTOR_HOST.getTypeQName());
            connectorType.setConnectorHostRef(ref);
        } else {
            // Embed the object
            connectorType.setConnectorHost(hostType);
        }
    }
    PrismSchema connectorSchema = generateConnectorConfigurationSchema(cinfo, connectorType);
    LOGGER.trace("Generated connector schema for {}: {} definitions", connectorType, connectorSchema.getDefinitions().size());
    UcfUtil.setConnectorSchema(connectorType, connectorSchema);
    return connectorType;
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) ConnectorKey(org.identityconnectors.framework.api.ConnectorKey) GuardedString(org.identityconnectors.common.security.GuardedString)

Example 25 with PrismSchema

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

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