Skip to content

Commit 74c7e88

Browse files
committed
[Fix_#359] Migration to 0.10 DSL
1 parent 48caa94 commit 74c7e88

File tree

368 files changed

+1292
-19439
lines changed

Some content is hidden

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

368 files changed

+1292
-19439
lines changed

api/pom.xml

+11-10
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>
@@ -34,9 +30,10 @@
3430
<artifactId>jackson-dataformat-yaml</artifactId>
3531
</dependency>
3632
<dependency>
37-
<groupId>jakarta.validation</groupId>
38-
<artifactId>jakarta.validation-api</artifactId>
33+
<groupId>jakarta.validation</groupId>
34+
<artifactId>jakarta.validation-api</artifactId>
3935
</dependency>
36+
4037
<!-- test -->
4138
<dependency>
4239
<groupId>org.junit.jupiter</groupId>
@@ -77,16 +74,20 @@
7774
<groupId>org.jsonschema2pojo</groupId>
7875
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
7976
<configuration>
80-
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
77+
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
78+
<!-- <sourcePaths>
79+
<sourcePath>https://raw.githubusercontent.com/serverlessworkflow/specification/main/schema/workflow.yaml</sourcePath>
80+
</sourcePaths> -->
81+
<sourceType>yamlschema</sourceType>
8182
<targetPackage>io.serverlessworkflow.api.types</targetPackage>
8283
<outputDirectory>${project.build.directory}/generated-sources/src/main/java</outputDirectory>
8384
<includeJsr303Annotations>true</includeJsr303Annotations>
8485
<generateBuilders>true</generateBuilders>
85-
<initializeCollections>false</initializeCollections>
86-
<includeAdditionalProperties>false</includeAdditionalProperties>
86+
<initializeCollections>true</initializeCollections>
87+
<includeAdditionalProperties>true</includeAdditionalProperties>
8788
<includeToString>false</includeToString>
8889
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
89-
<includeConstructors>true</includeConstructors>
90+
<includeConstructors>false</includeConstructors>
9091
<constructorsRequiredPropertiesOnly>true</constructorsRequiredPropertiesOnly>
9192
<serializable>true</serializable>
9293
<targetVersion>${java.version}</targetVersion>

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +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

1818
import com.fasterxml.jackson.databind.ObjectMapper;
1919

20-
public class JsonObjectMapperFactory {
20+
class JsonObjectMapperFactory {
2121

22-
private static final ObjectMapper instance = new JsonObjectMapper();
22+
private static final ObjectMapper instance =
23+
ObjectMapperCommonConfig.configure(new ObjectMapper());
2324

2425
public static final ObjectMapper mapper() {
2526
return instance;
2627
}
28+
29+
private JsonObjectMapperFactory() {}
2730
}

api/src/main/java/io/serverlessworkflow/api/mapper/YamlObjectMapperFactory.java renamed to api/src/main/java/io/serverlessworkflow/api/ObjectMapperCommonConfig.java

+10-6
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

1818
import com.fasterxml.jackson.databind.ObjectMapper;
19+
import com.fasterxml.jackson.databind.SerializationFeature;
1920

20-
public class YamlObjectMapperFactory {
21+
class ObjectMapperCommonConfig {
2122

22-
private static final ObjectMapper instance = new YamlObjectMapper();
23-
24-
public static final ObjectMapper mapper() {
25-
return instance;
23+
public static ObjectMapper configure(ObjectMapper mapper) {
24+
return mapper
25+
.configure(SerializationFeature.INDENT_OUTPUT, true)
26+
.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false)
27+
.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
2628
}
29+
30+
private ObjectMapperCommonConfig() {}
2731
}

api/src/main/java/io/serverlessworkflow/api/validation/WorkflowSchemaLoader.java renamed to api/src/main/java/io/serverlessworkflow/api/WorkflowFormat.java

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

18-
import com.fasterxml.jackson.databind.JsonNode;
1918
import com.fasterxml.jackson.databind.ObjectMapper;
20-
import java.io.IOException;
21-
import java.io.UncheckedIOException;
19+
import java.nio.file.Path;
2220

23-
public class WorkflowSchemaLoader {
21+
public enum WorkflowFormat {
22+
JSON(JsonObjectMapperFactory.mapper()),
23+
YAML(YamlObjectMapperFactory.mapper());
2424

25-
public static JsonNode getWorkflowSchema() {
26-
try {
27-
return ObjectMapperHolder.objectMapper.readTree(
28-
WorkflowSchemaLoader.class.getResourceAsStream("/schema/workflow.json"));
29-
} catch (IOException e) {
30-
throw new UncheckedIOException(e);
31-
}
25+
private final ObjectMapper mapper;
26+
27+
public static WorkflowFormat fromPath(Path path) {
28+
return fromFileName(path.getFileName().toString());
29+
}
30+
31+
public static WorkflowFormat fromFileName(String fileName) {
32+
return fileName.endsWith(".json") ? JSON : YAML;
33+
}
34+
35+
private WorkflowFormat(ObjectMapper mapper) {
36+
this.mapper = mapper;
3237
}
3338

34-
private static class ObjectMapperHolder {
35-
public static final ObjectMapper objectMapper = new ObjectMapper();
39+
public ObjectMapper mapper() {
40+
return mapper;
3641
}
3742
}
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 io.serverlessworkflow.api.types.Workflow;
19+
import java.io.FileNotFoundException;
20+
import java.io.IOException;
21+
import java.io.InputStream;
22+
import java.io.Reader;
23+
import java.nio.file.Files;
24+
import java.nio.file.Path;
25+
26+
public class WorkflowReader {
27+
28+
public static Workflow readWorkflow(InputStream input, WorkflowFormat format) throws IOException {
29+
return format.mapper().readValue(input, Workflow.class);
30+
}
31+
32+
public static Workflow readWorkflow(Reader input, WorkflowFormat format) throws IOException {
33+
return format.mapper().readValue(input, Workflow.class);
34+
}
35+
36+
public static Workflow readWorkflow(Path path, WorkflowFormat format) throws IOException {
37+
return format.mapper().readValue(Files.readAllBytes(path), Workflow.class);
38+
}
39+
40+
public static Workflow readWorkflowFromClasspath(String classpath) throws IOException {
41+
return readWorkflowFromClasspath(
42+
classpath,
43+
Thread.currentThread().getContextClassLoader(),
44+
WorkflowFormat.fromFileName(classpath));
45+
}
46+
47+
public static Workflow readWorkflowFromClasspath(
48+
String classpath, ClassLoader cl, WorkflowFormat format) throws IOException {
49+
try (InputStream in = cl.getResourceAsStream(classpath)) {
50+
if (in == null) {
51+
throw new FileNotFoundException(classpath);
52+
}
53+
return readWorkflow(in, format);
54+
}
55+
}
56+
57+
private WorkflowReader() {}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 io.serverlessworkflow.api.types.Workflow;
19+
import java.io.IOException;
20+
import java.io.OutputStream;
21+
import java.io.Writer;
22+
import java.nio.file.Files;
23+
import java.nio.file.Path;
24+
25+
public class WorkflowWriter {
26+
27+
public static void writeWorkflow(OutputStream output, Workflow workflow, WorkflowFormat format)
28+
throws IOException {
29+
format.mapper().writeValue(output, workflow);
30+
}
31+
32+
public static void writeWorkflow(Writer output, Workflow workflow, WorkflowFormat format)
33+
throws IOException {
34+
format.mapper().writeValue(output, workflow);
35+
}
36+
37+
public static void writeWorkflow(Path output, Workflow workflow) throws IOException {
38+
writeWorkflow(output, workflow, WorkflowFormat.fromPath(output));
39+
}
40+
41+
public static void writeWorkflow(Path output, Workflow workflow, WorkflowFormat format)
42+
throws IOException {
43+
try (OutputStream out = Files.newOutputStream(output)) {
44+
writeWorkflow(out, workflow, format);
45+
}
46+
}
47+
48+
private WorkflowWriter() {}
49+
}

api/src/main/java/io/serverlessworkflow/api/mapper/YamlObjectMapper.java renamed to api/src/main/java/io/serverlessworkflow/api/YamlObjectMapperFactory.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,21 @@
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;
1819
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
1920
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature;
20-
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
2121

22-
public class YamlObjectMapper extends BaseObjectMapper {
23-
public YamlObjectMapper() {
24-
this(null);
25-
}
22+
class YamlObjectMapperFactory {
23+
24+
private static final ObjectMapper instance =
25+
ObjectMapperCommonConfig.configure(
26+
new ObjectMapper(new YAMLFactory().enable(Feature.MINIMIZE_QUOTES)));
2627

27-
public YamlObjectMapper(WorkflowPropertySource context) {
28-
super(new YAMLFactory().enable(Feature.MINIMIZE_QUOTES), context);
28+
public static final ObjectMapper mapper() {
29+
return instance;
2930
}
31+
32+
private YamlObjectMapperFactory() {}
3033
}

api/src/main/java/io/serverlessworkflow/api/deserializers/AuthDefinitionDeserializer.java

-80
This file was deleted.

0 commit comments

Comments
 (0)