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);
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations