Skip to content

Commit

Permalink
Prevents pre-built themes being loaded during server-side automatic l…
Browse files Browse the repository at this point in the history
…ayout execution ... they have no element width/height definitions, and the themes have no impact on automatic layout.
  • Loading branch information
simonbrowndotje committed Dec 7, 2023
1 parent 504d851 commit c626228
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@

import java.io.File;
import java.nio.file.Files;
import java.util.Arrays;

@RestController
public class GraphvizController {

private static final Log log = LogFactory.getLog(GraphvizController.class);

private static final String PREBUILT_THEME_URL = "https://static.structurizr.com";

@PostMapping(value = "/graphviz", consumes = "application/json", produces = "application/json; charset=UTF-8")
public String post(@RequestBody String json,
@RequestParam(required = false) String view,
Expand All @@ -38,9 +41,11 @@ public String post(@RequestBody String json,
Workspace workspace = WorkspaceUtils.fromJson(json);

if (configuration.hasInternetConnection()) {
log.debug("Loading themes");
try {
ThemeUtils.loadThemes(workspace);
if (themesNeedToBeLoaded(workspace)) {
log.debug("Loading themes");
ThemeUtils.loadThemes(workspace);
}
} catch (Exception e) {
log.warn("Ignoring themes: " + e.getMessage());
}
Expand Down Expand Up @@ -130,4 +135,10 @@ public String post(@RequestBody String json,
}
}

private boolean themesNeedToBeLoaded(Workspace workspace) {
// the pre-built themes at https://static.structurizr.com do not include any element width/height definitions,
// and therefore don't need to be loaded in order to run automatic layout
return Arrays.stream(workspace.getViews().getConfiguration().getThemes()).anyMatch(t -> !t.startsWith(PREBUILT_THEME_URL));
}

}

0 comments on commit c626228

Please sign in to comment.