Split split = one.getSplit().orElse(new Split.Builder().build()); Split anotherSplit = another.getSplit().orElse(new Split.Builder().build()); pair(one.getConnectorId(), another.getConnectorId(), "connector-id"), pair(one.getCamelConnectorGAV(), another.getCamelConnectorGAV(), "camel-connector-gav"), pair(one.getCamelConnectorPrefix(), another.getCamelConnectorPrefix(), "camel-connector-prefix"), pair(one.getComponentScheme(), another.getComponentScheme(), "component-scheme"), pair(one.getConnectorFactory(), another.getConnectorFactory(), "connector-factory"), pair(one.getConnectorCustomizers(), another.getConnectorCustomizers(), "connector-customizers"), pair(one.getInputDataShape(), another.getInputDataShape(), "input-data-shape"), pair(one.getOutputDataShape(), another.getOutputDataShape(), "output-data-shape"), pair(one.getPropertyDefinitionSteps(), another.getPropertyDefinitionSteps(), "property-defn-steps"), pair(one.getConfiguredProperties(), another.getConfiguredProperties(), "configured-properties"));
"descriptor"); assertThat(generatedAction.getDescriptor().getPropertyDefinitionSteps()) .as("Generated and expected action definition property definition steps for action with id: " + actionId + " differs") .isEqualTo(expectedAction.getDescriptor().getPropertyDefinitionSteps()); if (expectedAction.getDescriptor().getInputDataShape().isPresent()) { final DataShape generatedInputDataShape = generatedAction.getDescriptor().getInputDataShape().get(); final DataShape expectedInputDataShape = expectedAction.getDescriptor().getInputDataShape().get(); if (expectedAction.getDescriptor().getOutputDataShape().isPresent()) { final DataShape generatedOutputDataShape = generatedAction.getDescriptor().getOutputDataShape().get(); final DataShape expectedOutputDataShape = expectedAction.getDescriptor().getOutputDataShape().get(); assertThat(generatedOutputDataShape) .as("Generated and expected output data shape for action with id: " + actionId + " differs")
final String scheme = Optionals.first(descriptor.getComponentScheme(), connector.getComponentScheme()).get(); final CamelContext context = builder.getContext(); final String componentId = scheme + "-" + flowIndex + "-" + stepIndex; descriptor.getConfiguredProperties().forEach(properties::put); descriptor.getInputDataShape().ifPresent(ds -> trySetInputDataShape(component, ds)); descriptor.getOutputDataShape().ifPresent(ds -> trySetOutputDataShape(component, ds));
@Test public void shouldSetInoutOutputShapesToAnyIfMetadataCallFails() { @SuppressWarnings({"unchecked", "rawtypes"}) final Class<Entity<Map<String, Object>>> entityType = (Class) Entity.class; ArgumentCaptor.forClass(entityType); // simulates fallback return final DynamicActionMetadata fallback = new DynamicActionMetadata.Builder().build(); when(metadataCommand.execute()).thenReturn(fallback); when(((HystrixInvokableInfo<?>) metadataCommand).isSuccessfulExecution()).thenReturn(false); final Response response = handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE, Collections.emptyMap()); @SuppressWarnings("unchecked") final Meta<ConnectorDescriptor> meta = (Meta<ConnectorDescriptor>) response.getEntity(); final ConnectorDescriptor descriptor = meta.getValue(); assertThat(descriptor.getInputDataShape()).contains(ConnectionActionHandler.ANY_SHAPE); assertThat(descriptor.getOutputDataShape()).contains(salesforceOutputShape); } }
public static void customizeComponent(final CamelContext context, final Connector connector, final ConnectorDescriptor descriptor, final Component component, final Map<String, Object> properties) { final List<String> customizers = CollectionsUtils.aggregate(ArrayList::new, connector.getConnectorCustomizers(), descriptor.getConnectorCustomizers()); // Set input/output data shape if the component proxy implements // Input/OutputDataShapeAware descriptor.getInputDataShape().ifPresent(ds -> trySetInputDataShape(component, ds)); descriptor.getOutputDataShape().ifPresent(ds -> trySetOutputDataShape(component, ds)); for (final String customizerType : customizers) { final ComponentCustomizer<Component> customizer = resolveCustomizer(context, customizerType); // Set the camel context if the customizer implements // the CamelContextAware interface. ObjectHelper.trySetCamelContext(customizer, context); // Set input/output data shape if the customizer implements // Input/OutputDataShapeAware descriptor.getInputDataShape().ifPresent(ds -> trySetInputDataShape(customizer, ds)); descriptor.getOutputDataShape().ifPresent(ds -> trySetOutputDataShape(customizer, ds)); // Try to set properties to the component setProperties(context, customizer, properties); // Invoke the customizer customizer.customize(component, properties); } }
private void from(Object object) { if (object instanceof ConnectorDescriptor) { ConnectorDescriptor instance = (ConnectorDescriptor) object; Optional<String> componentSchemeOptional = instance.getComponentScheme(); if (componentSchemeOptional.isPresent()) { componentScheme(componentSchemeOptional); Optional<String> connectorFactoryOptional = instance.getConnectorFactory(); if (connectorFactoryOptional.isPresent()) { connectorFactory(connectorFactoryOptional); addAllConnectorCustomizers(instance.getConnectorCustomizers()); String connectorIdValue = instance.getConnectorId(); if (connectorIdValue != null) { connectorId(connectorIdValue); String camelConnectorPrefixValue = instance.getCamelConnectorPrefix(); if (camelConnectorPrefixValue != null) { camelConnectorPrefix(camelConnectorPrefixValue); String camelConnectorGAVValue = instance.getCamelConnectorGAV(); if (camelConnectorGAVValue != null) { camelConnectorGAV(camelConnectorGAVValue);
final String componentScheme = action.getDescriptor().getComponentScheme().get(); final Map<String, String> configuredProperties = step.getConfiguredProperties(); final Map<String, String> properties = action.filterEndpointProperties(configuredProperties); properties.putAll(descriptor.getConfiguredProperties());
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)); properties.putAll(descriptor.getConfiguredProperties());
private List<ActionDescriptor.ActionDescriptorStep> getPropertyDefinitionStepsInitialize() { return ConnectorDescriptor.super.getPropertyDefinitionSteps(); }
@Override public boolean canHandle(Step step) { if (StepKind.endpoint != step.getStepKind() && StepKind.connector != step.getStepKind()) { return false; } if (step.getConnection().isPresent()) { return false; } if (!step.getActionAs(ConnectorAction.class).isPresent()) { return false; } ConnectorAction action = step.getActionAs(ConnectorAction.class).get(); if (action.getDescriptor() == null) { return false; } return action.getDescriptor().getComponentScheme().isPresent(); }
private Optional<Step> getConnectorSplitAsStep(Step step) { if (step.getAction().filter(ConnectorAction.class::isInstance).isPresent()) { final ConnectorAction action = step.getAction().filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).get(); final ConnectorDescriptor descriptor = action.getDescriptor(); if (descriptor.getSplit().isPresent()) { final Split split = descriptor.getSplit().get(); final Step.Builder splitBuilder = new Step.Builder().stepKind(StepKind.split); split.getLanguage().ifPresent(s -> splitBuilder.putConfiguredProperty("language", s)); split.getExpression().ifPresent(s -> splitBuilder.putConfiguredProperty("expression", s)); return Optional.of(splitBuilder.build()); } } return Optional.empty(); }
private Map<String, String> getConfiguredPropertiesInitialize() { return ConnectorDescriptor.super.getConfiguredProperties(); }
private List<String> getConnectorCustomizersInitialize() { return ConnectorDescriptor.super.getConnectorCustomizers(); }
private ComponentProxyComponent resolveComponent(String componentId, String componentScheme, CamelContext context, Connector connector, ConnectorDescriptor descriptor) { ComponentProxyFactory factory = ComponentProxyComponent::new; if (descriptor.getConnectorFactory().isPresent()) { factory = resolveComponentProxyFactory(context, descriptor.getConnectorFactory()).orElse(factory); } else if (connector.getConnectorFactory().isPresent()) { factory = resolveComponentProxyFactory(context, connector.getConnectorFactory()).orElse(factory); } return factory.newInstance(componentId, componentScheme); }
"descriptor"); assertThat(generatedAction.getDescriptor().getPropertyDefinitionSteps()) .as("Generated and expected action definition property definition steps for action with id: " + actionId + " differs") .isEqualTo(expectedAction.getDescriptor().getPropertyDefinitionSteps()); if (expectedAction.getDescriptor().getInputDataShape().isPresent()) { final DataShape generatedInputDataShape = generatedAction.getDescriptor().getInputDataShape().get(); final DataShape expectedInputDataShape = expectedAction.getDescriptor().getInputDataShape().get(); if (expectedAction.getDescriptor().getOutputDataShape().isPresent()) { final DataShape generatedOutputDataShape = generatedAction.getDescriptor().getOutputDataShape().get(); final DataShape expectedOutputDataShape = expectedAction.getDescriptor().getOutputDataShape().get(); assertThat(generatedOutputDataShape) .as("Generated and expected output data shape for action with id: " + actionId + " differs")
protected ComponentProxyComponent setUpComponent(String actionId) { Connector connector = mandatoryLookupConnector(); ConnectorAction action = mandatoryLookupAction(connector, actionId); ComponentProxyComponent component = new ComponentProxyComponent("salesforce-1", "salesforce"); component.setBeforeProducer(BEFORE_PROCESSOR); component.setAfterProducer(AFTER_PROCESSOR); DataShapeCustomizer customizer = new DataShapeCustomizer(); customizer.setCamelContext(context()); action.getDescriptor().getInputDataShape().ifPresent(customizer::setInputDataShape); action.getDescriptor().getOutputDataShape().ifPresent(customizer::setOutputDataShape); customizer.customize(component, Collections.emptyMap()); return component; }
public Builder replaceConfigurationProperty( final String propertyName, final Consumer<ConfigurationProperty.Builder> configurationPropertyConfigurator) { final ConnectorDescriptor definition = build(); final List<ActionDescriptorStep> steps = definition.getPropertyDefinitionSteps(); int stepIdx; ActionDescriptorStep step = null; for (stepIdx = 0; stepIdx < steps.size(); stepIdx++) { final ActionDescriptorStep potentialStep = steps.get(stepIdx); final Map<String, ConfigurationProperty> properties = potentialStep.getProperties(); if (properties.containsKey(propertyName)) { step = potentialStep; break; } } if (step == null) { // found no property to replace, lets just ignore it return this; } final ConfigurationProperty configurationProperty = step.getProperties().get(propertyName); final ConfigurationProperty.Builder configurationPropertyModifier = new ConfigurationProperty.Builder().createFrom(configurationProperty); configurationPropertyConfigurator.accept(configurationPropertyModifier); final ActionDescriptorStep.Builder stepModifier = new ActionDescriptorStep.Builder() .createFrom(step) .putProperty(propertyName, configurationPropertyModifier.build()); final List<ActionDescriptorStep> modifiedSteps = new ArrayList<>(steps); modifiedSteps.set(stepIdx, stepModifier.build()); return propertyDefinitionSteps(modifiedSteps); } }
@Override public boolean canHandle(Step step) { if (StepKind.endpoint != step.getStepKind() && StepKind.connector != step.getStepKind()) { return false; } if (!step.getConnection().isPresent()) { return false; } if (!step.getConnection().get().getConnector().isPresent()) { return false; } if (!step.getActionAs(ConnectorAction.class).isPresent()) { return false; } return !Optionals.first( step.getActionAs(ConnectorAction.class).get().getDescriptor().getComponentScheme(), step.getConnection().get().getConnector().get().getComponentScheme() ).isPresent(); }
private Optional<ProcessorDefinition<?>> configureConnectorSplit(Step step, ProcessorDefinition<?> route, String flowIndex, String stepIndex) { if (step.getAction().filter(ConnectorAction.class::isInstance).isPresent()) { final ConnectorAction action = step.getAction().filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).get(); final ConnectorDescriptor descriptor = action.getDescriptor(); if (descriptor.getSplit().isPresent()) { final Split split = descriptor.getSplit().get(); final Step.Builder splitBuilder = new Step.Builder().stepKind(StepKind.split); split.getLanguage().ifPresent(s -> splitBuilder.putConfiguredProperty("language", s)); split.getExpression().ifPresent(s -> splitBuilder.putConfiguredProperty("expression", s)); return new SplitStepHandler().handle( splitBuilder.build(), route, this, flowIndex, stepIndex); } } return Optional.empty(); }
@Override public boolean canHandle(Step step) { if (StepKind.endpoint != step.getStepKind() && StepKind.connector != step.getStepKind()) { return false; } if (!step.getConnection().isPresent()) { return false; } if (!step.getConnection().get().getConnector().isPresent()) { return false; } if (!step.getActionAs(ConnectorAction.class).isPresent()) { return false; } return Optionals.first( step.getActionAs(ConnectorAction.class).get().getDescriptor().getComponentScheme(), step.getConnection().get().getConnector().get().getComponentScheme() ).isPresent(); }