Search in sources :

Example 6 with Relationship

use of com.structurizr.model.Relationship in project java by structurizr.

the class ThemeUtilsTests method test_findRelationshipStyle_WithThemes.

@Test
public void test_findRelationshipStyle_WithThemes() {
    Workspace workspace = new Workspace("Name", "Description");
    SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Name");
    Relationship relationship = softwareSystem.uses(softwareSystem, "Uses");
    workspace.getViews().getConfiguration().getStyles().addRelationshipStyle("Relationship").dashed(false);
    // theme 1
    Collection<ElementStyle> elementStyles = new ArrayList<>();
    Collection<RelationshipStyle> relationshipStyles = new ArrayList<>();
    relationshipStyles.add(new RelationshipStyle("Relationship").color("#ff0000").thickness(4));
    workspace.getViews().getConfiguration().getStyles().addStylesFromTheme("url1", elementStyles, relationshipStyles);
    // theme 2
    elementStyles = new ArrayList<>();
    relationshipStyles = new ArrayList<>();
    relationshipStyles.add(new RelationshipStyle("Relationship").color("#0000ff"));
    workspace.getViews().getConfiguration().getStyles().addStylesFromTheme("url2", elementStyles, relationshipStyles);
    RelationshipStyle style = workspace.getViews().getConfiguration().getStyles().findRelationshipStyle(relationship);
    // from theme 1
    assertEquals(new Integer(4), style.getThickness());
    // from theme 2
    assertEquals("#0000ff", style.getColor());
    // from workspace
    Assert.assertFalse(style.getDashed());
    assertEquals(Routing.Direct, style.getRouting());
    assertEquals(new Integer(24), style.getFontSize());
    assertEquals(new Integer(200), style.getWidth());
    assertEquals(new Integer(50), style.getPosition());
    assertEquals(new Integer(100), style.getOpacity());
}
Also used : Relationship(com.structurizr.model.Relationship) ArrayList(java.util.ArrayList) SoftwareSystem(com.structurizr.model.SoftwareSystem) Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 7 with Relationship

use of com.structurizr.model.Relationship in project java by structurizr.

the class CustomView method addAnimation.

/**
 * Adds an animation step, with the specified elements.
 *
 * @param elements      the elements that should be shown in the animation step
 */
public void addAnimation(CustomElement... 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 (CustomElement 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));
}
Also used : CustomElement(com.structurizr.model.CustomElement) Element(com.structurizr.model.Element) Relationship(com.structurizr.model.Relationship) CustomElement(com.structurizr.model.CustomElement) HashSet(java.util.HashSet)

Example 8 with Relationship

use of com.structurizr.model.Relationship in project java by structurizr.

the class StaticViewTests method test_addAnimationStep.

@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()));
}
Also used : Relationship(com.structurizr.model.Relationship) SoftwareSystem(com.structurizr.model.SoftwareSystem) Test(org.junit.Test)

Example 9 with Relationship

use of com.structurizr.model.Relationship in project archifacts by archifacts.

the class C4ModelBuilderTest method assert_that_computation_rule_is_applied_to_relationship.

