From b4211a9674fdf681f87fca2584d5facd57c7dedf Mon Sep 17 00:00:00 2001 From: Simon Brown Date: Tue, 18 Jun 2024 14:25:28 +0100 Subject: [PATCH] Fixes https://github.com/structurizr/java/issues/306 --- build.gradle | 2 +- changelog.md | 7 ++++++- .../main/java/com/structurizr/model/Model.java | 5 +---- .../test/java/com/structurizr/WorkspaceTests.java | 15 +++++++++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 8420a695..8588325a 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ subprojects { proj -> description = 'Structurizr' group = 'com.structurizr' - version = '2.1.3' + version = '2.1.4' repositories { mavenCentral() diff --git a/changelog.md b/changelog.md index f5366e14..82310e5f 100644 --- a/changelog.md +++ b/changelog.md @@ -1,8 +1,13 @@ # Changelog + +## 2.1.4 (18th June 2024) + +- structurizr-core: Fixes https://github.com/structurizr/java/issues/306 (Workspace.trim() is not correctly removing relationships when the destination of a relationship is removed from the workspace). + ## 2.1.3 (16th June 2024) -- structurizr-core: Fixes https://github.com/structurizr/java/issues/298 (Unknown model item type on 'element') +- structurizr-core: Fixes https://github.com/structurizr/java/issues/298 (Unknown model item type on 'element'). ## 2.1.2 (30th April 2024) diff --git a/structurizr-core/src/main/java/com/structurizr/model/Model.java b/structurizr-core/src/main/java/com/structurizr/model/Model.java index 3e49dd9e..25d6c9d2 100644 --- a/structurizr-core/src/main/java/com/structurizr/model/Model.java +++ b/structurizr-core/src/main/java/com/structurizr/model/Model.java @@ -1149,12 +1149,9 @@ private void removeElement(Element element) { // remove any relationships to/from the element for (Relationship relationship : getRelationships()) { - if (relationship.getSource() == element) { + if (relationship.getSource() == element || relationship.getDestination() == element) { removeRelationshipFromInternalStructures(relationship); relationship.getSource().remove(relationship); - } else if (relationship.getDestination() == element) { - removeRelationshipFromInternalStructures(relationship); - relationship.getDestination().remove(relationship); } } diff --git a/structurizr-core/src/test/java/com/structurizr/WorkspaceTests.java b/structurizr-core/src/test/java/com/structurizr/WorkspaceTests.java index b5b741da..c22b582b 100644 --- a/structurizr-core/src/test/java/com/structurizr/WorkspaceTests.java +++ b/structurizr-core/src/test/java/com/structurizr/WorkspaceTests.java @@ -285,4 +285,19 @@ void trim_WhenSomeElementsAreUnused() { assertTrue(workspace.getModel().contains(bc)); } + @Test + void trim_WhenTheDestinationOfAnElementIsRemoved() { + Workspace workspace = new Workspace("Name", "Description"); + SoftwareSystem a = workspace.getModel().addSoftwareSystem("A"); + SoftwareSystem b = workspace.getModel().addSoftwareSystem("B"); + a.uses(b, "Uses"); + + SystemLandscapeView view = workspace.getViews().createSystemLandscapeView("key", "Description"); + view.add(a); + + workspace.trim(); + + assertEquals(0, a.getRelationships().size()); + } + } \ No newline at end of file