Search in sources :

Example 46 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis-qe by syndesisio.

the class SalesforceSteps method createSfStepWithAction.

@Given("^create SF \"([^\"]*)\" action step on field: \"([^\"]*)\"$")
public void createSfStepWithAction(String action, String field) {
    final Connector salesforceConnector = connectorsEndpoint.get("salesforce");
    final Connection salesforceConnection = connectionsEndpoint.get(RestConstants.getInstance().getSALESFORCE_CONNECTION_ID());
    final Action sfAction = TestUtils.findConnectorAction(salesforceConnector, action);
    final Map<String, String> properties = TestUtils.map("sObjectName", field);
    final ConnectorDescriptor connectorDescriptor = getConnectorDescriptor(sfAction, properties, RestConstants.getInstance().getSALESFORCE_CONNECTION_ID());
    final Step salesforceStep = new Step.Builder().stepKind(StepKind.endpoint).id(UUID.randomUUID().toString()).connection(salesforceConnection).action(generateStepAction(sfAction, connectorDescriptor)).configuredProperties(properties).build();
    steps.getStepDefinitions().add(new StepDefinition(salesforceStep, connectorDescriptor));
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) Action(io.syndesis.common.model.action.Action) Connection(io.syndesis.common.model.connection.Connection) StepDefinition(io.syndesis.qe.bdd.entities.StepDefinition) Step(io.syndesis.common.model.integration.Step) AbstractStep(io.syndesis.qe.bdd.AbstractStep) Given(cucumber.api.java.en.Given)

Example 47 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis-qe by syndesisio.

the class AbstractStep method createStep.

