use of com.structurizr.model.SoftwareSystem in project dsl by structurizr.
the class ContainerParser method parse.
Container parse(SoftwareSystemDslContext context, Tokens tokens) {
if (tokens.hasMoreThan(TAGS_INDEX)) {
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
}
if (!tokens.includes(NAME_INDEX)) {
throw new RuntimeException("Expected: " + GRAMMAR);
}
SoftwareSystem softwareSystem = context.getSoftwareSystem();
Container container = null;
String name = tokens.get(NAME_INDEX);
if (context.isExtendingWorkspace()) {
container = softwareSystem.getContainerWithName(name);
}
if (container == null) {
container = softwareSystem.addContainer(name);
}
if (tokens.includes(DESCRIPTION_INDEX)) {
String description = tokens.get(DESCRIPTION_INDEX);
container.setDescription(description);
}
if (tokens.includes(TECHNOLOGY_INDEX)) {
String technology = tokens.get(TECHNOLOGY_INDEX);
container.setTechnology(technology);
}
if (tokens.includes(TAGS_INDEX)) {
String tags = tokens.get(TAGS_INDEX);
container.addTags(tags.split(","));
}
if (context.hasGroup()) {
container.setGroup(context.getGroup().getName());
context.getGroup().addElement(container);
}
return container;
}
use of com.structurizr.model.SoftwareSystem in project dsl by structurizr.
the class ContainerViewParser method parse.
ContainerView parse(DslContext context, Tokens tokens) {
if (tokens.hasMoreThan(DESCRIPTION_INDEX)) {
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
}
if (!tokens.includes(SOFTWARE_SYSTEM_IDENTIFIER_INDEX)) {
throw new RuntimeException("Expected: " + GRAMMAR);
}
Workspace workspace = context.getWorkspace();
SoftwareSystem softwareSystem;
String key = "";
String description = "";
String softwareSystemIdentifier = tokens.get(SOFTWARE_SYSTEM_IDENTIFIER_INDEX);
Element element = context.getElement(softwareSystemIdentifier);
if (element == null) {
throw new RuntimeException("The software system \"" + softwareSystemIdentifier + "\" does not exist");
}
if (element instanceof SoftwareSystem) {
softwareSystem = (SoftwareSystem) element;
} else {
throw new RuntimeException("The element \"" + softwareSystemIdentifier + "\" is not a software system");
}
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = key = removeNonWordCharacters(softwareSystem.getName()) + "-" + VIEW_TYPE;
}
validateViewKey(key);
if (tokens.includes(DESCRIPTION_INDEX)) {
description = tokens.get(DESCRIPTION_INDEX);
}
ContainerView view = workspace.getViews().createContainerView(softwareSystem, key, description);
view.setExternalSoftwareSystemBoundariesVisible(true);
return view;
}
use of com.structurizr.model.SoftwareSystem in project java by structurizr.
the class ThemeUtilsTests method test_findRelationshipStyle_WithThemes.
@Test
public void test_findRelationshipStyle_WithThemes() {
Workspace workspace = new Workspace("Name", "Description");
SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Name");
Relationship relationship = softwareSystem.uses(softwareSystem, "Uses");
workspace.getViews().getConfiguration().getStyles().addRelationshipStyle("Relationship").dashed(false);
// theme 1
Collection<ElementStyle> elementStyles = new ArrayList<>();
Collection<RelationshipStyle> relationshipStyles = new ArrayList<>();
relationshipStyles.add(new RelationshipStyle("Relationship").color("#ff0000").thickness(4));
workspace.getViews().getConfiguration().getStyles().addStylesFromTheme("url1", elementStyles, relationshipStyles);
// theme 2
elementStyles = new ArrayList<>();
relationshipStyles = new ArrayList<>();
relationshipStyles.add(new RelationshipStyle("Relationship").color("#0000ff"));
workspace.getViews().getConfiguration().getStyles().addStylesFromTheme("url2", elementStyles, relationshipStyles);
RelationshipStyle style = workspace.getViews().getConfiguration().getStyles().findRelationshipStyle(relationship);
// from theme 1
assertEquals(new Integer(4), style.getThickness());
// from theme 2
assertEquals("#0000ff", style.getColor());
// from workspace
Assert.assertFalse(style.getDashed());
assertEquals(Routing.Direct, style.getRouting());
assertEquals(new Integer(24), style.getFontSize());
assertEquals(new Integer(200), style.getWidth());
assertEquals(new Integer(50), style.getPosition());
assertEquals(new Integer(100), style.getOpacity());
}
use of com.structurizr.model.SoftwareSystem in project java by structurizr.
the class DefaultLayoutMergeStrategyTests method test_copyLayoutInformation_WhenCanonicalNamesHaveNotChanged.
@Test
public void test_copyLayoutInformation_WhenCanonicalNamesHaveNotChanged() {
Workspace workspace1 = new Workspace("1", "");
SoftwareSystem softwareSystem1 = workspace1.getModel().addSoftwareSystem("Software System");
Container container1 = softwareSystem1.addContainer("Container", "", "");
ContainerView view1 = workspace1.getViews().createContainerView(softwareSystem1, "key", "");
view1.add(container1);
view1.getElementView(container1).setX(123);
view1.getElementView(container1).setY(456);
Workspace workspace2 = new Workspace("2", "");
SoftwareSystem softwareSystem2 = workspace2.getModel().addSoftwareSystem("Software System");
Container container2 = softwareSystem2.addContainer("Container", "", "");
ContainerView view2 = workspace2.getViews().createContainerView(softwareSystem2, "key", "");
view2.add(container2);
DefaultLayoutMergeStrategy strategy = new DefaultLayoutMergeStrategy();
strategy.copyLayoutInformation(view1, view2);
assertEquals(123, view2.getElementView(container2).getX());
assertEquals(456, view2.getElementView(container2).getY());
}
use of com.structurizr.model.SoftwareSystem in project java by structurizr.
the class DefaultLayoutMergeStrategyTests method test_copyLayoutInformation_WhenAnElementNameAndDescriptionAndIdHaveChanged.
@Test
public void test_copyLayoutInformation_WhenAnElementNameAndDescriptionAndIdHaveChanged() {
Workspace workspace1 = new Workspace("1", "");
SoftwareSystem softwareSystem1 = workspace1.getModel().addSoftwareSystem("Software System");
Container container1 = softwareSystem1.addContainer("Container", "Container description", "");
ContainerView view1 = workspace1.getViews().createContainerView(softwareSystem1, "key", "");
view1.add(container1);
view1.getElementView(container1).setX(123);
view1.getElementView(container1).setY(456);
Workspace workspace2 = new Workspace("2", "");
SoftwareSystem softwareSystem2 = workspace2.getModel().addSoftwareSystem("Software System");
// this element has ID 2
softwareSystem2.addContainer("Web Application", "Description", "");
Container container2 = softwareSystem2.addContainer("Database", "Description", "");
ContainerView view2 = workspace2.getViews().createContainerView(softwareSystem2, "key", "");
view2.add(container2);
DefaultLayoutMergeStrategy strategy = new DefaultLayoutMergeStrategy();
strategy.copyLayoutInformation(view1, view2);
assertEquals(0, view2.getElementView(container2).getX());
assertEquals(0, view2.getElementView(container2).getY());
}
Aggregations