Skip to content

Commit 5ae28b0

Browse files
Adds some code to deal with old workspaces, or those created by third party tooling that are missing view order properties.
1 parent b3fd678 commit 5ae28b0

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

structurizr-client/src/integrationTest/java/com/structurizr/api/BackwardsCompatibilityTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,12 @@ void documentation() throws Exception {
4848
{"configuration":{},"description":"Description","documentation":{"sections":[{"content":"## Heading 1","format":"Markdown","order":1,"title":""}]},"id":0,"model":{},"name":"Name","views":{"configuration":{"branding":{},"styles":{},"terminology":{}}}}""", WorkspaceUtils.toJson(workspace, false));
4949
}
5050

51+
@Test
52+
void viewsWithoutOrderProperties() throws Exception {
53+
File file = new File(PATH_TO_WORKSPACE_FILES, "views-without-order.json");
54+
Workspace workspace = WorkspaceUtils.loadWorkspaceFromJson(file);
55+
56+
assertEquals(2, workspace.getViews().getSystemLandscapeViews().size());
57+
}
58+
5159
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"description" : "Description",
3+
"id" : 0,
4+
"model" : {
5+
"people" : [ {
6+
"id" : "1",
7+
"name" : "User",
8+
"tags" : "Element,Person"
9+
} ]
10+
},
11+
"name" : "Name",
12+
"views" : {
13+
"systemLandscapeViews" : [ {
14+
"elements" : [ {
15+
"id" : "1"
16+
} ],
17+
"enterpriseBoundaryVisible" : true,
18+
"key" : "SystemLandscape-001"
19+
}, {
20+
"elements" : [ {
21+
"id" : "1"
22+
} ],
23+
"enterpriseBoundaryVisible" : true,
24+
"key" : "SystemLandscape-002"
25+
} ]
26+
}
27+
}

structurizr-core/src/main/java/com/structurizr/view/View.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,12 @@ void setProperties(Map<String, String> properties) {
162162

163163
@Override
164164
public int compareTo(View view) {
165-
return getOrder() - view.getOrder();
165+
int result = getOrder() - view.getOrder();
166+
if (result == 0) {
167+
result = getKey().compareToIgnoreCase(view.getKey());
168+
}
169+
170+
return result;
166171
}
167172

168173
}

0 commit comments

Comments
 (0)