From 5ae28b0cca6239f7a7c07d6cf33b35f9949bd793 Mon Sep 17 00:00:00 2001 From: Simon Brown Date: Fri, 15 Mar 2024 15:04:35 +0000 Subject: [PATCH] Adds some code to deal with old workspaces, or those created by third party tooling that are missing view `order` properties. --- .../api/BackwardsCompatibilityTests.java | 8 ++++++ .../views-without-order.json | 27 +++++++++++++++++++ .../main/java/com/structurizr/view/View.java | 7 ++++- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 structurizr-client/src/integrationTest/resources/backwardsCompatibility/views-without-order.json diff --git a/structurizr-client/src/integrationTest/java/com/structurizr/api/BackwardsCompatibilityTests.java b/structurizr-client/src/integrationTest/java/com/structurizr/api/BackwardsCompatibilityTests.java index e029b5ec..6ae4cb02 100644 --- a/structurizr-client/src/integrationTest/java/com/structurizr/api/BackwardsCompatibilityTests.java +++ b/structurizr-client/src/integrationTest/java/com/structurizr/api/BackwardsCompatibilityTests.java @@ -48,4 +48,12 @@ void documentation() throws Exception { {"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)); } + @Test + void viewsWithoutOrderProperties() throws Exception { + File file = new File(PATH_TO_WORKSPACE_FILES, "views-without-order.json"); + Workspace workspace = WorkspaceUtils.loadWorkspaceFromJson(file); + + assertEquals(2, workspace.getViews().getSystemLandscapeViews().size()); + } + } \ No newline at end of file diff --git a/structurizr-client/src/integrationTest/resources/backwardsCompatibility/views-without-order.json b/structurizr-client/src/integrationTest/resources/backwardsCompatibility/views-without-order.json new file mode 100644 index 00000000..c84331f3 --- /dev/null +++ b/structurizr-client/src/integrationTest/resources/backwardsCompatibility/views-without-order.json @@ -0,0 +1,27 @@ +{ + "description" : "Description", + "id" : 0, + "model" : { + "people" : [ { + "id" : "1", + "name" : "User", + "tags" : "Element,Person" + } ] + }, + "name" : "Name", + "views" : { + "systemLandscapeViews" : [ { + "elements" : [ { + "id" : "1" + } ], + "enterpriseBoundaryVisible" : true, + "key" : "SystemLandscape-001" + }, { + "elements" : [ { + "id" : "1" + } ], + "enterpriseBoundaryVisible" : true, + "key" : "SystemLandscape-002" + } ] + } +} \ No newline at end of file diff --git a/structurizr-core/src/main/java/com/structurizr/view/View.java b/structurizr-core/src/main/java/com/structurizr/view/View.java index 51043749..c34e2bf5 100644 --- a/structurizr-core/src/main/java/com/structurizr/view/View.java +++ b/structurizr-core/src/main/java/com/structurizr/view/View.java @@ -162,7 +162,12 @@ void setProperties(Map properties) { @Override public int compareTo(View view) { - return getOrder() - view.getOrder(); + int result = getOrder() - view.getOrder(); + if (result == 0) { + result = getKey().compareToIgnoreCase(view.getKey()); + } + + return result; } } \ No newline at end of file