Search in sources :

Example 1 with ConnectorTemplate

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

the class BaseSwaggerConnectorGenerator method info.

@Override
public final ConnectorSummary info(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) {
    final SwaggerModelInfo swaggerInfo = parseSpecification(connectorSettings, true);
    try {
        // No matter if the validation fails, try to process the swagger
        final Connector connector = basicConnector(connectorTemplate, connectorSettings);
        final Map<String, Path> paths = swaggerInfo.getModel().getPaths();
        final AtomicInteger total = new AtomicInteger(0);
        final Map<String, Integer> tagCounts = // 
        paths.entrySet().stream().flatMap(// 
        p -> p.getValue().getOperations().stream()).peek(// 
        o -> total.incrementAndGet()).flatMap(// 
        o -> o.getTags().stream().distinct()).collect(// 
        Collectors.groupingBy(// 
        Function.identity(), // 
        Collectors.reducing(0, (e) -> 1, Integer::sum)));
        final ActionsSummary actionsSummary = // 
        new ActionsSummary.Builder().totalActions(// 
        total.intValue()).actionCountByTags(// 
        tagCounts).build();
        return new ConnectorSummary.Builder().createFrom(connector).actionsSummary(actionsSummary).errors(swaggerInfo.getErrors()).warnings(swaggerInfo.getWarnings()).build();
    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") final Exception ex) {
        if (!swaggerInfo.getErrors().isEmpty()) {
            // Just log and return the validation errors if any
            LOG.error("An error occurred while trying to create a swagger connector", ex);
            return new ConnectorSummary.Builder().errors(swaggerInfo.getErrors()).warnings(swaggerInfo.getWarnings()).build();
        }
        throw SyndesisServerException.launderThrowable("An error occurred while trying to create a swagger connector", ex);
    }
}
Also used : Path(io.swagger.models.Path) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) SwaggerHelper(io.syndesis.server.connector.generator.swagger.util.SwaggerHelper) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) ActionComparator(io.syndesis.server.connector.generator.util.ActionComparator) Action(io.syndesis.common.model.action.Action) Swagger(io.swagger.models.Swagger) AbstractSerializableParameter(io.swagger.models.parameters.AbstractSerializableParameter) LoggerFactory(org.slf4j.LoggerFactory) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) PropertyValue(io.syndesis.common.model.connection.ConfigurationProperty.PropertyValue) Function(java.util.function.Function) ArrayList(java.util.ArrayList) RefParameter(io.swagger.models.parameters.RefParameter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Path(io.swagger.models.Path) Map(java.util.Map) ConnectorTemplate(io.syndesis.common.model.connection.ConnectorTemplate) URI(java.net.URI) Operation(io.swagger.models.Operation) JsonSchemaHelper(io.syndesis.server.connector.generator.swagger.util.JsonSchemaHelper) ConnectorSummary(io.syndesis.common.model.connection.ConnectorSummary) StringUtils.trimToNull(org.apache.commons.lang3.StringUtils.trimToNull) Logger(org.slf4j.Logger) BodyParameter(io.swagger.models.parameters.BodyParameter) ConnectorGenerator(io.syndesis.server.connector.generator.ConnectorGenerator) DataShape(io.syndesis.common.model.DataShape) Optional.ofNullable(java.util.Optional.ofNullable) Connector(io.syndesis.common.model.connection.Connector) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) Parameter(io.swagger.models.parameters.Parameter) Collectors(java.util.stream.Collectors) Info(io.swagger.models.Info) DataShapeKinds(io.syndesis.common.model.DataShapeKinds) List(java.util.List) OperationDescription(io.syndesis.server.connector.generator.swagger.util.OperationDescription) SyndesisServerException(io.syndesis.common.util.SyndesisServerException) Entry(java.util.Map.Entry) Optional(java.util.Optional) HttpMethod(io.swagger.models.HttpMethod) Collections(java.util.Collections) ActionsSummary(io.syndesis.common.model.action.ActionsSummary) Connector(io.syndesis.common.model.connection.Connector) ActionsSummary(io.syndesis.common.model.action.ActionsSummary) SyndesisServerException(io.syndesis.common.util.SyndesisServerException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConnectorSummary(io.syndesis.common.model.connection.ConnectorSummary) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 2 with ConnectorTemplate

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

the class BaseConnectorGeneratorHandler method withGeneratorAndTemplate.

final <T> T withGeneratorAndTemplate(final String templateId, final BiFunction<ConnectorGenerator, ConnectorTemplate, T> callback) {
    final ConnectorTemplate connectorTemplate = getDataManager().fetch(ConnectorTemplate.class, templateId);
    if (connectorTemplate == null) {
        throw new EntityNotFoundException("Connector template: " + templateId);
    }
    final ConnectorGenerator connectorGenerator = context.getBean(templateId, ConnectorGenerator.class);
    if (connectorGenerator == null) {
        throw new EntityNotFoundException("Unable to find connector generator for connector template with id: " + templateId);
    }
    return callback.apply(connectorGenerator, connectorTemplate);
}
Also used : ConnectorTemplate(io.syndesis.common.model.connection.ConnectorTemplate) ConnectorGenerator(io.syndesis.server.connector.generator.ConnectorGenerator) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 3 with ConnectorTemplate

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

the class CustomConnectorHandlerTest method shouldCreateNewConnectorsBasedOnConnectorTemplates.

@Test
public void shouldCreateNewConnectorsBasedOnConnectorTemplates() {
    final Map<String, ConfigurationProperty> properties = new HashMap<>();
    properties.put("prop1", new ConfigurationProperty.Builder().build());
    final Map<String, ConfigurationProperty> connectorProperties = new HashMap<>();
    connectorProperties.put("prop2", new ConfigurationProperty.Builder().build());
    connectorProperties.put("prop3", new ConfigurationProperty.Builder().build());
    final ConnectorGroup group = new ConnectorGroup.Builder().name("connector template group").build();
    final ConnectorTemplate connectorTemplate = // 
    new ConnectorTemplate.Builder().id(// 
    "connector-template-id").name(// 
    "connector template").properties(properties).connectorProperties(// 
    connectorProperties).connectorGroup(// 
    group).build();
    final ConnectorAction action = new ConnectorAction.Builder().name("action").build();
    when(dataManager.fetch(ConnectorTemplate.class, "connector-template-id")).thenReturn(connectorTemplate);
    when(dataManager.create(any(Connector.class))).thenAnswer(invocation -> invocation.getArgumentAt(0, Connector.class));
    when(applicationContext.getBean("connector-template-id", ConnectorGenerator.class)).thenReturn(new ConnectorGenerator() {

        @Override
        public Connector generate(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) {
            return new Connector.Builder().createFrom(baseConnectorFrom(connectorTemplate, connectorSettings)).putAllProperties(connectorProperties).putConfiguredProperty("prop1", "value1").addAction(action).build();
        }

        @Override
        public ConnectorSummary info(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) {
            return null;
        }
    });
    final Connector created = // 
    new CustomConnectorHandler(dataManager, applicationContext, iconDao).create(// 
    new ConnectorSettings.Builder().connectorTemplateId(// 
    "connector-template-id").name(// 
    "new connector").description(// 
    "new connector description").icon(// 
    "new connector icon").putConfiguredProperty("prop1", // 
    "value1").putConfiguredProperty("unknown-prop", // 
    "unknown-value").build());
    final Connector expected = // 
    new Connector.Builder().id(// 
    created.getId()).name(// 
    "new connector").description(// 
    "new connector description").icon(// 
    "new connector icon").connectorGroup(// 
    group).properties(// 
    connectorProperties).putConfiguredProperty("prop1", // 
    "value1").addAction(// 
    action).build();
    assertThat(created).isEqualTo(expected);
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Connector(io.syndesis.common.model.connection.Connector) HashMap(java.util.HashMap) ConnectorGenerator(io.syndesis.server.connector.generator.ConnectorGenerator) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) ConnectorSummary(io.syndesis.common.model.connection.ConnectorSummary) ConnectorTemplate(io.syndesis.common.model.connection.ConnectorTemplate) ConnectorGroup(io.syndesis.common.model.connection.ConnectorGroup) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Test(org.junit.Test)

Example 4 with ConnectorTemplate

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

the class Application method generateIntegrationProject.

private void generateIntegrationProject(File project) throws IOException {
    final ReadApiClientData reader = new ReadApiClientData();
    final ArrayList<Step> steps = new ArrayList<>();
    String deploymentText;
    try (InputStream is = resourceLoader.getResource("io/syndesis/server/dao/deployment.json").getInputStream()) {
        deploymentText = reader.from(is);
    }
    final List<ModelData<?>> modelList = reader.readDataFromString(deploymentText);
    for (final ModelData<?> model : modelList) {
        if (model.getKind() == Kind.Connector) {
            final Connector connector = (Connector) model.getData();
            for (final Action action : connector.getActions()) {
                steps.add(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().connector(connector).connectorId(connector.getId().get()).build()).action(action).build());
            }
        }
        if (model.getKind() == Kind.ConnectorTemplate) {
            final ConnectorTemplate template = (ConnectorTemplate) model.getData();
            steps.add(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().connectorId("connector-" + template.getId()).build()).action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().camelConnectorGAV(template.getCamelConnectorGAV()).camelConnectorPrefix(template.getCamelConnectorPrefix()).build()).build()).build());
        }
    }
    try {
        final ResourcePatternResolver resolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
        final Resource[] resources = resolver.getResources("classpath:/META-INF/syndesis/connector/*.json");
        if (resources != null) {
            for (Resource resource : resources) {
                Connector connector = Json.reader().forType(Connector.class).readValue(resource.getInputStream());
                if (connector != null) {
                    for (final Action action : connector.getActions()) {
                        steps.add(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().connector(connector).connectorId(connector.getId().get()).build()).action(action).build());
                    }
                }
            }
        }
    } catch (FileNotFoundException ignored) {
    // ignore
    }
    Integration integration = new Integration.Builder().id("Integration").name("Integration").description("This integration is used to prime the .m2 repo").steps(steps).build();
    generate(integration, project);
}
Also used : ModelData(io.syndesis.common.model.ModelData) Connector(io.syndesis.common.model.connection.Connector) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Action(io.syndesis.common.model.action.Action) Integration(io.syndesis.common.model.integration.Integration) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Connection(io.syndesis.common.model.connection.Connection) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) FileNotFoundException(java.io.FileNotFoundException) Step(io.syndesis.common.model.integration.Step) ConnectorTemplate(io.syndesis.common.model.connection.ConnectorTemplate) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) ReadApiClientData(io.syndesis.server.dao.init.ReadApiClientData)

