Skip to content

Commit f519a41

Browse files
authored
Merge pull request #642 from fjtirado/Fix_#636
[Fix #636] Refactor to separate Jackson/JQ from core
2 parents 6b9394b + 225b29b commit f519a41

File tree

82 files changed

+1353
-525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1353
-525
lines changed

examples/events/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<dependencies>
1212
<dependency>
1313
<groupId>io.serverlessworkflow</groupId>
14-
<artifactId>serverlessworkflow-impl-core</artifactId>
14+
<artifactId>serverlessworkflow-impl-jackson</artifactId>
1515
</dependency>
1616
<dependency>
1717
<groupId>org.slf4j</groupId>

examples/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
<artifactId>serverlessworkflow-impl-http</artifactId>
2222
<version>${project.version}</version>
2323
</dependency>
24+
<dependency>
25+
<groupId>io.serverlessworkflow</groupId>
26+
<artifactId>serverlessworkflow-impl-jackson</artifactId>
27+
<version>${project.version}</version>
28+
</dependency>
2429
<dependency>
2530
<groupId>org.slf4j</groupId>
2631
<artifactId>slf4j-simple</artifactId>

examples/simpleGet/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<dependencies>
1212
<dependency>
1313
<groupId>io.serverlessworkflow</groupId>
14-
<artifactId>serverlessworkflow-impl-core</artifactId>
14+
<artifactId>serverlessworkflow-impl-jackson</artifactId>
1515
</dependency>
1616
<dependency>
1717
<groupId>io.serverlessworkflow</groupId>

impl/core/pom.xml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,23 @@
88
<artifactId>serverlessworkflow-impl-core</artifactId>
99
<name>Serverless Workflow :: Impl :: Core</name>
1010
<dependencies>
11-
<dependency>
12-
<groupId>io.serverlessworkflow</groupId>
13-
<artifactId>serverlessworkflow-api</artifactId>
14-
<version>${project.version}</version>
11+
<dependency>
12+
<groupId>io.serverlessworkflow</groupId>
13+
<artifactId>serverlessworkflow-types</artifactId>
14+
<version>${project.version}</version>
1515
</dependency>
1616
<dependency>
1717
<groupId>io.cloudevents</groupId>
18-
<artifactId>cloudevents-api</artifactId>
18+
<artifactId>cloudevents-core</artifactId>
1919
</dependency>
2020
<dependency>
21-
<groupId>io.cloudevents</groupId>
22-
<artifactId>cloudevents-json-jackson</artifactId>
21+
<groupId>org.slf4j</groupId>
22+
<artifactId>slf4j-api</artifactId>
2323
</dependency>
2424
<dependency>
2525
<groupId>com.github.f4b6a3</groupId>
2626
<artifactId>ulid-creator</artifactId>
2727
</dependency>
28-
<dependency>
29-
<groupId>com.networknt</groupId>
30-
<artifactId>json-schema-validator</artifactId>
31-
</dependency>
32-
<dependency>
33-
<groupId>net.thisptr</groupId>
34-
<artifactId>jackson-jq</artifactId>
35-
</dependency>
3628
<dependency>
3729
<groupId>org.junit.jupiter</groupId>
3830
<artifactId>junit-jupiter-api</artifactId>

impl/core/src/main/java/io/serverlessworkflow/impl/TaskContext.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package io.serverlessworkflow.impl;
1717

18-
import com.fasterxml.jackson.databind.JsonNode;
1918
import io.serverlessworkflow.api.types.TaskBase;
2019
import io.serverlessworkflow.impl.executors.TransitionInfo;
2120
import java.time.Instant;
@@ -25,22 +24,22 @@
2524

2625
public class TaskContext {
2726

28-
private final JsonNode rawInput;
27+
private final WorkflowModel rawInput;
2928
private final TaskBase task;
3029
private final WorkflowPosition position;
3130
private final Instant startedAt;
3231
private final String taskName;
3332
private final Map<String, Object> contextVariables;
3433
private final Optional<TaskContext> parentContext;
3534

36-
private JsonNode input;
37-
private JsonNode output;
38-
private JsonNode rawOutput;
35+
private WorkflowModel input;
36+
private WorkflowModel output;
37+
private WorkflowModel rawOutput;
3938
private Instant completedAt;
4039
private TransitionInfo transition;
4140

4241
public TaskContext(
43-
JsonNode input,
42+
WorkflowModel input,
4443
WorkflowPosition position,
4544
Optional<TaskContext> parentContext,
4645
String taskName,
@@ -49,15 +48,15 @@ public TaskContext(
4948
}
5049

5150
private TaskContext(
52-
JsonNode rawInput,
51+
WorkflowModel rawInput,
5352
Optional<TaskContext> parentContext,
5453
String taskName,
5554
TaskBase task,
5655
WorkflowPosition position,
5756
Instant startedAt,
58-
JsonNode input,
59-
JsonNode output,
60-
JsonNode rawOutput) {
57+
WorkflowModel input,
58+
WorkflowModel output,
59+
WorkflowModel rawOutput) {
6160
this.rawInput = rawInput;
6261
this.parentContext = parentContext;
6362
this.taskName = taskName;
@@ -76,40 +75,40 @@ public TaskContext copy() {
7675
rawInput, parentContext, taskName, task, position, startedAt, input, output, rawOutput);
7776
}
7877

79-
public void input(JsonNode input) {
78+
public void input(WorkflowModel input) {
8079
this.input = input;
8180
this.rawOutput = input;
8281
this.output = input;
8382
}
8483

85-
public JsonNode input() {
84+
public WorkflowModel input() {
8685
return input;
8786
}
8887

89-
public JsonNode rawInput() {
88+
public WorkflowModel rawInput() {
9089
return rawInput;
9190
}
9291

9392
public TaskBase task() {
9493
return task;
9594
}
9695

97-
public TaskContext rawOutput(JsonNode output) {
96+
public TaskContext rawOutput(WorkflowModel output) {
9897
this.rawOutput = output;
9998
this.output = output;
10099
return this;
101100
}
102101

103-
public JsonNode rawOutput() {
102+
public WorkflowModel rawOutput() {
104103
return rawOutput;
105104
}
106105

107-
public TaskContext output(JsonNode output) {
106+
public TaskContext output(WorkflowModel output) {
108107
this.output = output;
109108
return this;
110109
}
111110

112-
public JsonNode output() {
111+
public WorkflowModel output() {
113112
return output;
114113
}
115114

impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowApplication.java

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,25 @@
1717

1818
import com.github.f4b6a3.ulid.UlidCreator;
1919
import io.serverlessworkflow.api.types.Document;
20+
import io.serverlessworkflow.api.types.SchemaInline;
2021
import io.serverlessworkflow.api.types.Workflow;
2122
import io.serverlessworkflow.impl.events.EventConsumer;
2223
import io.serverlessworkflow.impl.events.EventPublisher;
2324
import io.serverlessworkflow.impl.events.InMemoryEvents;
2425
import io.serverlessworkflow.impl.executors.DefaultTaskExecutorFactory;
2526
import io.serverlessworkflow.impl.executors.TaskExecutorFactory;
2627
import io.serverlessworkflow.impl.expressions.ExpressionFactory;
27-
import io.serverlessworkflow.impl.expressions.JQExpressionFactory;
2828
import io.serverlessworkflow.impl.expressions.RuntimeDescriptor;
29-
import io.serverlessworkflow.impl.jsonschema.DefaultSchemaValidatorFactory;
30-
import io.serverlessworkflow.impl.jsonschema.SchemaValidatorFactory;
3129
import io.serverlessworkflow.impl.resources.DefaultResourceLoaderFactory;
3230
import io.serverlessworkflow.impl.resources.ResourceLoaderFactory;
31+
import io.serverlessworkflow.impl.resources.StaticResource;
32+
import io.serverlessworkflow.impl.schema.SchemaValidator;
33+
import io.serverlessworkflow.impl.schema.SchemaValidatorFactory;
3334
import java.util.Collection;
3435
import java.util.Collections;
3536
import java.util.HashSet;
3637
import java.util.Map;
38+
import java.util.ServiceLoader;
3739
import java.util.concurrent.ConcurrentHashMap;
3840
import java.util.concurrent.ExecutorService;
3941
import java.util.concurrent.Executors;
@@ -101,11 +103,31 @@ public WorkflowIdFactory idFactory() {
101103
}
102104

103105
public static class Builder {
106+
private static final SchemaValidatorFactory EMPTY_SCHEMA_VALIDATOR =
107+
new SchemaValidatorFactory() {
108+
109+
private final SchemaValidator NoValidation =
110+
new SchemaValidator() {
111+
@Override
112+
public void validate(WorkflowModel node) {}
113+
};
114+
115+
@Override
116+
public SchemaValidator getValidator(StaticResource resource) {
117+
118+
return NoValidation;
119+
}
120+
121+
@Override
122+
public SchemaValidator getValidator(SchemaInline inline) {
123+
return NoValidation;
124+
}
125+
};
104126
private TaskExecutorFactory taskFactory = DefaultTaskExecutorFactory.get();
105-
private ExpressionFactory exprFactory = JQExpressionFactory.get();
127+
private ExpressionFactory exprFactory;
106128
private Collection<WorkflowExecutionListener> listeners;
107129
private ResourceLoaderFactory resourceLoaderFactory = DefaultResourceLoaderFactory.get();
108-
private SchemaValidatorFactory schemaValidatorFactory = DefaultSchemaValidatorFactory.get();
130+
private SchemaValidatorFactory schemaValidatorFactory;
109131
private WorkflowPositionFactory positionFactory = () -> new QueueWorkflowPosition();
110132
private WorkflowIdFactory idFactory = () -> UlidCreator.getMonotonicUlid().toString();
111133
private ExecutorServiceFactory executorFactory = () -> Executors.newCachedThreadPool();
@@ -175,6 +197,18 @@ public Builder withEventPublisher(EventPublisher eventPublisher) {
175197
}
176198

177199
public WorkflowApplication build() {
200+
if (exprFactory == null) {
201+
exprFactory =
202+
ServiceLoader.load(ExpressionFactory.class)
203+
.findFirst()
204+
.orElseThrow(() -> new IllegalStateException("Expression factory is required"));
205+
}
206+
if (schemaValidatorFactory == null) {
207+
schemaValidatorFactory =
208+
ServiceLoader.load(SchemaValidatorFactory.class)
209+
.findFirst()
210+
.orElse(EMPTY_SCHEMA_VALIDATOR);
211+
}
178212
return new WorkflowApplication(this);
179213
}
180214
}
@@ -202,6 +236,10 @@ public WorkflowPositionFactory positionFactory() {
202236
return positionFactory;
203237
}
204238

239+
public WorkflowModelFactory modelFactory() {
240+
return exprFactory.modelFactory();
241+
}
242+
205243
public RuntimeDescriptorFactory runtimeDescriptorFactory() {
206244
return runtimeDescriptorFactory;
207245
}

impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowContext.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
*/
1616
package io.serverlessworkflow.impl;
1717

18-
import com.fasterxml.jackson.databind.JsonNode;
19-
2018
public class WorkflowContext {
2119
private final WorkflowDefinition definition;
2220
private final WorkflowInstance instance;
23-
private JsonNode context;
21+
private WorkflowModel context;
2422

2523
WorkflowContext(WorkflowDefinition definition, WorkflowInstance instance) {
2624
this.definition = definition;
@@ -31,11 +29,11 @@ public WorkflowInstance instance() {
3129
return instance;
3230
}
3331

34-
public JsonNode context() {
32+
public WorkflowModel context() {
3533
return context;
3634
}
3735

38-
public void context(JsonNode context) {
36+
public void context(WorkflowModel context) {
3937
this.context = context;
4038
}
4139

impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowDefinition.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
import io.serverlessworkflow.api.types.Workflow;
2323
import io.serverlessworkflow.impl.executors.TaskExecutor;
2424
import io.serverlessworkflow.impl.executors.TaskExecutorHelper;
25-
import io.serverlessworkflow.impl.json.JsonUtils;
26-
import io.serverlessworkflow.impl.jsonschema.SchemaValidator;
2725
import io.serverlessworkflow.impl.resources.ResourceLoader;
26+
import io.serverlessworkflow.impl.schema.SchemaValidator;
2827
import java.nio.file.Path;
2928
import java.util.Collection;
3029
import java.util.Optional;
@@ -47,13 +46,13 @@ private WorkflowDefinition(
4746
Input input = workflow.getInput();
4847
this.inputSchemaValidator =
4948
getSchemaValidator(application.validatorFactory(), resourceLoader, input.getSchema());
50-
this.inputFilter = buildWorkflowFilter(application.expressionFactory(), input.getFrom());
49+
this.inputFilter = buildWorkflowFilter(application, input.getFrom());
5150
}
5251
if (workflow.getOutput() != null) {
5352
Output output = workflow.getOutput();
5453
this.outputSchemaValidator =
5554
getSchemaValidator(application.validatorFactory(), resourceLoader, output.getSchema());
56-
this.outputFilter = buildWorkflowFilter(application.expressionFactory(), output.getAs());
55+
this.outputFilter = buildWorkflowFilter(application, output.getAs());
5756
}
5857
this.taskExecutor =
5958
TaskExecutorHelper.createExecutorList(
@@ -74,7 +73,7 @@ static WorkflowDefinition of(WorkflowApplication application, Workflow workflow,
7473
}
7574

7675
public WorkflowInstance instance(Object input) {
77-
return new WorkflowInstance(this, JsonUtils.fromValue(input));
76+
return new WorkflowInstance(this, application.modelFactory().fromAny(input));
7877
}
7978

8079
Optional<SchemaValidator> inputSchemaValidator() {

impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowFilter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
*/
1616
package io.serverlessworkflow.impl;
1717

18-
import com.fasterxml.jackson.databind.JsonNode;
19-
2018
@FunctionalInterface
2119
public interface WorkflowFilter {
22-
JsonNode apply(WorkflowContext workflow, TaskContext task, JsonNode node);
20+
WorkflowModel apply(WorkflowContext workflow, TaskContext task, WorkflowModel node);
2321
}

0 commit comments

Comments
 (0)