From 000c1b9bceedd3328606a8156643be9c5304def4 Mon Sep 17 00:00:00 2001 From: Gabriel Roldan Date: Wed, 6 Dec 2023 22:23:02 -0300 Subject: [PATCH] qa: Resolve consistency code smells --- .../cloud/event/config/ConfigInfoAdded.java | 34 +++++++------- .../event/config/ConfigInfoModified.java | 37 ++++++--------- .../cloud/event/config/ConfigInfoRemoved.java | 17 +++---- .../ResolvingCatalogFacadeDecorator.java | 45 ++++++++++++++++++- 4 files changed, 82 insertions(+), 51 deletions(-) diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ConfigInfoAdded.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ConfigInfoAdded.java index e11ecb8d4..47206e799 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ConfigInfoAdded.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ConfigInfoAdded.java @@ -25,14 +25,14 @@ @JsonSubTypes.Type(value = SettingsAdded.class), }) @SuppressWarnings("serial") -public abstract class ConfigInfoAdded extends InfoAdded +public abstract class ConfigInfoAdded extends InfoAdded implements ConfigInfoEvent { protected ConfigInfoAdded() { // default constructor, needed for deserialization } - protected ConfigInfoAdded(long updateSequence, INFO object) { + protected ConfigInfoAdded(long updateSequence, I object) { super(updateSequence, object); } @@ -41,22 +41,18 @@ protected ConfigInfoAdded(long updateSequence, INFO object) { long updateSequence, @NonNull I info) { final ConfigInfoType type = ConfigInfoType.valueOf(info); - switch (type) { - case GeoServerInfo: - return (ConfigInfoAdded) - GeoServerInfoSet.createLocal(updateSequence, (GeoServerInfo) info); - case ServiceInfo: - return (ConfigInfoAdded) - ServiceAdded.createLocal(updateSequence, (ServiceInfo) info); - case SettingsInfo: - return (ConfigInfoAdded) - SettingsAdded.createLocal(updateSequence, (SettingsInfo) info); - case LoggingInfo: - return (ConfigInfoAdded) - LoggingInfoSet.createLocal(updateSequence, (LoggingInfo) info); - default: - throw new IllegalArgumentException( - "Uknown or unsupported config Info type: " + type + ". " + info); - } + return (ConfigInfoAdded) + switch (type) { + case GeoServerInfo -> GeoServerInfoSet.createLocal( + updateSequence, (GeoServerInfo) info); + case ServiceInfo -> ServiceAdded.createLocal( + updateSequence, (ServiceInfo) info); + case SettingsInfo -> SettingsAdded.createLocal( + updateSequence, (SettingsInfo) info); + case LoggingInfo -> LoggingInfoSet.createLocal( + updateSequence, (LoggingInfo) info); + default -> throw new IllegalArgumentException( + "Uknown or unsupported config Info type: " + type + ". " + info); + }; } } diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ConfigInfoModified.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ConfigInfoModified.java index 2f7e081ab..bafc1c910 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ConfigInfoModified.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ConfigInfoModified.java @@ -26,7 +26,7 @@ @JsonSubTypes.Type(value = SettingsModified.class), }) @SuppressWarnings("serial") -public abstract class ConfigInfoModified extends InfoModified +public abstract class ConfigInfoModified extends InfoModified implements ConfigInfoEvent { protected ConfigInfoModified() { @@ -46,27 +46,18 @@ protected ConfigInfoModified( long updateSequence, @NonNull Info info, @NonNull Patch patch) { final ConfigInfoType type = ConfigInfoType.valueOf(info); - switch (type) { - case GeoServerInfo: - { - return (ConfigInfoModified) - GeoServerInfoModified.createLocal( - updateSequence, (GeoServerInfo) info, patch); - } - case ServiceInfo: - ServiceInfo service = (ServiceInfo) info; - return (ConfigInfoModified) - ServiceModified.createLocal(updateSequence, service, patch); - case SettingsInfo: - SettingsInfo settings = (SettingsInfo) info; - return (ConfigInfoModified) - SettingsModified.createLocal(updateSequence, settings, patch); - case LoggingInfo: - return (ConfigInfoModified) - LoggingInfoModified.createLocal(updateSequence, (LoggingInfo) info, patch); - default: - throw new IllegalArgumentException( - "Uknown or unsupported config Info type: " + type + ". " + info); - } + return (ConfigInfoModified) + switch (type) { + case GeoServerInfo -> GeoServerInfoModified.createLocal( + updateSequence, (GeoServerInfo) info, patch); + case ServiceInfo -> ServiceModified.createLocal( + updateSequence, (ServiceInfo) info, patch); + case SettingsInfo -> SettingsModified.createLocal( + updateSequence, (SettingsInfo) info, patch); + case LoggingInfo -> LoggingInfoModified.createLocal( + updateSequence, (LoggingInfo) info, patch); + default -> throw new IllegalArgumentException( + "Uknown or unsupported config Info type: " + type + ". " + info); + }; } } diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ConfigInfoRemoved.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ConfigInfoRemoved.java index a5085e6a9..d4049bfb1 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ConfigInfoRemoved.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ConfigInfoRemoved.java @@ -38,13 +38,14 @@ protected ConfigInfoRemoved( long updateSequence, @NonNull I info) { final ConfigInfoType type = ConfigInfoType.valueOf(info); - return switch (type) { - case ServiceInfo -> (ConfigInfoRemoved) - ServiceRemoved.createLocal(updateSequence, (ServiceInfo) info); - case SettingsInfo -> (ConfigInfoRemoved) - SettingsRemoved.createLocal(updateSequence, (SettingsInfo) info); - default -> throw new IllegalArgumentException( - "Uknown or unsupported config Info type: " + type + ". " + info); - }; + return (ConfigInfoRemoved) + switch (type) { + case ServiceInfo -> ServiceRemoved.createLocal( + updateSequence, (ServiceInfo) info); + case SettingsInfo -> SettingsRemoved.createLocal( + updateSequence, (SettingsInfo) info); + default -> throw new IllegalArgumentException( + "Uknown or unsupported config Info type: " + type + ". " + info); + }; } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ResolvingCatalogFacadeDecorator.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ResolvingCatalogFacadeDecorator.java index 3615df398..2def88014 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ResolvingCatalogFacadeDecorator.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ResolvingCatalogFacadeDecorator.java @@ -409,41 +409,81 @@ public List getStylesByWorkspace(WorkspaceInfo workspace) { return resolveOutbound(super.getStylesByWorkspace(workspace)); } + /** + * @deprecated as per {@link ExtendedCatalogFacade#save(WorkspaceInfo)} use {@link + * #update(CatalogInfo, Patch)} instead + */ + @Deprecated(since = "1.0") @Override public void save(WorkspaceInfo info) { super.save(resolveInbound(info)); } + /** + * @deprecated as per {@link ExtendedCatalogFacade#save(NamespaceInfo)} use {@link + * #update(CatalogInfo, Patch)} instead + */ + @Deprecated(since = "1.0") @Override public void save(NamespaceInfo info) { super.save(resolveInbound(info)); } + /** + * @deprecated as per {@link ExtendedCatalogFacade#save(StoreInfo)} use {@link + * #update(CatalogInfo, Patch)} instead + */ + @Deprecated(since = "1.0") @Override public void save(StoreInfo info) { super.save(resolveInbound(info)); } + /** + * @deprecated as per {@link ExtendedCatalogFacade#save(ResourceInfo)} use {@link + * #update(CatalogInfo, Patch)} instead + */ + @Deprecated(since = "1.0") @Override public void save(ResourceInfo info) { super.save(resolveInbound(info)); } + /** + * @deprecated as per {@link ExtendedCatalogFacade#save(LayerInfo)} use {@link + * #update(CatalogInfo, Patch)} instead + */ + @Deprecated(since = "1.0") @Override public void save(LayerInfo info) { super.save(resolveInbound(info)); } + /** + * @deprecated as per {@link ExtendedCatalogFacade#save(LayerGroupInfo)} use {@link + * #update(CatalogInfo, Patch)} instead + */ + @Deprecated(since = "1.0") @Override public void save(LayerGroupInfo info) { super.save(resolveInbound(info)); } + /** + * @deprecated as per {@link ExtendedCatalogFacade#save(StyleInfo)} use {@link + * #update(CatalogInfo, Patch)} instead + */ + @Deprecated(since = "1.0") @Override public void save(StyleInfo info) { super.save(resolveInbound(info)); } + /** + * @deprecated as per {@link ExtendedCatalogFacade#save(MapInfo)} use {@link + * #update(CatalogInfo, Patch)} instead + */ + @Deprecated(since = "1.0") @Override public void save(MapInfo info) { super.save(resolveInbound(info)); @@ -489,11 +529,14 @@ public void remove(MapInfo info) { super.remove(resolveInbound(info)); } + /** + * @deprecated as per {@link ExtendedCatalogFacade#list()} use {@link #query(Query)} instead + */ + @Deprecated(since = "1.0") @Override public CloseableIterator list( Class of, Filter filter, Integer offset, Integer count, SortBy... sortOrder) { - @SuppressWarnings("deprecation") final CloseableIterator orig = facade().list(of, filter, offset, count, sortOrder); return CloseableIteratorAdapter.transform(orig, this::resolveOutbound); }