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;
}
}
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;
}
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]));
}
}
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;
}
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);
}
Aggregations