Search in sources :

Example 6 with ConnectorSettings

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

the class CustomConnectorHandler method info.

@POST
@Path("/info")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation("Provides a summary of the connector as it would be built using a ConnectorTemplate identified by the provided `connector-template-id` and the data given in `connectorSettings`")
public ConnectorSummary info(@MultipartForm final CustomConnectorFormData connectorFormData) {
    try {
        final String specification;
        try (BufferedSource source = Okio.buffer(Okio.source(connectorFormData.getSpecification()))) {
            specification = source.readUtf8();
        }
        final ConnectorSettings connectorSettings = new ConnectorSettings.Builder().createFrom(connectorFormData.getConnectorSettings()).putConfiguredProperty("specification", specification).build();
        return withGeneratorAndTemplate(connectorSettings.getConnectorTemplateId(), (generator, template) -> generator.info(template, connectorSettings));
    } catch (IOException e) {
        throw SyndesisServerException.launderThrowable("Failed to read specification", e);
    }
}
Also used : IOException(java.io.IOException) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) BufferedSource(okio.BufferedSource) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation)

Example 7 with ConnectorSettings

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

the class CustomConnectorITCase method shouldOfferCustomConnectorInfo.

@Test
public void shouldOfferCustomConnectorInfo() {
    final ConnectorSettings connectorSettings = new ConnectorSettings.Builder().connectorTemplateId(TEMPLATE_ID).icon("test-icon").build();
    final ResponseEntity<ConnectorSummary> response = post("/api/v1/connectors/custom/info", connectorSettings, ConnectorSummary.class);
    final ConnectorSummary expected = // \
    new ConnectorSummary.Builder().name(// 
    "test-name").description(// 
    "test-description").icon(// 
    "test-icon").putProperty("property1", // 
    TestConfiguration.PROPERTY_1).actionsSummary(// 
    TestConfiguration.ACTIONS_SUMMARY).build();
    assertThat(response.getBody()).isEqualTo(expected);
}
Also used : ConnectorSummary(io.syndesis.common.model.connection.ConnectorSummary) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) Test(org.junit.Test)

Example 8 with ConnectorSettings

use of io.syndesis.common.model.connection.ConnectorSettings 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 9 with ConnectorSettings

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

the class CustomConnectorHandler method create.

@POST
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation("Creates a new Connector based on the ConnectorTemplate identified by the provided `id` and the data given in `connectorSettings` multipart part, plus optional `icon` file")
@ApiResponses(@ApiResponse(code = 200, response = Connector.class, message = "Newly created Connector"))
public Connector create(@MultipartForm CustomConnectorFormData customConnectorFormData) throws IOException {
    final ConnectorSettings connectorSettings = customConnectorFormData.getConnectorSettings();
    if (connectorSettings == null) {
        throw new IllegalArgumentException("Missing connectorSettings parameter");
    }
    final ConnectorSettings connectorSettingsToUse;
    if (connectorSettings.getConfiguredProperties().containsKey("specification")) {
        connectorSettingsToUse = connectorSettings;
    } else {
        final String specification;
        try (BufferedSource source = Okio.buffer(Okio.source(customConnectorFormData.getSpecification()))) {
            specification = source.readUtf8();
        }
        connectorSettingsToUse = new ConnectorSettings.Builder().createFrom(connectorSettings).putConfiguredProperty("specification", specification).build();
    }
    Connector generatedConnector = withGeneratorAndTemplate(connectorSettingsToUse.getConnectorTemplateId(), (generator, template) -> generator.generate(template, connectorSettingsToUse));
    if (customConnectorFormData.getIconInputStream() != null) {
        // can continue to be used, rather than being consumed.
        try (BufferedInputStream iconStream = new BufferedInputStream(customConnectorFormData.getIconInputStream())) {
            String guessedMediaType = URLConnection.guessContentTypeFromStream(iconStream);
            if (!guessedMediaType.startsWith("image/")) {
                throw new IllegalArgumentException("Invalid file contents for an image");
            }
            MediaType mediaType = MediaType.valueOf(guessedMediaType);
            Icon.Builder iconBuilder = new Icon.Builder().mediaType(mediaType.toString());
            Icon icon = getDataManager().create(iconBuilder.build());
            iconDao.write(icon.getId().get(), iconStream);
            generatedConnector = new Connector.Builder().createFrom(generatedConnector).icon("db:" + icon.getId().get()).build();
        } catch (IOException e) {
            throw new IllegalArgumentException("Error while reading multipart request", e);
        }
    }
    return getDataManager().create(generatedConnector);
}
Also used : Connector(io.syndesis.common.model.connection.Connector) BufferedInputStream(java.io.BufferedInputStream) MediaType(javax.ws.rs.core.MediaType) Icon(io.syndesis.common.model.icon.Icon) IOException(java.io.IOException) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) BufferedSource(okio.BufferedSource) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 10 with ConnectorSettings

use of io.syndesis.common.model.connection.ConnectorSettings 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

ConnectorSettings (io.syndesis.common.model.connection.ConnectorSettings)16 Test (org.junit.Test)12 Connector (io.syndesis.common.model.connection.Connector)10 ConnectorSummary (io.syndesis.common.model.connection.ConnectorSummary)7 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)3 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)3 ConnectorTemplate (io.syndesis.common.model.connection.ConnectorTemplate)3 ConnectorGenerator (io.syndesis.server.connector.generator.ConnectorGenerator)3 ApiOperation (io.swagger.annotations.ApiOperation)2 DataShape (io.syndesis.common.model.DataShape)2 ActionsSummary (io.syndesis.common.model.action.ActionsSummary)2 IOException (java.io.IOException)2 ApiResponses (io.swagger.annotations.ApiResponses)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