Skip to content

Commit 713d25f

Browse files
author
Tihomir Surdilovic
authored
Merge pull request #57 from tsurdilo/addjq
add jq and expressionLang param
2 parents 71a5947 + c83053a commit 713d25f

File tree

81 files changed

+299
-231
lines changed

Some content is hidden

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

81 files changed

+299
-231
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ states:
122122
- functionRef:
123123
refName: greetingFunction
124124
arguments:
125-
name: "$.greet.name"
125+
name: ".greet.name"
126126
actionDataFilter:
127-
dataResultsPath: "$.payload.greeting"
127+
dataResultsPath: ".payload.greeting"
128128
stateDataFilter:
129-
dataOutputPath: "$.greeting"
129+
dataOutputPath: ".greeting"
130130
end: true
131131
```
132132

api/src/main/java/io/serverlessworkflow/api/serializers/WorkflowSerializer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public void serialize(Workflow workflow,
7575
workflow.getSchemaVersion());
7676
}
7777

78+
if (workflow.getExtensions() != null && !workflow.getExpressionLang().isEmpty()) {
79+
gen.writeStringField("expressionLang",
80+
workflow.getExpressionLang());
81+
}
82+
7883
if (workflow.getExecTimeout() != null) {
7984
gen.writeObjectField("execTimeout", workflow.getExecTimeout());
8085
}

api/src/main/resources/schema/workflow.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
"type": "string",
3232
"description": "Serverless Workflow schema version"
3333
},
34+
"expressionLang": {
35+
"type": "string",
36+
"description": "Identifies the expression language used for workflow expressions. Default is 'jq'",
37+
"default": "jq",
38+
"minLength": 1
39+
},
3440
"execTimeout": {
3541
"description": "Workflow execution timeout",
3642
"$ref": "exectimeout/exectimeout.json"

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.junit.jupiter.params.provider.ValueSource;
3535

3636
import java.util.List;
37-
import java.util.Map;
3837

3938
import static org.junit.jupiter.api.Assertions.*;
4039

@@ -240,7 +239,7 @@ public void testFunctionRefs(String workflowLocation) {
240239
FunctionRef functionRef2 = action2.getFunctionRef();
241240
assertEquals("sendRejectionEmailFunction", functionRef2.getRefName());
242241
assertEquals(1, functionRef2.getArguments().size());
243-
assertEquals("{{ $.customer }}", functionRef2.getArguments().get("applicant").asText());
242+
assertEquals("${ .customer }", functionRef2.getArguments().get("applicant").asText());
244243
}
245244

246245
@ParameterizedTest
@@ -387,4 +386,18 @@ public void testSimplifiedCron(String workflowLocation) {
387386

388387
assertEquals("0 0/15 * * * ?", operationState.getStart().getSchedule().getCron().getExpression());
389388
}
389+
390+
@ParameterizedTest
391+
@ValueSource(strings = {"/features/expressionlang.json", "/features/expressionlang.yml"})
392+
public void testExpressionLang(String workflowLocation) {
393+
Workflow workflow = Workflow.fromSource(WorkflowTestUtils.readWorkflowFile(workflowLocation));
394+
395+
assertNotNull(workflow);
396+
assertNotNull(workflow.getId());
397+
assertNotNull(workflow.getName());
398+
assertNotNull(workflow.getStates());
399+
400+
assertNotNull(workflow.getExpressionLang());
401+
assertEquals("abc", workflow.getExpressionLang());
402+
}
390403
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"start": true,
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
],
@@ -43,7 +43,7 @@
4343
"functionRef": {
4444
"refName": "sendRejectionEmailFunction",
4545
"arguments": {
46-
"applicant": "{{ $.applicant }}"
46+
"applicant": "${ .applicant }"
4747
}
4848
}
4949
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ states:
1111
type: switch
1212
start: true
1313
dataConditions:
14-
- condition: "{{ $.applicants[?(@.age >= 18)] }}"
14+
- condition: "${ .applicants[?(@.age >= 18)] }"
1515
transition: StartApplication
16-
- condition: "{{ $.applicants[?(@.age < 18)] }}"
16+
- condition: "${ .applicants[?(@.age < 18)] }"
1717
transition: RejectApplication
1818
default:
1919
transition: RejectApplication
@@ -28,5 +28,5 @@ states:
2828
- functionRef:
2929
refName: sendRejectionEmailFunction
3030
arguments:
31-
applicant: "{{ $.applicant }}"
31+
applicant: "${ .applicant }"
3232
end: true

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"functionRef": {
3232
"refName": "StoreBidFunction",
3333
"arguments": {
34-
"bid": "{{ $.bid }}"
34+
"bid": "${ .bid }"
3535
}
3636
}
3737
}]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ states:
2323
- functionRef:
2424
refName: StoreBidFunction
2525
arguments:
26-
bid: "{{ $.bid }}"
26+
bid: "${ .bid }"
2727
end:
2828
terminate: true

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"functionRef": {
3535
"refName": "callCreditCheckMicroservice",
3636
"arguments": {
37-
"customer": "{{ $.customer }}"
37+
"customer": "${ .customer }"
3838
}
3939
}
4040
},
@@ -48,12 +48,12 @@
4848
"dataConditions": [
4949
{
5050
"name": "Approved",
51-
"condition": "{{ $.creditCheck[?(@.decision == 'Approved')] }}",
51+
"condition": "${ .creditCheck[?(@.decision == 'Approved')] }",
5252
"transition": "StartApplication"
5353
},
5454
{
5555
"name": "Denied",
56-
"condition": "{{ $.creditCheck[?(@.decision == 'Denied')] }}",
56+
"condition": "${ .creditCheck[?(@.decision == 'Denied')] }",
5757
"transition": "RejectApplication"
5858
}
5959
],
@@ -76,7 +76,7 @@
7676
"functionRef": {
7777
"refName": "sendRejectionEmailFunction",
7878
"arguments": {
79-
"applicant": "{{ $.customer }}"
79+
"applicant": "${ .customer }"
8080
}
8181
}
8282
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ states:
2222
functionRef:
2323
refName: callCreditCheckMicroservice
2424
arguments:
25-
customer: "{{ $.customer }}"
25+
customer: "${ .customer }"
2626
eventRef: CreditCheckCompletedEvent
2727
timeout: PT15M
2828
transition: EvaluateDecision
2929
- name: EvaluateDecision
3030
type: switch
3131
dataConditions:
3232
- name: Approved
33-
condition: "{{ $.creditCheck[?(@.decision == 'Approved')] }}"
33+
condition: "${ .creditCheck[?(@.decision == 'Approved')] }"
3434
transition: StartApplication
3535
- name: Denied
36-
condition: "{{ $.creditCheck[?(@.decision == 'Denied')] }}"
36+
condition: "${ .creditCheck[?(@.decision == 'Denied')] }"
3737
transition: RejectApplication
3838
default:
3939
transition: RejectApplication
@@ -48,5 +48,5 @@ states:
4848
- functionRef:
4949
refName: sendRejectionEmailFunction
5050
arguments:
51-
applicant: "{{ $.customer }}"
51+
applicant: "${ .customer }"
5252
end: true

0 commit comments

Comments
 (0)