use of com.structurizr.view.SystemContextView in project kroki by yuzutech.
the class Structurizr method convert.
static byte[] convert(String source, FileFormat fileFormat, StructurizrPlantUMLExporter structurizrPlantUMLExporter, JsonObject options) {
StructurizrDslParser parser = new StructurizrDslParser();
try {
parser.parse(source);
Collection<View> views = parser.getWorkspace().getViews().getViews();
if (views.isEmpty()) {
throw new BadRequestException("Empty diagram, does not have any view.");
}
View selectedView;
String viewKey = options.getString("view-key");
if (viewKey != null && !viewKey.trim().isEmpty()) {
Optional<View> viewFound = views.stream().filter(view -> Objects.equals(view.getKey(), viewKey)).findFirst();
if (!viewFound.isPresent()) {
throw new BadRequestException("Unable to find view for key: " + viewKey + ".");
}
selectedView = viewFound.get();
} else {
// take the first view if not specified
selectedView = views.iterator().next();
}
final Diagram diagram;
if (selectedView instanceof DynamicView) {
diagram = structurizrPlantUMLExporter.export((DynamicView) selectedView);
} else if (selectedView instanceof DeploymentView) {
diagram = structurizrPlantUMLExporter.export((DeploymentView) selectedView);
} else if (selectedView instanceof ComponentView) {
diagram = structurizrPlantUMLExporter.export((ComponentView) selectedView);
} else if (selectedView instanceof ContainerView) {
diagram = structurizrPlantUMLExporter.export((ContainerView) selectedView);
} else if (selectedView instanceof SystemContextView) {
diagram = structurizrPlantUMLExporter.export((SystemContextView) selectedView);
} else if (selectedView instanceof SystemLandscapeView) {
diagram = structurizrPlantUMLExporter.export((SystemLandscapeView) selectedView);
} else {
throw new BadRequestException("View type is not supported: " + selectedView.getClass().getSimpleName() + ", must be a DynamicView, DeploymentView, ComponentView, ContainerView, SystemContextView or SystemLandscapeView.");
}
return Plantuml.convert(diagram.getDefinition(), fileFormat, new JsonObject());
} catch (StructurizrDslParserException e) {
String cause = e.getMessage();
final String message;
if (cause != null && !cause.trim().isEmpty()) {
message = "Unable to parse the Structurizr DSL. " + cause + ".";
} else {
message = "Unable to parse the Structurizr DSL.";
}
throw new BadRequestException(message, e);
}
}
use of com.structurizr.view.SystemContextView in project tutorials by eugenp.
the class StructurizrSimple method getSoftwareSystem.
private static Workspace getSoftwareSystem() {
Workspace workspace = new Workspace("Payment Gateway", "Payment Gateway");
Model model = workspace.getModel();
Person user = model.addPerson("Merchant", "Merchant");
SoftwareSystem paymentTerminal = model.addSoftwareSystem(PAYMENT_TERMINAL, "Payment Terminal");
user.uses(paymentTerminal, "Makes payment");
SoftwareSystem fraudDetector = model.addSoftwareSystem(FRAUD_DETECTOR, "Fraud Detector");
paymentTerminal.uses(fraudDetector, "Obtains fraud score");
ViewSet viewSet = workspace.getViews();
SystemContextView contextView = viewSet.createSystemContextView(workspace.getModel().getSoftwareSystemWithName(PAYMENT_TERMINAL), SOFTWARE_SYSTEM_VIEW, "Payment Gateway Diagram");
contextView.addAllElements();
return workspace;
}
use of com.structurizr.view.SystemContextView 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;
}
use of com.structurizr.view.SystemContextView in project dsl by structurizr.
the class StaticViewContentParserTests method test_parseInclude_ThrowsAnException_WhenTryingToAddAComponentToASystemContextView.
@Test
void test_parseInclude_ThrowsAnException_WhenTryingToAddAComponentToASystemContextView() {
SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
Container container = softwareSystem.addContainer("Container", "Description", "Technology");
Component component = container.addComponent("Component", "Description", "Technology");
SystemContextView view = views.createSystemContextView(softwareSystem, "key", "Description");
SystemContextViewDslContext context = new SystemContextViewDslContext(view);
context.setWorkspace(workspace);
IdentifiersRegister elements = new IdentifiersRegister();
elements.register("component", component);
context.setIdentifierRegister(elements);
try {
parser.parseInclude(context, tokens("include", "component"));
fail();
} catch (RuntimeException iae) {
assertEquals("The element \"component\" can not be added to this type of view", iae.getMessage());
}
}
use of com.structurizr.view.SystemContextView in project java by structurizr.
the class StructurizrClientIntegrationTests method test_putAndGetWorkspace_WithoutEncryption.
@Test
public void test_putAndGetWorkspace_WithoutEncryption() throws Exception {
Workspace workspace = new Workspace("Structurizr client library tests - without encryption", "A test workspace for the Structurizr client library");
SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Software System", "Description");
Person person = workspace.getModel().addPerson("Person", "Description");
person.uses(softwareSystem, "Uses");
SystemContextView systemContextView = workspace.getViews().createSystemContextView(softwareSystem, "SystemContext", "Description");
systemContextView.addAllElements();
structurizrClient.putWorkspace(20081, workspace);
workspace = structurizrClient.getWorkspace(20081);
assertNotNull(workspace.getModel().getSoftwareSystemWithName("Software System"));
assertNotNull(workspace.getModel().getPersonWithName("Person"));
assertEquals(1, workspace.getModel().getRelationships().size());
assertEquals(1, workspace.getViews().getSystemContextViews().size());
// and check the archive version is readable
Workspace archivedWorkspace = new JsonReader().read(new FileReader(getArchivedWorkspace()));
assertEquals(20081, archivedWorkspace.getId());
assertEquals("Structurizr client library tests - without encryption", archivedWorkspace.getName());
assertEquals(1, archivedWorkspace.getModel().getSoftwareSystems().size());
assertEquals(1, workspaceArchiveLocation.listFiles().length);
}
Aggregations