use of com.structurizr.view.ContainerView in project dsl by structurizr.
the class AbstractExpressionParserTests method test_parseExpression_ReturnsElements_WhenUsingAnElementParentExpression.
@Test
void test_parseExpression_ReturnsElements_WhenUsingAnElementParentExpression() {
SoftwareSystem softwareSystemA = model.addSoftwareSystem("Software System A");
Container container1 = softwareSystemA.addContainer("Container 1");
SoftwareSystem softwareSystemB = model.addSoftwareSystem("Software System B");
Container container2 = softwareSystemB.addContainer("Container 2");
ContainerView view = views.createContainerView(softwareSystemA, "key", "Description");
ContainerViewDslContext context = new ContainerViewDslContext(view);
context.setWorkspace(workspace);
IdentifiersRegister identifiersRegister = new IdentifiersRegister();
identifiersRegister.register("b", softwareSystemB);
context.setIdentifierRegister(identifiersRegister);
Set<ModelItem> elements = parser.parseExpression("element.parent==b", context);
assertEquals(1, elements.size());
assertTrue(elements.contains(container2));
}
use of com.structurizr.view.ContainerView 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.view.ContainerView in project tutorials by eugenp.
the class StructurizrSimple method addContainers.
private static void addContainers(Workspace workspace) {
Model model = workspace.getModel();
SoftwareSystem paymentTerminal = model.getSoftwareSystemWithName(PAYMENT_TERMINAL);
Container f5 = paymentTerminal.addContainer("Payment Load Balancer", "Payment Load Balancer", "F5");
Container jvm1 = paymentTerminal.addContainer("JVM-1", "JVM-1", "Java Virtual Machine");
Container jvm2 = paymentTerminal.addContainer("JVM-2", "JVM-2", "Java Virtual Machine");
Container jvm3 = paymentTerminal.addContainer("JVM-3", "JVM-3", "Java Virtual Machine");
Container oracle = paymentTerminal.addContainer("oracleDB", "Oracle Database", "RDBMS");
f5.uses(jvm1, "route");
f5.uses(jvm2, "route");
f5.uses(jvm3, "route");
jvm1.uses(oracle, "storage");
jvm2.uses(oracle, "storage");
jvm3.uses(oracle, "storage");
ContainerView view = workspace.getViews().createContainerView(paymentTerminal, CONTAINER_VIEW, "Container View");
view.addAllContainers();
}
use of com.structurizr.view.ContainerView in project agile-architecture-documentation-system by Riduidel.
the class ViewsGenerator method endVisit.
@Override
public void endVisit(Workspace workspace, OutputBuilder builder) {
ViewSet views = workspace.getViews();
SoftwareSystem agileArchitecture = workspace.getModel().getSoftwareSystemWithName(Architecture.AGILE_ARCHITECTURE_DOCUMENTATION);
SystemContextView contextView = views.createSystemContextView(agileArchitecture, "SystemContext", "Illustration of agile-architecture-documentation usage");
contextView.addAllSoftwareSystems();
contextView.addAllPeople();
ContainerView agileArchitectureContainers = views.createContainerView(agileArchitecture, "agile.architecture.containers", "Agile architecture containers");
agileArchitectureContainers.addAllContainersAndInfluencers();
ComponentView agileArchitectureBaseComponents = views.createComponentView(agileArchitecture.getContainerWithName(Architecture.CONTAINERS_BASE), "agile.architecture.base.components", "Agile architecture base components view");
agileArchitectureBaseComponents.addAllComponents();
// Styles styles = views.getConfiguration().getStyles();
// styles.addElementStyle(Tags.SOFTWARE_SYSTEM).background("#1168bd").color("#ffffff");
// styles.addElementStyle(Tags.PERSON).background("#08427b").color("#ffffff").shape(Shape.Person);
}
use of com.structurizr.view.ContainerView in project kroki by yuzutech.
the class Structurizr method convert.
static byte[] convert(String source, FileFormat fileFormat, StructurizrPlantUMLExporter structurizrPlantUMLExporter, JsonObject options) {
StructurizrDslParser parser = new StructurizrDslParser();
try {
parser.parse(source);
Collection<View> views = parser.getWorkspace().getViews().getViews();
if (views.isEmpty()) {
throw new BadRequestException("Empty diagram, does not have any view.");
}
View selectedView;
String viewKey = options.getString("view-key");
if (viewKey != null && !viewKey.trim().isEmpty()) {
Optional<View> viewFound = views.stream().filter(view -> Objects.equals(view.getKey(), viewKey)).findFirst();
if (!viewFound.isPresent()) {
throw new BadRequestException("Unable to find view for key: " + viewKey + ".");
}
selectedView = viewFound.get();
} else {
// take the first view if not specified
selectedView = views.iterator().next();
}
final Diagram diagram;
if (selectedView instanceof DynamicView) {
diagram = structurizrPlantUMLExporter.export((DynamicView) selectedView);
} else if (selectedView instanceof DeploymentView) {
diagram = structurizrPlantUMLExporter.export((DeploymentView) selectedView);
} else if (selectedView instanceof ComponentView) {
diagram = structurizrPlantUMLExporter.export((ComponentView) selectedView);
} else if (selectedView instanceof ContainerView) {
diagram = structurizrPlantUMLExporter.export((ContainerView) selectedView);
} else if (selectedView instanceof SystemContextView) {
diagram = structurizrPlantUMLExporter.export((SystemContextView) selectedView);
} else if (selectedView instanceof SystemLandscapeView) {
diagram = structurizrPlantUMLExporter.export((SystemLandscapeView) selectedView);
} else {
throw new BadRequestException("View type is not supported: " + selectedView.getClass().getSimpleName() + ", must be a DynamicView, DeploymentView, ComponentView, ContainerView, SystemContextView or SystemLandscapeView.");
}
return Plantuml.convert(diagram.getDefinition(), fileFormat, new JsonObject());
} catch (StructurizrDslParserException e) {
String cause = e.getMessage();
final String message;
if (cause != null && !cause.trim().isEmpty()) {
message = "Unable to parse the Structurizr DSL. " + cause + ".";
} else {
message = "Unable to parse the Structurizr DSL.";
}
throw new BadRequestException(message, e);
}
}
Aggregations