Source:
<code>public void execute(DelegateExecution execution) { Connector connector; IntegrationContext context; String implementation = ((ServiceTask) execution.getCurrentFlowElement()).getImplementation(); String connectorId = StringUtils.substringBefore(implementation, "."); String actionId = StringUtils.substringAfter(implementation, "."); boolean hasMatchingConnectorDefinitions = false; ActionDefinition actionDefinition = null; List<ConnectorDefinition> resultingConnectors = connectorDefinitions.stream().filter(c -> c.getId().equals(connectorId)).collect(Collectors.toList()); <START> if (resultingConnectors == null || resultingConnectors.size() == 0) { <END> context = integrationContextBuilder.from(execution, null); connector = applicationContext.getBean(implementation, Connector.class); } else { hasMatchingConnectorDefinitions = true; if (resultingConnectors.size() != 1) { throw new RuntimeException("Mismatch connector id mapping: " + connectorId); } ConnectorDefinition connectorDefinition = resultingConnectors.get(0); actionDefinition = connectorDefinition.getActions().get(actionId); if (actionDefinition == null) { throw new RuntimeException("Mismatch action id mapping: " + actionId); } context = integrationContextBuilder.from(execution, actionDefinition); connector = applicationContext.getBean(actionDefinition.getName(), Connector.class); } IntegrationContext results = connector.execute(context); Map<String, Object> outBoundVariables = new HashMap<>(); if (!hasMatchingConnectorDefinitions) { outBoundVariables = results.getOutBoundVariables(); } else { for (VariableDefinition variableDefinition : actionDefinition.getOutput()) { Object outBoundVariableValue = results.getOutBoundVariables().get(variableDefinition.getName()); if (outBoundVariableValue != null) { outBoundVariables.put(variableDefinition.getName(), outBoundVariableValue); } } } execution.setVariables(outBoundVariables); leave(execution); }</code><technical_language>This method is complex hard understand IMO. wondering if apply strategy pattern (one covering case hasMatchingConnectorDefinitions another covering case not). logic ok: behaviour if definition is fine</technical_language>

Target:
public void execute(DelegateExecution execution) { Connector connector; IntegrationContext context; String implementation = ((ServiceTask) execution.getCurrentFlowElement()).getImplementation(); Optional<ActionDefinition> actionDefinitionOptional = connectorActionDefinitionFinder.find(implementation, connectorDefinitions); ActionDefinition actionDefinition = null; if (actionDefinitionOptional.isPresent()) { actionDefinition = actionDefinitionOptional.get(); context = integrationContextBuilder.from(execution, actionDefinition); connector = applicationContext.getBean(actionDefinition.getName(), Connector.class); } else { context = integrationContextBuilder.from(execution, null); connector = applicationContext.getBean(implementation, Connector.class); } IntegrationContext results = connector.execute(context); List<VariableDefinition> outBoundVariableDefinitions = actionDefinition == null ? null : actionDefinition.getOutput(); execution.setVariables(variablesMatchHelper.match(results.getOutBoundVariables(), outBoundVariableDefinitions)); leave(execution); }