use of com.structurizr.view.View 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.View in project moduliths by moduliths.
the class Documenter method addComponentsToView.
private void addComponentsToView(Supplier<Stream<Module>> modules, ComponentView view, Options options, Consumer<ComponentView> afterCleanup) {
Styles styles = view.getViewSet().getConfiguration().getStyles();
Map<Module, Component> components = getComponents(options);
//
modules.get().distinct().filter(//
options.getExclusions().negate()).map(//
it -> applyBackgroundColor(it, components, options, styles)).filter(//
options.getComponentFilter()).forEach(view::add);
// view.getViewSet().getConfiguration().getStyles().findElementStyle(element).getBackground()
// Remove filtered dependency types
//
DependencyType.allBut(options.getDependencyTypes()).map(//
Object::toString).forEach(it -> view.removeRelationshipsWithTag(it));
afterCleanup.accept(view);
// Filter outgoing relationships of target-only modules
//
modules.get().filter(options.getTargetOnly()).forEach(module -> {
Component component = components.get(module);
//
view.getRelationships().stream().map(//
RelationshipView::getRelationship).filter(//
it -> it.getSource().equals(component)).forEach(it -> view.remove(it));
});
// … as well as all elements left without a relationship
if (options.hideElementsWithoutRelationships()) {
view.removeElementsWithNoRelationships();
}
afterCleanup.accept(view);
// Remove default relationships if more qualified ones exist
//
view.getRelationships().stream().map(//
RelationshipView::getRelationship).collect(//
Collectors.groupingBy(Connection::of)).values().stream().forEach(it -> potentiallyRemoveDefaultRelationship(view, it));
}
Aggregations