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