Skip to content
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
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,19 @@ String diagramSVG = workflowDiagram.getSvgDiagram();
`diagramSVG` includes the diagram SVG source which you can then decide to save to a file,
print, or process further.

Here are some generated diagrams from the specification examples:
By default the diagram legend is now shown. If you want to enable it you can do:

``` java
Workflow workflow = Workflow.fromSource(source);

WorkflowDiagram workflowDiagram = new WorkflowDiagramImpl();
workflowDiagram.setWorkflow(workflow)
.showLegend(true);

String diagramSVG = workflowDiagram.getSvgDiagram();
```

Here are some generated diagrams from the specification examples (with legend enabled):

1. [Job Monitoring Example](https://github.com/serverlessworkflow/specification/blob/master/examples/examples.md#Monitor-Job-Example)
<p align="center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public interface WorkflowDiagram {
WorkflowDiagram setSource(String source);

String getSvgDiagram() throws Exception;

WorkflowDiagram showLegend(boolean showLegend);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class WorkflowDiagramImpl implements WorkflowDiagram {

private String source;
private Workflow workflow;
private boolean showLegend = false;

@Override
public WorkflowDiagram setWorkflow(Workflow workflow) {
Expand All @@ -46,7 +47,6 @@ public WorkflowDiagram setWorkflow(Workflow workflow) {
public WorkflowDiagram setSource(String source) {
this.source = source;
this.workflow = Workflow.fromSource(source);

return this;
}

Expand All @@ -55,10 +55,16 @@ public String getSvgDiagram() throws Exception {
if(workflow == null) {
throw new IllegalAccessException("Unable to get diagram - no workflow set.");
}
SourceStringReader reader = new SourceStringReader(WorkflowToPlantuml.convert(workflow));
SourceStringReader reader = new SourceStringReader(WorkflowToPlantuml.convert(workflow, showLegend));
final ByteArrayOutputStream os = new ByteArrayOutputStream();
String desc = reader.generateImage(os, new FileFormatOption(FileFormat.SVG));
os.close();
return new String(os.toByteArray(), Charset.forName("UTF-8"));
}

@Override
public WorkflowDiagram showLegend(boolean showLegend) {
this.showLegend = showLegend;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ public class WorkflowDiagramModel {
private List<ModelStateDef> modelStateDefs = new ArrayList<>();
private List<ModelState> modelStates = new ArrayList<>();
private List<ModelConnection> modelConnections = new ArrayList<>();
private boolean showLegend;

public WorkflowDiagramModel(Workflow workflow) {
public WorkflowDiagramModel(Workflow workflow, boolean showLegend) {
this.workflow = workflow;
this.showLegend = showLegend;
inspect(workflow);
}

Expand Down Expand Up @@ -409,4 +411,8 @@ public List<ModelStateDef> getModelStateDefs() {
public void setModelStateDefs(List<ModelStateDef> modelStateDefs) {
this.modelStateDefs = modelStateDefs;
}

public boolean getShowLegend() {
return showLegend;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import org.thymeleaf.context.Context;

public class WorkflowToPlantuml {
public static String convert(Workflow workflow) {
public static String convert(Workflow workflow, boolean showLegend) {
TemplateEngine plantUmlTemplateEngine = ThymeleafConfig.templateEngine;
Context context = new Context();
context.setVariable("diagram", new WorkflowDiagramModel(workflow));
context.setVariable("diagram", new WorkflowDiagramModel(workflow, showLegend));

return plantUmlTemplateEngine.process("workflow-template", context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ state "[(${diagram.title})]" as workflow << workflow >> {

}

[# th:if="${diagram.showLegend}" ]
legend center
State Types and Border Colors:
| Event | Operation | Switch | Delay | Parallel | SubFlow | Inject | ForEach | CallBack |
|<#7fe5f0>|<#bada55>|<#92a0f2>|<#b83b5e>|<#6a2c70>|<#87753c>|<#1e5f74>|<#931a25>|<#ffcb8e>|
endlegend
[/]

@enduml