Search in sources :

Example 1 with StaticStructureElementInstance

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

the class AbstractExpressionParser method hasAllTags.

private boolean hasAllTags(ModelItem modelItem, String[] tags) {
    boolean result = true;
    for (String tag : tags) {
        boolean hasTag = modelItem.hasTag(tag.trim());
        if (!hasTag) {
            // perhaps the tag is instead on a related model item?
            if (modelItem instanceof StaticStructureElementInstance) {
                StaticStructureElementInstance elementInstance = (StaticStructureElementInstance) modelItem;
                hasTag = elementInstance.getElement().hasTag(tag.trim());
            } else if (modelItem instanceof Relationship) {
                Relationship relationship = (Relationship) modelItem;
                if (!StringUtils.isNullOrEmpty(relationship.getLinkedRelationshipId())) {
                    Relationship linkedRelationship = relationship.getModel().getRelationship(relationship.getLinkedRelationshipId());
                    if (linkedRelationship != null) {
                        hasTag = linkedRelationship.hasTag(tag.trim());
                    }
                }
            }
        }
        result = result && hasTag;
    }
    return result;
}
Also used : StaticStructureElementInstance(com.structurizr.model.StaticStructureElementInstance) Relationship(com.structurizr.model.Relationship)

Example 2 with StaticStructureElementInstance

use of com.structurizr.model.StaticStructureElementInstance 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 3 with StaticStructureElementInstance

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

the class HealthCheckParser method parse.

void parse(StaticStructureElementInstanceDslContext context, Tokens tokens) {
    if (tokens.hasMoreThan(TIMEOUT_INDEX)) {
        throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
    }
    if (!tokens.includes(URL_INDEX)) {
        throw new RuntimeException("Expected: " + GRAMMAR);
    }
    String name = tokens.get(NAME_INDEX);
    String url = tokens.get(URL_INDEX);
    int interval = DEFAULT_INTERVAL;
    long timeout = DEFAULT_TIMEOUT;
    if (tokens.includes(INTERVAL_INDEX)) {
        try {
            interval = Integer.parseInt(tokens.get(INTERVAL_INDEX));
            if (interval < 1) {
                throw new RuntimeException("The interval must be a positive integer (number of seconds)");
            }
        } catch (NumberFormatException e) {
            throw new RuntimeException("The interval of \"" + tokens.get(INTERVAL_INDEX) + "\" is not valid - it must be a positive integer (number of seconds)");
        }
    }
    if (tokens.includes(TIMEOUT_INDEX)) {
        try {
            timeout = Integer.parseInt(tokens.get(TIMEOUT_INDEX));
            if (timeout < 0) {
                throw new RuntimeException("The timeout must be zero or a positive integer (number of milliseconds)");
            }
        } catch (NumberFormatException e) {
            throw new RuntimeException("The timeout of \"" + tokens.get(TIMEOUT_INDEX) + "\" is not valid - it must be zero or a positive integer (number of milliseconds)");
        }
    }
    StaticStructureElementInstance elementInstance = context.getElementInstance();
    elementInstance.addHealthCheck(name, url, interval, timeout);
}
Also used : StaticStructureElementInstance(com.structurizr.model.StaticStructureElementInstance)

Aggregations

StaticStructureElementInstance (com.structurizr.model.StaticStructureElementInstance)3 Element (com.structurizr.model.Element)1 InfrastructureNode (com.structurizr.model.InfrastructureNode)1 Relationship (com.structurizr.model.Relationship)1 ArrayList (java.util.ArrayList)1