Skip to content

Commit bd6cfe8

Browse files
Merge pull request #367 from fjtirado/Fix_#359
Fix #359 - Add support to DSL 1.0.0
2 parents a1cb0b6 + fd4b7c4 commit bd6cfe8

File tree

379 files changed

+2046
-19749
lines changed

Some content is hidden

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

379 files changed

+2046
-19749
lines changed

README.md

+38-304
Large diffs are not rendered by default.

api/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ target/
2828
build/
2929

3030
### VS Code ###
31-
.vscode/
31+
.vscode/
32+
/.checkstyle

api/pom.xml

+23-7
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
<groupId>org.slf4j</groupId>
1818
<artifactId>slf4j-api</artifactId>
1919
</dependency>
20-
<dependency>
21-
<groupId>org.slf4j</groupId>
22-
<artifactId>jcl-over-slf4j</artifactId>
23-
</dependency>
2420
<dependency>
2521
<groupId>com.fasterxml.jackson.core</groupId>
2622
<artifactId>jackson-core</artifactId>
@@ -37,6 +33,7 @@
3733
<groupId>jakarta.validation</groupId>
3834
<artifactId>jakarta.validation-api</artifactId>
3935
</dependency>
36+
4037
<!-- test -->
4138
<dependency>
4239
<groupId>org.junit.jupiter</groupId>
@@ -53,6 +50,11 @@
5350
<artifactId>junit-jupiter-params</artifactId>
5451
<scope>test</scope>
5552
</dependency>
53+
<dependency>
54+
<groupId>org.assertj</groupId>
55+
<artifactId>assertj-core</artifactId>
56+
<scope>test</scope>
57+
</dependency>
5658
<dependency>
5759
<groupId>org.mockito</groupId>
5860
<artifactId>mockito-core</artifactId>
@@ -77,22 +79,36 @@
7779
<groupId>org.jsonschema2pojo</groupId>
7880
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
7981
<configuration>
80-
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
82+
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
83+
<!--The comment below is left intentionally in case jsonschema2pojo one day accepts https urls. That day we can remove the file from schema dir and use directly the real schema-->
84+
<!-- <sourcePaths>
85+
<sourcePath>https://raw.githubusercontent.com/serverlessworkflow/specification/main/schema/workflow.yaml</sourcePath>
86+
</sourcePaths> -->
87+
<sourceType>yamlschema</sourceType>
8188
<targetPackage>io.serverlessworkflow.api.types</targetPackage>
8289
<outputDirectory>${project.build.directory}/generated-sources/src/main/java</outputDirectory>
8390
<includeJsr303Annotations>true</includeJsr303Annotations>
8491
<generateBuilders>true</generateBuilders>
85-
<initializeCollections>false</initializeCollections>
86-
<includeAdditionalProperties>false</includeAdditionalProperties>
92+
<initializeCollections>true</initializeCollections>
93+
<includeAdditionalProperties>true</includeAdditionalProperties>
8794
<includeToString>false</includeToString>
8895
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
8996
<includeConstructors>true</includeConstructors>
9097
<constructorsRequiredPropertiesOnly>true</constructorsRequiredPropertiesOnly>
98+
<useTitleAsClassname>true</useTitleAsClassname>
9199
<serializable>true</serializable>
92100
<targetVersion>${java.version}</targetVersion>
93101
<usePrimitives>true</usePrimitives>
94102
<useJakartaValidation>true</useJakartaValidation>
103+
<customRuleFactory>io.serverlessworkflow.generator.UnreferencedFactory</customRuleFactory>
95104
</configuration>
105+
<dependencies>
106+
<dependency>
107+
<groupId>io.serverlessworkflow</groupId>
108+
<artifactId>custom-generator</artifactId>
109+
<version>${project.version}</version>
110+
</dependency>
111+
</dependencies>
96112
<executions>
97113
<execution>
98114
<goals>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.api;
17+
18+
import com.fasterxml.jackson.core.JsonParser;
19+
import com.fasterxml.jackson.databind.DeserializationContext;
20+
import com.fasterxml.jackson.databind.JsonDeserializer;
21+
import io.serverlessworkflow.api.types.CallAsyncAPI;
22+
import io.serverlessworkflow.api.types.CallGRPC;
23+
import io.serverlessworkflow.api.types.CallHTTP;
24+
import io.serverlessworkflow.api.types.CallOpenAPI;
25+
import io.serverlessworkflow.api.types.CallTask;
26+
import java.io.IOException;
27+
import java.util.List;
28+
29+
class CallTaskDeserializer extends JsonDeserializer<CallTask> {
30+
31+
@Override
32+
public CallTask deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
33+
return DeserializeHelper.deserialize(
34+
p,
35+
CallTask.class,
36+
List.of(CallHTTP.class, CallAsyncAPI.class, CallOpenAPI.class, CallGRPC.class));
37+
}
38+
}

