Search in sources :

Example 11 with Person

use of com.structurizr.model.Person in project agile-architecture-documentation-system by Riduidel.

the class Architecture method describeArchitecture.

/**
 * Creates the workspace object and add in it both the architecture components
 * AND the views used to display it
 *
 * @return
 */
public Workspace describeArchitecture() {
    // tag::structurizr-example-context[]
    String name = "agile-architecture-documentation-system";
    Workspace workspace = new Workspace(name, "This is the model of the agile architecture documentation system.");
    Model model = workspace.getModel();
    Person architect = model.addPerson("Architect", "The architect as team scribe is the writer of this kind of documentation.");
    Person stakeholder = model.addPerson("Stakeholder", "All project stakeholders are readers of this kind of documentation.");
    SoftwareSystem agileArchitecture = model.addSoftwareSystem(AGILE_ARCHITECTURE_DOCUMENTATION, "This software system generates the documentation.");
    agileArchitecture.addProperty(ModelElementKeys.ISSUE_MANAGER, "https://github.com/Riduidel/agile-architecture-documentation-system");
    agileArchitecture.addProperty(ADRExtractor.AGILE_ARCHITECTURE_TICKETS_PROJECT, name);
    agileArchitecture.addProperty(ADRExtractor.AGILE_ARCHITECTURE_TICKETS_ADR_LABEL, "decision");
    architect.uses(agileArchitecture, "Writes");
    stakeholder.uses(agileArchitecture, "Read");
    // end::structurizr-example-context[]
    // ///////////////////////////////////////////////////////////////////////////////////////
    // tag::structurizr-example-containers[]
    Container archetype = agileArchitecture.addContainer(CONTAINERS_ARCHETYPE, "Archetype generating a valid build", "maven archetype");
    archetype.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("archetype/pom.xml"));
    architect.uses(archetype, "Bootstrap a valid project");
    Container maven = agileArchitecture.addContainer(CONTAINERS_MAVEN, "Maven build tool", "Maven build tool");
    architect.uses(maven, "Generates documentation");
    Container base = agileArchitecture.addContainer(CONTAINERS_BASE, "Architecture base", "Java executable");
    base.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("base/pom.xml"));
    base.addProperty(ModelElementKeys.SCM_PATH, base.getName());
    // end::structurizr-example-containers[]
    // tag::structurizr-example-components[]
    ComponentFinder componentFinder = new ComponentFinder(base, // new SourceCodeComponentFinderStrategy(new File("../base/src/main/java")),
    ArchitectureModelProvider.class.getPackageName(), new StructurizrAnnotationsComponentFinderStrategy());
    // end::structurizr-example-components[]
    if (getClass().getClassLoader() instanceof URLClassLoader) {
        componentFinder.setUrlClassLoader((URLClassLoader) getClass().getClassLoader());
    }
    try {
        componentFinder.findComponents();
    } catch (Exception e) {
        throw new RuntimeException("Unable to locate components in ", e);
    }
    // model.addImplicitRelationships();
    // Damn, structurizr-annotations doesn't understand CDI. Let's supplement it!
    base.getComponentWithName("ArchitectureEnhancer").uses(base.getComponentWithName("DocumentsCollector"), "Collects documents in source folder");
    base.getComponentWithName("ArchitectureEnhancer").uses(base.getComponentWithName("SCMLinkGenerator"), "Generates links to SCM sources");
    base.getComponentWithName("ArchitectureEnhancer").uses(base.getComponentWithName("SCMReadmeReader"), "Includes elements readme when they exist");
    base.getComponentWithName("ArchitectureEnhancer").uses(base.getComponentWithName("ImplicitIncludeManager"), "Generates includes for all enhancers");
    base.getComponentWithName("ArchitectureEnhancer").uses(base.getComponentWithName("GraphEmitter"), "Generates diagrams in PlantUML format");
    maven.uses(base.getComponentWithName("ArchitectureDocumentationBuilder"), "Invokes that Java executable during maven build");
    Component gitHub = base.addComponent("github-scm-handler", "GitHub SCM Handler", "java");
    gitHub.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("github-scm-handler/pom.xml"));
    gitHub.addProperty(ModelElementKeys.SCM_PATH, gitHub.getName());
    base.getComponentWithName("SCMLinkGenerator").uses(gitHub, "Get project source link");
    base.getComponentWithName("SCMReadmeReader").uses(gitHub, "Get project readme");
    Component gitLab = base.addComponent("gitlab-scm-handler", "GitLab SCM Handler", "java");
    gitLab.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("gitlab-scm-handler/pom.xml"));
    gitLab.addProperty(ModelElementKeys.SCM_PATH, gitLab.getName());
    base.getComponentWithName("SCMLinkGenerator").uses(gitLab, "Get project source link");
    base.getComponentWithName("SCMReadmeReader").uses(gitLab, "Get project readme");
    Component adrTicketsExtractor = base.addComponent("adr-tickets-extractor", "enhanced by maven");
    adrTicketsExtractor.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("adr-tickets-extractor/pom.xml"));
    adrTicketsExtractor.addProperty(ModelElementKeys.SCM_PATH, adrTicketsExtractor.getName());
    adrTicketsExtractor.uses(gitLab, "Read tickets from Gitlab if configured so");
    adrTicketsExtractor.uses(gitHub, "Read tickets from GitHub if configured so");
    base.getComponentWithName("ArchitectureEnhancer").uses(adrTicketsExtractor, "Produces ADR reporting");
    Component cdiConfigExtension = base.addComponent("cdi-config-extension", "CDI Config extensions", "java");
    cdiConfigExtension.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("cdi-config-extension/pom.xml"));
    cdiConfigExtension.addProperty(ModelElementKeys.SCM_PATH, cdiConfigExtension.getName());
    base.getComponentWithName("ArchitectureDocumentationBuilder").uses(cdiConfigExtension, "Eases out some CDI code");
    Component mavenEnhancer = base.addComponent("maven-metadata-inferer", "Enhanced by Maven");
    cdiConfigExtension.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("maven-metadata-inferer/pom.xml"));
    cdiConfigExtension.addProperty(ModelElementKeys.SCM_PATH, mavenEnhancer.getName());
    base.getComponentWithName("ArchitectureDocumentationBuilder").uses(mavenEnhancer, "Infer most of element details from Maven infos");
    Container asciidoc = agileArchitecture.addContainer("asciidoc", "Asciidoc tooling", "Maven plugin");
    maven.uses(base, "Generates diagrams and asciidoc includes");
    maven.uses(asciidoc, "Generates documentation as usable text in HTML/PDF/...");
    // ///////////////////////////////////////////////////////////////////////////////////////
    // tag::structurizr-example-views[]
    ViewSet views = workspace.getViews();
    SystemContextView contextView = views.createSystemContextView(agileArchitecture, "SystemContext", "Illustration of agile-architecture-documentation usage");
    contextView.addAllSoftwareSystems();
    contextView.addAllPeople();
    ContainerView agileArchitectureContainers = views.createContainerView(agileArchitecture, "agile.architecture.containers", "Agile architecture containers");
    agileArchitectureContainers.addAllContainersAndInfluencers();
    ComponentView agileArchitectureBaseComponents = views.createComponentView(base, "agile.architecture.base.components", "Agile architecture base components view");
    agileArchitectureBaseComponents.addAllComponents();
    // styles.addElementStyle(Tags.PERSON).background("#08427b").color("#ffffff").shape(Shape.Person);
    return workspace;
}
Also used : ArchitectureModelProvider(org.ndx.agile.architecture.base.ArchitectureModelProvider) ComponentFinder(com.structurizr.analysis.ComponentFinder) StructurizrAnnotationsComponentFinderStrategy(com.structurizr.analysis.StructurizrAnnotationsComponentFinderStrategy) Container(com.structurizr.model.Container) ComponentView(com.structurizr.view.ComponentView) ViewSet(com.structurizr.view.ViewSet) SystemContextView(com.structurizr.view.SystemContextView) URLClassLoader(java.net.URLClassLoader) Model(com.structurizr.model.Model) SoftwareSystem(com.structurizr.model.SoftwareSystem) ContainerView(com.structurizr.view.ContainerView) Component(com.structurizr.model.Component) Person(com.structurizr.model.Person) Workspace(com.structurizr.Workspace)

