Skip to content

Commit e4ab5b0

Browse files
authored
[Fix serverlessworkflow#1091] Add EmittedEventDecorator (serverlessworkflow#1092)
Signed-off-by: fjtirado <[email protected]>
1 parent e7209d6 commit e4ab5b0

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl.events;
17+
18+
import io.cloudevents.core.builder.CloudEventBuilder;
19+
import io.serverlessworkflow.impl.ServicePriority;
20+
import io.serverlessworkflow.impl.TaskContext;
21+
import io.serverlessworkflow.impl.WorkflowContext;
22+
23+
public interface EmittedEventDecorator extends ServicePriority {
24+
25+
void decorate(
26+
CloudEventBuilder ceBuilder, WorkflowContext workflowContext, TaskContext taskContext);
27+
}

impl/core/src/main/java/io/serverlessworkflow/impl/executors/EmitExecutor.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,24 @@
3333
import io.serverlessworkflow.impl.WorkflowUtils;
3434
import io.serverlessworkflow.impl.WorkflowValueResolver;
3535
import io.serverlessworkflow.impl.events.CloudEventUtils;
36+
import io.serverlessworkflow.impl.events.EmittedEventDecorator;
3637
import io.serverlessworkflow.impl.events.EventPublisher;
3738
import io.serverlessworkflow.impl.expressions.ExpressionDescriptor;
3839
import java.net.URI;
3940
import java.time.OffsetDateTime;
4041
import java.util.Collection;
4142
import java.util.Map;
4243
import java.util.Optional;
44+
import java.util.ServiceLoader;
4345
import java.util.concurrent.CompletableFuture;
4446

4547
public class EmitExecutor extends RegularTaskExecutor<EmitTask> {
4648

49+
private static final Collection<EmittedEventDecorator> emittedDecorators =
50+
ServiceLoader.load(EmittedEventDecorator.class).stream()
51+
.map(ServiceLoader.Provider::get)
52+
.sorted()
53+
.toList();
4754
private final EventPropertiesBuilder props;
4855

4956
public static class EmitExecutorBuilder extends RegularTaskExecutorBuilder<EmitTask> {
@@ -124,7 +131,7 @@ private CloudEvent buildCloudEvent(WorkflowContext workflow, TaskContext taskCon
124131
.additionalFilter()
125132
.map(filter -> filter.apply(workflow, taskContext, taskContext.input()))
126133
.ifPresent(value -> value.forEach((k, v) -> addExtension(ceBuilder, k, v)));
127-
134+
emittedDecorators.forEach(d -> d.decorate(ceBuilder, workflow, taskContext));
128135
return ceBuilder.build();
129136
}
130137

0 commit comments

Comments
 (0)