From 228c5f003488692698137b38ec79fa6dc952f571 Mon Sep 17 00:00:00 2001 From: Gabriel Roldan Date: Wed, 13 Mar 2024 21:20:47 -0300 Subject: [PATCH] plugin: fix webui model's mutability of collection properties Fix mutability of collection properties in `MutableAccessRequest` and `MutableLayerDetails` broken in commit 7883f704c01f4186c8adaac142dcca273f8513ac "Replace Stream.collect(Collectors.toList()) by Stream.toList()" --- .../model/MutableAccessRequest.java | 7 +++++- .../model/MutableLayerDetails.java | 24 ++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/plugin/web/src/main/java/org/geoserver/acl/plugin/web/accessrules/model/MutableAccessRequest.java b/src/plugin/web/src/main/java/org/geoserver/acl/plugin/web/accessrules/model/MutableAccessRequest.java index 4a57359..e8292f3 100644 --- a/src/plugin/web/src/main/java/org/geoserver/acl/plugin/web/accessrules/model/MutableAccessRequest.java +++ b/src/plugin/web/src/main/java/org/geoserver/acl/plugin/web/accessrules/model/MutableAccessRequest.java @@ -17,7 +17,7 @@ public class MutableAccessRequest implements Serializable { private String user; - private Set roles = new HashSet<>(); + private final Set roles = new HashSet<>(); private String sourceAddress; private String service; @@ -27,6 +27,11 @@ public class MutableAccessRequest implements Serializable { private String workspace; private String layer; + public void setRoles(Set roles) { + this.roles.clear(); + if (roles != null) this.roles.addAll(roles); + } + public AccessRequest toRequest() { return AccessRequest.builder() .layer(layer) diff --git a/src/plugin/web/src/main/java/org/geoserver/acl/plugin/web/accessrules/model/MutableLayerDetails.java b/src/plugin/web/src/main/java/org/geoserver/acl/plugin/web/accessrules/model/MutableLayerDetails.java index 83bbedc..5be2947 100644 --- a/src/plugin/web/src/main/java/org/geoserver/acl/plugin/web/accessrules/model/MutableLayerDetails.java +++ b/src/plugin/web/src/main/java/org/geoserver/acl/plugin/web/accessrules/model/MutableLayerDetails.java @@ -37,8 +37,8 @@ public class MutableLayerDetails implements Serializable { private MultiPolygon area; private SpatialFilterType spatialFilterType; private CatalogMode catalogMode; - private Set allowedStyles = new TreeSet<>(); - private List attributes = new ArrayList<>(); + private final Set allowedStyles = new TreeSet<>(); + private final List attributes = new ArrayList<>(); public MutableLayerDetails() {} @@ -50,17 +50,25 @@ public MutableLayerDetails(@NonNull LayerDetails ld) { setArea(ld.getArea()); setCatalogMode(ld.getCatalogMode()); setSpatialFilterType(ld.getSpatialFilterType()); - setAllowedStyles(new TreeSet<>(ld.getAllowedStyles())); + setAllowedStyles(ld.getAllowedStyles()); setAttributes(ld.getAttributes().stream().map(MutableLayerAttribute::new).toList()); } + public void setAllowedStyles(Set styles) { + this.allowedStyles.clear(); + if (null != styles) this.allowedStyles.addAll(styles); + } + + public void setAttributes(List list) { + this.attributes.clear(); + if (null != list) this.attributes.addAll(list); + } + public LayerDetails toLayerDetails() { Set atts = - attributes == null || attributes.isEmpty() - ? Set.of() - : attributes.stream() - .map(MutableLayerAttribute::toLayerAttribute) - .collect(Collectors.toSet()); + attributes.stream() + .map(MutableLayerAttribute::toLayerAttribute) + .collect(Collectors.toSet()); Builder builder = LayerDetails.builder() .type(layerType)