Example 12 with Person

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

the class DynamicViewContentParserTests method test_parseRelationship_AddsTheRelationshipWithTheSpecifiedTechnologyToTheView_WhenItAlreadyExistsInTheModel.

@Test
void test_parseRelationship_AddsTheRelationshipWithTheSpecifiedTechnologyToTheView_WhenItAlreadyExistsInTheModel() {
    Person user = model.addPerson("User", "Description");
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
    Relationship r1 = user.uses(softwareSystem, "Uses 1", "Tech 1");
    Relationship r2 = user.uses(softwareSystem, "Uses 2", "Tech 2");
    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);
    parser.parseRelationship(context, tokens("source", "->", "destination", "Description", "Tech 2"));
    assertEquals(1, view.getRelationships().size());
    RelationshipView rv = view.getRelationships().iterator().next();
    assertSame(r2, rv.getRelationship());
    assertSame(user, rv.getRelationship().getSource());
    assertSame(softwareSystem, rv.getRelationship().getDestination());
    assertEquals("Description", 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 13 with Person

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

the class DynamicViewContentParserTests method test_parseRelationship_AddsTheRelationshipToTheView_WhenItAlreadyExistsInTheModel.

@Test
void test_parseRelationship_AddsTheRelationshipToTheView_WhenItAlreadyExistsInTheModel() {
    Person user = model.addPerson("User", "Description");
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
    user.uses(softwareSystem, "Uses");
    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);
    parser.parseRelationship(context, tokens("source", "->", "destination"));
    assertEquals(1, view.getRelationships().size());
    RelationshipView rv = view.getRelationships().iterator().next();
    assertSame(user, rv.getRelationship().getSource());
    assertSame(softwareSystem, rv.getRelationship().getDestination());
    assertEquals("", rv.getDescription());
    assertEquals("1", rv.getOrder());
}
Also used : RelationshipView(com.structurizr.view.RelationshipView) SoftwareSystem(com.structurizr.model.SoftwareSystem) DynamicView(com.structurizr.view.DynamicView) Person(com.structurizr.model.Person) Test(org.junit.jupiter.api.Test)

