Search in sources :

Example 11 with DynamicView

use of com.structurizr.view.DynamicView in project dsl by structurizr.

the class ViewParserTests method test_parseTitle_SetsTheTitleOfADynamicView.

@Test
void test_parseTitle_SetsTheTitleOfADynamicView() {
    DynamicView view = workspace.getViews().createDynamicView("key", "description");
    DynamicViewDslContext context = new DynamicViewDslContext(view);
    context.setWorkspace(workspace);
    assertNull(view.getTitle());
    parser.parseTitle(context, tokens("title", "A new title"));
    assertEquals("A new title", view.getTitle());
}
Also used : DynamicView(com.structurizr.view.DynamicView) Test(org.junit.jupiter.api.Test)

Example 12 with DynamicView

use of com.structurizr.view.DynamicView 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)

Example 13 with DynamicView

use of com.structurizr.view.DynamicView in project dsl by structurizr.

the class DynamicViewParserTests method test_parse_CreatesADynamicViewWithContainerScope.

@Test
void test_parse_CreatesADynamicViewWithContainerScope() {
    DslContext context = context();
    IdentifiersRegister elements = new IdentifiersRegister();
    Container container = model.addSoftwareSystem("Name", "Description").addContainer("Container", "Description", "Technology");
    elements.register("container", container);
    context.setIdentifierRegister(elements);
    parser.parse(context, tokens("dynamic", "container"));
    List<DynamicView> views = new ArrayList<>(this.views.getDynamicViews());
    assertEquals(1, views.size());
    assertEquals("Name-Container-Dynamic-001", views.get(0).getKey());
    assertEquals("", views.get(0).getDescription());
    assertSame(container, views.get(0).getElement());
}
Also used : Container(com.structurizr.model.Container) ArrayList(java.util.ArrayList) DynamicView(com.structurizr.view.DynamicView) Test(org.junit.jupiter.api.Test)

Example 14 with DynamicView

use of com.structurizr.view.DynamicView in project dsl by structurizr.

the class DynamicViewParserTests method test_parse_CreatesADynamicViewWithSoftwareSystemScope.

@Test
void test_parse_CreatesADynamicViewWithSoftwareSystemScope() {
    DslContext context = context();
    IdentifiersRegister elements = new IdentifiersRegister();
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Name", "Description");
    elements.register("softwaresystem", softwareSystem);
    context.setIdentifierRegister(elements);
    parser.parse(context, tokens("dynamic", "softwareSystem"));
    List<DynamicView> views = new ArrayList<>(this.views.getDynamicViews());
    assertEquals(1, views.size());
    assertEquals("Name-Dynamic-001", views.get(0).getKey());
    assertEquals("", views.get(0).getDescription());
    assertSame(softwareSystem, views.get(0).getElement());
}
Also used : ArrayList(java.util.ArrayList) SoftwareSystem(com.structurizr.model.SoftwareSystem) DynamicView(com.structurizr.view.DynamicView) Test(org.junit.jupiter.api.Test)

Example 15 with DynamicView

use of com.structurizr.view.DynamicView in project dsl by structurizr.

the class DynamicViewContentParserTests method test_parseRelationship_AddsTheRelationshipWithTheSpecifiedTechnologyToTheView_WhenItAlreadyExistsInTheModel.

@Test
void test_parseRelationship_AddsTheRelationshipWithTheSpecifiedTechnologyToTheView_WhenItAlreadyExistsInTheModel() {
    Person user = model.addPerson("User", "Description");
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
    Relationship r1 = user.uses(softwareSystem, "Uses 1", "Tech 1");
    Relationship r2 = user.uses(softwareSystem, "Uses 2", "Tech 2");
    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", "Description", "Tech 2"));
    assertEquals(1, view.getRelationships().size());
    RelationshipView rv = view.getRelationships().iterator().next();
    assertSame(r2, rv.getRelationship());
    assertSame(user, rv.getRelationship().getSource());
    assertSame(softwareSystem, rv.getRelationship().getDestination());
    assertEquals("Description", rv.getDescription());
    assertEquals("1", rv.getOrder());
}
Also used : RelationshipView(com.structurizr.view.RelationshipView) Relationship(com.structurizr.model.Relationship) SoftwareSystem(com.structurizr.model.SoftwareSystem) DynamicView(com.structurizr.view.DynamicView) Person(com.structurizr.model.Person) Test(org.junit.jupiter.api.Test)

Aggregations

DynamicView (com.structurizr.view.DynamicView)16 Test (org.junit.jupiter.api.Test)13 SoftwareSystem (com.structurizr.model.SoftwareSystem)8 ArrayList (java.util.ArrayList)6 Container (com.structurizr.model.Container)4 Person (com.structurizr.model.Person)4 RelationshipView (com.structurizr.view.RelationshipView)4 Element (com.structurizr.model.Element)2 Relationship (com.structurizr.model.Relationship)2 Workspace (com.structurizr.Workspace)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 StaticStructureElement (com.structurizr.model.StaticStructureElement)1 ComponentView (com.structurizr.view.ComponentView)1 ContainerView (com.structurizr.view.ContainerView)1 DeploymentView (com.structurizr.view.DeploymentView)1 SystemContextView (com.structurizr.view.SystemContextView)1 SystemLandscapeView (com.structurizr.view.SystemLandscapeView)1