Skip to content

Commit

Permalink
View keys will be automatically generated if not specified.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Feb 18, 2024
1 parent 36edcae commit 3d8da34
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 261 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Removes deprecated concepts (e.g. enterprise and software system/person location).
- structurizr-core: Adds `Workspace.trim()` to trim a workspace of unused elements (i.e. those not associated with any views).
- structurizr-core: Adds support for SVG image views (https://github.com/structurizr/java/issues/249).
- structurizr-core: View keys will be automatically generated if not specified.
- structurizr-client: Removes `StructurizrClient` (use `WorkspaceApiClient` instead).
- structurizr-import: Adds support for importing decisions managed by Log4brains.
- structurizr-import: Adds support for importing decisions in MADR format.
Expand Down
17 changes: 17 additions & 0 deletions structurizr-core/src/main/java/com/structurizr/view/View.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.structurizr.view;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.structurizr.PropertyHolder;

import javax.annotation.Nonnull;
Expand All @@ -13,6 +14,8 @@
public abstract class View implements PropertyHolder {

private String key;
private boolean generatedKey = false;

private int order;
private String title;
private String description;
Expand Down Expand Up @@ -57,6 +60,20 @@ void setKey(String key) {
this.key = key;
}

/**
* Returns true if this view has an automatically generated view key, false otherwise.
*
* @return true if this view has an automatically generated view key, false otherwise
*/
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public boolean isGeneratedKey() {
return generatedKey;
}

void setGeneratedKey(boolean generatedKey) {
this.generatedKey = generatedKey;
}

/**
* Gets the order of this view.
*
Expand Down
128 changes: 115 additions & 13 deletions structurizr-core/src/main/java/com/structurizr/view/ViewSet.java

Large diffs are not rendered by default.

314 changes: 124 additions & 190 deletions structurizr-core/src/test/java/com/structurizr/view/ViewSetTests.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ final class ComponentViewParser extends AbstractViewParser {

private static final String GRAMMAR = "component <container identifier> [key] [description] {";

private static final String VIEW_TYPE = "Component";

private static final int CONTAINER_IDENTIFIER_INDEX = 1;
private static final int KEY_INDEX = 2;
private static final int DESCRIPTION_INDEX = 3;
Expand Down Expand Up @@ -44,10 +42,8 @@ ComponentView parse(DslContext context, Tokens tokens) {

if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = workspace.getViews().generateViewKey(VIEW_TYPE);
validateViewKey(key);
}
validateViewKey(key);

if (tokens.includes(DESCRIPTION_INDEX)) {
description = tokens.get(DESCRIPTION_INDEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ final class ContainerViewParser extends AbstractViewParser {

private static final String GRAMMAR = "container <software system identifier> [key] [description] {";

private static final String VIEW_TYPE = "Container";

private static final int SOFTWARE_SYSTEM_IDENTIFIER_INDEX = 1;
private static final int KEY_INDEX = 2;
private static final int DESCRIPTION_INDEX = 3;
Expand Down Expand Up @@ -44,10 +42,8 @@ ContainerView parse(DslContext context, Tokens tokens) {

if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = workspace.getViews().generateViewKey(VIEW_TYPE);
validateViewKey(key);
}
validateViewKey(key);

if (tokens.includes(DESCRIPTION_INDEX)) {
description = tokens.get(DESCRIPTION_INDEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ final class CustomViewParser extends AbstractViewParser {

private static final String GRAMMAR = "custom [key] [title] [description] {";

private static final String VIEW_TYPE = "Custom";

private static final int KEY_INDEX = 1;
private static final int TITLE_INDEX = 2;
private static final int DESCRIPTION_INDEX = 3;
Expand All @@ -27,10 +25,8 @@ CustomView parse(DslContext context, Tokens tokens) {

if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = workspace.getViews().generateViewKey(VIEW_TYPE);
validateViewKey(key);
}
validateViewKey(key);

if (tokens.includes(TITLE_INDEX)) {
title = tokens.get(TITLE_INDEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ final class DeploymentViewParser extends AbstractViewParser {

private static final String GRAMMAR = "deployment <*|software system identifier> <environment> [key] [description] {";

private static final String VIEW_TYPE = "Deployment";

private static final int SCOPE_IDENTIFIER_INDEX = 1;
private static final int ENVIRONMENT_INDEX = 2;
private static final int KEY_INDEX = 3;
Expand Down Expand Up @@ -51,10 +49,8 @@ DeploymentView parse(DslContext context, Tokens tokens) {
if ("*".equals(scopeIdentifier)) {
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = workspace.getViews().generateViewKey(VIEW_TYPE);
validateViewKey(key);
}
validateViewKey(key);

view = workspace.getViews().createDeploymentView(key, description);
} else {
Expand All @@ -66,10 +62,8 @@ DeploymentView parse(DslContext context, Tokens tokens) {
if (element instanceof SoftwareSystem) {
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = workspace.getViews().generateViewKey(VIEW_TYPE);
validateViewKey(key);
}
validateViewKey(key);

view = workspace.getViews().createDeploymentView((SoftwareSystem)element, key, description);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
import com.structurizr.model.SoftwareSystem;
import com.structurizr.view.DynamicView;

import java.text.DecimalFormat;

class DynamicViewParser extends AbstractViewParser {

private static final String GRAMMAR = "dynamic <*|software system identifier|container identifier> [key] [description] {";

private static final String VIEW_TYPE = "Dynamic";

private static final int SCOPE_IDENTIFIER_INDEX = 1;
private static final int KEY_INDEX = 2;
private static final int DESCRIPTION_INDEX = 3;
Expand Down Expand Up @@ -45,10 +41,8 @@ DynamicView parse(DslContext context, Tokens tokens) {
if (WILDCARD.equals(scopeIdentifier)) {
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = workspace.getViews().generateViewKey(VIEW_TYPE);
validateViewKey(key);
}
validateViewKey(key);

view = workspace.getViews().createDynamicView(key, description);
} else {
Expand All @@ -60,20 +54,15 @@ DynamicView parse(DslContext context, Tokens tokens) {
if (element instanceof SoftwareSystem) {
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = workspace.getViews().generateViewKey(VIEW_TYPE);
validateViewKey(key);
}
validateViewKey(key);

view = workspace.getViews().createDynamicView((SoftwareSystem)element, key, description);
} else if (element instanceof Container) {
Container container = (Container)element;
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = workspace.getViews().generateViewKey(VIEW_TYPE);
validateViewKey(key);
}
validateViewKey(key);

view = workspace.getViews().createDynamicView((Container)element, key, description);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ final class FilteredViewParser extends AbstractViewParser {

private static final String GRAMMAR = "filtered <baseKey> <include|exclude> <tags> [key] [description]";

private static final String VIEW_TYPE = "Filtered";

private static final int BASE_KEY_INDEX = 1;
private static final int MODE_INDEX = 2;
private static final int TAGS_INDEX = 3;
Expand All @@ -37,7 +35,7 @@ FilteredView parse(DslContext context, Tokens tokens) {
}

Workspace workspace = context.getWorkspace();
String key;
String key = "";

StaticView baseView;
String baseKey = tokens.get(BASE_KEY_INDEX);
Expand Down Expand Up @@ -77,10 +75,8 @@ FilteredView parse(DslContext context, Tokens tokens) {

if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = workspace.getViews().generateViewKey(VIEW_TYPE);
validateViewKey(key);
}
validateViewKey(key);

return workspace.getViews().createFilteredView(baseView, key, description, filterMode, tags.toArray(new String[0]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class ImageViewParser extends AbstractViewParser {

private static final String GRAMMAR = "image <*|element identifier> [key] {";

private static final String VIEW_TYPE = "Image";

private static final int SCOPE_IDENTIFIER_INDEX = 1;
private static final int KEY_INDEX = 2;

Expand All @@ -32,10 +30,8 @@ ImageView parse(DslContext context, Tokens tokens) {
ImageView view;
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = workspace.getViews().generateViewKey(VIEW_TYPE);
validateViewKey(key);
}
validateViewKey(key);

String scopeIdentifier = tokens.get(SCOPE_IDENTIFIER_INDEX);
if (WILDCARD.equals(scopeIdentifier)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ final class SystemContextViewParser extends AbstractViewParser {

private static final String GRAMMAR = "systemContext <software system identifier> [key] [description] {";

private static final String VIEW_TYPE = "SystemContext";

private static final int SOFTWARE_SYSTEM_IDENTIFIER_INDEX = 1;
private static final int KEY_INDEX = 2;
private static final int DESCRIPTION_INDEX = 3;
Expand Down Expand Up @@ -44,10 +42,8 @@ SystemContextView parse(DslContext context, Tokens tokens) {

if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = workspace.getViews().generateViewKey(VIEW_TYPE);
validateViewKey(key);
}
validateViewKey(key);

if (tokens.includes(DESCRIPTION_INDEX)) {
description = tokens.get(DESCRIPTION_INDEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ final class SystemLandscapeViewParser extends AbstractViewParser {

private static final String GRAMMAR = "systemLandscape [key] [description] {";

private static final String VIEW_TYPE = "SystemLandscape";

private static final int KEY_INDEX = 1;
private static final int DESCRIPTION_INDEX = 2;

Expand All @@ -25,10 +23,8 @@ SystemLandscapeView parse(DslContext context, Tokens tokens) {

if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = workspace.getViews().generateViewKey(VIEW_TYPE);
validateViewKey(key);
}
validateViewKey(key);

if (tokens.includes(DESCRIPTION_INDEX)) {
description = tokens.get(DESCRIPTION_INDEX);
Expand Down

0 comments on commit 3d8da34

Please sign in to comment.