Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import com.structurizr.util.StringUtils;
import com.structurizr.util.WorkspaceUtils;
import com.structurizr.validation.WorkspaceScopeValidatorFactory;
import java.util.Arrays;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Stream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.scheduling.annotation.Scheduled;
Expand Down Expand Up @@ -120,8 +124,7 @@ private void writeToFile(File file, String content) {
}
}

private Workspace loadWorkspace(long workspaceId) {
File workspaceDirectory = getDataDirectory(workspaceId);
private Workspace loadWorkspace(long workspaceId, File workspaceDirectory) {
File dslFile = new File(workspaceDirectory, filename + ".dsl");
File jsonFile = new File(workspaceDirectory, filename + ".json");

Expand Down Expand Up @@ -197,37 +200,38 @@ private Workspace loadWorkspaceFromDsl(long workspaceId, File dslFile, File json

public List<WorkspaceMetaData> getWorkspaces() {
List<WorkspaceMetaData> workspaces = new ArrayList<>();

File[] files = dataDirectory.listFiles();
if (files != null) {
for (File file : files) {
long id = parseWorkspaceId(file.getName());
if (file.isDirectory() && id > 0) {
try {
Workspace workspace = loadWorkspace(id);
if (workspace == null) {
workspace = new Workspace("Workspace " + id, "");
workspace.setId(id);
}
workspaces.add(toWorkspaceMetadata(workspace));
} catch (Exception e) {
log.warn("Ignoring workspace with ID " + id + ": " + e.getMessage());
}
getWorkspaceDirs().forEach(wd -> {
try {
Workspace workspace = loadWorkspace(wd.getKey(), wd.getValue());
if (workspace == null) {
workspace = new Workspace("Workspace " + wd.getKey(), "");
workspace.setId(wd.getKey());
}
workspaces.add(toWorkspaceMetadata(workspace));
} catch (Exception e) {
log.warn("Ignoring workspace with ID " + wd.getKey() + ": " + e.getMessage());
}
}
});

return workspaces;
}

public Workspace getWorkspace(long workspaceId) {
Workspace workspace = loadWorkspace(workspaceId);

if (workspace != null) {
workspace.setId(workspaceId);
}
return getWorkspaceDirs()
.filter(e -> e.getKey().equals(workspaceId))
.findFirst()
.map(f -> loadWorkspace(f.getKey(), f.getValue()))
.map(ws -> {
ws.setId(workspaceId);
return ws;
})
.orElse(null);
}

return workspace;
private Stream<Entry<Long, File>> getWorkspaceDirs() {
return Arrays.stream(dataDirectory.listFiles(f -> f.isDirectory()))
.map(f -> Map.entry(parseWorkspaceId(f.getName()), f))
.filter(entry -> entry.getKey() > 0);
}

@Override
Expand Down
61 changes: 61 additions & 0 deletions ui.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

# - this script merges the contents of the structurizr/ui repository into this directory,
# - this has only been tested on WSL

export STRUCTURIZR_BUILD_NUMBER=$1
export STRUCTURIZR_UI_DIR=../structurizr-ui
export STRUCTURIZR_LITE_DIR=.

# Remove existing static resources
rm -rf "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static/bootstrap-icons"
rm -rf "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static/css"
rm -rf "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static/html"
rm -rf "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static/img"
rm -rf "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static/js"
mkdir -p "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static"

# JavaScript
mkdir -p "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static/js"
cp -a "$STRUCTURIZR_UI_DIR/src/js/"* "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static/js"

if [[ -n $STRUCTURIZR_BUILD_NUMBER ]]; then
for file in "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static/js/structurizr"*.js; do
filename="${file%.*}"

if [[ $file == *structurizr-embed.js ]]; then
echo "Skipping $filename"
else
mv "$filename.js" "$filename-$STRUCTURIZR_BUILD_NUMBER.js"
fi
done
fi

# CSS
mkdir -p "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static/css"
cp -a "$STRUCTURIZR_UI_DIR/src/css/"* "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static/css"

# Images
mkdir -p "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static/img"
cp -a "$STRUCTURIZR_UI_DIR/src/img/"* "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static/img"

# Bootstrap icons
mkdir -p "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static/bootstrap-icons"
cp -a "$STRUCTURIZR_UI_DIR/src/bootstrap-icons/"* "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static/bootstrap-icons"

# HTML (offline exports)
mkdir -p "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static/html"
cp "$STRUCTURIZR_UI_DIR/src/html/"* "$STRUCTURIZR_LITE_DIR/src/main/resources/static/static/html"

# JSP fragments
cp -a "$STRUCTURIZR_UI_DIR/src/fragments/"* "$STRUCTURIZR_LITE_DIR/src/main/webapp/WEB-INF/fragments"
rm -rf "$STRUCTURIZR_LITE_DIR/src/main/webapp/WEB-INF/fragments/dsl"

# JSP
cp -a "$STRUCTURIZR_UI_DIR/src/jsp/"* "$STRUCTURIZR_LITE_DIR/src/main/webapp/WEB-INF/jsp"
rm "$STRUCTURIZR_LITE_DIR/src/main/webapp/WEB-INF/jsp/review.jsp"
rm "$STRUCTURIZR_LITE_DIR/src/main/webapp/WEB-INF/jsp/review-create.jsp"

# Java
mkdir -p "$STRUCTURIZR_LITE_DIR/src/main/java/com/structurizr/util/"
cp "$STRUCTURIZR_UI_DIR/src/java/com/structurizr/util/DslTemplate.java" "$STRUCTURIZR_LITE_DIR/src/main/java/com/structurizr/util/"