Skip to content

Commit 1caf0e8

Browse files
committed
Updated README.md for Utils #127
Signed-off-by: manick02 <[email protected]>
1 parent 1c7c9ba commit 1caf0e8

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

README.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ states:
141141
end: true
142142
```
143143
144-
To parse it and create a Workflow intance you can do:
144+
To parse it and create a Workflow instance you can do:
145145
146146
``` java
147147
Workflow workflow = Workflow.fromSource(source);
@@ -288,5 +288,43 @@ Here are some generated diagrams from the specification examples (with legend en
288288

289289
2. [Send CloudEvent on Workflow completion Example](https://github.com/serverlessworkflow/specification/blob/master/examples/examples.md#send-cloudevent-on-workfow-completion-example)
290290
<p align="center">
291-
<img src="img/provisionorders.png" alt="Send Cloud Event on Workflow complation"/>
291+
<img src="img/provisionorders.png" alt="Send Cloud Event on Workflow completion"/>
292292
</p>
293+
294+
#### Using Workflow Utils
295+
Workflow utility allows you to interpret the Serverless Workflow Model.
296+
Once you have a `Workflow` instance, you can use it
297+
##### Get Starting State
298+
```Java
299+
State startingState = WorkflowUtils.getStartingState(workflow);
300+
```
301+
##### Get States by State Type
302+
```Java
303+
List<State> states = WorkflowUtils.getStates(workflow, DefaultState.Type.EVENT);
304+
```
305+
##### Get Consumed-Events, Produced-Events and their count
306+
```Java
307+
List<EventDefinition> consumedEvents = WorkflowUtils.getWorkflowConsumedEvents(workflow);
308+
int consumedEventsCount = WorkflowUtils.getWorkflowConsumedEventsCount(workflow);
309+
310+
List<EventDefinition> producedEvents = WorkflowUtils.getWorkflowProducedEvents(workflow);
311+
int producedEventsCount = WorkflowUtils.getWorkflowProducedEventsCount(workflow);
312+
```
313+
##### Get Defined Consumed-Events, Defined Produced-Events and their count
314+
```Java
315+
List<EventDefinition> consumedEvents = WorkflowUtils.getWorkflowConsumedEventsCount(workflow);
316+
int consumedEventsCount = WorkflowUtils.getWorkflowConsumedEventsCount(workflow);
317+
318+
List<EventDefinition> producedEvents = WorkflowUtils.getWorkflowProducedEvents(workflow);
319+
int producedEventsCount = WorkflowUtils.getWorkflowProducedEventsCount(workflow);
320+
```
321+
##### Get Function definitions which is used by an action
322+
```Java
323+
FunctionDefinition finalizeApplicationFunctionDefinition =
324+
WorkflowUtils.getFunctionDefinitionsForAction(workflow, "finalizeApplicationAction");
325+
```
326+
##### Get Actions which uses a Function definition
327+
```Java
328+
List<Action> actionsForFunctionDefinition =
329+
WorkflowUtils.getActionsForFunctionDefinition(workflow, functionRefName);
330+
```

utils/src/test/java/io/serverlessworkflow/util/EventsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
public class EventsTest {
3030
@ParameterizedTest
3131
@ValueSource(strings = {"/events/workflowwithevents.yml"})
32-
public void testGetDefinedConsumedEvents(String workflowEvents) {
32+
public void testGetConsumedEvents(String workflowEvents) {
3333
int expectedEventsCount = 2;
3434
Collection<String> expectedConsumedEvent =
3535
Arrays.asList("SATScoresReceived", "RecommendationLetterReceived");
@@ -44,7 +44,7 @@ public void testGetDefinedConsumedEvents(String workflowEvents) {
4444

4545
@ParameterizedTest
4646
@ValueSource(strings = {"/events/workflowwithevents.yml"})
47-
public void testGetDefinedConsumedEventsCount(String workflowEvents) {
47+
public void testGetConsumedEventsCount(String workflowEvents) {
4848
int expectedEventsCount = 2;
4949
Workflow workflow = TestUtils.createWorkflowFromTestResource(workflowEvents);
5050
int workflowConsumedEventsCount = WorkflowUtils.getWorkflowConsumedEventsCount(workflow);

0 commit comments

Comments
 (0)