Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public State deserialize(JsonParser jp,
case SWITCH:
return mapper.treeToValue(node,
SwitchState.class);
case DELAY:
case SLEEP:
return mapper.treeToValue(node,
DelayState.class);
SleepState.class);
case PARALLEL:
return mapper.treeToValue(node,
ParallelState.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public WorkflowModule(WorkflowPropertySource workflowPropertySource) {
private void addDefaultSerializers() {
addSerializer(new WorkflowSerializer());
addSerializer(new EventStateSerializer());
addSerializer(new DelayStateSerializer());
addSerializer(new SleepStateSerializer());
addSerializer(new OperationStateSerializer());
addSerializer(new ParallelStateSerializer());
addSerializer(new SwitchStateSerializer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,31 @@
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.fasterxml.jackson.databind.type.TypeFactory;
import io.serverlessworkflow.api.states.DefaultState;
import io.serverlessworkflow.api.states.DelayState;
import io.serverlessworkflow.api.states.SleepState;

import java.io.IOException;

public class DelayStateSerializer extends StdSerializer<DelayState> {
public class SleepStateSerializer extends StdSerializer<SleepState> {

public DelayStateSerializer() {
this(DelayState.class);
public SleepStateSerializer() {
this(SleepState.class);
}

protected DelayStateSerializer(Class<DelayState> t) {
protected SleepStateSerializer(Class<SleepState> t) {
super(t);
}

@Override
public void serialize(DelayState delayState,
public void serialize(SleepState delayState,
JsonGenerator gen,
SerializerProvider provider) throws IOException {

// set defaults for delay state
delayState.setType(DefaultState.Type.DELAY);
delayState.setType(DefaultState.Type.SLEEP);

// serialize after setting default bean values...
BeanSerializerFactory.instance.createSerializer(provider,
TypeFactory.defaultInstance().constructType(DelayState.class)).serialize(delayState,
TypeFactory.defaultInstance().constructType(SleepState.class)).serialize(delayState,
gen,
provider);
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/resources/schema/states/defaultstate.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"event",
"operation",
"switch",
"delay",
"sleep",
"parallel",
"subflow",
"inject",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "object",
"javaType": "io.serverlessworkflow.api.states.DelayState",
"javaType": "io.serverlessworkflow.api.states.SleepState",
"javaInterfaces": [
"io.serverlessworkflow.api.interfaces.State"
],
Expand All @@ -9,9 +9,9 @@
"$ref": "defaultstate.json"
},
"properties": {
"timeDelay": {
"duration": {
"type": "string",
"description": "Amount of time (ISO 8601 format) to delay"
"description": "Duration (ISO 8601 duration format) to sleep"
},
"usedForCompensation": {
"type": "boolean",
Expand All @@ -20,6 +20,6 @@
}
},
"required": [
"timeDelay"
"duration"
]
}
4 changes: 2 additions & 2 deletions api/src/main/resources/schema/workflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@
"existingJavaType": "io.serverlessworkflow.api.interfaces.State",
"anyOf": [
{
"title": "Delay State",
"$ref": "states/delaystate.json"
"title": "Sleep State",
"$ref": "states/sleepstate.json"
},
{
"title": "Event State",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
import io.serverlessworkflow.api.produce.ProduceEvent;
import io.serverlessworkflow.api.schedule.Schedule;
import io.serverlessworkflow.api.start.Start;
import io.serverlessworkflow.api.states.DelayState;
import io.serverlessworkflow.api.states.SleepState;
import io.serverlessworkflow.api.workflow.Events;
import io.serverlessworkflow.api.workflow.Functions;
import org.junit.jupiter.api.Test;

import java.util.Arrays;

import static io.serverlessworkflow.api.states.DefaultState.Type.DELAY;
import static io.serverlessworkflow.api.states.DefaultState.Type.SLEEP;
import static org.junit.jupiter.api.Assertions.*;

public class WorkflowToMarkupTest {
Expand All @@ -44,22 +44,22 @@ public void testSingleState() {
new Schedule().withInterval("PT1S")
))
.withStates(Arrays.asList(
new DelayState().withName("delayState").withType(DELAY)
new SleepState().withName("sleepState").withType(SLEEP)
.withEnd(
new End().withTerminate(true).withCompensate(true)
.withProduceEvents(Arrays.asList(
new ProduceEvent().withEventRef("someEvent")
))
)
.withTimeDelay("PT1M")
.withDuration("PT1M")
)
);

assertNotNull(workflow);
assertNotNull(workflow.getStart());
assertEquals(1, workflow.getStates().size());
State state = workflow.getStates().get(0);
assertTrue(state instanceof DelayState);
assertTrue(state instanceof SleepState);
assertNotNull(state.getEnd());

assertNotNull(Workflow.toJson(workflow));
Expand All @@ -78,19 +78,19 @@ public void testSingleFunction() {
.withOperation("testSwaggerDef#testOperationId")))
)
.withStates(Arrays.asList(
new DelayState().withName("delayState").withType(DELAY)
new SleepState().withName("delayState").withType(SLEEP)
.withEnd(
new End()
)
.withTimeDelay("PT1M")
.withDuration("PT1M")
)
);

assertNotNull(workflow);
assertNotNull(workflow.getStart());
assertEquals(1, workflow.getStates().size());
State state = workflow.getStates().get(0);
assertTrue(state instanceof DelayState);
assertTrue(state instanceof SleepState);
assertNotNull(workflow.getFunctions());
assertEquals(1, workflow.getFunctions().getFunctionDefs().size());
assertEquals("testFunction", workflow.getFunctions().getFunctionDefs().get(0).getName());
Expand All @@ -115,19 +115,19 @@ public void testSingleEvent() {
.withOperation("testSwaggerDef#testOperationId")))
)
.withStates(Arrays.asList(
new DelayState().withName("delayState").withType(DELAY)
new SleepState().withName("delayState").withType(SLEEP)
.withEnd(
new End()
)
.withTimeDelay("PT1M")
.withDuration("PT1M")
)
);

assertNotNull(workflow);
assertNotNull(workflow.getStart());
assertEquals(1, workflow.getStates().size());
State state = workflow.getStates().get(0);
assertTrue(state instanceof DelayState);
assertTrue(state instanceof SleepState);
assertNotNull(workflow.getFunctions());
assertEquals(1, workflow.getFunctions().getFunctionDefs().size());
assertEquals("testFunction", workflow.getFunctions().getFunctionDefs().get(0).getName());
Expand Down
6 changes: 3 additions & 3 deletions api/src/test/resources/examples/booklending.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@
"transition": "Wait two weeks"
},
{
"name": "Wait two weeks",
"type": "delay",
"timeDelay": "P2W",
"name": "Sleep two weeks",
"type": "sleep",
"duration": "P2W",
"transition": "Get Book Status"
},
{
Expand Down
4 changes: 2 additions & 2 deletions api/src/test/resources/examples/booklending.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ states:
lender: "${ .lender }"
transition: Wait two weeks
- name: Wait two weeks
type: delay
timeDelay: P2W
type: sleep
duration: P2W
transition: Get Book Status
- name: Check Out Book
type: operation
Expand Down
4 changes: 2 additions & 2 deletions api/src/test/resources/examples/jobmonitoring.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
},
{
"name": "WaitForCompletion",
"type": "delay",
"timeDelay": "PT5S",
"type": "sleep",
"duration": "PT5S",
"transition": "GetJobStatus"
},
{
Expand Down
4 changes: 2 additions & 2 deletions api/src/test/resources/examples/jobmonitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ states:
- subFlowRef: handleJobSubmissionErrorWorkflow
end: true
- name: WaitForCompletion
type: delay
timeDelay: PT5S
type: sleep
duration: PT5S
transition: GetJobStatus
- name: GetJobStatus
type: operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ private void inspectStatesInfo(Workflow workflow) {

}

if (state instanceof DelayState) {
DelayState delayState = (DelayState) state;
if (state instanceof SleepState) {
SleepState sleepState = (SleepState) state;

modelState.addInfo("Type: Delay State");
modelState.addInfo("Delay: " + delayState.getTimeDelay());
modelState.addInfo("Type: Sleep State");
modelState.addInfo("Duration: " + sleepState.getDuration());
}

if (state instanceof ParallelState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ skinparam state {
BorderColor<< event >> #7fe5f0
BorderColor<< operation >> #bada55
BorderColor<< switch >> #92a0f2
BorderColor<< delay >> #b83b5e
BorderColor<< sleep >> #b83b5e
BorderColor<< parallel >> #6a2c70
BorderColor<< inject >> #1e5f74
BorderColor<< foreach >> #931a25
Expand All @@ -38,7 +38,7 @@ state "[(${diagram.title})]" as workflow << workflow >> {
[# th:if="${diagram.showLegend}" ]
legend center
State Types and Border Colors:
| Event | Operation | Switch | Delay | Parallel | Inject | ForEach | CallBack |
| Event | Operation | Switch | Sleep | Parallel | Inject | ForEach | CallBack |
|<#7fe5f0>|<#bada55>|<#92a0f2>|<#b83b5e>|<#6a2c70>|<#1e5f74>|<#931a25>|<#ffcb8e>|
endlegend
[/]
Expand Down
4 changes: 2 additions & 2 deletions diagram/src/test/resources/examples/booklending.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
},
{
"name": "Wait two weeks",
"type": "delay",
"timeDelay": "P2W",
"type": "sleep",
"duration": "P2W",
"transition": "Get Book Status"
},
{
Expand Down
4 changes: 2 additions & 2 deletions diagram/src/test/resources/examples/booklending.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ states:
lender: "${ .lender }"
transition: Wait two weeks
- name: Wait two weeks
type: delay
timeDelay: P2W
type: sleep
duration: P2W
transition: Get Book Status
- name: Check Out Book
type: operation
Expand Down
4 changes: 2 additions & 2 deletions diagram/src/test/resources/examples/jobmonitoring.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
},
{
"name": "WaitForCompletion",
"type": "delay",
"timeDelay": "PT5S",
"type": "sleep",
"duration": "PT5S",
"transition": "GetJobStatus"
},
{
Expand Down
4 changes: 2 additions & 2 deletions diagram/src/test/resources/examples/jobmonitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ states:
- subFlowRef: handleJobSubmissionErrorWorkflow
end: true
- name: WaitForCompletion
type: delay
timeDelay: PT5S
type: sleep
duration: PT5S
transition: GetJobStatus
- name: GetJobStatus
type: operation
Expand Down
4 changes: 2 additions & 2 deletions diagram/src/test/resources/examples/singleswitchstate.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
},
{
"name": "FromFirstCondition",
"type": "delay",
"timeDelay": "PT2M",
"type": "sleep",
"duration": "PT2M",
"end": true
},
{
Expand Down
4 changes: 2 additions & 2 deletions diagram/src/test/resources/examples/singleswitchstate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ states:
condition: ''
end: true
- name: FromFirstCondition
type: delay
timeDelay: PT2M
type: sleep
duration: PT2M
end: true
- name: FromSecondCondition
type: inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
},
{
"name": "FromFirstCondition",
"type": "delay",
"timeDelay": "PT2M",
"type": "sleep",
"duration": "PT2M",
"end": true
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ states:
eventRef: fourthEvent
end: true
- name: FromFirstCondition
type: delay
timeDelay: PT2M
type: sleep
duration: PT2M
end: true
- name: FromSecondCondition
type: inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,10 @@ public List<ValidationError> validate() {
}
}

if (s instanceof DelayState) {
DelayState delayState = (DelayState) s;
if (delayState.getTimeDelay() == null || delayState.getTimeDelay().length() < 1) {
addValidationError("Delay state should have a non-empty time delay",
if (s instanceof SleepState) {
SleepState sleepState = (SleepState) s;
if (sleepState.getDuration() == null || sleepState.getDuration().length() < 1) {
addValidationError("Sleep state should have a non-empty time delay",
ValidationError.WORKFLOW_VALIDATION);
}
}
Expand Down
Loading