Example 5 with ConnectorTemplate

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

the class CustomConnectorHandlerTest method shouldProvideInfoAboutAppliedConnectorSettings.

@Test
public void shouldProvideInfoAboutAppliedConnectorSettings() {
    final CustomConnectorHandler handler = new CustomConnectorHandler(dataManager, applicationContext, iconDao);
    final ConnectorGenerator connectorGenerator = mock(ConnectorGenerator.class);
    final ConnectorTemplate template = new ConnectorTemplate.Builder().build();
    final ConnectorSettings connectorSettings = new ConnectorSettings.Builder().connectorTemplateId("connector-template").build();
    final ConnectorSummary preparedSummary = new ConnectorSummary.Builder().build();
    when(dataManager.fetch(ConnectorTemplate.class, "connector-template")).thenReturn(template);
    when(applicationContext.getBean("connector-template", ConnectorGenerator.class)).thenReturn(connectorGenerator);
    when(connectorGenerator.info(same(template), same(connectorSettings))).thenReturn(preparedSummary);
    final ConnectorSummary info = handler.info(connectorSettings);
    assertThat(info).isSameAs(preparedSummary);
}
Also used : ConnectorSummary(io.syndesis.common.model.connection.ConnectorSummary) ConnectorTemplate(io.syndesis.common.model.connection.ConnectorTemplate) ConnectorGenerator(io.syndesis.server.connector.generator.ConnectorGenerator) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) Test(org.junit.Test)

Aggregations

ConnectorTemplate (io.syndesis.common.model.connection.ConnectorTemplate)7 ConnectorGenerator (io.syndesis.server.connector.generator.ConnectorGenerator)4 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)3 Connector (io.syndesis.common.model.connection.Connector)3 ConnectorSettings (io.syndesis.common.model.connection.ConnectorSettings)3 ConnectorSummary (io.syndesis.common.model.connection.ConnectorSummary)3 Action (io.syndesis.common.model.action.Action)2 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Configuration (com.jayway.jsonpath.Configuration)1 JacksonJsonProvider (com.jayway.jsonpath.spi.json.JacksonJsonProvider)1 JacksonMappingProvider (com.jayway.jsonpath.spi.mapper.JacksonMappingProvider)1 HttpMethod (io.swagger.models.HttpMethod)1 Info (io.swagger.models.Info)1 Operation (io.swagger.models.Operation)1 Path (io.swagger.models.Path)1 Swagger (io.swagger.models.Swagger)1 AbstractSerializableParameter (io.swagger.models.parameters.AbstractSerializableParameter)1 BodyParameter (io.swagger.models.parameters.BodyParameter)1