Skip to content

Fix Groovy DSL for new splitter style #8669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import org.springframework.integration.dsl.ResequencerSpec
import org.springframework.integration.dsl.RouterSpec
import org.springframework.integration.dsl.ScatterGatherSpec
import org.springframework.integration.dsl.SplitterEndpointSpec
import org.springframework.integration.dsl.SplitterSpec
import org.springframework.integration.dsl.TransformerEndpointSpec
import org.springframework.integration.dsl.WireTapSpec
import org.springframework.integration.filter.MethodInvokingSelector
Expand Down Expand Up @@ -710,18 +711,47 @@ class GroovyIntegrationFlowDefinition {
this
}

/**
* Populate the {@link DefaultMessageSplitter} with default options to the current integration flow position.
*/
GroovyIntegrationFlowDefinition split() {
this.delegate.split()
this
}

/**
* Populate the {@link DefaultMessageSplitter} with provided options
* to the current integration flow position.
* Used with a Closure expression (optional).
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
* and for {@link DefaultMessageSplitter}.
* @since 6.2
* @see SplitterSpec
*/
GroovyIntegrationFlowDefinition splitWith(
@DelegatesTo(value = SplitterSpec, strategy = Closure.DELEGATE_FIRST)
@ClosureParams(value = SimpleType.class, options = 'org.springframework.integration.dsl.SplitterSpec')
Closure<?> splitConfigurer) {

this.delegate.splitWith createConfigurerIfAny(splitConfigurer)
this
}

