Skip to content

Commit 2aa323d

Browse files
committed
Cleanup tasks and javadoc
1 parent 6b51bfd commit 2aa323d

18 files changed

+310
-64
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ build
77

88
# IntelliJ
99
.idea
10+
out/
1011

1112
# Generated sources
1213
src-gen

Diff for: build.gradle

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ repositories {
1212
}
1313

1414
dependencies {
15-
compile group: 'guru.nidi', name: 'graphviz-java', version: '0.11.0'
16-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
17-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
15+
implementation "guru.nidi:graphviz-java:${graphvizVersion}"
16+
implementation "org.apache.commons:commons-lang3:${commonsLangVersion}"
17+
18+
testImplementation "org.junit.jupiter:junit-jupiter-api:${jUnitVersion}"
19+
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${jUnitVersion}"
1820
}
1921

2022
test {

Diff for: gradle.properties

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Publication repos
2+
ossSnapshotRepository=https://oss.sonatype.org/content/repositories/snapshots/
3+
ossReleaseStagingRepository=https://oss.sonatype.org/service/local/staging/deploy/maven2/
4+
5+
# dependency versions
6+
jUnitVersion=5.5.2
7+
commonsLangVersion=3.9
8+
graphvizVersion=0.11.0

Diff for: src/main/java/org/contextmapper/contextmap/generator/graphviz/ContextMapGenerator.java renamed to src/main/java/org/contextmapper/contextmap/generator/ContextMapGenerator.java

+6-19
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.contextmapper.contextmap.generator.graphviz;
16+
package org.contextmapper.contextmap.generator;
1717

1818
import guru.nidi.graphviz.attribute.Label;
1919
import guru.nidi.graphviz.attribute.Shape;
@@ -35,7 +35,7 @@
3535
import static guru.nidi.graphviz.model.Factory.*;
3636

3737
/**
38-
* Generating Context Map with graphviz. Experimental state!
38+
* Generating graphical Context Map with Graphviz.
3939
*
4040
* @author Stefan Kapferer
4141
*/
@@ -49,18 +49,18 @@ public void generateContextMapGraphic(ContextMap contextMap, String fileName) th
4949

5050
// create nodes
5151
contextMap.getBoundedContexts().forEach(bc -> {
52-
MutableNode node = mutNode(bc.getId());
52+
MutableNode node = mutNode(bc.getName());
5353
node.add(Label.lines(bc.getName()));
5454
node.add(Shape.EGG);
5555
node.add(attr("margin", "0.3"));
5656
node.add(attr("orientation", orientationDegree()));
57-
bcNodesMap.put(bc.getId(), node);
57+
bcNodesMap.put(bc.getName(), node);
5858
});
5959

6060
// link nodes
6161
contextMap.getRelationships().forEach(rel -> {
62-
MutableNode node1 = this.bcNodesMap.get(rel.getFirstParticipant().getId());
63-
MutableNode node2 = this.bcNodesMap.get(rel.getSecondParticipant().getId());
62+
MutableNode node1 = this.bcNodesMap.get(rel.getFirstParticipant().getName());
63+
MutableNode node2 = this.bcNodesMap.get(rel.getSecondParticipant().getName());
6464

6565
if (rel instanceof Partnership) {
6666
node1.addLink(to(node2).with(Label.of("Partnership")));
@@ -87,19 +87,6 @@ public void generateContextMapGraphic(ContextMap contextMap, String fileName) th
8787
Graphviz.fromGraph(graph).width(2000).render(Format.DOT).toFile(new File(fileName + ".dot"));
8888
}
8989

90-
/*
91-
* Select shape randomly
92-
*/
93-
/*private Shape getShape() {
94-
int selection = new Random().nextInt(2);
95-
switch (selection) {
96-
case 1:
97-
return Shape.EGG;
98-
default:
99-
return Shape.ELLIPSE;
100-
}
101-
}*/
102-
10390
/*
10491
* Generate random orientation degree
10592
*/

Diff for: src/main/java/org/contextmapper/contextmap/generator/model/BoundedContext.java

+29-4
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,47 @@
1515
*/
1616
package org.contextmapper.contextmap.generator.model;
1717

18+
import org.apache.commons.lang3.builder.EqualsBuilder;
19+
import org.apache.commons.lang3.builder.HashCodeBuilder;
20+
21+
/**
22+
* Represents a Bounded Context for the graphical Context Map to be generated.
23+
*
24+
* @author Stefan Kapferer
25+
*/
1826
public class BoundedContext {
1927

20-
private String id;
2128
private String name;
2229

2330
public BoundedContext(String name) {
2431
this.name = name;
25-
this.id = name.replaceAll(" ", "");
2632
}
2733

34+
/**
35+
* Gets the Bounded Context name.
36+
*
37+
* @return the name of the Bounded Context
38+
*/
2839
public String getName() {
2940
return name;
3041
}
3142

32-
public String getId() {
33-
return id;
43+
@Override
44+
public boolean equals(Object object) {
45+
if (!(object instanceof BoundedContext))
46+
return false;
47+
48+
BoundedContext bc = (BoundedContext) object;
49+
50+
return new EqualsBuilder()
51+
.append(name, bc.name)
52+
.isEquals();
3453
}
3554

55+
@Override
56+
public int hashCode() {
57+
return new HashCodeBuilder()
58+
.append(name)
59+
.hashCode();
60+
}
3661
}

Diff for: src/main/java/org/contextmapper/contextmap/generator/model/ContextMap.java

+42-10
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,70 @@
1515
*/
1616
package org.contextmapper.contextmap.generator.model;
1717

18+
import org.contextmapper.contextmap.generator.model.exception.BoundedContextAlreadyPartOfContextMapException;
19+
import org.contextmapper.contextmap.generator.model.exception.BoundedContextNotPartOfContextMapException;
20+
1821
import java.util.*;
1922

23+
/**
24+
* Represents a Context Map for which a graphical representation shall be created.
25+
*
26+
* @author Stefan Kapferer
27+
*/
2028
public class ContextMap {
2129

22-
private List<BoundedContext> boundedContexts;
23-
private List<Relationship> relationships;
30+
private Set<BoundedContext> boundedContexts;
31+
private Set<Relationship> relationships;
2432

2533
public ContextMap() {
26-
this.boundedContexts = new ArrayList<>();
27-
this.relationships = new ArrayList<>();
34+
this.boundedContexts = new HashSet<>();
35+
this.relationships = new HashSet<>();
2836
}
2937

30-
public void addBoundedContext(BoundedContext boundedContext) {
38+
/**
39+
* Adds a new Bounded Context to the Context Map.
40+
*
41+
* @param boundedContext the Bounded Context to be added to the Context Map
42+
*/
43+
public ContextMap addBoundedContext(BoundedContext boundedContext) {
44+
if (this.boundedContexts.contains(boundedContext))
45+
throw new BoundedContextAlreadyPartOfContextMapException(boundedContext.getName());
3146
this.boundedContexts.add(boundedContext);
47+
return this;
3248
}
3349

34-
public void addRelationship(Relationship relationship) {
50+
/**
51+
* Adds a new relationship to the Context Map.
52+
*
53+
* @param relationship the relationship to be added to the Context Map
54+
*/
55+
public ContextMap addRelationship(Relationship relationship) {
3556
if (!this.boundedContexts.contains(relationship.getFirstParticipant()))
3657
throw new BoundedContextNotPartOfContextMapException(relationship.getFirstParticipant());
3758
if (!this.boundedContexts.contains(relationship.getSecondParticipant()))
3859
throw new BoundedContextNotPartOfContextMapException(relationship.getSecondParticipant());
3960
this.relationships.add(relationship);
61+
return this;
4062
}
4163

42-
public List<BoundedContext> getBoundedContexts() {
43-
List<BoundedContext> set = new ArrayList<>();
64+
/**
65+
* Gets the set of Bounded Contexts on the Context Map.
66+
*
67+
* @return the set of Bounded Contexts on the Context Map
68+
*/
69+
public Set<BoundedContext> getBoundedContexts() {
70+
Set<BoundedContext> set = new HashSet<>();
4471
set.addAll(this.boundedContexts);
4572
return set;
4673
}
4774

48-
public List<Relationship> getRelationships() {
49-
List<Relationship> set = new ArrayList<>();
75+
/**
76+
* Gets the set of relationships on the Context Map.
77+
*
78+
* @return the set of relationships on the Context Map
79+
*/
80+
public Set<Relationship> getRelationships() {
81+
Set<Relationship> set = new HashSet<>();
5082
set.addAll(this.relationships);
5183
return set;
5284
}

Diff for: src/main/java/org/contextmapper/contextmap/generator/model/DownstreamPatterns.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package org.contextmapper.contextmap.generator.model;
22

3+
/**
4+
* The DDD relationship patterns allowed on the downstream side.
5+
*
6+
* @author Stefan Kapferer
7+
*/
38
public enum DownstreamPatterns {
49

510
ANTICORRUPTION_LAYER("ACL"), CONFORMIST("CF");

Diff for: src/main/java/org/contextmapper/contextmap/generator/model/Partnership.java

+15
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
*/
1616
package org.contextmapper.contextmap.generator.model;
1717

18+
/**
19+
* Represents a DDD Partnership relationship on a Context Map.
20+
*
21+
* @author Stefan Kapferer
22+
*/
1823
public class Partnership implements Relationship {
1924

2025
private BoundedContext bc1;
@@ -25,10 +30,20 @@ public Partnership(BoundedContext bc1, BoundedContext bc2) {
2530
this.bc2 = bc2;
2631
}
2732

33+
/**
34+
* Gets the first participant of the Partnership.
35+
*
36+
* @return the first participant of the Partnership
37+
*/
2838
public BoundedContext getFirstParticipant() {
2939
return bc1;
3040
}
3141

42+
/**
43+
* Gets the second participant of the Partnership.
44+
*
45+
* @return the second participant of the Partnership
46+
*/
3247
public BoundedContext getSecondParticipant() {
3348
return bc2;
3449
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
package org.contextmapper.contextmap.generator.model;
22

3+
/**
4+
* Represents a relationship on a Context Map.
5+
*
6+
* @author Stefan Kapferer
7+
*/
38
public interface Relationship {
49

510
BoundedContext getFirstParticipant();
11+
612
BoundedContext getSecondParticipant();
713

814
}

Diff for: src/main/java/org/contextmapper/contextmap/generator/model/SharedKernel.java

+15
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
*/
1616
package org.contextmapper.contextmap.generator.model;
1717

18+
/**
19+
* Represents a DDD Shared Kernel relationship on a Context Map.
20+
*
21+
* @author Stefan Kapferer
22+
*/
1823
public class SharedKernel implements Relationship {
1924

2025
private BoundedContext bc1;
@@ -25,10 +30,20 @@ public SharedKernel(BoundedContext bc1, BoundedContext bc2) {
2530
this.bc2 = bc2;
2631
}
2732

33+
/**
34+
* Gets the first participant of the Shared Kernel.
35+
*
36+
* @return the first participant of the Shared Kernel
37+
*/
2838
public BoundedContext getFirstParticipant() {
2939
return bc1;
3040
}
3141

42+
/**
43+
* Gets the second participant of the Shared Kernel.
44+
*
45+
* @return the second participant of the Shared Kernel
46+
*/
3247
public BoundedContext getSecondParticipant() {
3348
return bc2;
3449
}

0 commit comments

Comments
 (0)