Skip to content

Commit

Permalink
Adds support for workspace branches (on-premises installation only).
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Sep 9, 2024
1 parent 8dbdd78 commit 30da167
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -45,6 +44,7 @@ public class WorkspaceApiClient extends AbstractApiClient {

private String apiKey;
private String apiSecret;
private String branch = "";

private EncryptionStrategy encryptionStrategy;

Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 30da167

Please sign in to comment.