com.structurizr.model.Relationship Java Examples

The following examples show how to use com.structurizr.model.Relationship. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StaticView.java    From java with Apache License 2.0 6 votes vote down vote up
protected <T extends Element> void addNearestNeighbours(Element element, Class<T> typeOfElement) {
    if (element == null) {
        return;
    }

    addElement(element, true);

    Set<Relationship> relationships = getModel().getRelationships();
    relationships.stream().filter(r -> r.getSource().equals(element) && typeOfElement.isInstance(r.getDestination()))
            .map(Relationship::getDestination)
            .forEach(d -> addElement(d, true));

    relationships.stream().filter(r -> r.getDestination().equals(element) && typeOfElement.isInstance(r.getSource()))
            .map(Relationship::getSource)
            .forEach(s -> addElement(s, true));
}
 
Example #2
Source File: View.java    From java with Apache License 2.0 6 votes vote down vote up
private void addRelationships(Element element) {
    Set<Element> elements = getElements().stream()
            .map(ElementView::getElement)
            .collect(Collectors.toSet());

    // add relationships where the destination exists in the view already
    for (Relationship relationship : element.getRelationships()) {
        if (elements.contains(relationship.getDestination())) {
            this.relationshipViews.add(new RelationshipView(relationship));
        }
    }

    // add relationships where the source exists in the view already
    for (Element e : elements) {
        for (Relationship r : e.getRelationships()) {
            if (r.getDestination().equals(element)) {
                this.relationshipViews.add(new RelationshipView(r));
            }
        }
    }
}
 
Example #3
Source File: View.java    From java with Apache License 2.0 5 votes vote down vote up
protected RelationshipView addRelationship(Relationship relationship, String description, String order) {
    RelationshipView relationshipView = addRelationship(relationship);
    if (relationshipView != null) {
        relationshipView.setDescription(description);
        relationshipView.setOrder(order);
    }

    return relationshipView;
}
 
Example #4
Source File: StyleTests.java    From java with Apache License 2.0 5 votes vote down vote up
@Test
public void test_findRelationshipStyle_ReturnsTheCorrectStyle_WhenStylesAreDefined() {
    SoftwareSystem element = model.addSoftwareSystem("Name", "Description");
    Relationship relationship = element.uses(element, "Uses");
    relationship.addTags("Some Tag");

    styles.addRelationshipStyle(Tags.RELATIONSHIP).color("#ff0000");
    styles.addRelationshipStyle("Some Tag").color("#0000ff");

    RelationshipStyle style = styles.findRelationshipStyle(relationship);
    assertEquals("#0000ff", style.getColor());
}
 
Example #5
Source File: StyleTests.java    From java with Apache License 2.0 5 votes vote down vote up
@Test
public void test_findRelationshipStyle_ReturnsTheDefaultStyle_WhenNoStylesAreDefined() {
    SoftwareSystem element = model.addSoftwareSystem("Name", "Description");
    Relationship relationship = element.uses(element, "Uses");
    RelationshipStyle style = styles.findRelationshipStyle(relationship);
    assertEquals("#707070", style.getColor());
}
 
Example #6
Source File: StaticViewTests.java    From java with Apache License 2.0 5 votes vote down vote up
@Test
public void test_addAnimationStep() {
    SoftwareSystem element1 = model.addSoftwareSystem("Software System 1", "");
    SoftwareSystem element2 = model.addSoftwareSystem("Software System 2", "");
    SoftwareSystem element3 = model.addSoftwareSystem("Software System 3", "");

    Relationship relationship1_2 = element1.uses(element2, "uses");
    Relationship relationship2_3 = element2.uses(element3, "uses");

    SystemLandscapeView view = workspace.getViews().createSystemLandscapeView("key", "Description");
    view.addAllElements();

    view.addAnimation(element1);
    view.addAnimation(element2);
    view.addAnimation(element3);

    Animation step1 = view.getAnimations().stream().filter(step -> step.getOrder() == 1).findFirst().get();
    assertEquals(1, step1.getElements().size());
    assertTrue(step1.getElements().contains(element1.getId()));
    assertEquals(0, step1.getRelationships().size());

    Animation step2 = view.getAnimations().stream().filter(step -> step.getOrder() == 2).findFirst().get();
    assertEquals(1, step2.getElements().size());
    assertTrue(step2.getElements().contains(element2.getId()));
    assertEquals(1, step2.getRelationships().size());
    assertTrue(step2.getRelationships().contains(relationship1_2.getId()));

    Animation step3 = view.getAnimations().stream().filter(step -> step.getOrder() == 3).findFirst().get();
    assertEquals(1, step3.getElements().size());
    assertTrue(step3.getElements().contains(element3.getId()));
    assertEquals(1, step3.getRelationships().size());
    assertTrue(step3.getRelationships().contains(relationship2_3.getId()));
}
 
