Skip to content

Commit

Permalink
ViewSet.getViews() now includes all views.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Feb 16, 2023
1 parent 94826f9 commit 84a5664
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ subprojects { proj ->

description = 'Structurizr'
group = 'com.structurizr'
version = '1.20.0'
version = '1.20.1'

repositories {
mavenCentral()
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.20.1 (unreleased)

- `ViewSet.getViews()` now includes all views.
## 1.20.0 (16th February 2023)

- __Breaking change__: Renamed `com.structurizr.view.View` to `com.structurizr.view.ModelView`.
Expand Down
35 changes: 7 additions & 28 deletions structurizr-core/src/com/structurizr/view/ViewSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,7 @@ View getViewWithKey(String key) {
throw new IllegalArgumentException("A key must be specified.");
}

Set<View> views = new HashSet<>();
views.addAll(customViews);
views.addAll(systemLandscapeViews);
views.addAll(systemContextViews);
views.addAll(containerViews);
views.addAll(componentViews);
views.addAll(dynamicViews);
views.addAll(deploymentViews);

return views.stream().filter(v -> key.equals(v.getKey())).findFirst().orElse(null);
return getViews().stream().filter(v -> key.equals(v.getKey())).findFirst().orElse(null);
}

/**
Expand Down Expand Up @@ -528,20 +519,23 @@ void setImageView(Set<ImageView> imageViews) {
}

/**
* Gets the set of all views (except filtered and image views).
* Gets the set of all views.
*
* @return a Collection of View objects
*/
@JsonIgnore
public Collection<View> getViews() {
HashSet<View> views = new HashSet<>();

views.addAll(getCustomViews());
views.addAll(getSystemLandscapeViews());
views.addAll(getSystemContextViews());
views.addAll(getContainerViews());
views.addAll(getComponentViews());
views.addAll(getDynamicViews());
views.addAll(getDeploymentViews());
views.addAll(getFilteredViews());
views.addAll(getImageViews());

return views;
}
Expand Down Expand Up @@ -697,25 +691,10 @@ private void hydrateView(ModelView view) {
}
}

private Collection<View> getAllViews() {
Collection<View> views = new ArrayList<>();
views.addAll(customViews);
views.addAll(systemLandscapeViews);
views.addAll(systemContextViews);
views.addAll(containerViews);
views.addAll(componentViews);
views.addAll(dynamicViews);
views.addAll(deploymentViews);
views.addAll(filteredViews);
views.addAll(imageViews);

return views;
}

private void checkViewKeysAreUnique() {
Set<String> keys = new HashSet<>();

for (View view : getAllViews()) {
for (View view : getViews()) {
if (keys.contains(view.getKey())) {
throw new WorkspaceValidationException("A view with the key " + view.getKey() + " already exists.");
} else {
Expand All @@ -725,7 +704,7 @@ private void checkViewKeysAreUnique() {
}

private synchronized int getNextOrder() {
return getAllViews().stream().max(Comparator.comparingInt(View::getOrder)).map(View::getOrder).orElse(0) + 1;
return getViews().stream().max(Comparator.comparingInt(View::getOrder)).map(View::getOrder).orElse(0) + 1;
}

/**
Expand Down

0 comments on commit 84a5664

Please sign in to comment.