Skip to content

Fix #359 - Add support to DSL 1.0.0 #367

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 9 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
342 changes: 38 additions & 304 deletions README.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ target/
build/

### VS Code ###
.vscode/
.vscode/
/.checkstyle
25 changes: 18 additions & 7 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
Expand All @@ -37,6 +33,7 @@
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>

<!-- test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down Expand Up @@ -77,22 +74,36 @@
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
<!--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-->
<!-- <sourcePaths>
<sourcePath>https://raw.githubusercontent.com/serverlessworkflow/specification/main/schema/workflow.yaml</sourcePath>
</sourcePaths> -->
<sourceType>yamlschema</sourceType>
<targetPackage>io.serverlessworkflow.api.types</targetPackage>
<outputDirectory>${project.build.directory}/generated-sources/src/main/java</outputDirectory>
<includeJsr303Annotations>true</includeJsr303Annotations>
<generateBuilders>true</generateBuilders>
<initializeCollections>false</initializeCollections>
<includeAdditionalProperties>false</includeAdditionalProperties>
<initializeCollections>true</initializeCollections>
<includeAdditionalProperties>true</includeAdditionalProperties>
<includeToString>false</includeToString>
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
<includeConstructors>true</includeConstructors>
<constructorsRequiredPropertiesOnly>true</constructorsRequiredPropertiesOnly>
<useTitleAsClassname>true</useTitleAsClassname>
<serializable>true</serializable>
<targetVersion>${java.version}</targetVersion>
<usePrimitives>true</usePrimitives>
<useJakartaValidation>true</useJakartaValidation>
<customRuleFactory>io.serverlessworkflow.generator.UnreferencedFactory</customRuleFactory>
</configuration>
<dependencies>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>custom-generator</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.api;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature;

class ObjectMapperFactory {

private static final ObjectMapper jsonMapper = configure(new ObjectMapper());

private static final ObjectMapper yamlMapper =
configure(new ObjectMapper(new YAMLFactory().enable(Feature.MINIMIZE_QUOTES)));

public static final ObjectMapper jsonMapper() {
return jsonMapper;
}

public static final ObjectMapper yamlMapper() {
return yamlMapper;
}

private static ObjectMapper configure(ObjectMapper mapper) {
return mapper
.configure(SerializationFeature.INDENT_OUTPUT, true)
.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false)
.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}

private ObjectMapperFactory() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.api.mapper;
package io.serverlessworkflow.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.nio.file.Path;

public class JsonObjectMapperFactory {
public enum WorkflowFormat {
JSON(ObjectMapperFactory.jsonMapper()),
YAML(ObjectMapperFactory.yamlMapper());

private static final ObjectMapper instance = new JsonObjectMapper();
private final ObjectMapper mapper;

public static final ObjectMapper mapper() {
return instance;
public static WorkflowFormat fromPath(Path path) {
return fromFileName(path.getFileName().toString());
}

public static WorkflowFormat fromFileName(String fileName) {
return fileName.endsWith(".json") ? JSON : YAML;
}

private WorkflowFormat(ObjectMapper mapper) {
this.mapper = mapper;
}

public ObjectMapper mapper() {
return mapper;
}
}
58 changes: 58 additions & 0 deletions api/src/main/java/io/serverlessworkflow/api/WorkflowReader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.api;

import io.serverlessworkflow.api.types.Workflow;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;

public class WorkflowReader {

public static Workflow readWorkflow(InputStream input, WorkflowFormat format) throws IOException {
return format.mapper().readValue(input, Workflow.class);
}

public static Workflow readWorkflow(Reader input, WorkflowFormat format) throws IOException {
return format.mapper().readValue(input, Workflow.class);
}

public static Workflow readWorkflow(Path path, WorkflowFormat format) throws IOException {
return format.mapper().readValue(Files.readAllBytes(path), Workflow.class);
}

public static Workflow readWorkflowFromClasspath(String classpath) throws IOException {
return readWorkflowFromClasspath(
classpath,
Thread.currentThread().getContextClassLoader(),
WorkflowFormat.fromFileName(classpath));
}

public static Workflow readWorkflowFromClasspath(
String classpath, ClassLoader cl, WorkflowFormat format) throws IOException {
try (InputStream in = cl.getResourceAsStream(classpath)) {
if (in == null) {
throw new FileNotFoundException(classpath);
}
return readWorkflow(in, format);
}
}

private WorkflowReader() {}
}
49 changes: 49 additions & 0 deletions api/src/main/java/io/serverlessworkflow/api/WorkflowWriter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.api;

import io.serverlessworkflow.api.types.Workflow;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;

public class WorkflowWriter {

public static void writeWorkflow(OutputStream output, Workflow workflow, WorkflowFormat format)
throws IOException {
format.mapper().writeValue(output, workflow);
}

public static void writeWorkflow(Writer output, Workflow workflow, WorkflowFormat format)
throws IOException {
format.mapper().writeValue(output, workflow);
}

public static void writeWorkflow(Path output, Workflow workflow) throws IOException {
writeWorkflow(output, workflow, WorkflowFormat.fromPath(output));
}

public static void writeWorkflow(Path output, Workflow workflow, WorkflowFormat format)
throws IOException {
try (OutputStream out = Files.newOutputStream(output)) {
writeWorkflow(out, workflow, format);
}
}

private WorkflowWriter() {}
}

This file was deleted.

Loading
Loading