Search in sources :

Example 1 with SoftwareSystem

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;
}
Also used : Container(com.structurizr.model.Container) DecimalFormat(java.text.DecimalFormat) Element(com.structurizr.model.Element) SoftwareSystem(com.structurizr.model.SoftwareSystem) DynamicView(com.structurizr.view.DynamicView) Workspace(com.structurizr.Workspace)

Example 2 with SoftwareSystem

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

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

Example 4 with SoftwareSystem

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

Example 5 with SoftwareSystem

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

Aggregations

SoftwareSystem (com.structurizr.model.SoftwareSystem)69 Test (org.junit.jupiter.api.Test)38 Container (com.structurizr.model.Container)23 Workspace (com.structurizr.Workspace)22 Test (org.junit.Test)17 Person (com.structurizr.model.Person)9 Component (com.structurizr.model.Component)8 DynamicView (com.structurizr.view.DynamicView)8 ArrayList (java.util.ArrayList)8 Model (com.structurizr.model.Model)7 DeploymentView (com.structurizr.view.DeploymentView)6 SystemContextView (com.structurizr.view.SystemContextView)6 ViewSet (com.structurizr.view.ViewSet)5 Element (com.structurizr.model.Element)4 Relationship (com.structurizr.model.Relationship)4 ContainerView (com.structurizr.view.ContainerView)4 RelationshipView (com.structurizr.view.RelationshipView)4 DeploymentNode (com.structurizr.model.DeploymentNode)3 ComponentView (com.structurizr.view.ComponentView)3 EncryptedWorkspace (com.structurizr.encryption.EncryptedWorkspace)2