Skip to content

Commit 18a3d4e

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 0cf55c6 + e78b978 commit 18a3d4e

11 files changed

+59
-105
lines changed
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.patternpedia.api.entities.designmodel;
22

33
import com.patternpedia.api.rest.model.FileDTO;
4-
import lombok.AllArgsConstructor;
54
import lombok.Data;
6-
import lombok.NonNull;
7-
import lombok.RequiredArgsConstructor;
85

96
import java.util.HashMap;
107
import java.util.Map;
@@ -17,16 +14,13 @@ public class AggregationData {
1714

1815
private DesignModelPatternInstance target;
1916

20-
private DesignModelPatternEdge edge;
21-
2217
private Map<String, Object> templateContext = new HashMap<>();
2318

2419
private FileDTO result;
2520

2621

27-
public AggregationData(DesignModelPatternInstance source, DesignModelPatternInstance target, DesignModelPatternEdge edge) {
22+
public AggregationData(DesignModelPatternInstance source, DesignModelPatternInstance target) {
2823
this.source = source;
2924
this.target = target;
30-
this.edge = edge;
3125
}
3226
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.patternpedia.api.entities.designmodel;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
6+
7+
@AllArgsConstructor
8+
@Getter
9+
public class AggregationDataAndPatternEdge {
10+
11+
private AggregationData aggregationData;
12+
13+
private DesignModelPatternEdge edge;
14+
}

src/main/java/com/patternpedia/api/entities/designmodel/ConcreteSolution.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import lombok.NoArgsConstructor;
66
import org.springframework.hateoas.server.core.Relation;
77

8-
import javax.persistence.*;
9-
import java.util.List;
8+
import javax.persistence.Column;
9+
import javax.persistence.Entity;
10+
import javax.persistence.GeneratedValue;
11+
import javax.persistence.Id;
1012
import java.util.UUID;
1113

1214

@@ -26,9 +28,6 @@ public class ConcreteSolution {
2628

2729
private String name;
2830

29-
@ElementCollection
30-
private List<String> properties;
31-
3231
private String templateUri;
3332

3433
private String aggregatorType;

src/main/java/com/patternpedia/api/service/ConcreteSolutionServiceImpl.java

Lines changed: 31 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class ConcreteSolutionServiceImpl implements ConcreteSolutionService {
2323
private final ConcreteSolutionRepository concreteSolutionRepository;
2424
private final DesignModelEdgeTypeRepository designModelEdgeTypeRepository;
2525

26+
private UUID lastSourceNodeUUID = null;
27+
2628

2729
public ConcreteSolutionServiceImpl(ConcreteSolutionRepository concreteSolutionRepository,
2830
DesignModelEdgeTypeRepository designModelEdgeTypeRepository) {
@@ -58,7 +60,7 @@ private void linkConcreteSolutionsToPatternInstances(List<DesignModelPatternInst
5860
}
5961

6062

61-
private void swapEdgeDirections(List<DesignModelPatternEdge> edges) {
63+
private void normalizeEdgeDirections(List<DesignModelPatternEdge> edges) {
6264
Set<String> edgeTypesToSwapDirections = this.designModelEdgeTypeRepository.findAll().stream()
6365
.filter(DesignModelEdgeType::getSwap)
6466
.map(DesignModelEdgeType::getName)
@@ -74,72 +76,54 @@ private void swapEdgeDirections(List<DesignModelPatternEdge> edges) {
7476
}
7577

7678

77-
private Set<UUID> findRootNodes(List<DesignModelPatternInstance> patternInstances, List<DesignModelPatternEdge> edges) {
78-
Set<UUID> rootNodes = new HashSet<>();
79+
private Set<UUID> findSourceNodes(List<DesignModelPatternInstance> patternInstances, List<DesignModelPatternEdge> edges) {
80+
Set<UUID> sourceNodes = new HashSet<>();
7981

8082
for (DesignModelPatternInstance patternInstance : patternInstances) {
81-
rootNodes.add(patternInstance.getPatternInstanceId());
83+
sourceNodes.add(patternInstance.getPatternInstanceId());
8284
}
8385

8486
for (DesignModelPatternEdge edge : edges) {
85-
rootNodes.remove(edge.getPatternInstance1().getPatternInstanceId());
87+
sourceNodes.remove(edge.getPatternInstance2().getPatternInstanceId());
8688
}
8789

88-
log.info("Root nodes: " + rootNodes.toString());
89-
return rootNodes;
90+
return sourceNodes;
9091
}
9192

9293

93-
private Set<UUID> findLeafNodes(List<DesignModelPatternInstance> patternInstances, List<DesignModelPatternEdge> edges) {
94-
Set<UUID> leafNodes = new HashSet<>();
94+
private AggregationDataAndPatternEdge getSourceNodeAndNeighbor(List<DesignModelPatternInstance> patternInstances, List<DesignModelPatternEdge> edges) {
95+
Set<UUID> sourceNodes = findSourceNodes(patternInstances, edges);
9596

96-
for (DesignModelPatternInstance patternInstance : patternInstances) {
97-
leafNodes.add(patternInstance.getPatternInstanceId());
97+
if (sourceNodes.isEmpty()) {
98+
throw new RuntimeException("No source node found");
9899
}
99100

100-
for (DesignModelPatternEdge edge : edges) {
101-
leafNodes.remove(edge.getPatternInstance2().getPatternInstanceId());
102-
}
103-
104-
return leafNodes;
105-
}
106-
101+
final UUID sourceNodeUUID = sourceNodes.contains(lastSourceNodeUUID) ? lastSourceNodeUUID : sourceNodes.iterator().next();
102+
lastSourceNodeUUID = sourceNodeUUID;
107103

108-
private UUID lastLeafUUID = null;
109-
110-
private AggregationData getLeafAndPredecessor(List<DesignModelPatternInstance> patternInstances, List<DesignModelPatternEdge> edges) {
111-
Set<UUID> leafNodes = findLeafNodes(patternInstances, edges);
112-
113-
if (leafNodes.isEmpty()) {
114-
throw new RuntimeException("No leaf node found");
115-
}
116-
117-
final UUID leafNodeUUID = leafNodes.contains(lastLeafUUID) ? lastLeafUUID : leafNodes.iterator().next();
118-
lastLeafUUID = leafNodeUUID;
119-
120-
DesignModelPatternInstance leafPatternInstance = patternInstances.stream()
121-
.filter(designModelPatternInstance -> leafNodeUUID.equals(designModelPatternInstance.getPatternInstanceId()))
104+
DesignModelPatternInstance sourcePatternInstance = patternInstances.stream()
105+
.filter(designModelPatternInstance -> sourceNodeUUID.equals(designModelPatternInstance.getPatternInstanceId()))
122106
.findAny().orElse(null);
123107

124108
if (patternInstances.size() == 1) {
125-
return new AggregationData(leafPatternInstance, null, null);
109+
return new AggregationDataAndPatternEdge(new AggregationData(sourcePatternInstance, null), null);
126110
}
127111

128-
DesignModelPatternEdge edge = edges.stream().filter(designModelPatternEdge -> leafNodeUUID.equals(designModelPatternEdge.getPatternInstance1().getPatternInstanceId())).findAny().orElse(null);
112+
DesignModelPatternEdge edge = edges.stream().filter(designModelPatternEdge -> sourceNodeUUID.equals(designModelPatternEdge.getPatternInstance1().getPatternInstanceId())).findAny().orElse(null);
129113

130-
DesignModelPatternInstance predecessorPatternInstance = null;
114+
DesignModelPatternInstance neighborPatternInstance = null;
131115

132116
if (edge != null) {
133-
UUID predecessorNodeUUID = edge.getPatternInstance2().getPatternInstanceId();
117+
UUID neighborNodeUUID = edge.getPatternInstance2().getPatternInstanceId();
134118

135-
predecessorPatternInstance = patternInstances.stream()
136-
.filter(designModelPatternInstance -> predecessorNodeUUID.equals(designModelPatternInstance.getPatternInstanceId()))
119+
neighborPatternInstance = patternInstances.stream()
120+
.filter(designModelPatternInstance -> neighborNodeUUID.equals(designModelPatternInstance.getPatternInstanceId()))
137121
.findAny().orElse(null);
138122

139-
log.info("Found leaf [" + leafNodeUUID.toString() + "] and predecessor [" + predecessorNodeUUID.toString() + "]: " + leafPatternInstance.getPattern().getName() + " ---" + edge.getType() + "--- " + predecessorPatternInstance.getPattern().getName());
123+
log.info("Found source [" + sourceNodeUUID.toString() + "] and neighbor [" + neighborNodeUUID.toString() + "]: " + sourcePatternInstance.getPattern().getName() + " ---" + edge.getType() + "--- " + neighborPatternInstance.getPattern().getName());
140124
}
141125

142-
return new AggregationData(leafPatternInstance, predecessorPatternInstance, edge);
126+
return new AggregationDataAndPatternEdge(new AggregationData(sourcePatternInstance, neighborPatternInstance), edge);
143127
}
144128

145129

@@ -170,13 +154,14 @@ public List<FileDTO> aggregate(List<DesignModelPatternInstance> patternInstances
170154

171155
linkConcreteSolutionsToPatternInstances(patternInstances, concreteSolutionMapping);
172156

173-
swapEdgeDirections(edges);
157+
normalizeEdgeDirections(edges);
174158

175159
Map<String, Object> templateContext = new HashMap<>();
176-
List<FileDTO> aggregatedFiles = new ArrayList<>();
160+
List<FileDTO> artefacts = new ArrayList<>();
177161

178162
while (!patternInstances.isEmpty()) {
179-
AggregationData aggregationData = getLeafAndPredecessor(patternInstances, edges);
163+
AggregationDataAndPatternEdge aggregationDataAndPatternEdge = getSourceNodeAndNeighbor(patternInstances, edges);
164+
AggregationData aggregationData = aggregationDataAndPatternEdge.getAggregationData();
180165

181166
aggregationData.setTemplateContext(templateContext);
182167

@@ -185,16 +170,15 @@ public List<FileDTO> aggregate(List<DesignModelPatternInstance> patternInstances
185170
templateContext = aggregationData.getTemplateContext();
186171

187172
if (aggregationData.getResult() != null) {
188-
aggregatedFiles.add(aggregationData.getResult());
173+
artefacts.add(aggregationData.getResult());
189174
}
190175

191-
edges.remove(aggregationData.getEdge());
176+
edges.remove(aggregationDataAndPatternEdge.getEdge());
192177
if (!edges.stream().anyMatch(edge -> aggregationData.getSource().getPatternInstanceId().equals(edge.getPatternInstance1().getPatternInstanceId()))) {
193178
patternInstances.remove(aggregationData.getSource());
194179
}
195180
}
196181

197-
198-
return aggregatedFiles;
182+
return artefacts;
199183
}
200184
}

src/main/java/com/patternpedia/api/util/aggregator/AWSCloudFormationJsonAggregator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void aggregate(AggregationData aggregationData) {
4040
);
4141
}
4242

43-
if (aggregationData.getEdge() != null) {
43+
if (aggregationData.getTarget() != null) {
4444
addInputOutputChannelContext(aggregationData);
4545
}
4646

src/main/java/com/patternpedia/api/util/aggregator/ActiveMQAggregator.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.patternpedia.api.util.aggregator;
22

33
import com.patternpedia.api.entities.designmodel.AggregationData;
4-
import com.patternpedia.api.entities.designmodel.DesignModelPatternEdge;
5-
import com.patternpedia.api.entities.designmodel.DesignModelPatternEdgeId;
64
import lombok.extern.apachecommons.CommonsLog;
75

86
import java.util.*;
@@ -16,22 +14,6 @@ public abstract class ActiveMQAggregator extends AggregatorImpl {
1614
public abstract void aggregate(AggregationData aggregationData);
1715

1816

19-
public static Object getQueueList(Collection<DesignModelPatternEdge> edges) {
20-
if (edges.size() == 1) {
21-
DesignModelPatternEdgeId edgeId = edges.iterator().next().getEdgeId();
22-
return "queue" + edgeId.getPatternInstanceId2().toString();
23-
}
24-
if (edges.size() >= 2) {
25-
Set<String> queueNames = new HashSet<>();
26-
for (DesignModelPatternEdge edge : edges) {
27-
queueNames.add("queue" + edge.getEdgeId().getPatternInstanceId2().toString());
28-
}
29-
return queueNames;
30-
}
31-
return null;
32-
}
33-
34-
3517
protected static void addInputOutputChannelContext(AggregationData aggregationData) {
3618

3719
final String channelName = getIdentifier(aggregationData.getSource());

src/main/java/com/patternpedia/api/util/aggregator/ActiveMQJavaAggregator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void aggregate(AggregationData aggregationData) {
3838

3939
aggregationData.getTemplateContext().put(targetInstanceId + TEMPLATE_KEY, camelContext.toString());
4040

41-
if (aggregationData.getEdge() != null) {
41+
if (aggregationData.getTarget() != null) {
4242

4343
addInputOutputChannelContext(aggregationData);
4444

src/main/java/com/patternpedia/api/util/aggregator/ActiveMQXMLAggregator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void aggregate(AggregationData aggregationData) {
4242
aggregationData.getTemplateContext().put(targetInstanceId + TEMPLATE_KEY, camelContext.toString());
4343
}
4444

45-
if (aggregationData.getEdge() != null) {
45+
if (aggregationData.getTarget() != null) {
4646
addInputOutputChannelContext(aggregationData);
4747

4848
if ("ActiveMQ-XML".equals(aggregationData.getTarget().getConcreteSolution().getAggregatorType())) {

src/main/java/com/patternpedia/api/util/aggregator/AggregatorImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@CommonsLog
1818
public abstract class AggregatorImpl implements Aggregator {
1919

20-
protected static final String CONCRETE_SOLUTION_REPO = "https://raw.githubusercontent.com/marzn/pattern-atlas-pattern-implementations/main/";
20+
protected static final String CONCRETE_SOLUTION_REPO = "https://raw.githubusercontent.com/PatternAtlas/pattern-atlas-pattern-implementations/main/";
2121

2222
protected static final Random RANDOM = new Random();
2323

src/main/java/com/patternpedia/api/util/aggregator/MessageEndpointAggregator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import com.patternpedia.api.entities.designmodel.DesignModelPatternInstance;
66
import com.patternpedia.api.rest.model.FileDTO;
77

8+
import java.util.Arrays;
9+
import java.util.List;
810
import java.util.Map;
911

1012

11-
@AggregatorMetadata(sourceTypes = {"MessageEndpoint"}, targetTypes = {"", "ActiveMQ-XML", "ActiveMQ-Java"})
13+
@AggregatorMetadata(sourceTypes = {"MessageEndpoint"}, targetTypes = {"", "AWS-CloudFormation-JSON", "ActiveMQ-XML", "ActiveMQ-Java"})
1214
public class MessageEndpointAggregator extends ActiveMQAggregator {
1315

1416
private static final String MIME_TYPE = "text/x-java";
@@ -25,7 +27,8 @@ public void aggregate(AggregationData aggregationData) {
2527
String concreteSolutionTemplate = readFile(concreteSolution.getTemplateUri());
2628
concreteSolutionTemplate = extendVariables(concreteSolutionTemplate, patternInstanceId);
2729

28-
boolean isProducer = aggregationData.getTarget() == null;
30+
List<String> aggregationType = Arrays.asList("ActiveMQ-XML", "ActiveMQ-Java");
31+
boolean isProducer = aggregationData.getTarget() == null || !aggregationType.contains(aggregationData.getTarget().getConcreteSolution().getAggregatorType());
2932

3033
String filename = isProducer ? "QueueProducer.java" : "QueueConsumer.java";
3134
templateContext.put("producer", isProducer);

0 commit comments

Comments
 (0)