Example #7
Source File: DefaultLayoutMergeStrategy.java    From java with Apache License 2.0 5 votes vote down vote up
protected RelationshipView findRelationshipView(View view, Relationship relationship) {
    for (RelationshipView rv : view.getRelationships()) {
        if (
            rv.getRelationship().getSource().getCanonicalName().equals(relationship.getSource().getCanonicalName()) &&
            rv.getRelationship().getDestination().getCanonicalName().equals(relationship.getDestination().getCanonicalName()) &&
            rv.getRelationship().getDescription().equals(relationship.getDescription())
        ) {
            return rv;
        }
    }

    return null;
}
 
Example #8
Source File: StaticView.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * Adds an animation step, with the specified elements.
 *
 * @param elements      the elements that should be shown in the animation step
 */
public void addAnimation(Element... elements) {
    if (elements == null || elements.length == 0) {
        throw new IllegalArgumentException("One or more elements must be specified.");
    }

    Set<String> elementIdsInPreviousAnimationSteps = new HashSet<>();

    for (Animation animationStep : animations) {
        elementIdsInPreviousAnimationSteps.addAll(animationStep.getElements());
    }

    Set<Element> elementsInThisAnimationStep = new HashSet<>();
    Set<Relationship> relationshipsInThisAnimationStep = new HashSet<>();

    for (Element element : elements) {
        if (isElementInView(element)) {
            if (!elementIdsInPreviousAnimationSteps.contains(element.getId())) {
                elementIdsInPreviousAnimationSteps.add(element.getId());
                elementsInThisAnimationStep.add(element);
            }
        }
    }

    if (elementsInThisAnimationStep.size() == 0) {
        throw new IllegalArgumentException("None of the specified elements exist in this view.");
    }

    for (RelationshipView relationshipView : this.getRelationships()) {
        if (
                (elementsInThisAnimationStep.contains(relationshipView.getRelationship().getSource()) && elementIdsInPreviousAnimationSteps.contains(relationshipView.getRelationship().getDestination().getId())) ||
                (elementIdsInPreviousAnimationSteps.contains(relationshipView.getRelationship().getSource().getId()) && elementsInThisAnimationStep.contains(relationshipView.getRelationship().getDestination()))
           ) {
            relationshipsInThisAnimationStep.add(relationshipView.getRelationship());
        }
    }

    animations.add(new Animation(animations.size() + 1, elementsInThisAnimationStep, relationshipsInThisAnimationStep));
}
 
Example #9
Source File: View.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * Removes a relationship from this view.
 *
 * @param relationship      the Relationship to remove
 */
public void remove(Relationship relationship) {
    if (relationship != null) {
        RelationshipView relationshipView = new RelationshipView(relationship);
        relationshipViews.remove(relationshipView);
    }
}
 
Example #10
Source File: Documenter.java    From moduliths with Apache License 2.0 5 votes vote down vote up
private void potentiallyRemoveDefaultRelationship(View view, Collection<Relationship> relationships) {

		if (relationships.size() <= 1) {
			return;
		}

		relationships.stream().filter(it -> it.getTagsAsSet().contains(DependencyType.DEFAULT.toString())) //
				.findFirst().ifPresent(view::remove);
	}
 
Example #11
Source File: View.java    From java with Apache License 2.0 5 votes vote down vote up
protected RelationshipView addRelationship(Relationship relationship) {
    if (relationship == null) {
        throw new IllegalArgumentException("A relationship must be specified.");
    }

    if (isElementInView(relationship.getSource()) && isElementInView(relationship.getDestination())) {
        RelationshipView relationshipView = new RelationshipView(relationship);
        relationshipViews.add(relationshipView);

        return relationshipView;
    }

    return null;
}
 