public void createStep() {
    // Some steps do not have connector / connection
    Connector connector = properties.get(StepProperty.CONNECTOR_ID) == null ? null : connectorsEndpoint.get((String) properties.get(StepProperty.CONNECTOR_ID));
    Connection connection = properties.get(StepProperty.CONNECTION_ID) == null ? null : connectionsEndpoint.get((String) properties.get(StepProperty.CONNECTION_ID));
    Action action;
    // If the action is not String, then we already have action object, so just use it
    if (properties.get(StepProperty.ACTION) != null && !(properties.get(StepProperty.ACTION) instanceof String)) {
        action = (Action) properties.get(StepProperty.ACTION);
    } else {
        // It may not have an action
        action = properties.get(StepProperty.ACTION) == null ? null : findConnectorAction(connector, (String) properties.get(StepProperty.ACTION));
        if (action != null) {
            // Get the action with datashapes configured
            action = generateStepAction(action, getConnectorDescriptor(action, (Map) properties.get(StepProperty.PROPERTIES), (String) properties.get(StepProperty.CONNECTION_ID)));
        }
    }
    final Step.Builder stepBuilder = new Step.Builder();
    stepBuilder.stepKind(properties.get(StepProperty.KIND) == null ? StepKind.endpoint : (StepKind) properties.get(StepProperty.KIND));
    stepBuilder.id(properties.get(StepProperty.STEP_ID) == null ? UUID.randomUUID().toString() : (String) properties.get(StepProperty.STEP_ID));
    stepBuilder.name(properties.get(StepProperty.STEP_NAME) == null ? UUID.randomUUID().toString() : (String) properties.get(StepProperty.STEP_NAME));
    if (connection != null) {
        stepBuilder.connection(connection);
    }
    if (action != null) {
        stepBuilder.action(action);
    }
    if (properties.get(StepProperty.PROPERTIES) != null) {
        stepBuilder.configuredProperties((Map) properties.get(StepProperty.PROPERTIES));
    }
    if (properties.get(StepProperty.EXTENSION) != null) {
        stepBuilder.extension((Extension) properties.get(StepProperty.EXTENSION));
    }
    if (properties.get(StepProperty.KIND) == StepKind.mapper) {
        steps.getStepDefinitions().add(new StepDefinition(stepBuilder.build(), new DataMapperDefinition()));
    } else {
        steps.getStepDefinitions().add(new StepDefinition(stepBuilder.build()));
    }
    properties.clear();
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Action(io.syndesis.common.model.action.Action) DataMapperDefinition(io.syndesis.qe.entities.DataMapperDefinition) Connection(io.syndesis.common.model.connection.Connection) StepDefinition(io.syndesis.qe.entities.StepDefinition) Step(io.syndesis.common.model.integration.Step) StepKind(io.syndesis.common.model.integration.StepKind)

Example 48 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis-qe by syndesisio.

the class ConnectionsPublicApiSteps method checkConnectionProperties.

/**
 * DataTable ->  | property1 | value |
 * | property2 | value |
 */
@Then("^check that (\\w+) connection contains properties$")
public void checkConnectionProperties(String connectionName, DataTable tagsData) {
    List<List<String>> connectionProperties = tagsData.cells();
    Connection connection = connectionsEndpoint.getConnectionByName(connectionName);
    for (List<String> connectionProperty : connectionProperties) {
        assertThat(connection.getConfiguredProperties()).containsEntry(connectionProperty.get(0), connectionProperty.get(1));
    }
}
Also used : Connection(io.syndesis.common.model.connection.Connection) List(java.util.List) Then(io.cucumber.java.en.Then)

Example 49 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class ConnectorStepHandler method handle.

@SuppressWarnings("PMD")
@Override
public Optional<ProcessorDefinition> handle(Step step, ProcessorDefinition route, IntegrationRouteBuilder builder, final String index) {
    // Model
    final Connection connection = step.getConnection().get();
    final Connector connector = connection.getConnector().get();
    final ConnectorAction action = step.getActionAs(ConnectorAction.class).get();
    final ConnectorDescriptor descriptor = action.getDescriptor();
    // Camel
    final String scheme = Optionals.first(descriptor.getComponentScheme(), connector.getComponentScheme()).get();
    final CamelContext context = builder.getContext();
    final String componentId = scheme + "-" + index;
    final ComponentProxyComponent component = resolveComponent(componentId, scheme, context, connector, descriptor);
    final List<String> customizers = CollectionsUtils.aggregate(ArrayList::new, connector.getConnectorCustomizers(), descriptor.getConnectorCustomizers());
    final Map<String, String> properties = CollectionsUtils.aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties());
    final Map<String, ConfigurationProperty> configurationProperties = CollectionsUtils.aggregate(connector.getProperties(), action.getProperties());
    // Workaround for https://github.com/syndesisio/syndesis/issues/1713
    for (Map.Entry<String, ConfigurationProperty> entry : configurationProperties.entrySet()) {
        if (ObjectHelper.isNotEmpty(entry.getValue().getDefaultValue())) {
            properties.putIfAbsent(entry.getKey(), entry.getValue().getDefaultValue());
        }
    }
    // if the option is marked as secret use property placeholder as the
    // value is added to the integration secret.
    properties.entrySet().stream().filter(Predicates.or(connector::isSecret, action::isSecret)).forEach(e -> e.setValue(String.format("{{%s-%s.%s}}", scheme, index, e.getKey())));
    // raw values.
    properties.entrySet().stream().filter(Predicates.or(connector::isRaw, action::isRaw)).forEach(e -> e.setValue(String.format("RAW(%s)", e.getValue())));
    // Connector/Action properties have the precedence
    connector.getConfiguredProperties().forEach(properties::put);
    descriptor.getConfiguredProperties().forEach(properties::put);
    try {
        final Map<String, Object> proxyProperties = new HashMap<>(properties);
        // Set input/output data shape if the component proxy implements
        // Input/OutputDataShapeAware
        descriptor.getInputDataShape().ifPresent(ds -> trySetInputDataShape(component, ds));
        descriptor.getOutputDataShape().ifPresent(ds -> trySetOutputDataShape(component, ds));
        // Try to set properties to the component
        setProperties(context, component, proxyProperties);
        for (String customizerType : customizers) {
            final ComponentProxyCustomizer customizer = resolveCustomizer(context, customizerType);
            // Set the camel context if the customizer implements
            // the CamelContextAware interface.
            ObjectHelper.trySetCamelContext(customizer, context);
            // Set input/output data shape if the customizer implements
            // Input/OutputDataShapeAware
            descriptor.getInputDataShape().ifPresent(ds -> trySetInputDataShape(customizer, ds));
            descriptor.getOutputDataShape().ifPresent(ds -> trySetOutputDataShape(customizer, ds));
            // Try to set properties to the component
            setProperties(context, customizer, proxyProperties);
            // Invoke the customizer
            customizer.customize(component, proxyProperties);
        }
        component.setCamelContext(context);
        component.setOptions(proxyProperties);
        // Remove component
        context.removeComponent(component.getComponentId());
        context.removeService(component);
        // Register component
        context.addService(component, true, true);
        context.addComponent(component.getComponentId(), component);
        if (route == null) {
            route = builder.from(componentId);
        } else {
            route = route.to(componentId);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return Optional.ofNullable(route);
}
Also used : CamelContext(org.apache.camel.CamelContext) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Connector(io.syndesis.common.model.connection.Connector) ComponentProxyComponent(io.syndesis.integration.component.proxy.ComponentProxyComponent) ComponentProxyCustomizer(io.syndesis.integration.component.proxy.ComponentProxyCustomizer) HashMap(java.util.HashMap) Connection(io.syndesis.common.model.connection.Connection) ArrayList(java.util.ArrayList) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) HashMap(java.util.HashMap) Map(java.util.Map)

Example 50 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class ConnectionHandler method list.

@Override
public ListResult<ConnectionOverview> list(@Context UriInfo uriInfo) {
    final DataManager dataManager = getDataManager();
    final ListResult<Connection> connections = fetchAll(Connection.class, uriInfo);
    final List<ConnectionOverview> overviews = new ArrayList<>(connections.getTotalCount());
    for (Connection connection : connections.getItems()) {
        final String id = connection.getId().get();
        final ConnectionOverview.Builder builder = new ConnectionOverview.Builder().createFrom(connection);
        // set the connector
        DataManagerSupport.fetch(dataManager, Connector.class, connection.getConnectorId()).ifPresent(builder::connector);
        // set the board
        DataManagerSupport.fetchBoard(dataManager, ConnectionBulletinBoard.class, id).ifPresent(builder::board);
        overviews.add(builder.build());
    }
    return ListResult.of(overviews);
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ConnectionOverview(io.syndesis.common.model.connection.ConnectionOverview) Connection(io.syndesis.common.model.connection.Connection) ArrayList(java.util.ArrayList) DataManager(io.syndesis.server.dao.manager.DataManager) ConnectionBulletinBoard(io.syndesis.common.model.bulletin.ConnectionBulletinBoard)

Aggregations

Connection (io.syndesis.common.model.connection.Connection)111 Connector (io.syndesis.common.model.connection.Connector)65 Test (org.junit.Test)48 Step (io.syndesis.common.model.integration.Step)40 Integration (io.syndesis.common.model.integration.Integration)38 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)26 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)26 List (java.util.List)24 HashMap (java.util.HashMap)21 Action (io.syndesis.common.model.action.Action)18 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)18 ArrayList (java.util.ArrayList)17 Map (java.util.Map)16 IOException (java.io.IOException)14 InputStream (java.io.InputStream)14 IntegrationDeployment (io.syndesis.common.model.integration.IntegrationDeployment)13 StepDefinition (io.syndesis.qe.bdd.entities.StepDefinition)12 DataManager (io.syndesis.server.dao.manager.DataManager)11 Given (cucumber.api.java.en.Given)10 Flow (io.syndesis.common.model.integration.Flow)10