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