use of io.syndesis.common.model.connection.ConnectorSummary 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);
}
}
use of io.syndesis.common.model.connection.ConnectorSummary in project syndesis by syndesisio.
the class BaseSwaggerConnectorGeneratorTest method shouldProvideInfoFromPetstoreSwagger.
@Test
public void shouldProvideInfoFromPetstoreSwagger() throws IOException {
final String specification = resource("/swagger/petstore.swagger.json");
final ConnectorSettings connectorSettings = //
new ConnectorSettings.Builder().putConfiguredProperty("specification", //
specification).build();
final ConnectorSummary summary = generator.info(SWAGGER_TEMPLATE, connectorSettings);
final ActionsSummary actionsSummary = new ActionsSummary.Builder().totalActions(20).putActionCountByTag("store", 4).putActionCountByTag("user", 8).putActionCountByTag("pet", 8).build();
final ConnectorSummary expected = //
new ConnectorSummary.Builder().name(//
"Swagger Petstore").actionsSummary(//
actionsSummary).build();
assertThat(summary).isEqualToIgnoringGivenFields(expected, "icon", "description", "properties", "warnings");
assertThat(summary.getIcon()).startsWith("data:image");
assertThat(summary.getDescription()).startsWith("This is a sample server Petstore server");
assertThat(summary.getProperties().keySet()).contains("host", "basePath", "authenticationType", "clientId", "clientSecret", "accessToken", "authorizationEndpoint", "specification");
}
use of io.syndesis.common.model.connection.ConnectorSummary in project syndesis by syndesisio.
the class BaseSwaggerConnectorGeneratorTest method shouldReportErrorsFromInvalidPetstoreSwagger.
@Test
public void shouldReportErrorsFromInvalidPetstoreSwagger() throws IOException {
final String specification = resource("/swagger/invalid/invalid-scheme.petstore.swagger.json");
final ConnectorSettings connectorSettings = //
new ConnectorSettings.Builder().putConfiguredProperty("specification", //
specification).build();
final ConnectorSummary summary = generator.info(SWAGGER_TEMPLATE, connectorSettings);
assertThat(summary.getErrors()).hasSize(1);
assertThat(summary.getWarnings()).isEmpty();
}
use of io.syndesis.common.model.connection.ConnectorSummary in project syndesis by syndesisio.
the class ConnectorHandler method get.
@Override
public Connector get(final String id) {
final Connector connector = augmentedWithUsage(Getter.super.get(id));
final Optional<String> connectorGroupId = connector.getConnectorGroupId();
if (!connectorGroupId.map(applicationContext::containsBean).orElse(false)) {
return connector;
}
final ConnectorSummary summary = new ConnectorSummary.Builder().createFrom(connector).build();
return connector.builder().actionsSummary(summary.getActionsSummary()).build();
}
use of io.syndesis.common.model.connection.ConnectorSummary 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);
}
Aggregations