@Test public void shouldCreateBaseConnectorsWithGivenNameAndDescription() { final ConnectorSettings settings = new ConnectorSettings.Builder().name("given-name").description("given-description") .putConfiguredProperty("property2", "value2").build(); final Connector connector = generator.baseConnectorFrom(template, settings); assertThat(connector).isEqualToIgnoringGivenFields( new Connector.Builder() .name("given-name") .description("given-description") .addTags("from-connector") .connectorGroup(template.getConnectorGroup()) .connectorGroupId("template-group") .properties(template.getConnectorProperties()) .putConfiguredProperty("property2", "value2").build(), "id", "icon"); assertThat(connector.getIcon()).isEqualTo("data:image/svg+xml,dummy"); }
protected final Connector baseConnectorFrom(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) { final Set<String> properties = connectorTemplate.getProperties().keySet(); final Map<String, String> configuredProperties = connectorSettings.getConfiguredProperties() .entrySet().stream() .filter(e -> properties.contains(e.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); configuredProperties.putAll(baseConnector.getConfiguredProperties()); final String name = Optional.ofNullable(connectorSettings.getName()) .orElseGet(() -> determineConnectorName(connectorTemplate, connectorSettings)); final String description = Optional.ofNullable(connectorSettings.getDescription()) .orElseGet(() -> determineConnectorDescription(connectorTemplate, connectorSettings)); final Optional<ConnectorGroup> connectorGroup = connectorTemplate.getConnectorGroup(); final String icon; if (connectorSettings.getIcon() != null) { icon = connectorSettings.getIcon(); } else { icon = IconGenerator.generate(connectorTemplate.getId().get(), name); } return new Connector.Builder() .createFrom(baseConnector) .id(KeyGenerator.createKey()) .name(name) .description(description) .icon(icon) .configuredProperties(configuredProperties) .connectorGroup(connectorGroup) .connectorGroupId(connectorGroup.map(ConnectorGroup::getId).orElse(Optional.empty())) .build(); }
ConnectorGenerator { protected final Connector baseConnectorFrom(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) { final Set<String> properties = connectorTemplate.getProperties().keySet(); final Map<String, String> configuredProperties = connectorSettings.getConfiguredProperties() .entrySet().stream() .filter(e -> properties.contains(e.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); configuredProperties.putAll(baseConnector.getConfiguredProperties()); final String name = Optional.ofNullable(connectorSettings.getName()) .orElseGet(() -> determineConnectorName(connectorTemplate, connectorSettings)); final String description = Optional.ofNullable(connectorSettings.getDescription()) .orElseGet(() -> determineConnectorDescription(connectorTemplate, connectorSettings)); final Optional<ConnectorGroup> connectorGroup = connectorTemplate.getConnectorGroup(); final String icon; if (connectorSettings.getIcon() != null) { icon = connectorSettings.getIcon(); } else { icon = IconGenerator.generate(connectorTemplate.getId().get(), name); } return new Connector.Builder() .createFrom(baseConnector) .id(KeyGenerator.createKey()) .name(name) .description(description) .icon(icon) .configuredProperties(configuredProperties) .connectorGroup(connectorGroup) .connectorGroupId(connectorGroup.map(ConnectorGroup::getId).orElse(Optional.empty())) .build(); } }
ConnectorGenerator { protected final Connector baseConnectorFrom(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) { final Set<String> properties = connectorTemplate.getProperties().keySet(); final Map<String, String> configuredProperties = connectorSettings.getConfiguredProperties() .entrySet().stream() .filter(e -> properties.contains(e.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); configuredProperties.putAll(baseConnector.getConfiguredProperties()); final String name = Optional.ofNullable(connectorSettings.getName()) .orElseGet(() -> determineConnectorName(connectorTemplate, connectorSettings)); final String description = Optional.ofNullable(connectorSettings.getDescription()) .orElseGet(() -> determineConnectorDescription(connectorTemplate, connectorSettings)); final Optional<ConnectorGroup> connectorGroup = connectorTemplate.getConnectorGroup(); final String icon; if (connectorSettings.getIcon() != null) { icon = connectorSettings.getIcon(); } else { icon = IconGenerator.generate(connectorTemplate.getId().get(), name); } return new Connector.Builder() .createFrom(baseConnector) .id(KeyGenerator.createKey()) .name(name) .description(description) .icon(icon) .configuredProperties(configuredProperties) .connectorGroup(connectorGroup) .connectorGroupId(connectorGroup.map(ConnectorGroup::getId).orElse(Optional.empty())) .build(); } protected  ConnectorGenerator(final Connector baseConnector); }
ConnectorGenerator { protected final Connector baseConnectorFrom(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) { final Set<String> properties = connectorTemplate.getProperties().keySet(); final Map<String, String> configuredProperties = connectorSettings.getConfiguredProperties() .entrySet().stream() .filter(e -> properties.contains(e.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); configuredProperties.putAll(baseConnector.getConfiguredProperties()); final String name = Optional.ofNullable(connectorSettings.getName()) .orElseGet(() -> determineConnectorName(connectorTemplate, connectorSettings)); final String description = Optional.ofNullable(connectorSettings.getDescription()) .orElseGet(() -> determineConnectorDescription(connectorTemplate, connectorSettings)); final Optional<ConnectorGroup> connectorGroup = connectorTemplate.getConnectorGroup(); final String icon; if (connectorSettings.getIcon() != null) { icon = connectorSettings.getIcon(); } else { icon = IconGenerator.generate(connectorTemplate.getId().get(), name); } return new Connector.Builder() .createFrom(baseConnector) .id(KeyGenerator.createKey()) .name(name) .description(description) .icon(icon) .configuredProperties(configuredProperties) .connectorGroup(connectorGroup) .connectorGroupId(connectorGroup.map(ConnectorGroup::getId).orElse(Optional.empty())) .build(); } protected  ConnectorGenerator(final Connector baseConnector); abstract Connector generate(ConnectorTemplate connectorTemplate, ConnectorSettings connectorSettings); abstract APISummary info(ConnectorTemplate connectorTemplate, ConnectorSettings connectorSettings); }
ConnectorGenerator { protected final Connector baseConnectorFrom(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) { final Set<String> properties = connectorTemplate.getProperties().keySet(); final Map<String, String> configuredProperties = connectorSettings.getConfiguredProperties() .entrySet().stream() .filter(e -> properties.contains(e.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); configuredProperties.putAll(baseConnector.getConfiguredProperties()); final String name = Optional.ofNullable(connectorSettings.getName()) .orElseGet(() -> determineConnectorName(connectorTemplate, connectorSettings)); final String description = Optional.ofNullable(connectorSettings.getDescription()) .orElseGet(() -> determineConnectorDescription(connectorTemplate, connectorSettings)); final Optional<ConnectorGroup> connectorGroup = connectorTemplate.getConnectorGroup(); final String icon; if (connectorSettings.getIcon() != null) { icon = connectorSettings.getIcon(); } else { icon = IconGenerator.generate(connectorTemplate.getId().get(), name); } return new Connector.Builder() .createFrom(baseConnector) .id(KeyGenerator.createKey()) .name(name) .description(description) .icon(icon) .configuredProperties(configuredProperties) .connectorGroup(connectorGroup) .connectorGroupId(connectorGroup.map(ConnectorGroup::getId).orElse(Optional.empty())) .build(); } protected  ConnectorGenerator(final Connector baseConnector); abstract Connector generate(ConnectorTemplate connectorTemplate, ConnectorSettings connectorSettings); abstract APISummary info(ConnectorTemplate connectorTemplate, ConnectorSettings connectorSettings);  }