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 all 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
30 changes: 23 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 All @@ -53,6 +50,11 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand All @@ -77,22 +79,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,38 @@
/*
* 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.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import io.serverlessworkflow.api.types.CallAsyncAPI;
import io.serverlessworkflow.api.types.CallGRPC;
import io.serverlessworkflow.api.types.CallHTTP;
import io.serverlessworkflow.api.types.CallOpenAPI;
import io.serverlessworkflow.api.types.CallTask;
import java.io.IOException;
import java.util.List;

class CallTaskDeserializer extends JsonDeserializer<CallTask> {

@Override
public CallTask deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return DeserializeHelper.deserialize(
p,
CallTask.class,
List.of(CallHTTP.class, CallAsyncAPI.class, CallOpenAPI.class, CallGRPC.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.api.mapper;
package io.serverlessworkflow.api;

import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import io.serverlessworkflow.api.types.CallTask;
import java.io.IOException;

public class JsonObjectMapper extends BaseObjectMapper {

public JsonObjectMapper() {
this(null);
}

public JsonObjectMapper(WorkflowPropertySource context) {
super(null, context);
class CallTaskSerializer extends JsonSerializer<CallTask> {
@Override
public void serialize(CallTask value, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
SerializeHelper.serialize(gen, value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.databind.JsonMappingException;
import java.io.IOException;
import java.util.Collection;

public class DeserializeHelper {

public static <T> T deserialize(
JsonParser p, Class<T> targetClass, Collection<Class<?>> unionTypes) throws IOException {
TreeNode node = p.readValueAsTree();
JsonProcessingException ex = new JsonMappingException("Problem deserializing " + targetClass);
for (Class<?> unionType : unionTypes) {
try {
Object object = p.getCodec().treeToValue(node, unionType);
return targetClass.getConstructor(unionType).newInstance(object);
} catch (IOException | ReflectiveOperationException io) {
ex.addSuppressed(io);
}
}
throw ex;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature;
import io.serverlessworkflow.api.types.CallTask;
import io.serverlessworkflow.api.types.Task;

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) {
SimpleModule simpleModule = new SimpleModule();
simpleModule.addDeserializer(Task.class, new TaskDeserializer());
simpleModule.addSerializer(Task.class, new TaskSerializer());
simpleModule.addDeserializer(CallTask.class, new CallTaskDeserializer());
simpleModule.addSerializer(CallTask.class, new CallTaskSerializer());
return mapper
.configure(SerializationFeature.INDENT_OUTPUT, true)
.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false)
.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false)
.registerModule(simpleModule);
}

private ObjectMapperFactory() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.core.JsonGenerator;
import java.io.IOException;
import java.lang.reflect.Method;

public class SerializeHelper {
public static void serialize(JsonGenerator jgen, Object item) throws IOException {
try {
for (Method m : item.getClass().getDeclaredMethods()) {
Object value = m.invoke(item);
if (value != null) {
jgen.writeObject(value);
break;
}
}
} catch (ReflectiveOperationException ex) {
throw new IOException(ex);
}
}
}
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 com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import io.serverlessworkflow.api.types.CallTask;
import io.serverlessworkflow.api.types.DoTask;
import io.serverlessworkflow.api.types.EmitTask;
import io.serverlessworkflow.api.types.ForTask;
import io.serverlessworkflow.api.types.ForkTask;
import io.serverlessworkflow.api.types.ListenTask;
import io.serverlessworkflow.api.types.RaiseTask;
import io.serverlessworkflow.api.types.RunTask;
import io.serverlessworkflow.api.types.SetTask;
import io.serverlessworkflow.api.types.SwitchTask;
import io.serverlessworkflow.api.types.Task;
import io.serverlessworkflow.api.types.TryTask;
import io.serverlessworkflow.api.types.WaitTask;
import java.io.IOException;
import java.util.List;

class TaskDeserializer extends JsonDeserializer<Task> {

@Override
public Task deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return DeserializeHelper.deserialize(
p,
Task.class,
List.of(
CallTask.class,
DoTask.class,
SwitchTask.class,
TryTask.class,
RaiseTask.class,
EmitTask.class,
ForkTask.class,
ForTask.class,
ListenTask.class,
SetTask.class,
RunTask.class,
WaitTask.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
* 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 com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import io.serverlessworkflow.api.types.Task;
import java.io.IOException;

public class JsonObjectMapperFactory {
class TaskSerializer extends JsonSerializer<Task> {

private static final ObjectMapper instance = new JsonObjectMapper();

public static final ObjectMapper mapper() {
return instance;
@Override
public void serialize(Task value, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
SerializeHelper.serialize(gen, value);
}
}
Loading
Loading