Search in sources :

Example 6 with Element

use of com.structurizr.model.Element in project dsl by structurizr.

the class AbstractExpressionParser method parseIdentifier.

protected Set<ModelItem> parseIdentifier(String identifier, DslContext context) {
    Set<ModelItem> modelItems = new LinkedHashSet<>();
    Element element = context.getElement(identifier);
    if (element != null) {
        modelItems.addAll(getElements(identifier, context));
    }
    Relationship relationship = context.getRelationship(identifier);
    if (relationship != null) {
        modelItems.add(relationship);
    }
    if (modelItems.isEmpty()) {
        throw new RuntimeException("The element/relationship \"" + identifier + "\" does not exist");
    } else {
        return modelItems;
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Element(com.structurizr.model.Element) Relationship(com.structurizr.model.Relationship) ModelItem(com.structurizr.model.ModelItem)

Example 7 with Element

use of com.structurizr.model.Element 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 8 with Element

use of com.structurizr.model.Element in project dsl by structurizr.

the class DeploymentViewAnimationStepParser method parse.

void parse(DslContext context, DeploymentView view, Tokens tokens, int startIndex) {
    List<StaticStructureElementInstance> staticStructureElementInstances = new ArrayList<>();
    List<InfrastructureNode> infrastructureNodes = new ArrayList<>();
    for (int i = startIndex; i < tokens.size(); i++) {
        String identifier = tokens.get(i);
        Element element = context.getElement(identifier);
        if (element == null) {
            throw new RuntimeException("The element \"" + identifier + "\" does not exist");
        }
        if (element instanceof StaticStructureElementInstance) {
            staticStructureElementInstances.add((StaticStructureElementInstance) element);
        }
        if (element instanceof InfrastructureNode) {
            infrastructureNodes.add((InfrastructureNode) element);
        }
    }
    if (!(staticStructureElementInstances.isEmpty() && infrastructureNodes.isEmpty())) {
        view.addAnimation(staticStructureElementInstances.toArray(new StaticStructureElementInstance[0]), infrastructureNodes.toArray(new InfrastructureNode[0]));
    }
}
Also used : StaticStructureElementInstance(com.structurizr.model.StaticStructureElementInstance) Element(com.structurizr.model.Element) ArrayList(java.util.ArrayList) InfrastructureNode(com.structurizr.model.InfrastructureNode)

Example 9 with Element

use of com.structurizr.model.Element in project dsl by structurizr.

the class ComponentViewParser method parse.

ComponentView parse(DslContext context, Tokens tokens) {
    if (tokens.hasMoreThan(DESCRIPTION_INDEX)) {
        throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
    }
    if (!tokens.includes(CONTAINER_IDENTIFIER_INDEX)) {
        throw new RuntimeException("Expected: " + GRAMMAR);
    }
    Workspace workspace = context.getWorkspace();
    Container container;
    String key = "";
    String description = "";
    String containerIdentifier = tokens.get(CONTAINER_IDENTIFIER_INDEX);
    Element element = context.getElement(containerIdentifier);
    if (element == null) {
        throw new RuntimeException("The container \"" + containerIdentifier + "\" does not exist");
    }
    if (element instanceof Container) {
        container = (Container) element;
    } else {
        throw new RuntimeException("The element \"" + containerIdentifier + "\" is not a container");
    }
    if (tokens.includes(KEY_INDEX)) {
        key = tokens.get(KEY_INDEX);
    } else {
        key = removeNonWordCharacters(container.getSoftwareSystem().getName()) + "-" + removeNonWordCharacters(container.getName()) + "-" + VIEW_TYPE;
    }
    validateViewKey(key);
    if (tokens.includes(DESCRIPTION_INDEX)) {
        description = tokens.get(DESCRIPTION_INDEX);
    }
    ComponentView view = workspace.getViews().createComponentView(container, key, description);
    view.setExternalSoftwareSystemBoundariesVisible(true);
    return view;
}
Also used : Container(com.structurizr.model.Container) ComponentView(com.structurizr.view.ComponentView) Element(com.structurizr.model.Element) Workspace(com.structurizr.Workspace)

Example 10 with Element

use of com.structurizr.model.Element in project java by structurizr.

the class ElementViewTests method test_copyLayoutInformationFrom_DoesNothing_WhenNullIsPassed.

@Test
public void test_copyLayoutInformationFrom_DoesNothing_WhenNullIsPassed() {
    Element element = model.addSoftwareSystem(Location.External, "SystemA", "");
    ElementView elementView = new ElementView(element);
    elementView.copyLayoutInformationFrom(null);
}
Also used : Element(com.structurizr.model.Element) Test(org.junit.Test)

Aggregations

Element (com.structurizr.model.Element)27 SoftwareSystem (com.structurizr.model.SoftwareSystem)8 Workspace (com.structurizr.Workspace)7 Relationship (com.structurizr.model.Relationship)7 Collectors (java.util.stream.Collectors)7 Container (com.structurizr.model.Container)6 File (java.io.File)6 IOException (java.io.IOException)6 StaticStructureElement (com.structurizr.model.StaticStructureElement)5 ArrayList (java.util.ArrayList)5 LinkedHashSet (java.util.LinkedHashSet)5 Map (java.util.Map)5 Inject (javax.inject.Inject)5 OutputBuilder (org.ndx.agile.architecture.base.OutputBuilder)5 Component (com.structurizr.model.Component)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 Optional (java.util.Optional)4 Set (java.util.Set)4 Logger (java.util.logging.Logger)4