Search in sources :

Example 16 with ConnectorType

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

the class ConnectorFactoryConnIdImpl method convertToConnectorType.

/**
 * Converts ICF ConnectorInfo into a midPoint XML connector representation.
 * <p>
 * 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) {
        // bind using connectorHostRef and OID
        ObjectReferenceType ref = new ObjectReferenceType();
        ref.setOid(hostType.getOid());
        ref.setType(ObjectTypes.CONNECTOR_HOST.getTypeQName());
        ref.asReferenceValue().setObject(hostType.asPrismObject());
        connectorType.setConnectorHostRef(ref);
    }
    PrismSchema connectorSchema = generateConnectorConfigurationSchema(cinfo, connectorType);
    LOGGER.trace("Generated connector schema for {}: {} definitions", connectorType, connectorSchema.getDefinitions().size());
    UcfUtil.setConnectorSchema(connectorType, connectorSchema);
    return connectorType;
}
Also used : MutablePrismSchema(com.evolveum.midpoint.prism.schema.MutablePrismSchema) 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) GuardedString(org.identityconnectors.common.security.GuardedString)

Example 17 with ConnectorType

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

the class ConnectorFactoryConnIdImpl method listConnectors.

/**
 * Returns a list XML representation of the ICF connectors.
 */
@Override
public Set<ConnectorType> listConnectors(ConnectorHostType host, OperationResult parentResult) throws CommunicationException {
    OperationResult result = parentResult.createSubresult(ConnectorFactory.OPERATION_LIST_CONNECTORS);
    result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ConnectorFactoryConnIdImpl.class);
    result.addParam("host", host);
    try {
        if (host == null) {
            Set<ConnectorType> connectors = listLocalConnectors();
            result.recordSuccess();
            return connectors;
        } else {
            // This is necessary as list of the remote connectors is cached locally.
            // So if any remote connector is added then it will not be discovered unless we
            // clear the cache. This may look like inefficiency but in fact the listConnectors() method is
            // used only when discovering new connectors. Normal connector operation is using connector objects
            // stored in repository.
            connectorInfoManagerFactory.clearRemoteCache();
            Set<ConnectorType> connectors = listRemoteConnectors(host);
            result.recordSuccess();
            return connectors;
        }
    } catch (Throwable icfException) {
        Throwable ex = processConnIdException(icfException, "list connectors", result);
        result.recordFatalError(ex.getMessage(), ex);
        if (ex instanceof CommunicationException) {
            throw (CommunicationException) ex;
        } else if (ex instanceof RuntimeException) {
            throw (RuntimeException) ex;
        } else if (ex instanceof Error) {
            throw (Error) ex;
        } else {
            throw new SystemException("Unexpected ICF exception: " + ex.getMessage(), ex);
        }
    }
}
Also used : ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SystemException(com.evolveum.midpoint.util.exception.SystemException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 18 with ConnectorType

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

the class ConnectorFactoryBuiltinImpl method createConnectorStruct.

private ConnectorStruct createConnectorStruct(Class<?> connectorClass, ManagedConnector annotation) throws SchemaException {
    ConnectorStruct struct = new ConnectorStruct();
    if (!ConnectorInstance.class.isAssignableFrom(connectorClass)) {
        throw new IllegalStateException("Connector class " + connectorClass + " is not of ConnectorInstance type");
    }
    // noinspection unchecked
    struct.connectorClass = (Class<? extends ConnectorInstance>) connectorClass;
    ConnectorType connectorType = new ConnectorType();
    String bundleName = connectorClass.getPackage().getName();
    String type = annotation.type();
    if (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.setConnectorVersion(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);
    // noinspection ConstantConditions (probably can be null in the future)
    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 : MutablePrismSchema(com.evolveum.midpoint.prism.schema.MutablePrismSchema) PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) AbstractManagedConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.connectors.AbstractManagedConnectorInstance) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)

Example 19 with ConnectorType

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

the class ConfigurationStep method createConfigContainerWrappers.

// @NotNull
private PrismContainerWrapper<ConnectorConfigurationType> createConfigContainerWrappers() throws SchemaException {
    PrismObject<ResourceType> resource = resourceModelNoFetch.getObject();
    PrismContainer<ConnectorConfigurationType> configuration = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    if (parentPage.isNewResource()) {
        return null;
    }
    ItemStatus configurationStatus = ItemStatus.NOT_CHANGED;
    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();
        definitionFixed.toMutable().setMaxOccurs(1);
        configuration = definitionFixed.instantiate();
        configurationStatus = ItemStatus.ADDED;
    }
    Task task = getPageBase().createSimpleTask(OPERATION_CREATE_CONFIGURATION_WRAPPERS);
    WrapperContext ctx = new WrapperContext(task, getResult());
    ctx.setReadOnly(parentPage.isReadOnly());
    ctx.setShowEmpty(ItemStatus.ADDED == configurationStatus);
    return getPageBase().createItemWrapper(configuration, configurationStatus, ctx);
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) 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) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 20 with ConnectorType

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

the class NameStep method discoverConnectorsPerformed.

@SuppressWarnings("unchecked")
private void discoverConnectorsPerformed(AjaxRequestTarget target) {
    DropDownChoice<PrismObject<ConnectorHostType>> connectorHostChoice = ((DropDownFormGroup<PrismObject<ConnectorHostType>>) get(ID_CONNECTOR_HOST)).getInput();
    PrismObject<ConnectorHostType> connectorHostObject = connectorHostChoice.getModelObject();
    ConnectorHostType host = connectorHostObject != null ? connectorHostObject.asObjectable() : null;
    if (host != null) {
        discoverConnectors(host);
        allConnectorsModel.reset();
    }
    relevantConnectorsModel.reset();
    DropDownFormGroup<PrismObject<ConnectorType>> connectorDropDown = getConnectorDropDown();
    PrismObject<ConnectorType> selectedConnector = connectorDropDown.getInput().getModelObject();
    if (selectedConnector != null) {
        if (!isConnectorOnHost(selectedConnector, connectorHostObject)) {
            PrismObject<ConnectorType> compatibleConnector = null;
            for (PrismObject<ConnectorType> relevantConnector : relevantConnectorsModel.getObject()) {
                if (isConfigurationSchemaCompatible(relevantConnector)) {
                    compatibleConnector = relevantConnector;
                    break;
                }
            }
            selectedConnectorModel.setObject(compatibleConnector);
        }
    }
    target.add(connectorDropDown.getInput(), connectorDropDown.getAdditionalInfoComponent(), ((PageBase) getPage()).getFeedbackPanel());
}
Also used : ConnectorHostType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorHostType) PrismObject(com.evolveum.midpoint.prism.PrismObject) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) DropDownFormGroup(com.evolveum.midpoint.web.component.form.DropDownFormGroup)

Aggregations

ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)39 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)21 Test (org.testng.annotations.Test)17 PrismObject (com.evolveum.midpoint.prism.PrismObject)13 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)13 Task (com.evolveum.midpoint.task.api.Task)12 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)12 PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)8 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)8 SystemException (com.evolveum.midpoint.util.exception.SystemException)8 QName (javax.xml.namespace.QName)7 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)6 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)6 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)4 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)4 ConnectorConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType)4 ConnectorHostType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorHostType)4 XmlSchemaType (com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType)4 Element (org.w3c.dom.Element)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3