Search in sources :

Example 11 with ConnectorConfigurationType

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

the class TestUcfDummy method test031ResourceSchemaAccountObjectClass.

@Test
public void test031ResourceSchemaAccountObjectClass() throws Exception {
    final String TEST_NAME = "test031ResourceSchemaAccountObjectClass";
    TestUtil.displayTestTile(TEST_NAME);
    OperationResult result = new OperationResult(TestUcfDummy.class + "." + TEST_NAME);
    cc = connectorFactory.createConnectorInstance(connectorType, ResourceTypeUtil.getResourceNamespace(resourceType), "test connector");
    assertNotNull("Failed to instantiate connector", cc);
    PrismContainerValue<ConnectorConfigurationType> configContainer = resourceType.getConnectorConfiguration().asPrismContainerValue();
    display("Configuration container", configContainer);
    cc.configure(configContainer, result);
    List<QName> objectClassesToGenerate = new ArrayList<QName>();
    QName accountObjectClass = new QName(resource.asObjectable().getNamespace(), "AccountObjectClass");
    objectClassesToGenerate.add(accountObjectClass);
    // WHEN
    resourceSchema = cc.fetchResourceSchema(objectClassesToGenerate, result);
    // THEN
    display("Generated resource schema", resourceSchema);
    assertEquals("Unexpected number of definitions", 1, resourceSchema.getDefinitions().size());
    assertEquals("Unexpected number of object class definitions", 1, resourceSchema.getObjectClassDefinitions().size());
    display("RESOURCE SCHEMA DEFINITION" + resourceSchema.getDefinitions().iterator().next().getTypeName());
}
Also used : ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 12 with ConnectorConfigurationType

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

the class ResourceManager method applyDefinition.

