Search in sources :

Example 1 with ComponentView

use of com.structurizr.view.ComponentView in project moduliths by moduliths.

the class Documenter method createPlantUml.

private String createPlantUml(Options options) throws IOException {
    ComponentView componentView = createComponentView(options);
    componentView.setTitle(modules.getSystemName().orElse("Modules"));
    addComponentsToView(() -> modules.stream(), componentView, options, it -> {
    });
    return render(componentView, options);
}
Also used : ComponentView(com.structurizr.view.ComponentView)

Example 2 with ComponentView

use of com.structurizr.view.ComponentView in project moduliths by moduliths.

the class Documenter method writeModuleAsPlantUml.

/**
 * Writes the PlantUML component diagram for the given {@link Module} with the given rendering {@link Options}.
 *
 * @param module must not be {@literal null}.
 * @param options must not be {@literal null}.
 * @return the current instance, will never be {@literal null}.
 */
public Documenter writeModuleAsPlantUml(Module module, Options options) {
    Assert.notNull(module, "Module must not be null!");
    Assert.notNull(options, "Options must not be null!");
    ComponentView view = createComponentView(options, module);
    view.setTitle(options.getDefaultDisplayName().apply(module));
    addComponentsToView(module, view, options);
    String fileNamePattern = options.getTargetFileName().orElse("module-%s.uml");
    Assert.isTrue(fileNamePattern.contains("%s"), () -> String.format(INVALID_FILE_NAME_PATTERN, fileNamePattern));
    return writeViewAsPlantUml(view, String.format(fileNamePattern, module.getName()), options);
}
Also used : ComponentView(com.structurizr.view.ComponentView)

Example 3 with ComponentView

use of com.structurizr.view.ComponentView in project dsl by structurizr.

the class ComponentViewParser method parse.

ComponentView parse(DslContext context, Tokens tokens) {
    if (tokens.hasMoreThan(DESCRIPTION_INDEX)) {
        throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
    }
    if (!tokens.includes(CONTAINER_IDENTIFIER_INDEX)) {
        throw new RuntimeException("Expected: " + GRAMMAR);
    }
    Workspace workspace = context.getWorkspace();
    Container container;
    String key = "";
    String description = "";
    String containerIdentifier = tokens.get(CONTAINER_IDENTIFIER_INDEX);
    Element element = context.getElement(containerIdentifier);
    if (element == null) {
        throw new RuntimeException("The container \"" + containerIdentifier + "\" does not exist");
    }
    if (element instanceof Container) {
        container = (Container) element;
    } else {
        throw new RuntimeException("The element \"" + containerIdentifier + "\" is not a container");
    }
    if (tokens.includes(KEY_INDEX)) {
        key = tokens.get(KEY_INDEX);
    } else {
        key = removeNonWordCharacters(container.getSoftwareSystem().getName()) + "-" + removeNonWordCharacters(container.getName()) + "-" + VIEW_TYPE;
    }
    validateViewKey(key);
    if (tokens.includes(DESCRIPTION_INDEX)) {
        description = tokens.get(DESCRIPTION_INDEX);
    }
    ComponentView view = workspace.getViews().createComponentView(container, key, description);
    view.setExternalSoftwareSystemBoundariesVisible(true);
    return view;
}
Also used : Container(com.structurizr.model.Container) ComponentView(com.structurizr.view.ComponentView) Element(com.structurizr.model.Element) Workspace(com.structurizr.Workspace)

Example 4 with ComponentView

use of com.structurizr.view.ComponentView in project agile-architecture-documentation-system by Riduidel.

the class ViewsGenerator method endVisit.

