Skip to content

Update 1.0.x for release #41

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 4 commits into from
Jan 22, 2021
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ a) Add the following repositories to your build.gradle `repositories` section:

```text
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven{ url "https://jitpack.io" }
```

b) Add the following dependencies to your build.gradle `dependencies` section:
Expand Down Expand Up @@ -116,8 +115,7 @@ functions:
states:
- name: Greet
type: operation
start:
kind: default
start: true
actionMode: sequential
actions:
- functionRef:
Expand All @@ -128,8 +126,7 @@ states:
dataResultsPath: "$.payload.greeting"
stateDataFilter:
dataOutputPath: "$.greeting"
end:
kind: default
end: true
```

To parse it and create a Workflow intance you can do:
Expand Down
6 changes: 3 additions & 3 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>com.github.everit-org.json-schema</groupId>
<artifactId>org.everit.json.schema</artifactId>
<groupId>com.github.erosb</groupId>
<artifactId>everit-json-schema</artifactId>
</dependency>

<!-- test -->
Expand Down Expand Up @@ -110,4 +110,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.deserializers;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import io.serverlessworkflow.api.end.End;
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
import io.serverlessworkflow.api.produce.ProduceEvent;
import io.serverlessworkflow.api.start.Start;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class EndDefinitionDeserializer extends StdDeserializer<End> {

private static final long serialVersionUID = 510l;
private static Logger logger = LoggerFactory.getLogger(EndDefinitionDeserializer.class);

private WorkflowPropertySource context;

public EndDefinitionDeserializer() {
this(End.class);
}

public EndDefinitionDeserializer(Class<?> vc) {
super(vc);
}

public EndDefinitionDeserializer(WorkflowPropertySource context) {
this(Start.class);
this.context = context;
}

@Override
public End deserialize(JsonParser jp,
DeserializationContext ctxt) throws IOException {

ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode node = jp.getCodec().readTree(jp);

End end = new End();

if (node.isBoolean()) {
end.setProduceEvents(null);
end.setCompensate(false);
end.setTerminate(false);
return node.asBoolean() ? end : null;
} else {
if(node.get("produceEvents") != null) {
List<ProduceEvent> produceEvents= new ArrayList<>();
for (final JsonNode nodeEle : node.get("produceEvents")) {
produceEvents.add(mapper.treeToValue(nodeEle, ProduceEvent.class));
}
end.setProduceEvents(produceEvents);
}

if(node.get("terminate") != null) {
end.setTerminate(node.get("terminate").asBoolean());
} else {
end.setTerminate(false);
}

if(node.get("compensate") != null) {
end.setCompensate(node.get("compensate").asBoolean());
} else {
end.setCompensate(false);
}

return end;

}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.deserializers;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
import io.serverlessworkflow.api.schedule.Schedule;
import io.serverlessworkflow.api.start.Start;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class StartDefinitionDeserializer extends StdDeserializer<Start> {

private static final long serialVersionUID = 510l;
private static Logger logger = LoggerFactory.getLogger(StartDefinitionDeserializer.class);

private WorkflowPropertySource context;

public StartDefinitionDeserializer() {
this(Start.class);
}

public StartDefinitionDeserializer(Class<?> vc) {
super(vc);
}

public StartDefinitionDeserializer(WorkflowPropertySource context) {
this(Start.class);
this.context = context;
}

@Override
public Start deserialize(JsonParser jp,
DeserializationContext ctxt) throws IOException {

ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode node = jp.getCodec().readTree(jp);

Start start = new Start();

if (node.isBoolean()) {
start.setSchedule(null);
return node.asBoolean() ? start : null;
} else {
if(node.get("schedule") != null) {
start.setSchedule(mapper.treeToValue(node.get("schedule"), Schedule.class));
}

return start;

}

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

import com.fasterxml.jackson.databind.module.SimpleModule;
import io.serverlessworkflow.api.deserializers.*;
import io.serverlessworkflow.api.end.End;
import io.serverlessworkflow.api.events.EventDefinition;
import io.serverlessworkflow.api.events.OnEvents;
import io.serverlessworkflow.api.interfaces.Extension;
import io.serverlessworkflow.api.interfaces.State;
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
import io.serverlessworkflow.api.schedule.Schedule;
import io.serverlessworkflow.api.serializers.*;
import io.serverlessworkflow.api.start.Start;
import io.serverlessworkflow.api.states.DefaultState;
import io.serverlessworkflow.api.states.OperationState;
import io.serverlessworkflow.api.states.ParallelState;
Expand Down Expand Up @@ -64,6 +66,8 @@ private void addDefaultSerializers() {
addSerializer(new InjectStateSerializer());
addSerializer(new ForEachStateSerializer());
addSerializer(new CallbackStateSerializer());
addSerializer(new StartDefinitionSerializer());
addSerializer(new EndDefinitionSerializer());
addSerializer(extensionSerializer);
}

Expand All @@ -84,6 +88,8 @@ private void addDefaultDeserializers() {
addDeserializer(Retries.class, new RetriesDeserializer(workflowPropertySource));
addDeserializer(Functions.class, new FunctionsDeserializer(workflowPropertySource));
addDeserializer(Events.class, new EventsDeserializer(workflowPropertySource));
addDeserializer(Start.class, new StartDefinitionDeserializer(workflowPropertySource));
addDeserializer(End.class, new EndDefinitionDeserializer(workflowPropertySource));
addDeserializer(Extension.class, extensionDeserializer);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.serializers;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import io.serverlessworkflow.api.end.End;
import io.serverlessworkflow.api.produce.ProduceEvent;

import java.io.IOException;

public class EndDefinitionSerializer extends StdSerializer<End> {

public EndDefinitionSerializer() {
this(End.class);
}

protected EndDefinitionSerializer(Class<End> t) {
super(t);
}

@Override
public void serialize(End end,
JsonGenerator gen,
SerializerProvider provider) throws IOException {

if(end != null) {
if((end.getProduceEvents() == null || end.getProduceEvents().size() < 1)
&& !end.isCompensate() && !end.isTerminate()) {
gen.writeBoolean(true);
} else {
gen.writeStartObject();

if(end.isTerminate()) {
gen.writeBooleanField("terminate", true);
}

if (end.getProduceEvents() != null && !end.getProduceEvents().isEmpty()) {
gen.writeArrayFieldStart("produceEvents");
for (ProduceEvent produceEvent : end.getProduceEvents()) {
gen.writeObject(produceEvent);
}
gen.writeEndArray();
}

if(end.isCompensate()) {
gen.writeBooleanField("compensate", true);
}

gen.writeEndObject();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.serializers;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import io.serverlessworkflow.api.start.Start;

import java.io.IOException;

public class StartDefinitionSerializer extends StdSerializer<Start> {

public StartDefinitionSerializer() {
this(Start.class);
}

protected StartDefinitionSerializer(Class<Start> t) {
super(t);
}

@Override
public void serialize(Start start,
JsonGenerator gen,
SerializerProvider provider) throws IOException {

if(start != null) {
if(start.getSchedule() == null) {
gen.writeBoolean(true);
} else {
gen.writeStartObject();
gen.writeObjectField("schedule",
start.getSchedule());
gen.writeEndObject();
}
}
}
}
18 changes: 18 additions & 0 deletions api/src/main/resources/schema/cron/crondef.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "object",
"javaType": "io.serverlessworkflow.api.cron.Cron",
"description": "Schedule cron definition",
"properties": {
"expression": {
"type": "string",
"description": "Repeating interval (cron expression) describing when the workflow instance should be created"
},
"validUntil": {
"type": "string",
"description": "Specific date and time (ISO 8601 format) when the cron expression invocation is no longer valid"
}
},
"required": [
"expression"
]
}
Loading