Skip to content

Commit

Permalink
Fixes #410
Browse files Browse the repository at this point in the history
  • Loading branch information
Riduidel committed Dec 20, 2023
1 parent c5389fc commit 7d4abe7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ private void enhancerVisitModel(ModelEnhancer enhancer, Model model) {
Stream<SoftwareSystem> systems = model.getSoftwareSystems().stream();
if(enhancer.isParallel())
systems = systems.parallel();
systems.filter(s -> withClassLoader(() -> enhancer.startVisit(s)))
systems
.sorted(new OrderedModelElement())
.filter(s -> withClassLoader(() -> enhancer.startVisit(s)))
.peek(s -> withClassLoader(() -> enhancerVisitSystem(enhancer, s)))
.forEach(s -> withClassLoader(() -> enhancer.endVisit(s, outputBuilder)));
enhancer.endVisit(model, outputBuilder);
Expand All @@ -179,7 +181,9 @@ private void enhancerVisitSystem(ModelEnhancer enhancer, SoftwareSystem system)
Stream<Container> containers = system.getContainers().stream();
if(enhancer.isParallel())
containers = containers.parallel();
containers.filter(c -> withClassLoader(() -> enhancer.startVisit(c)))
containers
.sorted(new OrderedModelElement())
.filter(c -> withClassLoader(() -> enhancer.startVisit(c)))
.peek(c -> withClassLoader(() -> enhancerVisitContainer(enhancer, c)))
.forEach(c -> withClassLoader(() -> enhancer.endVisit(c, outputBuilder)));
}
Expand All @@ -189,7 +193,9 @@ private void enhancerVisitContainer(ModelEnhancer enhancer, Container container)
Stream<Component> systems = container.getComponents().stream();
if(enhancer.isParallel())
systems = systems.parallel();
systems.filter(c -> withClassLoader(() -> enhancer.startVisit(c)))
systems
.sorted(new OrderedModelElement())
.filter(c -> withClassLoader(() -> enhancer.startVisit(c)))
.forEach(c -> withClassLoader(() -> enhancer.endVisit(c, outputBuilder)));
}

Expand Down
23 changes: 23 additions & 0 deletions base/src/main/java/org/ndx/aadarchi/base/OrderedModelElement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.ndx.aadarchi.base;

import java.util.Comparator;

import org.ndx.aadarchi.base.enhancers.ModelElementKeys;

import com.structurizr.model.Element;

public class OrderedModelElement implements Comparator<Element> {

@Override
public int compare(Element o1, Element o2) {
if(o1.getProperties().containsKey(ModelElementKeys.ORDERING)) {
if(o2.getProperties().containsKey(ModelElementKeys.ORDERING)) {
long n1 = Long.parseLong(o1.getProperties().get(ModelElementKeys.ORDERING));
long n2 = Long.parseLong(o1.getProperties().get(ModelElementKeys.ORDERING));
return (int) (n1-n2);
}
}
return o1.getCanonicalName().compareTo(o2.getCanonicalName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,11 @@ public static interface CheckoutLocation {
* When set, this property contains a description used for {@link #EXTERNAL_DEPENDENCIES}
* generated links
*/
String EXTERNAL_DEPENDENCY_DESCRIPTION = PREFIX+".depends.description";
String EXTERNAL_DEPENDENCY_DESCRIPTION = PREFIX+"depends.description";
/**
* When set, model elements will be ordered according to this key instead of the name (which is used by default).
* Why introducing this complexity? Because it allows cleaner, and more controlled, ordering.
* Please use integer or long values (floats and double won't be supported here)
*/
String ORDERING = PREFIX+"ordering";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.List;
import java.util.stream.Collectors;

import org.ndx.aadarchi.base.enhancers.ModelElementKeys;

import com.structurizr.PropertyHolder;
import com.structurizr.Workspace;
import com.structurizr.model.Component;
Expand All @@ -22,8 +24,13 @@ public static String getCanonicalPath(Element element) {
if(element.getParent()!=null) {
returned = getCanonicalPath(element.getParent());
}
returned += "/" + element.getName();
return returned;
returned += "/";
if(element.getProperties().containsKey(ModelElementKeys.ORDERING)) {
long ordering = Long.parseLong(element.getProperties().get(ModelElementKeys.ORDERING));
returned+= String.format("%02d-", ordering);
}
returned += element.getName();
return returned.trim();
}

public static List<PropertyHolder> getHierarchy(List<? extends PropertyHolder> elements) {
Expand Down

0 comments on commit 7d4abe7

Please sign in to comment.