Skip to content

Commit bbb7591

Browse files
authored
Merge pull request #76 from antmendoza/add-checkcarvitals-solvemathproblems-example
added checkcarvitals and solvemathproblems examples
2 parents 9479190 + 3f11239 commit bbb7591

14 files changed

+379
-48
lines changed

spec/examples/applicantrequest.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
import {WorkflowBuilder} from "../../src/model/workflow.builder";
1817
import * as fs from "fs";
19-
import {FunctionDefBuilder} from "../../src/model/function-def.builder";
20-
import {DatabasedSwitchBuilder} from "../../src/model/databased-switch.builder";
21-
import {TransitionDataConditionBuilder} from "../../src/model/transition-data-condition.builder";
22-
import {OperationStateBuilder} from "../../src/model/operation-state.builder";
23-
import {SubFlowStateBuilder} from "../../src/model/sub-flow-state.builder";
24-
import {ActionBuilder} from "../../src/model/action.builder";
25-
import {DefaultTransitionTypeBuilder} from "../../src/model/default-transition-type.builder";
26-
import {FunctionRefBuilder} from '../../src/model/function-ref.builder';
18+
import {WorkflowBuilder} from "../../src";
19+
import {FunctionDefBuilder} from "../../src";
20+
import {DatabasedSwitchBuilder} from "../../src";
21+
import {TransitionDataConditionBuilder} from "../../src";
22+
import {OperationStateBuilder} from "../../src";
23+
import {SubFlowStateBuilder} from "../../src";
24+
import {ActionBuilder} from "../../src";
25+
import {DefaultTransitionTypeBuilder} from "../../src";
26+
import {FunctionRefBuilder} from "../../src";
2727

2828

