/** * Fetch the Connectors */ protected static Map<String, Connector> fetchConnectorsMap(DataManager dataManager) { return dataManager.fetchAll(Connector.class).getItems() .stream() .collect(Collectors.toMap(o -> o.getId().get(), Function.identity())); } }
private Connector migrateOldConnectorData(Connector existingConnector, Connector newConnector) { Map<String, String> propValues = new TreeMap<>(existingConnector.getConfiguredProperties()); propValues.keySet().retainAll(newConnector.getProperties().keySet()); if (!propValues.isEmpty()) { return new Connector.Builder() .createFrom(newConnector) .putAllConfiguredProperties(propValues) .build(); } return newConnector; }
public final ConnectorAction mandatoryLookupAction(Connector connector, String actionId) { for (ConnectorAction action : connector.getActions()) { if (action.getId().isPresent() && action.getId().get().equals(actionId)) { return action; } } throw new IllegalArgumentException("Unable to find action: " + actionId); }
private static OAuthApp createOAuthApp(Connector connector) { OAuthApp app = new OAuthApp(); app.id = connector.getId().get(); app.name = connector.getName(); app.icon = connector.getIcon(); app.clientId = connector.propertyTaggedWith(Credentials.CLIENT_ID_TAG).orElse(null); app.clientSecret = connector.propertyTaggedWith(Credentials.CLIENT_SECRET_TAG).orElse(null); return app; }
List<Connector> augmentedWithUsage(final List<Connector> connectors) { ListResult<Integration> integrationListResult = getDataManager().fetchAll(Integration.class); List<Integration> items = integrationListResult.getItems(); final Map<String, Long> connectorUsage = items.stream()// .filter(i -> !i.isDeleted())// .flatMap(i -> i.getUsedConnectorIds().stream())// .collect(Collectors.groupingBy(String::toString, Collectors.counting())); return connectors.stream().map(c -> { final int uses = connectorUsage.getOrDefault(c.getId().get(), 0L).intValue(); return c.builder().uses(uses).build(); }).collect(Collectors.toList()); }
final Map<String, String> generatedConfiguredProperties = generated.getConfiguredProperties(); final String generatedSpecification = generatedConfiguredProperties.get("specification"); final Map<String, String> expectedConfiguredProperties = expected.getConfiguredProperties(); final String expectedSpecification = expectedConfiguredProperties.get("specification"); assertThat(reformatJson(generatedSpecification)).isEqualTo(reformatJson(expectedSpecification)); .containsAllEntriesOf(without(expectedConfiguredProperties, "specification")); assertThat(generated.getProperties().keySet()).as("Expecting the same properties to be generated") .containsOnlyElementsOf(expected.getProperties().keySet()); assertThat(generated.getProperties()).containsAllEntriesOf(expected.getProperties()); assertThat(generated).isEqualToIgnoringGivenFields(expected, "id", "icon", "properties", "configuredProperties", "actions"); assertThat(generated.getIcon()).startsWith("data:image"); assertThat(generated.getActions()).hasSameSizeAs(expected.getActions()); for (final ConnectorAction expectedAction : expected.getActions()) { final String actionId = expectedAction.getId().get().replace("_id_", generated.getId().get()); final Optional<ConnectorAction> maybeGeneratedAction = generated.actionById(actionId); assertThat(maybeGeneratedAction).as("No action with id: " + actionId + " was generated").isPresent();
@SuppressWarnings("unchecked") private io.syndesis.integration.model.steps.Step createConnector(StepVisitorContext visitorContext, Step step, Connection connection, Connector connector, ConnectorAction action) { final Map<String, String> properties = aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties()); final String scheme = Optionals.first(action.getDescriptor().getComponentScheme(), connector.getComponentScheme()).get(); // if the option is marked as secret use property placeholder as the // value is added to the integration secret. if (visitorContext.getGeneratorContext().getGeneratorProperties().isSecretMaskingEnabled()) { properties.entrySet() .stream() .filter(Predicates.or(connector::isSecret, action::isSecret)) .forEach(e -> e.setValue(String.format("{{%s-%d.%s}}", scheme, visitorContext.getIndex(), e.getKey()))); } //Connector/Action properties have the precedence connector.getConfiguredProperties().forEach(properties::put); action.getDescriptor().getConfiguredProperties().forEach(properties::put); return new io.syndesis.camel.component.proxy.runtime.Connector( scheme + "-" + visitorContext.getIndex(), scheme, Map.class.cast(properties), Optionals.first(action.getDescriptor().getConnectorFactory(), connector.getConnectorFactory()).orElse(null), action.getDescriptor().getConnectorCustomizers() ); }
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, descriptor); final List<String> customizers = CollectionsUtils.aggregate(ArrayList::new, connector.getConnectorCustomizers(), descriptor.getConnectorCustomizers()); final Map<String, String> properties = CollectionsUtils.aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties()); connector.getConfiguredProperties().forEach(properties::put); descriptor.getConfiguredProperties().forEach(properties::put);
protected final Connector basicConnector(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) { final Swagger swagger = parseSpecification(connectorSettings, false).getModel(); // could be either JSON of the Swagger specification or a URL to one final String specification = requiredSpecification(connectorSettings); if (specification.startsWith("http")) { swagger.vendorExtension(URL_EXTENSION, URI.create(specification)); } final Connector baseConnector = baseConnectorFrom(connectorTemplate, connectorSettings); final Connector.Builder builder = new Connector.Builder().createFrom(baseConnector); final Map<String, String> alreadyConfiguredProperties = builder.build().getConfiguredProperties(); connectorTemplate.getConnectorProperties().forEach((propertyName, template) -> { final Optional<ConfigurationProperty> maybeProperty = PropertyGenerators.createProperty(propertyName, swagger, template); maybeProperty.ifPresent(property -> { builder.putProperty(propertyName, property); if (!alreadyConfiguredProperties.containsKey(propertyName)) { final String defaultValue = property.getDefaultValue(); if (defaultValue != null) { builder.putConfiguredProperty(propertyName, defaultValue); } } }); }); return builder.build(); }
@Test public void getTwitterConnector() { Connector connector = dataManager.fetch(Connector.class, "twitter"); Assert.assertEquals("First Connector in the deployment.json is Twitter", "Twitter", connector.getName()); Assert.assertEquals(2, connector.getActions().size()); }
@Override public boolean canHandle(Step step) { if (!"endpoint".equals(step.getStepKind()) && !"connector".equals(step.getStepKind())) { return false; } if (!step.getConnection().isPresent()) { return false; } if (!step.getConnection().get().getConnector().isPresent()) { return false; } if (!step.getAction().filter(ConnectorAction.class::isInstance).isPresent()) { return false; } return Optionals.first( step.getAction().filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).get().getDescriptor().getComponentScheme(), step.getConnection().get().getConnector().get().getComponentScheme() ).isPresent(); }
final String componentScheme = action.getDescriptor().getCamelConnectorPrefix(); final Map<String, String> configuredProperties = CollectionsUtils.aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties()); final Map<String, String> properties = CollectionsUtils.aggregate(connector.filterEndpointProperties(configuredProperties), action.filterEndpointProperties(configuredProperties));
@GET @Produces(MediaType.APPLICATION_JSON) @Path(value = "/{connectorId}/actions/{actionId}/filters/options") public FilterOptions getFilterOptions(@PathParam("connectorId") @ApiParam(required = true) final String connectorId, @PathParam("actionId") @ApiParam(required = true) final String actionId) { final FilterOptions.Builder builder = new FilterOptions.Builder().addOp(Op.DEFAULT_OPTS); final Connector connector = getDataManager().fetch(Connector.class, connectorId); if (connector == null) { return builder.build(); } connector.actionById(actionId).filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).ifPresent(action -> { action.getOutputDataShape().ifPresent(dataShape -> { final List<String> paths = inspectors.getPaths(dataShape.getKind().toString(), dataShape.getType(), dataShape.getSpecification(), dataShape.getExemplar()); builder.addAllPaths(paths); }); }); return builder.build(); }
protected final Connector basicConnector(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) { final Swagger swagger = parseSpecification(connectorSettings, false).getModel(); // could be either JSON of the Swagger specification or a URL to one final String specification = requiredSpecification(connectorSettings); if (specification.startsWith("http")) { swagger.vendorExtension(URL_EXTENSION, URI.create(specification)); } final Connector baseConnector = baseConnectorFrom(connectorTemplate, connectorSettings); final Connector.Builder builder = new Connector.Builder().createFrom(baseConnector); final Map<String, String> alreadyConfiguredProperties = builder.build().getConfiguredProperties(); connectorTemplate.getConnectorProperties().forEach((propertyName, template) -> { final Optional<ConfigurationProperty> maybeProperty = PropertyGenerators.createProperty(propertyName, swagger, template); maybeProperty.ifPresent(property -> { builder.putProperty(propertyName, property); if (!alreadyConfiguredProperties.containsKey(propertyName)) { final String defaultValue = property.getDefaultValue(); if (defaultValue != null) { builder.putConfiguredProperty(propertyName, defaultValue); } } }); }); return builder.build(); }
@Test public void getSalesforceConnector() { Connector connector = dataManager.fetch(Connector.class, "salesforce"); Assert.assertEquals("Second Connector in the deployment.json is Salesforce", "Salesforce", connector.getName()); Assert.assertEquals(10, connector.getActions().size()); }
@Override public boolean canHandle(Step step) { if (!"endpoint".equals(step.getStepKind()) && !"connector".equals(step.getStepKind())) { return false; } if (!step.getConnection().isPresent()) { return false; } if (!step.getConnection().get().getConnector().isPresent()) { return false; } if (!step.getAction().filter(ConnectorAction.class::isInstance).isPresent()) { return false; } return !Optionals.first( step.getAction().filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).get().getDescriptor().getComponentScheme(), step.getConnection().get().getConnector().get().getComponentScheme() ).isPresent(); }
@SuppressWarnings("unchecked") private io.syndesis.integration.model.steps.Step createEndpoint(StepVisitorContext visitorContext, Step step, Connection connection, Connector connector, ConnectorAction action) { final Map<String, String> configuredProperties = aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties()); final Map<String, String> properties = aggregate(connector.filterEndpointProperties(configuredProperties), action.filterEndpointProperties(configuredProperties)); final String componentScheme = action.getDescriptor().getCamelConnectorPrefix(); // if the option is marked as secret use property placeholder as the // value is added to the integration secret. if (visitorContext.getGeneratorContext().getGeneratorProperties().isSecretMaskingEnabled()) { properties.entrySet() .stream() .filter(Predicates.or(connector::isEndpointProperty, action::isEndpointProperty)) .filter(Predicates.or(connector::isSecret, action::isSecret)) .forEach(e -> e.setValue(String.format("{{%s-%d.%s}}", componentScheme, visitorContext.getIndex(), e.getKey()))); } // any configuredProperties on action descriptor are considered final ConnectorDescriptor descriptor = action.getDescriptor(); properties.putAll(descriptor.getConfiguredProperties()); if (hasComponentProperties(configuredProperties, connector, action)) { return new io.syndesis.integration.model.steps.Endpoint(String.format("%s-%d", componentScheme, visitorContext.getIndex()), Map.class.cast(properties)); } else { return new io.syndesis.integration.model.steps.Endpoint(componentScheme, Map.class.cast(properties)); } }
/** * Fetch the Connectors */ protected static Map<String, Connector> fetchConnectorsMap(DataManager dataManager) { return dataManager.fetchAll(Connector.class).getItems() .stream() .collect(Collectors.toMap(o -> o.getId().get(), Function.identity())); } }
@Test public void shouldIncorporateGivenConfiguredProperties() throws IOException { final String specification = resource("/swagger/reverb.swagger.yaml"); final ConnectorSettings connectorSettings = new ConnectorSettings.Builder()// .name("Reverb API")// .description("Invokes Reverb API")// .icon("fa-music")// .putConfiguredProperty("specification", specification)// .putConfiguredProperty("tokenEndpoint", "http://some.token.url").build(); final Connector connector = generator.generate(SWAGGER_TEMPLATE, connectorSettings); assertThat(connector.getConfiguredProperties()).containsEntry("tokenEndpoint", "http://some.token.url"); }