Skip to content

Commit

Permalink
Adds a findTerminology() method on the Terminology class.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Mar 27, 2021
1 parent 04af66c commit c79d3a8
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ subprojects { proj ->

description = 'Structurizr'
group = 'com.structurizr'
version = '1.9.0'
version = '1.9.1'

repositories {
mavenCentral()
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.9.1 (unreleased)

- Adds a `findTerminology` method on the `Terminology` class.

## 1.9.0 (20th March 2021)

- Adds support for adding individual infrastructure nodes, software system instances, and container instances to a deployment view.
Expand Down
32 changes: 32 additions & 0 deletions structurizr-core/src/com/structurizr/view/Terminology.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.structurizr.view;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.structurizr.model.*;
import com.structurizr.util.StringUtils;

/**
* Provides a way for the terminology on diagrams, etc to be modified (e.g. language translations).
Expand Down Expand Up @@ -106,4 +108,34 @@ public void setRelationship(String relationship) {
this.relationship = relationship;
}

/**
* Finds the terminology that can be used to describe/label the specified model item.
*
* @param modelItem an Element or Relationship
* @return the default or overridden terminology for the specified model item
*/
public String findTerminology(ModelItem modelItem) {
if (modelItem instanceof StaticStructureElementInstance) {
modelItem = ((StaticStructureElementInstance)modelItem).getElement();
}

if (modelItem instanceof Relationship) {
return !StringUtils.isNullOrEmpty(getRelationship()) ? getRelationship() : "Relationship";
} else if (modelItem instanceof Person) {
return !StringUtils.isNullOrEmpty(getPerson()) ? getPerson() : "Person";
} else if (modelItem instanceof SoftwareSystem) {
return !StringUtils.isNullOrEmpty(getSoftwareSystem()) ? getSoftwareSystem() : "Software System";
} else if (modelItem instanceof Container) {
return !StringUtils.isNullOrEmpty(getContainer()) ? getContainer() : "Container";
} else if (modelItem instanceof Component) {
return !StringUtils.isNullOrEmpty(getComponent()) ? getComponent() : "Component";
} else if (modelItem instanceof DeploymentNode) {
return !StringUtils.isNullOrEmpty(getDeploymentNode()) ? getDeploymentNode() : "Deployment Node";
} else if (modelItem instanceof InfrastructureNode) {
return !StringUtils.isNullOrEmpty(getInfrastructureNode()) ? getInfrastructureNode() : "Infrastructure Node";
}

throw new IllegalArgumentException("Unknown model item type.");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.structurizr.view;

import com.structurizr.Workspace;
import com.structurizr.model.*;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class TerminologyTests {

@Test
public void test_findTerminology() {
Workspace workspace = new Workspace("Name", "Description");
Terminology terminology = workspace.getViews().getConfiguration().getTerminology();
Person person = workspace.getModel().addPerson("Name");
SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Name");
Container container = softwareSystem.addContainer("Container");
Component component = container.addComponent("Component");
DeploymentNode deploymentNode = workspace.getModel().addDeploymentNode("Deployment Node");
InfrastructureNode infrastructureNode = deploymentNode.addInfrastructureNode("Infrastructure Node");
SoftwareSystemInstance softwareSystemInstance = deploymentNode.add(softwareSystem);
ContainerInstance containerInstance = deploymentNode.add(container);
Relationship relationship = person.uses(softwareSystem, "Uses");

assertEquals("Person", terminology.findTerminology(person));
assertEquals("Software System", terminology.findTerminology(softwareSystem));
assertEquals("Container", terminology.findTerminology(container));
assertEquals("Component", terminology.findTerminology(component));
assertEquals("Deployment Node", terminology.findTerminology(deploymentNode));
assertEquals("Infrastructure Node", terminology.findTerminology(infrastructureNode));
assertEquals("Software System", terminology.findTerminology(softwareSystemInstance));
assertEquals("Container", terminology.findTerminology(containerInstance));
assertEquals("Relationship", terminology.findTerminology(relationship));

terminology.setPerson("PERSON");
terminology.setSoftwareSystem("SOFTWARE SYSTEM");
terminology.setContainer("CONTAINER");
terminology.setComponent("COMPONENT");
terminology.setDeploymentNode("DEPLOYMENT NODE");
terminology.setInfrastructureNode("INFRASTRUCTURE NODE");
terminology.setRelationship("RELATIONSHIP");

assertEquals("PERSON", terminology.findTerminology(person));
assertEquals("SOFTWARE SYSTEM", terminology.findTerminology(softwareSystem));
assertEquals("CONTAINER", terminology.findTerminology(container));
assertEquals("COMPONENT", terminology.findTerminology(component));
assertEquals("DEPLOYMENT NODE", terminology.findTerminology(deploymentNode));
assertEquals("INFRASTRUCTURE NODE", terminology.findTerminology(infrastructureNode));
assertEquals("SOFTWARE SYSTEM", terminology.findTerminology(softwareSystemInstance));
assertEquals("CONTAINER", terminology.findTerminology(containerInstance));
assertEquals("RELATIONSHIP", terminology.findTerminology(relationship));
}

}

0 comments on commit c79d3a8

Please sign in to comment.