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