2929
describe("applicationrequest workflow example", () => {

spec/examples/booklending.spec.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*
1616
*/
17+
import * as fs from 'fs';
1718
import {
1819
ActionBuilder,
1920
DatabasedSwitchBuilder,
@@ -22,15 +23,14 @@ import {
2223
TransitionDataConditionBuilder,
2324
WorkflowBuilder,
2425
} from '../../src';
25-
import * as fs from 'fs';
26-
import {StartBuilder} from '../../src/model/start.builder';
27-
import {EventStateBuilder} from '../../src/model/event-state.builder';
28-
import {OnEventBuilder} from '../../src/model/on-event.builder';
29-
import {FunctionRefBuilder} from '../../src/model/function-ref.builder';
30-
import {FunctionsBuilder} from '../../src/model/functions.builder';
31-
import {EventBasedSwitchBuilder} from '../../src/model/event-based-switch.builder';
32-
import {TransitionEventConditionBuilder} from '../../src/model/transition-event-condition.builder';
33-
import {DelayStateBuilder} from '../../src/model/delay-state.builder';
26+
import {StartBuilder} from "../../src";
27+
import {EventStateBuilder} from "../../src";
28+
import {OnEventBuilder} from "../../src";
29+
import {FunctionRefBuilder} from "../../src";
30+
import {FunctionsBuilder} from "../../src";
31+
import {EventBasedSwitchBuilder} from "../../src";
32+
import {TransitionEventConditionBuilder} from "../../src";
33+
import {DelayStateBuilder} from "../../src";
3434

3535

3636
describe("booklending workflow example", () => {
@@ -127,11 +127,11 @@ describe("booklending workflow example", () => {
127127
])
128128
.withTransition("Wait two weeks")
129129
.build(),
130-
new DelayStateBuilder()
131-
.withName("Wait two weeks")
132-
.withTimeDelay("PT2W")
133-
.withTransition("Get Book Status")
134-
.build(),
130+
new DelayStateBuilder()
131+
.withName("Wait two weeks")
132+
.withTimeDelay("PT2W")
133+
.withTransition("Get Book Status")
134+
.build(),
135135
new OperationStateBuilder()
136136
.withName("Check Out Book")
137137
.withActions([
@@ -140,7 +140,7 @@ describe("booklending workflow example", () => {
140140
new FunctionRefBuilder()
141141
.withRefName("Check out book with id")
142142
.withArguments({
143-
"bookid": "${ .book.id }"
143+
"bookid": "${ .book.id }",
144144
})
145145
.build())
146146
.build(),
@@ -150,14 +150,14 @@ describe("booklending workflow example", () => {
150150
.withRefName("Notify Lender for checkout")
151151
.withArguments({
152152
"bookid": "${ .book.id }",
153-
"lender": "${ .lender }"
153+
"lender": "${ .lender }",
154154
})
155155
.build())
156-
.build()
156+
.build(),
157157

158158
])
159159
.withEnd(true)
160-
.build()
160+
.build(),
161161

162162
])
163163
.withFunctions(new FunctionsBuilder()

spec/examples/carauctionbids.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
*/
1717
import {ActionBuilder, FunctionDefBuilder, WorkflowBuilder} from '../../src';
1818
import * as fs from 'fs';
19-
import {StartBuilder} from '../../src/model/start.builder';
20-
import {EventsBuilder} from '../../src/model/events.builder';
21-
import {EventBuilder} from '../../src/model/event.builder';
22-
import {EventStateBuilder} from '../../src/model/event-state.builder';
23-
import {OnEventBuilder} from '../../src/model/on-event.builder';
24-
import {FunctionRefBuilder} from '../../src/model/function-ref.builder';
19+
import {StartBuilder} from "../../src";
20+
import {EventsBuilder} from "../../src";
21+
import {EventBuilder} from "../../src";
22+
import {EventStateBuilder} from "../../src";
23+
import {OnEventBuilder} from "../../src";
24+
import {FunctionRefBuilder} from "../../src";
2525

2626
describe("carauctionbids workflow example", () => {
2727

spec/examples/checkcarvitals.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"id": "checkcarvitals",
3+
"name": "Check Car Vitals Workflow",
4+
"version": "1.0",
5+
"start": "WhenCarIsOn",
6+
"states": [
7+
{
8+
"name": "WhenCarIsOn",
9+
"type": "event",
10+
"onEvents": [
11+
{
12+
"eventRefs": [
13+
"CarTurnedOnEvent"
14+
]
15+
}
16+
],
17+
"transition": "DoCarVitalsChecks"
18+
},
19+
{
20+
"name": "DoCarVitalsChecks",
21+
"type": "subflow",
22+
"workflowId": "vitalscheck",
23+
"repeat": {
24+
"stopOnEvents": [
25+
"CarTurnedOffEvent"
26+
]
27+
},
28+
"end": true
29+
}
30+
],
31+
"events": [
32+
{
33+
"name": "CarTurnedOnEvent",
34+
"type": "car.events",
35+
"source": "my/car/start"
36+
},
37+
{
38+
"name": "CarTurnedOffEvent",
39+
"type": "car.events",
40+
"source": "my/car/start"
41+
}
42+
]
43+
}

spec/examples/checkcarvitals.spec.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2021-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+
import {WorkflowBuilder} from "../../src/model/workflow.builder";
18+
import * as fs from "fs";
19+
import {SubFlowStateBuilder} from "../../src/model/sub-flow-state.builder";
20+
import {EventBuilder, EventsBuilder, EventStateBuilder, OnEventBuilder, RepeatBuilder} from '../../src';
21+
22+
23+
describe("checkcarvitals workflow example", () => {
24+
25+
26+
it('should generate Workflow object', function () {
27+
28+
const workflow = new WorkflowBuilder()
29+
.withId("checkcarvitals")
30+
.withVersion("1.0")
31+
.withName("Check Car Vitals Workflow")
32+
.withStart("WhenCarIsOn")
33+
.withStates([
34+
new EventStateBuilder()
35+
.withName("WhenCarIsOn")
36+
.withOnEvents([
37+
new OnEventBuilder()
38+
.withEventsRef(["CarTurnedOnEvent"])
39+
.build(),
40+
])
41+
.withTransition("DoCarVitalsChecks")
42+
.build(),
43+
new SubFlowStateBuilder()
44+
.withName("DoCarVitalsChecks")
45+
.withWorkflowId("vitalscheck")
46+
.withRepeat(new RepeatBuilder()
47+
.withStopOnEvents(["CarTurnedOffEvent"])
48+
.build())
49+
.withEnd(true)
50+
.build(),
51+
])
52+
.withEvents(
53+
new EventsBuilder()
54+
.withEvents([
55+
new EventBuilder()
56+
.withName("CarTurnedOnEvent")
57+
.withType("car.events")
58+
.withSource("my/car/start")
59+
.build(),
60+
new EventBuilder()
61+
.withName("CarTurnedOffEvent")
62+
.withType("car.events")
63+
.withSource("my/car/start")
64+
.build(),
65+
66+
]).build(),
67+
)
68+
.build();
69+
70+
71+
const expected = JSON.parse(fs.readFileSync("./spec/examples/checkcarvitals.json")
72+
.toLocaleString()) as any;
73+
expect(workflow).toEqual(expected);
74+
75+
});
76+
77+
78+
});

spec/examples/solvemathproblems.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"id": "solvemathproblems",
3+
"version": "1.0",
4+
"name": "Solve Math Problems Workflow",
5+
"description": "Solve math problems",
6+
"start": "Solve",
7+
"functions": [
8+
{
9+
"name": "solveMathExpressionFunction",
10+
"type": "rest",
11+
"operation": "http://myapis.org/mapthapis.json#solveExpression"
12+
}
13+
],
14+
"states": [
15+
{
16+
"name": "Solve",
17+
"type": "foreach",
18+
"inputCollection": "${ .expressions }",
19+
"iterationParam": "singleexpression",
20+
"outputCollection": "${ .results }",
21+
"actions": [
22+
{
23+
"functionRef": {
24+
"refName": "solveMathExpressionFunction",
25+
"arguments": {
26+
"expression": "${ .singleexpression }"
27+
}
28+
}
29+
}
30+
],
31+
"stateDataFilter": {
32+
"output": "${ .results }"
33+
},
34+
"end": true
35+
}
36+
]
37+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2021-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+
import {WorkflowBuilder} from "../../src/model/workflow.builder";
18+
import * as fs from "fs";
19+
import {ActionBuilder, FunctionDefBuilder, FunctionRefBuilder} from '../../src';
20+
import {ForEachStateBuilder} from '../../src/model/for-each-state.builder';
21+
import {StateDataFilterBuilder} from '../../src/model/state-data-filter.builder';
22+
23+
24+
describe("solvemathproblems workflow example", () => {
25+
26+
27+
it('should generate Workflow object', function () {
28+
29+
const workflow = new WorkflowBuilder()
30+
.withId("solvemathproblems")
31+
.withVersion("1.0")
32+
.withName("Solve Math Problems Workflow")
33+
.withDescription("Solve math problems")
34+
.withStart("Solve")
35+
.withFunctions([
36+
new FunctionDefBuilder()
37+
.withName("solveMathExpressionFunction")
38+
.withOperation("http://myapis.org/mapthapis.json#solveExpression")
39+
.build(),
40+
])
41+
.withStates([
42+
new ForEachStateBuilder()
43+
.withName("Solve")
44+
.withInputCollection("${ .expressions }")
45+
.withIterationParam("singleexpression")
46+
.withOutputCollection("${ .results }")
47+
.withActions([
48+
new ActionBuilder()
49+
.withFunctionRef(
50+
new FunctionRefBuilder()
51+
.withRefName("solveMathExpressionFunction")
52+
.withArguments({
53+
"expression": "${ .singleexpression }",
54+
})
55+
.build())
56+
.build(),
57+
])
58+
.withStateDataFilter(
59+
new StateDataFilterBuilder()
60+
.withOutput("${ .results }")
61+
.build(),
62+
)
63+
.withEnd(true)
64+
.build(),
65+
])
66+
.build();
67+
68+
69+
const expected = JSON.parse(fs.readFileSync("./spec/examples/solvemathproblems.json")
70+
.toLocaleString()) as any;
71+
expect(workflow).toEqual(expected);
72+
73+
});
74+
75+
76+
});

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export {EventBasedSwitchBuilder} from "./model/event-based-switch.builder";
2828
export {EventRefBuilder} from "./model/event-ref.builder";
2929
export {EventStateBuilder} from "./model/event-state.builder";
3030
export {EventsBuilder} from "./model/events.builder";
31+
export {ForEachStateBuilder} from "./model/for-each-state.builder";
3132
export {FunctionDefBuilder} from "./model/function-def.builder";
3233
export {FunctionRefBuilder} from "./model/function-ref.builder";
3334
export {FunctionsBuilder} from "./model/functions.builder";
@@ -39,6 +40,7 @@ export {ProduceEventDefBuilder} from "./model/produce-event-def.builder";
3940
export {RepeatBuilder} from "./model/repeat.builder";
4041
export {ScheduleBuilder} from "./model/schedule.builder";
4142
export {StartBuilder} from "./model/start.builder";
43+
export {StateDataFilterBuilder} from "./model/state-data-filter.builder";
4244
export {SubFlowStateBuilder} from "./model/sub-flow-state.builder";
4345
export {TransitionDataConditionBuilder} from "./model/transition-data-condition.builder";
4446
export {TransitionEventConditionBuilder} from "./model/transition-event-condition.builder";

0 commit comments

Comments
 (0)