Search in sources :

Example 1 with ContainerView

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));
}
Also used : ContainerView(com.structurizr.view.ContainerView) Test(org.junit.jupiter.api.Test)

Example 2 with ContainerView

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;
}
Also used : Element(com.structurizr.model.Element) SoftwareSystem(com.structurizr.model.SoftwareSystem) ContainerView(com.structurizr.view.ContainerView) Workspace(com.structurizr.Workspace)

Example 3 with ContainerView

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();
}
Also used : Container(com.structurizr.model.Container) Model(com.structurizr.model.Model) SoftwareSystem(com.structurizr.model.SoftwareSystem) ContainerView(com.structurizr.view.ContainerView)

Example 4 with ContainerView

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);
}
Also used : ComponentView(com.structurizr.view.ComponentView) ViewSet(com.structurizr.view.ViewSet) SystemContextView(com.structurizr.view.SystemContextView) SoftwareSystem(com.structurizr.model.SoftwareSystem) ContainerView(com.structurizr.view.ContainerView)

Example 5 with ContainerView

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);
    }
}
Also used : Arrays(java.util.Arrays) DecodeException(io.kroki.server.error.DecodeException) DiagramSource(io.kroki.server.decode.DiagramSource) StructurizrDslParserException(com.structurizr.dsl.StructurizrDslParserException) View(com.structurizr.view.View) SystemLandscapeView(com.structurizr.view.SystemLandscapeView) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) DeploymentView(com.structurizr.view.DeploymentView) Diagram(com.structurizr.export.Diagram) BadRequestException(io.kroki.server.error.BadRequestException) ComponentView(com.structurizr.view.ComponentView) ContainerView(com.structurizr.view.ContainerView) DynamicView(com.structurizr.view.DynamicView) Collection(java.util.Collection) StructurizrPlantUMLExporter(com.structurizr.export.plantuml.StructurizrPlantUMLExporter) Vertx(io.vertx.core.Vertx) FileFormat(io.kroki.server.format.FileFormat) SourceDecoder(io.kroki.server.decode.SourceDecoder) Objects(java.util.Objects) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) StructurizrDslParser(com.structurizr.dsl.StructurizrDslParser) SystemContextView(com.structurizr.view.SystemContextView) Optional(java.util.Optional) Handler(io.vertx.core.Handler) StructurizrDslParser(com.structurizr.dsl.StructurizrDslParser) JsonObject(io.vertx.core.json.JsonObject) StructurizrDslParserException(com.structurizr.dsl.StructurizrDslParserException) View(com.structurizr.view.View) SystemLandscapeView(com.structurizr.view.SystemLandscapeView) DeploymentView(com.structurizr.view.DeploymentView) ComponentView(com.structurizr.view.ComponentView) ContainerView(com.structurizr.view.ContainerView) DynamicView(com.structurizr.view.DynamicView) SystemContextView(com.structurizr.view.SystemContextView) Diagram(com.structurizr.export.Diagram) ComponentView(com.structurizr.view.ComponentView) SystemContextView(com.structurizr.view.SystemContextView) BadRequestException(io.kroki.server.error.BadRequestException) SystemLandscapeView(com.structurizr.view.SystemLandscapeView) DynamicView(com.structurizr.view.DynamicView) ContainerView(com.structurizr.view.ContainerView) DeploymentView(com.structurizr.view.DeploymentView)

Aggregations

ContainerView (com.structurizr.view.ContainerView)7 SoftwareSystem (com.structurizr.model.SoftwareSystem)4 ComponentView (com.structurizr.view.ComponentView)4 SystemContextView (com.structurizr.view.SystemContextView)3 Workspace (com.structurizr.Workspace)2 Container (com.structurizr.model.Container)2 Model (com.structurizr.model.Model)2 ViewSet (com.structurizr.view.ViewSet)2 ComponentFinder (com.structurizr.analysis.ComponentFinder)1 StructurizrAnnotationsComponentFinderStrategy (com.structurizr.analysis.StructurizrAnnotationsComponentFinderStrategy)1 StructurizrDslParser (com.structurizr.dsl.StructurizrDslParser)1 StructurizrDslParserException (com.structurizr.dsl.StructurizrDslParserException)1 Diagram (com.structurizr.export.Diagram)1 StructurizrPlantUMLExporter (com.structurizr.export.plantuml.StructurizrPlantUMLExporter)1 Component (com.structurizr.model.Component)1 Element (com.structurizr.model.Element)1 Person (com.structurizr.model.Person)1 DeploymentView (com.structurizr.view.DeploymentView)1 DynamicView (com.structurizr.view.DynamicView)1 SystemLandscapeView (com.structurizr.view.SystemLandscapeView)1