Skip to content

Commit

Permalink
Adds support for inter-workspace URLs of the form `{workspace:123456}…
Browse files Browse the repository at this point in the history
…/diagrams`.
  • Loading branch information
simonbrowndotje committed Dec 28, 2023
1 parent 33797b6 commit 0ccffba
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.29.0 (unreleased)

- Adds `com.structurizr.api.AdminApiClient` as a client for the cloud service/on-premises admin APIs.
- Adds support for inter-workspace URLs of the form `{workspace:123456}/diagrams`.

## 1.28.1 (11th December 2023)

Expand Down
4 changes: 3 additions & 1 deletion structurizr-core/src/com/structurizr/model/ModelItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ public void setUrl(String url) {
if (StringUtils.isNullOrEmpty(url)) {
this.url = null;
} else {
if (url.startsWith(Url.WORKSPACE_URL_PREFIX)) {
if (url.startsWith(Url.INTRA_WORKSPACE_URL_PREFIX)) {
this.url = url;
} else if (url.matches(Url.INTER_WORKSPACE_URL_REGEX)) {
this.url = url;
} else if (Url.isUrl(url)) {
this.url = url;
Expand Down
3 changes: 2 additions & 1 deletion structurizr-core/src/com/structurizr/util/Url.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
*/
public class Url {

public static final String WORKSPACE_URL_PREFIX = "{workspace}";
public static final String INTRA_WORKSPACE_URL_PREFIX = "{workspace}";
public static final String INTER_WORKSPACE_URL_REGEX = "\\{workspace:\\d+\\}.*";

/**
* Determines whether the supplied string is a valid URL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,24 @@ void setUrl_AcceptsAUrl() {
}

@Test
void setUrl_AcceptsAWorkspaceUrl() {
void setUrl_AcceptsAnIntraWorkspaceUrl() {
Element element = model.addSoftwareSystem("Name");
element.setUrl("{workspace}/diagrams#key");
assertEquals("{workspace}/diagrams#key", element.getUrl());
}

@Test
void setUrl_AcceptsAnInterWorkspaceUrl() {
Element element = model.addSoftwareSystem("Name");

element.setUrl("{workspace:123456}");
assertEquals("{workspace:123456}", element.getUrl());

element.setUrl("{workspace:123456}/diagrams#key");
assertEquals("{workspace:123456}/diagrams#key", element.getUrl());

element.setUrl("{workspace:123456}/documentation");
assertEquals("{workspace:123456}/documentation", element.getUrl());
}

}

0 comments on commit 0ccffba

Please sign in to comment.