api/src/main/java/io/serverlessworkflow/api/mapper/JsonObjectMapper.java renamed to api/src/main/java/io/serverlessworkflow/api/CallTaskSerializer.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.serverlessworkflow.api.mapper;
16+
package io.serverlessworkflow.api;
1717

18-
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
18+
import com.fasterxml.jackson.core.JsonGenerator;
19+
import com.fasterxml.jackson.databind.JsonSerializer;
20+
import com.fasterxml.jackson.databind.SerializerProvider;
21+
import io.serverlessworkflow.api.types.CallTask;
22+
import java.io.IOException;
1923

20-
public class JsonObjectMapper extends BaseObjectMapper {
21-
22-
public JsonObjectMapper() {
23-
this(null);
24-
}
25-
26-
public JsonObjectMapper(WorkflowPropertySource context) {
27-
super(null, context);
24+
class CallTaskSerializer extends JsonSerializer<CallTask> {
25+
@Override
26+
public void serialize(CallTask value, JsonGenerator gen, SerializerProvider serializers)
27+
throws IOException {
28+
SerializeHelper.serialize(gen, value);
2829
}
2930
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.api;
17+
18+
import com.fasterxml.jackson.core.JsonParser;
19+
import com.fasterxml.jackson.core.JsonProcessingException;
20+
import com.fasterxml.jackson.core.TreeNode;
21+
import com.fasterxml.jackson.databind.JsonMappingException;
22+
import java.io.IOException;
23+
import java.util.Collection;
24+
25+
public class DeserializeHelper {
26+
27+
public static <T> T deserialize(
28+
JsonParser p, Class<T> targetClass, Collection<Class<?>> unionTypes) throws IOException {
29+
TreeNode node = p.readValueAsTree();
30+
JsonProcessingException ex = new JsonMappingException("Problem deserializing " + targetClass);
31+
for (Class<?> unionType : unionTypes) {
32+
try {
33+
Object object = p.getCodec().treeToValue(node, unionType);
34+
return targetClass.getConstructor(unionType).newInstance(object);
35+
} catch (IOException | ReflectiveOperationException io) {
36+
ex.addSuppressed(io);
37+
}
38+
}
39+
throw ex;
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.api;
17+
18+
import com.fasterxml.jackson.databind.ObjectMapper;
19+
import com.fasterxml.jackson.databind.SerializationFeature;
20+
import com.fasterxml.jackson.databind.module.SimpleModule;
21+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
22+
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature;
23+
import io.serverlessworkflow.api.types.CallTask;
24+
import io.serverlessworkflow.api.types.Task;
25+
26+
class ObjectMapperFactory {
27+
28+
private static final ObjectMapper jsonMapper = configure(new ObjectMapper());
29+
30+
private static final ObjectMapper yamlMapper =
31+
configure(new ObjectMapper(new YAMLFactory().enable(Feature.MINIMIZE_QUOTES)));
32+
33+
public static final ObjectMapper jsonMapper() {
34+
return jsonMapper;
35+
}
36+
37+
public static final ObjectMapper yamlMapper() {
38+
return yamlMapper;
39+
}
40+
41+
private static ObjectMapper configure(ObjectMapper mapper) {
42+
SimpleModule simpleModule = new SimpleModule();
43+
simpleModule.addDeserializer(Task.class, new TaskDeserializer());
44+
simpleModule.addSerializer(Task.class, new TaskSerializer());
45+
simpleModule.addDeserializer(CallTask.class, new CallTaskDeserializer());
46+
simpleModule.addSerializer(CallTask.class, new CallTaskSerializer());
47+
return mapper
48+
.configure(SerializationFeature.INDENT_OUTPUT, true)
49+
.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false)
50+
.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false)
51+
.registerModule(simpleModule);
52+
}
53+
54+
private ObjectMapperFactory() {}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.api;
17+
18+
import com.fasterxml.jackson.core.JsonGenerator;
19+
import java.io.IOException;
20+
import java.lang.reflect.Method;
21+
22+
public class SerializeHelper {
23+
public static void serialize(JsonGenerator jgen, Object item) throws IOException {
24+
try {
25+
for (Method m : item.getClass().getDeclaredMethods()) {
26+
Object value = m.invoke(item);
27+
if (value != null) {
28+
jgen.writeObject(value);
29+
break;
30+
}
31+
}
32+
} catch (ReflectiveOperationException ex) {
33+
throw new IOException(ex);
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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.api;
17+
18+
import com.fasterxml.jackson.core.JsonParser;
19+
import com.fasterxml.jackson.databind.DeserializationContext;
20+
import com.fasterxml.jackson.databind.JsonDeserializer;
21+
import io.serverlessworkflow.api.types.CallTask;
22+
import io.serverlessworkflow.api.types.DoTask;
23+
import io.serverlessworkflow.api.types.EmitTask;
24+
import io.serverlessworkflow.api.types.ForTask;
25+
import io.serverlessworkflow.api.types.ForkTask;
26+
import io.serverlessworkflow.api.types.ListenTask;
27+
import io.serverlessworkflow.api.types.RaiseTask;
28+
import io.serverlessworkflow.api.types.RunTask;
29+
import io.serverlessworkflow.api.types.SetTask;
30+
import io.serverlessworkflow.api.types.SwitchTask;
31+
import io.serverlessworkflow.api.types.Task;
32+
import io.serverlessworkflow.api.types.TryTask;
33+
import io.serverlessworkflow.api.types.WaitTask;
34+
import java.io.IOException;
35+
import java.util.List;
36+
37+
class TaskDeserializer extends JsonDeserializer<Task> {
38+
39+
@Override
40+
public Task deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
41+
return DeserializeHelper.deserialize(
42+
p,
43+
Task.class,
44+
List.of(
45+
CallTask.class,
46+
DoTask.class,
47+
SwitchTask.class,
48+
TryTask.class,
49+
RaiseTask.class,
50+
EmitTask.class,
51+
ForkTask.class,
52+
ForTask.class,
53+
ListenTask.class,
54+
SetTask.class,
55+
RunTask.class,
56+
WaitTask.class));
57+
}
58+
}

api/src/main/java/io/serverlessworkflow/api/mapper/JsonObjectMapperFactory.java renamed to api/src/main/java/io/serverlessworkflow/api/TaskSerializer.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.serverlessworkflow.api.mapper;
16+
package io.serverlessworkflow.api;
1717

18-
import com.fasterxml.jackson.databind.ObjectMapper;
18+
import com.fasterxml.jackson.core.JsonGenerator;
19+
import com.fasterxml.jackson.databind.JsonSerializer;
20+
import com.fasterxml.jackson.databind.SerializerProvider;
21+
import io.serverlessworkflow.api.types.Task;
22+
import java.io.IOException;
1923

20-
public class JsonObjectMapperFactory {
24+
class TaskSerializer extends JsonSerializer<Task> {
2125

22-
private static final ObjectMapper instance = new JsonObjectMapper();
23-
24-
public static final ObjectMapper mapper() {
25-
return instance;
26+
@Override
27+
public void serialize(Task value, JsonGenerator gen, SerializerProvider serializers)
28+
throws IOException {
29+
SerializeHelper.serialize(gen, value);
2630
}
2731
}

0 commit comments

Comments
 (0)