Example 14 with Person

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

the class PersonParser method parse.

Person parse(GroupableDslContext context, Tokens tokens) {
    if (tokens.hasMoreThan(TAGS_INDEX)) {
        throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
    }
    if (!tokens.includes(NAME_INDEX)) {
        throw new RuntimeException("Expected: " + GRAMMAR);
    }
    Person person = null;
    String name = tokens.get(NAME_INDEX);
    if (context.isExtendingWorkspace()) {
        person = context.getWorkspace().getModel().getPersonWithName(name);
    }
    if (person == null) {
        person = context.getWorkspace().getModel().addPerson(name);
    }
    String description = "";
    if (tokens.includes(DESCRIPTION_INDEX)) {
        description = tokens.get(DESCRIPTION_INDEX);
        person.setDescription(description);
    }
    if (tokens.includes(TAGS_INDEX)) {
        String tags = tokens.get(TAGS_INDEX);
        person.addTags(tags.split(","));
    }
    if (context instanceof EnterpriseDslContext) {
        person.setLocation(Location.Internal);
    }
    if (context.hasGroup()) {
        person.setGroup(context.getGroup().getName());
        context.getGroup().addElement(person);
    }
    return person;
}
Also used : Person(com.structurizr.model.Person)

Example 15 with Person

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

the class PersonParserTests method test_parse_CreatesAPerson.

@Test
void test_parse_CreatesAPerson() {
    parser.parse(context(), tokens("person", "User"));
    assertEquals(1, model.getElements().size());
    Person user = model.getPersonWithName("User");
    assertNotNull(user);
    assertEquals("", user.getDescription());
    assertEquals(Location.Unspecified, user.getLocation());
    assertEquals("Element,Person", user.getTags());
}
Also used : Person(com.structurizr.model.Person) Test(org.junit.jupiter.api.Test)

Aggregations

Person (com.structurizr.model.Person)19 Test (org.junit.jupiter.api.Test)13 SoftwareSystem (com.structurizr.model.SoftwareSystem)9 Workspace (com.structurizr.Workspace)5 DynamicView (com.structurizr.view.DynamicView)4 RelationshipView (com.structurizr.view.RelationshipView)4 SystemContextView (com.structurizr.view.SystemContextView)4 Model (com.structurizr.model.Model)3 ModelItem (com.structurizr.model.ModelItem)3 Relationship (com.structurizr.model.Relationship)3 ViewSet (com.structurizr.view.ViewSet)3 EncryptedWorkspace (com.structurizr.encryption.EncryptedWorkspace)2 EncryptedJsonReader (com.structurizr.io.json.EncryptedJsonReader)2 Container (com.structurizr.model.Container)2 Enterprise (com.structurizr.model.Enterprise)2 FileReader (java.io.FileReader)2 Test (org.junit.Test)2 ComponentFinder (com.structurizr.analysis.ComponentFinder)1 StructurizrAnnotationsComponentFinderStrategy (com.structurizr.analysis.StructurizrAnnotationsComponentFinderStrategy)1 AesEncryptionStrategy (com.structurizr.encryption.AesEncryptionStrategy)1