Search in sources :

Example 1 with Element

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

the class StaticViewAnimationStepParser method parse.

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

Example 2 with Element

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

the class DynamicViewContentParser method parseRelationship.

void parseRelationship(DynamicViewDslContext context, Tokens tokens) {
    // <identifier> -> <identifier> [description] [technology]
    DynamicView view = context.getView();
    if (tokens.hasMoreThan(TECHNOLOGY_INDEX)) {
        throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
    }
    if (!tokens.includes(DESTINATION_IDENTIFIER_INDEX)) {
        throw new RuntimeException("Expected: " + GRAMMAR);
    }
    String sourceId = tokens.get(SOURCE_IDENTIFIER_INDEX);
    String destinationId = tokens.get(DESTINATION_IDENTIFIER_INDEX);
    Element sourceElement = context.getElement(sourceId);
    if (sourceElement == null) {
        throw new RuntimeException("The source element \"" + sourceId + "\" does not exist");
    }
    if (!(sourceElement instanceof StaticStructureElement)) {
        throw new RuntimeException("The source element \"" + sourceId + "\" should be a static structure element");
    }
    Element destinationElement = context.getElement(destinationId);
    if (destinationElement == null) {
        throw new RuntimeException("The destination element \"" + destinationId + "\" does not exist");
    }
    if (!(destinationElement instanceof StaticStructureElement)) {
        throw new RuntimeException("The destination element \"" + destinationId + "\" should be a static structure element");
    }
    String description = "";
    if (tokens.includes(DESCRIPTION_INDEX)) {
        description = tokens.get(DESCRIPTION_INDEX);
    }
    String technology = "";
    if (tokens.includes(TECHNOLOGY_INDEX)) {
        technology = tokens.get(TECHNOLOGY_INDEX);
    }
    if (!sourceElement.hasEfferentRelationshipWith(destinationElement) && !destinationElement.hasEfferentRelationshipWith(sourceElement)) {
        new ExplicitRelationshipParser().parse(context, tokens);
    }
    view.add((StaticStructureElement) sourceElement, description, technology, (StaticStructureElement) destinationElement);
}
Also used : StaticStructureElement(com.structurizr.model.StaticStructureElement) StaticStructureElement(com.structurizr.model.StaticStructureElement) Element(com.structurizr.model.Element) DynamicView(com.structurizr.view.DynamicView)

Example 3 with Element

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

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

the class IdentifiersRegister method register.

void register(String identifier, Relationship relationship) {
    if (StringUtils.isNullOrEmpty(identifier)) {
        identifier = UUID.randomUUID().toString();
    }
    identifier = identifier.toLowerCase();
    Element e = elementsByIdentifier.get(identifier);
    Relationship r = relationshipsByIdentifier.get(identifier);
    if ((e == null && r == null) || (r == relationship)) {
        relationshipsByIdentifier.put(identifier, relationship);
    } else {
        throw new RuntimeException("The identifier \"" + identifier + "\" is already in use");
    }
}
Also used : Element(com.structurizr.model.Element) Relationship(com.structurizr.model.Relationship)

Example 5 with Element

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

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