use of com.structurizr.model.SoftwareSystem in project dsl by structurizr.
the class DynamicViewParser method parse.
DynamicView parse(DslContext context, Tokens tokens) {
// dynamic <*|software system identifier|container identifier> [key] [description] {
Workspace workspace = context.getWorkspace();
String key = "";
String description = "";
DecimalFormat format = new DecimalFormat("000");
if (tokens.hasMoreThan(DESCRIPTION_INDEX)) {
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
}
if (!tokens.includes(SCOPE_IDENTIFIER_INDEX)) {
throw new RuntimeException("Expected: " + GRAMMAR);
}
if (tokens.includes(DESCRIPTION_INDEX)) {
description = tokens.get(DESCRIPTION_INDEX);
}
DynamicView view;
String scopeIdentifier = tokens.get(SCOPE_IDENTIFIER_INDEX);
if (WILDCARD.equals(scopeIdentifier)) {
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = VIEW_TYPE + "-" + format.format(workspace.getViews().getDynamicViews().size() + 1);
}
validateViewKey(key);
view = workspace.getViews().createDynamicView(key, description);
} else {
Element element = context.getElement(scopeIdentifier);
if (element == null) {
throw new RuntimeException("The software system or container \"" + scopeIdentifier + "\" does not exist");
}
if (element instanceof SoftwareSystem) {
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = removeNonWordCharacters(element.getName()) + "-" + VIEW_TYPE + "-" + format.format(workspace.getViews().getDynamicViews().size() + 1);
}
validateViewKey(key);
view = workspace.getViews().createDynamicView((SoftwareSystem) element, key, description);
} else if (element instanceof Container) {
Container container = (Container) element;
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = removeNonWordCharacters(container.getSoftwareSystem().getName()) + "-" + removeNonWordCharacters(container.getName()) + "-" + VIEW_TYPE + "-" + format.format(workspace.getViews().getDynamicViews().size() + 1);
}
validateViewKey(key);
view = workspace.getViews().createDynamicView((Container) element, key, description);
} else {
throw new RuntimeException("The element \"" + scopeIdentifier + "\" is not a software system or container");
}
}
view.setExternalBoundariesVisible(true);
return view;
}
use of com.structurizr.model.SoftwareSystem in project dsl by structurizr.
the class SoftwareSystemParser method parse.
SoftwareSystem parse(GroupableDslContext 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 = null;
String name = tokens.get(NAME_INDEX);
if (context.isExtendingWorkspace()) {
softwareSystem = context.getWorkspace().getModel().getSoftwareSystemWithName(name);
}
if (softwareSystem == null) {
softwareSystem = context.getWorkspace().getModel().addSoftwareSystem(name);
}
String description = "";
if (tokens.includes(DESCRIPTION_INDEX)) {
description = tokens.get(DESCRIPTION_INDEX);
softwareSystem.setDescription(description);
}
if (tokens.includes(TAGS_INDEX)) {
String tags = tokens.get(TAGS_INDEX);
softwareSystem.addTags(tags.split(","));
}
if (context instanceof EnterpriseDslContext) {
softwareSystem.setLocation(Location.Internal);
}
if (context.hasGroup()) {
softwareSystem.setGroup(context.getGroup().getName());
context.getGroup().addElement(softwareSystem);
}
return softwareSystem;
}
use of com.structurizr.model.SoftwareSystem in project dsl by structurizr.
the class SystemContextViewParser method parse.
SystemContextView parse(DslContext context, Tokens tokens) {
// systemContext <software system identifier> [key] [description] {
Workspace workspace = context.getWorkspace();
SoftwareSystem softwareSystem;
String key = "";
String description = "";
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);
}
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 = removeNonWordCharacters(softwareSystem.getName()) + "-" + VIEW_TYPE;
}
validateViewKey(key);
if (tokens.includes(DESCRIPTION_INDEX)) {
description = tokens.get(DESCRIPTION_INDEX);
}
SystemContextView view = workspace.getViews().createSystemContextView(softwareSystem, key, description);
view.setEnterpriseBoundaryVisible(true);
return view;
}
use of com.structurizr.model.SoftwareSystem in project dsl by structurizr.
the class DynamicViewContentParserTests method test_parseRelationship_AddsTheRelationshipToTheViewWithAnOverriddenDescription_WhenItAlreadyExistsInTheModel.
@Test
void test_parseRelationship_AddsTheRelationshipToTheViewWithAnOverriddenDescription_WhenItAlreadyExistsInTheModel() {
Person user = model.addPerson("User", "Description");
SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
user.uses(softwareSystem, "Uses");
DynamicView view = views.createDynamicView("key", "Description");
DynamicViewDslContext context = new DynamicViewDslContext(view);
IdentifiersRegister elements = new IdentifiersRegister();
elements.register("source", user);
elements.register("destination", softwareSystem);
context.setIdentifierRegister(elements);
parser.parseRelationship(context, tokens("source", "->", "destination", "Does something with"));
assertEquals(1, view.getRelationships().size());
RelationshipView rv = view.getRelationships().iterator().next();
assertSame(user, rv.getRelationship().getSource());
assertSame(softwareSystem, rv.getRelationship().getDestination());
assertEquals("Does something with", rv.getDescription());
assertEquals("1", rv.getOrder());
}
use of com.structurizr.model.SoftwareSystem in project dsl by structurizr.
the class ContainerParserTests method test_parse_CreatesAContainerWithADescription.
@Test
void test_parse_CreatesAContainerWithADescription() {
SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
SoftwareSystemDslContext context = new SoftwareSystemDslContext(softwareSystem);
parser.parse(context, tokens("container", "Name", "Description"));
assertEquals(2, model.getElements().size());
Container container = softwareSystem.getContainerWithName("Name");
assertNotNull(container);
assertEquals("Description", container.getDescription());
assertEquals("", container.getTechnology());
assertEquals("Element,Container", container.getTags());
}
Aggregations