Skip to content

Commit 011f0a4

Browse files
author
Tihomir Surdilovic
authored
Merge pull request #15 from tsurdilo/diagramskin
Updating generated diagram look/feel and adding legend
2 parents daa34bb + ee8e63b commit 011f0a4

File tree

7 files changed

+103
-17
lines changed

7 files changed

+103
-17
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,11 @@ List<ValidationError> validationErrors = workflowValidator.setWorkflow(workflow)
270270

271271
#### Building Workflow Diagram
272272

273-
Given a valid workflow source or a Workflow object you can build the workflow Diagram SVG.
274-
Diagrams are built using [PlantUML](https://plantuml.com/) and can be embedded inside your
273+
Given a valid workflow definition (JSON/YAML) or a Workflow object you can build the workflow diagram SVG.
274+
The generated diagram SVG uses [PlantUML](https://plantuml.com/) state diagram visualization and can be embedded inside your
275275
tooling or web pages, or any SVG viewer.
276276

277-
You can build the workflow diagram SVG the the following code:
277+
You can build the workflow diagram SVG with the following code:
278278

279279
``` java
280280
Workflow workflow = Workflow.fromSource(source);
@@ -285,7 +285,7 @@ workflowDiagram.setWorkflow(workflow);
285285
String diagramSVG = workflowDiagram.getSvgDiagram();
286286
```
287287

288-
`diagramSVG` includes the diagram SVG which you can then decide to save to a file,
288+
`diagramSVG` includes the diagram SVG source which you can then decide to save to a file,
289289
print, or process further.
290290

291291
Here are some generated diagrams from the specification examples:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2020-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+
package io.serverlessworkflow.diagram.model;
18+
19+
import io.serverlessworkflow.diagram.utils.WorkflowDiagramUtils;
20+
21+
public class ModelStateDef {
22+
private String name;
23+
private String type;
24+
25+
public ModelStateDef(String name, String type) {
26+
this.name = name;
27+
this.type = type;
28+
}
29+
30+
@Override
31+
public String toString() {
32+
StringBuffer retBuff = new StringBuffer();
33+
retBuff.append(WorkflowDiagramUtils.stateDef)
34+
.append(name)
35+
.append(WorkflowDiagramUtils.typeDefStart)
36+
.append(type)
37+
.append(WorkflowDiagramUtils.typeDefEnd);
38+
return retBuff.toString();
39+
}
40+
}

diagram/src/main/java/io/serverlessworkflow/diagram/model/WorkflowDiagramModel.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import io.serverlessworkflow.api.Workflow;
2020
import io.serverlessworkflow.api.interfaces.State;
21-
import io.serverlessworkflow.api.interfaces.WorkflowDiagram;
2221
import io.serverlessworkflow.api.states.*;
2322
import io.serverlessworkflow.api.switchconditions.DataCondition;
2423
import io.serverlessworkflow.api.switchconditions.EventCondition;
@@ -34,6 +33,7 @@ public class WorkflowDiagramModel {
3433
private String title;
3534
private String legend;
3635
private String footer;
36+
private List<ModelStateDef> modelStateDefs = new ArrayList<>();
3737
private List<ModelState> modelStates = new ArrayList<>();
3838
private List<ModelConnection> modelConnections = new ArrayList<>();
3939

@@ -44,10 +44,9 @@ public WorkflowDiagramModel(Workflow workflow) {
4444

4545
private void inspect(Workflow workflow) {
4646
// title
47-
setTitle(WorkflowDiagramUtils.title + workflow.getName());
47+
setTitle(workflow.getName());
4848
if (workflow.getVersion() != null && workflow.getVersion().trim().length() > 0) {
4949
StringBuffer titleBuf = new StringBuffer()
50-
.append(WorkflowDiagramUtils.title)
5150
.append(workflow.getName())
5251
.append(WorkflowDiagramUtils.versionSeparator)
5352
.append(workflow.getVersion());
@@ -68,15 +67,24 @@ private void inspect(Workflow workflow) {
6867
// footer
6968
setFooter(WorkflowDiagramUtils.footer);
7069

71-
// states
72-
inspectStates(workflow);
70+
// state definitions
71+
inspectStateDefinitions(workflow);
7372

74-
// connections
75-
inspectConnections(workflow);
73+
// states info
74+
inspectStatesInfo(workflow);
7675

76+
// states connections
77+
inspectStatesConnections(workflow);
78+
79+
}
80+
81+
private void inspectStateDefinitions(Workflow workflow) {
82+
for(State state : workflow.getStates()) {
83+
modelStateDefs.add(new ModelStateDef(state.getName(), state.getType().value()));
84+
}
7785
}
7886

79-
private void inspectConnections(Workflow workflow) {
87+
private void inspectStatesConnections(Workflow workflow) {
8088
State workflowStartState = WorkflowDiagramUtils.getWorkflowStartState(workflow);
8189
modelConnections.add(new ModelConnection(WorkflowDiagramUtils.wfStart, workflowStartState.getName(), ""));
8290

@@ -242,7 +250,7 @@ private void inspectConnections(Workflow workflow) {
242250
}
243251
}
244252

245-
private void inspectStates(Workflow workflow) {
253+
private void inspectStatesInfo(Workflow workflow) {
246254
List<State> workflowStates = workflow.getStates();
247255
for(State state : workflowStates) {
248256
ModelState modelState = new ModelState(state.getName());
@@ -393,4 +401,12 @@ public List<ModelConnection> getModelConnections() {
393401
public void setModelConnections(List<ModelConnection> modelConnections) {
394402
this.modelConnections = modelConnections;
395403
}
404+
405+
public List<ModelStateDef> getModelStateDefs() {
406+
return modelStateDefs;
407+
}
408+
409+
public void setModelStateDefs(List<ModelStateDef> modelStateDefs) {
410+
this.modelStateDefs = modelStateDefs;
411+
}
396412
}

diagram/src/main/java/io/serverlessworkflow/diagram/utils/WorkflowDiagramUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public class WorkflowDiagramUtils {
3434
public static final String footer = "center footer Serverless Workflow Specification - serverlessworkflow.io";
3535
public static final String legendStart = new StringBuffer().append("legend top center").append(System.lineSeparator()).toString();
3636
public static final String legendEnd = new StringBuffer().append(System.lineSeparator()).append("endlegend").toString();
37+
public static final String stateDef = "state ";
38+
public static final String typeDefStart = " << ";
39+
public static final String typeDefEnd = " >> ";
40+
3741

3842
public static State getWorkflowStartState(Workflow workflow) {
3943
return workflow.getStates().stream()
Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
@startuml
2-
[(${diagram.title})]
3-
[(${diagram.legend})]
4-
[(${diagram.footer})]
52
skinparam backgroundColor White
3+
skinparam legendBackgroundColor White
4+
skinparam legendBorderColor White
65
skinparam state {
76
StartColor Green
8-
EndColor Red
7+
EndColor Orange
8+
BackgroundColor GhostWhite
9+
BackgroundColor<< workflow >> White
10+
BorderColor Black
11+
ArrowColor Black
12+
13+
BorderColor<< event >> #7fe5f0
14+
BorderColor<< operation >> #bada55
15+
BorderColor<< switch >> #92a0f2
16+
BorderColor<< delay >> #b83b5e
17+
BorderColor<< parallel >> #6a2c70
18+
BorderColor<< subflow >> #87753c
19+
BorderColor<< inject >> #1e5f74
20+
BorderColor<< foreach >> #931a25
21+
BorderColor<< callback >> #ffcb8e
922
}
23+
state "[(${diagram.title})]" as workflow << workflow >> {
24+
25+
[# th:each="stateDef : ${diagram.modelStateDefs}" ]
26+
[(${stateDef.toString()})]
27+
[/]
1028

1129
[# th:each="state : ${diagram.modelStates}" ]
1230
[(${state.toString()})]
@@ -16,4 +34,12 @@ skinparam state {
1634
[(${connection.toString()})]
1735
[/]
1836

37+
}
38+
39+
legend center
40+
State Types and Border Colors:
41+
| Event | Operation | Switch | Delay | Parallel | SubFlow | Inject | ForEach | CallBack |
42+
|<#7fe5f0>|<#bada55>|<#92a0f2>|<#b83b5e>|<#6a2c70>|<#87753c>|<#1e5f74>|<#931a25>|<#ffcb8e>|
43+
endlegend
44+
1945
@enduml

img/jobmonitoring.png

-4.78 KB
Loading

img/provisionorders.png

-36.8 KB
Loading

0 commit comments

Comments
 (0)