Search in sources :

Example 1 with Relationship

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

the class IdentifiersRegister method register.

void register(String identifier, Relationship relationship) {
    if (StringUtils.isNullOrEmpty(identifier)) {
        identifier = UUID.randomUUID().toString();
    }
    identifier = identifier.toLowerCase();
    Element e = elementsByIdentifier.get(identifier);
    Relationship r = relationshipsByIdentifier.get(identifier);
    if ((e == null && r == null) || (r == relationship)) {
        relationshipsByIdentifier.put(identifier, relationship);
    } else {
        throw new RuntimeException("The identifier \"" + identifier + "\" is already in use");
    }
}
Also used : Element(com.structurizr.model.Element) Relationship(com.structurizr.model.Relationship)

Example 2 with Relationship

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

the class DynamicViewContentParserTests method test_parseRelationship_AddsTheRelationshipToTheModelAndView_WhenItDoesNotAlreadyExistInTheModel.

@Test
void test_parseRelationship_AddsTheRelationshipToTheModelAndView_WhenItDoesNotAlreadyExistInTheModel() {
    Person user = model.addPerson("User", "Description");
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
    DynamicView view = views.createDynamicView("key", "Description");
    DynamicViewDslContext context = new DynamicViewDslContext(view);
    IdentifiersRegister elements = new IdentifiersRegister();
    elements.register("source", user);
    elements.register("destination", softwareSystem);
    context.setIdentifierRegister(elements);
    assertEquals(0, model.getRelationships().size());
    parser.parseRelationship(context, tokens("source", "->", "destination", "Uses"));
    assertEquals(1, model.getRelationships().size());
    Relationship r = model.getRelationships().iterator().next();
    assertSame(user, r.getSource());
    assertSame(softwareSystem, r.getDestination());
    assertEquals("Uses", r.getDescription());
    assertEquals(1, view.getRelationships().size());
    RelationshipView rv = view.getRelationships().iterator().next();
    assertSame(user, rv.getRelationship().getSource());
    assertSame(softwareSystem, rv.getRelationship().getDestination());
    assertEquals("Uses", rv.getDescription());
    assertEquals("1", rv.getOrder());
}
Also used : RelationshipView(com.structurizr.view.RelationshipView) Relationship(com.structurizr.model.Relationship) SoftwareSystem(com.structurizr.model.SoftwareSystem) DynamicView(com.structurizr.view.DynamicView) Person(com.structurizr.model.Person) Test(org.junit.jupiter.api.Test)

Example 3 with Relationship

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

the class RefParserTests method test_parse_FindsARelationshipByIdentifier.

@Test
void test_parse_FindsARelationshipByIdentifier() {
    Person user = workspace.getModel().addPerson("User");
    Relationship relationship = user.interactsWith(user, "Description");
    ModelDslContext context = context();
    IdentifiersRegister register = new IdentifiersRegister();
    register.register("rel", relationship);
    context.setIdentifierRegister(register);
    ModelItem modelItem = parser.parse(context, tokens("ref", "rel"));
    assertSame(modelItem, relationship);
}
Also used : Relationship(com.structurizr.model.Relationship) ModelItem(com.structurizr.model.ModelItem) Person(com.structurizr.model.Person) Test(org.junit.jupiter.api.Test)

Example 4 with Relationship

use of com.structurizr.model.Relationship 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;
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Element(com.structurizr.model.Element) Relationship(com.structurizr.model.Relationship) ModelItem(com.structurizr.model.ModelItem)

Example 5 with Relationship

use of com.structurizr.model.Relationship 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)

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