diff --git a/changelog.md b/changelog.md index 739b77a1..8c1760d4 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Changelog +## unreleased + +- structurizr-core: Fixes https://github.com/structurizr/java/issues/298 (Unknown model item type on 'element') + ## 2.1.2 (30th April 2024) - structurizr-core: Adds better backwards compatibility to deal with old workspaces and those created by third party tooling that are missing view `order` property on views. diff --git a/structurizr-core/src/main/java/com/structurizr/view/Terminology.java b/structurizr-core/src/main/java/com/structurizr/view/Terminology.java index b8daf3e1..575a16a5 100644 --- a/structurizr-core/src/main/java/com/structurizr/view/Terminology.java +++ b/structurizr-core/src/main/java/com/structurizr/view/Terminology.java @@ -134,6 +134,9 @@ public String findTerminology(ModelItem modelItem) { return !StringUtils.isNullOrEmpty(getDeploymentNode()) ? getDeploymentNode() : "Deployment Node"; } else if (modelItem instanceof InfrastructureNode) { return !StringUtils.isNullOrEmpty(getInfrastructureNode()) ? getInfrastructureNode() : "Infrastructure Node"; + } else if (modelItem instanceof CustomElement) { + String terminology = ((CustomElement)modelItem).getMetadata(); + return !StringUtils.isNullOrEmpty(terminology) ? terminology : "Element"; } throw new IllegalArgumentException("Unknown model item type."); diff --git a/structurizr-core/src/test/java/com/structurizr/view/TerminologyTests.java b/structurizr-core/src/test/java/com/structurizr/view/TerminologyTests.java index 7f19c895..316a23bb 100644 --- a/structurizr-core/src/test/java/com/structurizr/view/TerminologyTests.java +++ b/structurizr-core/src/test/java/com/structurizr/view/TerminologyTests.java @@ -12,6 +12,7 @@ public class TerminologyTests { void findTerminology() { Workspace workspace = new Workspace("Name", "Description"); Terminology terminology = workspace.getViews().getConfiguration().getTerminology(); + CustomElement element = workspace.getModel().addCustomElement("Element", "Hardware Device", "Description"); Person person = workspace.getModel().addPerson("Name"); SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Name"); Container container = softwareSystem.addContainer("Container"); @@ -22,6 +23,7 @@ void findTerminology() { ContainerInstance containerInstance = deploymentNode.add(container); Relationship relationship = person.uses(softwareSystem, "Uses"); + assertEquals("Hardware Device", terminology.findTerminology(element)); assertEquals("Person", terminology.findTerminology(person)); assertEquals("Software System", terminology.findTerminology(softwareSystem)); assertEquals("Container", terminology.findTerminology(container));