From 30da167b7cf720d062cbc2391fc9468e412c19d9 Mon Sep 17 00:00:00 2001 From: Simon Brown Date: Mon, 9 Sep 2024 14:36:08 +0100 Subject: [PATCH] Adds support for workspace branches (on-premises installation only). --- .../structurizr/api/WorkspaceApiClient.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/structurizr-client/src/main/java/com/structurizr/api/WorkspaceApiClient.java b/structurizr-client/src/main/java/com/structurizr/api/WorkspaceApiClient.java index d12adf3a..159a8fff 100644 --- a/structurizr-client/src/main/java/com/structurizr/api/WorkspaceApiClient.java +++ b/structurizr-client/src/main/java/com/structurizr/api/WorkspaceApiClient.java @@ -32,7 +32,6 @@ import java.text.SimpleDateFormat; import java.util.Base64; import java.util.Date; -import java.util.Properties; /** * A client for the Structurizr workspace API that allows you to get and put Structurizr workspaces in a JSON format. @@ -45,6 +44,7 @@ public class WorkspaceApiClient extends AbstractApiClient { private String apiKey; private String apiSecret; + private String branch = ""; private EncryptionStrategy encryptionStrategy; @@ -111,6 +111,14 @@ protected void setApiSecret(String apiSecret) { this.apiSecret = apiSecret; } + public String getBranch() { + return branch; + } + + public void setBranch(String branch) { + this.branch = branch; + } + /** * Gets the location where a copy of the workspace is archived when it is retrieved from the server. * @@ -224,7 +232,14 @@ public Workspace getWorkspace(long workspaceId) throws StructurizrClientExceptio try (CloseableHttpClient httpClient = HttpClients.createSystem()) { log.info("Getting workspace with ID " + workspaceId); - HttpGet httpGet = new HttpGet(url + WORKSPACE_PATH + "/" + workspaceId); + + HttpGet httpGet; + if (StringUtils.isNullOrEmpty(branch)) { + httpGet = new HttpGet(url + WORKSPACE_PATH + "/" + workspaceId); + } else { + httpGet = new HttpGet(url + WORKSPACE_PATH + "/" + workspaceId + "/branch/" + branch); + } + addHeaders(httpGet, "", ""); debugRequest(httpGet, null); @@ -296,7 +311,12 @@ public void putWorkspace(long workspaceId, Workspace workspace) throws Structuri workspace.setLastModifiedAgent(agent); workspace.setLastModifiedUser(getUser()); - HttpPut httpPut = new HttpPut(url + WORKSPACE_PATH + "/" + workspaceId); + HttpPut httpPut; + if (StringUtils.isNullOrEmpty(branch)) { + httpPut = new HttpPut(url + WORKSPACE_PATH + "/" + workspaceId); + } else { + httpPut = new HttpPut(url + WORKSPACE_PATH + "/" + workspaceId + "/branch/" + branch); + } StringWriter stringWriter = new StringWriter(); if (encryptionStrategy == null) {