/**
* Populate the {@link DefaultMessageSplitter} with provided options
* to the current integration flow position.
* Used with a Closure expression.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
* and for {@link DefaultMessageSplitter}.
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
* @see SplitterEndpointSpec
*/
@Deprecated(since = '6.2', forRemoval = true)
@SuppressWarnings(['removal', 'deprecation'])
GroovyIntegrationFlowDefinition split(
@DelegatesTo(value = SplitterEndpointSpec<DefaultMessageSplitter>, strategy = Closure.DELEGATE_FIRST)
@ClosureParams(value = SimpleType.class, options = 'org.springframework.integration.dsl.SplitterEndpointSpec')
Closure<?> endpointConfigurer = null) {
Closure<?> endpointConfigurer) {

this.delegate.split createConfigurerIfAny(endpointConfigurer)
this
Expand All @@ -733,7 +763,10 @@ class GroovyIntegrationFlowDefinition {
* @param expression the splitter SpEL expression.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
* and for {@link ExpressionEvaluatingSplitter}.
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
*/
@Deprecated(since = '6.2', forRemoval = true)
@SuppressWarnings(['removal', 'deprecation'])
GroovyIntegrationFlowDefinition split(
String expression,
@DelegatesTo(value = SplitterEndpointSpec<ExpressionEvaluatingSplitter>, strategy = Closure.DELEGATE_FIRST)
Expand All @@ -752,7 +785,10 @@ class GroovyIntegrationFlowDefinition {
* @param methodName the method to invoke.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
* and for {@link MethodInvokingSplitter}.
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
*/
@Deprecated(since = '6.2', forRemoval = true)
@SuppressWarnings(['removal', 'deprecation'])
GroovyIntegrationFlowDefinition split(
Object service, String methodName = null,
@DelegatesTo(value = SplitterEndpointSpec<MethodInvokingSplitter>, strategy = Closure.DELEGATE_FIRST)
Expand All @@ -772,7 +808,10 @@ class GroovyIntegrationFlowDefinition {
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
* and for {@link MethodInvokingSplitter}.
* @see org.springframework.integration.dsl.SplitterEndpointSpec
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
*/
@Deprecated(since = '6.2', forRemoval = true)
@SuppressWarnings(['removal', 'deprecation'])
GroovyIntegrationFlowDefinition split(
String beanName, String methodName,
@DelegatesTo(value = SplitterEndpointSpec<MethodInvokingSplitter>, strategy = Closure.DELEGATE_FIRST)
Expand All @@ -791,7 +830,10 @@ class GroovyIntegrationFlowDefinition {
* @param messageProcessorSpec the splitter {@link MessageProcessorSpec}.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
* and for {@link MethodInvokingSplitter}.
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
*/
@Deprecated(since = '6.2', forRemoval = true)
@SuppressWarnings(['removal', 'deprecation'])
GroovyIntegrationFlowDefinition split(
MessageProcessorSpec<?> messageProcessorSpec,
@DelegatesTo(value = SplitterEndpointSpec<MethodInvokingSplitter>, strategy = Closure.DELEGATE_FIRST)
Expand All @@ -811,8 +853,11 @@ class GroovyIntegrationFlowDefinition {
* Conversion to this type will be attempted, if necessary.
* @param splitter the splitter {@link Function}.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
* @param < P > the payload type or {@code Message.class}.
* @param <P> the payload type or {@code Message.class}.
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
*/
@Deprecated(since = '6.2', forRemoval = true)
@SuppressWarnings(['removal', 'deprecation'])
<P> GroovyIntegrationFlowDefinition split(
Class<P> expectedType, Function<P, ?> splitter,
@DelegatesTo(value = SplitterEndpointSpec<MethodInvokingSplitter>, strategy = Closure.DELEGATE_FIRST)
Expand All @@ -830,9 +875,12 @@ class GroovyIntegrationFlowDefinition {
* flow position.
* @param splitterMessageHandlerSpec the {@link MessageHandlerSpec} to populate.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
* @param < S > the {@link AbstractMessageSplitter}
* @param <S> the {@link AbstractMessageSplitter}
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
* @see org.springframework.integration.dsl.SplitterEndpointSpec
*/
@Deprecated(since = '6.2', forRemoval = true)
@SuppressWarnings(['removal', 'deprecation'])
<S extends AbstractMessageSplitter> GroovyIntegrationFlowDefinition split(
MessageHandlerSpec<?, S> splitterMessageHandlerSpec,
@DelegatesTo(value = SplitterEndpointSpec<S>, strategy = Closure.DELEGATE_FIRST)
Expand All @@ -848,9 +896,12 @@ class GroovyIntegrationFlowDefinition {
* flow position.
* @param splitter the {@link AbstractMessageSplitter} to populate.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
* @param < S > the {@link AbstractMessageSplitter}
* @param <S> the {@link AbstractMessageSplitter}
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
* @see org.springframework.integration.dsl.SplitterEndpointSpec
*/
@Deprecated(since = '6.2', forRemoval = true)
@SuppressWarnings(['removal', 'deprecation'])
<S extends AbstractMessageSplitter> GroovyIntegrationFlowDefinition split(
S splitter,
@DelegatesTo(value = SplitterEndpointSpec<S>, strategy = Closure.DELEGATE_FIRST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,15 @@ class GroovyDslTests {
transform {
transformer { it.toUpperCase() }
}
split Message<?>, { it.payload }
split Object, { it }, { id 'splitterEndpoint' }
splitWith {
expectedType Message<?>
function { it.payload }
}
splitWith {
expectedType Object
id 'splitterEndpoint'
function { it }
}
resequence()
aggregate {
id 'aggregator'
Expand Down
11 changes: 9 additions & 2 deletions src/reference/asciidoc/groovy-dsl.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,15 @@ functionFlow() {
transformer { it.toUpperCase() }
expectedType String
}
split Message<?>, { it.payload }
split Object, { it }, { id 'splitterEndpoint' }
splitWith {
expectedType Message<?>
function { it.payload }
}
splitWith {
expectedType Object
id 'splitterEndpoint'
function { it }
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this indentation correct?

resequence()
aggregate {
id 'aggregator'
Expand Down
5 changes: 4 additions & 1 deletion src/reference/asciidoc/splitter.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ fun someFlow() =
@Bean
someFlow() {
integrationFlow {
split Message<?>, { it.payload }
splitWith {
expectedType Message<?>
function { it.payload }
}
}
}
----
Expand Down
8 changes: 6 additions & 2 deletions src/reference/asciidoc/zip.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,12 @@ fun unzipFlow(executor: Executor) =
unzipFlow(Executor executor) {
integrationFlow 'unzipChannel',
{
transform new UnZipTransformer()
split new UnZipResultSplitter()
transformWith {
ref new UnZipTransformer()
}
splitWith {
ref new UnZipResultSplitter()
}
channel { executor 'entriesChannel', executor }
}
}
Expand Down