@Test
void assert_that_computation_rule_is_applied_to_relationship() {
    final JavaClasses javaClasses = new ClassFileImporter().importPackages("org.archifacts.integration.c4.model.domain");
    final Application application = Application.builder().descriptor(buildingBlockType1Descriptor).descriptor(defaultContainerDescriptor).descriptor(referenceDescriptor).buildApplication(javaClasses);
    final C4ModelBuilder c4ModelBuilder = C4Model.builder(new Workspace(this.getClass().getSimpleName(), null));
    application.getArtifacts().stream().forEach(c4ModelBuilder::artifact);
    application.getRelationships().stream().forEach(c4ModelBuilder::relationship);
    final BuildingBlock source = application.getBuildingBlocksOfType(buildingBlockType1).iterator().next();
    final Artifact target = application.getArtifacts().stream().filter(MiscArtifact.class::isInstance).findFirst().get();
    c4ModelBuilder.relartionshipRule().predicate(a -> true).computation((relationship, lookup) -> Set.of(lookup.component(source).uses(lookup.component(target), "uses"), lookup.component(target).uses(lookup.component(source), "is used by")));
    final C4Model c4Model = c4ModelBuilder.build();
    final Set<Container> containers = c4Model.softwareSystem().getContainers();
    assertThat(containers).hasSize(1).extracting(Container::getName, Container::getTechnology).containsExactly(tuple("DefaultContainer", "ContainerType1"));
    final Container container = containers.iterator().next();
    final Component class1ForBuildingBlockType1 = container.getComponentWithName("Class1ForBuildingBlockType1");
    assertThat(class1ForBuildingBlockType1).isNotNull();
    final Component miscArtifact1 = container.getComponentWithName("MiscArtifact1");
    assertThat(miscArtifact1).isNotNull();
    assertThat(container.getComponents()).flatMap(Component::getRelationships).hasSize(2).extracting(Relationship::getDescription, Relationship::getSource, Relationship::getDestination).containsExactlyInAnyOrder(tuple("uses", class1ForBuildingBlockType1, miscArtifact1), tuple("is used by", miscArtifact1, class1ForBuildingBlockType1));
}
Also used : ArtifactContainer(org.archifacts.core.model.ArtifactContainer) ArtifactContainerType(org.archifacts.core.model.ArtifactContainerType) ReplaceUnderscores(org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArtifactContainerDescriptor(org.archifacts.core.descriptor.ArtifactContainerDescriptor) Component(com.structurizr.model.Component) JavaField(com.tngtech.archunit.core.domain.JavaField) Assertions.assertThatNoException(org.assertj.core.api.Assertions.assertThatNoException) JavaClass(com.tngtech.archunit.core.domain.JavaClass) Artifact(org.archifacts.core.model.Artifact) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) SourceBasedArtifactRelationshipDescriptor(org.archifacts.core.descriptor.SourceBasedArtifactRelationshipDescriptor) Container(com.structurizr.model.Container) MiscArtifact(org.archifacts.core.model.MiscArtifact) Assertions.tuple(org.assertj.core.api.Assertions.tuple) DisplayNameGeneration(org.junit.jupiter.api.DisplayNameGeneration) Set(java.util.Set) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test) Application(org.archifacts.core.model.Application) Stream(java.util.stream.Stream) ArtifactRelationshipRole(org.archifacts.core.model.ArtifactRelationshipRole) Relationship(com.structurizr.model.Relationship) BuildingBlockDescriptor(org.archifacts.core.descriptor.BuildingBlockDescriptor) BuildingBlock(org.archifacts.core.model.BuildingBlock) Optional(java.util.Optional) BuildingBlockType(org.archifacts.core.model.BuildingBlockType) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) BuildingBlock(org.archifacts.core.model.BuildingBlock) Artifact(org.archifacts.core.model.Artifact) MiscArtifact(org.archifacts.core.model.MiscArtifact) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) ArtifactContainer(org.archifacts.core.model.ArtifactContainer) Container(com.structurizr.model.Container) MiscArtifact(org.archifacts.core.model.MiscArtifact) Component(com.structurizr.model.Component) Application(org.archifacts.core.model.Application) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test)

Example 10 with Relationship

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

the class IdentifiersRegister method register.

void register(String identifier, Element element) {
    if (StringUtils.isNullOrEmpty(identifier)) {
        identifier = UUID.randomUUID().toString();
    }
    identifier = identifier.toLowerCase();
    if (identifierScope == IdentifierScope.Hierarchical) {
        identifier = calculateHierarchicalIdentifier(identifier, element);
    }
    // check whether this element has already been registered with another identifier
    for (String id : elementsByIdentifier.keySet()) {
        Element e = elementsByIdentifier.get(id);
        if (e.equals(element) && !id.equals(identifier)) {
            if (id.matches("[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}")) {
                throw new RuntimeException("Please assign an identifier to \"" + element.getCanonicalName() + "\" before using it with !ref");
            } else {
                throw new RuntimeException("The element is already registered with an identifier of \"" + id + "\"");
            }
        }
    }
    Element e = elementsByIdentifier.get(identifier);
    Relationship r = relationshipsByIdentifier.get(identifier);
    if ((e == null && r == null) || (e == element)) {
        elementsByIdentifier.put(identifier, element);
    } else {
        throw new RuntimeException("The identifier \"" + identifier + "\" is already in use");
    }
}
Also used : Element(com.structurizr.model.Element) Relationship(com.structurizr.model.Relationship)

Aggregations

Relationship (com.structurizr.model.Relationship)15 Element (com.structurizr.model.Element)8 SoftwareSystem (com.structurizr.model.SoftwareSystem)6 Workspace (com.structurizr.Workspace)4 RelationshipView (com.structurizr.view.RelationshipView)4 Component (com.structurizr.model.Component)3 Container (com.structurizr.model.Container)3 JavaClass (com.tngtech.archunit.core.domain.JavaClass)3 HashSet (java.util.HashSet)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3 Test (org.junit.jupiter.api.Test)3 Diagram (com.structurizr.io.Diagram)2 BasicPlantUMLWriter (com.structurizr.io.plantuml.BasicPlantUMLWriter)2 C4PlantUMLExporter (com.structurizr.io.plantuml.C4PlantUMLExporter)2 PlantUMLWriter (com.structurizr.io.plantuml.PlantUMLWriter)2 Model (com.structurizr.model.Model)2 ModelItem (com.structurizr.model.ModelItem)2 Person (com.structurizr.model.Person)2 Tags (com.structurizr.model.Tags)2