Skip to content

Updated README.md for Utils #127 #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 12, 2021
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
42 changes: 40 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ states:
end: true
```

To parse it and create a Workflow intance you can do:
To parse it and create a Workflow instance you can do:

``` java
Workflow workflow = Workflow.fromSource(source);
Expand Down Expand Up @@ -288,5 +288,43 @@ Here are some generated diagrams from the specification examples (with legend en

2. [Send CloudEvent on Workflow completion Example](https://github.com/serverlessworkflow/specification/blob/master/examples/examples.md#send-cloudevent-on-workfow-completion-example)
<p align="center">
<img src="img/provisionorders.png" alt="Send Cloud Event on Workflow complation"/>
<img src="img/provisionorders.png" alt="Send Cloud Event on Workflow completion"/>
</p>

#### Using Workflow Utils
Workflow utils provide a number of useful methods for extracting information from workflow definitions.
Once you have a `Workflow` instance, you can use it
##### Get Starting State
```Java
State startingState = WorkflowUtils.getStartingState(workflow);
```
##### Get States by State Type
```Java
List<State> states = WorkflowUtils.getStates(workflow, DefaultState.Type.EVENT);
```
##### Get Consumed-Events, Produced-Events and their count
```Java
List<EventDefinition> consumedEvents = WorkflowUtils.getWorkflowConsumedEvents(workflow);
int consumedEventsCount = WorkflowUtils.getWorkflowConsumedEventsCount(workflow);

List<EventDefinition> producedEvents = WorkflowUtils.getWorkflowProducedEvents(workflow);
int producedEventsCount = WorkflowUtils.getWorkflowProducedEventsCount(workflow);
```
##### Get Defined Consumed-Events, Defined Produced-Events and their count
```Java
List<EventDefinition> consumedEvents = WorkflowUtils.getWorkflowConsumedEventsCount(workflow);
int consumedEventsCount = WorkflowUtils.getWorkflowConsumedEventsCount(workflow);

List<EventDefinition> producedEvents = WorkflowUtils.getWorkflowProducedEvents(workflow);
int producedEventsCount = WorkflowUtils.getWorkflowProducedEventsCount(workflow);
```
##### Get Function definitions which is used by an action
```Java
FunctionDefinition finalizeApplicationFunctionDefinition =
WorkflowUtils.getFunctionDefinitionsForAction(workflow, "finalizeApplicationAction");
```
##### Get Actions which uses a Function definition
```Java
List<Action> actionsForFunctionDefinition =
WorkflowUtils.getActionsForFunctionDefinition(workflow, functionRefName);
```
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class EventsTest {
@ParameterizedTest
@ValueSource(strings = {"/events/workflowwithevents.yml"})
public void testGetDefinedConsumedEvents(String workflowEvents) {
public void testGetConsumedEvents(String workflowEvents) {
int expectedEventsCount = 2;
Collection<String> expectedConsumedEvent =
Arrays.asList("SATScoresReceived", "RecommendationLetterReceived");
Expand All @@ -44,7 +44,7 @@ public void testGetDefinedConsumedEvents(String workflowEvents) {

@ParameterizedTest
@ValueSource(strings = {"/events/workflowwithevents.yml"})
public void testGetDefinedConsumedEventsCount(String workflowEvents) {
public void testGetConsumedEventsCount(String workflowEvents) {
int expectedEventsCount = 2;
Workflow workflow = TestUtils.createWorkflowFromTestResource(workflowEvents);
int workflowConsumedEventsCount = WorkflowUtils.getWorkflowConsumedEventsCount(workflow);
Expand Down