/** * Adds an individual container to this view. * * @param container the Container to add * @param addRelationships whether to add relationships to/from the container */ public void add(Container container, boolean addRelationships) { if (container != null && !container.equals(getContainer())) { addElement(container, addRelationships); } }
/** * Gets the (computed) name of this view. * * @return the name, as a String */ @Override public String getName() { return getSoftwareSystem().getName() + " - " + getContainer().getName() + " - Components"; }
protected void write(ComponentView view, Writer writer) { try { writeHeader(view, writer); view.getElements().stream() .filter(ev -> !(ev.getElement() instanceof Component)) .map(ElementView::getElement) .sorted((e1, e2) -> e1.getName().compareTo(e2.getName())) .forEach(e -> write(view, e, writer, false)); writer.write("package \"" + view.getContainer().getName() + "\" <<" + typeOf(view.getContainer()) + ">> {"); writer.write(System.lineSeparator()); view.getElements().stream() .filter(ev -> ev.getElement() instanceof Component) .map(ElementView::getElement) .sorted((e1, e2) -> e1.getName().compareTo(e2.getName())) .forEach(e -> write(view, e, writer, true)); writer.write("}"); writer.write(System.lineSeparator()); writeRelationships(view, writer); writeFooter(writer); } catch (IOException e) { e.printStackTrace(); } }
/** * Adds an individual component to this view. * * @param component the Component to add * @param addRelationships whether to add relationships to/from the component */ public void add(Component component, boolean addRelationships) { if (component != null) { if (!component.getContainer().equals(getContainer())) { throw new IllegalArgumentException("Only components belonging to " + container.getName() + " can be added to this view."); } addElement(component, addRelationships); } }
for (Relationship relationship : getContainer().getModel().getRelationships()) { if (components.contains(relationship.getSource())) { addExternalDependency(relationship.getDestination(), components);
/** * Writes the views in the given workspace as DOT notation, to the specified Writer. * * @param workspace the workspace containing the views to be written * @param writer the Writer to write to */ public void write(Workspace workspace, Writer writer) { workspace.getViews().getSystemContextViews().forEach(v -> write(v, null, writer)); workspace.getViews().getContainerViews().forEach(v -> write(v, v.getSoftwareSystem(), writer)); workspace.getViews().getComponentViews().forEach(v -> write(v, v.getContainer(), writer)); }
private void addExternalDependency(Element element, Set<Element> components) { if (element instanceof Component) { if (element.getParent().equals(getContainer())) { // the component is in the same container, so we'll ignore it since we're only interested in external dependencies return; } else { // the component is in a different container, so let's try to add that instead element = element.getParent(); } } if (element instanceof Container) { if (element.getParent().equals(this.getContainer().getParent())) { // the container is in the same software system addElement(element, true); return; } else { // the container is in a different software system, so add that instead element = element.getParent(); } } if (element instanceof SoftwareSystem || element instanceof Person) { addElement(element, true); } }
@Test public void test_createComponentView() { Workspace workspace = new Workspace("Name", "Description"); SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Software System", "Description"); Container container = softwareSystem.addContainer("Container", "Description", "Technology"); ComponentView componentView = workspace.getViews().createComponentView(container, "key", "Description"); assertEquals("key", componentView.getKey()); assertEquals("Description", componentView.getDescription()); assertSame(softwareSystem, componentView.getSoftwareSystem()); assertSame(container, componentView.getContainer()); }
assertSame(views, componentView.getViewSet()); assertSame(softwareSystem, componentView.getSoftwareSystem()); assertSame(container, componentView.getContainer()); assertSame(component, componentView.getElementView(component).getElement());