public void applyDefinition(ObjectDelta<ResourceType> delta, ResourceType resourceWhenNoOid, GetOperationOptions options, Task task, OperationResult objectResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    if (delta.isAdd()) {
        PrismObject<ResourceType> resource = delta.getObjectToAdd();
        applyConnectorSchemaToResource(resource, task, objectResult);
        return;
    } else if (delta.isModify()) {
    // Go on
    } else {
        return;
    }
    if (delta.hasCompleteDefinition()) {
        //nothing to do, all modifications has definitions..just aplly this deltas..
        return;
    }
    PrismObject<ResourceType> resource;
    String resourceOid = delta.getOid();
    if (resourceOid == null) {
        Validate.notNull(resourceWhenNoOid, "Resource oid not specified in the object delta, and resource is not specified as well. Could not apply definition.");
        resource = resourceWhenNoOid.asPrismObject();
    } else {
        resource = getResource(resourceOid, options, task, objectResult);
    }
    ResourceType resourceType = resource.asObjectable();
    //		ResourceType resourceType = completeResource(resource.asObjectable(), null, objectResult);
    //TODO TODO TODO FIXME FIXME FIXME copied from ObjectImprted..union this two cases
    PrismContainer<ConnectorConfigurationType> configurationContainer = ResourceTypeUtil.getConfigurationContainer(resourceType);
    if (configurationContainer == null || configurationContainer.isEmpty()) {
        // Nothing to check
        objectResult.recordWarning("The resource has no configuration");
        return;
    }
    // Check the resource configuration. The schema is in connector, so fetch the connector first
    String connectorOid = resourceType.getConnectorRef().getOid();
    if (StringUtils.isBlank(connectorOid)) {
        objectResult.recordFatalError("The connector reference (connectorRef) is null or empty");
        return;
    }
    //ItemDelta.findItemDelta(delta.getModifications(), ResourceType.F_SCHEMA, ContainerDelta.class) == null || 
    ReferenceDelta connectorRefDelta = ReferenceDelta.findReferenceModification(delta.getModifications(), ResourceType.F_CONNECTOR_REF);
    if (connectorRefDelta != null) {
        Item<PrismReferenceValue, PrismReferenceDefinition> connectorRefNew = connectorRefDelta.getItemNewMatchingPath(null);
        if (connectorRefNew.getValues().size() == 1) {
            PrismReferenceValue connectorRefValue = connectorRefNew.getValues().iterator().next();
            if (connectorRefValue.getOid() != null && !connectorOid.equals(connectorRefValue.getOid())) {
                connectorOid = connectorRefValue.getOid();
            }
        }
    }
    PrismObject<ConnectorType> connector = null;
    ConnectorType connectorType = null;
    try {
        connector = repositoryService.getObject(ConnectorType.class, connectorOid, null, objectResult);
        connectorType = connector.asObjectable();
    } catch (ObjectNotFoundException e) {
        // No connector, no fun. We can't check the schema. But this is referential integrity problem.
        // Mark the error ... there is nothing more to do
        objectResult.recordFatalError("Connector (OID:" + connectorOid + ") referenced from the resource is not in the repository", e);
        return;
    } catch (SchemaException e) {
        // Probably a malformed connector. To be kind of robust, lets allow the import.
        // Mark the error ... there is nothing more to do
        objectResult.recordPartialError("Connector (OID:" + connectorOid + ") referenced from the resource has schema problems: " + e.getMessage(), e);
        LOGGER.error("Connector (OID:{}) referenced from the imported resource \"{}\" has schema problems: {}", new Object[] { connectorOid, resourceType.getName(), e.getMessage(), e });
        return;
    }
    Element connectorSchemaElement = ConnectorTypeUtil.getConnectorXsdSchema(connector);
    PrismSchema connectorSchema = null;
    if (connectorSchemaElement == null) {
        // No schema to validate with
        return;
    }
    try {
        connectorSchema = PrismSchemaImpl.parse(connectorSchemaElement, true, "schema for " + connector, prismContext);
    } catch (SchemaException e) {
        objectResult.recordFatalError("Error parsing connector schema for " + connector + ": " + e.getMessage(), e);
        return;
    }
    QName configContainerQName = new QName(connectorType.getNamespace(), ResourceType.F_CONNECTOR_CONFIGURATION.getLocalPart());
    PrismContainerDefinition<ConnectorConfigurationType> configContainerDef = connectorSchema.findContainerDefinitionByElementName(configContainerQName);
    if (configContainerDef == null) {
        objectResult.recordFatalError("Definition of configuration container " + configContainerQName + " not found in the schema of of " + connector);
        return;
    }
    try {
        configurationContainer.applyDefinition(configContainerDef);
    } catch (SchemaException e) {
        objectResult.recordFatalError("Configuration error in " + resource + ": " + e.getMessage(), e);
        return;
    }
    PrismContainer configContainer = resourceType.asPrismObject().findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    configContainer.applyDefinition(configContainerDef);
    for (ItemDelta<?, ?> itemDelta : delta.getModifications()) {
        applyItemDefinition(itemDelta, configContainerDef, objectResult);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 13 with ConnectorConfigurationType

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

the class ConnectorManager method createConfiguredConnectorInstance.

private ConnectorInstance createConfiguredConnectorInstance(ConnectorSpec connectorSpec, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException {
    ConnectorType connectorType = getConnectorTypeReadOnly(connectorSpec, result);
    ConnectorFactory connectorFactory = determineConnectorFactory(connectorType);
    ConnectorInstance connector = null;
    try {
        connector = connectorFactory.createConnectorInstance(connectorType, ResourceTypeUtil.getResourceNamespace(connectorSpec.getResource()), connectorSpec.toString());
    } catch (ObjectNotFoundException e) {
        result.recordFatalError(e.getMessage(), e);
        throw new ObjectNotFoundException(e.getMessage(), e);
    }
    PrismContainerValue<ConnectorConfigurationType> connectorConfigurationVal = connectorSpec.getConnectorConfiguration().getValue();
    if (connectorConfigurationVal == null) {
        SchemaException e = new SchemaException("No connector configuration in " + connectorSpec);
        result.recordFatalError(e);
        throw e;
    }
    try {
        connector.configure(connectorConfigurationVal, result);
        ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(connectorSpec.getResource(), prismContext);
        Collection<Object> capabilities = ResourceTypeUtil.getNativeCapabilitiesCollection(connectorSpec.getResource().asObjectable());
        connector.initialize(resourceSchema, capabilities, ResourceTypeUtil.isCaseIgnoreAttributeNames(connectorSpec.getResource().asObjectable()), result);
        InternalMonitor.recordConnectorInstanceInitialization();
    } catch (GenericFrameworkException e) {
        // Not expected. Transform to system exception
        result.recordFatalError("Generic provisioning framework error", e);
        throw new SystemException("Generic provisioning framework error: " + e.getMessage(), e);
    } catch (CommunicationException e) {
        result.recordFatalError(e);
        throw e;
    } catch (ConfigurationException e) {
        result.recordFatalError(e);
        throw e;
    }
    // This log message should be INFO level. It happens only occasionally.
    // If it happens often, it may be an
    // indication of a problem. Therefore it is good for admin to see it.
    LOGGER.info("Created new connector instance for {}: {} v{}", connectorSpec, connectorType.getConnectorType(), connectorType.getConnectorVersion());
    return connector;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) ConnectorFactory(com.evolveum.midpoint.provisioning.ucf.api.ConnectorFactory) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 14 with ConnectorConfigurationType

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

the class TestResources method assertResource.

private void assertResource(PrismObject<ResourceType> resource, boolean expectSchema) {
    display("Resource", resource);
    display("Resource def", resource.getDefinition());
    PrismContainer<ConnectorConfigurationType> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertNotNull("No Resource connector configuration def", configurationContainer);
    PrismContainerDefinition<ConnectorConfigurationType> configurationContainerDefinition = configurationContainer.getDefinition();
    display("Resource connector configuration def", configurationContainerDefinition);
    display("Resource connector configuration def complex type def", configurationContainerDefinition.getComplexTypeDefinition());
    assertNotNull("Empty Resource connector configuration def", configurationContainer.isEmpty());
    assertEquals("Wrong compile-time class in Resource connector configuration in " + resource, ConnectorConfigurationType.class, configurationContainer.getCompileTimeClass());
    assertEquals("configurationContainer maxOccurs", 1, configurationContainerDefinition.getMaxOccurs());
    resource.checkConsistence(true, true);
    Element schema = ResourceTypeUtil.getResourceXsdSchema(resource);
    if (expectSchema) {
        assertNotNull("no schema in " + resource, schema);
    } else {
        assertNull("Unexpected schema in " + resource + ": " + schema, schema);
    }
}
Also used : ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) Element(org.w3c.dom.Element)

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