Skip to content

Commit 59df160

Browse files
author
Pascal Dal Farra
committed
feat: add global diagram settings + update arrow colors + update unit tests resources accordingly
1 parent 961f5ce commit 59df160

35 files changed

+234
-192
lines changed

Diff for: spring-statemachine-uml/src/main/java/org/springframework/statemachine/plantuml/PlantUmlWriter.java

+6-11
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,10 @@ public String toPlantUml(
153153
historyStatesToHistoryId = StateMachineHelper.collectHistoryStates(stateMachine);
154154
historyTransitions = new ArrayList<>();
155155

156-
StringBuilder sb = new StringBuilder();
157-
sb.append("""
158-
@startuml
159-
'https://plantuml.com/state-diagram
160-
161-
'hide description area for state without description
162-
hide empty description
163-
164-
""");
156+
StringBuilder sb = new StringBuilder("@startuml\n")
157+
.append(PlantUmlWriterParameters.getStateDiagramSettings(plantUmlWriterParameters))
158+
.append("\n");
159+
165160

166161
// 2nd pass: processing statemachine AND collecting history transitions in 'historyTransitions
167162
processRegion(stateMachine, stateContext, plantUmlWriterParameters, sb, "", null);
@@ -651,7 +646,7 @@ private void processPseudoStatesTransition(
651646
S target = targetState.getId();
652647
sb.append("""
653648
%s%s
654-
%s%s -%s[%s]-> %s %s
649+
%s%s -%s%s-> %s %s
655650
"""
656651
.formatted(
657652
indent,
@@ -746,7 +741,7 @@ private void addTransition(
746741
Transition<S, E> transition
747742
) {
748743
sb.append("""
749-
%s%s -%s[%s]-> %s %s
744+
%s%s -%s%s-> %s %s
750745
"""
751746
.formatted(
752747
indent,

Diff for: spring-statemachine-uml/src/main/java/org/springframework/statemachine/plantuml/PlantUmlWriterParameters.java

+44-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package org.springframework.statemachine.plantuml;
22

3-
import lombok.Builder;
4-
import lombok.EqualsAndHashCode;
5-
import lombok.Getter;
6-
import lombok.Value;
3+
import lombok.*;
74
import org.apache.commons.logging.Log;
85
import org.apache.commons.logging.LogFactory;
96
import org.springframework.lang.Nullable;
@@ -21,7 +18,48 @@ public class PlantUmlWriterParameters<S> {
2118

2219
private static final Log log = LogFactory.getLog(PlantUmlWriterParameters.class);
2320

24-
// TODO add hidden arrows 'S1 -[hidden]-> S2'
21+
public static final String DEFAULT_STATE_DIAGRAM_SETTINGS = """
22+
'https://plantuml.com/state-diagram
23+
24+
'hide description area for state without description
25+
hide empty description
26+
27+
'https://plantuml.com/fr/skinparam
28+
'https://plantuml-documentation.readthedocs.io/en/latest/formatting/all-skin-params.html
29+
'https://plantuml.com/fr/color
30+
skinparam BackgroundColor white
31+
skinparam DefaultFontColor black
32+
'skinparam DefaultFontName Impact
33+
skinparam DefaultFontSize 14
34+
skinparam DefaultFontStyle Normal
35+
skinparam NoteBackgroundColor #FEFFDD
36+
skinparam NoteBorderColor black
37+
38+
skinparam state {
39+
ArrowColor black
40+
BackgroundColor #F1F1F1
41+
BorderColor #181818
42+
FontColor black
43+
' FontName Impact
44+
FontSize 14
45+
FontStyle Normal
46+
}
47+
""";
48+
49+
@Setter
50+
private String stateDiagramSettings = DEFAULT_STATE_DIAGRAM_SETTINGS;
51+
52+
public static String getStateDiagramSettings(@Nullable PlantUmlWriterParameters<?> plantUmlWriterParameters) {
53+
return plantUmlWriterParameters == null
54+
? DEFAULT_STATE_DIAGRAM_SETTINGS
55+
: plantUmlWriterParameters.getStateDiagramSettings();
56+
}
57+
58+
private String getStateDiagramSettings() {
59+
return stateDiagramSettings == null
60+
? ""
61+
: stateDiagramSettings;
62+
}
2563

2664
/**
2765
* Direction of an arrow connecting 2 States
@@ -206,7 +244,7 @@ public String getStateColor(S state, @Nullable S currentState) {
206244
}
207245

208246
public String getArrowColor(boolean isCurrentTransaction) {
209-
return isCurrentTransaction ? "#FF0000" : "#000000";
247+
return isCurrentTransaction ? "[#FF0000]" : "";
210248
}
211249

212250
}

Diff for: spring-statemachine-uml/src/test/java/org/springframework/statemachine/plantuml/PlantUmlWriterTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ void plantUmlTest(String resourcePath, PlantUmlWriterParameters<String> plantUml
110110
// make umlStateMachineModelFactory aware of beans available in BeansForUmlFiles.class
111111
umlStateMachineModelFactory.setBeanFactory(context);
112112

113+
if (plantUmlWriterParameters == null) {
114+
plantUmlWriterParameters = new PlantUmlWriterParameters<>();
115+
}// setting some PlantUml parameters
116+
plantUmlWriterParameters.setStateDiagramSettings("""
117+
'https://plantuml.com/state-diagram
118+
119+
'hide description area for state without description
120+
hide empty description
121+
""");
113122
// Dumping statemachine to PlantUml diagram
114123
String stateMachineAsPlantUML = new PlantUmlWriter<String, String>()
115124
.toPlantUml(

Diff for: spring-statemachine-uml/src/test/resources/org/springframework/statemachine/uml/action-with-transition-choice.puml

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ state S5
1818
state S6
1919

2020

21-
[*] -[#000000]-> S1
22-
S1 -down[#000000]-> CHOICE1 : E1\n/ s1ToChoice
23-
CHOICE1 -down[#000000]-> CHOICE2 : [choice2Guard]\n/ choice1ToChoice2
24-
CHOICE2 -down[#000000]-> S6 : / choiceToS6
25-
CHOICE2 -down[#000000]-> S5 : [s5Guard]\n/ choiceToS5
26-
CHOICE1 -down[#000000]-> S4 : / choiceToS4
27-
CHOICE1 -down[#000000]-> S3 : [s3Guard]
28-
CHOICE1 -down[#000000]-> S2 : [s2Guard]\n/ choiceToS2
21+
[*] --> S1
22+
CHOICE1 -down-> CHOICE2 : [choice2Guard]\n/ choice1ToChoice2
23+
CHOICE1 -down-> S2 : [s2Guard]\n/ choiceToS2
24+
CHOICE1 -down-> S3 : [s3Guard]
25+
CHOICE1 -down-> S4 : / choiceToS4
26+
CHOICE2 -down-> S5 : [s5Guard]\n/ choiceToS5
27+
CHOICE2 -down-> S6 : / choiceToS6
28+
S1 -down-> CHOICE1 : E1\n/ s1ToChoice
2929

3030
@enduml

Diff for: spring-statemachine-uml/src/test/resources/org/springframework/statemachine/uml/action-with-transition-junction.puml

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ state S5
1818
state S6
1919

2020

21-
[*] -[#000000]-> S1
22-
S1 -down[#000000]-> JUNCTION1 : E1\n/ s1ToChoice
23-
JUNCTION1 -down[#000000]-> JUNCTION2 : [choice2Guard]\n/ choice1ToChoice2
24-
JUNCTION2 -down[#000000]-> S6 : / choiceToS6
25-
JUNCTION2 -down[#000000]-> S5 : [s5Guard]\n/ choiceToS5
26-
JUNCTION1 -down[#000000]-> S4 : / choiceToS4
27-
JUNCTION1 -down[#000000]-> S3 : [s3Guard]
28-
JUNCTION1 -down[#000000]-> S2 : [s2Guard]\n/ choiceToS2
21+
[*] --> S1
22+
JUNCTION1 -down-> JUNCTION2 : [choice2Guard]\n/ choice1ToChoice2
23+
JUNCTION1 -down-> S2 : [s2Guard]\n/ choiceToS2
24+
JUNCTION1 -down-> S3 : [s3Guard]
25+
JUNCTION1 -down-> S4 : / choiceToS4
26+
JUNCTION2 -down-> S5 : [s5Guard]\n/ choiceToS5
27+
JUNCTION2 -down-> S6 : / choiceToS6
28+
S1 -down-> JUNCTION1 : E1\n/ s1ToChoice
2929

3030
@enduml

Diff for: spring-statemachine-uml/src/test/resources/org/springframework/statemachine/uml/broken-model-shadowentries.puml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ state S1
88
state S2
99

1010

11-
[*] -[#000000]-> S1
12-
S1 -down[#000000]-> S2
11+
[*] --> S1
12+
S1 -down-> S2
1313

1414
@enduml

Diff for: spring-statemachine-uml/src/test/resources/org/springframework/statemachine/uml/initial-actions.puml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ state S1
88
state S2
99

1010

11-
[*] -[#000000]-> S1 : / initialAction
12-
S1 -down[#000000]-> S2 : E1
11+
[*] --> S1 : / initialAction
12+
S1 -down-> S2 : E1
1313

1414
@enduml

Diff for: spring-statemachine-uml/src/test/resources/org/springframework/statemachine/uml/missingname-choice.puml

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ state choice1 <<choice>>
1313
note left of choice1 : choice1
1414

1515

16-
[*] -[#000000]-> S1
17-
S1 -down[#000000]-> choice1 : E1
18-
choice1 -down[#000000]-> S2 : [s2Guard]
19-
choice1 -down[#000000]-> S3 : [s3Guard]
20-
choice1 -down[#000000]-> S4
16+
[*] --> S1
17+
S1 -down-> choice1 : E1
18+
choice1 -down-> S2 : [s2Guard]
19+
choice1 -down-> S3 : [s3Guard]
20+
choice1 -down-> S4
2121

2222
@enduml

Diff for: spring-statemachine-uml/src/test/resources/org/springframework/statemachine/uml/multijoin-forkjoin.puml

+12-12
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ state S2 {
1212
state S21
1313

1414

15-
[*] -[#000000]-> S20
15+
[*] --> S20
1616
state S30
1717
state S31
1818

1919

20-
[*] -[#000000]-> S30
20+
[*] --> S30
2121
}
2222
'S3 <<JOIN>>
2323
state S3 <<join>>
@@ -29,17 +29,17 @@ note left of SF : SF
2929
state SI
3030

3131

32-
S1 -down[#000000]-> S20
32+
S1 -down-> S20
3333

34-
S1 -down[#000000]-> S30
34+
S1 -down-> S30
3535

36-
[*] -[#000000]-> SI
37-
S20 -down[#000000]-> S21 : E2
38-
S30 -down[#000000]-> S31 : E3
39-
SI -down[#000000]-> S1 : E1
40-
S31 -down[#000000]-> S3
41-
S21 -down[#000000]-> S3
42-
S3 -down[#000000]-> S4 : [extendedState.variables.isEmpty()]
43-
S3 -down[#000000]-> SF : [!extendedState.variables.isEmpty()]
36+
[*] --> SI
37+
S20 -down-> S21 : E2
38+
S21 -down-> S3
39+
S30 -down-> S31 : E3
40+
S31 -down-> S3
41+
S3 -down-> S4 : [extendedState.variables.isEmpty()]
42+
S3 -down-> SF : [!extendedState.variables.isEmpty()]
43+
SI -down-> S1 : E1
4444

4545
@enduml

Diff for: spring-statemachine-uml/src/test/resources/org/springframework/statemachine/uml/pseudostate-in-submachine.puml

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ state S1 {
1212
state S12
1313

1414

15-
[*] -[#000000]-> S11
15+
[*] --> S11
1616
}
1717

1818

19-
[*] -[#000000]-> S1
20-
S11 -down[#000000]-> CHOICE
21-
CHOICE -down[#000000]-> S12
19+
[*] --> S1
20+
CHOICE -down-> S12
21+
S11 -down-> CHOICE
2222

2323
@enduml

Diff for: spring-statemachine-uml/src/test/resources/org/springframework/statemachine/uml/pseudostate-in-submachineref.puml

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ state S1 {
1212
state S12
1313

1414

15-
[*] -[#000000]-> S11
15+
[*] --> S11
1616
}
1717

1818

19-
[*] -[#000000]-> S1
20-
S11 -down[#000000]-> CHOICE
21-
CHOICE -down[#000000]-> S12
19+
[*] --> S1
20+
CHOICE -down-> S12
21+
S11 -down-> CHOICE
2222

2323
@enduml

Diff for: spring-statemachine-uml/src/test/resources/org/springframework/statemachine/uml/simple-actions.puml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ S2 : /entry s2Entry
1111
S2 : /do extendedState.variables.put('hellos2do','hellos2dovalue')
1212

1313

14-
[*] -[#000000]-> S1
15-
S1 -down[#000000]-> S2 : E1\n/ e1Action
14+
[*] --> S1
15+
S1 -down-> S2 : E1\n/ e1Action
1616

1717
@enduml

Diff for: spring-statemachine-uml/src/test/resources/org/springframework/statemachine/uml/simple-choice.puml

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ state S3
1313
state S4
1414

1515

16-
[*] -[#000000]-> S1
17-
S1 -down[#000000]-> CHOICE : E1
18-
CHOICE -down[#000000]-> S4
19-
CHOICE -down[#000000]-> S3 : [s3Guard]
20-
CHOICE -down[#000000]-> S2 : [s2Guard]
16+
[*] --> S1
17+
CHOICE -down-> S2 : [s2Guard]
18+
CHOICE -down-> S3 : [s3Guard]
19+
CHOICE -down-> S4
20+
S1 -down-> CHOICE : E1
2121

2222
@enduml
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@startuml
2-
note "!!! NOT WORKING !!!\n!!! Missing 'EXIT -down[#000000]-> S4' transition !!!\n It seems ConnectionPointRef is not supported by Spring Statemachine" as NOT_WORKING
2+
note "!!! NOT WORKING !!!\n!!! Missing 'EXIT -down-> S4' transition !!!\n It seems ConnectionPointRef is not supported by Spring Statemachine" as NOT_WORKING
33
'https://plantuml.com/state-diagram
44

55
'hide description area for state without description
@@ -11,20 +11,20 @@ state S2 {
1111
state S22
1212

1313

14-
[*] -[#000000]-> S21
14+
[*] --> S21
1515
state ENTRY <<entryPoint>>
1616
state EXIT <<exitPoint>>
1717
}
1818
state S3
1919
state S4
2020

2121

22-
[*] -[#000000]-> S1
23-
S1 -down[#000000]-> S2 : E1
24-
ENTRY -down[#000000]-> S22
25-
S22 -down[#000000]-> EXIT : E4
26-
S1 -down[#000000]-> ENTRY : E3
27-
S2 -down[#000000]-> S3 : E2
28-
EXIT -down[#000000]-> S4
22+
[*] --> S1
23+
S1 -down-> S2 : E1
24+
ENTRY -down-> S22
25+
S22 -down-> EXIT : E4
26+
S1 -down-> ENTRY : E3
27+
S2 -down-> S3 : E2
28+
EXIT -down-> S4
2929

3030
@enduml

Diff for: spring-statemachine-uml/src/test/resources/org/springframework/statemachine/uml/simple-entryexit.puml

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ state S2 {
1010
state S22
1111

1212

13-
[*] -[#000000]-> S21
13+
[*] --> S21
1414
state ENTRY <<entryPoint>>
1515
state EXIT <<exitPoint>>
1616
}
1717
state S3
1818
state S4
1919

2020

21-
[*] -[#000000]-> S1
22-
ENTRY -down[#000000]-> S22
23-
S22 -down[#000000]-> EXIT : E4
24-
S1 -down[#000000]-> ENTRY : E3
25-
EXIT -down[#000000]-> S4
26-
S1 -down[#000000]-> S2 : E1
27-
S2 -down[#000000]-> S3 : E2
21+
[*] --> S1
22+
ENTRY -down-> S22
23+
EXIT -down-> S4
24+
S1 -down-> ENTRY : E3
25+
S1 -down-> S2 : E1
26+
S22 -down-> EXIT : E4
27+
S2 -down-> S3 : E2
2828

2929
@enduml

Diff for: spring-statemachine-uml/src/test/resources/org/springframework/statemachine/uml/simple-eventdefer.puml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ state S2
1010
state S3
1111

1212

13-
[*] -[#000000]-> S1
14-
S1 -down[#000000]-> S2 : E1
15-
S2 -down[#000000]-> S3 : E2
13+
[*] --> S1
14+
S1 -down-> S2 : E1
15+
S2 -down-> S3 : E2
1616

1717
@enduml

0 commit comments

Comments
 (0)