@Override
public void endVisit(Workspace workspace, OutputBuilder builder) {
    ViewSet views = workspace.getViews();
    SoftwareSystem agileArchitecture = workspace.getModel().getSoftwareSystemWithName(Architecture.AGILE_ARCHITECTURE_DOCUMENTATION);
    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(agileArchitecture.getContainerWithName(Architecture.CONTAINERS_BASE), "agile.architecture.base.components", "Agile architecture base components view");
    agileArchitectureBaseComponents.addAllComponents();
// Styles styles = views.getConfiguration().getStyles();
// styles.addElementStyle(Tags.SOFTWARE_SYSTEM).background("#1168bd").color("#ffffff");
// styles.addElementStyle(Tags.PERSON).background("#08427b").color("#ffffff").shape(Shape.Person);
}
Also used : ComponentView(com.structurizr.view.ComponentView) ViewSet(com.structurizr.view.ViewSet) SystemContextView(com.structurizr.view.SystemContextView) SoftwareSystem(com.structurizr.model.SoftwareSystem) ContainerView(com.structurizr.view.ContainerView)

Example 5 with ComponentView

use of com.structurizr.view.ComponentView 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);
    }
}
Also used : Arrays(java.util.Arrays) DecodeException(io.kroki.server.error.DecodeException) DiagramSource(io.kroki.server.decode.DiagramSource) StructurizrDslParserException(com.structurizr.dsl.StructurizrDslParserException) View(com.structurizr.view.View) SystemLandscapeView(com.structurizr.view.SystemLandscapeView) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) DeploymentView(com.structurizr.view.DeploymentView) Diagram(com.structurizr.export.Diagram) BadRequestException(io.kroki.server.error.BadRequestException) ComponentView(com.structurizr.view.ComponentView) ContainerView(com.structurizr.view.ContainerView) DynamicView(com.structurizr.view.DynamicView) Collection(java.util.Collection) StructurizrPlantUMLExporter(com.structurizr.export.plantuml.StructurizrPlantUMLExporter) Vertx(io.vertx.core.Vertx) FileFormat(io.kroki.server.format.FileFormat) SourceDecoder(io.kroki.server.decode.SourceDecoder) Objects(java.util.Objects) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) StructurizrDslParser(com.structurizr.dsl.StructurizrDslParser) SystemContextView(com.structurizr.view.SystemContextView) Optional(java.util.Optional) Handler(io.vertx.core.Handler) StructurizrDslParser(com.structurizr.dsl.StructurizrDslParser) JsonObject(io.vertx.core.json.JsonObject) StructurizrDslParserException(com.structurizr.dsl.StructurizrDslParserException) View(com.structurizr.view.View) SystemLandscapeView(com.structurizr.view.SystemLandscapeView) DeploymentView(com.structurizr.view.DeploymentView) ComponentView(com.structurizr.view.ComponentView) ContainerView(com.structurizr.view.ContainerView) DynamicView(com.structurizr.view.DynamicView) SystemContextView(com.structurizr.view.SystemContextView) Diagram(com.structurizr.export.Diagram) ComponentView(com.structurizr.view.ComponentView) SystemContextView(com.structurizr.view.SystemContextView) BadRequestException(io.kroki.server.error.BadRequestException) SystemLandscapeView(com.structurizr.view.SystemLandscapeView) DynamicView(com.structurizr.view.DynamicView) ContainerView(com.structurizr.view.ContainerView) DeploymentView(com.structurizr.view.DeploymentView)

Aggregations

ComponentView (com.structurizr.view.ComponentView)11 Container (com.structurizr.model.Container)5 SoftwareSystem (com.structurizr.model.SoftwareSystem)4 ContainerView (com.structurizr.view.ContainerView)4 Workspace (com.structurizr.Workspace)3 Component (com.structurizr.model.Component)3 Model (com.structurizr.model.Model)3 SystemContextView (com.structurizr.view.SystemContextView)3 Element (com.structurizr.model.Element)2 View (com.structurizr.view.View)2 ViewSet (com.structurizr.view.ViewSet)2 File (java.io.File)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 ComponentFinder (com.structurizr.analysis.ComponentFinder)1 StructurizrAnnotationsComponentFinderStrategy (com.structurizr.analysis.StructurizrAnnotationsComponentFinderStrategy)1 StructurizrDslParser (com.structurizr.dsl.StructurizrDslParser)1 StructurizrDslParserException (com.structurizr.dsl.StructurizrDslParserException)1 Diagram (com.structurizr.export.Diagram)1 StructurizrPlantUMLExporter (com.structurizr.export.plantuml.StructurizrPlantUMLExporter)1