Example #12
Source File: Animation.java    From java with Apache License 2.0 5 votes vote down vote up
Animation(int order, Set<Element> elements, Set<Relationship> relationships) {
    this.order = order;

    for (Element element : elements) {
        this.elements.add(element.getId());
    }

    for (Relationship relationship : relationships) {
        this.relationships.add(relationship.getId());
    }
}
 
Example #13
Source File: StructurizrService.java    From structurizr-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    List<ModelPostProcessor> postProcessors = event.getApplicationContext()
            .getBeansOfType(ModelPostProcessor.class).values().stream().collect(Collectors.toList());

    AnnotationAwareOrderComparator.sort(postProcessors);

    for (ModelPostProcessor postProcessor : postProcessors) {
        postProcessor.postProcess(workspace.getModel());
    }

    if (properties.isAddImplicitRelationships()) {
        final Set<Relationship> relationships = workspace.getModel().addImplicitRelationships();
        LOG.info("Added {} implicit relationships.", relationships.size());
    }

    event.getApplicationContext()
            .getBeansOfType(ViewProvider.class)
            .values().stream()
            .forEach(vp -> vp.createViews(workspace.getViews()));


    if (properties.isPerformMerge()) {
        try {
            structurizrClient.putWorkspace(properties.getWorkspace().getId(), workspace);
        } catch (StructurizrClientException e) {
            LOG.error("Could not put workspace.", e);
            throw new RuntimeException(e);
        }
    }
}
 
Example #14
Source File: Styles.java    From java with Apache License 2.0 4 votes vote down vote up
public RelationshipStyle findRelationshipStyle(Relationship relationship) {
    RelationshipStyle style = new RelationshipStyle("").color("#707070");

    if (relationship != null) {
        for (String tag : relationship.getTagsAsSet()) {
            RelationshipStyle relationshipStyle = findRelationshipStyle(tag);
            if (relationshipStyle != null) {
                if (relationshipStyle.getThickness() != null) {
                    style.setThickness(relationshipStyle.getThickness());
                }

                if (!StringUtils.isNullOrEmpty(relationshipStyle.getColor())) {
                    style.setColor(relationshipStyle.getColor());
                }

                if (relationshipStyle.getDashed() != null) {
                    style.setDashed(relationshipStyle.getDashed());
                }

                if (relationshipStyle.getRouting() != null) {
                    style.setRouting(relationshipStyle.getRouting());
                }

                if (relationshipStyle.getFontSize() != null) {
                    style.setFontSize(relationshipStyle.getFontSize());
                }

                if (relationshipStyle.getWidth() != null) {
                    style.setWidth(relationshipStyle.getWidth());
                }

                if (relationshipStyle.getPosition() != null) {
                    style.setPosition(relationshipStyle.getPosition());
                }

                if (relationshipStyle.getOpacity() != null) {
                    style.setOpacity(relationshipStyle.getOpacity());
                }
            }
        }
    }

    return style;
}
 
Example #15
Source File: RelationshipView.java    From java with Apache License 2.0 4 votes vote down vote up
void setRelationship(Relationship relationship) {
    this.relationship = relationship;
}
 
Example #16
Source File: RelationshipView.java    From java with Apache License 2.0 4 votes vote down vote up
RelationshipView(Relationship relationship) {
    this.relationship = relationship;
}
 
Example #17
Source File: Documenter.java    From moduliths with Apache License 2.0 4 votes vote down vote up
public static Connection of(Relationship relationship) {
	return new Connection(relationship.getSource(), relationship.getDestination());
}
 
Example #18
Source File: View.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the relationship view for the given relationship.
 *
 * @param relationship  the Relationship to find the RelationshipView for
 * @return  an RelationshipView object, or null if the relationship doesn't exist in the view
 */
public RelationshipView getRelationshipView(@Nonnull Relationship relationship) {
    Optional<RelationshipView> relationshipView = this.relationshipViews.stream().filter(rv -> rv.getId().equals(relationship.getId())).findFirst();
    return relationshipView.orElse(null);
}
 
Example #19
Source File: StaticView.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Adds a specific relationship to this view.
 *
 * @param relationship  the Relationship to be added
 * @return  a RelationshipView object representing the relationship added
 */
public RelationshipView add(@Nonnull Relationship relationship) {
    return addRelationship(relationship);
}
 
Example #20
Source File: RelationshipView.java    From java with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the relationship that this RelationshipView represents.
 *
 * @return  a Relationship instance
 */
@JsonIgnore
public Relationship getRelationship() {
    return relationship;
}