Skip to content

Commit d72f20b

Browse files
author
Tihomir Surdilovic
authored
Merge pull request #41 from tsurdilo/update10x
Update 1.0.x for release
2 parents ac4ea15 + 6ba32e2 commit d72f20b

File tree

93 files changed

+556
-531
lines changed

Some content is hidden

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

93 files changed

+556
-531
lines changed

README.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ a) Add the following repositories to your build.gradle `repositories` section:
8585

8686
```text
8787
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
88-
maven{ url "https://jitpack.io" }
8988
```
9089

9190
b) Add the following dependencies to your build.gradle `dependencies` section:
@@ -116,8 +115,7 @@ functions:
116115
states:
117116
- name: Greet
118117
type: operation
119-
start:
120-
kind: default
118+
start: true
121119
actionMode: sequential
122120
actions:
123121
- functionRef:
@@ -128,8 +126,7 @@ states:
128126
dataResultsPath: "$.payload.greeting"
129127
stateDataFilter:
130128
dataOutputPath: "$.greeting"
131-
end:
132-
kind: default
129+
end: true
133130
```
134131
135132
To parse it and create a Workflow intance you can do:

api/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
<artifactId>json</artifactId>
4242
</dependency>
4343
<dependency>
44-
<groupId>com.github.everit-org.json-schema</groupId>
45-
<artifactId>org.everit.json.schema</artifactId>
44+
<groupId>com.github.erosb</groupId>
45+
<artifactId>everit-json-schema</artifactId>
4646
</dependency>
4747

4848
<!-- test -->
@@ -110,4 +110,4 @@
110110
</plugin>
111111
</plugins>
112112
</build>
113-
</project>
113+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
* <p>
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+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
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+
*/
17+
package io.serverlessworkflow.api.deserializers;
18+
19+
import com.fasterxml.jackson.core.JsonParser;
20+
import com.fasterxml.jackson.databind.DeserializationContext;
21+
import com.fasterxml.jackson.databind.JsonNode;
22+
import com.fasterxml.jackson.databind.ObjectMapper;
23+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
24+
import io.serverlessworkflow.api.end.End;
25+
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
26+
import io.serverlessworkflow.api.produce.ProduceEvent;
27+
import io.serverlessworkflow.api.start.Start;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
30+
31+
import java.io.IOException;
32+
import java.util.ArrayList;
33+
import java.util.List;
34+
35+
public class EndDefinitionDeserializer extends StdDeserializer<End> {
36+
37+
private static final long serialVersionUID = 510l;
38+
private static Logger logger = LoggerFactory.getLogger(EndDefinitionDeserializer.class);
39+
40+
private WorkflowPropertySource context;
41+
42+
public EndDefinitionDeserializer() {
43+
this(End.class);
44+
}
45+
46+
public EndDefinitionDeserializer(Class<?> vc) {
47+
super(vc);
48+
}
49+
50+
public EndDefinitionDeserializer(WorkflowPropertySource context) {
51+
this(Start.class);
52+
this.context = context;
53+
}
54+
55+
@Override
56+
public End deserialize(JsonParser jp,
57+
DeserializationContext ctxt) throws IOException {
58+
59+
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
60+
JsonNode node = jp.getCodec().readTree(jp);
61+
62+
End end = new End();
63+
64+
if (node.isBoolean()) {
65+
end.setProduceEvents(null);
66+
end.setCompensate(false);
67+
end.setTerminate(false);
68+
return node.asBoolean() ? end : null;
69+
} else {
70+
if(node.get("produceEvents") != null) {
71+
List<ProduceEvent> produceEvents= new ArrayList<>();
72+
for (final JsonNode nodeEle : node.get("produceEvents")) {
73+
produceEvents.add(mapper.treeToValue(nodeEle, ProduceEvent.class));
74+
}
75+
end.setProduceEvents(produceEvents);
76+
}
77+
78+
if(node.get("terminate") != null) {
79+
end.setTerminate(node.get("terminate").asBoolean());
80+
} else {
81+
end.setTerminate(false);
82+
}
83+
84+
if(node.get("compensate") != null) {
85+
end.setCompensate(node.get("compensate").asBoolean());
86+
} else {
87+
end.setCompensate(false);
88+
}
89+
90+
return end;
91+
92+
}
93+
94+
}
95+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
* <p>
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+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
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+
*/
17+
package io.serverlessworkflow.api.deserializers;
18+
19+
import com.fasterxml.jackson.core.JsonParser;
20+
import com.fasterxml.jackson.databind.DeserializationContext;
21+
import com.fasterxml.jackson.databind.JsonNode;
22+
import com.fasterxml.jackson.databind.ObjectMapper;
23+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
24+
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
25+
import io.serverlessworkflow.api.schedule.Schedule;
26+
import io.serverlessworkflow.api.start.Start;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
29+
30+
import java.io.IOException;
31+
32+
public class StartDefinitionDeserializer extends StdDeserializer<Start> {
33+
34+
private static final long serialVersionUID = 510l;
35+
private static Logger logger = LoggerFactory.getLogger(StartDefinitionDeserializer.class);
36+
37+
private WorkflowPropertySource context;
38+
39+
public StartDefinitionDeserializer() {
40+
this(Start.class);
41+
}
42+
43+
public StartDefinitionDeserializer(Class<?> vc) {
44+
super(vc);
45+
}
46+
47+
public StartDefinitionDeserializer(WorkflowPropertySource context) {
48+
this(Start.class);
49+
this.context = context;
50+
}
51+
52+
@Override
53+
public Start deserialize(JsonParser jp,
54+
DeserializationContext ctxt) throws IOException {
55+
56+
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
57+
JsonNode node = jp.getCodec().readTree(jp);
58+
59+
Start start = new Start();
60+
61+
if (node.isBoolean()) {
62+
start.setSchedule(null);
63+
return node.asBoolean() ? start : null;
64+
} else {
65+
if(node.get("schedule") != null) {
66+
start.setSchedule(mapper.treeToValue(node.get("schedule"), Schedule.class));
67+
}
68+
69+
return start;
70+
71+
}
72+
73+
}
74+
}
75+

api/src/main/java/io/serverlessworkflow/api/mapper/WorkflowModule.java

+6
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818

1919
import com.fasterxml.jackson.databind.module.SimpleModule;
2020
import io.serverlessworkflow.api.deserializers.*;
21+
import io.serverlessworkflow.api.end.End;
2122
import io.serverlessworkflow.api.events.EventDefinition;
2223
import io.serverlessworkflow.api.events.OnEvents;
2324
import io.serverlessworkflow.api.interfaces.Extension;
2425
import io.serverlessworkflow.api.interfaces.State;
2526
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
2627
import io.serverlessworkflow.api.schedule.Schedule;
2728
import io.serverlessworkflow.api.serializers.*;
29+
import io.serverlessworkflow.api.start.Start;
2830
import io.serverlessworkflow.api.states.DefaultState;
2931
import io.serverlessworkflow.api.states.OperationState;
3032
import io.serverlessworkflow.api.states.ParallelState;
@@ -64,6 +66,8 @@ private void addDefaultSerializers() {
6466
addSerializer(new InjectStateSerializer());
6567
addSerializer(new ForEachStateSerializer());
6668
addSerializer(new CallbackStateSerializer());
69+
addSerializer(new StartDefinitionSerializer());
70+
addSerializer(new EndDefinitionSerializer());
6771
addSerializer(extensionSerializer);
6872
}
6973

@@ -84,6 +88,8 @@ private void addDefaultDeserializers() {
8488
addDeserializer(Retries.class, new RetriesDeserializer(workflowPropertySource));
8589
addDeserializer(Functions.class, new FunctionsDeserializer(workflowPropertySource));
8690
addDeserializer(Events.class, new EventsDeserializer(workflowPropertySource));
91+
addDeserializer(Start.class, new StartDefinitionDeserializer(workflowPropertySource));
92+
addDeserializer(End.class, new EndDefinitionDeserializer(workflowPropertySource));
8793
addDeserializer(Extension.class, extensionDeserializer);
8894

8995
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
* <p>
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+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
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+
*/
17+
package io.serverlessworkflow.api.serializers;
18+
19+
import com.fasterxml.jackson.core.JsonGenerator;
20+
import com.fasterxml.jackson.databind.SerializerProvider;
21+
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
22+
import io.serverlessworkflow.api.end.End;
23+
import io.serverlessworkflow.api.produce.ProduceEvent;
24+
25+
import java.io.IOException;
26+
27+
public class EndDefinitionSerializer extends StdSerializer<End> {
28+
29+
public EndDefinitionSerializer() {
30+
this(End.class);
31+
}
32+
33+
protected EndDefinitionSerializer(Class<End> t) {
34+
super(t);
35+
}
36+
37+
@Override
38+
public void serialize(End end,
39+
JsonGenerator gen,
40+
SerializerProvider provider) throws IOException {
41+
42+
if(end != null) {
43+
if((end.getProduceEvents() == null || end.getProduceEvents().size() < 1)
44+
&& !end.isCompensate() && !end.isTerminate()) {
45+
gen.writeBoolean(true);
46+
} else {
47+
gen.writeStartObject();
48+
49+
if(end.isTerminate()) {
50+
gen.writeBooleanField("terminate", true);
51+
}
52+
53+
if (end.getProduceEvents() != null && !end.getProduceEvents().isEmpty()) {
54+
gen.writeArrayFieldStart("produceEvents");
55+
for (ProduceEvent produceEvent : end.getProduceEvents()) {
56+
gen.writeObject(produceEvent);
57+
}
58+
gen.writeEndArray();
59+
}
60+
61+
if(end.isCompensate()) {
62+
gen.writeBooleanField("compensate", true);
63+
}
64+
65+
gen.writeEndObject();
66+
}
67+
}
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
* <p>
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+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
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+
*/
17+
package io.serverlessworkflow.api.serializers;
18+
19+
import com.fasterxml.jackson.core.JsonGenerator;
20+
import com.fasterxml.jackson.databind.SerializerProvider;
21+
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
22+
import io.serverlessworkflow.api.start.Start;
23+
24+
import java.io.IOException;
25+
26+
public class StartDefinitionSerializer extends StdSerializer<Start> {
27+
28+
public StartDefinitionSerializer() {
29+
this(Start.class);
30+
}
31+
32+
protected StartDefinitionSerializer(Class<Start> t) {
33+
super(t);
34+
}
35+
36+
@Override
37+
public void serialize(Start start,
38+
JsonGenerator gen,
39+
SerializerProvider provider) throws IOException {
40+
41+
if(start != null) {
42+
if(start.getSchedule() == null) {
43+
gen.writeBoolean(true);
44+
} else {
45+
gen.writeStartObject();
46+
gen.writeObjectField("schedule",
47+
start.getSchedule());
48+
gen.writeEndObject();
49+
}
50+
}
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"type": "object",
3+
"javaType": "io.serverlessworkflow.api.cron.Cron",
4+
"description": "Schedule cron definition",
5+
"properties": {
6+
"expression": {
7+
"type": "string",
8+
"description": "Repeating interval (cron expression) describing when the workflow instance should be created"
9+
},
10+
"validUntil": {
11+
"type": "string",
12+
"description": "Specific date and time (ISO 8601 format) when the cron expression invocation is no longer valid"
13+
}
14+
},
15+
"required": [
16+
"expression"
17+
]
18+
}

0 commit comments

Comments
 (0)