Skip to content

Commit 9394b72

Browse files
author
Tihomir Surdilovic
authored
Merge pull request #59 from tsurdilo/updateexamples
Update all examples from spec
2 parents 5367003 + f648c0b commit 9394b72

Some content is hidden

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

48 files changed

+713
-133
lines changed

api/src/test/java/io/serverlessworkflow/api/test/MarkupToWorkflowTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public class MarkupToWorkflowTest {
5858
"/examples/vetappointmentservice.json", "/examples/vetappointmentservice.yml",
5959
"/examples/eventbasedtransition.json", "/examples/eventbasedtransition.yml",
6060
"/examples/roomreadings.json", "/examples/roomreadings.yml",
61-
"/examples/checkcarvitals.json", "/examples/checkcarvitals.yml"
61+
"/examples/checkcarvitals.json", "/examples/checkcarvitals.yml",
62+
"/examples/booklending.json", "/examples/booklending.yml"
6263
})
6364
public void testSpecExamplesParsing(String workflowLocation) {
6465
Workflow workflow = Workflow.fromSource(WorkflowTestUtils.readWorkflowFile(workflowLocation));

api/src/test/resources/examples/applicantrequest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"type":"switch",
1717
"dataConditions": [
1818
{
19-
"condition": "${ .applicants[?(@.age >= 18)] }",
19+
"condition": "${ .applicants | .age >= 18 }",
2020
"transition": "StartApplication"
2121
},
2222
{
23-
"condition": "${ .applicants[?(@.age < 18)] }",
23+
"condition": "${ .applicants | .age < 18 }",
2424
"transition": "RejectApplication"
2525
}
2626
],

api/src/test/resources/examples/applicantrequest.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
---
21
id: applicantrequest
32
version: '1.0'
43
name: Applicant Request Decision Workflow
@@ -11,9 +10,9 @@ states:
1110
- name: CheckApplication
1211
type: switch
1312
dataConditions:
14-
- condition: "${ .applicants[?(@.age >= 18)] }"
13+
- condition: "${ .applicants | .age >= 18 }"
1514
transition: StartApplication
16-
- condition: "${ .applicants[?(@.age < 18)] }"
15+
- condition: "${ .applicants | .age < 18 }"
1716
transition: RejectApplication
1817
default:
1918
transition: RejectApplication
@@ -29,4 +28,4 @@ states:
2928
refName: sendRejectionEmailFunction
3029
arguments:
3130
applicant: "${ .applicant }"
32-
end: true
31+
end: true
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
{
2+
"id": "booklending",
3+
"name": "Book Lending Workflow",
4+
"version": "1.0",
5+
"start": "Book Lending Request",
6+
"states": [
7+
{
8+
"name": "Book Lending Request",
9+
"type": "event",
10+
"onEvents": [
11+
{
12+
"eventRefs": ["Book Lending Request Event"]
13+
}
14+
],
15+
"transition": "Get Book Status"
16+
},
17+
{
18+
"name": "Get Book Status",
19+
"type": "operation",
20+
"actions": [
21+
{
22+
"functionRef": {
23+
"refName": "Get status for book",
24+
"arguments": {
25+
"bookid": "${ .book.id }"
26+
}
27+
}
28+
}
29+
],
30+
"transition": "Book Status Decision"
31+
},
32+
{
33+
"name": "Book Status Decision",
34+
"type": "switch",
35+
"dataConditions": [
36+
{
37+
"name": "Book is on loan",
38+
"condition": "${ .book.status == \"onloan\" }",
39+
"transition": "Report Status To Lender"
40+
},
41+
{
42+
"name": "Check is available",
43+
"condition": "${ .book.status == \"available\" }",
44+
"transition": "Check Out Book"
45+
}
46+
]
47+
},
48+
{
49+
"name": "Report Status To Lender",
50+
"type": "operation",
51+
"actions": [
52+
{
53+
"functionRef": {
54+
"refName": "Send status to lender",
55+
"arguments": {
56+
"bookid": "${ .book.id }",
57+
"message": "Book ${ .book.title } is already on loan"
58+
}
59+
}
60+
}
61+
],
62+
"transition": "Wait for Lender response"
63+
},
64+
{
65+
"name": "Wait for Lender response",
66+
"type": "switch",
67+
"eventConditions": [
68+
{
69+
"name": "Hold Book",
70+
"eventRef": "Hold Book Event",
71+
"transition": "Request Hold"
72+
},
73+
{
74+
"name": "Decline Book Hold",
75+
"eventRef": "Decline Hold Event",
76+
"transition": "Cancel Request"
77+
}
78+
]
79+
},
80+
{
81+
"name": "Request Hold",
82+
"type": "operation",
83+
"actions": [
84+
{
85+
"functionRef": {
86+
"refName": "Request hold for lender",
87+
"arguments": {
88+
"bookid": "${ .book.id }",
89+
"lender": "${ .lender }"
90+
}
91+
}
92+
}
93+
],
94+
"transition": "Wait two weeks"
95+
},
96+
{
97+
"name": "Wait two weeks",
98+
"type": "delay",
99+
"timeDelay": "PT2W",
100+
"transition": "Get Book Status"
101+
},
102+
{
103+
"name": "Check Out Book",
104+
"type": "operation",
105+
"actions": [
106+
{
107+
"functionRef": {
108+
"refName": "Check out book with id",
109+
"arguments": {
110+
"bookid": "${ .book.id }"
111+
}
112+
}
113+
},
114+
{
115+
"functionRef": {
116+
"refName": "Notify Lender for checkout",
117+
"arguments": {
118+
"bookid": "${ .book.id }",
119+
"lender": "${ .lender }"
120+
}
121+
}
122+
}
123+
],
124+
"end": true
125+
}
126+
],
127+
"functions": "file://books/lending/functions.json",
128+
"events": "file://books/lending/events.json"
129+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
id: booklending
2+
name: Book Lending Workflow
3+
version: '1.0'
4+
start: Book Lending Request
5+
states:
6+
- name: Book Lending Request
7+
type: event
8+
onEvents:
9+
- eventRefs:
10+
- Book Lending Request Event
11+
transition: Get Book Status
12+
- name: Get Book Status
13+
type: operation
14+
actions:
15+
- functionRef:
16+
refName: Get status for book
17+
arguments:
18+
bookid: "${ .book.id }"
19+
transition: Book Status Decision
20+
- name: Book Status Decision
21+
type: switch
22+
dataConditions:
23+
- name: Book is on loan
24+
condition: ${ .book.status == "onloan" }
25+
transition: Report Status To Lender
26+
- name: Check is available
27+
condition: ${ .book.status == "available" }
28+
transition: Check Out Book
29+
- name: Report Status To Lender
30+
type: operation
31+
actions:
32+
- functionRef:
33+
refName: Send status to lender
34+
arguments:
35+
bookid: "${ .book.id }"
36+
message: Book ${ .book.title } is already on loan
37+
transition: Wait for Lender response
38+
- name: Wait for Lender response
39+
type: switch
40+
eventConditions:
41+
- name: Hold Book
42+
eventRef: Hold Book Event
43+
transition: Request Hold
44+
- name: Decline Book Hold
45+
eventRef: Decline Hold Event
46+
transition: Cancel Request
47+
- name: Request Hold
48+
type: operation
49+
actions:
50+
- functionRef:
51+
refName: Request fold for lender
52+
arguments:
53+
bookid: "${ .book.id }"
54+
lender: "${ .lender }"
55+
transition: Wait two weeks
56+
- name: Wait two weeks
57+
type: delay
58+
timeDelay: PT2W
59+
transition: Get Book Status
60+
- name: Check Out Book
61+
type: operation
62+
actions:
63+
- functionRef:
64+
refName: Check out book with id
65+
arguments:
66+
bookid: "${ .book.id }"
67+
- functionRef:
68+
refName: Notify Lender for checkout
69+
arguments:
70+
bookid: "${ .book.id }"
71+
lender: "${ .lender }"
72+
end: true
73+
functions: file://books/lending/functions.json
74+
events: file://books/lending/events.json

api/src/test/resources/examples/carauctionbids.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ name: Car Auction Bidding Workflow
44
description: Store a single bid whole the car auction is active
55
start:
66
stateName: StoreCarAuctionBid
7-
schedule:
8-
interval: 2020-03-20T09:00:00Z/2020-03-20T15:00:00Z
7+
schedule: 2020-03-20T09:00:00Z/2020-03-20T15:00:00Z
98
functions:
109
- name: StoreBidFunction
1110
operation: http://myapis.org/carauctionapi.json#storeBid
@@ -25,5 +24,4 @@ states:
2524
refName: StoreBidFunction
2625
arguments:
2726
bid: "${ .bid }"
28-
end:
29-
terminate: true
27+
end: true

api/src/test/resources/examples/checkcarvitals.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ states:
1313
type: subflow
1414
workflowId: vitalscheck
1515
repeat:
16-
max: 10
17-
continueOnError: true
1816
stopOnEvents:
1917
- CarTurnedOffEvent
2018
end: true

api/src/test/resources/examples/creditcheck.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@
4747
"type": "switch",
4848
"dataConditions": [
4949
{
50-
"name": "Approved",
51-
"condition": "${ .creditCheck[?(@.decision == 'Approved')] }",
52-
"transition": "StartApplication"
50+
"condition": "${ .creditCheck | .decision == \"Approved\" }",
51+
"transition": "StartApplication'"
5352
},
5453
{
55-
"name": "Denied",
56-
"condition": "${ .creditCheck[?(@.decision == 'Denied')] }",
54+
"condition": "${ .creditCheck | .decision == \"Denied\" }",
5755
"transition": "RejectApplication"
5856
}
5957
],

api/src/test/resources/examples/creditcheck.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
---
21
id: customercreditcheck
32
version: '1.0'
43
name: Customer Credit Check Workflow
@@ -29,11 +28,9 @@ states:
2928
- name: EvaluateDecision
3029
type: switch
3130
dataConditions:
32-
- name: Approved
33-
condition: "${ .creditCheck[?(@.decision == 'Approved')] }"
31+
- condition: "${ .creditCheck | .decision == \"Approved\" }"
3432
transition: StartApplication
35-
- name: Denied
36-
condition: "${ .creditCheck[?(@.decision == 'Denied')] }"
33+
- condition: "${ .creditCheck | .decision == \"Denied\" }"
3734
transition: RejectApplication
3835
default:
3936
transition: RejectApplication
@@ -49,4 +46,4 @@ states:
4946
refName: sendRejectionEmailFunction
5047
arguments:
5148
applicant: "${ .customer }"
52-
end: true
49+
end: true

api/src/test/resources/examples/eventbasedtransition.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
---
21
id: eventbasedswitch
32
version: '1.0'
43
name: Event Based Switch Transitions
@@ -33,4 +32,4 @@ states:
3332
- name: HandleNoVisaDecision
3433
type: subflow
3534
workflowId: handleNoVisaDecisionWorkfowId
36-
end: true
35+
end: true

0 commit comments

Comments
 (0)