diff --git a/src/apps/geoserver/gwc/src/main/java/org/geoserver/cloud/gwc/app/GeoWebCacheApplicationConfiguration.java b/src/apps/geoserver/gwc/src/main/java/org/geoserver/cloud/gwc/app/GeoWebCacheApplicationConfiguration.java index de39aee60..00900ec44 100644 --- a/src/apps/geoserver/gwc/src/main/java/org/geoserver/cloud/gwc/app/GeoWebCacheApplicationConfiguration.java +++ b/src/apps/geoserver/gwc/src/main/java/org/geoserver/cloud/gwc/app/GeoWebCacheApplicationConfiguration.java @@ -62,6 +62,7 @@ public void configureContentNegotiation(ContentNegotiationConfigurer configurer) */ @SuppressWarnings("deprecation") @Bean + @Override public RequestMappingHandlerMapping requestMappingHandlerMapping( @Qualifier("mvcContentNegotiationManager") ContentNegotiationManager contentNegotiationManager, @@ -102,17 +103,20 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha protected ServletRequest adaptRequest(HttpServletRequest request) { final String requestURI = request.getRequestURI(); - final int restIdx = requestURI.indexOf("/rest"); + final String restBasePath = "/rest"; + final int restIdx = requestURI.indexOf(restBasePath); if (restIdx > -1) { - final String pathToRest = requestURI.substring(0, restIdx + "/rest".length()); + final String pathToRest = requestURI.substring(0, restIdx + restBasePath.length()); final String pathInfo = requestURI.substring(pathToRest.length()); return new HttpServletRequestWrapper(request) { - public @Override String getServletPath() { - return "/rest"; + @Override + public String getServletPath() { + return restBasePath; } - public @Override String getPathInfo() { + @Override + public String getPathInfo() { return pathInfo; } }; diff --git a/src/apps/geoserver/gwc/src/test/java/org/geoserver/cloud/gwc/app/GeoWebCacheApplicationTest.java b/src/apps/geoserver/gwc/src/test/java/org/geoserver/cloud/gwc/app/GeoWebCacheApplicationTest.java index b19096eaa..705422058 100644 --- a/src/apps/geoserver/gwc/src/test/java/org/geoserver/cloud/gwc/app/GeoWebCacheApplicationTest.java +++ b/src/apps/geoserver/gwc/src/test/java/org/geoserver/cloud/gwc/app/GeoWebCacheApplicationTest.java @@ -25,7 +25,7 @@ @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @ActiveProfiles("test") -public class GeoWebCacheApplicationTest { +class GeoWebCacheApplicationTest { @Autowired private TestRestTemplate restTemplate; @@ -37,7 +37,7 @@ void before() { } @Test - public void testRESTDefaultContentType() throws ParseException { + void testRESTDefaultContentType() throws ParseException { ResponseEntity response = testGetRequestContentType("/gwc/rest/layers", APPLICATION_JSON); JsonElement parsed = JsonParser.parseString(response.getBody()); @@ -45,7 +45,7 @@ public void testRESTDefaultContentType() throws ParseException { } @Test - public void testRESTPathExtensionContentNegotiation() { + void testRESTPathExtensionContentNegotiation() { ResponseEntity response = testGetRequestContentType("/gwc/rest/layers.json", APPLICATION_JSON); JsonElement parsed = JsonParser.parseString(response.getBody()); diff --git a/src/apps/geoserver/restconfig/src/main/java/org/geoserver/cloud/restconfig/RestConfigApplicationConfiguration.java b/src/apps/geoserver/restconfig/src/main/java/org/geoserver/cloud/restconfig/RestConfigApplicationConfiguration.java index f687f74bd..f57c9b3d0 100644 --- a/src/apps/geoserver/restconfig/src/main/java/org/geoserver/cloud/restconfig/RestConfigApplicationConfiguration.java +++ b/src/apps/geoserver/restconfig/src/main/java/org/geoserver/cloud/restconfig/RestConfigApplicationConfiguration.java @@ -56,6 +56,7 @@ public void configureContentNegotiation(ContentNegotiationConfigurer configurer) * https://github.com/spring-projects/spring-framework/issues/24179} */ @Bean + @Override public RequestMappingHandlerMapping requestMappingHandlerMapping( @Qualifier("mvcContentNegotiationManager") ContentNegotiationManager contentNegotiationManager, @@ -68,8 +69,6 @@ public RequestMappingHandlerMapping requestMappingHandlerMapping( handlerMapping.setUseSuffixPatternMatch(true); handlerMapping.setUseRegisteredSuffixPatternMatch(true); - // handlerMapping.setUseTrailingSlashMatch(true); - // handlerMapping.setAlwaysUseFullPath(true); return handlerMapping; } @@ -98,17 +97,20 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha protected ServletRequest adaptRequest(HttpServletRequest request) { final String requestURI = request.getRequestURI(); - final int restIdx = requestURI.indexOf("/rest"); + final String restBasePath = "/rest"; + final int restIdx = requestURI.indexOf(restBasePath); if (restIdx > -1) { - final String pathToRest = requestURI.substring(0, restIdx + "/rest".length()); + final String pathToRest = requestURI.substring(0, restIdx + restBasePath.length()); final String pathInfo = requestURI.substring(pathToRest.length()); return new HttpServletRequestWrapper(request) { - public @Override String getServletPath() { - return "/rest"; + @Override + public String getServletPath() { + return restBasePath; } - public @Override String getPathInfo() { + @Override + public String getPathInfo() { return pathInfo; } }; diff --git a/src/apps/geoserver/restconfig/src/test/java/org/geoserver/cloud/restconfig/RestConfigApplicationTest.java b/src/apps/geoserver/restconfig/src/test/java/org/geoserver/cloud/restconfig/RestConfigApplicationTest.java index 49b20f254..f9b8c677c 100644 --- a/src/apps/geoserver/restconfig/src/test/java/org/geoserver/cloud/restconfig/RestConfigApplicationTest.java +++ b/src/apps/geoserver/restconfig/src/test/java/org/geoserver/cloud/restconfig/RestConfigApplicationTest.java @@ -23,7 +23,7 @@ @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @ActiveProfiles("test") -public class RestConfigApplicationTest { +class RestConfigApplicationTest { @Autowired private TestRestTemplate restTemplate; @@ -33,14 +33,14 @@ void before() { } @Test - public void testDefaultContentType() { + void testDefaultContentType() { testPathExtensionContentType("/rest/workspaces", APPLICATION_JSON); testPathExtensionContentType("/rest/layers", APPLICATION_JSON); } @Test - public void testPathExtensionContentNegotiation() { + void testPathExtensionContentNegotiation() { testPathExtensionContentType("/rest/styles/line.json", APPLICATION_JSON); testPathExtensionContentType("/rest/styles/line.xml", APPLICATION_XML); diff --git a/src/apps/geoserver/wcs/src/main/java/org/geoserver/cloud/wcs/WCSController.java b/src/apps/geoserver/wcs/src/main/java/org/geoserver/cloud/wcs/WCSController.java index a1658a7ce..1aba1b550 100644 --- a/src/apps/geoserver/wcs/src/main/java/org/geoserver/cloud/wcs/WCSController.java +++ b/src/apps/geoserver/wcs/src/main/java/org/geoserver/cloud/wcs/WCSController.java @@ -4,9 +4,11 @@ */ package org.geoserver.cloud.wcs; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import org.geoserver.cloud.virtualservice.VirtualServiceVerifier; import org.geoserver.ows.Dispatcher; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -16,13 +18,14 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +@RequiredArgsConstructor public @Controller class WCSController { - private @Autowired Dispatcher geoserverDispatcher; + private final @NonNull Dispatcher geoserverDispatcher; - private @Autowired org.geoserver.ows.ClasspathPublisher classPathPublisher; + private final @NonNull org.geoserver.ows.ClasspathPublisher classPathPublisher; - private @Autowired VirtualServiceVerifier virtualServiceVerifier; + private final @NonNull VirtualServiceVerifier virtualServiceVerifier; @GetMapping("/") public RedirectView redirectRootToGetCapabilities() { diff --git a/src/apps/geoserver/wcs/src/main/java/org/geoserver/cloud/wcs/WcsApplicationConfiguration.java b/src/apps/geoserver/wcs/src/main/java/org/geoserver/cloud/wcs/WcsApplicationConfiguration.java index 0ee7d42d5..6b82d84e9 100644 --- a/src/apps/geoserver/wcs/src/main/java/org/geoserver/cloud/wcs/WcsApplicationConfiguration.java +++ b/src/apps/geoserver/wcs/src/main/java/org/geoserver/cloud/wcs/WcsApplicationConfiguration.java @@ -4,8 +4,10 @@ */ package org.geoserver.cloud.wcs; +import org.geoserver.catalog.Catalog; import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; import org.geoserver.cloud.virtualservice.VirtualServiceVerifier; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; @@ -22,7 +24,7 @@ public class WcsApplicationConfiguration { @Bean - VirtualServiceVerifier virtualServiceVerifier() { - return new VirtualServiceVerifier(); + VirtualServiceVerifier virtualServiceVerifier(@Qualifier("rawCatalog") Catalog catalog) { + return new VirtualServiceVerifier(catalog); } } diff --git a/src/apps/geoserver/wcs/src/test/java/org/geoserver/cloud/wcs/WcsApplicationTest.java b/src/apps/geoserver/wcs/src/test/java/org/geoserver/cloud/wcs/WcsApplicationTest.java index 9d2d1bf2b..7c13217e5 100644 --- a/src/apps/geoserver/wcs/src/test/java/org/geoserver/cloud/wcs/WcsApplicationTest.java +++ b/src/apps/geoserver/wcs/src/test/java/org/geoserver/cloud/wcs/WcsApplicationTest.java @@ -10,8 +10,8 @@ @SpringBootTest @ActiveProfiles("test") -public class WcsApplicationTest { +class WcsApplicationTest { @Test - public void contextLoads() {} + void contextLoads() {} } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/core/WebCoreConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/core/WebCoreConfiguration.java index 266207976..b96f1e0ec 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/core/WebCoreConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/core/WebCoreConfiguration.java @@ -41,21 +41,14 @@ TestWfsPost testWfsPostServlet() { @Bean ServletRegistrationBean geoServerWicketServletRegistration() { GeoServerWicketServlet servlet = geoServerWicketServlet(); - ServletRegistrationBean registration; - registration = - new ServletRegistrationBean(servlet, "/web", "/web/*"); - - return registration; + return new ServletRegistrationBean<>(servlet, "/web", "/web/*"); } /** Register the {@link TestWfsPost servlet} */ @Bean ServletRegistrationBean wfsTestServletRegistration() { TestWfsPost servlet = testWfsPostServlet(); - ServletRegistrationBean registration; - registration = new ServletRegistrationBean(servlet, "/TestWfsPost"); - - return registration; + return new ServletRegistrationBean<>(servlet, "/TestWfsPost"); } @Bean @@ -63,7 +56,6 @@ HeaderContribution geoserverCloudCssTheme() { HeaderContribution contribution = new HeaderContribution(); contribution.setScope(GeoServerBasePage.class); contribution.setCSSFilename("geoserver-cloud.css"); - // contribution.setFaviconFilename("favicon.ico"); return contribution; } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/core/WebUIApplicationAutoConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/core/WebUIApplicationAutoConfiguration.java index 830964273..88fd6ba6a 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/core/WebUIApplicationAutoConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/core/WebUIApplicationAutoConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.core; -import lombok.extern.slf4j.Slf4j; - import org.geoserver.cloud.autoconfigure.core.GeoServerWebMvcMainAutoConfiguration; import org.geoserver.cloud.autoconfigure.web.demo.DemosAutoConfiguration; import org.geoserver.cloud.autoconfigure.web.extension.ExtensionsAutoConfiguration; @@ -15,16 +13,11 @@ import org.geoserver.cloud.autoconfigure.web.wfs.WfsAutoConfiguration; import org.geoserver.cloud.autoconfigure.web.wms.WmsAutoConfiguration; import org.geoserver.cloud.autoconfigure.web.wps.WpsAutoConfiguration; -import org.geoserver.config.GeoServer; -import org.geoserver.config.GeoServerInfo; -import org.geoserver.config.GeoServerInfo.WebUIMode; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.core.env.Environment; -import javax.annotation.PostConstruct; - @AutoConfiguration(after = {GeoServerWebMvcMainAutoConfiguration.class}) @Import({ // WebCoreConfiguration.class, // this one is mandatory @@ -37,27 +30,10 @@ DemosAutoConfiguration.class, ToolsAutoConfiguration.class }) -@Slf4j public class WebUIApplicationAutoConfiguration { - private @Autowired GeoServer geoServer; - private @Autowired Environment environment; - - public @PostConstruct void setDefaults() { - GeoServerInfo global = geoServer.getGlobal(); - WebUIMode webUIMode = global.getWebUIMode(); - if (!WebUIMode.DO_NOT_REDIRECT.equals(webUIMode)) { - log.info("Forcing web-ui mode to DO_NOT_REDIRECT, was {}", webUIMode); - global.setWebUIMode(WebUIMode.DO_NOT_REDIRECT); - geoServer.save(global); - } - - Boolean hidefs = - environment.getProperty( - "geoserver.web-ui.file-browser.hide-file-system", Boolean.class); - if (Boolean.TRUE.equals(hidefs)) { - log.info("Setting GEOSERVER_FILEBROWSER_HIDEFS=true System Property"); - System.setProperty("GEOSERVER_FILEBROWSER_HIDEFS", "true"); - } + @Bean + WebUIInitializer webUIDefaultsInitializer(Environment env) { + return new WebUIInitializer(env); } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/core/WebUIInitializer.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/core/WebUIInitializer.java new file mode 100644 index 000000000..95b9c8bfd --- /dev/null +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/core/WebUIInitializer.java @@ -0,0 +1,41 @@ +/* + * (c) 2020 Open Source Geospatial Foundation - all rights reserved This code is licensed under the + * GPL 2.0 license, available at the root application directory. + */ +package org.geoserver.cloud.autoconfigure.web.core; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +import org.geoserver.config.GeoServer; +import org.geoserver.config.GeoServerInfo; +import org.geoserver.config.GeoServerInfo.WebUIMode; +import org.geoserver.config.GeoServerInitializer; +import org.springframework.core.env.Environment; + +@Slf4j +@RequiredArgsConstructor +class WebUIInitializer implements GeoServerInitializer { + + private final @NonNull Environment environment; + + @Override + public void initialize(GeoServer geoServer) throws Exception { + GeoServerInfo global = geoServer.getGlobal(); + WebUIMode webUIMode = global.getWebUIMode(); + if (!WebUIMode.DO_NOT_REDIRECT.equals(webUIMode)) { + log.info("Forcing web-ui mode to DO_NOT_REDIRECT, was {}", webUIMode); + global.setWebUIMode(WebUIMode.DO_NOT_REDIRECT); + geoServer.save(global); + } + + Boolean hidefs = + environment.getProperty( + "geoserver.web-ui.file-browser.hide-file-system", Boolean.class); + if (Boolean.TRUE.equals(hidefs)) { + log.info("Setting GEOSERVER_FILEBROWSER_HIDEFS=true System Property"); + System.setProperty("GEOSERVER_FILEBROWSER_HIDEFS", "true"); + } + } +} diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/DemoRequestsConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/DemoRequestsConfiguration.java index 50df61898..b164ff16b 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/DemoRequestsConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/DemoRequestsConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.demo; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -27,5 +25,8 @@ public class DemoRequestsConfiguration extends AbstractWebUIAutoConfiguration { static final String CONFIG_PREFIX = DemosAutoConfiguration.CONFIG_PREFIX + ".demo-requests"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/DemosAutoConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/DemosAutoConfiguration.java index 778468b2c..e371953ce 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/DemosAutoConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/DemosAutoConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.demo; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -31,5 +29,8 @@ public class DemosAutoConfiguration extends AbstractWebUIAutoConfiguration { static final String CONFIG_PREFIX = "geoserver.web-ui.demos"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/LayerPreviewConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/LayerPreviewConfiguration.java index b2c9bb974..3bff28e92 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/LayerPreviewConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/LayerPreviewConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.demo; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.geoserver.cloud.autoconfigure.web.demo.LayerPreviewConfiguration.GmlCommonFormatsConfiguration; import org.geoserver.cloud.autoconfigure.web.demo.LayerPreviewConfiguration.KmlCommonFormatsConfiguration; @@ -37,7 +35,10 @@ public class LayerPreviewConfiguration extends AbstractWebUIAutoConfiguration { static final String CONFIG_PREFIX = "geoserver.web-ui.demos.layer-preview-page"; static final String COMMON_FORMATS_PREFIX = CONFIG_PREFIX + ".common-formats"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } @Configuration @ConditionalOnProperty( @@ -53,7 +54,10 @@ public class OpenLayersCommonFormatsConfiguration extends AbstractWebUIAutoConfi static final String CONFIG_PREFIX = LayerPreviewConfiguration.COMMON_FORMATS_PREFIX + ".open-layers"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } @Configuration @@ -70,7 +74,10 @@ public class GmlCommonFormatsConfiguration extends AbstractWebUIAutoConfiguratio static final String CONFIG_PREFIX = LayerPreviewConfiguration.COMMON_FORMATS_PREFIX + ".gml"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } @Configuration @@ -87,6 +94,9 @@ public class KmlCommonFormatsConfiguration extends AbstractWebUIAutoConfiguratio static final String CONFIG_PREFIX = LayerPreviewConfiguration.COMMON_FORMATS_PREFIX + ".kml"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/ReprojectionConsoleConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/ReprojectionConsoleConfiguration.java index 4f3e998df..ae58e622c 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/ReprojectionConsoleConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/ReprojectionConsoleConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.demo; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -28,5 +26,8 @@ public class ReprojectionConsoleConfiguration extends AbstractWebUIAutoConfigura static final String CONFIG_PREFIX = DemosAutoConfiguration.CONFIG_PREFIX + ".reprojection-console"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/SrsListConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/SrsListConfiguration.java index 5abdc2677..10900cb32 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/SrsListConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/SrsListConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.demo; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -27,5 +25,8 @@ public class SrsListConfiguration extends AbstractWebUIAutoConfiguration { static final String CONFIG_PREFIX = DemosAutoConfiguration.CONFIG_PREFIX + ".srs-list"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/WcsRequestBuilderConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/WcsRequestBuilderConfiguration.java index b14410c8d..0d0c4dde4 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/WcsRequestBuilderConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/WcsRequestBuilderConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.demo; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -31,5 +29,8 @@ public class WcsRequestBuilderConfiguration extends AbstractWebUIAutoConfigurati static final String CONFIG_PREFIX = DemosAutoConfiguration.CONFIG_PREFIX + ".wcs-request-builder"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/WpsRequestBuilderConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/WpsRequestBuilderConfiguration.java index 78ab28710..d919ef0eb 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/WpsRequestBuilderConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/demo/WpsRequestBuilderConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.demo; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -28,5 +26,8 @@ public class WpsRequestBuilderConfiguration extends AbstractWebUIAutoConfigurati static final String CONFIG_PREFIX = DemosAutoConfiguration.CONFIG_PREFIX + ".wps-request-builder"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/extension/importer/ImporterAutoConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/extension/importer/ImporterAutoConfiguration.java index b324b570c..e9cb425ce 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/extension/importer/ImporterAutoConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/extension/importer/ImporterAutoConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.extension.importer; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -24,5 +22,8 @@ public class ImporterAutoConfiguration extends AbstractWebUIAutoConfiguration { static final String CONFIG_PREFIX = "geoserver.web-ui.extensions.importer"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/security/SecurityAutoConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/security/SecurityAutoConfiguration.java index 5e0fde797..7e3c96ac1 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/security/SecurityAutoConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/security/SecurityAutoConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.security; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -24,5 +22,8 @@ public class SecurityAutoConfiguration extends AbstractWebUIAutoConfiguration { static final String CONFIG_PREFIX = "geoserver.web-ui.security"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/tools/CatalogBulkLoadToolConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/tools/CatalogBulkLoadToolConfiguration.java index c3e1e12a4..8e3b2f432 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/tools/CatalogBulkLoadToolConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/tools/CatalogBulkLoadToolConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.tools; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -27,5 +25,8 @@ public class CatalogBulkLoadToolConfiguration extends AbstractWebUIAutoConfigura static final String CONFIG_PREFIX = ToolsAutoConfiguration.CONFIG_PREFIX + ".catalog-bulk-load"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/tools/ReprojectionConsoleConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/tools/ReprojectionConsoleConfiguration.java index d0af32bf4..719526ae6 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/tools/ReprojectionConsoleConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/tools/ReprojectionConsoleConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.tools; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -28,5 +26,8 @@ public class ReprojectionConsoleConfiguration extends AbstractWebUIAutoConfigura static final String CONFIG_PREFIX = ToolsAutoConfiguration.CONFIG_PREFIX + ".reprojection-console"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/tools/ResourceBrowserConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/tools/ResourceBrowserConfiguration.java index 1c85e4645..1a214d6da 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/tools/ResourceBrowserConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/tools/ResourceBrowserConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.tools; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -34,5 +32,8 @@ public class ResourceBrowserConfiguration extends AbstractWebUIAutoConfiguration static final String CONFIG_PREFIX = ToolsAutoConfiguration.CONFIG_PREFIX + ".resource-browser"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/tools/ToolsAutoConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/tools/ToolsAutoConfiguration.java index 73e8e87b0..787d39442 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/tools/ToolsAutoConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/tools/ToolsAutoConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.tools; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Configuration; @@ -26,5 +24,8 @@ public class ToolsAutoConfiguration extends AbstractWebUIAutoConfiguration { static final String CONFIG_PREFIX = "geoserver.web-ui.tools"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/wcs/WcsAutoConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/wcs/WcsAutoConfiguration.java index 5acb3ad2d..77ac55563 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/wcs/WcsAutoConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/wcs/WcsAutoConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.wcs; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -24,5 +22,8 @@ public class WcsAutoConfiguration extends AbstractWebUIAutoConfiguration { static final String CONFIG_PREFIX = "geoserver.web-ui.wcs"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/wfs/WfsAutoConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/wfs/WfsAutoConfiguration.java index 78500e57f..4e7a339c5 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/wfs/WfsAutoConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/wfs/WfsAutoConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.wfs; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -24,5 +22,8 @@ public class WfsAutoConfiguration extends AbstractWebUIAutoConfiguration { static final String CONFIG_PREFIX = "geoserver.web-ui.wfs"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/wms/WmsAutoConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/wms/WmsAutoConfiguration.java index 286ceb738..147602a38 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/wms/WmsAutoConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/wms/WmsAutoConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.wms; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -24,5 +22,8 @@ public class WmsAutoConfiguration extends AbstractWebUIAutoConfiguration { static final String CONFIG_PREFIX = "geoserver.web-ui.wms"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/wps/WpsAutoConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/wps/WpsAutoConfiguration.java index 93ea5e0c3..793ff790b 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/wps/WpsAutoConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/autoconfigure/web/wps/WpsAutoConfiguration.java @@ -4,8 +4,6 @@ */ package org.geoserver.cloud.autoconfigure.web.wps; -import lombok.Getter; - import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -24,5 +22,8 @@ public class WpsAutoConfiguration extends AbstractWebUIAutoConfiguration { static final String CONFIG_PREFIX = "geoserver.web-ui.wps"; - private final @Getter String configPrefix = CONFIG_PREFIX; + @Override + public String getConfigPrefix() { + return CONFIG_PREFIX; + } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/service/ServiceInstance.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/service/ServiceInstance.java index 7ef6e09fa..860500fe6 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/service/ServiceInstance.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/service/ServiceInstance.java @@ -19,7 +19,8 @@ private String uri; private String status; - public @Override int compareTo(ServiceInstance o) { + @Override + public int compareTo(ServiceInstance o) { int c = getName().compareTo(o.getName()); if (c == 0) { c = getInstanceId().compareTo(o.getInstanceId()); diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/service/ServiceInstanceRegistry.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/service/ServiceInstanceRegistry.java index fcd9e10fb..2b7abd4cb 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/service/ServiceInstanceRegistry.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/service/ServiceInstanceRegistry.java @@ -51,13 +51,11 @@ private ServiceInstance toService(org.springframework.cloud.client.ServiceInstan } private String getStatus(org.springframework.cloud.client.ServiceInstance i) { - if (i instanceof EurekaServiceInstance) { - EurekaServiceInstance e = (EurekaServiceInstance) i; + if (i instanceof EurekaServiceInstance e) { InstanceInfo instanceInfo = e.getInstanceInfo(); InstanceStatus status = instanceInfo.getStatus(); return status.toString(); } - // Map metadata = i.getMetadata(); return "UNKNOWN"; } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/service/WebUiCloudServicesConfiguration.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/service/WebUiCloudServicesConfiguration.java index 5e9770cee..b33e59bcd 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/service/WebUiCloudServicesConfiguration.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/service/WebUiCloudServicesConfiguration.java @@ -6,10 +6,12 @@ import org.geoserver.cloud.web.ui.GeoServerCloudHomePageContentProvider; import org.geoserver.cloud.web.ui.ServiceRegistryPage; +import org.geoserver.security.GeoServerSecurityManager; import org.geoserver.web.Category; import org.geoserver.web.ComponentAuthorizer; import org.geoserver.web.MenuPageInfo; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.info.BuildProperties; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -54,14 +56,14 @@ MenuPageInfo serviceRegistryMenuPage( menu.setTitleKey("ServiceRegistryPage.title"); menu.setDescriptionKey("ServiceRegistryPage.description"); menu.setComponentClass(ServiceRegistryPage.class); - // menu.setIcon(null); menu.setOrder(1000); menu.setAuthorizer(ComponentAuthorizer.ADMIN); return menu; } @Bean - GeoServerCloudHomePageContentProvider geoServerCloudHomePageContentProvider() { - return new GeoServerCloudHomePageContentProvider(); + GeoServerCloudHomePageContentProvider geoServerCloudHomePageContentProvider( + GeoServerSecurityManager secManager, BuildProperties props) { + return new GeoServerCloudHomePageContentProvider(secManager, props); } } diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/ui/GeoServerCloudHomePageContentProvider.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/ui/GeoServerCloudHomePageContentProvider.java index 8124c499e..22b9c0410 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/ui/GeoServerCloudHomePageContentProvider.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/ui/GeoServerCloudHomePageContentProvider.java @@ -4,11 +4,13 @@ */ package org.geoserver.cloud.web.ui; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import org.apache.wicket.Component; import org.apache.wicket.markup.html.WebMarkupContainer; import org.geoserver.security.GeoServerSecurityManager; import org.geoserver.web.GeoServerHomePageContentProvider; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.info.BuildProperties; /** @@ -16,11 +18,12 @@ * * @since 1.0 */ +@RequiredArgsConstructor public class GeoServerCloudHomePageContentProvider implements GeoServerHomePageContentProvider { - private @Autowired GeoServerSecurityManager secManager; + private final @NonNull GeoServerSecurityManager secManager; - private @Autowired BuildProperties buildProperties; + private final @NonNull BuildProperties buildProperties; @Override public Component getPageBodyComponent(String id) { diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/ui/GeoServerCloudStatusPanel.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/ui/GeoServerCloudStatusPanel.java index fd3f0d164..f6b3480c9 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/ui/GeoServerCloudStatusPanel.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/ui/GeoServerCloudStatusPanel.java @@ -11,7 +11,7 @@ /** * @since 1.0 */ -public class GeoServerCloudStatusPanel extends Panel { +class GeoServerCloudStatusPanel extends Panel { private static final long serialVersionUID = 1L; public GeoServerCloudStatusPanel(String id, BuildProperties buildInfo) { diff --git a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/ui/ServiceProvider.java b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/ui/ServiceProvider.java index 4bfb5c444..71bff507b 100644 --- a/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/ui/ServiceProvider.java +++ b/src/apps/geoserver/webui/src/main/java/org/geoserver/cloud/web/ui/ServiceProvider.java @@ -10,7 +10,6 @@ import org.geoserver.web.wicket.GeoServerDataProvider; import java.util.List; -import java.util.stream.Collectors; /** * @since 1.0 @@ -18,11 +17,11 @@ class ServiceProvider extends GeoServerDataProvider { private static final long serialVersionUID = 1L; - public static Property NAME = new BeanProperty<>("name", "name"); - public static Property INSTANCEID = + public static final Property NAME = new BeanProperty<>("name", "name"); + public static final Property INSTANCEID = new BeanProperty<>("instanceId", "instanceId"); - public static Property STATUS = new BeanProperty<>("status", "status"); - public static Property URI = new BeanProperty<>("uri", "uri"); + public static final Property STATUS = new BeanProperty<>("status", "status"); + public static final Property URI = new BeanProperty<>("uri", "uri"); protected @Override List> getProperties() { return List.of(NAME, STATUS, INSTANCEID, URI); @@ -31,6 +30,6 @@ class ServiceProvider extends GeoServerDataProvider { protected @Override List getItems() { GeoServerApplication webApp = GeoServerApplication.get(); ServiceInstanceRegistry registry = webApp.getBeanOfType(ServiceInstanceRegistry.class); - return registry.getServices().sorted().collect(Collectors.toList()); + return registry.getServices().sorted().toList(); } } diff --git a/src/apps/geoserver/webui/src/test/java/org/geoserver/cloud/web/app/AclIntegrationTest.java b/src/apps/geoserver/webui/src/test/java/org/geoserver/cloud/web/app/AclIntegrationTest.java index 71040dea3..ee63457c7 100644 --- a/src/apps/geoserver/webui/src/test/java/org/geoserver/cloud/web/app/AclIntegrationTest.java +++ b/src/apps/geoserver/webui/src/test/java/org/geoserver/cloud/web/app/AclIntegrationTest.java @@ -36,7 +36,7 @@ "logging.level.org.geoserver.acl: debug" }) @ActiveProfiles("test") // see bootstrap-test.yml -public class AclIntegrationTest { +class AclIntegrationTest { private @Autowired GeoServerApplication app; private WicketTester tester; @@ -81,7 +81,7 @@ protected void login(String username, String password, String... roles) { } @Test - public void HomePage_ACL_enabled_smoke_test() { + void HomePage_ACL_enabled_smoke_test() { login(); GeoServerHomePage page = tester.startPage(GeoServerHomePage.class); assertNotNull(page); diff --git a/src/apps/geoserver/webui/src/test/java/org/geoserver/cloud/web/app/WebUIApplicationTest.java b/src/apps/geoserver/webui/src/test/java/org/geoserver/cloud/web/app/WebUIApplicationTest.java index 5076ad404..5377472b9 100644 --- a/src/apps/geoserver/webui/src/test/java/org/geoserver/cloud/web/app/WebUIApplicationTest.java +++ b/src/apps/geoserver/webui/src/test/java/org/geoserver/cloud/web/app/WebUIApplicationTest.java @@ -44,7 +44,7 @@ "eureka.client.enabled: false" }) @ActiveProfiles("test") // see bootstrap-test.yml -public class WebUIApplicationTest { +class WebUIApplicationTest { private @Autowired GeoServerApplication app; private WicketTester tester; @@ -97,7 +97,7 @@ private void print(Component component) { } @Test - public void GeoServerHomePage_smoke_test_anonymous() { + void GeoServerHomePage_smoke_test_anonymous() { GeoServerHomePage page = tester.startPage(GeoServerHomePage.class); assertNotNull(page); // print(page); @@ -106,7 +106,7 @@ public void GeoServerHomePage_smoke_test_anonymous() { } @Test - public void GeoServerHomePage_smoke_test_logged_in() { + void GeoServerHomePage_smoke_test_logged_in() { login(); GeoServerHomePage page = tester.startPage(GeoServerHomePage.class); assertNotNull(page); @@ -118,14 +118,14 @@ public void GeoServerHomePage_smoke_test_logged_in() { } @Test - public void GlobalSettingsPage_smoke_test_loggedout() { + void GlobalSettingsPage_smoke_test_loggedout() { logout(); tester.startPage(GlobalSettingsPage.class); tester.assertRenderedPage(GeoServerLoginPage.class); } @Test - public void GlobalSettingsPage_smoke_test() { + void GlobalSettingsPage_smoke_test() { login(); tester.startPage(GlobalSettingsPage.class); tester.assertRenderedPage(GlobalSettingsPage.class); @@ -140,7 +140,7 @@ public void GlobalSettingsPage_smoke_test() { } @Test - public void GeoServerHomePage_smoke_test_service_links() { + void GeoServerHomePage_smoke_test_service_links() { GeoServerHomePage page = tester.startPage(GeoServerHomePage.class); assertNotNull(page); // print(page); diff --git a/src/apps/geoserver/wfs/src/main/java/org/geoserver/cloud/wfs/app/WFSController.java b/src/apps/geoserver/wfs/src/main/java/org/geoserver/cloud/wfs/app/WFSController.java index b22b5a803..770677987 100644 --- a/src/apps/geoserver/wfs/src/main/java/org/geoserver/cloud/wfs/app/WFSController.java +++ b/src/apps/geoserver/wfs/src/main/java/org/geoserver/cloud/wfs/app/WFSController.java @@ -4,9 +4,11 @@ */ package org.geoserver.cloud.wfs.app; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import org.geoserver.cloud.virtualservice.VirtualServiceVerifier; import org.geoserver.ows.Dispatcher; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -17,13 +19,14 @@ import javax.servlet.http.HttpServletResponse; @Controller +@RequiredArgsConstructor public class WFSController { - private @Autowired Dispatcher geoserverDispatcher; + private final @NonNull Dispatcher geoserverDispatcher; - private @Autowired org.geoserver.ows.ClasspathPublisher classPathPublisher; + private final @NonNull org.geoserver.ows.ClasspathPublisher classPathPublisher; - private @Autowired VirtualServiceVerifier virtualServiceVerifier; + private final @NonNull VirtualServiceVerifier virtualServiceVerifier; @GetMapping("/") public RedirectView redirectRootToGetCapabilities() { diff --git a/src/apps/geoserver/wfs/src/main/java/org/geoserver/cloud/wfs/config/WfsAutoConfiguration.java b/src/apps/geoserver/wfs/src/main/java/org/geoserver/cloud/wfs/config/WfsAutoConfiguration.java index 774c149b4..20d3aa8e8 100644 --- a/src/apps/geoserver/wfs/src/main/java/org/geoserver/cloud/wfs/config/WfsAutoConfiguration.java +++ b/src/apps/geoserver/wfs/src/main/java/org/geoserver/cloud/wfs/config/WfsAutoConfiguration.java @@ -4,9 +4,11 @@ */ package org.geoserver.cloud.wfs.config; +import org.geoserver.catalog.Catalog; import org.geoserver.cloud.autoconfigure.core.GeoServerWebMvcMainAutoConfiguration; import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; import org.geoserver.cloud.virtualservice.VirtualServiceVerifier; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ImportResource; @@ -22,7 +24,7 @@ public class WfsAutoConfiguration { @Bean - VirtualServiceVerifier virtualServiceVerifier() { - return new VirtualServiceVerifier(); + VirtualServiceVerifier virtualServiceVerifier(@Qualifier("rawCatalog") Catalog catalog) { + return new VirtualServiceVerifier(catalog); } } diff --git a/src/apps/geoserver/wfs/src/test/java/org/geoserver/cloud/wfs/app/WfsApplicationTest.java b/src/apps/geoserver/wfs/src/test/java/org/geoserver/cloud/wfs/app/WfsApplicationTest.java index 2ed16c1c0..578e75766 100644 --- a/src/apps/geoserver/wfs/src/test/java/org/geoserver/cloud/wfs/app/WfsApplicationTest.java +++ b/src/apps/geoserver/wfs/src/test/java/org/geoserver/cloud/wfs/app/WfsApplicationTest.java @@ -12,8 +12,8 @@ @SpringBootTest @EnableAutoConfiguration @ActiveProfiles("test") -public class WfsApplicationTest { +class WfsApplicationTest { @Test - public void contextLoads() {} + void contextLoads() {} } diff --git a/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/autoconfigure/wms/KMLAutoConfiguration.java b/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/autoconfigure/wms/KMLAutoConfiguration.java index 2bc05304f..462ffdf21 100644 --- a/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/autoconfigure/wms/KMLAutoConfiguration.java +++ b/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/autoconfigure/wms/KMLAutoConfiguration.java @@ -8,6 +8,9 @@ import org.geoserver.cloud.wms.controller.kml.KMLIconsController; import org.geoserver.cloud.wms.controller.kml.KMLReflectorController; import org.geoserver.community.mbstyle.MBStyleHandler; +import org.geoserver.ows.Dispatcher; +import org.geoserver.wms.icons.IconService; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; @@ -31,12 +34,12 @@ public class KMLAutoConfiguration { @Bean - KMLIconsController kmlIconsController() { - return new KMLIconsController(); + KMLIconsController kmlIconsController(@Qualifier("kmlIconService") IconService kmlIconService) { + return new KMLIconsController(kmlIconService); } @Bean - KMLReflectorController kmlReflectorController() { - return new KMLReflectorController(); + KMLReflectorController kmlReflectorController(Dispatcher geoserverDispatcher) { + return new KMLReflectorController(geoserverDispatcher); } } diff --git a/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/autoconfigure/wms/WmsApplicationAutoConfiguration.java b/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/autoconfigure/wms/WmsApplicationAutoConfiguration.java index 6d4d417dd..13d6bb885 100644 --- a/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/autoconfigure/wms/WmsApplicationAutoConfiguration.java +++ b/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/autoconfigure/wms/WmsApplicationAutoConfiguration.java @@ -11,6 +11,7 @@ import org.geoserver.cloud.wms.controller.GetMapReflectorController; import org.geoserver.cloud.wms.controller.WMSController; import org.geoserver.config.GeoServer; +import org.geoserver.ows.Dispatcher; import org.geoserver.platform.GeoServerResourceLoader; import org.geoserver.wfs.xml.FeatureTypeSchemaBuilder; import org.geoserver.wfs.xml.v1_1_0.WFS; @@ -81,13 +82,16 @@ WFSConfiguration wfsConfiguration(GeoServer geoServer) { } @Bean - WMSController webMapServiceController() { - return new WMSController(); + WMSController webMapServiceController( + Dispatcher geoserverDispatcher, + org.geoserver.ows.ClasspathPublisher classPathPublisher, + VirtualServiceVerifier virtualServiceVerifier) { + return new WMSController(geoserverDispatcher, classPathPublisher, virtualServiceVerifier); } @Bean - VirtualServiceVerifier virtualServiceVerifier() { - return new VirtualServiceVerifier(); + VirtualServiceVerifier virtualServiceVerifier(@Qualifier("rawCatalog") Catalog catalog) { + return new VirtualServiceVerifier(catalog); } @ConditionalOnProperty( @@ -96,7 +100,7 @@ VirtualServiceVerifier virtualServiceVerifier() { havingValue = "true", matchIfMissing = true) @Bean - GetMapReflectorController getMapReflectorController() { - return new GetMapReflectorController(); + GetMapReflectorController getMapReflectorController(Dispatcher geoserverDispatcher) { + return new GetMapReflectorController(geoserverDispatcher); } } diff --git a/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/wms/controller/GetMapReflectorController.java b/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/wms/controller/GetMapReflectorController.java index 8a258e50d..66e83486a 100644 --- a/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/wms/controller/GetMapReflectorController.java +++ b/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/wms/controller/GetMapReflectorController.java @@ -4,17 +4,21 @@ */ package org.geoserver.cloud.wms.controller; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import org.geoserver.ows.Dispatcher; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -public @Controller class GetMapReflectorController { +@Controller +@RequiredArgsConstructor +public class GetMapReflectorController { - private @Autowired Dispatcher geoserverDispatcher; + private final @NonNull Dispatcher geoserverDispatcher; @GetMapping(path = {"/wms/reflect", "/{workspace}/wms/reflect"}) public void getMapReflect(HttpServletRequest request, HttpServletResponse response) diff --git a/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/wms/controller/WMSController.java b/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/wms/controller/WMSController.java index 4f90d3327..771e76751 100644 --- a/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/wms/controller/WMSController.java +++ b/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/wms/controller/WMSController.java @@ -4,9 +4,11 @@ */ package org.geoserver.cloud.wms.controller; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import org.geoserver.cloud.virtualservice.VirtualServiceVerifier; import org.geoserver.ows.Dispatcher; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -16,13 +18,15 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -public @Controller class WMSController { +@Controller +@RequiredArgsConstructor +public class WMSController { - private @Autowired Dispatcher geoserverDispatcher; + private final @NonNull Dispatcher geoserverDispatcher; - private @Autowired org.geoserver.ows.ClasspathPublisher classPathPublisher; + private final @NonNull org.geoserver.ows.ClasspathPublisher classPathPublisher; - private @Autowired VirtualServiceVerifier virtualServiceVerifier; + private final @NonNull VirtualServiceVerifier virtualServiceVerifier; @GetMapping("/") public RedirectView redirectRootToGetCapabilities() { diff --git a/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/wms/controller/kml/KMLIconsController.java b/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/wms/controller/kml/KMLIconsController.java index 8a280a3d2..09790ea77 100644 --- a/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/wms/controller/kml/KMLIconsController.java +++ b/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/wms/controller/kml/KMLIconsController.java @@ -4,10 +4,11 @@ */ package org.geoserver.cloud.wms.controller.kml; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import org.geoserver.kml.KMLReflector; import org.geoserver.wms.icons.IconService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @@ -26,7 +27,9 @@ * * @since 1.0 */ -public @Controller class KMLIconsController { +@Controller +@RequiredArgsConstructor +public class KMLIconsController { // // // @@ -38,8 +41,7 @@ // // // - - private @Autowired @Qualifier("kmlIconService") IconService kmlIconService; + private final @NonNull IconService kmlIconService; @GetMapping(path = "/kml/icon/**") public void getKmlIcon(HttpServletRequest request, HttpServletResponse response) @@ -60,11 +62,13 @@ private HttpServletRequest adaptRequest(HttpServletRequest request) { final String pathInfo = requestURI.substring(pathToKml.length()); return new HttpServletRequestWrapper(request) { - public @Override String getServletPath() { + @Override + public String getServletPath() { return servletPath; } - public @Override String getPathInfo() { + @Override + public String getPathInfo() { return pathInfo; } }; diff --git a/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/wms/controller/kml/KMLReflectorController.java b/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/wms/controller/kml/KMLReflectorController.java index b8138399c..e99806b1e 100644 --- a/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/wms/controller/kml/KMLReflectorController.java +++ b/src/apps/geoserver/wms/src/main/java/org/geoserver/cloud/wms/controller/kml/KMLReflectorController.java @@ -4,9 +4,11 @@ */ package org.geoserver.cloud.wms.controller.kml; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import org.geoserver.kml.KMLReflector; import org.geoserver.ows.Dispatcher; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @@ -22,9 +24,11 @@ * * @since 1.0 */ -public @Controller class KMLReflectorController { +@Controller +@RequiredArgsConstructor +public class KMLReflectorController { - private @Autowired Dispatcher geoserverDispatcher; + private final @NonNull Dispatcher geoserverDispatcher; @GetMapping(path = {"/wms/kml", "/{workspace}/wms/kml"}) public void kmlReflect(HttpServletRequest request, HttpServletResponse response) diff --git a/src/apps/geoserver/wms/src/test/java/org/geoserver/cloud/wms/app/WmsApplicationDataDirectoryTest.java b/src/apps/geoserver/wms/src/test/java/org/geoserver/cloud/wms/app/WmsApplicationDataDirectoryTest.java index 92d75e633..9ed44098b 100644 --- a/src/apps/geoserver/wms/src/test/java/org/geoserver/cloud/wms/app/WmsApplicationDataDirectoryTest.java +++ b/src/apps/geoserver/wms/src/test/java/org/geoserver/cloud/wms/app/WmsApplicationDataDirectoryTest.java @@ -15,7 +15,7 @@ /** See {@code src/test/resources/bootstrap-testdatadir.yml} */ @SpringBootTest(properties = "gwc.wms-integration=true") @ActiveProfiles({"test", "testdatadir"}) -public class WmsApplicationDataDirectoryTest extends WmsApplicationTest { +class WmsApplicationDataDirectoryTest extends WmsApplicationTest { private static @TempDir File tmpDataDir; diff --git a/src/apps/geoserver/wms/src/test/java/org/geoserver/cloud/wms/app/WmsApplicationJdbcconfigTest.java b/src/apps/geoserver/wms/src/test/java/org/geoserver/cloud/wms/app/WmsApplicationJdbcconfigTest.java index 50d4fe4fd..0abdb0017 100644 --- a/src/apps/geoserver/wms/src/test/java/org/geoserver/cloud/wms/app/WmsApplicationJdbcconfigTest.java +++ b/src/apps/geoserver/wms/src/test/java/org/geoserver/cloud/wms/app/WmsApplicationJdbcconfigTest.java @@ -10,4 +10,4 @@ /** See {@code src/test/resources/bootstrap-testjdbcconfig.yml} */ @SpringBootTest(properties = "gwc.wms-integration=true") @ActiveProfiles({"test", "testjdbcconfig"}) -public class WmsApplicationJdbcconfigTest extends WmsApplicationTest {} +class WmsApplicationJdbcconfigTest extends WmsApplicationTest {} diff --git a/src/apps/geoserver/wms/src/test/java/org/geoserver/cloud/wms/app/WmsApplicationTest.java b/src/apps/geoserver/wms/src/test/java/org/geoserver/cloud/wms/app/WmsApplicationTest.java index 0f12e4184..81cb02b8b 100644 --- a/src/apps/geoserver/wms/src/test/java/org/geoserver/cloud/wms/app/WmsApplicationTest.java +++ b/src/apps/geoserver/wms/src/test/java/org/geoserver/cloud/wms/app/WmsApplicationTest.java @@ -27,7 +27,7 @@ abstract class WmsApplicationTest { protected @Autowired ConfigurableApplicationContext context; @Test - public void testExpectedBeansFromWmsApplicationAutoConfiguration() { + void testExpectedBeansFromWmsApplicationAutoConfiguration() { expecteBean("wfsConfiguration", WFSConfiguration.class); expecteBean("webMapServiceController", WMSController.class); expecteBean("virtualServiceVerifier", VirtualServiceVerifier.class); @@ -38,7 +38,7 @@ public void testExpectedBeansFromWmsApplicationAutoConfiguration() { } @Test - public void testExpectedBeansFromGsWfsJarFile() { + void testExpectedBeansFromGsWfsJarFile() { expecteBean("bboxKvpParser", BBoxKvpParser.class); expecteBean("featureIdKvpParser", FlatKvpParser.class); expecteBean("cqlKvpParser", CQLFilterKvpParser.class); @@ -68,7 +68,7 @@ public void testExpectedBeansFromGsWfsJarFile() { } @Test - public void testGwcWmsIntegration() { + void testGwcWmsIntegration() { expecteBean( "gwcWMSExtendedCapabilitiesProvider", CachingExtendedCapabilitiesProvider.class); expecteBean("gwcGetMapAdvise", ForwardGetMapToGwcAspect.class); diff --git a/src/apps/geoserver/wps/src/main/java/org/geoserver/cloud/wps/WPSController.java b/src/apps/geoserver/wps/src/main/java/org/geoserver/cloud/wps/WPSController.java index a344db6b7..554a83037 100644 --- a/src/apps/geoserver/wps/src/main/java/org/geoserver/cloud/wps/WPSController.java +++ b/src/apps/geoserver/wps/src/main/java/org/geoserver/cloud/wps/WPSController.java @@ -4,9 +4,11 @@ */ package org.geoserver.cloud.wps; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import org.geoserver.cloud.virtualservice.VirtualServiceVerifier; import org.geoserver.ows.Dispatcher; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -16,13 +18,15 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -public @Controller class WPSController { +@Controller +@RequiredArgsConstructor +public class WPSController { - private @Autowired Dispatcher geoserverDispatcher; + private final @NonNull Dispatcher geoserverDispatcher; - private @Autowired org.geoserver.ows.ClasspathPublisher classPathPublisher; + private final @NonNull org.geoserver.ows.ClasspathPublisher classPathPublisher; - private @Autowired VirtualServiceVerifier virtualServiceVerifier; + private final @NonNull VirtualServiceVerifier virtualServiceVerifier; @GetMapping("/") public RedirectView redirectRootToGetCapabilities() { diff --git a/src/apps/geoserver/wps/src/main/java/org/geoserver/cloud/wps/WpsApplicationConfiguration.java b/src/apps/geoserver/wps/src/main/java/org/geoserver/cloud/wps/WpsApplicationConfiguration.java index 60a1961b9..a4c3c164f 100644 --- a/src/apps/geoserver/wps/src/main/java/org/geoserver/cloud/wps/WpsApplicationConfiguration.java +++ b/src/apps/geoserver/wps/src/main/java/org/geoserver/cloud/wps/WpsApplicationConfiguration.java @@ -4,8 +4,10 @@ */ package org.geoserver.cloud.wps; +import org.geoserver.catalog.Catalog; import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; import org.geoserver.cloud.virtualservice.VirtualServiceVerifier; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; @@ -27,7 +29,7 @@ public class WpsApplicationConfiguration { @Bean - VirtualServiceVerifier virtualServiceVerifier() { - return new VirtualServiceVerifier(); + VirtualServiceVerifier virtualServiceVerifier(@Qualifier("rawCatalog") Catalog catalog) { + return new VirtualServiceVerifier(catalog); } } diff --git a/src/apps/geoserver/wps/src/test/java/org/geoserver/cloud/wps/WpsApplicationTest.java b/src/apps/geoserver/wps/src/test/java/org/geoserver/cloud/wps/WpsApplicationTest.java index 96dfbb595..c3ebc1d86 100644 --- a/src/apps/geoserver/wps/src/test/java/org/geoserver/cloud/wps/WpsApplicationTest.java +++ b/src/apps/geoserver/wps/src/test/java/org/geoserver/cloud/wps/WpsApplicationTest.java @@ -12,8 +12,8 @@ @SpringBootTest @EnableAutoConfiguration @ActiveProfiles("test") -public class WpsApplicationTest { +class WpsApplicationTest { @Test - public void contextLoads() {} + void contextLoads() {} } diff --git a/src/apps/infrastructure/config/src/test/java/org/geoserver/cloud/config/ConfigApplicationTest.java b/src/apps/infrastructure/config/src/test/java/org/geoserver/cloud/config/ConfigApplicationTest.java index 167c54491..5c90222b6 100644 --- a/src/apps/infrastructure/config/src/test/java/org/geoserver/cloud/config/ConfigApplicationTest.java +++ b/src/apps/infrastructure/config/src/test/java/org/geoserver/cloud/config/ConfigApplicationTest.java @@ -25,7 +25,7 @@ @Slf4j @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @ActiveProfiles({"native", "test"}) -public class ConfigApplicationTest { +class ConfigApplicationTest { @LocalServerPort private int port; @@ -38,13 +38,15 @@ void setup() { baseUri = "http://localhost:" + port + "/test-service"; } - public @Test void testNoProfile() throws Exception { + @Test + void testNoProfile() throws Exception { assertThat( this.restTemplate.getForEntity(baseUri, String.class).getStatusCode(), equalTo(HttpStatus.NOT_FOUND)); } - public @Test void testDefaultProfile() throws Exception { + @Test + void testDefaultProfile() throws Exception { String uri = baseUri + "/default"; ResponseEntity response = this.restTemplate.getForEntity(uri, String.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); @@ -58,7 +60,8 @@ void setup() { JSONAssert.assertEquals(expected, config, JSONCompareMode.LENIENT); } - public @Test void testProfile() throws Exception { + @Test + void testProfile() throws Exception { String uri = baseUri + "/profile1"; ResponseEntity response = this.restTemplate.getForEntity(uri, String.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); diff --git a/src/apps/infrastructure/discovery/src/test/java/org/geoserver/cloud/discovery/DiscoveryApplicationTests.java b/src/apps/infrastructure/discovery/src/test/java/org/geoserver/cloud/discovery/DiscoveryApplicationTests.java index 05a74316e..1b76e4b6a 100644 --- a/src/apps/infrastructure/discovery/src/test/java/org/geoserver/cloud/discovery/DiscoveryApplicationTests.java +++ b/src/apps/infrastructure/discovery/src/test/java/org/geoserver/cloud/discovery/DiscoveryApplicationTests.java @@ -8,8 +8,8 @@ import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest -public class DiscoveryApplicationTests { +class DiscoveryApplicationTests { @Test - public void contextLoads() {} + void contextLoads() {} } diff --git a/src/apps/infrastructure/gateway/src/main/java/org/geoserver/cloud/gateway/GatewayApplication.java b/src/apps/infrastructure/gateway/src/main/java/org/geoserver/cloud/gateway/GatewayApplication.java index bb24c5d69..c372496dd 100644 --- a/src/apps/infrastructure/gateway/src/main/java/org/geoserver/cloud/gateway/GatewayApplication.java +++ b/src/apps/infrastructure/gateway/src/main/java/org/geoserver/cloud/gateway/GatewayApplication.java @@ -13,6 +13,7 @@ import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; @SpringBootApplication @Configuration(proxyBeanMethods = false) @@ -38,8 +39,8 @@ RegExpQueryRoutePredicateFactory regExpQueryRoutePredicateFactory() { /** Allows to enable routes only if a given spring profile is enabled */ @Bean - RouteProfileGatewayFilterFactory routeProfileGatewayFilterFactory() { - return new RouteProfileGatewayFilterFactory(); + RouteProfileGatewayFilterFactory routeProfileGatewayFilterFactory(Environment environment) { + return new RouteProfileGatewayFilterFactory(environment); } @Bean diff --git a/src/apps/infrastructure/gateway/src/main/java/org/geoserver/cloud/gateway/filter/RouteProfileGatewayFilterFactory.java b/src/apps/infrastructure/gateway/src/main/java/org/geoserver/cloud/gateway/filter/RouteProfileGatewayFilterFactory.java index eb5548d71..858a740fe 100644 --- a/src/apps/infrastructure/gateway/src/main/java/org/geoserver/cloud/gateway/filter/RouteProfileGatewayFilterFactory.java +++ b/src/apps/infrastructure/gateway/src/main/java/org/geoserver/cloud/gateway/filter/RouteProfileGatewayFilterFactory.java @@ -11,7 +11,6 @@ import lombok.RequiredArgsConstructor; import lombok.experimental.Accessors; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.gateway.filter.GatewayFilter; import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; @@ -36,10 +35,11 @@ public class RouteProfileGatewayFilterFactory private static final List SHORTCUT_FIELD_ORDER = Collections.unmodifiableList(Arrays.asList(Config.PROFILE_KEY, Config.HTTPSTATUS_KEY)); - @Autowired private Environment environment; + private final Environment environment; - public RouteProfileGatewayFilterFactory() { + public RouteProfileGatewayFilterFactory(@NonNull Environment environment) { super(Config.class); + this.environment = environment; } @Override diff --git a/src/apps/infrastructure/gateway/src/main/java/org/geoserver/cloud/gateway/filter/StripBasePathGatewayFilterFactory.java b/src/apps/infrastructure/gateway/src/main/java/org/geoserver/cloud/gateway/filter/StripBasePathGatewayFilterFactory.java index e3d003a7a..175fb33c7 100644 --- a/src/apps/infrastructure/gateway/src/main/java/org/geoserver/cloud/gateway/filter/StripBasePathGatewayFilterFactory.java +++ b/src/apps/infrastructure/gateway/src/main/java/org/geoserver/cloud/gateway/filter/StripBasePathGatewayFilterFactory.java @@ -44,9 +44,6 @@ public GatewayFilter apply(PrefixConfig config) { final String basePath = config.getPrefix(); final String path = request.getURI().getRawPath(); - // if (basePath.equals(path)) { - // return chain.filter(exchange); - // } final int partsToRemove = resolvePartsToStrip(basePath, path); if (partsToRemove == 0) { @@ -77,9 +74,6 @@ private int resolvePartsToStrip(String basePath, String requestPath) { private String prefix; public void checkPreconditions() { - final String prefix = getPrefix(); - - // requireNonNull(prefix, "StripBasePath prefix can't be null"); if (prefix != null) { checkArgument(prefix.startsWith("/"), "StripBasePath prefix must start with /"); diff --git a/src/apps/infrastructure/gateway/src/main/java/org/geoserver/cloud/gateway/predicate/RegExpQueryRoutePredicateFactory.java b/src/apps/infrastructure/gateway/src/main/java/org/geoserver/cloud/gateway/predicate/RegExpQueryRoutePredicateFactory.java index b3ab03d32..f40115293 100644 --- a/src/apps/infrastructure/gateway/src/main/java/org/geoserver/cloud/gateway/predicate/RegExpQueryRoutePredicateFactory.java +++ b/src/apps/infrastructure/gateway/src/main/java/org/geoserver/cloud/gateway/predicate/RegExpQueryRoutePredicateFactory.java @@ -68,11 +68,13 @@ public RegExpQueryRoutePredicateFactory() { super(Config.class); } - public @Override List shortcutFieldOrder() { + @Override + public List shortcutFieldOrder() { return Arrays.asList(PARAM_KEY, VALUE_KEY); } - public @Override Predicate apply(Config config) { + @Override + public Predicate apply(Config config) { return new RegExpQueryRoutePredicate(config); } @@ -80,7 +82,8 @@ public RegExpQueryRoutePredicateFactory() { private static class RegExpQueryRoutePredicate implements GatewayPredicate { private final @NonNull Config config; - public @Override boolean test(ServerWebExchange exchange) { + @Override + public boolean test(ServerWebExchange exchange) { final String paramRegexp = config.getParamRegexp(); final String valueRegexp = config.getValueRegexp(); @@ -93,7 +96,8 @@ private static class RegExpQueryRoutePredicate implements GatewayPredicate { return paramNameMatches && paramValueMatches(paramName.get(), valueRegexp, exchange); } - public @Override String toString() { + @Override + public String toString() { return String.format( "Query: param regexp='%s' value regexp='%s'", config.getParamRegexp(), config.getValueRegexp()); diff --git a/src/catalog/backends/catalog-service/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/catalogservice/CatalogClientBackendAutoConfigurationTest.java b/src/catalog/backends/catalog-service/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/catalogservice/CatalogClientBackendAutoConfigurationTest.java index 8cb9e3861..f3f276f1a 100644 --- a/src/catalog/backends/catalog-service/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/catalogservice/CatalogClientBackendAutoConfigurationTest.java +++ b/src/catalog/backends/catalog-service/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/catalogservice/CatalogClientBackendAutoConfigurationTest.java @@ -32,7 +32,7 @@ * when {@code geoserver.backend.catalog-service.enabled=true} */ @Disabled("Make it run without ReactiveCatalogClient trying to connect") -public class CatalogClientBackendAutoConfigurationTest { +class CatalogClientBackendAutoConfigurationTest { // geoserver.security.enabled=false to avoid calling the catalog during bean initialization, // since there's no backend service to connect to @@ -52,19 +52,22 @@ public class CatalogClientBackendAutoConfigurationTest { WebClientAutoConfiguration.class, CacheAutoConfiguration.class)); - public @Test void testCatalog() { + @Test + void testCatalog() { contextRunner.run( context -> context.isTypeMatch( "rawCatalog", org.geoserver.catalog.plugin.CatalogPlugin.class)); } - public @Test void testCatalogFacade() { + @Test + void testCatalogFacade() { contextRunner.run( context -> context.isTypeMatch("catalogFacade", CatalogClientCatalogFacade.class)); } - public @Test void testCatalogFacadeIsRawCatalogFacade() { + @Test + void testCatalogFacadeIsRawCatalogFacade() { contextRunner.run( context -> { CatalogPlugin catalog = context.getBean("rawCatalog", CatalogPlugin.class); @@ -74,13 +77,15 @@ public class CatalogClientBackendAutoConfigurationTest { }); } - public @Test void testResourceStore() { + @Test + void testResourceStore() { contextRunner.run( context -> context.isTypeMatch("resourceStoreImpl", CatalogClientResourceStore.class)); } - public @Test void testResourceLoadersResourceStore() { + @Test + void testResourceLoadersResourceStore() { contextRunner.run( context -> { GeoServerResourceLoader resourceLoader = @@ -91,13 +96,15 @@ public class CatalogClientBackendAutoConfigurationTest { }); } - public @Test void testGeoserverFacade() { + @Test + void testGeoserverFacade() { contextRunner.run( context -> context.isTypeMatch("geoserverFacade", CatalogClientGeoServerFacade.class)); } - public @Test void testGeoserverLoader() { + @Test + void testGeoserverLoader() { contextRunner.run( context -> context.isTypeMatch( diff --git a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/catalog/backend/core/XstreamServiceLoadersAutoConfiguration.java b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/catalog/backend/core/XstreamServiceLoadersAutoConfiguration.java index dd6f73d01..34f454132 100644 --- a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/catalog/backend/core/XstreamServiceLoadersAutoConfiguration.java +++ b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/catalog/backend/core/XstreamServiceLoadersAutoConfiguration.java @@ -32,6 +32,8 @@ @Slf4j(topic = "org.geoserver.cloud.config.catalog") public class XstreamServiceLoadersAutoConfiguration { + private static final String CONTRIBUTING_MSG = "Automatically contributing {}"; + @ConditionalOnMissingBean(WFSXStreamLoader.class) @Bean WFSXStreamLoader wfsLoader(GeoServerResourceLoader resourceLoader) { @@ -41,7 +43,7 @@ WFSXStreamLoader wfsLoader(GeoServerResourceLoader resourceLoader) { @ConditionalOnMissingBean(WFSFactoryExtension.class) @Bean WFSFactoryExtension wfsFactoryExtension(GeoServerResourceLoader resourceLoader) { - log.info("Automatically contributing {}", WFSFactoryExtension.class.getSimpleName()); + log(WFSFactoryExtension.class); return new WFSFactoryExtension() {}; // constructor is protected! } @@ -54,8 +56,7 @@ WMSXStreamLoader wmsLoader(GeoServerResourceLoader resourceLoader) { @ConditionalOnMissingBean(WMSFactoryExtension.class) @Bean WMSFactoryExtension wmsFactoryExtension() { - log.info("Automatically contributing {}", WMSFactoryExtension.class.getSimpleName()); - return new WMSFactoryExtension(); + return log(new WMSFactoryExtension()); } @ConditionalOnMissingBean(WCSXStreamLoader.class) @@ -67,8 +68,7 @@ WCSXStreamLoader wcsLoader(GeoServerResourceLoader resourceLoader) { @ConditionalOnMissingBean(WCSFactoryExtension.class) @Bean WCSFactoryExtension wcsFactoryExtension() { - log.info("Automatically contributing {}", WCSFactoryExtension.class.getSimpleName()); - return new WCSFactoryExtension(); + return log(new WCSFactoryExtension()); } @ConditionalOnMissingBean(WMTSXStreamLoader.class) @@ -80,7 +80,7 @@ WMTSXStreamLoader wmtsLoader(GeoServerResourceLoader resourceLoader) { @ConditionalOnMissingBean(WMTSFactoryExtension.class) @Bean WMTSFactoryExtension wmtsFactoryExtension() { - log.info("Automatically contributing {}", WMTSFactoryExtension.class.getSimpleName()); + log(WMTSFactoryExtension.class); return new WMTSFactoryExtension() {}; // constructor is protected! } @@ -93,12 +93,16 @@ WPSXStreamLoader wpsServiceLoader(GeoServerResourceLoader resourceLoader) { @ConditionalOnMissingBean(WPSFactoryExtension.class) @Bean WPSFactoryExtension WPSFactoryExtension() { - log.info("Automatically contributing {}", WPSFactoryExtension.class.getSimpleName()); + log(WPSFactoryExtension.class); return new WPSFactoryExtension() {}; // constructor is protected! } private T log(T extension) { - log.info("Automatically contributing {}", extension.getClass().getSimpleName()); + log(extension.getClass()); return extension; } + + private void log(Class extensionType) { + log.info(CONTRIBUTING_MSG, extensionType.getSimpleName()); + } } diff --git a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/geotools/GeoToolsHttpClientAutoConfiguration.java b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/geotools/GeoToolsHttpClientAutoConfiguration.java index d3c9e73c7..43f1f074f 100644 --- a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/geotools/GeoToolsHttpClientAutoConfiguration.java +++ b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/geotools/GeoToolsHttpClientAutoConfiguration.java @@ -8,7 +8,6 @@ import org.geoserver.cloud.autoconfigure.geotools.GeoToolsHttpClientProxyConfigurationProperties.ProxyHostConfig; import org.geotools.http.HTTPClientFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -77,7 +76,7 @@ public class GeoToolsHttpClientAutoConfiguration { @Bean SpringEnvironmentAwareGeoToolsHttpClientFactory springEnvironmentAwareGeoToolsHttpClientFactory( - @Autowired GeoToolsHttpClientProxyConfigurationProperties proxyConfig) { + GeoToolsHttpClientProxyConfigurationProperties proxyConfig) { log.info("Using spring environment aware GeoTools HTTPClientFactory"); log(proxyConfig.getHttp(), "HTTP"); diff --git a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/geotools/SpringEnvironmentAwareGeoToolsHttpClient.java b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/geotools/SpringEnvironmentAwareGeoToolsHttpClient.java index b93df5f66..43d723d26 100644 --- a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/geotools/SpringEnvironmentAwareGeoToolsHttpClient.java +++ b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/geotools/SpringEnvironmentAwareGeoToolsHttpClient.java @@ -24,7 +24,6 @@ import org.apache.http.Header; import org.apache.http.HttpEntity; -import org.apache.http.HttpException; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; @@ -148,10 +147,9 @@ private void setProxyCredentials(BasicCredentialsProvider provider, ProxyHostCon } private void setTargetCredentials( - BasicCredentialsProvider provider, String user2, String password2) { + BasicCredentialsProvider provider, String userName, String pwd) { AuthScope authscope = AuthScope.ANY; - Credentials credentials = new UsernamePasswordCredentials(user, password); - // TODO - check if this works for all types of auth or do we need to look it up? + Credentials credentials = new UsernamePasswordCredentials(userName, pwd); provider.setCredentials(authscope, credentials); } @@ -170,7 +168,8 @@ private HttpClientBuilder builder() { return builder; } - public @Override HttpMethodResponse post( + @Override + public HttpMethodResponse post( final URL url, final InputStream postContent, final String postContentType) throws IOException { @@ -197,12 +196,8 @@ private HttpClientBuilder builder() { postMethod.setEntity(requestEntity); - HttpMethodResponse response = null; - try { - response = executeMethod(postMethod); - } catch (HttpException e) { - throw new IOException(e); - } + HttpMethodResponse response = executeMethod(postMethod); + if (200 != response.getStatusCode()) { postMethod.releaseConnection(); throw new IOException( @@ -218,8 +213,7 @@ private HttpClientBuilder builder() { /** * @return the http status code of the execution */ - private HttpMethodResponse executeMethod(HttpRequestBase method) - throws IOException, HttpException { + private HttpMethodResponse executeMethod(HttpRequestBase method) throws IOException { HttpClientContext localContext = HttpClientContext.create(); HttpResponse resp; @@ -230,16 +224,16 @@ private HttpMethodResponse executeMethod(HttpRequestBase method) resp = client.execute(method); } - HttpMethodResponse response = new HttpMethodResponse(resp); - - return response; + return new HttpMethodResponse(resp); } - public @Override HTTPResponse get(final URL url) throws IOException { + @Override + public HTTPResponse get(final URL url) throws IOException { return this.get(url, null); } - public @Override HTTPResponse get(URL url, Map headers) throws IOException { + @Override + public HTTPResponse get(URL url, Map headers) throws IOException { HttpGet getMethod = new HttpGet(url.toExternalForm()); getMethod.setConfig(connectionConfig(url)); @@ -253,12 +247,7 @@ private HttpMethodResponse executeMethod(HttpRequestBase method) } } - HttpMethodResponse response = null; - try { - response = executeMethod(getMethod); - } catch (HttpException e) { - throw new IOException(e); - } + HttpMethodResponse response = executeMethod(getMethod); if (200 != response.getStatusCode()) { getMethod.releaseConnection(); @@ -271,51 +260,61 @@ private HttpMethodResponse executeMethod(HttpRequestBase method) return response; } - public @Override String getUser() { + @Override + public String getUser() { return user; } - public @Override void setUser(String user) { + @Override + public void setUser(String user) { this.user = user; resetCredentials(); } - public @Override String getPassword() { + @Override + public String getPassword() { return password; } - public @Override void setPassword(String password) { + @Override + public void setPassword(String password) { this.password = password; resetCredentials(); } - public @Override int getConnectTimeout() { + @Override + public int getConnectTimeout() { return (int) ofMillis(connectionConfig.getConnectionRequestTimeout()).toSeconds(); } - public @Override void setConnectTimeout(int connectTimeout) { + @Override + public void setConnectTimeout(int connectTimeout) { connectionConfig = RequestConfig.copy(connectionConfig) .setConnectionRequestTimeout((int) ofSeconds(connectTimeout).toMillis()) .build(); } - public @Override int getReadTimeout() { + @Override + public int getReadTimeout() { return (int) ofMillis(connectionConfig.getSocketTimeout()).toSeconds(); } - public @Override void setReadTimeout(int readTimeout) { + @Override + public void setReadTimeout(int readTimeout) { connectionConfig = RequestConfig.copy(connectionConfig) .setSocketTimeout((int) ofSeconds(readTimeout).toMillis()) .build(); } - public @Override int getMaxConnections() { + @Override + public int getMaxConnections() { return connectionManager.getDefaultMaxPerRoute(); } - public @Override void setMaxConnections(final int maxConnections) { + @Override + public void setMaxConnections(final int maxConnections) { connectionManager.setDefaultMaxPerRoute(maxConnections); connectionManager.setMaxTotal(maxConnections); } @@ -339,7 +338,8 @@ public int getStatusCode() { } } - public @Override void dispose() { + @Override + public void dispose() { if (responseBodyAsStream != null) { try { responseBodyAsStream.close(); @@ -353,16 +353,19 @@ public int getStatusCode() { } } - public @Override String getContentType() { + @Override + public String getContentType() { return getResponseHeader("Content-Type"); } - public @Override String getResponseHeader(final String headerName) { + @Override + public String getResponseHeader(final String headerName) { Header responseHeader = methodResponse.getFirstHeader(headerName); return responseHeader == null ? null : responseHeader.getValue(); } - public @Override InputStream getResponseStream() throws IOException { + @Override + public InputStream getResponseStream() throws IOException { if (responseBodyAsStream == null) { responseBodyAsStream = methodResponse.getEntity().getContent(); // commons httpclient does not handle gzip encoding automatically, we have to check @@ -375,21 +378,25 @@ public int getStatusCode() { return responseBodyAsStream; } - public @Override String getResponseCharset() { + @Override + public String getResponseCharset() { final Header encoding = methodResponse.getEntity().getContentEncoding(); return encoding == null ? null : encoding.getValue(); } } - public @Override void setTryGzip(boolean tryGZIP) { + @Override + public void setTryGzip(boolean tryGZIP) { this.tryGzip = tryGZIP; } - public @Override boolean isTryGzip() { + @Override + public boolean isTryGzip() { return tryGzip; } - public @Override void close() { + @Override + public void close() { this.connectionManager.shutdown(); } } diff --git a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/geotools/SpringEnvironmentAwareGeoToolsHttpClientFactory.java b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/geotools/SpringEnvironmentAwareGeoToolsHttpClientFactory.java index 671bf2384..b895ae979 100644 --- a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/geotools/SpringEnvironmentAwareGeoToolsHttpClientFactory.java +++ b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/geotools/SpringEnvironmentAwareGeoToolsHttpClientFactory.java @@ -22,11 +22,13 @@ public class SpringEnvironmentAwareGeoToolsHttpClientFactory extends AbstractHTT GeoToolsHttpClientProxyConfigurationProperties proxyConfig = new GeoToolsHttpClientProxyConfigurationProperties(); - public @Override List> clientClasses() { + @Override + public List> clientClasses() { return List.of(SpringEnvironmentAwareGeoToolsHttpClient.class); } - public @Override final HTTPClient createClient(List> behaviors) { + @Override + public final HTTPClient createClient(List> behaviors) { return new SpringEnvironmentAwareGeoToolsHttpClient(proxyConfig); } diff --git a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/metrics/catalog/CatalogMetrics.java b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/metrics/catalog/CatalogMetrics.java index 4f9d48aaf..b6534a690 100644 --- a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/metrics/catalog/CatalogMetrics.java +++ b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/metrics/catalog/CatalogMetrics.java @@ -53,7 +53,8 @@ class CatalogMetrics implements MeterBinder { private MetricsCatalogListener listener; - public @Override void bindTo(@NonNull MeterRegistry registry) { + @Override + public void bindTo(@NonNull MeterRegistry registry) { if (listener != null) { catalog.removeListener(listener); } diff --git a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/metrics/catalog/MetricsCatalogListener.java b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/metrics/catalog/MetricsCatalogListener.java index 5fa15b517..d7439ec96 100644 --- a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/metrics/catalog/MetricsCatalogListener.java +++ b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/autoconfigure/metrics/catalog/MetricsCatalogListener.java @@ -30,17 +30,17 @@ class MetricsCatalogListener implements CatalogListener { public MetricsCatalogListener(@NonNull MeterRegistry registry, @Nullable String instanceId) { added = - counter("geoserver.catalog.added", instanceId, registry) + counter("geoserver.catalog.added", instanceId) .description( "Number of CatalogInfo objects added to this instance's Catalog") .register(registry); removed = - counter("geoserver.catalog.removed", instanceId, registry) + counter("geoserver.catalog.removed", instanceId) .description( "Number of CatalogInfo objects removed on this instance's Catalog") .register(registry); modified = - counter("geoserver.catalog.modified", instanceId, registry) + counter("geoserver.catalog.modified", instanceId) .description( "Number of modifications to CatalogInfo objects on this instance's Catalog") .register(registry); @@ -52,7 +52,7 @@ public MetricsCatalogListener(@NonNull MeterRegistry registry, @Nullable String .register(registry); } - private Counter.Builder counter(String name, String instanceId, MeterRegistry registry) { + private Counter.Builder counter(String name, String instanceId) { Builder builder = Counter.builder(name) // .baseUnit(BaseUnits.OPERATIONS); @@ -60,23 +60,28 @@ private Counter.Builder counter(String name, String instanceId, MeterRegistry re return builder; } - public @Override void handleAddEvent(CatalogAddEvent event) throws CatalogException { + @Override + public void handleAddEvent(CatalogAddEvent event) throws CatalogException { added.increment(); } - public @Override void handleRemoveEvent(CatalogRemoveEvent event) { + @Override + public void handleRemoveEvent(CatalogRemoveEvent event) { removed.increment(); } - public @Override void reloaded() { + @Override + public void reloaded() { reloads.increment(); } - public @Override void handlePostModifyEvent(CatalogPostModifyEvent event) { + @Override + public void handlePostModifyEvent(CatalogPostModifyEvent event) { modified.increment(); } - public @Override void handleModifyEvent(CatalogModifyEvent event) { + @Override + public void handleModifyEvent(CatalogModifyEvent event) { // no-op, see #handlePostModifyEvent } } diff --git a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/config/catalog/backend/core/CoreBackendConfiguration.java b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/config/catalog/backend/core/CoreBackendConfiguration.java index d380e5f92..e7acef71b 100644 --- a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/config/catalog/backend/core/CoreBackendConfiguration.java +++ b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/config/catalog/backend/core/CoreBackendConfiguration.java @@ -23,7 +23,6 @@ import org.geoserver.security.impl.DataAccessRuleDAO; import org.geoserver.security.impl.DefaultResourceAccessManager; import org.geoserver.security.impl.LayerGroupContainmentCache; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -44,13 +43,6 @@ XStreamPersisterFactory xstreamPersisterFactory() { return new XStreamPersisterFactory(); } - // @Autowired - // @DependsOn("geoServerLoaderImpl") - // @Bean GeoServerLoaderProxy geoServerLoader(GeoServerResourceLoader resourceLoader) - // { - // return new GeoServerLoaderProxy(resourceLoader); - // } - @Bean GeoServerExtensions extensions() { return new GeoServerExtensions(); @@ -179,14 +171,12 @@ Catalog localWorkspaceCatalog( @Bean(name = "geoServer") GeoServerImpl geoServer( @Qualifier("catalog") Catalog catalog, - @Qualifier("geoserverFacade") GeoServerFacade facade) - throws Exception { + @Qualifier("geoserverFacade") GeoServerFacade facade) { GeoServerImpl gs = new GeoServerImpl(facade); gs.setCatalog(catalog); return gs; } - @Autowired @Bean GeoServerDataDirectory dataDirectory(GeoServerResourceLoader resourceLoader) { return new GeoServerDataDirectory(resourceLoader); diff --git a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/event/remote/resourcepool/RemoteEventResourcePoolProcessor.java b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/event/remote/resourcepool/RemoteEventResourcePoolProcessor.java index dcbf444cc..09e657c59 100644 --- a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/event/remote/resourcepool/RemoteEventResourcePoolProcessor.java +++ b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/event/remote/resourcepool/RemoteEventResourcePoolProcessor.java @@ -10,6 +10,7 @@ import org.geoserver.catalog.Catalog; import org.geoserver.catalog.CatalogInfo; +import org.geoserver.catalog.Info; import org.geoserver.catalog.ResourceInfo; import org.geoserver.catalog.ResourcePool; import org.geoserver.catalog.ResourcePool.CacheClearingListener; @@ -68,7 +69,7 @@ public void onCatalogRemoteModifyEvent(CatalogInfoModified event) { () -> log.trace("Ignoring event from self: {}", event)); } - private void evictFromResourcePool(@SuppressWarnings("rawtypes") InfoEvent event) { + private void evictFromResourcePool(InfoEvent event) { final String id = event.getObjectId(); final ConfigInfoType infoType = event.getObjectType(); diff --git a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/security/CloudGeoServerSecurityManager.java b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/security/CloudGeoServerSecurityManager.java index d6977a807..d516db26f 100644 --- a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/security/CloudGeoServerSecurityManager.java +++ b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/security/CloudGeoServerSecurityManager.java @@ -64,7 +64,8 @@ public void setProviders(List providers) throws Exceptio super.setProviders(providers); } - public @Override void reload() { + @Override + public void reload() { if (reloading.compareAndSet(false, true)) { changedDuringReload = false; try { @@ -111,49 +112,55 @@ public void fireRemoteChangedEvent(@NonNull String reason) { } /** Override to {@link #fireChanged fire} a remote {@link SecurityConfigChanged} */ - public @Override void saveRoleService(SecurityRoleServiceConfig config) + @Override + public void saveRoleService(SecurityRoleServiceConfig config) throws IOException, SecurityConfigException { super.saveRoleService(config); fireRemoteChangedEvent("SecurityRoleServiceConfig changed"); } /** Override to {@link #fireChanged fire} a remote {@link SecurityConfigChanged} */ - public @Override void savePasswordPolicy(PasswordPolicyConfig config) + @Override + public void savePasswordPolicy(PasswordPolicyConfig config) throws IOException, SecurityConfigException { super.savePasswordPolicy(config); fireRemoteChangedEvent("PasswordPolicyConfig changed"); } /** Override to {@link #fireChanged fire} a remote {@link SecurityConfigChanged} */ - public @Override void saveUserGroupService(SecurityUserGroupServiceConfig config) + @Override + public void saveUserGroupService(SecurityUserGroupServiceConfig config) throws IOException, SecurityConfigException { super.saveUserGroupService(config); fireRemoteChangedEvent("SecurityUserGroupServiceConfig changed"); } /** Override to {@link #fireChanged fire} a remote {@link SecurityConfigChanged} */ - public @Override void saveAuthenticationProvider(SecurityAuthProviderConfig config) + @Override + public void saveAuthenticationProvider(SecurityAuthProviderConfig config) throws IOException, SecurityConfigException { super.saveAuthenticationProvider(config); fireRemoteChangedEvent("SecurityAuthProviderConfig changed"); } /** Override to {@link #fireChanged fire} a remote {@link SecurityConfigChanged} */ - public @Override void saveFilter(SecurityNamedServiceConfig config) + @Override + public void saveFilter(SecurityNamedServiceConfig config) throws IOException, SecurityConfigException { super.saveFilter(config); fireRemoteChangedEvent("SecurityNamedServiceConfig changed"); } /** Override to {@link #fireChanged fire} a remote {@link SecurityConfigChanged} */ - public @Override synchronized void saveSecurityConfig(SecurityManagerConfig config) - throws Exception { + @Override + public synchronized void saveSecurityConfig(SecurityManagerConfig config) throws Exception { super.saveSecurityConfig(config); fireRemoteChangedEvent("SecurityManagerConfig changed"); } /** Override to {@link #fireChanged fire} a remote {@link SecurityConfigChanged} */ - public @Override synchronized void saveMasterPasswordConfig( + @Override + public synchronized void saveMasterPasswordConfig( MasterPasswordConfig config, char[] currPasswd, char[] newPasswd, @@ -164,13 +171,15 @@ public void fireRemoteChangedEvent(@NonNull String reason) { } /** Override to {@link #fireChanged fire} a remote {@link SecurityConfigChanged} */ - public @Override void saveMasterPasswordConfig(MasterPasswordConfig config) throws IOException { + @Override + public void saveMasterPasswordConfig(MasterPasswordConfig config) throws IOException { super.saveMasterPasswordConfig(config); fireRemoteChangedEvent("MasterPasswordConfig changed"); } /** Override to {@link #fireChanged fire} a remote {@link SecurityConfigChanged} */ - public @Override void saveMasterPasswordProviderConfig(MasterPasswordProviderConfig config) + @Override + public void saveMasterPasswordProviderConfig(MasterPasswordProviderConfig config) throws IOException, SecurityConfigException { super.saveMasterPasswordProviderConfig(config); fireRemoteChangedEvent("MasterPasswordProviderConfig changed"); diff --git a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/security/EnvironmentAdminAuthenticationProvider.java b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/security/EnvironmentAdminAuthenticationProvider.java index b76cafbb8..532b53fa3 100644 --- a/src/catalog/backends/common/src/main/java/org/geoserver/cloud/security/EnvironmentAdminAuthenticationProvider.java +++ b/src/catalog/backends/common/src/main/java/org/geoserver/cloud/security/EnvironmentAdminAuthenticationProvider.java @@ -119,15 +119,15 @@ public Authentication authenticate(Authentication token) throws AuthenticationEx // proceed with the authentication chain return null; } - final String adminUserName = this.adminUserName; - final String adminPassword = this.adminPassword; + final String expectedName = this.adminUserName; + final String expectedPassword = this.adminPassword; final String name = token.getName(); - if (GeoServerUser.ADMIN_USERNAME.equals(name) && !adminUserName.equals(name)) { + if (GeoServerUser.ADMIN_USERNAME.equals(name) && !expectedName.equals(name)) { throw new InternalAuthenticationServiceException("Default admin user is disabled"); } - final boolean sameName = hasText(adminUserName) && adminUserName.equals(name); + final boolean sameName = hasText(expectedName) && expectedName.equals(name); if (!sameName) { // not the configured admin username, proceed with the authentication chain return null; @@ -137,11 +137,11 @@ public Authentication authenticate(Authentication token) throws AuthenticationEx final String pwd = token.getCredentials() == null ? null : token.getCredentials().toString(); - if (adminPassword.equals(pwd)) { + if (expectedPassword.equals(pwd)) { List adminRoles = adminRoles(); UsernamePasswordAuthenticationToken authenticated = UsernamePasswordAuthenticationToken.authenticated( - adminUserName, null, adminRoles); + expectedName, null, adminRoles); authenticated.setDetails(token.getDetails()); return authenticated; } diff --git a/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/autoconfigure/catalog/backend/datadir/DataDirectoryAutoConfiguration.java b/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/autoconfigure/catalog/backend/datadir/DataDirectoryAutoConfiguration.java index 764ef4d8f..ed0484685 100644 --- a/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/autoconfigure/catalog/backend/datadir/DataDirectoryAutoConfiguration.java +++ b/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/autoconfigure/catalog/backend/datadir/DataDirectoryAutoConfiguration.java @@ -6,10 +6,13 @@ import org.geoserver.cloud.autoconfigure.catalog.backend.core.DefaultUpdateSequenceAutoConfiguration; import org.geoserver.cloud.config.catalog.backend.datadirectory.DataDirectoryBackendConfiguration; +import org.geoserver.cloud.config.catalog.backend.datadirectory.DataDirectoryProperties; import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Import; @AutoConfiguration(before = DefaultUpdateSequenceAutoConfiguration.class) @ConditionalOnDataDirectoryEnabled +@EnableConfigurationProperties(DataDirectoryProperties.class) @Import(DataDirectoryBackendConfiguration.class) public class DataDirectoryAutoConfiguration {} diff --git a/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/config/catalog/backend/datadirectory/DataDirectoryBackendConfiguration.java b/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/config/catalog/backend/datadirectory/DataDirectoryBackendConfiguration.java index ac2902919..aafabf92e 100644 --- a/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/config/catalog/backend/datadirectory/DataDirectoryBackendConfiguration.java +++ b/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/config/catalog/backend/datadirectory/DataDirectoryBackendConfiguration.java @@ -17,18 +17,18 @@ import org.geoserver.catalog.plugin.locking.LockingGeoServer; import org.geoserver.cloud.config.catalog.backend.core.CatalogProperties; import org.geoserver.cloud.config.catalog.backend.core.GeoServerBackendConfigurer; +import org.geoserver.config.GeoServerDataDirectory; import org.geoserver.config.GeoServerLoader; import org.geoserver.config.plugin.RepositoryGeoServerFacade; +import org.geoserver.config.util.XStreamPersisterFactory; import org.geoserver.platform.GeoServerResourceLoader; import org.geoserver.platform.ModuleStatusImpl; import org.geoserver.platform.config.UpdateSequence; import org.geoserver.platform.resource.LockProvider; import org.geoserver.platform.resource.ResourceStore; import org.geoserver.security.GeoServerSecurityManager; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; @@ -39,16 +39,17 @@ /** */ @Configuration(proxyBeanMethods = true) -@EnableConfigurationProperties(DataDirectoryProperties.class) @Slf4j(topic = "org.geoserver.cloud.config.datadirectory") public class DataDirectoryBackendConfiguration extends GeoServerBackendConfigurer { - private @Autowired CatalogProperties properties; + private final CatalogProperties catalogProperties; - private DataDirectoryProperties dataDirectoryConfig; + private final DataDirectoryProperties dataDirectoryConfig; - public DataDirectoryBackendConfiguration(DataDirectoryProperties dataDirectoryConfig) { + public DataDirectoryBackendConfiguration( + DataDirectoryProperties dataDirectoryConfig, CatalogProperties catalogProperties) { this.dataDirectoryConfig = dataDirectoryConfig; + this.catalogProperties = catalogProperties; log.info( "Loading geoserver config backend with {}", DataDirectoryBackendConfiguration.class.getSimpleName()); @@ -65,7 +66,7 @@ ModuleStatusImpl moduleStatus() { @Bean CatalogPlugin rawCatalog() { - boolean isolated = properties.isIsolated(); + boolean isolated = catalogProperties.isIsolated(); GeoServerConfigurationLock configurationLock = configurationLock(); ExtendedCatalogFacade catalogFacade = catalogFacade(); GeoServerResourceLoader resourceLoader = resourceLoader(); @@ -84,7 +85,10 @@ LockingGeoServer geoServer(@Qualifier("catalog") Catalog catalog) { } protected @Bean @Override UpdateSequence updateSequence() { - return new DataDirectoryUpdateSequence(); + ResourceStore resourceStore = resourceStoreImpl(); + GeoServerDataDirectory dd = new GeoServerDataDirectory(resourceLoader()); + XStreamPersisterFactory xpf = new XStreamPersisterFactory(); + return new DataDirectoryUpdateSequence(resourceStore, dd, xpf); } protected @Bean @Override GeoServerConfigurationLock configurationLock() { @@ -176,8 +180,8 @@ GeoServerLoader geoServerLoaderImplParallel(GeoServerSecurityManager securityMan } private Path dataDirectoryFile() { - DataDirectoryProperties dataDirectoryConfig = this.dataDirectoryConfig; - Path path = dataDirectoryConfig.getLocation(); + DataDirectoryProperties config = this.dataDirectoryConfig; + Path path = config.getLocation(); Objects.requireNonNull( path, "geoserver.backend.data-directory.location config property resolves to null"); return path; diff --git a/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/config/catalog/backend/datadirectory/DataDirectoryUpdateSequence.java b/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/config/catalog/backend/datadirectory/DataDirectoryUpdateSequence.java index 8adb0a777..d6b3ad6de 100644 --- a/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/config/catalog/backend/datadirectory/DataDirectoryUpdateSequence.java +++ b/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/config/catalog/backend/datadirectory/DataDirectoryUpdateSequence.java @@ -4,6 +4,7 @@ */ package org.geoserver.cloud.config.catalog.backend.datadirectory; +import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -12,6 +13,8 @@ import org.geoserver.config.GeoServer; import org.geoserver.config.GeoServerDataDirectory; import org.geoserver.config.GeoServerInfo; +import org.geoserver.config.GeoServerInitializer; +import org.geoserver.config.impl.GeoServerInfoImpl; import org.geoserver.config.util.XStreamPersister; import org.geoserver.config.util.XStreamPersisterFactory; import org.geoserver.platform.config.UpdateSequence; @@ -19,15 +22,13 @@ import org.geoserver.platform.resource.Resource; import org.geoserver.platform.resource.ResourceStore; import org.geoserver.platform.resource.Resources; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.Lazy; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; +import java.io.UncheckedIOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Optional; @@ -38,7 +39,7 @@ */ @Slf4j @RequiredArgsConstructor -public class DataDirectoryUpdateSequence implements UpdateSequence { +public class DataDirectoryUpdateSequence implements UpdateSequence, GeoServerInitializer { private static final String UPDATE_SEQUENCE_FILE_NAME = "updateSequence.properties"; @@ -47,38 +48,51 @@ public class DataDirectoryUpdateSequence implements UpdateSequence { private static final String CLUSTER_LOCK_NAME = "UPDATE_SEQUENCE"; /** Provides the cluster aware {@link ResourceStore#getLockProvider LockProvider} */ - private @Autowired @Qualifier("resourceStoreImpl") ResourceStore resourceStore; + private final @NonNull ResourceStore resourceStore; - private @Autowired @Lazy @Qualifier("geoServer") GeoServer geoServer; - private @Autowired GeoServerDataDirectory dd; - private @Autowired XStreamPersisterFactory xpf; + private final @NonNull GeoServerDataDirectory dd; + private final @NonNull XStreamPersisterFactory xpf; + private GeoServer geoServer; private XStreamPersister xp; - public @Override long currValue() { + @Override + public void initialize(GeoServer geoServer) throws IOException { + this.geoServer = geoServer; + Resource resource = getOrCreateResource(); + log.debug("Update sequence resource is {}", resource.path()); + } + + @Override + public long currValue() { try { - Resource resource = resource(); - if (!Resources.exists(resource)) { - org.geoserver.platform.resource.Resource.Lock clusterLock = lock(); - try { - resource = resource(); - if (!Resources.exists(resource)) { - initialize(resource); - } - } finally { - clusterLock.release(); - } - } + Resource resource = getOrCreateResource(); Properties props = load(resource); - final long currentValue = getValue(props); - return currentValue; + return getValue(props); } catch (IOException e) { - throw new IllegalStateException(e); + throw new UncheckedIOException(e); + } + } + + private Resource getOrCreateResource() throws IOException { + Resource resource = resource(); + if (!Resources.exists(resource)) { + org.geoserver.platform.resource.Resource.Lock clusterLock = lock(); + try { + resource = resource(); + if (!Resources.exists(resource)) { + initialize(resource); + } + } finally { + clusterLock.release(); + } } + return resource; } - public @Override long nextValue() { + @Override + public long nextValue() { org.geoserver.platform.resource.Resource.Lock clusterLock = lock(); try { final long newValue = computeAndSaveNewValue(); @@ -108,13 +122,13 @@ private void persistGeoServerInfo(long newValue) { GeoServerInfo info = ModificationProxy.unwrap(geoServer.getGlobal()); info.setUpdateSequence(newValue); Resource resource = dd.config(info); - XStreamPersister xp = persister(); + XStreamPersister persister = persister(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { - xp.save(info, out); + persister.save(info, out); resource.setContents(out.toByteArray()); } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } } @@ -159,21 +173,26 @@ protected Properties load(Resource resource) throws IOException { /** Precondition: be called while holding the {@link #lock()} */ private void initialize(Resource resource) throws IOException { + GeoServerInfo geoServerInfo = null; + if (null == geoServer) { + Resource configResource = dd.config(new GeoServerInfoImpl()); + if (Resources.exists(configResource)) { + geoServerInfo = xp.load(configResource.in(), GeoServerInfo.class); + } + } else { + geoServerInfo = geoServer.getGlobal(); + } final long initialValue = - Optional.ofNullable(geoServer.getGlobal()) - .map(GeoServerInfo::getUpdateSequence) - .orElse(0L); + Optional.ofNullable(geoServerInfo).map(GeoServerInfo::getUpdateSequence).orElse(0L); save(resource, initialValue); } - protected Resource resource() throws IOException { + protected Resource resource() { return resourceStore.get(UPDATE_SEQUENCE_FILE_NAME); } protected org.geoserver.platform.resource.Resource.Lock lock() { LockProvider lockProvider = resourceStore.getLockProvider(); - org.geoserver.platform.resource.Resource.Lock lock = - lockProvider.acquire(CLUSTER_LOCK_NAME); - return lock; + return lockProvider.acquire(CLUSTER_LOCK_NAME); } } diff --git a/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/config/catalog/backend/datadirectory/NoServletContextDataDirectoryResourceStore.java b/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/config/catalog/backend/datadirectory/NoServletContextDataDirectoryResourceStore.java index 0146e972e..b9d49a832 100644 --- a/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/config/catalog/backend/datadirectory/NoServletContextDataDirectoryResourceStore.java +++ b/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/config/catalog/backend/datadirectory/NoServletContextDataDirectoryResourceStore.java @@ -37,7 +37,8 @@ public NoServletContextDataDirectoryResourceStore(File resourceDirectory) { this.setBaseDirectory(resourceDirectory); } - public @Override void setServletContext(ServletContext servletContext) { + @Override + public void setServletContext(ServletContext servletContext) { log.debug("setServletContext(ServletContext) ignored, data directory explicitly provided."); } } diff --git a/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/event/remote/datadir/RemoteEventDataDirectoryProcessor.java b/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/event/remote/datadir/RemoteEventDataDirectoryProcessor.java index 5a8f09d4b..15c02e522 100644 --- a/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/event/remote/datadir/RemoteEventDataDirectoryProcessor.java +++ b/src/catalog/backends/datadir/src/main/java/org/geoserver/cloud/event/remote/datadir/RemoteEventDataDirectoryProcessor.java @@ -61,7 +61,7 @@ public void onUpdateSequenceEvent(UpdateSequenceEvent updateSequenceEvent) { } @EventListener(InfoRemoved.class) - public void onRemoteRemoveEvent(InfoRemoved event) { + public void onRemoteRemoveEvent(InfoRemoved event) { if (event.isLocal()) { return; } @@ -74,19 +74,13 @@ public void onRemoteRemoveEvent(InfoRemoved event) { case WorkspaceInfo: remove(objectId, catalogFacade::getWorkspace, catalogFacade::remove); break; - case CoverageInfo: - case FeatureTypeInfo: - case WmsLayerInfo: - case WmtsLayerInfo: + case CoverageInfo, FeatureTypeInfo, WmsLayerInfo, WmtsLayerInfo: remove( objectId, id -> catalogFacade.getResource(id, ResourceInfo.class), catalogFacade::remove); break; - case CoverageStoreInfo: - case DataStoreInfo: - case WmsStoreInfo: - case WmtsStoreInfo: + case CoverageStoreInfo, DataStoreInfo, WmsStoreInfo, WmtsStoreInfo: remove( objectId, id -> catalogFacade.getStore(id, StoreInfo.class), @@ -117,7 +111,7 @@ public void onRemoteRemoveEvent(InfoRemoved event) { } @EventListener(InfoAdded.class) - public void onRemoteAddEvent(InfoAdded event) { + public void onRemoteAddEvent(InfoAdded event) { if (event.isLocal()) { return; } @@ -203,7 +197,7 @@ public void onRemoteDefaultDataStoreEvent(DefaultDataStoreSet event) { } @EventListener(InfoModified.class) - public void onRemoteModifyEvent(InfoModified event) { + public void onRemoteModifyEvent(InfoModified event) { if (event.isLocal()) { return; } @@ -271,9 +265,9 @@ public void onRemoteModifyEvent(InfoModified event) { log.warn("Object not found on local Catalog, can't update upon {}", event); } else { patch.applyTo(info); - if (info instanceof CatalogInfo) { + if (info instanceof CatalogInfo catalogInfo) { // going directly through the CatalogFacade does not produce any further event - this.catalogFacade.update((CatalogInfo) info, patch); + this.catalogFacade.update(catalogInfo, patch); } log.debug( "Object updated: {}({}). Properties: {}", diff --git a/src/catalog/backends/datadir/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/datadir/DataDirectoryAutoConfigurationTest.java b/src/catalog/backends/datadir/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/datadir/DataDirectoryAutoConfigurationTest.java index d2de8fcaa..b4805ccc9 100644 --- a/src/catalog/backends/datadir/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/datadir/DataDirectoryAutoConfigurationTest.java +++ b/src/catalog/backends/datadir/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/datadir/DataDirectoryAutoConfigurationTest.java @@ -33,7 +33,7 @@ * Test {@link DataDirectoryBackendConfiguration} through {@link DataDirectoryAutoConfiguration} * when {@code geoserver.backend.data-directory.enabled=true} */ -public class DataDirectoryAutoConfigurationTest { +class DataDirectoryAutoConfigurationTest { private ApplicationContextRunner runner = new ApplicationContextRunner() @@ -64,7 +64,8 @@ public class DataDirectoryAutoConfigurationTest { "geoserver.backend.dataDirectory.location=/tmp/data_dir_autoconfiguration_test" // ); - public @Test void testProperties() { + @Test + void testProperties() { runner.run( context -> { @@ -77,21 +78,24 @@ public class DataDirectoryAutoConfigurationTest { }); } - public @Test void testCatalog() { + @Test + void testCatalog() { runner.run( context -> { assertThat(context).getBean("rawCatalog").isInstanceOf(LockingCatalog.class); }); } - public @Test void testGeoServer() { + @Test + void testGeoServer() { runner.run( context -> { assertThat(context).getBean("geoServer").isInstanceOf(LockingGeoServer.class); }); } - public @Test void testCatalogFacadeIsRawCatalogFacade() { + @Test + void testCatalogFacadeIsRawCatalogFacade() { runner.run( context -> { CatalogFacade rawCatalogFacade = @@ -101,7 +105,8 @@ public class DataDirectoryAutoConfigurationTest { }); } - public @Test void testCatalogFacade() { + @Test + void testCatalogFacade() { runner.run( context -> { assertThat(context) @@ -110,7 +115,8 @@ public class DataDirectoryAutoConfigurationTest { }); } - public @Test void testResourceLoader() { + @Test + void testResourceLoader() { runner.run( context -> { assertThat(context) @@ -119,7 +125,8 @@ public class DataDirectoryAutoConfigurationTest { }); } - public @Test void testGeoserverFacade() { + @Test + void testGeoserverFacade() { runner.run( context -> { assertThat(context) @@ -128,7 +135,8 @@ public class DataDirectoryAutoConfigurationTest { }); } - public @Test void testGeoserverLoaderLegacy() { + @Test + void testGeoserverLoaderLegacy() { runner.withPropertyValues("geoserver.backend.data-directory.parallel-loader=false") .run( context -> { @@ -138,7 +146,8 @@ public class DataDirectoryAutoConfigurationTest { }); } - public @Test void testGeoserverLoader() { + @Test + void testGeoserverLoader() { runner.run( context -> { assertThat(context) @@ -147,7 +156,8 @@ public class DataDirectoryAutoConfigurationTest { }); } - public @Test void testResourceStoreImpl() { + @Test + void testResourceStoreImpl() { runner.run( context -> { assertThat(context) @@ -156,7 +166,8 @@ public class DataDirectoryAutoConfigurationTest { }); } - public @Test void testUpdateSequence() { + @Test + void testUpdateSequence() { runner.run( context -> { assertThat(context) @@ -165,7 +176,8 @@ public class DataDirectoryAutoConfigurationTest { }); } - public @Test void testGeoServerConfigurationLock() { + @Test + void testGeoServerConfigurationLock() { runner.run( context -> { assertThat(context) diff --git a/src/catalog/backends/datadir/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/datadir/DataDirectoryUpdateSequenceTest.java b/src/catalog/backends/datadir/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/datadir/DataDirectoryUpdateSequenceTest.java index 5e6aa9f8b..32b0edf5b 100644 --- a/src/catalog/backends/datadir/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/datadir/DataDirectoryUpdateSequenceTest.java +++ b/src/catalog/backends/datadir/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/datadir/DataDirectoryUpdateSequenceTest.java @@ -24,7 +24,7 @@ "geoserver.backend.dataDirectory.location=/tmp/data_dir_autoconfiguration_test" }) @ActiveProfiles("test") -public class DataDirectoryUpdateSequenceTest implements UpdateSequenceConformanceTest { +class DataDirectoryUpdateSequenceTest implements UpdateSequenceConformanceTest { private @Autowired DataDirectoryUpdateSequence updateSequence; private @Autowired GeoServer geoserver; diff --git a/src/catalog/backends/datadir/src/test/resources/application.yml b/src/catalog/backends/datadir/src/test/resources/application.yml index 50ef7d8d0..8ca8b8f34 100644 --- a/src/catalog/backends/datadir/src/test/resources/application.yml +++ b/src/catalog/backends/datadir/src/test/resources/application.yml @@ -28,4 +28,4 @@ logging: org.geoserver.cloud.config.factory: warn org.geoserver.jdbcconfig: warn org.geoserver.jdbcstore: warn - org.geoserver.cloud.catalog.locking: debug + org.geoserver.cloud.catalog.locking: info diff --git a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/RemoteEventJdbcConfigAutoConfiguration.java b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/RemoteEventJdbcConfigAutoConfiguration.java index fe544fc8e..dbbff465b 100644 --- a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/RemoteEventJdbcConfigAutoConfiguration.java +++ b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/RemoteEventJdbcConfigAutoConfiguration.java @@ -6,6 +6,7 @@ import org.geoserver.cloud.autoconfigure.catalog.event.ConditionalOnCatalogEvents; import org.geoserver.cloud.event.remote.jdbcconfig.RemoteEventJdbcConfigProcessor; +import org.geoserver.jdbcconfig.internal.ConfigDatabase; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -15,7 +16,8 @@ public class RemoteEventJdbcConfigAutoConfiguration { @Bean - RemoteEventJdbcConfigProcessor jdbcConfigRemoteEventProcessor() { - return new RemoteEventJdbcConfigProcessor(); + RemoteEventJdbcConfigProcessor jdbcConfigRemoteEventProcessor( + ConfigDatabase jdbcConfigDatabase) { + return new RemoteEventJdbcConfigProcessor(jdbcConfigDatabase); } } diff --git a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcCatalogFacade.java b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcCatalogFacade.java index 8d3028f97..eeedf779d 100644 --- a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcCatalogFacade.java +++ b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcCatalogFacade.java @@ -7,7 +7,6 @@ import org.geoserver.catalog.Catalog; import org.geoserver.catalog.impl.CatalogImpl; import org.geoserver.catalog.plugin.CatalogFacadeExtensionAdapter; -import org.geoserver.catalog.plugin.CatalogFacadeExtensionAdapter.SilentCatalog; import org.geoserver.jdbcconfig.catalog.JDBCCatalogFacade; import org.geoserver.jdbcconfig.internal.ConfigDatabase; @@ -22,16 +21,18 @@ public CloudJdbcCatalogFacade(ConfigDatabase db) { this.db = db; } - public @Override void setCatalog(Catalog catalog) { + @Override + public void setCatalog(Catalog catalog) { this.catalog = catalog; CatalogImpl catalogForResolvingCatalogProperties = (CatalogImpl) catalog; - if (catalog instanceof CatalogFacadeExtensionAdapter.SilentCatalog) { - catalogForResolvingCatalogProperties = ((SilentCatalog) catalog).getSubject(); + if (catalog instanceof CatalogFacadeExtensionAdapter.SilentCatalog silentCatalog) { + catalogForResolvingCatalogProperties = silentCatalog.getSubject(); } db.setCatalog(catalogForResolvingCatalogProperties); } - public @Override Catalog getCatalog() { + @Override + public Catalog getCatalog() { return this.catalog; } } diff --git a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcConfigDatabase.java b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcConfigDatabase.java index f071301af..4fd860523 100644 --- a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcConfigDatabase.java +++ b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcConfigDatabase.java @@ -66,7 +66,8 @@ public void remove(Info info) { * we don't do caching here and the {@link CatalogClearingListener} produces null pointer * exceptions */ - public @Override void setCatalog(CatalogImpl catalog) { + @Override + public void setCatalog(CatalogImpl catalog) { super.setCatalog(catalog); catalog.removeListeners(CatalogClearingListener.class); } diff --git a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcConfigProperties.java b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcConfigProperties.java index 3a8399c81..d87c10166 100644 --- a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcConfigProperties.java +++ b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcConfigProperties.java @@ -7,6 +7,8 @@ import com.google.common.base.Optional; import com.google.common.base.Preconditions; +import lombok.EqualsAndHashCode; + import org.geoserver.jdbcconfig.internal.ConfigDatabase; import org.geoserver.jdbcconfig.internal.JDBCConfigProperties; import org.geoserver.jdbcconfig.internal.JDBCConfigPropertiesFactoryBean; @@ -22,9 +24,10 @@ import javax.sql.DataSource; /** Extends {@link JDBCConfigProperties} to not need a {@link JDBCConfigPropertiesFactoryBean} */ +@EqualsAndHashCode(callSuper = true) public class CloudJdbcConfigProperties extends JDBCConfigProperties { private static final long serialVersionUID = 1L; - private DataSource dataSource; + private transient DataSource dataSource; public CloudJdbcConfigProperties(DataSource dataSource) { super((JDBCConfigPropertiesFactoryBean) null); @@ -32,8 +35,9 @@ public CloudJdbcConfigProperties(DataSource dataSource) { } /** Override to not save at all */ - public @Override void save() throws IOException { - // factory.saveConfig(this); + @Override + public void save() throws IOException { + // no-op } public boolean isH2() { @@ -47,7 +51,8 @@ public boolean isPostgreSQL() { } /** Override to return {@code true} only if the db schema is not already created */ - public @Override boolean isInitDb() { + @Override + public boolean isInitDb() { boolean initDb = Boolean.parseBoolean(getProperty("initdb", "false")); if (initDb) { try (Connection c = dataSource.getConnection(); @@ -59,7 +64,7 @@ public boolean isPostgreSQL() { // table not found, proceed with initialization } } catch (SQLException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } return initDb; @@ -69,7 +74,8 @@ public boolean isPostgreSQL() { * Override to get the init script directly from the ones in the classpath (inside * gs-jdbcconfig.jar) */ - public @Override Resource getInitScript() { + @Override + public Resource getInitScript() { String scriptName; if (isH2()) { scriptName = "initdb.h2.sql"; @@ -89,15 +95,15 @@ public boolean isPostgreSQL() { ConfigDatabase.class.getPackage().getName(), scriptName); - Resource resource = org.geoserver.platform.resource.URIs.asResource(initScript); - return resource; + return org.geoserver.platform.resource.URIs.asResource(initScript); } /** * Override to throw an {@link UnsupportedOperationException}, we're not using {@link * DataSourceFactoryBean}, the datasource is provided by spring instead */ - public @Override Optional getJdbcUrl() { + @Override + public Optional getJdbcUrl() { throw new UnsupportedOperationException( "shouldn't be called, this module doesn't use org.geoserver.jdbcloader.DataSourceFactoryBean"); } diff --git a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcGeoServerLoader.java b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcGeoServerLoader.java index aa1e7e5c9..3cd8e3e73 100644 --- a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcGeoServerLoader.java +++ b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcGeoServerLoader.java @@ -5,7 +5,6 @@ package org.geoserver.cloud.config.catalog.backend.jdbcconfig; import org.geoserver.catalog.Catalog; -import org.geoserver.catalog.plugin.CatalogPlugin; import org.geoserver.cloud.config.catalog.backend.core.CoreBackendConfiguration; import org.geoserver.config.DefaultGeoServerLoader; import org.geoserver.config.GeoServer; @@ -21,8 +20,6 @@ import org.geoserver.platform.GeoServerExtensions; import org.geoserver.platform.GeoServerResourceLoader; import org.geoserver.platform.resource.Resource.Lock; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import java.io.IOException; import java.util.List; @@ -45,19 +42,22 @@ */ public class CloudJdbcGeoServerLoader extends DefaultGeoServerLoader { - private @Autowired @Qualifier("rawCatalog") Catalog rawCatalog; - private @Autowired GeoServer geoserver; + private Catalog rawCatalog; + private GeoServer geoserver; private JDBCConfigProperties config; private ConfigDatabase configdb; public CloudJdbcGeoServerLoader( + Catalog rawCatalog, + GeoServer geoserver, GeoServerResourceLoader resourceLoader, JDBCConfigProperties config, - ConfigDatabase configdb) - throws Exception { + ConfigDatabase configdb) { super(resourceLoader); + this.rawCatalog = rawCatalog; + this.geoserver = geoserver; this.config = config; this.configdb = configdb; } @@ -69,7 +69,7 @@ public CloudJdbcGeoServerLoader( @SuppressWarnings({"unchecked", "rawtypes"}) @Override - protected void loadGeoServer(GeoServer geoServer, XStreamPersister xp) throws Exception { + protected void loadGeoServer(GeoServer geoServer, XStreamPersister xp) { final Lock lock = resourceLoader.getLockProvider().acquire("GLOBAL"); try { if (geoServer.getGlobal() == null) { @@ -93,12 +93,12 @@ protected void loadGeoServer(GeoServer geoServer, XStreamPersister xp) throws Ex } @Override - protected void loadCatalog(Catalog catalog, XStreamPersister xp) throws Exception { - loadCatalogInternal((CatalogPlugin) catalog, xp); + protected void loadCatalog(Catalog catalog, XStreamPersister xp) throws IOException { + loadCatalogInternal(xp); catalog.addListener(new GeoServerResourcePersister(catalog)); } - private void loadCatalogInternal(CatalogPlugin catalog, XStreamPersister xp) throws Exception { + private void loadCatalogInternal(XStreamPersister xp) throws IOException { if (!config.isInitDb() && !config.isImport() && config.isRepopulate()) { ConfigDatabase configDatabase = this.configdb; configDatabase.repopulateQueryableProperties(); diff --git a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcGeoserverFacade.java b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcGeoserverFacade.java index 04ebd97cc..c9dc22b25 100644 --- a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcGeoserverFacade.java +++ b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcGeoserverFacade.java @@ -43,6 +43,8 @@ public class CloudJdbcGeoserverFacade implements GeoServerFacade { static final Logger LOGGER = Logging.getLogger(JDBCGeoServerFacade.class); + private static final String WORKSPACE_ID = "workspace.id"; + private static final String GLOBAL_ID = "GeoServerInfo.global"; private static final String GLOBAL_LOGGING_ID = "LoggingInfo.global"; @@ -68,8 +70,7 @@ public void setGeoServer(GeoServer geoServer) { @Override public GeoServerInfo getGlobal() { - GeoServerInfo global = db.getById(GLOBAL_ID, GeoServerInfo.class); - return global; + return db.getById(GLOBAL_ID, GeoServerInfo.class); } @Override @@ -79,8 +80,6 @@ public void setGlobal(GeoServerInfo global) { SettingsInfo defaultSettings = geoServer.getFactory().createSettings(); add(defaultSettings); global.setSettings(defaultSettings); - // JD: disabling this check, global settings should have an id - // }else if(null == global.getSettings().getId()){ } else { add(global.getSettings()); } @@ -109,8 +108,7 @@ public void save(GeoServerInfo global) { @Override public LoggingInfo getLogging() { - LoggingInfo loggingInfo = db.getById(GLOBAL_LOGGING_ID, LoggingInfo.class); - return loggingInfo; + return db.getById(GLOBAL_LOGGING_ID, LoggingInfo.class); } @Override @@ -167,11 +165,8 @@ public void save(ServiceInfo service) { @Override public SettingsInfo getSettings(WorkspaceInfo workspace) { - // Filter filter = equal("workspace.id", workspace.getId()); - // return db.get(SettingsInfo.class, filter); - String wsId = workspace.getId(); - return db.getByIdentity(SettingsInfo.class, "workspace.id", wsId); + return db.getByIdentity(SettingsInfo.class, WORKSPACE_ID, wsId); } @Override @@ -206,14 +201,14 @@ public Collection getServices() { private Filter filterForWorkspace(WorkspaceInfo workspace) { if (workspace != null && workspace != ANY_WORKSPACE) { - return equal("workspace.id", workspace.getId()); + return equal(WORKSPACE_ID, workspace.getId()); } else { return filterForGlobal(); } } private Filter filterForGlobal() { - return isNull("workspace.id"); + return isNull(WORKSPACE_ID); } @Override @@ -262,7 +257,7 @@ private T findByName( Filter filter = equal("name", name); if (null != workspace && ANY_WORKSPACE != workspace) { final String wsId = workspace.getId(); - Filter wsFilter = equal("workspace.id", wsId); + Filter wsFilter = equal(WORKSPACE_ID, wsId); filter = and(filter, wsFilter); } try { diff --git a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcStoreProperties.java b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcStoreProperties.java index 96688bd0b..2b601a414 100644 --- a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcStoreProperties.java +++ b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/CloudJdbcStoreProperties.java @@ -7,6 +7,8 @@ import com.google.common.base.Optional; import com.google.common.base.Preconditions; +import lombok.EqualsAndHashCode; + import org.geoserver.jdbcloader.DataSourceFactoryBean; import org.geoserver.jdbcstore.internal.JDBCResourceStoreProperties; import org.geoserver.jdbcstore.internal.JDBCResourceStorePropertiesFactoryBean; @@ -25,13 +27,14 @@ * Extends {@link JDBCResourceStoreProperties} to not need a {@link * JDBCResourceStorePropertiesFactoryBean} */ +@EqualsAndHashCode(callSuper = true) public class CloudJdbcStoreProperties extends JDBCResourceStoreProperties { private static final long serialVersionUID = 1L; private static final String DEFAULT_CACHE_DIRECTORY = System.getProperty("java.io.tmpdir") + File.separator + "geoserver-jdbcconfig-cache"; - private DataSource dataSource; + private transient DataSource dataSource; public CloudJdbcStoreProperties(DataSource dataSource) { super((JDBCResourceStorePropertiesFactoryBean) null); @@ -49,12 +52,14 @@ public File getCacheDirectory() { * Override to not save at all, the canonical source of config settings is the spring boot * configuration properties */ - public @Override void save() throws IOException { - // factory.saveConfig(this); + @Override + public void save() throws IOException { + // no-op } /** Override to return {@code true} only if the db schema is not already created */ - public @Override boolean isInitDb() { + @Override + public boolean isInitDb() { boolean initDb = Boolean.parseBoolean(getProperty("initdb", "false")); if (initDb) { try (Connection c = dataSource.getConnection(); @@ -66,7 +71,7 @@ public File getCacheDirectory() { // table not found, proceed with initialization } } catch (SQLException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } return initDb; @@ -76,7 +81,8 @@ public File getCacheDirectory() { * Override to get the init script directly from the ones in the classpath (inside * gs-jdbcconfig.jar) */ - public @Override Resource getInitScript() { + @Override + public Resource getInitScript() { final String driverClassName = getProperty("datasource.driverClassname"); String scriptName; switch (driverClassName) { @@ -99,15 +105,15 @@ public File getCacheDirectory() { JDBCResourceStoreProperties.class.getPackage().getName(), scriptName); - Resource resource = org.geoserver.platform.resource.URIs.asResource(initScript); - return resource; + return org.geoserver.platform.resource.URIs.asResource(initScript); } /** * Override to throw an {@link UnsupportedOperationException}, we're not using {@link * DataSourceFactoryBean}, the datasource is provided by spring instead */ - public @Override Optional getJdbcUrl() { + @Override + public Optional getJdbcUrl() { throw new UnsupportedOperationException( "shouldn't be called, this module doesn't use org.geoserver.jdbcloader.DataSourceFactoryBean"); } diff --git a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/JDBCConfigBackendConfigurer.java b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/JDBCConfigBackendConfigurer.java index e374852d1..e92cbfe22 100644 --- a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/JDBCConfigBackendConfigurer.java +++ b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/JDBCConfigBackendConfigurer.java @@ -14,9 +14,11 @@ import lombok.extern.slf4j.Slf4j; import org.geoserver.GeoServerConfigurationLock; +import org.geoserver.catalog.Catalog; import org.geoserver.catalog.plugin.CatalogFacadeExtensionAdapter; import org.geoserver.catalog.plugin.ExtendedCatalogFacade; import org.geoserver.cloud.config.catalog.backend.core.GeoServerBackendConfigurer; +import org.geoserver.config.GeoServer; import org.geoserver.config.GeoServerFacade; import org.geoserver.config.util.XStreamPersisterFactory; import org.geoserver.jdbcconfig.JDBCGeoServerLoader; @@ -30,6 +32,7 @@ import org.geoserver.jdbcstore.cache.SimpleResourceCache; import org.geoserver.jdbcstore.internal.JDBCQueryHelper; import org.geoserver.jdbcstore.locks.LockRegistryAdapter; +import org.geoserver.platform.GeoServerExtensions; import org.geoserver.platform.GeoServerResourceLoader; import org.geoserver.platform.config.UpdateSequence; import org.geoserver.platform.resource.Resource; @@ -190,18 +193,14 @@ CloudJdbcStoreProperties jdbcStoreProperties() { final ConfigDatabase jdbcConfigDB = jdbcConfigDB(); initDbSchema(jdbcConfigProperties, jdbcStoreProperties, jdbcConfigDB); - try { - // no fall back to data directory, jdbcconfig is either enabled and fully engaged, or - // not at all - JDBCResourceStore resourceStore; - resourceStore = new JDBCResourceStore(jdbcConfigDataSource(), jdbcStoreProperties); - resourceStore.setCache(jdbcResourceCache()); - resourceStore.setLockProvider(jdbcStoreLockProvider()); - resourceStore.setResourceNotificationDispatcher(resourceNotificationDispatcher()); - return resourceStore; - } catch (Exception e) { - throw new RuntimeException(e); - } + // no fall back to data directory, jdbcconfig is either enabled and fully engaged, or + // not at all + JDBCResourceStore resourceStore; + resourceStore = new JDBCResourceStore(jdbcConfigDataSource(), jdbcStoreProperties); + resourceStore.setCache(jdbcResourceCache()); + resourceStore.setLockProvider(jdbcStoreLockProvider()); + resourceStore.setResourceNotificationDispatcher(resourceNotificationDispatcher()); + return resourceStore; } @DependsOn({"extensions", "jdbcConfigDataSourceStartupValidator"}) @@ -258,8 +257,7 @@ DefaultLockRepository jdbcLockRepository() { protected @Override GeoServerFacade geoserverFacade() { initDbSchema(jdbcConfigProperties(), jdbcStoreProperties(), jdbcConfigDB()); ConfigDatabase configDB = jdbcConfigDB(); - CloudJdbcGeoserverFacade facade = new CloudJdbcGeoserverFacade(configDB); - return facade; + return new CloudJdbcGeoserverFacade(configDB); } @Bean(name = {"geoServerLoaderImpl", "JDBCGeoServerLoader"}) @@ -276,8 +274,11 @@ DefaultLockRepository jdbcLockRepository() { protected @Override CloudJdbcGeoServerLoader geoServerLoaderImpl() { JDBCConfigProperties config = jdbcConfigProperties(); ConfigDatabase configdb = jdbcConfigDB(); + Catalog rawCatalog = (Catalog) GeoServerExtensions.bean("rawCatalog"); + GeoServer geoserver = (GeoServer) GeoServerExtensions.bean("geoServer"); try { - return new CloudJdbcGeoServerLoader(resourceLoader(), config, configdb); + return new CloudJdbcGeoServerLoader( + rawCatalog, geoserver, resourceLoader(), config, configdb); } catch (Exception e) { throw new BeanInstantiationException(JDBCGeoServerLoader.class, e.getMessage(), e); } @@ -307,9 +308,7 @@ ConfigDatabase jdbcConfigDB() { DataSource dataSource = jdbcConfigDataSource(); XStreamInfoSerialBinding binding = jdbcPersistenceBinding(); CacheProvider cacheProvider = jdbcCacheProvider(); - ConfigDatabase configDb = - new CloudJdbcConfigDatabase(config, dataSource, binding, cacheProvider); - return configDb; + return new CloudJdbcConfigDatabase(config, dataSource, binding, cacheProvider); } private boolean initDbSchema( @@ -333,7 +332,8 @@ public StoreHelper(DataSource ds) { super(ds); } - public @Override void runScript(Resource script) { + @Override + public void runScript(Resource script) { super.runScript(script); } } diff --git a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/JdbcConfigUpdateSequence.java b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/JdbcConfigUpdateSequence.java index 82189aca0..e3ebbe74e 100644 --- a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/JdbcConfigUpdateSequence.java +++ b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/config/catalog/backend/jdbcconfig/JdbcConfigUpdateSequence.java @@ -66,7 +66,6 @@ public void afterPropertiesSet() throws Exception { incrementAndGetQuery = format("SELECT NEXTVAL('%s')", SEQUENCE_NAME); } else if (props.isH2()) { createSequenceStatement = format("CREATE SEQUENCE IF NOT EXISTS %s", SEQUENCE_NAME); - // getQuery = format("SELECT CURRVAL('%s')", SEQUENCE_NAME); getQuery = format( """ @@ -83,7 +82,6 @@ public void afterPropertiesSet() throws Exception { Statement st = c.createStatement()) { st.execute(createSequenceStatement); } - // incrementAndGet(); } protected long runAndGetLong(String query) { diff --git a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/event/remote/jdbcconfig/RemoteEventJdbcConfigProcessor.java b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/event/remote/jdbcconfig/RemoteEventJdbcConfigProcessor.java index 406ffe1c9..b66750e6e 100644 --- a/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/event/remote/jdbcconfig/RemoteEventJdbcConfigProcessor.java +++ b/src/catalog/backends/jdbcconfig/src/main/java/org/geoserver/cloud/event/remote/jdbcconfig/RemoteEventJdbcConfigProcessor.java @@ -4,6 +4,8 @@ */ package org.geoserver.cloud.event.remote.jdbcconfig; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.geoserver.catalog.CatalogInfo; @@ -13,7 +15,6 @@ import org.geoserver.cloud.event.info.InfoModified; import org.geoserver.cloud.event.info.InfoRemoved; import org.geoserver.jdbcconfig.internal.ConfigDatabase; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.event.EventListener; /** @@ -21,20 +22,22 @@ * from the {@link ConfigDatabase} cache */ @Slf4j(topic = "org.geoserver.cloud.bus.incoming.jdbcconfig") +@RequiredArgsConstructor public class RemoteEventJdbcConfigProcessor { - private @Autowired ConfigDatabase jdbcConfigDatabase; + + private final @NonNull ConfigDatabase jdbcConfigDatabase; @EventListener(InfoRemoved.class) - public void onRemoteRemoveEvent(InfoRemoved event) { + public void onRemoteRemoveEvent(InfoRemoved event) { evictConfigDatabaseEntry(event); } @EventListener(InfoModified.class) - public void onRemoteModifyEvent(InfoModified event) { + public void onRemoteModifyEvent(InfoModified event) { evictConfigDatabaseEntry(event); } - private void evictConfigDatabaseEntry(InfoEvent event) { + private void evictConfigDatabaseEntry(InfoEvent event) { event.remote() .ifPresent( remoteEvent -> { diff --git a/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JDBCConfigAutoConfigurationTest.java b/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JDBCConfigAutoConfigurationTest.java index a99be16e6..d72e35f5e 100644 --- a/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JDBCConfigAutoConfigurationTest.java +++ b/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JDBCConfigAutoConfigurationTest.java @@ -35,15 +35,17 @@ @SpringBootTest( classes = AutoConfigurationTestConfiguration.class, properties = "geoserver.backend.jdbcconfig.enabled=true") -public class JDBCConfigAutoConfigurationTest extends JDBCConfigTest { +class JDBCConfigAutoConfigurationTest extends JDBCConfigTest { private @Autowired JdbcConfigConfigurationProperties configProperties; - public @Test void testCatalog() { + @Test + void testCatalog() { assertThat(rawCatalog, instanceOf(CatalogImpl.class)); } - public @Test void testProperties() { + @Test + void testProperties() { assertNotNull(configProperties); assertNotNull(configProperties.getDatasource()); assertNotNull(configProperties.getCacheDirectory()); @@ -51,30 +53,36 @@ public class JDBCConfigAutoConfigurationTest extends JDBCConfigTest { "/tmp/geoserver-jdbcconfig-cache", configProperties.getCacheDirectory().toString()); } - public @Test void testCatalogFacade() { + @Test + void testCatalogFacade() { assertThat(rawCatalogFacade, instanceOf(CatalogFacadeExtensionAdapter.class)); assertThat( ((CatalogFacadeExtensionAdapter) rawCatalogFacade).getSubject(), instanceOf(JDBCCatalogFacade.class)); } - public @Test void testResourceLoader() { + @Test + void testResourceLoader() { assertThat(resourceLoader, instanceOf(GeoServerResourceLoader.class)); } - public @Test void testGeoserverFacade() { + @Test + void testGeoserverFacade() { assertThat(geoserverFacade, instanceOf(CloudJdbcGeoserverFacade.class)); } - public @Test void testGeoserverLoader() { + @Test + void testGeoserverLoader() { assertThat(geoserverLoader, instanceOf(CloudJdbcGeoServerLoader.class)); } - public @Test void testResourceStoreImpl() { + @Test + void testResourceStoreImpl() { assertThat(resourceStoreImpl, instanceOf(JDBCResourceStore.class)); } - public @Test void crudTest() { + @Test + void crudTest() { Catalog catalog = (Catalog) context.getBean("catalog"); WorkspaceInfoImpl ws = new WorkspaceInfoImpl(); ws.setName("test-ws"); @@ -85,7 +93,8 @@ public class JDBCConfigAutoConfigurationTest extends JDBCConfigTest { assertNull(catalog.getWorkspaceByName("test-ws")); } - public @Test void testUpdateSequence() { + @Test + void testUpdateSequence() { UpdateSequence updateSequence = context.getBean(UpdateSequence.class); assertThat(updateSequence, instanceOf(JdbcConfigUpdateSequence.class)); } diff --git a/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JDBCConfigAutoConfigurationWebDisabledTest.java b/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JDBCConfigAutoConfigurationWebDisabledTest.java index c67e9c1af..1d2937ef4 100644 --- a/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JDBCConfigAutoConfigurationWebDisabledTest.java +++ b/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JDBCConfigAutoConfigurationWebDisabledTest.java @@ -23,10 +23,10 @@ "geoserver.backend.jdbcconfig.enabled=true", "geoserver.backend.jdbcconfig.web.enabled=false" }) -public class JDBCConfigAutoConfigurationWebDisabledTest extends JDBCConfigTest { +class JDBCConfigAutoConfigurationWebDisabledTest extends JDBCConfigTest { @Test - public void testJDBCConfigStatusProvider() { + void testJDBCConfigStatusProvider() { assertThrows( NoSuchBeanDefinitionException.class, () -> context.getBean(JDBCConfigStatusProvider.class)); diff --git a/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JDBCConfigAutoConfigurationWebEnabledTest.java b/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JDBCConfigAutoConfigurationWebEnabledTest.java index 6d5764f69..b9db0f486 100644 --- a/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JDBCConfigAutoConfigurationWebEnabledTest.java +++ b/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JDBCConfigAutoConfigurationWebEnabledTest.java @@ -24,10 +24,10 @@ "geoserver.backend.jdbcconfig.web.enabled=true" }) @ActiveProfiles("test") -public class JDBCConfigAutoConfigurationWebEnabledTest extends JDBCConfigTest { +class JDBCConfigAutoConfigurationWebEnabledTest extends JDBCConfigTest { @Test - public void testJDBCConfigStatusProvider() { + void testJDBCConfigStatusProvider() { assertThat( context.getBean("JDBCConfigStatusProvider"), instanceOf(JDBCConfigStatusProvider.class)); diff --git a/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JdbcConfigDataSourceTest.java b/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JdbcConfigDataSourceTest.java index 468c9fccd..c6cbc2644 100644 --- a/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JdbcConfigDataSourceTest.java +++ b/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JdbcConfigDataSourceTest.java @@ -30,9 +30,10 @@ "geoserver.backend.jdbcconfig.datasource.connectionTimeout=250", // 250ms "geoserver.backend.jdbcconfig.datasource.idleTimeout=10000", // 10 secs }) -public class JdbcConfigDataSourceTest extends JDBCConfigTest { +class JdbcConfigDataSourceTest extends JDBCConfigTest { - public @Test void testDataSource() throws SQLException { + @Test + void testDataSource() throws SQLException { DataSource ds = context.getBean("jdbcConfigDataSource", DataSource.class); assertSame(ds, context.getBean("jdbcStoreDataSource", DataSource.class)); assertThat(ds, instanceOf(HikariDataSource.class)); diff --git a/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JdbcConfigUpdateSequenceTest.java b/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JdbcConfigUpdateSequenceTest.java index 35435e109..895dba378 100644 --- a/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JdbcConfigUpdateSequenceTest.java +++ b/src/catalog/backends/jdbcconfig/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/jdbcconfig/JdbcConfigUpdateSequenceTest.java @@ -16,8 +16,7 @@ @SpringBootTest( classes = AutoConfigurationTestConfiguration.class, properties = "geoserver.backend.jdbcconfig.enabled=true") -public class JdbcConfigUpdateSequenceTest extends JDBCConfigTest - implements UpdateSequenceConformanceTest { +class JdbcConfigUpdateSequenceTest extends JDBCConfigTest implements UpdateSequenceConformanceTest { private @Autowired JdbcConfigUpdateSequence updateSequence; @@ -33,7 +32,8 @@ public GeoServer getGeoSever() { @Disabled( "Couldn't get rid of the DB closed error if running more than one test, so better just run the parallel one") - public @Override @Test void testUpdateSequence() { + @Override + public @Test void testUpdateSequence() { // no-op } } diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/autoconfigure/catalog/backend/pgsql/PgsqlBackendAutoConfiguration.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/autoconfigure/catalog/backend/pgsql/PgsqlBackendAutoConfiguration.java index 11f202123..87a721b20 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/autoconfigure/catalog/backend/pgsql/PgsqlBackendAutoConfiguration.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/autoconfigure/catalog/backend/pgsql/PgsqlBackendAutoConfiguration.java @@ -4,8 +4,10 @@ */ package org.geoserver.cloud.autoconfigure.catalog.backend.pgsql; +import org.geoserver.cloud.config.catalog.backend.core.CatalogProperties; import org.geoserver.cloud.config.catalog.backend.pgsql.PgsqlBackendConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Import; /** @@ -13,5 +15,6 @@ */ @AutoConfiguration(after = PgsqlMigrationAutoConfiguration.class) @ConditionalOnPgsqlBackendEnabled +@EnableConfigurationProperties(CatalogProperties.class) @Import(PgsqlBackendConfiguration.class) public class PgsqlBackendAutoConfiguration {} diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/PgsqlCatalogFacade.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/PgsqlCatalogFacade.java index 5e7f15bee..8af7600d4 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/PgsqlCatalogFacade.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/PgsqlCatalogFacade.java @@ -29,6 +29,5 @@ public PgsqlCatalogFacade(@NonNull JdbcTemplate template) { super.setLayerRepository(new PgsqlLayerRepository(template)); super.setLayerGroupRepository(new PgsqlLayerGroupRepository(template)); super.setStyleRepository(new PgsqlStyleRepository(template)); - // super.setMapRepository(new PgsqlCatalogInfoRepository(template) {}); } } diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/filter/PgsqlFilterCapabilities.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/filter/PgsqlFilterCapabilities.java index d90206af2..4ae85007d 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/filter/PgsqlFilterCapabilities.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/filter/PgsqlFilterCapabilities.java @@ -4,6 +4,8 @@ */ package org.geoserver.cloud.backend.pgsql.catalog.filter; +import lombok.experimental.UtilityClass; + import org.geotools.api.filter.ExcludeFilter; import org.geotools.api.filter.Id; import org.geotools.api.filter.IncludeFilter; @@ -45,6 +47,7 @@ /** * @since 1.4 */ +@UtilityClass class PgsqlFilterCapabilities { private static final FilterCapabilities INSTANCE = createFilterCapabilities(); diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/filter/PgsqlFilterToSQL.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/filter/PgsqlFilterToSQL.java index 8619195e5..96a2e62d0 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/filter/PgsqlFilterToSQL.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/filter/PgsqlFilterToSQL.java @@ -31,6 +31,7 @@ import java.io.IOException; import java.io.StringWriter; +import java.io.UncheckedIOException; import java.io.Writer; import java.util.Date; import java.util.List; @@ -115,7 +116,7 @@ public Object visit(PropertyIsLike filter, Object extraData) { writeLiteral(pattern); } catch (java.io.IOException ioe) { - throw new RuntimeException(IO_ERROR, ioe); + throw new UncheckedIOException(IO_ERROR, ioe); } return extraData; } @@ -125,9 +126,9 @@ public Object visit(Function function, Object extraData) throws RuntimeException super.encodingFunction = true; boolean encoded; try { - encoded = visitFunction(function, extraData); + encoded = visitFunction(function); } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(IO_ERROR, e); } super.encodingFunction = false; @@ -169,7 +170,7 @@ protected String getFunctionName(Function function) { * * @implNote copied and adapted from org.geotools.data.postgis.FilterToSqlHelper */ - protected boolean visitFunction(Function function, Object extraData) throws IOException { + protected boolean visitFunction(Function function) throws IOException { if (function instanceof FilterFunction_strConcat) { Expression s1 = getParameter(function, 0, true); Expression s2 = getParameter(function, 1, true); @@ -213,20 +214,6 @@ protected boolean visitFunction(Function function, Object extraData) throws IOEx out.write("::text))"); return true; } - // if (function instanceof FilterFunction_strToLowerCase) { - // Expression first = getParameter(function, 0, true); - // out.write("(lower("); - // first.accept(this, String.class); - // out.write("::text))"); - // return true; - // } - // if (function instanceof FilterFunction_strToUpperCase) { - // Expression first = getParameter(function, 0, true); - // out.write("(upper("); - // first.accept(this, String.class); - // out.write("::text))"); - // return true; - // } if (function instanceof FilterFunction_strIndexOf) { Expression first = getParameter(function, 0, true); Expression second = getParameter(function, 1, true); @@ -275,14 +262,6 @@ protected boolean visitFunction(Function function, Object extraData) throws IOEx out.write(")"); return true; } - // if (function instanceof JsonPointerFunction) { - // encodeJsonPointer(function, extraData); - // return true; - // } - // if (function instanceof JsonArrayContainsFunction) { - // encodeJsonArrayContains(function); - // return true; - // } // function not supported return false; } diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/filter/ToPgsqlCompatibleFilterDuplicator.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/filter/ToPgsqlCompatibleFilterDuplicator.java index bb273a63a..1baeaa072 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/filter/ToPgsqlCompatibleFilterDuplicator.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/filter/ToPgsqlCompatibleFilterDuplicator.java @@ -41,7 +41,7 @@ public static Filter adapt(Filter filter) { @Override public Object visit(PropertyName expression, Object extraData) { - boolean matchCase = (extraData instanceof Boolean) ? (Boolean) extraData : true; + boolean matchCase = (extraData instanceof Boolean match) ? match : true; if (!matchCase) { return getFactory(null).function("strToLowerCase", expression); } @@ -50,7 +50,7 @@ public Object visit(PropertyName expression, Object extraData) { @Override public Object visit(Literal expression, Object extraData) { - boolean matchCase = (extraData instanceof Boolean) ? (Boolean) extraData : true; + boolean matchCase = (extraData instanceof Boolean match) ? match : true; if (!matchCase) { return getFactory(null).function("strToLowerCase", expression); } @@ -116,10 +116,7 @@ protected Filter visitBinaryComparisonOperator(BinaryComparisonOperator filter) Expression e1 = filter.getExpression1(); Expression e2 = filter.getExpression2(); - Literal literal = - e1 instanceof Literal - ? (Literal) e1 - : (e2 instanceof Literal ? (Literal) e2 : null); + Literal literal = e1 instanceof Literal l ? l : (e2 instanceof Literal l ? l : null); Object value = null == literal ? null : literal.getValue(); if (!(value instanceof Collection)) { diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/CatalogInfoRowMapper.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/CatalogInfoRowMapper.java index 53ae266f7..46a26c08f 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/CatalogInfoRowMapper.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/CatalogInfoRowMapper.java @@ -23,6 +23,7 @@ import org.geotools.jackson.databind.util.ObjectMapperUtil; import org.springframework.jdbc.core.RowMapper; +import java.io.UncheckedIOException; import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashMap; @@ -164,7 +165,7 @@ protected StyleInfo mapStyle(String id, ResultSet rs) { } protected StyleInfo mapStyle(String id, String column, ResultSet rs) { - return resolveCached(id, StyleInfo.class, rs, r -> loadStyle(r, "defaultStyle")); + return resolveCached(id, StyleInfo.class, rs, r -> loadStyle(r, column)); } /** @@ -370,7 +371,7 @@ protected V decode(String encoded, Class valueType) { try { return null == encoded ? null : infoMapper.readValue(encoded, valueType); } catch (JsonProcessingException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } } diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlCatalogInfoRepository.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlCatalogInfoRepository.java index ce42b3949..dd43ab1c9 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlCatalogInfoRepository.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlCatalogInfoRepository.java @@ -25,6 +25,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; +import java.io.UncheckedIOException; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; @@ -54,7 +55,7 @@ public abstract class PgsqlCatalogInfoRepository /** * @param template */ - public PgsqlCatalogInfoRepository(@NonNull JdbcTemplate template) { + protected PgsqlCatalogInfoRepository(@NonNull JdbcTemplate template) { this.template = template; } @@ -184,8 +185,7 @@ public Stream findAll(Query query) { if (!filterFullySupported) { filter = SimplifyingFilterVisitor.simplify(unsupportedFilter); - Predicate predicate = toPredicate(unsupportedFilter); - // Predicate predicate = toPredicate(filter); + Predicate predicate = toPredicate(filter); stream = stream.filter(predicate) .skip(query.offset().orElse(0)) @@ -347,7 +347,7 @@ protected String encode(T info) { try { return infoMapper.writeValueAsString(info); } catch (JsonProcessingException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } } @@ -361,7 +361,6 @@ protected String infoType(CatalogInfo value) { if (clazz.isInterface()) cm = ClassMappings.fromInterface(clazz); else cm = ClassMappings.fromImpl(clazz); - String infotype = cm.getInterface().getSimpleName(); - return infotype; + return cm.getInterface().getSimpleName(); } } diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlLayerGroupRepository.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlLayerGroupRepository.java index 6492afae3..1c31ceeb8 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlLayerGroupRepository.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlLayerGroupRepository.java @@ -4,7 +4,6 @@ */ package org.geoserver.cloud.backend.pgsql.catalog.repository; -import lombok.Getter; import lombok.NonNull; import org.geoserver.catalog.LayerGroupInfo; @@ -22,9 +21,6 @@ public class PgsqlLayerGroupRepository extends PgsqlCatalogInfoRepository implements LayerGroupRepository { - private final @Getter Class contentType = LayerGroupInfo.class; - private final @Getter String queryTable = "layergroupinfos"; - /** * @param template */ @@ -32,6 +28,16 @@ public PgsqlLayerGroupRepository(@NonNull JdbcTemplate template) { super(template); } + @Override + public Class getContentType() { + return LayerGroupInfo.class; + } + + @Override + protected String getQueryTable() { + return "layergroupinfos"; + } + @Override public Optional findByNameAndWorkspaceIsNull(@NonNull String name) { String sql = diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlLayerRepository.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlLayerRepository.java index 501d7f3d5..55a6fd1b2 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlLayerRepository.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlLayerRepository.java @@ -4,7 +4,6 @@ */ package org.geoserver.cloud.backend.pgsql.catalog.repository; -import lombok.Getter; import lombok.NonNull; import org.geoserver.catalog.LayerInfo; @@ -25,9 +24,6 @@ public class PgsqlLayerRepository extends PgsqlCatalogInfoRepository implements LayerRepository { - private final @Getter Class contentType = LayerInfo.class; - private final @Getter String queryTable = "layerinfos"; - /** * @param template */ @@ -35,6 +31,16 @@ public PgsqlLayerRepository(@NonNull JdbcTemplate template) { super(template); } + @Override + public Class getContentType() { + return LayerInfo.class; + } + + @Override + protected String getQueryTable() { + return "layerinfos"; + } + @Override public Optional findOneByName(@NonNull String possiblyPrefixedName) { String sql = diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlNamespaceRepository.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlNamespaceRepository.java index 50719c1ec..10bbd60a9 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlNamespaceRepository.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlNamespaceRepository.java @@ -4,7 +4,6 @@ */ package org.geoserver.cloud.backend.pgsql.catalog.repository; -import lombok.Getter; import lombok.NonNull; import org.geoserver.catalog.NamespaceInfo; @@ -21,9 +20,6 @@ public class PgsqlNamespaceRepository extends PgsqlCatalogInfoRepository implements NamespaceRepository { - private final @Getter Class contentType = NamespaceInfo.class; - private final @Getter String queryTable = "namespaceinfos"; - /** * @param template */ @@ -31,6 +27,16 @@ public PgsqlNamespaceRepository(@NonNull JdbcTemplate template) { super(template); } + @Override + public Class getContentType() { + return NamespaceInfo.class; + } + + @Override + protected String getQueryTable() { + return "namespaceinfos"; + } + @Override public void setDefaultNamespace(@NonNull NamespaceInfo namespace) { unsetDefaultNamespace(); diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlResourceRepository.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlResourceRepository.java index 07ccdd804..4fc8784dd 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlResourceRepository.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlResourceRepository.java @@ -4,7 +4,6 @@ */ package org.geoserver.cloud.backend.pgsql.catalog.repository; -import lombok.Getter; import lombok.NonNull; import org.geoserver.catalog.NamespaceInfo; @@ -23,8 +22,7 @@ public class PgsqlResourceRepository extends PgsqlCatalogInfoRepository implements ResourceRepository { - private final @Getter Class contentType = ResourceInfo.class; - private final @Getter String queryTable = "resourceinfos"; + private static final String AND_TYPE_INFOTYPE = " AND \"@type\" = ?::infotype"; /** * @param template @@ -33,6 +31,16 @@ public PgsqlResourceRepository(@NonNull JdbcTemplate template) { super(template); } + @Override + public Class getContentType() { + return ResourceInfo.class; + } + + @Override + protected String getQueryTable() { + return "resourceinfos"; + } + @Override public Optional findByNameAndNamespace( @NonNull String name, @NonNull NamespaceInfo namespace, @NonNull Class clazz) { @@ -45,7 +53,7 @@ public Optional findByNameAndNamespace( if (ResourceInfo.class.equals(clazz)) { return findOne(query, clazz, newRowMapper(), namespace.getId(), name); } - query += " AND \"@type\" = ?::infotype"; + query += AND_TYPE_INFOTYPE; return findOne(query, clazz, newRowMapper(), namespace.getId(), name, infoType(clazz)); } @@ -76,7 +84,7 @@ public Stream findAllByNamespace( if (ResourceInfo.class.equals(clazz)) { return template.queryForStream(query, newRowMapper(), ns.getId()).map(clazz::cast); } - query += " AND \"@type\" = ?::infotype"; + query += AND_TYPE_INFOTYPE; return template.queryForStream(query, newRowMapper(), ns.getId(), infoType(clazz)) .map(clazz::cast); } @@ -94,7 +102,7 @@ public Optional findByStoreAndName( if (ResourceInfo.class.equals(clazz)) { return findOne(query, clazz, newRowMapper(), store.getId(), name); } - query += " AND \"@type\" = ?::infotype"; + query += AND_TYPE_INFOTYPE; return findOne(query, clazz, newRowMapper(), store.getId(), name, infoType(clazz)); } @@ -109,7 +117,7 @@ public Stream findAllByStore(StoreInfo store, Class< if (ResourceInfo.class.equals(clazz)) { return template.queryForStream(query, newRowMapper(), store.getId()).map(clazz::cast); } - query += " AND \"@type\" = ?::infotype"; + query += AND_TYPE_INFOTYPE; return template.queryForStream(query, newRowMapper(), store.getId(), infoType(clazz)) .map(clazz::cast); } diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlStoreRepository.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlStoreRepository.java index 460b50f0e..28b325504 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlStoreRepository.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlStoreRepository.java @@ -4,7 +4,6 @@ */ package org.geoserver.cloud.backend.pgsql.catalog.repository; -import lombok.Getter; import lombok.NonNull; import org.geoserver.catalog.DataStoreInfo; @@ -23,9 +22,6 @@ public class PgsqlStoreRepository extends PgsqlCatalogInfoRepository implements StoreRepository { - private final @Getter Class contentType = StoreInfo.class; - private final @Getter String queryTable = "storeinfos"; - /** * @param template */ @@ -33,6 +29,16 @@ public PgsqlStoreRepository(@NonNull JdbcTemplate template) { super(template); } + @Override + public Class getContentType() { + return StoreInfo.class; + } + + @Override + protected String getQueryTable() { + return "storeinfos"; + } + @Override public Optional findById(@NonNull String id, Class clazz) { String sql = diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlStyleRepository.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlStyleRepository.java index 57bd84b41..71fd63dbb 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlStyleRepository.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlStyleRepository.java @@ -4,7 +4,6 @@ */ package org.geoserver.cloud.backend.pgsql.catalog.repository; -import lombok.Getter; import lombok.NonNull; import org.geoserver.catalog.StyleInfo; @@ -22,9 +21,6 @@ public class PgsqlStyleRepository extends PgsqlCatalogInfoRepository implements StyleRepository { - private final @Getter Class contentType = StyleInfo.class; - private final @Getter String queryTable = "styleinfos"; - /** * @param template */ @@ -32,6 +28,16 @@ public PgsqlStyleRepository(@NonNull JdbcTemplate template) { super(template); } + @Override + public Class getContentType() { + return StyleInfo.class; + } + + @Override + protected String getQueryTable() { + return "styleinfos"; + } + @Override public Stream findAllByNullWorkspace() { String query = diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlWorkspaceRepository.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlWorkspaceRepository.java index 1fcb81975..7decb8f9c 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlWorkspaceRepository.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/PgsqlWorkspaceRepository.java @@ -4,7 +4,6 @@ */ package org.geoserver.cloud.backend.pgsql.catalog.repository; -import lombok.Getter; import lombok.NonNull; import org.geoserver.catalog.WorkspaceInfo; @@ -21,9 +20,6 @@ public class PgsqlWorkspaceRepository extends PgsqlCatalogInfoRepository implements WorkspaceRepository { - private final @Getter Class contentType = WorkspaceInfo.class; - private final @Getter String queryTable = "workspaceinfos"; - /** * @param template */ @@ -31,6 +27,16 @@ public PgsqlWorkspaceRepository(@NonNull JdbcTemplate template) { super(template); } + @Override + public Class getContentType() { + return WorkspaceInfo.class; + } + + @Override + protected String getQueryTable() { + return "workspaceinfos"; + } + @Override public void unsetDefaultWorkspace() { template.update( diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/UncheckedSqlException.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/UncheckedSqlException.java index 2d820ea9b..5af3a6839 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/UncheckedSqlException.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/catalog/repository/UncheckedSqlException.java @@ -16,7 +16,8 @@ class UncheckedSqlException extends RuntimeException { super(cause); } - public @Override synchronized SQLException getCause() { + @Override + public synchronized SQLException getCause() { return (SQLException) super.getCause(); } diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/config/PgsqlConfigRepository.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/config/PgsqlConfigRepository.java index 65f36368e..d82fd2bda 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/config/PgsqlConfigRepository.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/config/PgsqlConfigRepository.java @@ -25,6 +25,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; +import java.io.UncheckedIOException; import java.util.Arrays; import java.util.NoSuchElementException; import java.util.Optional; @@ -194,7 +195,7 @@ public S update(S service, Patch patch) { } @Override - public Stream getGlobalServices() { + public Stream getGlobalServices() { return template.queryForStream( """ SELECT info, workspace FROM serviceinfos WHERE "workspace.id" IS NULL @@ -203,7 +204,7 @@ public Stream getGlobalServices() { } @Override - public Stream getServicesByWorkspace(WorkspaceInfo workspace) { + public Stream getServicesByWorkspace(WorkspaceInfo workspace) { String workspaceId = workspace.getId(); return template.queryForStream( """ @@ -297,7 +298,7 @@ private String encode(Info info) { try { return infoMapper.writeValueAsString(info); } catch (JsonProcessingException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } } @@ -305,7 +306,7 @@ private static C decode(String value, Class type) { try { return infoMapper.readValue(value, type); } catch (JsonProcessingException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } } @@ -314,8 +315,7 @@ private static C decode(String value, Class type) { if (clazz.isInterface()) cm = ClassMappings.fromInterface(clazz); else cm = ClassMappings.fromImpl(clazz); - String infotype = cm.getInterface().getSimpleName(); - return infotype; + return cm.getInterface().getSimpleName(); } protected Optional findOne( diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/config/PgsqlUpdateSequence.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/config/PgsqlUpdateSequence.java index 93e5ec7fa..0f3e78e84 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/config/PgsqlUpdateSequence.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/config/PgsqlUpdateSequence.java @@ -28,9 +28,9 @@ public class PgsqlUpdateSequence implements UpdateSequence { // not using CURRVAL() to avoid the "currval of sequence "" is not yet defined in this // session" error - private static final String getQuery = "SELECT last_value FROM %s".formatted(SEQUENCE_NAME); + private static final String GET_QUERY = "SELECT last_value FROM %s".formatted(SEQUENCE_NAME); - private static final String incrementAndGetQuery = + private static final String INCREMENT_AND_GET_QUERY = "SELECT NEXTVAL('%s')".formatted(SEQUENCE_NAME); private final @NonNull DataSource dataSource; @@ -38,12 +38,12 @@ public class PgsqlUpdateSequence implements UpdateSequence { @Override public long currValue() { - return runAndGetLong(getQuery); + return runAndGetLong(GET_QUERY); } @Override public synchronized long nextValue() { - long nextValue = runAndGetLong(incrementAndGetQuery); + long nextValue = runAndGetLong(INCREMENT_AND_GET_QUERY); GeoServerInfo global = geoServer.getGlobal(); if (null == global) { global = new GeoServerInfoImpl(); @@ -65,7 +65,7 @@ protected long runAndGetLong(String query) { if (rs.next()) { return rs.getLong(1); } - throw new IllegalStateException("Query did not return a result: " + getQuery); + throw new IllegalStateException("Query did not return a result: " + GET_QUERY); } finally { c.setAutoCommit(true); } diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/gwc/PgsqlTileLayerInfo.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/gwc/PgsqlTileLayerInfo.java index 1700da09d..bdf3c9b51 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/gwc/PgsqlTileLayerInfo.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/gwc/PgsqlTileLayerInfo.java @@ -4,6 +4,7 @@ */ package org.geoserver.cloud.backend.pgsql.gwc; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -12,14 +13,14 @@ /** * @since 1.4 */ +@EqualsAndHashCode(callSuper = true) @SuppressWarnings("serial") public class PgsqlTileLayerInfo extends GeoServerTileLayerInfoImpl { @Getter @Setter private String workspaceId; @Override - public GeoServerTileLayerInfoImpl clone() { - PgsqlTileLayerInfo clone = (PgsqlTileLayerInfo) super.clone(); - return clone; + public PgsqlTileLayerInfo clone() { + return (PgsqlTileLayerInfo) super.clone(); } } diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/resource/FileSystemResourceStoreCache.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/resource/FileSystemResourceStoreCache.java index de403e0b9..51b2f4679 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/resource/FileSystemResourceStoreCache.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/resource/FileSystemResourceStoreCache.java @@ -49,7 +49,8 @@ private FileSystemResourceStoreCache(@NonNull Path cacheDirectory, boolean dispo return new FileSystemResourceStoreCache(cacheDirectory, disposable); } - public @Override void destroy() { + @Override + public void destroy() { if (disposable && Files.isDirectory(this.base)) { try { log.info("Deleting resource store cache directory {}", base); @@ -74,8 +75,7 @@ public File getFile(PgsqlResource resource) { private long getLastmodified(final Path path) throws IOException { BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class); - long fileMtime = attr.lastModifiedTime().toMillis(); - return fileMtime; + return attr.lastModifiedTime().toMillis(); } public Path ensureFileExists(PgsqlResource resource) throws IOException { diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/resource/PgsqlResourceStore.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/resource/PgsqlResourceStore.java index 03763e88e..d62ae6975 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/resource/PgsqlResourceStore.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/backend/pgsql/resource/PgsqlResourceStore.java @@ -312,7 +312,8 @@ public OutputStream out(PgsqlResource res) { res.type = Type.RESOURCE; } return new ByteArrayOutputStream() { - public @Override void close() { + @Override + public void close() { if (!res.exists()) { String path = res.path(); save(res); diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/config/catalog/backend/pgsql/PgsqlBackendConfiguration.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/config/catalog/backend/pgsql/PgsqlBackendConfiguration.java index 78fcab93e..df49e472b 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/config/catalog/backend/pgsql/PgsqlBackendConfiguration.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/config/catalog/backend/pgsql/PgsqlBackendConfiguration.java @@ -18,12 +18,10 @@ import org.geoserver.cloud.backend.pgsql.resource.PgsqlResourceStore; import org.geoserver.cloud.config.catalog.backend.core.CatalogProperties; import org.geoserver.cloud.config.catalog.backend.core.GeoServerBackendConfigurer; -import org.geoserver.cloud.config.catalog.backend.pgsql.DatabaseMigrationConfiguration.Migrations; import org.geoserver.config.GeoServerLoader; import org.geoserver.platform.GeoServerResourceLoader; import org.geoserver.platform.resource.LockProvider; import org.geoserver.platform.resource.ResourceStore; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; @@ -45,19 +43,20 @@ public class PgsqlBackendConfiguration extends GeoServerBackendConfigurer { private String instanceId; private DataSource dataSource; - private @Autowired CatalogProperties properties; + private CatalogProperties catalogProperties; PgsqlBackendConfiguration( @Value("${info.instance-id:}") String instanceId, @Qualifier("pgsqlConfigDatasource") DataSource dataSource, - Migrations migrations) { + CatalogProperties catalogProperties) { this.instanceId = instanceId; this.dataSource = dataSource; + this.catalogProperties = catalogProperties; } @Bean CatalogPlugin rawCatalog() { - boolean isolated = properties.isIsolated(); + boolean isolated = catalogProperties.isIsolated(); CatalogPlugin rawCatalog = new CatalogPlugin(isolated); PgsqlCatalogFacade rawFacade = catalogFacade(); @@ -73,8 +72,7 @@ CatalogPlugin rawCatalog() { @Bean(name = "pgsqlCongigJdbcTemplate") JdbcTemplate template() { - JdbcTemplate template = new JdbcTemplate(dataSource); - return template; + return new JdbcTemplate(dataSource); } protected @Bean @Override GeoServerConfigurationLock configurationLock() { diff --git a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/config/catalog/backend/pgsql/PgsqlDatabaseMigrations.java b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/config/catalog/backend/pgsql/PgsqlDatabaseMigrations.java index ba4887f88..4c018aedc 100644 --- a/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/config/catalog/backend/pgsql/PgsqlDatabaseMigrations.java +++ b/src/catalog/backends/pgsql/src/main/java/org/geoserver/cloud/config/catalog/backend/pgsql/PgsqlDatabaseMigrations.java @@ -42,14 +42,12 @@ public void clean() { } protected Flyway buildFlyway() { - Flyway flyway = - Flyway.configure() - .dataSource(dataSource) - .schemas(schema) - .createSchemas(createSchema) - .cleanDisabled(cleanDisabled) - .locations("db/pgsqlcatalog/migration") - .load(); - return flyway; + return Flyway.configure() + .dataSource(dataSource) + .schemas(schema) + .createSchemas(createSchema) + .cleanDisabled(cleanDisabled) + .locations("db/pgsqlcatalog/migration") + .load(); } } diff --git a/src/catalog/backends/pgsql/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/pgsql/PgsqlBackendAutoConfigurationTest.java b/src/catalog/backends/pgsql/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/pgsql/PgsqlBackendAutoConfigurationTest.java index 9f9c8c5a2..05deb1d85 100644 --- a/src/catalog/backends/pgsql/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/pgsql/PgsqlBackendAutoConfigurationTest.java +++ b/src/catalog/backends/pgsql/src/test/java/org/geoserver/cloud/autoconfigure/catalog/backend/pgsql/PgsqlBackendAutoConfigurationTest.java @@ -12,7 +12,6 @@ import org.geoserver.cloud.backend.pgsql.config.PgsqlGeoServerFacade; import org.geoserver.cloud.backend.pgsql.config.PgsqlUpdateSequence; import org.geoserver.cloud.backend.pgsql.resource.PgsqlLockProvider; -import org.geoserver.cloud.config.catalog.backend.core.CatalogProperties; import org.geoserver.cloud.config.catalog.backend.pgsql.PgsqlGeoServerLoader; import org.geoserver.cloud.config.catalog.backend.pgsql.PgsqlGeoServerResourceLoader; import org.junit.jupiter.api.BeforeEach; @@ -34,7 +33,6 @@ class PgsqlBackendAutoConfigurationTest { private ApplicationContextRunner runner = new ApplicationContextRunner() - .withBean(CatalogProperties.class, CatalogProperties::new) .withConfiguration( AutoConfigurations.of( PgsqlDataSourceAutoConfiguration.class, diff --git a/src/catalog/backends/pgsql/src/test/java/org/geoserver/cloud/backend/pgsql/catalog/PgsqlCatalogBackendConformanceTest.java b/src/catalog/backends/pgsql/src/test/java/org/geoserver/cloud/backend/pgsql/catalog/PgsqlCatalogBackendConformanceTest.java index c1be1cf56..30e0c7da5 100644 --- a/src/catalog/backends/pgsql/src/test/java/org/geoserver/cloud/backend/pgsql/catalog/PgsqlCatalogBackendConformanceTest.java +++ b/src/catalog/backends/pgsql/src/test/java/org/geoserver/cloud/backend/pgsql/catalog/PgsqlCatalogBackendConformanceTest.java @@ -39,7 +39,8 @@ class PgsqlCatalogBackendConformanceTest extends CatalogConformanceTest { revisit, seems to be just a problem of ordering or equals with the \ returned ft/ft2 where mockito is not throwing the expected exception """) - public @Override void testSaveDataStoreRollbacksBothStoreAndResources() throws Exception {} + @Override + public void testSaveDataStoreRollbacksBothStoreAndResources() throws Exception {} static @BeforeAll void createDataSource() throws Exception { String url = container.getJdbcUrl(); diff --git a/src/catalog/backends/pgsql/src/test/java/org/geoserver/cloud/backend/pgsql/config/PgsqlConfigRepositoryConformanceTest.java b/src/catalog/backends/pgsql/src/test/java/org/geoserver/cloud/backend/pgsql/config/PgsqlConfigRepositoryConformanceTest.java index ac4436eb4..af3ab586d 100644 --- a/src/catalog/backends/pgsql/src/test/java/org/geoserver/cloud/backend/pgsql/config/PgsqlConfigRepositoryConformanceTest.java +++ b/src/catalog/backends/pgsql/src/test/java/org/geoserver/cloud/backend/pgsql/config/PgsqlConfigRepositoryConformanceTest.java @@ -26,7 +26,7 @@ * @since 1.4 */ @Testcontainers(disabledWithoutDocker = true) -public class PgsqlConfigRepositoryConformanceTest extends GeoServerConfigConformanceTest { +class PgsqlConfigRepositoryConformanceTest extends GeoServerConfigConformanceTest { @Container static PostgreSQLContainer container = new PostgreSQLContainer<>("postgres:15"); diff --git a/src/catalog/backends/pgsql/src/test/java/org/geoserver/cloud/backend/pgsql/resource/PgsqlResourceTest.java b/src/catalog/backends/pgsql/src/test/java/org/geoserver/cloud/backend/pgsql/resource/PgsqlResourceTest.java index b79f5351c..eddda70f8 100644 --- a/src/catalog/backends/pgsql/src/test/java/org/geoserver/cloud/backend/pgsql/resource/PgsqlResourceTest.java +++ b/src/catalog/backends/pgsql/src/test/java/org/geoserver/cloud/backend/pgsql/resource/PgsqlResourceTest.java @@ -36,7 +36,7 @@ import javax.sql.DataSource; @RunWith(Theories.class) -public class PgsqlResourceTest extends ResourceTheoryTest { +class PgsqlResourceTest extends ResourceTheoryTest { public @ClassRule static PostgreSQLContainer container = new PostgreSQLContainer<>("postgres:15"); diff --git a/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/CacheConfigurationPostProcessor.java b/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/CacheConfigurationPostProcessor.java index 5721d1170..cf840cad1 100644 --- a/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/CacheConfigurationPostProcessor.java +++ b/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/CacheConfigurationPostProcessor.java @@ -4,20 +4,22 @@ */ package org.geoserver.cloud.catalog.cache; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.geoserver.catalog.plugin.CatalogPlugin; import org.geoserver.config.plugin.GeoServerImpl; import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanPostProcessor; /** */ +@RequiredArgsConstructor @Slf4j(topic = "org.geoserver.cloud.catalog.caching") class CacheConfigurationPostProcessor implements BeanPostProcessor { - private @Autowired CachingCatalogFacade cachingCatalogFacade; - private @Autowired CachingGeoServerFacade cachingGeoServerFacade; + private final @NonNull CachingCatalogFacade cachingCatalogFacade; + private final @NonNull CachingGeoServerFacade cachingGeoServerFacade; @Override public Object postProcessAfterInitialization(Object bean, String beanName) diff --git a/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/CachingCatalogFacadeImpl.java b/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/CachingCatalogFacadeImpl.java index 13656a84e..e45cbd45b 100644 --- a/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/CachingCatalogFacadeImpl.java +++ b/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/CachingCatalogFacadeImpl.java @@ -20,7 +20,6 @@ import org.geoserver.catalog.plugin.ExtendedCatalogFacade; import org.geoserver.catalog.plugin.Patch; import org.geoserver.catalog.plugin.forwarding.ForwardingExtendedCatalogFacade; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.Cache; import org.springframework.cache.Cache.ValueWrapper; import org.springframework.cache.CacheManager; @@ -39,15 +38,13 @@ class CachingCatalogFacadeImpl extends ForwardingExtendedCatalogFacade implements CachingCatalogFacade { private Cache idCache; - public CachingCatalogFacadeImpl(ExtendedCatalogFacade facade) { + public CachingCatalogFacadeImpl(ExtendedCatalogFacade facade, CacheManager cacheManager) { super(facade); - } - - public @Autowired void setCacheManager(CacheManager cacheManager) { idCache = cacheManager.getCache(CachingCatalogFacade.CACHE_NAME); } - public @Override boolean evict(CatalogInfo info) { + @Override + public boolean evict(CatalogInfo info) { if (info == null || idCache == null) return false; if (info instanceof Catalog) { @@ -56,72 +53,73 @@ public CachingCatalogFacadeImpl(ExtendedCatalogFacade facade) { return evicted; } - if (info instanceof ResourceInfo) { - CatalogInfoKey layersByResourceKey = generateLayersByResourceKey((ResourceInfo) info); + if (info instanceof ResourceInfo ri) { + CatalogInfoKey layersByResourceKey = generateLayersByResourceKey(ri); idCache.evict(layersByResourceKey); - } else if (info instanceof LayerInfo) { - LayerInfo l = (LayerInfo) info; + } else if (info instanceof LayerInfo l) { ResourceInfo r = l.getResource(); if (r != null) { CatalogInfoKey layersByResourceKey = generateLayersByResourceKey(r); idCache.evict(layersByResourceKey); } - } else if (info instanceof WorkspaceInfo) { - WorkspaceInfo workspace = (WorkspaceInfo) info; + } else if (info instanceof WorkspaceInfo workspace) { idCache.evictIfPresent(CachingCatalogFacade.generateDefaultDataStoreKey(workspace)); } CatalogInfoKey key = new CatalogInfoKey(info); - boolean evicted = idCache.evictIfPresent(key); - return evicted; + return idCache.evictIfPresent(key); } - public @Override boolean evict(@NonNull Object key) { + @Override + public boolean evict(@NonNull Object key) { return idCache.evictIfPresent(key); } @CachePut(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override StoreInfo add(StoreInfo store) { + @Override + public StoreInfo add(StoreInfo store) { return super.add(store); } @CachePut(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override ResourceInfo add(ResourceInfo resource) { + @Override + public ResourceInfo add(ResourceInfo resource) { return super.add(resource); } @CachePut(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override LayerInfo add(LayerInfo layer) { + @Override + public LayerInfo add(LayerInfo layer) { return super.add(layer); } - // @CachePut(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - // public @Override LayerGroupInfo add(LayerGroupInfo layerGroup) { - // return super.add(layerGroup); - // } - @CachePut(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override NamespaceInfo add(NamespaceInfo namespace) { + @Override + public NamespaceInfo add(NamespaceInfo namespace) { return super.add(namespace); } @CachePut(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override WorkspaceInfo add(WorkspaceInfo workspace) { + @Override + public WorkspaceInfo add(WorkspaceInfo workspace) { return super.add(workspace); } @CachePut(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override StyleInfo add(StyleInfo style) { + @Override + public StyleInfo add(StyleInfo style) { return super.add(style); } @CacheEvict(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override void remove(StoreInfo store) { + @Override + public void remove(StoreInfo store) { super.remove(store); } @CacheEvict(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override void remove(ResourceInfo resource) { + @Override + public void remove(ResourceInfo resource) { super.remove(resource); } @@ -134,83 +132,86 @@ public CachingCatalogFacadeImpl(ExtendedCatalogFacade facade) { key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey('layers@' + #layer.resource.id, 'LAYER')") }) - public @Override void remove(LayerInfo layer) { + @Override + public void remove(LayerInfo layer) { super.remove(layer); } - // @CacheEvict(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - // public @Override void remove(LayerGroupInfo layerGroup) { - // super.remove(layerGroup); - // } - @CacheEvict(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override void remove(NamespaceInfo namespace) { + @Override + public void remove(NamespaceInfo namespace) { super.remove(namespace); } @CacheEvict(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override void remove(WorkspaceInfo workspace) { + @Override + public void remove(WorkspaceInfo workspace) { super.remove(workspace); } @CacheEvict(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override void remove(StyleInfo style) { + @Override + public void remove(StyleInfo style) { super.remove(style); } @CacheEvict(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override void save(StoreInfo store) { + @Override + public void save(StoreInfo store) { super.remove(store); } @CacheEvict(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override void save(ResourceInfo resource) { + @Override + public void save(ResourceInfo resource) { super.remove(resource); } @CacheEvict(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override void save(StyleInfo style) { + @Override + public void save(StyleInfo style) { super.save(style); } @CacheEvict(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override void save(LayerInfo layer) { + @Override + public void save(LayerInfo layer) { super.save(layer); } - // @CacheEvict(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - // public @Override void save(LayerGroupInfo layerGroup) { - // super.save(layerGroup); - // } - @CacheEvict(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override void save(NamespaceInfo namespace) { + @Override + public void save(NamespaceInfo namespace) { super.save(namespace); } @CacheEvict(key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#p0)") - public @Override void save(WorkspaceInfo workspace) { + @Override + public void save(WorkspaceInfo workspace) { super.save(workspace); } @CachePut( key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#info)", unless = "#result == null") - public @Override I update(final I info, final Patch patch) { + @Override + public I update(final I info, final Patch patch) { return super.update(info, patch); } @Cacheable( key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#id, 'WORKSPACE')", unless = "#result == null") - public @Override WorkspaceInfo getWorkspace(String id) { + @Override + public WorkspaceInfo getWorkspace(String id) { return super.getWorkspace(id); } @Cacheable( key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#id, 'NAMESPACE')", unless = "#result == null") - public @Override NamespaceInfo getNamespace(String id) { + @Override + public NamespaceInfo getNamespace(String id) { return super.getNamespace(id); } @@ -218,7 +219,8 @@ public CachingCatalogFacadeImpl(ExtendedCatalogFacade facade) { * @implNote manual caching; checks the cache using the requested type, but caches using the * result's concrete type */ - public @Override T getStore(String id, Class clazz) { + @Override + public T getStore(String id, Class clazz) { return getOrCache(id, clazz, super::getStore); } @@ -226,7 +228,8 @@ public CachingCatalogFacadeImpl(ExtendedCatalogFacade facade) { * @implNote manual caching; checks the cache using the requested type, but caches using the * result's concrete type */ - public @Override T getResource(String id, Class clazz) { + @Override + public T getResource(String id, Class clazz) { return getOrCache(id, clazz, super::getResource); } @@ -256,14 +259,16 @@ private T getOrCache( @Cacheable( key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#id, 'STYLE')", unless = "#result == null") - public @Override StyleInfo getStyle(String id) { + @Override + public StyleInfo getStyle(String id) { return super.getStyle(id); } @Cacheable( key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#id, 'LAYER')", unless = "#result == null") - public @Override LayerInfo getLayer(String id) { + @Override + public LayerInfo getLayer(String id) { return super.getLayer(id); } @@ -271,58 +276,46 @@ private T getOrCache( key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey('layers@' + #resource.id, 'LAYER')", unless = "#result.isEmpty()") - public @Override List getLayers(ResourceInfo resource) { + @Override + public List getLayers(ResourceInfo resource) { return super.getLayers(resource); } - // @Cacheable( - // key = "new org.geoserver.cloud.catalog.cache.CatalogInfoKey(#id, 'LAYERGROUP')", - // unless = "#result == null") - // public @Override LayerGroupInfo getLayerGroup(String id) { - // return super.getLayerGroup(id); - // } - @Cacheable(key = "'" + DEFAULT_WORKSPACE_CACHE_KEY + "'", unless = "#result == null") - public @Override WorkspaceInfo getDefaultWorkspace() { + @Override + public WorkspaceInfo getDefaultWorkspace() { return super.getDefaultWorkspace(); } @CacheEvict(key = "'" + DEFAULT_WORKSPACE_CACHE_KEY + "'") - public @Override void setDefaultWorkspace(WorkspaceInfo workspace) { + @Override + public void setDefaultWorkspace(WorkspaceInfo workspace) { super.setDefaultWorkspace(workspace); } @Cacheable(key = "'" + DEFAULT_NAMESPACE_CACHE_KEY + "'", unless = "#result == null") - public @Override NamespaceInfo getDefaultNamespace() { + @Override + public NamespaceInfo getDefaultNamespace() { return super.getDefaultNamespace(); } @CacheEvict(key = "'" + DEFAULT_NAMESPACE_CACHE_KEY + "'") - public @Override void setDefaultNamespace(NamespaceInfo defaultNamespace) { + @Override + public void setDefaultNamespace(NamespaceInfo defaultNamespace) { super.setDefaultNamespace(defaultNamespace); } @Cacheable( key = "'" + DEFAULT_DATASTORE_CACHE_KEY_PREFIX + "' + #p0.id", unless = "#result == null") - public @Override DataStoreInfo getDefaultDataStore(WorkspaceInfo workspace) { + @Override + public DataStoreInfo getDefaultDataStore(WorkspaceInfo workspace) { return super.getDefaultDataStore(workspace); } @CacheEvict(key = "'" + DEFAULT_DATASTORE_CACHE_KEY_PREFIX + "' + #p0.id") - public @Override void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo store) { + @Override + public void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo store) { super.setDefaultDataStore(workspace, store); } - - // public @Override T getStoreByName(WorkspaceInfo workspace, String - // name, Class clazz){} - // public @Override LayerInfo getLayerByName(String name){} - // public @Override LayerGroupInfo getLayerGroupByName(String name){} - // public @Override LayerGroupInfo getLayerGroupByName(WorkspaceInfo workspace, String - // name){} - // public @Override NamespaceInfo getNamespaceByPrefix(String prefix){} - // public @Override NamespaceInfo getNamespaceByURI(String uri){} - // public @Override WorkspaceInfo getWorkspaceByName(String name){} - // public @Override StyleInfo getStyleByName(String name){} - // public @Override StyleInfo getStyleByName(WorkspaceInfo workspace, String name){} } diff --git a/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/CachingGeoServerFacadeImpl.java b/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/CachingGeoServerFacadeImpl.java index b85cc3372..8e0861cc5 100644 --- a/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/CachingGeoServerFacadeImpl.java +++ b/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/CachingGeoServerFacadeImpl.java @@ -15,7 +15,6 @@ import org.geoserver.config.ServiceInfo; import org.geoserver.config.SettingsInfo; import org.geoserver.config.plugin.forwarding.ForwardingGeoServerFacade; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.Cache; import org.springframework.cache.Cache.ValueWrapper; import org.springframework.cache.CacheManager; @@ -66,8 +65,7 @@ public boolean evict(Info info) { return true; } } - if (info instanceof ServiceInfo) { - ServiceInfo service = (ServiceInfo) info; + if (info instanceof ServiceInfo service) { Object idKey = CachingGeoServerFacade.serviceByIdKey(service.getId()); ValueWrapper cachedValue = cache.get(idKey); if (cachedValue != null) { @@ -111,30 +109,31 @@ static T cachePut(@NonNull Cache cache, @NonNull T servi return service; } - public CachingGeoServerFacadeImpl(GeoServerFacade facade) { + public CachingGeoServerFacadeImpl(GeoServerFacade facade, CacheManager cacheManager) { super(facade); - } - - public @Autowired void setCacheManager(CacheManager cacheManager) { cache = cacheManager.getCache(CACHE_NAME); } @Cacheable(key = "'" + GEOSERVERINFO_KEY + "'", unless = "#result == null") - public @Override GeoServerInfo getGlobal() { + @Override + public GeoServerInfo getGlobal() { return super.getGlobal(); } @CacheEvict(key = "'" + GEOSERVERINFO_KEY + "'") - public @Override void setGlobal(GeoServerInfo global) { + @Override + public void setGlobal(GeoServerInfo global) { super.setGlobal(global); } @CacheEvict(key = "'" + GEOSERVERINFO_KEY + "'") - public @Override void save(GeoServerInfo geoServer) { + @Override + public void save(GeoServerInfo geoServer) { super.save(geoServer); } - public @Override SettingsInfo getSettings(WorkspaceInfo workspace) { + @Override + public SettingsInfo getSettings(WorkspaceInfo workspace) { SettingsInfo settings; Object key = CachingGeoServerFacade.settingsKey(workspace); ValueWrapper cached = cache.get(key); @@ -155,7 +154,8 @@ public CachingGeoServerFacadeImpl(GeoServerFacade facade) { @CacheEvict(key = "#settings.id"), @CacheEvict(key = "'settings@' + #settings.workspace.id") }) - public @Override void save(SettingsInfo settings) { + @Override + public void save(SettingsInfo settings) { super.save(settings); } @@ -164,36 +164,43 @@ public CachingGeoServerFacadeImpl(GeoServerFacade facade) { @CacheEvict(key = "#settings.id"), @CacheEvict(key = "'settings@' + #settings.workspace.id") }) - public @Override void remove(SettingsInfo settings) { + @Override + public void remove(SettingsInfo settings) { super.remove(settings); } @Cacheable(key = "'" + LOGGINGINFO_KEY + "'", unless = "#result == null") - public @Override LoggingInfo getLogging() { + @Override + public LoggingInfo getLogging() { return super.getLogging(); } @CacheEvict(key = "'" + LOGGINGINFO_KEY + "'") - public @Override void setLogging(LoggingInfo logging) { + @Override + public void setLogging(LoggingInfo logging) { super.setLogging(logging); } @CacheEvict(key = "'" + LOGGINGINFO_KEY + "'") - public @Override void save(LoggingInfo logging) { + @Override + public void save(LoggingInfo logging) { super.save(logging); } - public @Override void remove(ServiceInfo service) { + @Override + public void remove(ServiceInfo service) { evict(service); super.remove(service); } - public @Override void save(ServiceInfo service) { + @Override + public void save(ServiceInfo service) { evict(service); super.save(service); } - public @Override T getService(Class clazz) { + @Override + public T getService(Class clazz) { Object key = CachingGeoServerFacade.serviceByTypeKey(null, clazz); ValueWrapper value = cache.get(key); ServiceInfo service; @@ -205,7 +212,8 @@ public CachingGeoServerFacadeImpl(GeoServerFacade facade) { return clazz.isInstance(service) ? clazz.cast(service) : null; } - public @Override T getService(WorkspaceInfo workspace, Class clazz) { + @Override + public T getService(WorkspaceInfo workspace, Class clazz) { Object byTypeKey = CachingGeoServerFacade.serviceByTypeKey(workspace, clazz); ValueWrapper value = cache.get(byTypeKey); ServiceInfo service; @@ -217,7 +225,8 @@ public CachingGeoServerFacadeImpl(GeoServerFacade facade) { return clazz.isInstance(service) ? clazz.cast(service) : null; } - public @Override T getService(String id, Class clazz) { + @Override + public T getService(String id, Class clazz) { Object key = CachingGeoServerFacade.serviceByIdKey(id); ValueWrapper value = cache.get(key); ServiceInfo service; @@ -229,7 +238,8 @@ public CachingGeoServerFacadeImpl(GeoServerFacade facade) { return clazz.isInstance(service) ? clazz.cast(service) : null; } - public @Override T getServiceByName(String name, Class clazz) { + @Override + public T getServiceByName(String name, Class clazz) { Object key = CachingGeoServerFacade.serviceByNameKey((WorkspaceInfo) null, name); ValueWrapper value = cache.get(key); ServiceInfo service; @@ -241,7 +251,8 @@ public CachingGeoServerFacadeImpl(GeoServerFacade facade) { return clazz.isInstance(service) ? clazz.cast(service) : null; } - public @Override T getServiceByName( + @Override + public T getServiceByName( String name, WorkspaceInfo workspace, Class clazz) { Object key = CachingGeoServerFacade.serviceByNameKey(workspace, name); diff --git a/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/CatalogInfoKey.java b/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/CatalogInfoKey.java index 3420ba83b..527b87e6b 100644 --- a/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/CatalogInfoKey.java +++ b/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/CatalogInfoKey.java @@ -69,21 +69,22 @@ public CatalogInfoKey(String id, Class type) { } private ClassMappings resolveTypeId(Info info) { - Class type = CatalogInfoTypeRegistry.resolveType(info); - return resolveTypeId(type); + Class infoType = CatalogInfoTypeRegistry.resolveType(info); + return resolveTypeId(infoType); } private ClassMappings resolveTypeId(Class type) { return CatalogInfoTypeRegistry.determineKey(type); } - public @Override int hashCode() { + @Override + public int hashCode() { return id.hashCode(); - // return 31 * id.hashCode() + (type == null ? 0 : type.hashCode()); } - public @Override boolean equals(Object o) { - if (!CatalogInfoKey.class.isInstance(o)) return false; + @Override + public boolean equals(Object o) { + if (!(o instanceof CatalogInfoKey)) return false; CatalogInfoKey k = (CatalogInfoKey) o; diff --git a/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/GeoServerBackendCacheConfiguration.java b/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/GeoServerBackendCacheConfiguration.java index 8c5825019..608e5f971 100644 --- a/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/GeoServerBackendCacheConfiguration.java +++ b/src/catalog/cache/src/main/java/org/geoserver/cloud/catalog/cache/GeoServerBackendCacheConfiguration.java @@ -12,6 +12,7 @@ import org.geoserver.config.GeoServerFacade; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -31,26 +32,28 @@ public class GeoServerBackendCacheConfiguration implements BeanPostProcessor { @Bean - CacheConfigurationPostProcessor cacheConfigurationPostProcessor() { - return new CacheConfigurationPostProcessor(); + CacheConfigurationPostProcessor cacheConfigurationPostProcessor( + CachingCatalogFacade cachingCatalogFacade, + CachingGeoServerFacade cachingGeoServerFacade) { + return new CacheConfigurationPostProcessor(cachingCatalogFacade, cachingGeoServerFacade); } @Bean CachingCatalogFacade cachingCatalogFacade( - @Qualifier("catalogFacade") CatalogFacade rawCatalogFacade) { - CatalogFacade raw = rawCatalogFacade; + @Qualifier("catalogFacade") CatalogFacade rawCatalogFacade, CacheManager cacheManager) { ExtendedCatalogFacade facade; - if (raw instanceof ExtendedCatalogFacade) { - facade = (ExtendedCatalogFacade) rawCatalogFacade; + if (rawCatalogFacade instanceof ExtendedCatalogFacade ecf) { + facade = ecf; } else { - facade = new CatalogFacadeExtensionAdapter(raw); + facade = new CatalogFacadeExtensionAdapter(rawCatalogFacade); } - return new CachingCatalogFacadeImpl(facade); + return new CachingCatalogFacadeImpl(facade, cacheManager); } @Bean CachingGeoServerFacade cachingGeoServerFacade( - @Qualifier("geoserverFacade") GeoServerFacade rawGeoServerFacade) { - return new CachingGeoServerFacadeImpl(rawGeoServerFacade); + @Qualifier("geoserverFacade") GeoServerFacade rawGeoServerFacade, + CacheManager cacheManager) { + return new CachingGeoServerFacadeImpl(rawGeoServerFacade, cacheManager); } } diff --git a/src/catalog/cache/src/main/java/org/geoserver/cloud/event/remote/cache/RemoteEventCacheEvictor.java b/src/catalog/cache/src/main/java/org/geoserver/cloud/event/remote/cache/RemoteEventCacheEvictor.java index 9dae1ba20..113e8c166 100644 --- a/src/catalog/cache/src/main/java/org/geoserver/cloud/event/remote/cache/RemoteEventCacheEvictor.java +++ b/src/catalog/cache/src/main/java/org/geoserver/cloud/event/remote/cache/RemoteEventCacheEvictor.java @@ -152,7 +152,7 @@ private void applyUpdateSequence(Long updateSequence) { }); } - private void evictCatalogInfo(InfoEvent event) { + private void evictCatalogInfo(InfoEvent event) { evictEntry( event, () -> { @@ -164,7 +164,7 @@ private void evictCatalogInfo(InfoEvent event) { }); } - public void evictConfigEntry(InfoEvent event) { + public void evictConfigEntry(InfoEvent event) { evictEntry( event, () -> { @@ -175,7 +175,7 @@ public void evictConfigEntry(InfoEvent event) { }); } - private void evictEntry(InfoEvent event, BooleanSupplier evictor) { + private void evictEntry(InfoEvent event, BooleanSupplier evictor) { event.remote() .ifPresent( evt -> { diff --git a/src/catalog/cache/src/test/java/org/geoserver/cloud/catalog/cache/CachingCatalogFacadeTest.java b/src/catalog/cache/src/test/java/org/geoserver/cloud/catalog/cache/CachingCatalogFacadeTest.java index 6cacb2f4d..b44de962e 100644 --- a/src/catalog/cache/src/test/java/org/geoserver/cloud/catalog/cache/CachingCatalogFacadeTest.java +++ b/src/catalog/cache/src/test/java/org/geoserver/cloud/catalog/cache/CachingCatalogFacadeTest.java @@ -10,7 +10,6 @@ import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.times; @@ -60,7 +59,7 @@ @SpringBootTest(classes = GeoServerBackendCacheConfiguration.class) @EnableAutoConfiguration(exclude = LocalCatalogEventsAutoConfiguration.class) @SuppressWarnings("deprecation") -public class CachingCatalogFacadeTest { +class CachingCatalogFacadeTest { private @MockBean @Qualifier("defaultUpdateSequence") UpdateSequence updateSequence; private @MockBean @Qualifier("rawCatalog") CatalogPlugin rawCatalog; @@ -102,31 +101,32 @@ public class CachingCatalogFacadeTest { lg = stub(LayerGroupInfo.class); style = stub(StyleInfo.class); - when(mock.getWorkspace(eq(ws.getId()))).thenReturn(ws); - when(mock.getNamespace(eq(ns.getId()))).thenReturn(ns); + when(mock.getWorkspace(ws.getId())).thenReturn(ws); + when(mock.getNamespace(ns.getId())).thenReturn(ns); - when(mock.getStore(eq(ds.getId()), eq(StoreInfo.class))).thenReturn(ds); - when(mock.getStore(eq(ds.getId()), eq(DataStoreInfo.class))).thenReturn(ds); + when(mock.getStore(ds.getId(), StoreInfo.class)).thenReturn(ds); + when(mock.getStore(ds.getId(), DataStoreInfo.class)).thenReturn(ds); - when(mock.getStore(eq(cs.getId()), eq(StoreInfo.class))).thenReturn(cs); - when(mock.getStore(eq(cs.getId()), eq(CoverageStoreInfo.class))).thenReturn(cs); + when(mock.getStore(cs.getId(), StoreInfo.class)).thenReturn(cs); + when(mock.getStore(cs.getId(), CoverageStoreInfo.class)).thenReturn(cs); - when(mock.getResource(eq(ft.getId()), eq(ResourceInfo.class))).thenReturn(ft); - when(mock.getResource(eq(ft.getId()), eq(FeatureTypeInfo.class))).thenReturn(ft); + when(mock.getResource(ft.getId(), ResourceInfo.class)).thenReturn(ft); + when(mock.getResource(ft.getId(), FeatureTypeInfo.class)).thenReturn(ft); - when(mock.getResource(eq(c.getId()), eq(ResourceInfo.class))).thenReturn(c); - when(mock.getResource(eq(c.getId()), eq(CoverageInfo.class))).thenReturn(c); + when(mock.getResource(c.getId(), ResourceInfo.class)).thenReturn(c); + when(mock.getResource(c.getId(), CoverageInfo.class)).thenReturn(c); - when(mock.getLayer(eq(layer.getId()))).thenReturn(layer); - when(mock.getLayerGroup(eq(lg.getId()))).thenReturn(lg); + when(mock.getLayer(layer.getId())).thenReturn(layer); + when(mock.getLayerGroup(lg.getId())).thenReturn(lg); - when(mock.getStyle(eq(style.getId()))).thenReturn(style); + when(mock.getStyle(style.getId())).thenReturn(style); this.cache = cacheManager.getCache(CachingCatalogFacade.CACHE_NAME); this.cache.clear(); } - public @Test void testEvict() { + @Test + void testEvict() { testEvicts(ws, caching::evict); testEvicts(ns, caching::evict); testEvicts(ds, caching::evict); @@ -135,7 +135,8 @@ public class CachingCatalogFacadeTest { testEvicts(c, caching::evict); } - public @Test void testSuperTypeEvicts() { + @Test + void testSuperTypeEvicts() { CatalogInfoKey concreteTypeKey = new CatalogInfoKey(ds); CatalogInfoKey abstractTypeKey = new CatalogInfoKey(ds.getId(), StoreInfo.class); @@ -147,7 +148,8 @@ public class CachingCatalogFacadeTest { assertNull(cache.get(concreteTypeKey)); } - public @Test void testSubTypeEvicts() { + @Test + void testSubTypeEvicts() { CatalogInfoKey concreteTypeKey = new CatalogInfoKey(ft); CatalogInfoKey abstractTypeKey = new CatalogInfoKey(ft.getId(), ResourceInfo.class); @@ -160,7 +162,8 @@ public class CachingCatalogFacadeTest { assertNull(cache.get(abstractTypeKey)); } - public @Test void testPublishedInfoEvicts() { + @Test + void testPublishedInfoEvicts() { CatalogInfoKey concreteTypeKey = new CatalogInfoKey(layer); CatalogInfoKey abstractTypeKey = new CatalogInfoKey(layer.getId(), PublishedInfo.class); @@ -173,7 +176,8 @@ public class CachingCatalogFacadeTest { assertNull(cache.get(concreteTypeKey)); } - public @Test void testAddStoreInfo() { + @Test + void testAddStoreInfo() { DataStoreInfo info = this.ds; DataStoreInfo added = stub(DataStoreInfo.class, 1); // same id when(mock.add(same(info))).thenReturn(added); @@ -181,29 +185,32 @@ public class CachingCatalogFacadeTest { assertSame(added, cache.get(new CatalogInfoKey(info)).get(), "expected cache put"); } - public @Test void testRemoveStoreInfo() { + @Test + void testRemoveStoreInfo() { testEvicts(ds, caching::remove); testEvicts(cs, caching::remove); } - public @Test void testSaveStoreInfo() { + @Test + void testSaveStoreInfo() { testEvicts(ds, caching::save); testEvicts(cs, caching::save); } - public @Test void testGetStore() { + @Test + void testGetStore() { assertSameTimesN(ds, id -> caching.getStore(id, DataStoreInfo.class), 3); - verify(mock, times(1)).getStore(eq(ds.getId()), eq(DataStoreInfo.class)); + verify(mock, times(1)).getStore(ds.getId(), DataStoreInfo.class); assertSameTimesN(ds, id -> caching.getStore(id, StoreInfo.class), 3); // assertSame(ds, caching.getStore(ds.getId(), StoreInfo.class)); - verify(mock, times(0)).getStore(eq(ds.getId()), eq(StoreInfo.class)); + verify(mock, times(0)).getStore(ds.getId(), StoreInfo.class); assertSameTimesN(cs, id -> caching.getStore(id, StoreInfo.class), 3); - verify(mock, times(1)).getStore(eq(cs.getId()), eq(StoreInfo.class)); + verify(mock, times(1)).getStore(cs.getId(), StoreInfo.class); assertSameTimesN(cs, id -> caching.getStore(id, CoverageStoreInfo.class), 3); - verify(mock, times(0)).getStore(eq(cs.getId()), eq(CoverageStoreInfo.class)); + verify(mock, times(0)).getStore(cs.getId(), CoverageStoreInfo.class); verifyNoMoreInteractions(mock); @@ -211,7 +218,8 @@ public class CachingCatalogFacadeTest { assertNull(caching.getStore(cs.getId(), DataStoreInfo.class)); } - public @Test void testGetDefaultDataStore() { + @Test + void testGetDefaultDataStore() { final Object key = CachingCatalogFacade.generateDefaultDataStoreKey(ws); assertNull(caching.getDefaultDataStore(ws)); assertNull(cache.get(key), "null return value should have not been cached"); @@ -231,7 +239,8 @@ public class CachingCatalogFacadeTest { verify(mock, times(1)).getDefaultDataStore(same(ws)); } - public @Test void testSetDefaultDataStore() { + @Test + void testSetDefaultDataStore() { final Object key = CachingCatalogFacade.generateDefaultDataStoreKey(ws); when(mock.getDefaultDataStore(same(ws))).thenReturn(ds); assertSame(ds, caching.getDefaultDataStore(ws)); @@ -248,7 +257,8 @@ public class CachingCatalogFacadeTest { assertNull(cache.get(key), "expected cache evict"); } - public @Test void testAddResourceInfo() { + @Test + void testAddResourceInfo() { FeatureTypeInfo info = this.ft; FeatureTypeInfo added = stub(FeatureTypeInfo.class, 1); // same id when(mock.add(same(info))).thenReturn(added); @@ -256,29 +266,33 @@ public class CachingCatalogFacadeTest { assertSame(added, cache.get(new CatalogInfoKey(info)).get(), "expected cache put"); } - public @Test void testRemoveResourceInfo() { + @Test + void testRemoveResourceInfo() { testEvicts(ft, caching::remove); testEvicts(c, caching::remove); } - public @Test void testSaveResourceInfo() { + @Test + void testSaveResourceInfo() { testEvicts(ft, caching::save); testEvicts(c, caching::save); } - public @Test void testGetResource() { + @Test + void testGetResource() { CatalogInfo info = ft; assertSameTimesN(info, id -> caching.getResource(id, ResourceInfo.class), 3); - verify(mock, times(1)).getResource(eq(info.getId()), eq(ResourceInfo.class)); + verify(mock, times(1)).getResource(info.getId(), ResourceInfo.class); assertSameTimesN(info, id -> caching.getResource(id, FeatureTypeInfo.class), 3); - verify(mock, times(0)).getResource(eq(info.getId()), eq(FeatureTypeInfo.class)); + verify(mock, times(0)).getResource(info.getId(), FeatureTypeInfo.class); assertNull(caching.getResource(ft.getId(), CoverageInfo.class)); assertNull(caching.getResource(c.getId(), FeatureTypeInfo.class)); } - public @Test void testAddLayerInfo() { + @Test + void testAddLayerInfo() { LayerInfo info = this.layer; LayerInfo added = stub(LayerInfo.class, 1); // same id when(mock.add(same(info))).thenReturn(added); @@ -286,11 +300,13 @@ public class CachingCatalogFacadeTest { assertSame(added, cache.get(new CatalogInfoKey(info)).get(), "expected cache put"); } - public @Test void testRemoveLayerInfo() { + @Test + void testRemoveLayerInfo() { testEvicts(layer, caching::remove); } - public @Test void testRemoveLayerEvictsLayersPerResource() { + @Test + void testRemoveLayerEvictsLayersPerResource() { assertNotNull(layer.getResource()); List layers = Collections.singletonList(layer); when(mock.getLayers(same(ft))).thenReturn(layers); @@ -306,17 +322,20 @@ public class CachingCatalogFacadeTest { assertNull(cache.get(layersKey), "layers by resource not evicted then layer deleted"); } - public @Test void testSaveLayerInfo() { + @Test + void testSaveLayerInfo() { testEvicts(layer, caching::save); } - public @Test void testGetLayer() { + @Test + void testGetLayer() { CatalogInfo info = layer; assertSameTimesN(info, caching::getLayer, 3); - verify(mock, times(1)).getLayer(eq(info.getId())); + verify(mock, times(1)).getLayer(info.getId()); } - public @Test void testGetLayersByResource() { + @Test + void testGetLayersByResource() { List expected = Collections.singletonList(layer); when(mock.getLayers(same(ft))).thenReturn(expected); @@ -333,7 +352,8 @@ public class CachingCatalogFacadeTest { } @Disabled("LayerGroups are not cached") - public @Test void testAddLayerGroupInfo() { + @Test + void testAddLayerGroupInfo() { LayerGroupInfo info = this.lg; LayerGroupInfo added = stub(LayerGroupInfo.class, 1); // same id when(mock.add(same(info))).thenReturn(added); @@ -342,23 +362,27 @@ public class CachingCatalogFacadeTest { } @Disabled("LayerGroups are not cached") - public @Test void testRemoveLayerGroupInfo() { + @Test + void testRemoveLayerGroupInfo() { testEvicts(lg, caching::remove); } @Disabled("LayerGroups are not cached") - public @Test void testSaveLayerGroupInfo() { + @Test + void testSaveLayerGroupInfo() { testEvicts(lg, caching::save); } @Disabled("LayerGroups are not cached") - public @Test void testGetLayerGroup() { + @Test + void testGetLayerGroup() { CatalogInfo info = lg; assertSameTimesN(info, caching::getLayerGroup, 3); - verify(mock, times(1)).getLayerGroup(eq(info.getId())); + verify(mock, times(1)).getLayerGroup(info.getId()); } - public @Test void testAddNamespaceInfo() { + @Test + void testAddNamespaceInfo() { NamespaceInfo info = this.ns2; NamespaceInfo added = stub(NamespaceInfo.class, 2); // same id when(mock.add(same(info))).thenReturn(added); @@ -366,15 +390,18 @@ public class CachingCatalogFacadeTest { assertSame(added, cache.get(new CatalogInfoKey(info)).get(), "expected cache put"); } - public @Test void testRemoveNamespaceInfo() { + @Test + void testRemoveNamespaceInfo() { testEvicts(ns, caching::remove); } - public @Test void testSaveNamespaceInfo() { + @Test + void testSaveNamespaceInfo() { testEvicts(ns, caching::save); } - public @Test void testGetDefaultNamespace() { + @Test + void testGetDefaultNamespace() { final String key = CachingCatalogFacade.DEFAULT_NAMESPACE_CACHE_KEY; assertNull(caching.getDefaultNamespace()); assertNull(cache.get(key)); @@ -388,7 +415,8 @@ public class CachingCatalogFacadeTest { verify(mock, times(1)).getDefaultNamespace(); } - public @Test void testSetDefaultNamespace() { + @Test + void testSetDefaultNamespace() { final String key = CachingCatalogFacade.DEFAULT_NAMESPACE_CACHE_KEY; when(mock.getDefaultNamespace()).thenReturn(ns); assertSame(ns, caching.getDefaultNamespace()); @@ -403,18 +431,21 @@ public class CachingCatalogFacadeTest { assertNull(cache.get(key), "expected cache evict"); } - public @Test void testGetNamespace() { + @Test + void testGetNamespace() { CatalogInfo info = ns; assertSameTimesN(info, caching::getNamespace, 3); - verify(mock, times(1)).getNamespace(eq(info.getId())); + verify(mock, times(1)).getNamespace(info.getId()); } - public @Test void testGetWorkspace() { + @Test + void testGetWorkspace() { assertSameTimesN(ws, caching::getWorkspace, 3); - verify(mock, times(1)).getWorkspace(eq(ws.getId())); + verify(mock, times(1)).getWorkspace(ws.getId()); } - public @Test void testAddWorkspaceInfo() { + @Test + void testAddWorkspaceInfo() { WorkspaceInfo info = this.ws; WorkspaceInfo added = stub(WorkspaceInfo.class, 1); // same id than ws when(mock.add(same(info))).thenReturn(added); @@ -422,15 +453,18 @@ public class CachingCatalogFacadeTest { assertSame(added, cache.get(new CatalogInfoKey(info)).get(), "expected cache put"); } - public @Test void testRemoveWorkspaceInfo() { + @Test + void testRemoveWorkspaceInfo() { testEvicts(ws, caching::remove); } - public @Test void testSaveWorkspaceInfo() { + @Test + void testSaveWorkspaceInfo() { testEvicts(ws, caching::save); } - public @Test void testGetDefaultWorkspace() { + @Test + void testGetDefaultWorkspace() { assertNull(caching.getDefaultWorkspace()); assertNull(cache.get(CachingCatalogFacade.DEFAULT_WORKSPACE_CACHE_KEY)); @@ -443,7 +477,8 @@ public class CachingCatalogFacadeTest { verify(mock, times(1)).getDefaultWorkspace(); } - public @Test void testSetDefaultWorkspace() { + @Test + void testSetDefaultWorkspace() { final String key = CachingCatalogFacade.DEFAULT_WORKSPACE_CACHE_KEY; when(mock.getDefaultWorkspace()).thenReturn(ws); assertSame(ws, caching.getDefaultWorkspace()); @@ -458,7 +493,8 @@ public class CachingCatalogFacadeTest { assertNull(cache.get(key), "expected cache evict"); } - public @Test void testAddStyleInfo() { + @Test + void testAddStyleInfo() { StyleInfo info = this.style; StyleInfo added = stub(StyleInfo.class, 1); // same id when(mock.add(same(info))).thenReturn(added); @@ -466,21 +502,25 @@ public class CachingCatalogFacadeTest { assertSame(added, cache.get(new CatalogInfoKey(info)).get(), "expected cache put"); } - public @Test void testRemoveStyleInfo() { + @Test + void testRemoveStyleInfo() { testEvicts(style, caching::remove); } - public @Test void testSaveStyleInfo() { + @Test + void testSaveStyleInfo() { testEvicts(style, caching::save); } - public @Test void testGetStyle() { + @Test + void testGetStyle() { CatalogInfo info = style; assertSameTimesN(info, caching::getStyle, 3); - verify(mock, times(1)).getStyle(eq(info.getId())); + verify(mock, times(1)).getStyle(info.getId()); } - public @Test void testUpdate() { + @Test + void testUpdate() { DataStoreInfo info = this.ds; DataStoreInfo updated = stub(DataStoreInfo.class, 1); // same id when(mock.update(same(info), any())).thenReturn(updated); diff --git a/src/catalog/cache/src/test/java/org/geoserver/cloud/catalog/cache/CachingGeoServerFacadeTest.java b/src/catalog/cache/src/test/java/org/geoserver/cloud/catalog/cache/CachingGeoServerFacadeTest.java index 717e7b2e9..9c3322112 100644 --- a/src/catalog/cache/src/test/java/org/geoserver/cloud/catalog/cache/CachingGeoServerFacadeTest.java +++ b/src/catalog/cache/src/test/java/org/geoserver/cloud/catalog/cache/CachingGeoServerFacadeTest.java @@ -5,8 +5,6 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -42,7 +40,7 @@ @SpringBootTest(classes = GeoServerBackendCacheConfiguration.class) @EnableAutoConfiguration(exclude = LocalCatalogEventsAutoConfiguration.class) -public class CachingGeoServerFacadeTest { +class CachingGeoServerFacadeTest { private @MockBean @Qualifier("defaultUpdateSequence") UpdateSequence updateSequence; private @MockBean @Qualifier("rawCatalog") CatalogPlugin rawCatalog; @@ -91,45 +89,43 @@ public static interface TestService2 extends ServiceInfo {} when(mock.getService(TestService1.class)).thenReturn(service1); when(mock.getService(TestService2.class)).thenReturn(service2); - when(mock.getService(eq(service1.getId()), eq(ServiceInfo.class))).thenReturn(service1); - when(mock.getService(eq(service1.getId()), eq(TestService1.class))).thenReturn(service1); - when(mock.getService(eq(service2.getId()), eq(ServiceInfo.class))).thenReturn(service2); - when(mock.getService(eq(service2.getId()), eq(TestService2.class))).thenReturn(service2); + when(mock.getService(service1.getId(), ServiceInfo.class)).thenReturn(service1); + when(mock.getService(service1.getId(), TestService1.class)).thenReturn(service1); + when(mock.getService(service2.getId(), ServiceInfo.class)).thenReturn(service2); + when(mock.getService(service2.getId(), TestService2.class)).thenReturn(service2); doReturn(Arrays.asList(service1, service2)).when(mock).getServices(); - when(mock.getService(same(ws), eq(TestService1.class))).thenReturn(wsService1); - when(mock.getService(same(ws), eq(TestService2.class))).thenReturn(wsService2); - doReturn(Arrays.asList(wsService1, wsService2)).when(mock).getServices(same(ws)); + when(mock.getService(ws, TestService1.class)).thenReturn(wsService1); + when(mock.getService(ws, TestService2.class)).thenReturn(wsService2); + doReturn(Arrays.asList(wsService1, wsService2)).when(mock).getServices(ws); - when(mock.getServiceByName(eq(service1.getName()), eq(ServiceInfo.class))) - .thenReturn(service1); - when(mock.getServiceByName(eq(service1.getName()), eq(TestService1.class))) - .thenReturn(service1); - when(mock.getServiceByName(eq(service2.getName()), eq(ServiceInfo.class))) - .thenReturn(service1); - when(mock.getServiceByName(eq(service2.getName()), eq(TestService2.class))) - .thenReturn(service2); + when(mock.getServiceByName(service1.getName(), ServiceInfo.class)).thenReturn(service1); + when(mock.getServiceByName(service1.getName(), TestService1.class)).thenReturn(service1); + when(mock.getServiceByName(service2.getName(), ServiceInfo.class)).thenReturn(service1); + when(mock.getServiceByName(service2.getName(), TestService2.class)).thenReturn(service2); - when(mock.getServiceByName(eq(wsService1.getName()), same(ws), eq(ServiceInfo.class))) + when(mock.getServiceByName(wsService1.getName(), ws, ServiceInfo.class)) .thenReturn(wsService1); - when(mock.getServiceByName(eq(wsService1.getName()), same(ws), eq(TestService1.class))) + when(mock.getServiceByName(wsService1.getName(), ws, TestService1.class)) .thenReturn(wsService1); - when(mock.getServiceByName(eq(wsService2.getName()), same(ws), eq(ServiceInfo.class))) + when(mock.getServiceByName(wsService2.getName(), ws, ServiceInfo.class)) .thenReturn(wsService1); - when(mock.getServiceByName(eq(wsService2.getName()), same(ws), eq(TestService2.class))) + when(mock.getServiceByName(wsService2.getName(), ws, TestService2.class)) .thenReturn(wsService2); - when(mock.getSettings(same(ws))).thenReturn(settings); + when(mock.getSettings(ws)).thenReturn(settings); this.cache = cacheManager.getCache(CachingGeoServerFacade.CACHE_NAME); this.cache.clear(); } - public @Test void testGetGlobal() { + @Test + void testGetGlobal() { assertSameTimesN(global, caching::getGlobal, 3); verify(mock, times(1)).getGlobal(); } - public @Test void testSetGlobal() { + @Test + void testSetGlobal() { assertSameTimesN(global, caching::getGlobal, 3); assertNotNull(cache.get(CachingGeoServerFacade.GEOSERVERINFO_KEY)); @@ -137,7 +133,8 @@ public static interface TestService2 extends ServiceInfo {} assertNull(cache.get(CachingGeoServerFacade.GEOSERVERINFO_KEY)); } - public @Test void testSaveGeoServerInfo() { + @Test + void testSaveGeoServerInfo() { assertSameTimesN(global, caching::getGlobal, 3); assertNotNull(cache.get(CachingGeoServerFacade.GEOSERVERINFO_KEY)); @@ -145,37 +142,42 @@ public static interface TestService2 extends ServiceInfo {} assertNull(cache.get(CachingGeoServerFacade.GEOSERVERINFO_KEY)); } - public @Test void testGetSettings() { + @Test + void testGetSettings() { assertSameTimesN(settings, () -> caching.getSettings(ws), 3); - verify(mock, times(1)).getSettings(same(ws)); + verify(mock, times(1)).getSettings(ws); assertNotNull(cache.get(CachingGeoServerFacade.settingsKey(ws))); } - public @Test void testSaveSettingsInfo() { + @Test + void testSaveSettingsInfo() { assertSameTimesN(settings, () -> caching.getSettings(ws), 3); - verify(mock, times(1)).getSettings(same(ws)); + verify(mock, times(1)).getSettings(ws); assertNotNull(cache.get(CachingGeoServerFacade.settingsKey(ws))); caching.save(settings); assertNull(cache.get(CachingGeoServerFacade.settingsKey(ws))); } - public @Test void testRemoveSettingsInfo() { + @Test + void testRemoveSettingsInfo() { assertSameTimesN(settings, () -> caching.getSettings(ws), 3); - verify(mock, times(1)).getSettings(same(ws)); + verify(mock, times(1)).getSettings(ws); assertNotNull(cache.get(CachingGeoServerFacade.settingsKey(ws))); caching.remove(settings); assertNull(cache.get(CachingGeoServerFacade.settingsKey(ws))); } - public @Test void testGetLogging() { + @Test + void testGetLogging() { assertSameTimesN(logging, caching::getLogging, 3); verify(mock, times(1)).getLogging(); assertNotNull(cache.get(CachingGeoServerFacade.LOGGINGINFO_KEY)); } - public @Test void testSetLogging() { + @Test + void testSetLogging() { assertSameTimesN(logging, caching::getLogging, 3); verify(mock, times(1)).getLogging(); assertNotNull(cache.get(CachingGeoServerFacade.LOGGINGINFO_KEY)); @@ -183,7 +185,8 @@ public static interface TestService2 extends ServiceInfo {} assertNull(cache.get(CachingGeoServerFacade.LOGGINGINFO_KEY)); } - public @Test void testSaveLoggingInfo() { + @Test + void testSaveLoggingInfo() { assertSameTimesN(logging, caching::getLogging, 3); verify(mock, times(1)).getLogging(); assertNotNull(cache.get(CachingGeoServerFacade.LOGGINGINFO_KEY)); @@ -191,7 +194,8 @@ public static interface TestService2 extends ServiceInfo {} assertNull(cache.get(CachingGeoServerFacade.LOGGINGINFO_KEY)); } - public @Test void testRemoveServiceInfo() { + @Test + void testRemoveServiceInfo() { testEvictsServiceInfo(service1, () -> caching.remove(service1)); assertNotNull(wsService1.getWorkspace(), "preflight check failure"); @@ -199,7 +203,8 @@ public static interface TestService2 extends ServiceInfo {} testEvictsServiceInfo(wsService1, () -> caching.remove(wsService1)); } - public @Test void testSaveServiceInfo() { + @Test + void testSaveServiceInfo() { testEvictsServiceInfo(service1, () -> caching.save(service1)); assertNotNull(wsService1.getWorkspace(), "preflight check failure"); @@ -227,7 +232,8 @@ private void testEvictsServiceInfo(ServiceInfo service, Runnable task) { } /** {@link GeoServerFacade#getService(Class)} */ - public @Test void testGetServiceByType() { + @Test + void testGetServiceByType() { ServiceInfo service = service1; ServiceInfoKey idKey = ServiceInfoKey.byId(service.getId()); ServiceInfoKey nameKey = ServiceInfoKey.byName(service.getWorkspace(), service.getName()); @@ -238,7 +244,7 @@ private void testEvictsServiceInfo(ServiceInfo service, Runnable task) { assertNull(cache.get(typeKey)); assertSameTimesN(service, () -> caching.getService(TestService1.class), 3); - verify(mock, times(1)).getService(eq(TestService1.class)); + verify(mock, times(1)).getService(TestService1.class); assertNotNull(cache.get(idKey)); assertNotNull(cache.get(nameKey)); @@ -248,11 +254,12 @@ private void testEvictsServiceInfo(ServiceInfo service, Runnable task) { /** * {@link GeoServerFacade#getService(WorkspaceInfo, Class) */ - public @Test void testGetServiceByWorkspaceAndType() { + @Test + void testGetServiceByWorkspaceAndType() { TestService1 service = wsService1; WorkspaceInfo ws = service.getWorkspace(); assertNotNull(ws, "preflight check failure"); - when(mock.getService(same(ws), eq(TestService1.class))).thenReturn(service); + when(mock.getService(ws, TestService1.class)).thenReturn(service); ServiceInfoKey idKey = ServiceInfoKey.byId(service.getId()); ServiceInfoKey nameKey = ServiceInfoKey.byName(service.getWorkspace(), service.getName()); @@ -263,7 +270,7 @@ private void testEvictsServiceInfo(ServiceInfo service, Runnable task) { assertNull(cache.get(typeKey)); assertSameTimesN(service, () -> caching.getService(ws, TestService1.class), 3); - verify(mock, times(1)).getService(same(ws), eq(TestService1.class)); + verify(mock, times(1)).getService(ws, TestService1.class); assertNotNull(cache.get(idKey)); assertNotNull(cache.get(nameKey)); @@ -273,9 +280,10 @@ private void testEvictsServiceInfo(ServiceInfo service, Runnable task) { /** * {@link GeoServerFacade#getService(String, Class) */ - public @Test void testGetServiceByIdAndType() { + @Test + void testGetServiceByIdAndType() { TestService1 service = service1; - when(mock.getService(eq(service.getId()), eq(TestService1.class))).thenReturn(service); + when(mock.getService(service.getId(), TestService1.class)).thenReturn(service); ServiceInfoKey idKey = ServiceInfoKey.byId(service.getId()); ServiceInfoKey nameKey = ServiceInfoKey.byName(service.getWorkspace(), service.getName()); @@ -286,18 +294,19 @@ private void testEvictsServiceInfo(ServiceInfo service, Runnable task) { assertNull(cache.get(typeKey)); assertSameTimesN(service, () -> caching.getService(service.getId(), TestService1.class), 3); - verify(mock, times(1)).getService(eq(service.getId()), eq(TestService1.class)); + verify(mock, times(1)).getService(service.getId(), TestService1.class); assertNotNull(cache.get(idKey)); assertNotNull(cache.get(nameKey)); assertNotNull(cache.get(typeKey)); } - public @Test void testGetServiceByNameAndType() { + @Test + void testGetServiceByNameAndType() { TestService1 service = service1; String name = service.getName(); assertNotNull("preflight check failure", name); - when(mock.getServiceByName(eq(name), eq(TestService1.class))).thenReturn(service); + when(mock.getServiceByName(name, TestService1.class)).thenReturn(service); ServiceInfoKey idKey = ServiceInfoKey.byId(service.getId()); ServiceInfoKey nameKey = ServiceInfoKey.byName(service.getWorkspace(), service.getName()); @@ -308,20 +317,21 @@ private void testEvictsServiceInfo(ServiceInfo service, Runnable task) { assertNull(cache.get(typeKey)); assertSameTimesN(service, () -> caching.getServiceByName(name, TestService1.class), 3); - verify(mock, times(1)).getServiceByName(eq(name), eq(TestService1.class)); + verify(mock, times(1)).getServiceByName(name, TestService1.class); assertNotNull(cache.get(idKey)); assertNotNull(cache.get(nameKey)); assertNotNull(cache.get(typeKey)); } - public @Test void testGetServiceByNameAndWorkspaceAndType() { + @Test + void testGetServiceByNameAndWorkspaceAndType() { TestService1 service = wsService1; String name = service.getName(); WorkspaceInfo ws = service.getWorkspace(); assertNotNull(name, "preflight check failure"); assertNotNull(ws, "preflight check failure"); - when(mock.getServiceByName(eq(name), eq(ws), eq(TestService1.class))).thenReturn(service); + when(mock.getServiceByName(name, ws, TestService1.class)).thenReturn(service); ServiceInfoKey idKey = ServiceInfoKey.byId(service.getId()); ServiceInfoKey nameKey = ServiceInfoKey.byName(service.getWorkspace(), service.getName()); @@ -332,7 +342,7 @@ private void testEvictsServiceInfo(ServiceInfo service, Runnable task) { assertNull(cache.get(typeKey)); assertSameTimesN(service, () -> caching.getServiceByName(name, ws, TestService1.class), 3); - verify(mock, times(1)).getServiceByName(eq(name), eq(ws), eq(TestService1.class)); + verify(mock, times(1)).getServiceByName(name, ws, TestService1.class); assertNotNull(cache.get(idKey)); assertNotNull(cache.get(nameKey)); @@ -340,7 +350,8 @@ private void testEvictsServiceInfo(ServiceInfo service, Runnable task) { } /** {@link CachingGeoServerFacade#evict(Info)} manual eviction aid */ - public @Test void testEvict_GeoServerInfo() { + @Test + void testEvict_GeoServerInfo() { GeoServerInfo gsProxy = ResolvingProxy.create("someid", GeoServerInfo.class); assertFalse(caching.evict(gsProxy)); cache.put(CachingGeoServerFacade.GEOSERVERINFO_KEY, global); @@ -350,7 +361,8 @@ private void testEvictsServiceInfo(ServiceInfo service, Runnable task) { } /** {@link CachingGeoServerFacade#evict(Info)} manual eviction aid */ - public @Test void testEvict_LoggingInfo() { + @Test + void testEvict_LoggingInfo() { LoggingInfo loggingProxy = ResolvingProxy.create(settings.getId(), LoggingInfo.class); assertFalse(caching.evict(loggingProxy)); cache.put(CachingGeoServerFacade.LOGGINGINFO_KEY, logging); @@ -360,7 +372,8 @@ private void testEvictsServiceInfo(ServiceInfo service, Runnable task) { } /** {@link CachingGeoServerFacade#evict(Info)} manual eviction aid */ - public @Test void testEvict_SettingsInfo() { + @Test + void testEvict_SettingsInfo() { assertNotNull(settings.getWorkspace()); Object wsKey = CachingGeoServerFacade.settingsKey(settings.getWorkspace()); final String id = settings.getId(); @@ -382,7 +395,8 @@ private void testEvictsServiceInfo(ServiceInfo service, Runnable task) { } /** {@link CachingGeoServerFacade#evict(Info)} manual eviction aid */ - public @Test void testEvict_ServiceInfo() { + @Test + void testEvict_ServiceInfo() { TestService1 service = service1; ServiceInfoKey idKey = ServiceInfoKey.byId(service.getId()); ServiceInfoKey nameKey = ServiceInfoKey.byName(service.getWorkspace(), service.getName()); diff --git a/src/catalog/cache/src/test/java/org/geoserver/cloud/catalog/cache/GeoServerBackendCacheConfigurationTest.java b/src/catalog/cache/src/test/java/org/geoserver/cloud/catalog/cache/GeoServerBackendCacheConfigurationTest.java index f27543ef4..c8f35d52b 100644 --- a/src/catalog/cache/src/test/java/org/geoserver/cloud/catalog/cache/GeoServerBackendCacheConfigurationTest.java +++ b/src/catalog/cache/src/test/java/org/geoserver/cloud/catalog/cache/GeoServerBackendCacheConfigurationTest.java @@ -17,7 +17,7 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner; /** */ -public class GeoServerBackendCacheConfigurationTest { +class GeoServerBackendCacheConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() @@ -36,12 +36,14 @@ public class GeoServerBackendCacheConfigurationTest { UserConfigurations.of(GeoServerBackendCacheConfiguration.class)) .withConfiguration(AutoConfigurations.of(CacheAutoConfiguration.class)); - public @Test void testCachingCatalogFacade() { + @Test + void testCachingCatalogFacade() { contextRunner.run( context -> context.isTypeMatch("cachingCatalogFacade", CachingCatalogFacade.class)); } - public @Test void testCachingGeoServerFacade() { + @Test + void testCachingGeoServerFacade() { contextRunner.run( context -> context.isTypeMatch( diff --git a/src/catalog/cache/src/test/java/org/geoserver/cloud/event/remote/cache/RemoteEventCacheEvictorTest.java b/src/catalog/cache/src/test/java/org/geoserver/cloud/event/remote/cache/RemoteEventCacheEvictorTest.java index 4ddbae2e3..e63f883b6 100644 --- a/src/catalog/cache/src/test/java/org/geoserver/cloud/event/remote/cache/RemoteEventCacheEvictorTest.java +++ b/src/catalog/cache/src/test/java/org/geoserver/cloud/event/remote/cache/RemoteEventCacheEvictorTest.java @@ -84,7 +84,7 @@ "logging.level.org.springframework.cache=DEBUG", "logging.level.org.geoserver.cloud.events=DEBUG" }) -public class RemoteEventCacheEvictorTest { +class RemoteEventCacheEvictorTest { /** Spring-cache for CatalogInfo objects, named after {@link CachingCatalogFacade#CACHE_NAME} */ private Cache catalogCache; @@ -125,7 +125,8 @@ public class RemoteEventCacheEvictorTest { // data.after(); } - public @Test void testRemoteDefaultWorkspaceEvent() { + @Test + void testRemoteDefaultWorkspaceEvent() { assertNull(catalogCache.get(DEFAULT_WORKSPACE_CACHE_KEY)); catalog.getDefaultWorkspace(); @@ -141,13 +142,14 @@ private Patch patch(String propertyName, Object value) { return patch; } - private > E publishRemote(E event) { + private > E publishRemote(E event) { event.setRemote(true); publisher.publishEvent(event); return event; } - public @Test void testRemoteDefaultNamespaceEvent() { + @Test + void testRemoteDefaultNamespaceEvent() { assertNull(catalogCache.get(DEFAULT_NAMESPACE_CACHE_KEY)); catalog.getDefaultNamespace(); @@ -158,7 +160,8 @@ private Patch patch(String propertyName, Object value) { assertNull(catalogCache.get(DEFAULT_NAMESPACE_CACHE_KEY)); } - public @Test void testRemoteDefaultDataStoreEvent() { + @Test + void testRemoteDefaultDataStoreEvent() { final Object key = CachingCatalogFacade.generateDefaultDataStoreKey(data.workspaceA); assertNull(catalogCache.get(key)); @@ -179,7 +182,8 @@ private Patch patch(String propertyName, Object value) { assertNotNull(catalogCache.get(key)); } - public @Test void testCatalogInfoEvictingEvents() { + @Test + void testCatalogInfoEvictingEvents() { // layergroups are not cached // testModifyThenRemoveCatalogInfo(data.layerGroup1, catalog::getLayerGroup); testModifyThenRemoveCatalogInfo(data.layerFeatureTypeA, catalog::getLayer); @@ -235,7 +239,8 @@ private void testModifyThenRemoveCatalogInfo( assertNull(catalogCache.get(key)); } - public @Test void testRemoteServiceInfoModifyEvent_global_service() { + @Test + void testRemoteServiceInfoModifyEvent_global_service() { WMSInfoImpl globalService = new WMSInfoImpl(); globalService.setId("wms-global"); globalService.setName("WMS"); @@ -243,7 +248,8 @@ private void testModifyThenRemoveCatalogInfo( testRemoteServiceInfoModifyEvent(globalService); } - public @Test void testRemoteServiceInfoModifyEvent_workspace_service() { + @Test + void testRemoteServiceInfoModifyEvent_workspace_service() { WorkspaceInfoImpl workspace = new WorkspaceInfoImpl(); workspace.setId("fake-ws"); @@ -280,7 +286,8 @@ private void testRemoteServiceInfoModifyEvent(ServiceInfo service) { assertNull(configCache.get(typeKey), "service by type not evicted"); } - public @Test void testRemoteServiceInfoRemoveEvent_global_service() { + @Test + void testRemoteServiceInfoRemoveEvent_global_service() { WMSInfoImpl globalService = new WMSInfoImpl(); globalService.setId("wms-global"); globalService.setName("WMS"); @@ -288,7 +295,8 @@ private void testRemoteServiceInfoModifyEvent(ServiceInfo service) { testRemoteServiceInfoRemoveEvent(globalService); } - public @Test void testRemoteServiceInfoRemoveEvent_workspace_service() { + @Test + void testRemoteServiceInfoRemoveEvent_workspace_service() { WorkspaceInfoImpl workspace = new WorkspaceInfoImpl(); workspace.setId("fake-ws"); @@ -322,7 +330,8 @@ private void testRemoteServiceInfoRemoveEvent(ServiceInfo service) { assertNull(configCache.get(typeKey), "service by type not evicted"); } - public @Test void testRemoteSettingsInfoModifyEvent() { + @Test + void testRemoteSettingsInfoModifyEvent() { WorkspaceInfoImpl ws = new WorkspaceInfoImpl(); ws.setId("fakews"); SettingsInfoImpl settings = new SettingsInfoImpl(); @@ -355,7 +364,8 @@ private void testRemoteServiceInfoRemoveEvent(ServiceInfo service) { "expected workspace settings entry to be evicted"); } - public @Test void testRemoteSettingsInfoRemoveEvent() { + @Test + void testRemoteSettingsInfoRemoveEvent() { WorkspaceInfoImpl ws = new WorkspaceInfoImpl(); ws.setId("fakews"); SettingsInfoImpl settings = new SettingsInfoImpl(); @@ -385,7 +395,8 @@ private void testRemoteServiceInfoRemoveEvent(ServiceInfo service) { "expected workspace settings entry to be evicted"); } - public @Test void testRemoteLoggingInfoSetEvent() { + @Test + void testRemoteLoggingInfoSetEvent() { LoggingInfo info = geoServer.getLogging(); assertNotNull(info); final String key = CachingGeoServerFacade.LOGGINGINFO_KEY; @@ -402,7 +413,8 @@ private void testRemoteServiceInfoRemoveEvent(ServiceInfo service) { assertNull(configCache.get(key), "logging not evicted"); } - public @Test void testRemoteLoggingInfoModifyEvent() { + @Test + void testRemoteLoggingInfoModifyEvent() { LoggingInfo info = geoServer.getLogging(); assertNotNull(info); final String key = CachingGeoServerFacade.LOGGINGINFO_KEY; @@ -417,7 +429,8 @@ private void testRemoteServiceInfoRemoveEvent(ServiceInfo service) { assertNull(configCache.get(key), "logging not evicted"); } - public @Test void testRemoteGeoServerInfoSetEvent() { + @Test + void testRemoteGeoServerInfoSetEvent() { GeoServerInfo info = geoServer.getGlobal(); assertNotNull(info); final String key = CachingGeoServerFacade.GEOSERVERINFO_KEY; @@ -434,7 +447,8 @@ private void testRemoteServiceInfoRemoveEvent(ServiceInfo service) { assertNull(configCache.get(key), "global not evicted"); } - public @Test void testRemoteGeoServerInfoModifyEvent() { + @Test + void testRemoteGeoServerInfoModifyEvent() { GeoServerInfo info = geoServer.getGlobal(); assertNotNull(info); final String key = CachingGeoServerFacade.GEOSERVERINFO_KEY; @@ -451,7 +465,8 @@ private void testRemoteServiceInfoRemoveEvent(ServiceInfo service) { assertNull(configCache.get(key), "global not evicted"); } - public @Test void testUpdateSequenceModifyEvent_evicts_but_applies_update_sequence_in_place() { + @Test + void testUpdateSequenceModifyEvent_evicts_but_applies_update_sequence_in_place() { GeoServerInfo local = geoServer.getGlobal(); assertNotNull(local); final String key = CachingGeoServerFacade.GEOSERVERINFO_KEY; @@ -467,7 +482,7 @@ private void testRemoteServiceInfoRemoveEvent(ServiceInfo service) { Mockito.clearInvocations(this.evictor); - UpdateSequenceEvent event = + UpdateSequenceEvent event = publishRemote(GeoServerInfoModified.createLocal(updateSequence, remote, patch)); Mockito.verify(evictor, times(1)).onUpdateSequenceEvent(same(event)); diff --git a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/impl/CatalogClientCatalogFacade.java b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/impl/CatalogClientCatalogFacade.java index 0f579ee24..518401928 100644 --- a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/impl/CatalogClientCatalogFacade.java +++ b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/impl/CatalogClientCatalogFacade.java @@ -67,7 +67,8 @@ public CatalogClientCatalogFacade(@NonNull RepositoryCatalogFacade rawFacade) { } // set up resolving chain - public @Override void setCatalog(Catalog catalog) { + @Override + public void setCatalog(Catalog catalog) { super.setCatalog(catalog); final ResolvingProxyResolver proxyResolver = diff --git a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/impl/CatalogClientResource.java b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/impl/CatalogClientResource.java index 0099d8019..d9a01d624 100644 --- a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/impl/CatalogClientResource.java +++ b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/impl/CatalogClientResource.java @@ -26,7 +26,6 @@ import java.nio.file.Paths; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; /** */ @AllArgsConstructor @@ -35,23 +34,28 @@ class CatalogClientResource implements Resource { private @NonNull ReactiveResourceStoreClient.ResourceDescriptor descriptor; private @NonNull CatalogClientResourceStore store; - public @Override String path() { + @Override + public String path() { return descriptor.getPath(); } - public @Override void addListener(ResourceListener listener) { + @Override + public void addListener(ResourceListener listener) { store.getResourceNotificationDispatcher().addListener(path(), listener); } - public @Override void removeListener(ResourceListener listener) { + @Override + public void removeListener(ResourceListener listener) { store.getResourceNotificationDispatcher().removeListener(path(), listener); } - public @Override String name() { + @Override + public String name() { return Paths.get(path()).getFileName().toString(); } - public @Override Lock lock() { + @Override + public Lock lock() { return store.getLockProvider().acquire(path()); } @@ -64,16 +68,19 @@ private byte[] toByteArray(org.springframework.core.io.Resource buff) { } } - public @Override byte[] getContents() throws IOException { + @Override + public byte[] getContents() throws IOException { org.springframework.core.io.Resource contents = store.getFileContent(path()); return toByteArray(contents); } - public @Override void setContents(byte[] contents) throws IOException { + @Override + public void setContents(byte[] contents) throws IOException { store.put(path(), ByteBuffer.wrap(contents)); } - public @Override InputStream in() { + @Override + public InputStream in() { try { return new ByteArrayInputStream(getContents()); } catch (IOException e) { @@ -81,28 +88,34 @@ private byte[] toByteArray(org.springframework.core.io.Resource buff) { } } - public @Override OutputStream out() { + @Override + public OutputStream out() { return new ByteArrayOutputStream() { - public @Override void close() throws IOException { + @Override + public void close() throws IOException { ByteBuffer buff = ByteBuffer.wrap(super.buf, 0, super.count); store.put(path(), buff); } }; } - public @Override File file() { + @Override + public File file() { return store.file(this); } - public @Override File dir() { + @Override + public File dir() { return store.dir(this); } - public @Override long lastmodified() { + @Override + public long lastmodified() { return descriptor.getLastModified(); } - public @Override Resource parent() { + @Override + public Resource parent() { Path parentPath = Paths.get(path()).getParent(); if (null == parentPath) { parentPath = Paths.get(org.geoserver.platform.resource.Paths.BASE); // root @@ -110,7 +123,8 @@ private byte[] toByteArray(org.springframework.core.io.Resource buff) { return store.get(parentPath.toString()); } - public @Override Resource get(final String childName) { + @Override + public Resource get(final String childName) { Objects.requireNonNull(childName, "Resource path required"); if ("".equals(childName)) { return this; @@ -120,15 +134,18 @@ private byte[] toByteArray(org.springframework.core.io.Resource buff) { return store.get(child.toString()); } - public @Override List list() { - return store.list(path()).collect(Collectors.toList()); + @Override + public List list() { + return store.list(path()).map(Resource.class::cast).toList(); } - public @Override Type getType() { + @Override + public Type getType() { return descriptor.getType(); } - public @Override boolean delete() { + @Override + public boolean delete() { boolean removed = store.remove(path()); if (removed) { this.descriptor.setType(Type.UNDEFINED); @@ -136,7 +153,8 @@ private byte[] toByteArray(org.springframework.core.io.Resource buff) { return removed; } - public @Override boolean renameTo(Resource dest) { + @Override + public boolean renameTo(Resource dest) { boolean moved = store.move(path(), dest.path()); if (moved) { this.descriptor = store.get(dest.path()).getDescriptor(); @@ -150,7 +168,8 @@ ResourceDescriptor getDescriptor() { return this.descriptor; } - public @Override String toString() { + @Override + public String toString() { return String.format( "%s[path: %s, type: %s, lastModified: %s, lockProvider: %s]", getClass().getSimpleName(), diff --git a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/impl/CatalogClientResourceStore.java b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/impl/CatalogClientResourceStore.java index c7a60c392..caefc98fd 100644 --- a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/impl/CatalogClientResourceStore.java +++ b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/impl/CatalogClientResourceStore.java @@ -91,8 +91,8 @@ public void setLocalCacheDirectory(File localCache) { private FileSystemResourceStore createLocalStore(@NonNull File localCache) { FileSystemResourceStore local = new FileSystemResourceStore(localCache) { - public @Override ResourceNotificationDispatcher - getResourceNotificationDispatcher() { + @Override + public ResourceNotificationDispatcher getResourceNotificationDispatcher() { return NullResourceNotificationDispatcher.INSTANCE; } }; @@ -102,7 +102,8 @@ private FileSystemResourceStore createLocalStore(@NonNull File localCache) { private Map dumbCache = new ConcurrentHashMap<>(); - public @Override CatalogClientResource get(String path) { + @Override + public CatalogClientResource get(String path) { try { // ResourceDescriptor descriptor = remoteStore.describe(path); ResourceDescriptor descriptor = dumbCache.computeIfAbsent(path, remoteStore::describe); @@ -113,7 +114,8 @@ private FileSystemResourceStore createLocalStore(@NonNull File localCache) { } } - public @Override boolean remove(String path) { + @Override + public boolean remove(String path) { boolean deleted = remoteStore.delete(path); if (deleted) { localStore.get(path).delete(); @@ -121,13 +123,15 @@ private FileSystemResourceStore createLocalStore(@NonNull File localCache) { return deleted; } - public @Override boolean move(String path, String target) { + @Override + public boolean move(String path, String target) { ResourceDescriptor moved = remoteStore.move(path, target).orElse(null); localStore.move(path, target); return moved != null && target.equals(moved.getPath()); } - public @Override ResourceNotificationDispatcher getResourceNotificationDispatcher() { + @Override + public ResourceNotificationDispatcher getResourceNotificationDispatcher() { return resourceNotificationDispatcher; } @@ -137,13 +141,16 @@ private static class NullResourceNotificationDispatcher static final NullResourceNotificationDispatcher INSTANCE = new NullResourceNotificationDispatcher(); - public @Override void addListener(String resource, ResourceListener listener) {} + @Override + public void addListener(String resource, ResourceListener listener) {} - public @Override boolean removeListener(String resource, ResourceListener listener) { + @Override + public boolean removeListener(String resource, ResourceListener listener) { return true; } - public @Override void changed(ResourceNotification notification) {} + @Override + public void changed(ResourceNotification notification) {} } org.springframework.core.io.Resource getFileContent(String path) throws IOException { diff --git a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/impl/InnerResolvingProxy.java b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/impl/InnerResolvingProxy.java index 9066a13bb..77625d4fb 100644 --- a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/impl/InnerResolvingProxy.java +++ b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/impl/InnerResolvingProxy.java @@ -80,8 +80,8 @@ public Patch resolve(Patch patch) { } private Object resolvePatchPropertyValue(Object orig) { - if (orig instanceof Info) { - return resolve((Info) orig); + if (orig instanceof Info info) { + return resolve(info); } if (orig instanceof List) { @SuppressWarnings("unchecked") @@ -245,8 +245,8 @@ protected void resolveInternal(LayerInfo layer) { } protected T resolveInternal(T published) { - if (published instanceof LayerInfo) resolve((LayerInfo) published); - else if (published instanceof LayerGroupInfo) resolve((LayerGroupInfo) published); + if (published instanceof LayerInfo li) resolve(li); + else if (published instanceof LayerGroupInfo lg) resolve(lg); return published; } diff --git a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/reactivefeign/ReactiveConfigClient.java b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/reactivefeign/ReactiveConfigClient.java index 61f81fee9..756a86ebd 100644 --- a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/reactivefeign/ReactiveConfigClient.java +++ b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/reactivefeign/ReactiveConfigClient.java @@ -96,7 +96,7 @@ Mono updateService( /** Global (no-workspace) services. */ @GetMapping("/services") - Flux getGlobalServices(); + Flux getGlobalServices(); /** GeoServer global service filtered by class. */ @GetMapping("/services/type/{type}") diff --git a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientConfigRepository.java b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientConfigRepository.java index 56177a1f9..c738db483 100644 --- a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientConfigRepository.java +++ b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientConfigRepository.java @@ -50,47 +50,57 @@ protected Optional blockAndReturn(Mono call) { return call.blockOptional(); } - public @Override Optional getGlobal() { + @Override + public Optional getGlobal() { return blockAndReturn(client.getGlobal()); } - public @Override void setGlobal(GeoServerInfo global) { + @Override + public void setGlobal(GeoServerInfo global) { checkNotAProxy(global); blockAndReturn(client.setGlobal(global)); } - public @Override Optional getSettingsById(String id) { + @Override + public Optional getSettingsById(String id) { return blockAndReturn(client.getSettingsById(id)); } - public @Override Optional getSettingsByWorkspace(WorkspaceInfo workspace) { + @Override + public Optional getSettingsByWorkspace(WorkspaceInfo workspace) { return blockAndReturn(client.getSettingsByWorkspace(workspace.getId())); } - public @Override void add(SettingsInfo settings) { + @Override + public void add(SettingsInfo settings) { checkNotAProxy(settings); blockAndReturn(client.createSettings(settings.getWorkspace().getId(), settings)); } - public @Override SettingsInfo update(SettingsInfo settings, Patch patch) { + @Override + public SettingsInfo update(SettingsInfo settings, Patch patch) { return blockAndReturn(client.updateSettings(settings.getWorkspace().getId(), patch)) .orElseThrow(() -> new IllegalStateException()); } - public @Override void remove(SettingsInfo settings) { + @Override + public void remove(SettingsInfo settings) { blockAndReturn(client.deleteSettings(settings.getWorkspace().getId())); } - public @Override Optional getLogging() { + @Override + public Optional getLogging() { return blockAndReturn(client.getLogging()); } - public @Override void setLogging(LoggingInfo logging) { + @Override + public void setLogging(LoggingInfo logging) { checkNotAProxy(logging); blockAndReturn(client.setLogging(logging)); } - public @Override void add(ServiceInfo service) { + @Override + public void add(ServiceInfo service) { checkNotAProxy(service); WorkspaceInfo workspace = service.getWorkspace(); if (workspace == null) { @@ -100,48 +110,56 @@ protected Optional blockAndReturn(Mono call) { } } - public @Override void remove(ServiceInfo service) { + @Override + public void remove(ServiceInfo service) { client.deleteService(service.getId()); } @SuppressWarnings("unchecked") - public @Override S update(S service, Patch patch) { + @Override + public S update(S service, Patch patch) { Optional updated = blockAndReturn(client.updateService(service.getId(), patch)); return updated.map(u -> (S) u).orElseThrow(() -> new IllegalStateException()); } - public @Override Stream getGlobalServices() { + @Override + public Stream getGlobalServices() { return client.getGlobalServices().toStream(); } - public @Override Stream getServicesByWorkspace(WorkspaceInfo workspace) { + @Override + public Stream getServicesByWorkspace(WorkspaceInfo workspace) { return client.getServicesByWorkspace(workspace.getId()).toStream(); } - public @Override Optional getGlobalService(Class clazz) { + @Override + public Optional getGlobalService(Class clazz) { String typeName = interfaceName(clazz); return blockAndReturn(client.getGlobalServiceByType(typeName).map(clazz::cast)); } - public @Override Optional getServiceByWorkspace( + @Override + public Optional getServiceByWorkspace( WorkspaceInfo workspace, Class clazz) { String typeName = interfaceName(clazz); return blockAndReturn( client.getServiceByWorkspaceAndType(workspace.getId(), typeName).map(clazz::cast)); } - public @Override Optional getServiceById(String id, Class clazz) { + @Override + public Optional getServiceById(String id, Class clazz) { return blockAndReturn(client.getServiceById(id).filter(clazz::isInstance).map(clazz::cast)); } - public @Override Optional getServiceByName( - String name, Class clazz) { + @Override + public Optional getServiceByName(String name, Class clazz) { return blockAndReturn( client.getGlobalServiceByName(name).filter(clazz::isInstance).map(clazz::cast)); } - public @Override Optional getServiceByNameAndWorkspace( + @Override + public Optional getServiceByNameAndWorkspace( String name, WorkspaceInfo workspace, Class clazz) { return blockAndReturn( client.getServiceByWorkspaceAndName(workspace.getId(), name) @@ -150,7 +168,8 @@ protected Optional blockAndReturn(Mono call) { } /** no-op */ - public @Override void dispose() { + @Override + public void dispose() { // no-op } diff --git a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientLayerGroupRepository.java b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientLayerGroupRepository.java index 0dc5a06f7..93a417320 100644 --- a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientLayerGroupRepository.java +++ b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientLayerGroupRepository.java @@ -20,19 +20,23 @@ public class CatalogClientLayerGroupRepository extends CatalogClientRepository contentType = LayerGroupInfo.class; - public @Override Stream findAllByWorkspaceIsNull() { + @Override + public Stream findAllByWorkspaceIsNull() { return toStream(client().findLayerGroupsByNullWoskspace()); } - public @Override Stream findAllByWorkspace(@NonNull WorkspaceInfo workspace) { + @Override + public Stream findAllByWorkspace(@NonNull WorkspaceInfo workspace) { return toStream(client().findLayerGroupsByWoskspaceId(workspace.getId())); } - public @Override Optional findByNameAndWorkspaceIsNull(@NonNull String name) { + @Override + public Optional findByNameAndWorkspaceIsNull(@NonNull String name) { return blockAndReturn(client().findLayerGroupByNameAndNullWorkspace(name)); } - public @Override Optional findByNameAndWorkspace( + @Override + public Optional findByNameAndWorkspace( @NonNull String name, @NonNull WorkspaceInfo workspace) { Objects.requireNonNull(workspace.getId()); return blockAndReturn(client().findLayerGroupByWorkspaceIdAndName(workspace.getId(), name)); diff --git a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientLayerRepository.java b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientLayerRepository.java index dfdff09c6..08a34427f 100644 --- a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientLayerRepository.java +++ b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientLayerRepository.java @@ -20,15 +20,18 @@ public class CatalogClientLayerRepository extends CatalogClientRepository contentType = LayerInfo.class; - public @Override Stream findAllByDefaultStyleOrStyles(StyleInfo style) { + @Override + public Stream findAllByDefaultStyleOrStyles(StyleInfo style) { return toStream(client().findLayersWithStyle(style.getId())); } - public @Override Stream findAllByResource(ResourceInfo resource) { + @Override + public Stream findAllByResource(ResourceInfo resource) { return toStream(client().findLayersByResourceId(resource.getId())); } - public @Override Optional findOneByName(@NonNull String name) { + @Override + public Optional findOneByName(@NonNull String name) { return findFirstByName(name, LayerInfo.class); } } diff --git a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientNamespaceRepository.java b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientNamespaceRepository.java index 69bb5b6a6..bb88bfa3a 100644 --- a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientNamespaceRepository.java +++ b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientNamespaceRepository.java @@ -20,12 +20,14 @@ public class CatalogClientNamespaceRepository extends CatalogClientRepository contentType = NamespaceInfo.class; - public @Override void setDefaultNamespace(@NonNull NamespaceInfo namespace) { + @Override + public void setDefaultNamespace(@NonNull NamespaceInfo namespace) { Objects.requireNonNull(namespace.getId(), "provided null namespace id"); blockAndReturn(client().setDefaultNamespace(namespace.getId())); } - public @Override Optional findFirstByName( + @Override + public Optional findFirstByName( @NonNull String name, @NonNull Class infoType) { // geoserver has this tendency to loose method contracts... if (name.indexOf(':') > -1) { @@ -34,19 +36,23 @@ public class CatalogClientNamespaceRepository extends CatalogClientRepository getDefaultNamespace() { + @Override + public @Nullable Optional getDefaultNamespace() { return blockAndReturn(client().getDefaultNamespace()); } - public @Override @Nullable Optional findOneByURI(@NonNull String uri) { + @Override + public @Nullable Optional findOneByURI(@NonNull String uri) { return blockAndReturn(client().findOneNamespaceByURI(uri)); } - public @Override Stream findAllByURI(@NonNull String uri) { + @Override + public Stream findAllByURI(@NonNull String uri) { return toStream(client().findAllNamespacesByURI(uri)); } } diff --git a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientRepository.java b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientRepository.java index 9319f7eb2..642baf293 100644 --- a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientRepository.java +++ b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientRepository.java @@ -37,7 +37,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.function.Supplier; -import java.util.stream.Collectors; import java.util.stream.Stream; @Slf4j @@ -128,7 +127,8 @@ protected Optional blockAndReturn(Mono call) { private final ConcurrentMap positiveCanSortByCache = new ConcurrentHashMap<>(); - public @Override boolean canSortBy(@NonNull String propertyName) { + @Override + public boolean canSortBy(@NonNull String propertyName) { Boolean canSort = positiveCanSortByCache.computeIfAbsent(propertyName, this::callCanSort); return canSort == null ? false : canSort.booleanValue(); } @@ -139,33 +139,39 @@ protected Optional blockAndReturn(Mono call) { return canSort.booleanValue() ? Boolean.TRUE : null; } - public @Override void add(@NonNull CI value) { + @Override + public void add(@NonNull CI value) { blockAndReturn(client.create(endpoint(), value)); } - public @Override void remove(@NonNull CI value) { + @Override + public void remove(@NonNull CI value) { blockAndReturn(client.deleteById(endpoint(), value.getId())); } - public @Override T update(@NonNull T value, @NonNull Patch patch) { + @Override + public T update(@NonNull T value, @NonNull Patch patch) { Mono updated = client.update(endpoint(), value.getId(), patch); return blockAndReturn(updated).get(); } - public @Override Optional findFirstByName( + @Override + public Optional findFirstByName( @NonNull String name, @NonNull Class infoType) { ClassMappings typeArg = typeEnum(infoType); Mono found = client.findFirstByName(endpoint(), name, typeArg); return blockAndReturn(found); } - public @Override Stream findAll() { + @Override + public Stream findAll() { ClassMappings typeArg = typeEnum(getContentType()); Flux flux = client.findAll(endpoint(), typeArg); return toStream(flux); } - public @Override Stream findAll(Query query) { + @Override + public Stream findAll(Query query) { final Filter rawFilter = query.getFilter(); if (Filter.EXCLUDE.equals(rawFilter)) { return Stream.empty(); // don't even bother @@ -193,7 +199,8 @@ protected Stream query(Query query, Filter unsupportedFilte return stream; } - public @Override long count(@NonNull Class of, @NonNull Filter rawFilter) { + @Override + public long count(@NonNull Class of, @NonNull Filter rawFilter) { if (Filter.EXCLUDE.equals(rawFilter)) { return 0L; } @@ -219,7 +226,7 @@ private List getServerSupportedFunctions() { try { ReactiveCatalogClient client = client(); Flux functionNames = client.getSupportedFilterFunctionNames(); - List list = functionNames.toStream().collect(Collectors.toList()); + List list = functionNames.toStream().toList(); return list; } catch (Exception e) { log.warn( @@ -229,19 +236,21 @@ private List getServerSupportedFunctions() { } } - public @Override Optional findById( - @NonNull String id, @NonNull Class clazz) { + @Override + public Optional findById(@NonNull String id, @NonNull Class clazz) { ClassMappings typeArg = typeEnum(clazz); Optional ret = blockAndReturn(client.findById(endpoint(), id, typeArg)); return ret; } - public @Override void dispose() { + @Override + public void dispose() { // no-op...? } - public @Override void syncTo(@NonNull CatalogInfoRepository target) { + @Override + public void syncTo(@NonNull CatalogInfoRepository target) { findAll().forEach(target::add); } diff --git a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientResourceRepository.java b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientResourceRepository.java index b68347ee1..56c34d702 100644 --- a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientResourceRepository.java +++ b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientResourceRepository.java @@ -29,11 +29,13 @@ public class CatalogClientResourceRepository extends CatalogClientRepository Stream findAllByType(@Nullable Class clazz) { + @Override + public Stream findAllByType(@Nullable Class clazz) { return toStream(client().findAll(endpoint(), typeEnum(clazz)).map(clazz::cast)); } - public @Override Stream findAllByNamespace( + @Override + public Stream findAllByNamespace( @NonNull NamespaceInfo ns, @Nullable Class clazz) { // REVISIT: missed custom method on ReactiveCatalogClient @@ -42,7 +44,8 @@ public class CatalogClientResourceRepository extends CatalogClientRepository Optional findByStoreAndName( + @Override + public @Nullable Optional findByStoreAndName( @NonNull StoreInfo store, @NonNull String name, @Nullable Class clazz) { // REVISIT: missed custom method on ReactiveCatalogClient Filter filter = @@ -56,8 +59,8 @@ public class CatalogClientResourceRepository extends CatalogClientRepository Stream findAllByStore( - StoreInfo store, Class clazz) { + @Override + public Stream findAllByStore(StoreInfo store, Class clazz) { // REVISIT: missed custom method on ReactiveCatalogClient Filter filter = ff.equals(ff.property("store.id"), ff.literal(store.getId())); @@ -65,7 +68,8 @@ public class CatalogClientResourceRepository extends CatalogClientRepository Optional findByNameAndNamespace( + @Override + public Optional findByNameAndNamespace( @NonNull String name, @NonNull NamespaceInfo namespace, @NonNull Class clazz) { String namespaceId = namespace.getId(); diff --git a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientStoreRepository.java b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientStoreRepository.java index a0909e8a6..7d01c0de2 100644 --- a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientStoreRepository.java +++ b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientStoreRepository.java @@ -24,7 +24,8 @@ public class CatalogClientStoreRepository extends CatalogClientRepository contentType = StoreInfo.class; - public @Override void setDefaultDataStore( + @Override + public void setDefaultDataStore( @NonNull WorkspaceInfo workspace, @NonNull DataStoreInfo dataStore) { String workspaceId = workspace.getId(); @@ -32,21 +33,25 @@ public class CatalogClientStoreRepository extends CatalogClientRepository getDefaultDataStore(@NonNull WorkspaceInfo workspace) { + @Override + public Optional getDefaultDataStore(@NonNull WorkspaceInfo workspace) { String workspaceId = workspace.getId(); return blockAndReturn(client().findDefaultDataStoreByWorkspaceId(workspaceId)); } - public @Override Stream getDefaultDataStores() { + @Override + public Stream getDefaultDataStores() { return toStream(client().getDefaultDataStores()); } - public @Override Stream findAllByWorkspace( + @Override + public Stream findAllByWorkspace( @NonNull WorkspaceInfo workspace, @Nullable Class clazz) { String workspaceId = workspace.getId(); @@ -56,12 +61,14 @@ public class CatalogClientStoreRepository extends CatalogClientRepository Stream findAllByType(@NonNull Class clazz) { + @Override + public Stream findAllByType(@NonNull Class clazz) { return toStream(client().findAll(endpoint(), typeEnum(clazz)).map(clazz::cast)); } - public @Override Optional findByNameAndWorkspace( + @Override + public Optional findByNameAndWorkspace( @NonNull String name, @NonNull WorkspaceInfo workspace, @NonNull Class clazz) { String workspaceId = workspace.getId(); diff --git a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientStyleRepository.java b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientStyleRepository.java index 5586120b6..c858c316c 100644 --- a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientStyleRepository.java +++ b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientStyleRepository.java @@ -19,19 +19,23 @@ public class CatalogClientStyleRepository extends CatalogClientRepository contentType = StyleInfo.class; - public @Override Stream findAllByNullWorkspace() { + @Override + public Stream findAllByNullWorkspace() { return toStream(client().findStylesByNullWorkspace()); } - public @Override Stream findAllByWorkspace(@NonNull WorkspaceInfo ws) { + @Override + public Stream findAllByWorkspace(@NonNull WorkspaceInfo ws) { return toStream(client().findStylesByWorkspaceId(ws.getId())); } - public @Override Optional findByNameAndWordkspaceNull(@NonNull String name) { + @Override + public Optional findByNameAndWordkspaceNull(@NonNull String name) { return blockAndReturn(client().findStyleByNameAndNullWorkspace(name)); } - public @Override Optional findByNameAndWorkspace( + @Override + public Optional findByNameAndWorkspace( @NonNull String name, @NonNull WorkspaceInfo workspace) { String workspaceId = workspace.getId(); diff --git a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientWorkspaceRepository.java b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientWorkspaceRepository.java index fb09f6f2c..88c2641e5 100644 --- a/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientWorkspaceRepository.java +++ b/src/catalog/catalog-server/client/src/main/java/org/geoserver/cloud/catalog/client/repository/CatalogClientWorkspaceRepository.java @@ -19,16 +19,19 @@ public class CatalogClientWorkspaceRepository extends CatalogClientRepository contentType = WorkspaceInfo.class; - public @Override void setDefaultWorkspace(@NonNull WorkspaceInfo workspace) { + @Override + public void setDefaultWorkspace(@NonNull WorkspaceInfo workspace) { Objects.requireNonNull(workspace.getId(), "workspace id can't be null"); blockAndReturn(client().setDefaultWorkspace(workspace.getId())); } - public @Override void unsetDefaultWorkspace() { + @Override + public void unsetDefaultWorkspace() { block(client().unsetDefaultWorkspace()); } - public @Override @Nullable Optional getDefaultWorkspace() { + @Override + public @Nullable Optional getDefaultWorkspace() { return blockAndReturn(client().getDefaultWorkspace()); } } diff --git a/src/catalog/catalog-server/client/src/test/java/org/geoserver/cloud/catalog/client/impl/CatalogClientConfigurationTest.java b/src/catalog/catalog-server/client/src/test/java/org/geoserver/cloud/catalog/client/impl/CatalogClientConfigurationTest.java index 461202ebc..9f3722fec 100644 --- a/src/catalog/catalog-server/client/src/test/java/org/geoserver/cloud/catalog/client/impl/CatalogClientConfigurationTest.java +++ b/src/catalog/catalog-server/client/src/test/java/org/geoserver/cloud/catalog/client/impl/CatalogClientConfigurationTest.java @@ -19,7 +19,7 @@ @SpringBootTest(classes = CatalogClientConfiguration.class) @EnableAutoConfiguration @ActiveProfiles("test") -public class CatalogClientConfigurationTest { +class CatalogClientConfigurationTest { private @Autowired CatalogClientCatalogFacade rawCatalogServiceFacade; @@ -28,7 +28,8 @@ public class CatalogClientConfigurationTest { private @Autowired GeoToolsFilterModule geotoolsFilterModule; private @Autowired GeoToolsGeoJsonModule geotoolsGeoJSONModule; - public @Test void smokeTest() { + @Test + void smokeTest() { assertNotNull(rawCatalogServiceFacade); assertNotNull(catalogJacksonModule); assertNotNull(configJacksonModule); diff --git a/src/catalog/catalog-server/client/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/ReactiveCatalogApiClientConfigurationTest.java b/src/catalog/catalog-server/client/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/ReactiveCatalogApiClientConfigurationTest.java index 90d0dd2f8..9ca0b0b81 100644 --- a/src/catalog/catalog-server/client/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/ReactiveCatalogApiClientConfigurationTest.java +++ b/src/catalog/catalog-server/client/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/ReactiveCatalogApiClientConfigurationTest.java @@ -16,7 +16,7 @@ import reactivefeign.spring.config.ReactiveFeignAutoConfiguration; -public class ReactiveCatalogApiClientConfigurationTest { +class ReactiveCatalogApiClientConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() // @@ -33,7 +33,8 @@ public class ReactiveCatalogApiClientConfigurationTest { ReactiveCatalogApiClientConfiguration.class // )); - public @Test void testReactiveCatalogClientIsLoaded() { + @Test + void testReactiveCatalogClientIsLoaded() { this.contextRunner.run( context -> { assertThat(context).hasSingleBean(ReactiveCatalogClient.class); @@ -42,7 +43,8 @@ public class ReactiveCatalogApiClientConfigurationTest { }); } - public @Test void testReactiveConfigClientIsLoaded() { + @Test + void testReactiveConfigClientIsLoaded() { this.contextRunner.run( context -> { assertThat(context).hasSingleBean(ReactiveConfigClient.class); @@ -51,7 +53,8 @@ public class ReactiveCatalogApiClientConfigurationTest { }); } - public @Test void testReactiveResourceStoreClientIsLoaded() { + @Test + void testReactiveResourceStoreClientIsLoaded() { this.contextRunner.run( context -> { assertThat(context).hasSingleBean(ReactiveResourceStoreClient.class); diff --git a/src/catalog/catalog-server/client/src/test/java/org/geoserver/cloud/catalog/client/repository/CatalogClientRepositoryConfigurationTest.java b/src/catalog/catalog-server/client/src/test/java/org/geoserver/cloud/catalog/client/repository/CatalogClientRepositoryConfigurationTest.java index ebc8383e2..fb9fa37e2 100644 --- a/src/catalog/catalog-server/client/src/test/java/org/geoserver/cloud/catalog/client/repository/CatalogClientRepositoryConfigurationTest.java +++ b/src/catalog/catalog-server/client/src/test/java/org/geoserver/cloud/catalog/client/repository/CatalogClientRepositoryConfigurationTest.java @@ -17,7 +17,7 @@ import reactivefeign.spring.config.ReactiveFeignAutoConfiguration; -public class CatalogClientRepositoryConfigurationTest { +class CatalogClientRepositoryConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() @@ -46,35 +46,43 @@ void verify(Class> repoType) { })); } - public @Test void workspaceRepository() { + @Test + void workspaceRepository() { verify(CatalogClientWorkspaceRepository.class); } - public @Test void namespaceRepository() { + @Test + void namespaceRepository() { verify(CatalogClientNamespaceRepository.class); } - public @Test void storeRepository() { + @Test + void storeRepository() { verify(CatalogClientStoreRepository.class); } - public @Test void resourceRepository() { + @Test + void resourceRepository() { verify(CatalogClientResourceRepository.class); } - public @Test void layerRepository() { + @Test + void layerRepository() { verify(CatalogClientLayerRepository.class); } - public @Test void layerGroupRepository() { + @Test + void layerGroupRepository() { verify(CatalogClientLayerGroupRepository.class); } - public @Test void styleRepository() { + @Test + void styleRepository() { verify(CatalogClientNamespaceRepository.class); } - public @Test void mapRepository() { + @Test + void mapRepository() { verify(CatalogClientMapRepository.class); } } diff --git a/src/catalog/catalog-server/client/src/test/java/org/geoserver/cloud/catalog/client/repository/CatalogClientRepositoryTest.java b/src/catalog/catalog-server/client/src/test/java/org/geoserver/cloud/catalog/client/repository/CatalogClientRepositoryTest.java index fa6e4fd2b..be2776a8e 100644 --- a/src/catalog/catalog-server/client/src/test/java/org/geoserver/cloud/catalog/client/repository/CatalogClientRepositoryTest.java +++ b/src/catalog/catalog-server/client/src/test/java/org/geoserver/cloud/catalog/client/repository/CatalogClientRepositoryTest.java @@ -67,7 +67,7 @@ @SpringBootTest(classes = CatalogClientRepositoryConfiguration.class) @ActiveProfiles("test") -public class CatalogClientRepositoryTest { +class CatalogClientRepositoryTest { private @MockBean ReactiveCatalogClient mockClient; @@ -98,11 +98,13 @@ public class CatalogClientRepositoryTest { testData.after(); } - public @Test void workspaceRepository_CRUD() { + @Test + void workspaceRepository_CRUD() { crudTest(workspaceRepository, testData.workspaceA); } - public @Test void workspaceRepository_DefaultWorkspace() { + @Test + void workspaceRepository_DefaultWorkspace() { when(mockClient.getDefaultWorkspace()).thenReturn(Mono.just(testData.workspaceB)); assertSame(testData.workspaceB, workspaceRepository.getDefaultWorkspace().get()); @@ -118,11 +120,13 @@ public class CatalogClientRepositoryTest { NullPointerException.class, () -> workspaceRepository.setDefaultWorkspace(null)); } - public @Test void namespaceRepository_CRUD() { + @Test + void namespaceRepository_CRUD() { crudTest(namespaceRepository, testData.namespaceA); } - public @Test void namespaceRepository_DefaultNamespace() { + @Test + void namespaceRepository_DefaultNamespace() { when(mockClient.getDefaultNamespace()).thenReturn(Mono.just(testData.namespaceB)); assertSame(testData.namespaceB, namespaceRepository.getDefaultNamespace().get()); verify(mockClient, times(1)).getDefaultNamespace(); @@ -137,14 +141,16 @@ public class CatalogClientRepositoryTest { NullPointerException.class, () -> namespaceRepository.setDefaultNamespace(null)); } - public @Test void storeRepository_CRUD() { + @Test + void storeRepository_CRUD() { crudTest(storeRepository, testData.coverageStoreA); crudTest(storeRepository, testData.dataStoreA); crudTest(storeRepository, testData.wmsStoreA); crudTest(storeRepository, testData.wmtsStoreA); } - public @Test void storeRepository_GetDefaultDataStore() { + @Test + void storeRepository_GetDefaultDataStore() { when(mockClient.findDefaultDataStoreByWorkspaceId(eq(testData.workspaceA.getId()))) .thenReturn(Mono.just(testData.dataStoreA)); when(mockClient.findDefaultDataStoreByWorkspaceId(eq(testData.workspaceB.getId()))) @@ -159,7 +165,8 @@ public class CatalogClientRepositoryTest { assertThrows(NullPointerException.class, () -> storeRepository.getDefaultDataStore(null)); } - public @Test void storeRepository_SetDefaultDataStore() { + @Test + void storeRepository_SetDefaultDataStore() { WorkspaceInfo newWs = testData.workspaceC; DataStoreInfo ds = testData.dataStoreA; @@ -177,14 +184,16 @@ public class CatalogClientRepositoryTest { verifyNoMoreInteractions(mockClient); } - public @Test void storeRepository_GetDefaultDataStores_Empty() { + @Test + void storeRepository_GetDefaultDataStores_Empty() { when(mockClient.getDefaultDataStores()).thenReturn(Flux.empty()); assertEquals(0L, storeRepository.getDefaultDataStores().count()); verify(mockClient, times(1)).getDefaultDataStores(); verifyNoMoreInteractions(mockClient); } - public @Test void storeRepository_GetDefaultDataStores() { + @Test + void storeRepository_GetDefaultDataStores() { when(mockClient.getDefaultDataStores()) .thenReturn(Flux.just(testData.dataStoreA, testData.dataStoreB)); assertEquals(2L, storeRepository.getDefaultDataStores().count()); @@ -192,22 +201,26 @@ public class CatalogClientRepositoryTest { verifyNoMoreInteractions(mockClient); } - public @Test void resourceRepository_CRUD() { + @Test + void resourceRepository_CRUD() { crudTest(resourceRepository, testData.coverageA); crudTest(resourceRepository, testData.featureTypeA); crudTest(resourceRepository, testData.wmsLayerA); crudTest(resourceRepository, testData.wmtsLayerA); } - public @Test void layerRepository_CRUD() { + @Test + void layerRepository_CRUD() { crudTest(layerRepository, testData.layerFeatureTypeA); } - public @Test void layerGroupRepository_CRUD() { + @Test + void layerGroupRepository_CRUD() { crudTest(layerGroupRepository, testData.layerGroup1); } - public @Test void styleRepository_CRUD() { + @Test + void styleRepository_CRUD() { crudTest(styleRepository, testData.style1); } @@ -282,7 +295,8 @@ private void assertFindByName(CatalogInfoRepository r verify(mockClient, times(1)).findFirstByName(any(String.class), eq(name), eq(subType)); } - public @Test void testFindByNameNullType() { + @Test + void testFindByNameNullType() { testFindByNameNullType(workspaceRepository, testData.workspaceA.getName()); testFindByNameNullType(namespaceRepository, testData.namespaceA.getName()); testFindByNameNullType(storeRepository, testData.dataStoreA.getName()); diff --git a/src/catalog/catalog-server/server/src/main/java/org/geoserver/cloud/catalog/server/service/BlockingCatalog.java b/src/catalog/catalog-server/server/src/main/java/org/geoserver/cloud/catalog/server/service/BlockingCatalog.java index 455697234..f4e300071 100644 --- a/src/catalog/catalog-server/server/src/main/java/org/geoserver/cloud/catalog/server/service/BlockingCatalog.java +++ b/src/catalog/catalog-server/server/src/main/java/org/geoserver/cloud/catalog/server/service/BlockingCatalog.java @@ -59,7 +59,8 @@ public AllowAllCatalogFacade(CatalogFacade facade) { super(facade); } - public @Override CatalogCapabilities getCatalogCapabilities() { + @Override + public CatalogCapabilities getCatalogCapabilities() { return CATALOG_CAPABILITIES; } } @@ -67,12 +68,9 @@ public AllowAllCatalogFacade(CatalogFacade facade) { public BlockingCatalog(@Qualifier("rawCatalog") Catalog rawCatalog) { super(rawCatalog); // Make sure isolated workspaces can be created/updated - if (rawCatalog instanceof org.geoserver.catalog.plugin.CatalogPlugin) { - CatalogPlugin impl = ((org.geoserver.catalog.plugin.CatalogPlugin) rawCatalog); - impl.getRawFacade().getCatalogCapabilities().setIsolatedWorkspacesSupport(true); - } else if (rawCatalog instanceof org.geoserver.catalog.impl.CatalogImpl) { - org.geoserver.catalog.impl.CatalogImpl impl = - ((org.geoserver.catalog.impl.CatalogImpl) rawCatalog); + if (rawCatalog instanceof org.geoserver.catalog.plugin.CatalogPlugin plugin) { + plugin.getRawFacade().getCatalogCapabilities().setIsolatedWorkspacesSupport(true); + } else if (rawCatalog instanceof org.geoserver.catalog.impl.CatalogImpl impl) { impl.setFacade(new AllowAllCatalogFacade(impl.getFacade())); } } diff --git a/src/catalog/catalog-server/server/src/main/java/org/geoserver/cloud/catalog/server/service/ReactiveCatalogImpl.java b/src/catalog/catalog-server/server/src/main/java/org/geoserver/cloud/catalog/server/service/ReactiveCatalogImpl.java index 9d6aa3a8e..bfa03f49b 100644 --- a/src/catalog/catalog-server/server/src/main/java/org/geoserver/cloud/catalog/server/service/ReactiveCatalogImpl.java +++ b/src/catalog/catalog-server/server/src/main/java/org/geoserver/cloud/catalog/server/service/ReactiveCatalogImpl.java @@ -71,7 +71,8 @@ private Mono async(Runnable runnable, T returnValue) { return Mono.fromRunnable(runnable).subscribeOn(catalogScheduler).thenReturn(returnValue); } - public @Override Mono create(@NonNull Mono info) { + @Override + public Mono create(@NonNull Mono info) { return info.subscribeOn(catalogScheduler).map(blockingCatalog::add); } @@ -79,32 +80,36 @@ public Mono update(@NonNull C info, @NonNull Mono blockingCatalog.update(info, p)); } - public @Override Mono delete(@NonNull C info) { + @Override + public Mono delete(@NonNull C info) { return Mono.just(info).subscribeOn(catalogScheduler).map(blockingCatalog::delete); } - public @Override Flux getAll(@NonNull Class type) { + @Override + public Flux getAll(@NonNull Class type) { return query(Query.all(type)); } - public @Override Mono getById( - @NonNull String id, @NonNull Class type) { + @Override + public Mono getById(@NonNull String id, @NonNull Class type) { return async(() -> blockingCatalog.get(id, type)); } - public @Override Mono getFirstByName( + @Override + public Mono getFirstByName( @NonNull String name, @NonNull Class type) { return async(() -> blockingCatalog.getByName(name, type)); } - public @Override Mono canSortBy( - Class type, String propertyName) { + @Override + public Mono canSortBy(Class type, String propertyName) { return async(() -> blockingCatalog.getFacade().canSort(type, propertyName)); } - public @Override Flux query(@NonNull Query query) { + @Override + public Flux query(@NonNull Query query) { log.debug( "Processing request query of {} with filter {}", query.getType().getSimpleName(), @@ -112,13 +117,15 @@ public Mono update(@NonNull C info, @NonNull Mono blockingCatalog.query(query)).subscribeOn(catalogScheduler); } - public @Override Mono count( + @Override + public Mono count( @NonNull Class type, @NonNull Filter filter) { return async(() -> (long) blockingCatalog.count(type, filter)); } - public @Override Flux getSupportedFunctionNames() { + @Override + public Flux getSupportedFunctionNames() { return Flux.fromStream(this::supportedFunctionNames).subscribeOn(catalogScheduler); } @@ -177,89 +184,107 @@ private boolean isCommonParamType(Class type) { .anyMatch(c -> c.isAssignableFrom(type)); } - public @Override Mono setDefaultWorkspace(@NonNull WorkspaceInfo workspace) { + @Override + public Mono setDefaultWorkspace(@NonNull WorkspaceInfo workspace) { return async(() -> blockingCatalog.setDefaultWorkspace(workspace), workspace); } - public @Override Mono unsetDefaultWorkspace() { + @Override + public Mono unsetDefaultWorkspace() { return getDefaultWorkspace().doOnSuccess(ns -> blockingCatalog.setDefaultWorkspace(null)); } - public @Override Mono unsetDefaultNamespace() { + @Override + public Mono unsetDefaultNamespace() { return getDefaultNamespace().doOnSuccess(ns -> blockingCatalog.setDefaultNamespace(null)); } - public @Override Mono unsetDefaultDataStore(@NonNull WorkspaceInfo workspace) { + @Override + public Mono unsetDefaultDataStore(@NonNull WorkspaceInfo workspace) { return getDefaultDataStore(workspace) .doOnSuccess(ds -> blockingCatalog.setDefaultDataStore(workspace, null)); } - public @Override Mono getDefaultWorkspace() { + @Override + public Mono getDefaultWorkspace() { return async(blockingCatalog::getDefaultWorkspace); } - public @Override Mono setDefaultNamespace(@NonNull NamespaceInfo namespace) { + @Override + public Mono setDefaultNamespace(@NonNull NamespaceInfo namespace) { return async(() -> blockingCatalog.setDefaultNamespace(namespace), namespace); } - public @Override Mono getDefaultNamespace() { + @Override + public Mono getDefaultNamespace() { return async(blockingCatalog::getDefaultNamespace); } - public @Override Mono getOneNamespaceByURI(@NonNull String uri) { + @Override + public Mono getOneNamespaceByURI(@NonNull String uri) { return Mono.just(uri).subscribeOn(catalogScheduler).map(blockingCatalog::getNamespaceByURI); } - public @Override Flux getAllNamespacesByURI(@NonNull String uri) { + @Override + public Flux getAllNamespacesByURI(@NonNull String uri) { return Flux.just(uri) .subscribeOn(catalogScheduler) .map(blockingCatalog::getNamespacesByURI) .flatMap(Flux::fromStream); } - public @Override Flux getDefaultDataStores() { + @Override + public Flux getDefaultDataStores() { return Flux.fromStream(blockingCatalog::getDefaultDataStores).subscribeOn(catalogScheduler); } - public @Override Mono setDefaultDataStore( + @Override + public Mono setDefaultDataStore( @NonNull WorkspaceInfo workspace, @NonNull DataStoreInfo dataStore) { return async(() -> blockingCatalog.setDefaultDataStore(workspace, dataStore), dataStore); } - public @Override Mono getDefaultDataStore(@NonNull WorkspaceInfo workspace) { + @Override + public Mono getDefaultDataStore(@NonNull WorkspaceInfo workspace) { return async(() -> blockingCatalog.getDefaultDataStore(workspace)); } - public @Override Flux getStoresByWorkspace( + @Override + public Flux getStoresByWorkspace( @NonNull WorkspaceInfo workspace, @NonNull Class type) { return Flux.fromStream(() -> blockingCatalog.getStoresByWorkspace(workspace, type).stream()) .subscribeOn(catalogScheduler); } - public @Override Mono getStoreByName( + @Override + public Mono getStoreByName( @NonNull WorkspaceInfo workspace, @NonNull String name, Class type) { return async(() -> blockingCatalog.getStoreByName(workspace, name, type)); } - public @Override Mono getResourceByName( + @Override + public Mono getResourceByName( @NonNull NamespaceInfo namespace, @NonNull String name, @NonNull Class type) { return async(() -> blockingCatalog.getResourceByName(namespace, name, type)); } - public @Override Flux getLayersWithStyle(@NonNull StyleInfo style) { + @Override + public Flux getLayersWithStyle(@NonNull StyleInfo style) { return Flux.fromStream(() -> blockingCatalog.getLayers(style).stream()) .subscribeOn(catalogScheduler); } - public @Override Flux getLayersByResource(@NonNull ResourceInfo resource) { + @Override + public Flux getLayersByResource(@NonNull ResourceInfo resource) { return Flux.fromStream(() -> blockingCatalog.getLayers(resource).stream()) .subscribeOn(catalogScheduler); } - public @Override Flux getLayerGroupsWithNoWoskspace() { + @Override + public Flux getLayerGroupsWithNoWoskspace() { return Flux.fromStream( () -> blockingCatalog @@ -268,24 +293,27 @@ private boolean isCommonParamType(Class type) { .subscribeOn(catalogScheduler); } - public @Override Flux getLayerGroupsByWoskspace( - @NonNull WorkspaceInfo workspace) { + @Override + public Flux getLayerGroupsByWoskspace(@NonNull WorkspaceInfo workspace) { return Flux.fromStream(() -> blockingCatalog.getLayerGroupsByWorkspace(workspace).stream()) .subscribeOn(catalogScheduler); } - public @Override Mono getLayerGroupByName(@NonNull String name) { + @Override + public Mono getLayerGroupByName(@NonNull String name) { return Mono.just(name) .subscribeOn(catalogScheduler) .map(blockingCatalog::getLayerGroupByName); } - public @Override Mono getLayerGroupByName( + @Override + public Mono getLayerGroupByName( @NonNull WorkspaceInfo workspace, @NonNull String name) { return async(() -> blockingCatalog.getLayerGroupByName(workspace, name)); } - public @Override Flux getStylesWithNoWorkspace() { + @Override + public Flux getStylesWithNoWorkspace() { return Flux.fromStream( () -> blockingCatalog @@ -294,19 +322,21 @@ private boolean isCommonParamType(Class type) { .subscribeOn(catalogScheduler); } - public @Override Flux getStylesByWorkspace(@NonNull WorkspaceInfo workspace) { + @Override + public Flux getStylesByWorkspace(@NonNull WorkspaceInfo workspace) { return Flux.just(workspace) .subscribeOn(catalogScheduler) .map(blockingCatalog::getStylesByWorkspace) .flatMap(Flux::fromIterable); } - public @Override Mono getStyleByName( - @NonNull WorkspaceInfo workspace, @NonNull String name) { + @Override + public Mono getStyleByName(@NonNull WorkspaceInfo workspace, @NonNull String name) { return async(() -> blockingCatalog.getStyleByName(workspace, name)); } - public @Override Mono getStyleByName(@NonNull String name) { + @Override + public Mono getStyleByName(@NonNull String name) { return async(() -> blockingCatalog.getStyleByName(CatalogFacade.NO_WORKSPACE, name)); } } diff --git a/src/catalog/catalog-server/server/src/main/java/org/geoserver/cloud/catalog/server/service/ReactiveResourceStoreImpl.java b/src/catalog/catalog-server/server/src/main/java/org/geoserver/cloud/catalog/server/service/ReactiveResourceStoreImpl.java index f722f1b42..059892a98 100644 --- a/src/catalog/catalog-server/server/src/main/java/org/geoserver/cloud/catalog/server/service/ReactiveResourceStoreImpl.java +++ b/src/catalog/catalog-server/server/src/main/java/org/geoserver/cloud/catalog/server/service/ReactiveResourceStoreImpl.java @@ -28,11 +28,13 @@ public class ReactiveResourceStoreImpl implements ReactiveResourceStore { private @Autowired @Qualifier("resourceStoreImpl") ResourceStore blockingStore; private @Autowired Scheduler catalogScheduler; - public @Override Mono get(String path) { + @Override + public Mono get(String path) { return Mono.just(path).subscribeOn(catalogScheduler).map(blockingStore::get); } - public @Override Mono getContents(String path) { + @Override + public Mono getContents(String path) { return get(path) .map( r -> { @@ -46,7 +48,8 @@ public class ReactiveResourceStoreImpl implements ReactiveResourceStore { .map(ByteBuffer::wrap); } - public @Override Mono setContents(String path, ByteBuffer contents) { + @Override + public Mono setContents(String path, ByteBuffer contents) { return get(path) .map( resource -> { @@ -61,14 +64,16 @@ public class ReactiveResourceStoreImpl implements ReactiveResourceStore { }); } - public @Override Mono remove(String path) { + @Override + public Mono remove(String path) { return Mono.just(path).subscribeOn(catalogScheduler).map(blockingStore::remove); } /** * @return the new resource, or empty if it couldn't be moved */ - public @Override Mono move(String path, String target) { + @Override + public Mono move(String path, String target) { return Mono.just(path) .subscribeOn(catalogScheduler) .map(source -> blockingStore.move(source, target)) diff --git a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/AbstractReactiveCatalogControllerTest.java b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/AbstractReactiveCatalogControllerTest.java index 2abedecf6..3462fd649 100644 --- a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/AbstractReactiveCatalogControllerTest.java +++ b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/AbstractReactiveCatalogControllerTest.java @@ -187,7 +187,8 @@ protected WebTestClient webtTestClient() { return this.clientSupport.get(); } - public @Test void testFindByIdNotFound() throws IOException { + @Test + void testFindByIdNotFound() throws IOException { client().findById("non-existent-ws-id", infoType).expectStatus().isNoContent(); } diff --git a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/LayerControllerTest.java b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/LayerControllerTest.java index 8ac2f0a29..72fbc7da4 100644 --- a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/LayerControllerTest.java +++ b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/LayerControllerTest.java @@ -22,7 +22,7 @@ import java.util.stream.Collectors; @AutoConfigureWebTestClient(timeout = "360000") -public class LayerControllerTest extends AbstractReactiveCatalogControllerTest { +class LayerControllerTest extends AbstractReactiveCatalogControllerTest { public LayerControllerTest() { super(LayerInfo.class); @@ -42,7 +42,8 @@ public LayerControllerTest() { catalog.remove(testData.layerFeatureTypeA); } - public @Override @Test void testFindAll() { + @Override + public @Test void testFindAll() { assertTrue(super.findAll().isEmpty()); LayerInfo layer1 = testData.layerFeatureTypeA; LayerInfo layer2 = @@ -59,7 +60,8 @@ public LayerControllerTest() { super.testFindAll(layer1, layer2); } - public @Override @Test void testFindAllByType() { + @Override + public @Test void testFindAllByType() { assertTrue(super.findAll().isEmpty()); LayerInfo layer1 = testData.layerFeatureTypeA; LayerInfo layer2 = @@ -76,12 +78,14 @@ public LayerControllerTest() { super.testFindAll(LayerInfo.class, layer1, layer2); } - public @Override @Test void testFindById() { + @Override + public @Test void testFindById() { catalog.add(testData.layerFeatureTypeA); super.testFindById(testData.layerFeatureTypeA); } - public @Override @Test void testQueryFilter() { + @Override + public @Test void testQueryFilter() { catalog.add(testData.layerFeatureTypeA); StyleInfo style1 = testData.style1; StyleInfo style2 = testData.style2; @@ -114,7 +118,8 @@ public LayerControllerTest() { super.testQueryFilter(cql, layer1, layer2); } - public @Test void testLayerCRUD() { + @Test + void testLayerCRUD() { LayerInfo layer = testData.layerFeatureTypeA; crudTest( layer, @@ -127,7 +132,8 @@ public LayerControllerTest() { }); } - public @Test void testUpdateStyles() { + @Test + void testUpdateStyles() { LayerInfo layer = testData.layerFeatureTypeA; catalog.add(layer); @@ -145,7 +151,8 @@ public LayerControllerTest() { }); } - public @Test void testFindLayersByResource() { + @Test + void testFindLayersByResource() { LayerInfo layer = testData.layerFeatureTypeA; catalog.add(layer); @@ -159,13 +166,15 @@ public LayerControllerTest() { .consumeWith(res -> assertEquals(1, res.getResponseBody().size())); } - public @Test void testFindLayersByResource_NonExistentResourceId() { + @Test + void testFindLayersByResource_NonExistentResourceId() { client().getRelative("/layers/resource/{id}", "bad-resource-id") .expectStatus() .isNoContent(); } - public @Test void testFindLayersWithStyle() { + @Test + void testFindLayersWithStyle() { StyleInfo style1 = testData.style1; // on layer1 and layer2 StyleInfo style2 = testData.style2; // layer2's default style StyleInfo style3 = testData.createStyle("style3"); // on layer2 diff --git a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/LayerGroupControllerTest.java b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/LayerGroupControllerTest.java index 591088f4a..2785842e0 100644 --- a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/LayerGroupControllerTest.java +++ b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/LayerGroupControllerTest.java @@ -16,8 +16,7 @@ import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; @AutoConfigureWebTestClient(timeout = "360000") -public class LayerGroupControllerTest - extends AbstractReactiveCatalogControllerTest { +class LayerGroupControllerTest extends AbstractReactiveCatalogControllerTest { public LayerGroupControllerTest() { super(LayerGroupInfo.class); @@ -31,7 +30,8 @@ public LayerGroupControllerTest() { assertEquals(expected.getLayers(), actual.getLayers()); } - public @Override @Test void testFindAll() { + @Override + public @Test void testFindAll() { super.testFindAll(testData.layerGroup1); LayerGroupInfo lg2 = testData.createLayerGroup( @@ -44,15 +44,18 @@ public LayerGroupControllerTest() { super.testFindAll(testData.layerGroup1, lg2); } - public @Override @Test void testFindById() { + @Override + public @Test void testFindById() { super.testFindById(testData.layerGroup1); } - public @Override @Test void testFindAllByType() { + @Override + public @Test void testFindAllByType() { super.testFindAll(LayerGroupInfo.class, testData.layerGroup1); } - public @Override @Test void testQueryFilter() { + @Override + public @Test void testQueryFilter() { LayerGroupInfo lg1 = testData.layerGroup1; LayerGroupInfo lg2 = testData.createLayerGroup( @@ -73,7 +76,8 @@ public LayerGroupControllerTest() { super.testQueryFilter(cql, lg1); } - public @Test void testLayerGroupCRUD_NoWorkspace() { + @Test + void testLayerGroupCRUD_NoWorkspace() { WorkspaceInfo workspace = null; LayerGroupInfo layerGroup = testData.createLayerGroup( @@ -101,7 +105,8 @@ public LayerGroupControllerTest() { }); } - public @Test void testLayerGroupCRUD_Workspace() { + @Test + void testLayerGroupCRUD_Workspace() { final WorkspaceInfo workspace = testData.workspaceA; LayerGroupInfo layerGroup = testData.createLayerGroup( @@ -122,7 +127,8 @@ public LayerGroupControllerTest() { }); } - public @Test void testUpdateLayers() { + @Test + void testUpdateLayers() { WorkspaceInfo workspace = null; LayerGroupInfo layerGroup = testData.createLayerGroup( diff --git a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/NamespaceControllerTest.java b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/NamespaceControllerTest.java index 0e97d8029..de194259d 100644 --- a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/NamespaceControllerTest.java +++ b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/NamespaceControllerTest.java @@ -18,7 +18,7 @@ import java.util.List; @AutoConfigureWebTestClient(timeout = "360000") -public class NamespaceControllerTest extends AbstractReactiveCatalogControllerTest { +class NamespaceControllerTest extends AbstractReactiveCatalogControllerTest { public NamespaceControllerTest() { super(NamespaceInfo.class); @@ -30,22 +30,26 @@ public NamespaceControllerTest() { assertEquals(expected.getURI(), actual.getURI()); } - public @Override @Test void testFindAll() { + @Override + public @Test void testFindAll() { super.testFindAll(testData.namespaceA, testData.namespaceB, testData.namespaceC); } - public @Override @Test void testFindAllByType() { + @Override + public @Test void testFindAllByType() { super.testFindAll( NamespaceInfo.class, testData.namespaceA, testData.namespaceB, testData.namespaceC); } - public @Override @Test void testFindById() { + @Override + public @Test void testFindById() { super.testFindById(testData.namespaceA); super.testFindById(testData.namespaceB); super.testFindById(testData.namespaceC); } - public @Override @Test void testQueryFilter() { + @Override + public @Test void testQueryFilter() { NamespaceInfo ns1 = catalog.getNamespace(testData.namespaceA.getId()); NamespaceInfo ns2 = catalog.getNamespace(testData.namespaceB.getId()); NamespaceInfo ns3 = catalog.getNamespace(testData.namespaceC.getId()); @@ -59,13 +63,15 @@ public NamespaceControllerTest() { super.testQueryFilter(String.format("URI = '%s'", ns1.getURI()), ns1, ns3); } - public @Test void testFindNamespaceById() { + @Test + void testFindNamespaceById() { testFindById(testData.namespaceA); testFindById(testData.namespaceB); testFindById(testData.namespaceC); } - public @Test void testFindNamespacePrefix() { + @Test + void testFindNamespacePrefix() { testFindByPrefix(testData.namespaceA); testFindByPrefix(testData.namespaceB); testFindByPrefix(testData.namespaceC); @@ -75,7 +81,8 @@ private void testFindByPrefix(NamespaceInfo expected) { assertEquals(expected, client().getFirstByName(expected.getPrefix())); } - public @Test void testNamespaceInfo_CRUD() throws IOException { + @Test + void testNamespaceInfo_CRUD() throws IOException { NamespaceInfo ns = testData.faker().namespace(); crudTest( ns, @@ -84,7 +91,8 @@ private void testFindByPrefix(NamespaceInfo expected) { (old, updated) -> assertEquals("modified-prefix", updated.getPrefix())); } - public @Test void testSetDefaultNamespace() { + @Test + void testSetDefaultNamespace() { assertEquals(testData.namespaceA, catalog.getDefaultNamespace()); NamespaceInfo returned = @@ -100,7 +108,8 @@ private void testFindByPrefix(NamespaceInfo expected) { assertEquals(testData.namespaceB, returned); } - public @Test void testSetDefaultNamespaceNonExistent() { + @Test + void testSetDefaultNamespaceNonExistent() { assertEquals(testData.namespaceA, catalog.getDefaultNamespace()); client().put("/namespaces/default/{id}", "non-existent-id") @@ -110,7 +119,8 @@ private void testFindByPrefix(NamespaceInfo expected) { .contentType(APPLICATION_JSON); } - public @Test void testGetDefaultNamespace() { + @Test + void testGetDefaultNamespace() { NamespaceInfo returned = client().getRelative("/namespaces/default") .expectStatus() @@ -137,7 +147,8 @@ private void testFindByPrefix(NamespaceInfo expected) { assertEquals(testData.namespaceB, returned); } - public @Test void testGetDefaultNamespaceNoDefaultExists() { + @Test + void testGetDefaultNamespaceNoDefaultExists() { testData.deleteAll(); client().getRelative("/namespaces/default") .expectStatus() @@ -146,7 +157,8 @@ private void testFindByPrefix(NamespaceInfo expected) { .contentType(APPLICATION_JSON); } - public @Test void testFindOneNamespaceByURI() { + @Test + void testFindOneNamespaceByURI() { NamespaceInfo ns1 = testData.namespaceA; NamespaceInfo ns2 = testData.faker().namespace("second-ns-with-duplicate-uri", "prefix2", ns1.getURI()); @@ -171,7 +183,8 @@ protected NamespaceInfo findByURI(String uri) { return found; } - public @Test void testFindAllNamespacesByURI() { + @Test + void testFindAllNamespacesByURI() { NamespaceInfo ns1 = testData.namespaceA; NamespaceInfo ns2 = testData.faker().namespace("second-ns-with-duplicate-uri", "prefix2", ns1.getURI()); @@ -193,7 +206,8 @@ protected NamespaceInfo findByURI(String uri) { assertEquals(2, found.size()); } - public @Test void testCreateNamespaceDuplicateURI() { + @Test + void testCreateNamespaceDuplicateURI() { NamespaceInfo ns1 = testData.namespaceA; NamespaceInfo ns2 = testData.faker().namespace("second-ns-with-duplicate-uri", "prefix2", ns1.getURI()); diff --git a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/ReactiveConfigControllerTest.java b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/ReactiveConfigControllerTest.java index b7148c72a..6fb44507f 100644 --- a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/ReactiveConfigControllerTest.java +++ b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/ReactiveConfigControllerTest.java @@ -53,7 +53,7 @@ classes = {CatalogServerConfiguration.class, WebTestClientSupportConfiguration.class}) @ActiveProfiles("test") // see bootstrap-test.yml @AutoConfigureWebTestClient(timeout = "360000") -public class ReactiveConfigControllerTest { +class ReactiveConfigControllerTest { private @Autowired WebTestClient testClient; @@ -83,7 +83,8 @@ public class ReactiveConfigControllerTest { } // GET /global - public @Test void getGlobal() { + @Test + void getGlobal() { GeoServerInfo global = controller.getGlobal().block(); assertNotNull(global); GeoServerInfo responseBody = @@ -102,7 +103,8 @@ public class ReactiveConfigControllerTest { } // PUT /global - public @Test void setGlobal() { + @Test + void setGlobal() { GeoServerInfo newGlobal = testData.global; newGlobal.setAdminPassword("testme"); newGlobal.setAdminUsername("me"); @@ -118,7 +120,8 @@ public class ReactiveConfigControllerTest { } // GET /workspaces/{workspaceId}/settings - public @Test void getSettingsByWorkspace() { + @Test + void getSettingsByWorkspace() { WorkspaceInfo workspace = testData.workspaceA; get("/workspaces/{workspaceId}/settings", workspace.getId()).expectStatus().isNoContent(); @@ -136,7 +139,8 @@ public class ReactiveConfigControllerTest { } // POST /workspaces/{workspaceId}/settings - public @Test void createSettings() { + @Test + void createSettings() { WorkspaceInfo workspace = testData.workspaceA; assertNull(geoServer.getSettings(workspace)); SettingsInfo settings = testData.workspaceASettings; @@ -149,7 +153,8 @@ public class ReactiveConfigControllerTest { } // PATCH /workspaces/{workspaceId}/settings - public @Test void updateSettings() { + @Test + void updateSettings() { WorkspaceInfo workspace = testData.workspaceA; SettingsInfo settings = testData.workspaceASettings; settings.setWorkspace(workspace); @@ -168,7 +173,8 @@ public class ReactiveConfigControllerTest { } // DELETE /workspaces/{workspaceId}/settings - public @Test void deleteSettings() { + @Test + void deleteSettings() { WorkspaceInfo workspace = testData.workspaceA; SettingsInfo settings = testData.workspaceASettings; settings.setWorkspace(workspace); @@ -186,7 +192,8 @@ public class ReactiveConfigControllerTest { } // get /logging - public @Test void getLogging() { + @Test + void getLogging() { geoServer.setLogging(testData.logging); LoggingInfo logging = geoServer.getLogging(); assertNotNull(logging); @@ -201,7 +208,8 @@ public class ReactiveConfigControllerTest { } // PUT /logging - public @Test void setLogging() { + @Test + void setLogging() { LoggingInfo logging = testData.logging; logging.setLevel("apiLevel"); logging.setLocation("/right/there"); @@ -212,7 +220,8 @@ public class ReactiveConfigControllerTest { } // POST /services - public @Test void createService() { + @Test + void createService() { if (null != geoServer.getService(WMSInfo.class)) geoServer.remove(geoServer.getService(WMSInfo.class)); @@ -228,7 +237,8 @@ public class ReactiveConfigControllerTest { } // POST /workspaces/{workspaceId}/services - public @Test void createServiceByWorkspace() { + @Test + void createServiceByWorkspace() { WorkspaceInfo workspace = testData.workspaceA; if (null != geoServer.getService(workspace, WMSInfo.class)) geoServer.remove(geoServer.getService(workspace, WMSInfo.class)); @@ -249,7 +259,8 @@ public class ReactiveConfigControllerTest { } // DELETE /services/{serviceId} - public @Test void deleteServiceById() { + @Test + void deleteServiceById() { WMSInfo service = testData.wmsService; if (null == geoServer.getService(WMSInfo.class)) geoServer.add(service); assertNotNull(geoServer.getService(WMSInfo.class)); @@ -264,7 +275,8 @@ public class ReactiveConfigControllerTest { } // GET /services/{serviceId} - public @Test void getServiceById() { + @Test + void getServiceById() { WorkspaceInfo ws = testData.workspaceA; WMSInfo wmsService = testData.wmsService; WCSInfo wcsService = testData.wcsService; @@ -302,7 +314,8 @@ public class ReactiveConfigControllerTest { } // PATCH /services/{id} - public @Test void updateService() { + @Test + void updateService() { geoServer.add(testData.wmsService); geoServer.add(testData.wcsService); geoServer.add(testData.wfsService); @@ -318,7 +331,8 @@ public class ReactiveConfigControllerTest { } // PATCH /services/{id} - public @Test void updateServiceByWorkspace() { + @Test + void updateServiceByWorkspace() { addServicesToWorkspaceA(); WorkspaceInfo ws = testData.workspaceA; @@ -367,7 +381,8 @@ private Patch asPatch(Info modified) { } // GET /workspaces/{workspaceId}/services - public @Test void getServicesByWorkspace() { + @Test + void getServicesByWorkspace() { WorkspaceInfo ws = testData.workspaceA; geoServer.getServices(ws).forEach(geoServer::remove); @@ -421,7 +436,8 @@ private void testGetServicesByWorkspace(WorkspaceInfo ws, ServiceInfo... expecte } // GET /services - public @Test void getGlobalServices() { + @Test + void getGlobalServices() { geoServer.getServices().forEach(geoServer::remove); get("/services") @@ -465,7 +481,8 @@ private void testGetServices(ServiceInfo... expected) { } // GET @GetMapping("/services/type/{type} - public @Test void getGlobalService() { + @Test + void getGlobalService() { testGetGlobalService(testData.wmsService, WMSInfo.class); testGetGlobalService(testData.wfsService, WFSInfo.class); testGetGlobalService(testData.wcsService, WCSInfo.class); @@ -487,7 +504,8 @@ private void testGetGlobalService(S service, Class ty } // @GetMapping("/workspaces/{workspaceId}/services/type/{type}") - public @Test void getServiceByWorkspaceAndType() { + @Test + void getServiceByWorkspaceAndType() { WorkspaceInfo ws = testData.workspaceA; geoServer.getServices(ws).forEach(geoServer::remove); testGetServiceByWorkspaceAndType(ws, WMSInfo.class, testData.wmsService); @@ -521,7 +539,8 @@ private void testGetServiceByWorkspaceAndType( } // GET /services/name/{name} - public @Test void getGlobalServiceByName() { + @Test + void getGlobalServiceByName() { geoServer.getServices().forEach(geoServer::remove); testGetGlobalServiceByName(testData.wmsService); testGetGlobalServiceByName(testData.wfsService); @@ -562,7 +581,8 @@ private void testGetGlobalServiceByName(ServiceInfo service) { } // GET /workspaces/{workspaceId}/services/name/{name} - public @Test void getServiceByWorkspaceAndName() { + @Test + void getServiceByWorkspaceAndName() { addServicesToWorkspaceA(); testGetServiceByWorkspaceAndName(testData.wmsService); diff --git a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/ResourceInfoControllerTest.java b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/ResourceInfoControllerTest.java index 49e4f4e4f..b15c0e35e 100644 --- a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/ResourceInfoControllerTest.java +++ b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/ResourceInfoControllerTest.java @@ -27,8 +27,7 @@ import java.util.List; @AutoConfigureWebTestClient(timeout = "360000") -public class ResourceInfoControllerTest - extends AbstractReactiveCatalogControllerTest { +class ResourceInfoControllerTest extends AbstractReactiveCatalogControllerTest { public ResourceInfoControllerTest() { super(ResourceInfo.class); @@ -43,19 +42,22 @@ public ResourceInfoControllerTest() { assertEquals(expected.getStore().getId(), actual.getStore().getId()); } - public @Override @Test void testFindAll() { + @Override + public @Test void testFindAll() { super.testFindAll( testData.featureTypeA, testData.coverageA, testData.wmsLayerA, testData.wmtsLayerA); } - public @Override @Test void testFindById() { + @Override + public @Test void testFindById() { super.testFindById(testData.featureTypeA); super.testFindById(testData.coverageA); super.testFindById(testData.wmsLayerA); super.testFindById(testData.wmtsLayerA); } - public @Override @Test void testFindAllByType() { + @Override + public @Test void testFindAllByType() { super.testFindAll( ResourceInfo.class, testData.featureTypeA, @@ -68,7 +70,8 @@ public ResourceInfoControllerTest() { super.testFindAll(WMTSLayerInfo.class, testData.wmtsLayerA); } - public @Override @Test void testQueryFilter() { + @Override + public @Test void testQueryFilter() { FeatureTypeInfo ft = catalog.getResource(testData.featureTypeA.getId(), FeatureTypeInfo.class); CoverageInfo cv = catalog.getResource(testData.coverageA.getId(), CoverageInfo.class); @@ -88,7 +91,8 @@ public ResourceInfoControllerTest() { super.testQueryFilter("enabled = false", wms, wmts); } - public @Test void testResourceInfoCRUD_FeatureTypeInfo() { + @Test + void testResourceInfoCRUD_FeatureTypeInfo() { FeatureTypeInfo toCreate = testData.createFeatureType( "featureTypeCRUD", @@ -113,7 +117,8 @@ public ResourceInfoControllerTest() { }); } - public @Test void testResourceInfoCRUD_CoverageInfo() { + @Test + void testResourceInfoCRUD_CoverageInfo() { CoverageInfo toCreate = testData.createCoverage( "coverageCRUD", testData.coverageStoreA, "coverageCRUD_name"); @@ -142,7 +147,8 @@ public ResourceInfoControllerTest() { * java.util.Collections$EmptySet (in module java.base) with modifiers "private"} */ @Disabled - public @Test void testResourceInfoCRUD_WMSLayerInfo() { + @Test + void testResourceInfoCRUD_WMSLayerInfo() { WMSLayerInfo toCreate = testData.createWMSLayer( "wmsLayerCRUD", @@ -165,7 +171,8 @@ public ResourceInfoControllerTest() { }); } - public @Test void testResourceInfoCRUD_WMTSLayerInfo() { + @Test + void testResourceInfoCRUD_WMTSLayerInfo() { WMTSLayerInfo toCreate = testData.createWMTSLayer( "wmtsLayerCRUD", @@ -188,14 +195,16 @@ public ResourceInfoControllerTest() { }); } - public @Test void testFindResourceInfoById() { + @Test + void testFindResourceInfoById() { testFindById(testData.featureTypeA); testFindById(testData.coverageA); testFindById(testData.wmsLayerA); testFindById(testData.wmtsLayerA); } - public @Test void testFindResourceInfoById_SubtypeMismatch() throws IOException { + @Test + void testFindResourceInfoById_SubtypeMismatch() throws IOException { CatalogTestClient client = client(); client.findById(testData.featureTypeA.getId(), CoverageInfo.class) .expectStatus() @@ -211,7 +220,8 @@ public ResourceInfoControllerTest() { .isNoContent(); } - public @Test void testFindResourceByNamespaceIdAndName() { + @Test + void testFindResourceByNamespaceIdAndName() { NamespaceInfo ns = testData.namespaceA; ResourceInfo ftA = testData.featureTypeA; @@ -227,7 +237,8 @@ public ResourceInfoControllerTest() { .consumeWith(result -> assertEquals(ftA.getId(), result.getResponseBody().getId())); } - public @Test void testFindAllBySubtype() { + @Test + void testFindAllBySubtype() { List all = super.findAll(ClassMappings.fromInterface(FeatureTypeInfo.class)); assertEquals(catalog.getResources(FeatureTypeInfo.class).size(), all.size()); diff --git a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/StoreControllerTest.java b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/StoreControllerTest.java index 57adfb9ce..46e628949 100644 --- a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/StoreControllerTest.java +++ b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/StoreControllerTest.java @@ -33,7 +33,7 @@ import java.util.stream.Collectors; @AutoConfigureWebTestClient(timeout = "360000") -public class StoreControllerTest extends AbstractReactiveCatalogControllerTest { +class StoreControllerTest extends AbstractReactiveCatalogControllerTest { public StoreControllerTest() { super(StoreInfo.class); @@ -56,16 +56,15 @@ public StoreControllerTest() { assertEquals(expected.getType(), actual.getType()); assertEquals(expected.getWorkspace(), actual.getWorkspace()); assertEquals(expected.isEnabled(), actual.isEnabled()); - if (expected instanceof CoverageStoreInfo) + if (expected instanceof CoverageStoreInfo store) + assertEquals(store.getURL(), ((CoverageStoreInfo) actual).getURL()); + if (expected instanceof HTTPStoreInfo httpStore) assertEquals( - ((CoverageStoreInfo) expected).getURL(), ((CoverageStoreInfo) actual).getURL()); - if (expected instanceof HTTPStoreInfo) - assertEquals( - ((HTTPStoreInfo) expected).getCapabilitiesURL(), - ((HTTPStoreInfo) actual).getCapabilitiesURL()); + httpStore.getCapabilitiesURL(), ((HTTPStoreInfo) actual).getCapabilitiesURL()); } - public @Override @Test void testFindAll() { + @Override + public @Test void testFindAll() { super.testFindAll( testData.dataStoreA, testData.dataStoreB, @@ -75,14 +74,16 @@ public StoreControllerTest() { testData.wmtsStoreA); } - public @Override @Test void testFindById() { + @Override + public @Test void testFindById() { super.testFindById(testData.dataStoreA); super.testFindById(testData.coverageStoreA); super.testFindById(testData.wmsStoreA); super.testFindById(testData.wmtsStoreA); } - public @Override @Test void testFindAllByType() { + @Override + public @Test void testFindAllByType() { super.testFindAll( StoreInfo.class, testData.dataStoreA, @@ -99,7 +100,8 @@ public StoreControllerTest() { super.testFindAll(WMTSStoreInfo.class, testData.wmtsStoreA); } - public @Override @Test void testQueryFilter() { + @Override + public @Test void testQueryFilter() { DataStoreInfo ds1 = catalog.getDataStore(testData.dataStoreA.getId()); DataStoreInfo ds2 = catalog.getDataStore(testData.dataStoreB.getId()); DataStoreInfo ds3 = catalog.getDataStore(testData.dataStoreC.getId()); @@ -123,7 +125,8 @@ public StoreControllerTest() { super.testQueryFilter(ecql, ds2); } - public @Test void testDataStoreInfo_CRUD() throws IOException { + @Test + void testDataStoreInfo_CRUD() throws IOException { DataStoreInfo store = testData.faker() .dataStoreInfo( @@ -150,7 +153,8 @@ public StoreControllerTest() { }); } - public @Test void testCoverageStoreInfo_CRUD() { + @Test + void testCoverageStoreInfo_CRUD() { CoverageStoreInfo store = testData.createCoverageStore( "coverageStoreCRUD", @@ -179,7 +183,8 @@ public StoreControllerTest() { }); } - public @Test void testWMSStoreInfo_CRUD() { + @Test + void testWMSStoreInfo_CRUD() { WMSStoreInfo store = testData.createWebMapServer( "wmsStoreCRUD", @@ -206,7 +211,8 @@ public StoreControllerTest() { }); } - public @Test void testWMTSStoreInfo_CRUD() { + @Test + void testWMTSStoreInfo_CRUD() { WMTSStoreInfo store = testData.createWebMapTileServer( "wmsStoreCRUD", @@ -233,7 +239,8 @@ public StoreControllerTest() { }); } - public @Test void testFindStoreById() throws IOException { + @Test + void testFindStoreById() throws IOException { testFindById(testData.coverageStoreA); testFindById(testData.dataStoreA); testFindById(testData.dataStoreB); @@ -241,7 +248,8 @@ public StoreControllerTest() { testFindById(testData.wmtsStoreA); } - public @Test void testFindStoreById_SubtypeMismatch() throws IOException { + @Test + void testFindStoreById_SubtypeMismatch() throws IOException { CatalogTestClient client = client(); client.findById(testData.coverageStoreA.getId(), DataStoreInfo.class) .expectStatus() @@ -254,7 +262,8 @@ public StoreControllerTest() { .isNoContent(); } - public @Test void testFindStoreByName() throws IOException { + @Test + void testFindStoreByName() throws IOException { findStoreByName(testData.coverageStoreA); findStoreByName(testData.dataStoreA); findStoreByName(testData.dataStoreB); @@ -268,7 +277,8 @@ private void findStoreByName(StoreInfo store) { assertCatalogInfoEquals(store, resolved); } - public @Test void testFindStoreByWorkspaceAndName() throws IOException { + @Test + void testFindStoreByWorkspaceAndName() throws IOException { testFindStoreByWorkspaceAndName(testData.coverageStoreA, null); testFindStoreByWorkspaceAndName(testData.coverageStoreA, ClassMappings.COVERAGESTORE); @@ -304,7 +314,8 @@ private void testFindStoreByWorkspaceAndName(StoreInfo store, @Nullable ClassMap assertEquals(store.getName(), found.getName()); } - public @Test void testFindStoreByName_WrongWorkspace() throws IOException { + @Test + void testFindStoreByName_WrongWorkspace() throws IOException { testFindStoreByName_WrongWorkspace(testData.coverageStoreA, testData.workspaceC); testFindStoreByName_WrongWorkspace(testData.dataStoreA, testData.workspaceC); testFindStoreByName_WrongWorkspace(testData.dataStoreB, testData.workspaceC); @@ -324,7 +335,8 @@ private void testFindStoreByName_WrongWorkspace(StoreInfo store, WorkspaceInfo w .isNoContent(); } - public @Test void testFindStoresByWorkspace() { + @Test + void testFindStoresByWorkspace() { testFindStoresByWorkspace( testData.workspaceA, testData.dataStoreA, diff --git a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/StyleControllerTest.java b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/StyleControllerTest.java index d5aaa4967..9d472ee51 100644 --- a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/StyleControllerTest.java +++ b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/StyleControllerTest.java @@ -23,7 +23,7 @@ import java.util.stream.Collectors; @AutoConfigureWebTestClient(timeout = "360000") -public class StyleControllerTest extends AbstractReactiveCatalogControllerTest { +class StyleControllerTest extends AbstractReactiveCatalogControllerTest { public StyleControllerTest() { super(StyleInfo.class); @@ -48,7 +48,8 @@ private void assertLegendEquals(LegendInfo expected, LegendInfo actual) { } } - public @Test void testStyleCRUD_NoWorkspace() { + @Test + void testStyleCRUD_NoWorkspace() { StyleInfo style = testData.createStyle("styleCRUD", null, "styleCRUD", "styleCRUD.sld"); ((StyleInfoImpl) style).setFormat(SLDHandler.FORMAT); ((StyleInfoImpl) style).setFormatVersion(SLDHandler.VERSION_10); @@ -83,7 +84,8 @@ private void assertLegendEquals(LegendInfo expected, LegendInfo actual) { }); } - public @Test void testStyleCRUD_Workspace() { + @Test + void testStyleCRUD_Workspace() { StyleInfo style = testData.createStyle( "styleCRUD_Workspace", @@ -155,7 +157,8 @@ private void assertLegendEquals(LegendInfo expected, LegendInfo actual) { super.testQueryFilter(cql, ws1s1, ws1s2); } - public @Test void testFindStyleByNameAndNullWorkspace() { + @Test + void testFindStyleByNameAndNullWorkspace() { WorkspaceInfo ws1 = testData.workspaceA; StyleInfo ws1s1 = testData.createStyle("s1ws1", ws1); catalog.add(ws1s1); @@ -178,7 +181,8 @@ private void testFindStyleByNameAndNullWorkspace(StyleInfo style) { .consumeWith(r -> assertEquals(style.getId(), r.getResponseBody().getId())); } - public @Test void testfindStyleByWorkspaceIdAndName() { + @Test + void testfindStyleByWorkspaceIdAndName() { WorkspaceInfo ws1 = testData.workspaceA; WorkspaceInfo ws2 = testData.workspaceB; StyleInfo ws1s1 = testData.createStyle("s1ws1", ws1); @@ -205,7 +209,8 @@ private void testfindStyleByWorkspaceIdAndName(WorkspaceInfo ws, StyleInfo style .consumeWith(r -> assertEquals(style.getId(), r.getResponseBody().getId())); } - public @Test void testFindStylesByNullWorkspace() { + @Test + void testFindStylesByNullWorkspace() { StyleInfo ws1s1 = testData.createStyle("s1ws1", testData.workspaceA); catalog.add(ws1s1); @@ -231,7 +236,8 @@ private void testfindStyleByWorkspaceIdAndName(WorkspaceInfo ws, StyleInfo style }); } - public @Test void testFindStylesByWorkspaceId() { + @Test + void testFindStylesByWorkspaceId() { WorkspaceInfo ws1 = testData.workspaceA; WorkspaceInfo ws2 = testData.workspaceB; diff --git a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/WorkspaceControllerTest.java b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/WorkspaceControllerTest.java index 8e53792af..193072ff8 100644 --- a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/WorkspaceControllerTest.java +++ b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/api/v1/WorkspaceControllerTest.java @@ -17,7 +17,7 @@ import org.springframework.http.MediaType; @AutoConfigureWebTestClient(timeout = "360000") -public class WorkspaceControllerTest extends AbstractReactiveCatalogControllerTest { +class WorkspaceControllerTest extends AbstractReactiveCatalogControllerTest { public WorkspaceControllerTest() { super(WorkspaceInfo.class); @@ -28,27 +28,32 @@ public WorkspaceControllerTest() { assertEquals(expected.isIsolated(), actual.isIsolated()); } - public @Override @Test void testFindById() { + @Override + public @Test void testFindById() { testFindById(testData.workspaceA); testFindById(testData.workspaceB); testFindById(testData.workspaceC); } - public @Override @Test void testFindAll() { + @Override + public @Test void testFindAll() { super.testFindAll(testData.workspaceA, testData.workspaceB, testData.workspaceC); } - public @Override @Test void testFindAllByType() { + @Override + public @Test void testFindAllByType() { super.testFindAll( WorkspaceInfo.class, testData.workspaceA, testData.workspaceB, testData.workspaceC); } - public @Test void testFindByName() { + @Test + void testFindByName() { WorkspaceInfo ws1 = testData.workspaceA; assertEquals(ws1, client().getFirstByName(ws1.getName())); } - public @Override @Test void testQueryFilter() { + @Override + public @Test void testQueryFilter() { WorkspaceInfo wsA = catalog.getWorkspace(testData.workspaceA.getId()); WorkspaceInfo wsB = catalog.getWorkspace(testData.workspaceB.getId()); WorkspaceInfo wsC = catalog.getWorkspace(testData.workspaceC.getId()); @@ -63,7 +68,8 @@ public WorkspaceControllerTest() { super.testQueryFilter(format("\"id\" = '%s'", wsA.getId()), wsA); } - public @Test void testWorkspaceCRUD() { + @Test + void testWorkspaceCRUD() { WorkspaceInfo ws = testData.faker().workspaceInfo("workspaceCRUD"); crudTest( ws, @@ -78,7 +84,8 @@ public WorkspaceControllerTest() { }); } - public @Test void testGetDefaultWorkspace() { + @Test + void testGetDefaultWorkspace() { WorkspaceInfo expected = catalog.getDefaultWorkspace(); assertNotNull(expected); WorkspaceInfo actual = @@ -93,7 +100,8 @@ public WorkspaceControllerTest() { assertEquals(expected, actual); } - public @Test void testGetDefaultWorkspaceIsNullOnEmptyCatalog() { + @Test + void testGetDefaultWorkspaceIsNullOnEmptyCatalog() { testData.deleteAll(); assertNull(catalog.getDefaultWorkspace()); @@ -104,7 +112,8 @@ public WorkspaceControllerTest() { .contentType(MediaType.APPLICATION_JSON); } - public @Test void testSetDefaultWorkspace() { + @Test + void testSetDefaultWorkspace() { WorkspaceInfo current = catalog.getDefaultWorkspace(); assertNotNull(current); assertEquals(testData.workspaceA.getId(), current.getId()); diff --git a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/test/WebTestClientSupport.java b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/test/WebTestClientSupport.java index 8c676c435..b126e73b4 100644 --- a/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/test/WebTestClientSupport.java +++ b/src/catalog/catalog-server/server/src/test/java/org/geoserver/cloud/catalog/server/test/WebTestClientSupport.java @@ -41,7 +41,8 @@ public class WebTestClientSupport implements Supplier { // .build(); } - public @Override WebTestClient get() { + @Override + public WebTestClient get() { return client; } diff --git a/src/catalog/event-bus/src/main/java/org/geoserver/cloud/autoconfigure/event/bus/RemoteGeoServerEventsAutoConfiguration.java b/src/catalog/event-bus/src/main/java/org/geoserver/cloud/autoconfigure/event/bus/RemoteGeoServerEventsAutoConfiguration.java index c716be640..faffc3d20 100644 --- a/src/catalog/event-bus/src/main/java/org/geoserver/cloud/autoconfigure/event/bus/RemoteGeoServerEventsAutoConfiguration.java +++ b/src/catalog/event-bus/src/main/java/org/geoserver/cloud/autoconfigure/event/bus/RemoteGeoServerEventsAutoConfiguration.java @@ -115,7 +115,7 @@ RemoteGeoServerEventBridge remoteEventBroadcaster( log.info("Configuring GeoServer Catalog distributed events."); - Consumer> localEventPublisher = eventPublisher::publishEvent; + Consumer localEventPublisher = eventPublisher::publishEvent; Consumer remoteEventPublisher = eventPublisher::publishEvent; Supplier busId = serviceMatcher::getBusId; return new RemoteGeoServerEventBridge( diff --git a/src/catalog/event-bus/src/main/java/org/geoserver/cloud/event/bus/InfoEventResolver.java b/src/catalog/event-bus/src/main/java/org/geoserver/cloud/event/bus/InfoEventResolver.java index 51390facb..c539f1294 100644 --- a/src/catalog/event-bus/src/main/java/org/geoserver/cloud/event/bus/InfoEventResolver.java +++ b/src/catalog/event-bus/src/main/java/org/geoserver/cloud/event/bus/InfoEventResolver.java @@ -52,14 +52,11 @@ public InfoEventResolver(@NonNull Catalog rawCatalog, @NonNull GeoServer geoserv .andThen(ResolvingProxyResolver.of(rawCatalog)); } - @SuppressWarnings({"rawtypes", "unchecked"}) - public InfoEvent resolve(InfoEvent event) { - if (event instanceof InfoAdded) { - InfoAdded addEvent = (InfoAdded) event; - Info object = addEvent.getObject(); + public InfoEvent resolve(InfoEvent event) { + if (event instanceof InfoAdded addEvent) { + I object = addEvent.getObject(); addEvent.setObject(resolve(object)); - } else if (event instanceof InfoModified) { - InfoModified modifyEvent = (InfoModified) event; + } else if (event instanceof InfoModified modifyEvent) { modifyEvent.setPatch(resolve(modifyEvent.getPatch())); } return event; @@ -68,8 +65,8 @@ public InfoEventResolver(@NonNull Catalog rawCatalog, @NonNull GeoServer geoserv @SuppressWarnings("unchecked") private I resolve(I object) { if (object == null) return null; - if (object instanceof CatalogInfo) { - return (I) resolve((CatalogInfo) object); + if (object instanceof CatalogInfo i) { + return (I) resolve(i); } return (I) configInfoResolver.apply(object); } diff --git a/src/catalog/event-bus/src/main/java/org/geoserver/cloud/event/bus/RemoteGeoServerEvent.java b/src/catalog/event-bus/src/main/java/org/geoserver/cloud/event/bus/RemoteGeoServerEvent.java index ca75d9687..612243e1a 100644 --- a/src/catalog/event-bus/src/main/java/org/geoserver/cloud/event/bus/RemoteGeoServerEvent.java +++ b/src/catalog/event-bus/src/main/java/org/geoserver/cloud/event/bus/RemoteGeoServerEvent.java @@ -13,11 +13,10 @@ import org.springframework.cloud.bus.event.RemoteApplicationEvent; @EqualsAndHashCode(callSuper = true) +@SuppressWarnings("serial") public class RemoteGeoServerEvent extends RemoteApplicationEvent { - private static final long serialVersionUID = 1L; - - private @Getter GeoServerEvent event; + @Getter @NonNull private GeoServerEvent event; /** Deserialization-time constructor, {@link #getSource()} will be {@code null} */ protected RemoteGeoServerEvent() { @@ -27,7 +26,7 @@ protected RemoteGeoServerEvent() { /** Publish-time constructor, {@link #getSource()} won't be {@code null} */ public RemoteGeoServerEvent( Object source, - @NonNull GeoServerEvent event, + @NonNull GeoServerEvent event, @NonNull String originService, @NonNull Destination destination) { super(source, originService, destination); diff --git a/src/catalog/event-bus/src/main/java/org/geoserver/cloud/event/bus/RemoteGeoServerEventBridge.java b/src/catalog/event-bus/src/main/java/org/geoserver/cloud/event/bus/RemoteGeoServerEventBridge.java index f68c32cc3..5129d9cbb 100644 --- a/src/catalog/event-bus/src/main/java/org/geoserver/cloud/event/bus/RemoteGeoServerEventBridge.java +++ b/src/catalog/event-bus/src/main/java/org/geoserver/cloud/event/bus/RemoteGeoServerEventBridge.java @@ -33,7 +33,7 @@ public class RemoteGeoServerEventBridge { private boolean enabled = true; public RemoteGeoServerEventBridge( // - @NonNull Consumer> localRemoteEventPublisher, // + @NonNull Consumer localRemoteEventPublisher, // @NonNull Consumer remoteEventPublisher, // @NonNull RemoteGeoServerEventMapper mapper, // @NonNull Supplier localBusId) { @@ -47,7 +47,7 @@ public RemoteGeoServerEventBridge( // } @EventListener(GeoServerEvent.class) - public void handleLocalEvent(GeoServerEvent event) { + public void handleLocalEvent(GeoServerEvent event) { if (enabled) { outgoing.broadCastIfLocal(event); } @@ -67,7 +67,7 @@ private static class Outgoing { private final @NonNull RemoteGeoServerEventMapper mapper; private @NonNull Supplier localBusId; - public void broadCastIfLocal(GeoServerEvent event) throws CatalogException { + public void broadCastIfLocal(GeoServerEvent event) throws CatalogException { if (event.isLocal()) { RemoteGeoServerEvent remote = mapper.toRemote(event); @@ -88,10 +88,10 @@ private void publishRemoteEvent(RemoteGeoServerEvent remoteEvent) { } protected void logOutgoing(RemoteGeoServerEvent remoteEvent) { - @NonNull GeoServerEvent event = remoteEvent.getEvent(); + @NonNull GeoServerEvent event = remoteEvent.getEvent(); String logMsg = "{}: broadcasting {}"; - if (event instanceof InfoModified) { - Patch patch = ((InfoModified) event).getPatch(); + if (event instanceof InfoModified modEvent) { + Patch patch = modEvent.getPatch(); if (patch.isEmpty()) { logMsg = "{}: broadcasting no-change event {}"; } @@ -105,7 +105,7 @@ protected void logOutgoing(RemoteGeoServerEvent remoteEvent) { @Slf4j(topic = "org.geoserver.cloud.event.bus.incoming") private static class Incoming { - private final @NonNull Consumer> localRemoteEventPublisher; + private final @NonNull Consumer localRemoteEventPublisher; private final @NonNull RemoteGeoServerEventMapper mapper; private @NonNull Supplier localBusId; @@ -123,7 +123,7 @@ public void handleRemoteEvent(RemoteGeoServerEvent incoming) throws CatalogExcep private void publishLocalEvent(RemoteGeoServerEvent incoming) { log.trace("Received remote event {}", incoming); - GeoServerEvent localRemoteEvent = mapper.toLocalRemote(incoming); + GeoServerEvent localRemoteEvent = mapper.toLocalRemote(incoming); log.debug("{}: publishing as local event {}", localBusId.get(), incoming); try { localRemoteEventPublisher.accept(localRemoteEvent); diff --git a/src/catalog/event-bus/src/main/java/org/geoserver/cloud/event/bus/RemoteGeoServerEventMapper.java b/src/catalog/event-bus/src/main/java/org/geoserver/cloud/event/bus/RemoteGeoServerEventMapper.java index 727d9a8e5..192067dd2 100644 --- a/src/catalog/event-bus/src/main/java/org/geoserver/cloud/event/bus/RemoteGeoServerEventMapper.java +++ b/src/catalog/event-bus/src/main/java/org/geoserver/cloud/event/bus/RemoteGeoServerEventMapper.java @@ -33,7 +33,7 @@ private Destination destinationService() { return serviceMatcher.getBusId(); } - public RemoteGeoServerEvent toRemote(GeoServerEvent anyLocalCatalogOrConfigEvent) { + public RemoteGeoServerEvent toRemote(GeoServerEvent anyLocalCatalogOrConfigEvent) { String origin = originService(); Destination destination = destinationService(); RemoteGeoServerEvent remote = @@ -50,12 +50,12 @@ public Optional ifRemote(@NonNull RemoteGeoServerEvent bus return Optional.ofNullable(republishAsLocal ? busEvent : null); } - public GeoServerEvent toLocalRemote(@NonNull RemoteGeoServerEvent incoming) { - GeoServerEvent event = incoming.getEvent(); + public GeoServerEvent toLocalRemote(@NonNull RemoteGeoServerEvent incoming) { + GeoServerEvent event = incoming.getEvent(); event.setRemote(true); event.setOrigin(incoming.getOriginService()); - if (event instanceof InfoEvent) - event = remoteEventsPropertyResolver.resolve((InfoEvent) event); + if (event instanceof InfoEvent infoEvent) + event = remoteEventsPropertyResolver.resolve(infoEvent); return event; } } diff --git a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/autoconfigure/event/bus/RemoteGeoServerEventsAutoConfigurationTest.java b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/autoconfigure/event/bus/RemoteGeoServerEventsAutoConfigurationTest.java index fd69192c8..2e079a6d6 100644 --- a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/autoconfigure/event/bus/RemoteGeoServerEventsAutoConfigurationTest.java +++ b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/autoconfigure/event/bus/RemoteGeoServerEventsAutoConfigurationTest.java @@ -42,19 +42,23 @@ class RemoteGeoServerEventsAutoConfigurationTest { BusAutoConfiguration.class, RemoteGeoServerEventsAutoConfiguration.class)); - public @Test void enabledByDefault() { + @Test + void enabledByDefault() { assertEnabled(runner); } - public @Test void conditionalOnGeoServerRemoteEventsEnabled() { + @Test + void conditionalOnGeoServerRemoteEventsEnabled() { assertDisabled(runner.withPropertyValues("geoserver.bus.enabled: false")); } - public @Test void conditionalOnBusEnabled() { + @Test + void conditionalOnBusEnabled() { assertDisabled(runner.withPropertyValues("spring.cloud.bus.enabled: false")); } - public @Test void conditionalOnCatalogEvents() { + @Test + void conditionalOnCatalogEvents() { assertDisabled(runner.withPropertyValues("geoserver.catalog.events.enabled: false")); } diff --git a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/BusAmqpIntegrationTests.java b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/BusAmqpIntegrationTests.java index 4ac86a621..81797e1a4 100644 --- a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/BusAmqpIntegrationTests.java +++ b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/BusAmqpIntegrationTests.java @@ -318,7 +318,7 @@ protected void assertRemoteEvent(T info, RemoteGeoServerEvent b assertNotNull(busEvent.getOriginService()); assertEquals("**", busEvent.getDestinationService()); - GeoServerEvent event = busEvent.getEvent(); + GeoServerEvent event = busEvent.getEvent(); assertNotNull(event); assertNotNull(((InfoEvent) event).getObjectId()); // assertNotNull(event.getTarget()); @@ -341,8 +341,7 @@ protected void assertRemoteEvent(T info, RemoteGeoServerEvent b } assertThat(infoType.isInstance(info)).isTrue(); - if (event instanceof InfoAdded) { - InfoAdded e = (InfoAdded) event; + if (event instanceof InfoAdded e) { assertThat(e.getObject()).isNotNull(); assertThat(infoType.isInstance(e.getObject())).isTrue(); assertThat(e.getObject().getId()).isEqualTo(info.getId()); @@ -353,8 +352,7 @@ protected void assertRemoteEvent(T info, RemoteGeoServerEvent b // testData.assertEqualsLenientConnectionParameters(info, object); } - if (event instanceof InfoModified) { - InfoModified modifyEvent = (InfoModified) event; + if (event instanceof InfoModified modifyEvent) { assertThat(modifyEvent.getPatch()).isNotNull(); } } diff --git a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/BusEventCollector.java b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/BusEventCollector.java index d32a8955b..832b7cc5f 100644 --- a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/BusEventCollector.java +++ b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/BusEventCollector.java @@ -25,7 +25,6 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import java.util.function.Predicate; -import java.util.stream.Collectors; import java.util.stream.Stream; @Configuration @@ -48,7 +47,7 @@ public void onApplicationEvent(RemoteGeoServerEvent busEvent) { log.debug("{}: capturing is off, ignoring {}", busId, busEvent); return; } - GeoServerEvent payloadEvent = busEvent.getEvent(); + GeoServerEvent payloadEvent = busEvent.getEvent(); if (!eventType.isInstance(payloadEvent)) { log.debug( "{}: ignoring non {} event {}", busId, eventType.getSimpleName(), payloadEvent); @@ -114,7 +113,7 @@ public RemoteGeoServerEvent expectOne( @SuppressWarnings("rawtypes") public List allOf(Class payloadType) { - return capturedEvents(payloadType).collect(Collectors.toList()); + return capturedEvents(payloadType).toList(); } @SuppressWarnings("rawtypes") diff --git a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/CatalogRemoteApplicationEventsIT.java b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/CatalogRemoteApplicationEventsIT.java index 0a8e62fca..2f0fd5953 100644 --- a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/CatalogRemoteApplicationEventsIT.java +++ b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/CatalogRemoteApplicationEventsIT.java @@ -54,9 +54,10 @@ import java.util.function.Predicate; import java.util.stream.IntStream; -public class CatalogRemoteApplicationEventsIT extends BusAmqpIntegrationTests { +class CatalogRemoteApplicationEventsIT extends BusAmqpIntegrationTests { - public @Test void testCatalogSetDefaultWorkspace() { + @Test + void testCatalogSetDefaultWorkspace() { catalog.add(testData.workspaceA); catalog.add(testData.workspaceC); final Class eventType = DefaultWorkspaceSet.class; @@ -85,7 +86,8 @@ public class CatalogRemoteApplicationEventsIT extends BusAmqpIntegrationTests { } } - public @Test void testCatalogSetDefaultNamespace() { + @Test + void testCatalogSetDefaultNamespace() { catalog.add(testData.namespaceA); catalog.add(testData.namespaceB); @@ -116,7 +118,8 @@ public class CatalogRemoteApplicationEventsIT extends BusAmqpIntegrationTests { } } - public @Test void testCatalogSetDefaultDataStoreByWorkspace() { + @Test + void testCatalogSetDefaultDataStoreByWorkspace() { WorkspaceInfo workspace = testData.workspaceA; DataStoreInfo dataStore = testData.dataStoreA; @@ -157,27 +160,32 @@ public class CatalogRemoteApplicationEventsIT extends BusAmqpIntegrationTests { } } - public @Test void testAdd_Workspace() { + @Test + void testAdd_Workspace() { testRemoteCatalogInfoAddEvent(testData.workspaceA, catalog::add); } - public @Test void testAdd_Namespace() { + @Test + void testAdd_Namespace() { testRemoteCatalogInfoAddEvent(testData.namespaceA, catalog::add); } - public @Test void testAdd_CoverageStore() { + @Test + void testAdd_CoverageStore() { catalog.add(testData.workspaceA); catalog.add(testData.namespaceA); testRemoteCatalogInfoAddEvent(testData.coverageStoreA, catalog::add); } - public @Test void testAdd_DataStore() { + @Test + void testAdd_DataStore() { catalog.add(testData.workspaceA); catalog.add(testData.namespaceA); testRemoteCatalogInfoAddEvent(testData.dataStoreA, catalog::add); } - public @Test void testAdd_Coverage() { + @Test + void testAdd_Coverage() { catalog.add(testData.workspaceA); catalog.add(testData.namespaceA); catalog.add(testData.namespaceB); @@ -185,14 +193,16 @@ public class CatalogRemoteApplicationEventsIT extends BusAmqpIntegrationTests { testRemoteCatalogInfoAddEvent(testData.coverageA, catalog::add); } - public @Test void testAdd_FeatureType() { + @Test + void testAdd_FeatureType() { catalog.add(testData.workspaceA); catalog.add(testData.namespaceA); catalog.add(testData.dataStoreA); testRemoteCatalogInfoAddEvent(testData.featureTypeA, catalog::add); } - public @Test void testAdd_Layer() { + @Test + void testAdd_Layer() { catalog.add(testData.workspaceA); catalog.add(testData.namespaceA); catalog.add(testData.dataStoreA); @@ -201,7 +211,8 @@ public class CatalogRemoteApplicationEventsIT extends BusAmqpIntegrationTests { testRemoteCatalogInfoAddEvent(testData.layerFeatureTypeA, catalog::add); } - public @Test void testAdd_LayerGroup() { + @Test + void testAdd_LayerGroup() { catalog.add(testData.workspaceA); catalog.add(testData.namespaceA); catalog.add(testData.dataStoreA); @@ -211,11 +222,13 @@ public class CatalogRemoteApplicationEventsIT extends BusAmqpIntegrationTests { testRemoteCatalogInfoAddEvent(testData.layerGroup1, catalog::add); } - public @Test void testAdd_Style_Payload() { + @Test + void testAdd_Style_Payload() { testRemoteCatalogInfoAddEvent(testData.style1, catalog::add); } - public @Test void testModifyEventsWorkspace() { + @Test + void testModifyEventsWorkspace() { setupClean(); testCatalogInfoModifyEvent( testData.workspaceA, @@ -225,7 +238,8 @@ public class CatalogRemoteApplicationEventsIT extends BusAmqpIntegrationTests { catalog::save); } - public @Test void testModifyEventsNamespace() { + @Test + void testModifyEventsNamespace() { setupClean(); testCatalogInfoModifyEvent( testData.namespaceA, @@ -236,7 +250,8 @@ public class CatalogRemoteApplicationEventsIT extends BusAmqpIntegrationTests { catalog::save); } - public @Test void testModifyEventsDataStore() { + @Test + void testModifyEventsDataStore() { setupClean(); testCatalogInfoModifyEvent( testData.dataStoreA, @@ -249,7 +264,8 @@ public class CatalogRemoteApplicationEventsIT extends BusAmqpIntegrationTests { catalog::save); } - public @Test void testModifyEventsCoverageStore() { + @Test + void testModifyEventsCoverageStore() { setupClean(); testCatalogInfoModifyEvent( testData.coverageStoreA, @@ -262,7 +278,8 @@ public class CatalogRemoteApplicationEventsIT extends BusAmqpIntegrationTests { catalog::save); } - public @Test void tesAddCoverageStore_COG() { + @Test + void tesAddCoverageStore_COG() { CoverageStoreInfo store = createCOGStoreInfo(); RemoteGeoServerEvent remoteEvent = testRemoteCatalogInfoAddEvent(store, catalog::add); @@ -298,7 +315,8 @@ private CoverageStoreInfo createCOGStoreInfo() { return store; } - public @Test void testModifyEventsCoverageStore_COG() { + @Test + void testModifyEventsCoverageStore_COG() { setupClean(); CoverageStoreInfo store = testData.coverageStoreA; @@ -324,7 +342,8 @@ private CoverageStoreInfo createCOGStoreInfo() { assertThat(settings.getRangeReaderSettings()).isEqualTo(RangeReaderType.S3); } - public @Test void testModifyEventsWMSStore() { + @Test + void testModifyEventsWMSStore() { setupClean(); testCatalogInfoModifyEvent( testData.wmsStoreA, @@ -339,7 +358,8 @@ private CoverageStoreInfo createCOGStoreInfo() { catalog::save); } - public @Test void testModifyEventsWMTSStore() { + @Test + void testModifyEventsWMTSStore() { setupClean(); testCatalogInfoModifyEvent( testData.wmsStoreA, @@ -354,7 +374,8 @@ private CoverageStoreInfo createCOGStoreInfo() { catalog::save); } - public @Test void testModifyEventsFeatureType() throws SchemaException { + @Test + void testModifyEventsFeatureType() throws SchemaException { setupClean(); SimpleFeatureType type = DataUtilities.createType("test", "name:String,location:Point"); @@ -394,11 +415,13 @@ private CoverageStoreInfo createCOGStoreInfo() { } @Disabled("implement") - public @Test void testModifyEventsCoverage() { + @Test + void testModifyEventsCoverage() { fail("NOT IMPLEMENTED"); } - public @Test void testModifyEventsWMSLayer() throws Exception { + @Test + void testModifyEventsWMSLayer() throws Exception { setupClean(); WMSLayerInfo layer = testData.wmsLayerA; @@ -421,7 +444,8 @@ private CoverageStoreInfo createCOGStoreInfo() { catalog::save); } - public @Test void testModifyEventsWMTSLayer() throws Exception { + @Test + void testModifyEventsWMTSLayer() throws Exception { setupClean(); WMTSLayerInfo layer = testData.wmtsLayerA; @@ -444,7 +468,8 @@ private CoverageStoreInfo createCOGStoreInfo() { catalog::save); } - public @Test void testModifyEventsLayer() { + @Test + void testModifyEventsLayer() { setupClean(); LayerInfo layer = testData.layerFeatureTypeA; @@ -469,16 +494,19 @@ private CoverageStoreInfo createCOGStoreInfo() { } @Disabled("implement") - public @Test void testModifyEventsLayerGroup() { + @Test + void testModifyEventsLayerGroup() { fail("NOT IMPLEMENTED"); } @Disabled("implement") - public @Test void testModifyEventsStyle() { + @Test + void testModifyEventsStyle() { fail("NOT IMPLEMENTED"); } - public @Test void testRemoveEvents() { + @Test + void testRemoveEvents() { setupClean(); Class eventType = CatalogInfoRemoved.class; diff --git a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/ConfigRemoteApplicationEventsIT.java b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/ConfigRemoteApplicationEventsIT.java index b7d5a49fa..8cc59424d 100644 --- a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/ConfigRemoteApplicationEventsIT.java +++ b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/ConfigRemoteApplicationEventsIT.java @@ -38,7 +38,7 @@ import java.util.Locale; import java.util.Map; -public class ConfigRemoteApplicationEventsIT extends BusAmqpIntegrationTests { +class ConfigRemoteApplicationEventsIT extends BusAmqpIntegrationTests { @BeforeEach public void before() { @@ -46,27 +46,31 @@ public void before() { super.setupClean(); } - public @Test void testConfigAddEvent_ServiceInfo() { + @Test + void testConfigAddEvent_ServiceInfo() { WMSInfoImpl service = new WMSInfoImpl(); service.setName("WMS"); testRemoteAddEvent(service, geoserver::add, ServiceAdded.class); } - public @Test void testConfigAddEvent_WPSInfo() { + @Test + void testConfigAddEvent_WPSInfo() { WPSInfoImpl service = new WPSInfoImpl(); service.setName("WPS"); service.setTitle("My WPS"); testRemoteAddEvent(service, geoserver::add, ServiceAdded.class); } - public @Test void testConfigAddEvent_ServiceInfo_Workspace() { + @Test + void testConfigAddEvent_ServiceInfo_Workspace() { WMSInfoImpl workspaceService = new WMSInfoImpl(); workspaceService.setName("WMS"); workspaceService.setWorkspace(testData.workspaceB); testRemoteAddEvent(workspaceService, geoserver::add, ServiceAdded.class); } - public @Test void testConfigRemoteModifyEvent_ServiceInfo_Workspace() { + @Test + void testConfigRemoteModifyEvent_ServiceInfo_Workspace() { WMSInfo service = testData.faker().serviceInfo("WMS_WS_TEST", WMSInfoImpl::new); service.setWorkspace(testData.workspaceB); geoserver.add(service); @@ -83,7 +87,8 @@ public void before() { ServiceModified.class); } - public @Test void testConfigRemoteModifyEvent_WPSInfo() { + @Test + void testConfigRemoteModifyEvent_WPSInfo() { WPSInfo service = testData.faker().serviceInfo("WPS_WS_TEST", WPSInfoImpl::new); service.setWorkspace(testData.workspaceB); geoserver.add(service); @@ -97,7 +102,8 @@ public void before() { ServiceModified.class); } - public @Test void testConfigAddEvent_SettingsInfo() { + @Test + void testConfigAddEvent_SettingsInfo() { catalog.add(testData.workspaceB); SettingsInfoImpl workspaceSettings = new SettingsInfoImpl(); @@ -105,7 +111,8 @@ public void before() { testRemoteAddEvent(workspaceSettings, geoserver::add, SettingsAdded.class); } - public @Test void testConfigRemoteModifyEvents_GeoServerInfo() { + @Test + void testConfigRemoteModifyEvents_GeoServerInfo() { GeoServerInfo global = geoserver.getGlobal(); assertNotNull(global); @@ -136,7 +143,8 @@ public void before() { assertThat(settings.getContact().getAddressCity()).isEqualTo("Buenos Aires"); } - public @Test void testConfigRemotetModifyEvents_GloabalSettingsInfo() { + @Test + void testConfigRemotetModifyEvents_GloabalSettingsInfo() { testData.initConfig(true).initConfig(); // odd API weirdness here, can't modify global settings through // GeoServer.save(SettingsInfo), @@ -167,7 +175,8 @@ public void before() { assertThat(newSettings.getContact().getAddressCity()).isEqualTo("Rosario"); } - public @Test void testConfigRemotetModifyEvents_SettingsInfo() { + @Test + void testConfigRemotetModifyEvents_SettingsInfo() { SettingsInfo workspaceSettings = new SettingsInfoImpl(); WorkspaceInfo workspace = testData.workspaceC; workspaceSettings.setWorkspace(workspace); @@ -183,7 +192,8 @@ public void before() { geoserver::save); } - public @Test void testConfigRemoteModifyEvents_LoggingInfo() { + @Test + void testConfigRemoteModifyEvents_LoggingInfo() { catalog.add(testData.workspaceA); catalog.add(testData.workspaceB); @@ -198,7 +208,8 @@ public void before() { geoserver::save); } - public @Test void testConfigRemoteRemoveEvent_SettingsInfo() { + @Test + void testConfigRemoteRemoveEvent_SettingsInfo() { SettingsInfo settings = new SettingsInfoImpl(); settings.setWorkspace(testData.workspaceC); geoserver.add(settings); @@ -208,7 +219,8 @@ public void before() { assertEquals(testData.workspaceC.getId(), event.getWorkspaceId()); } - public @Test void testConfigRemoveEvent_ServiceInfo() { + @Test + void testConfigRemoveEvent_ServiceInfo() { ServiceInfo service = new WMSInfoImpl(); geoserver.add(service); @@ -218,7 +230,8 @@ public void before() { assertThat(event.getWorkspaceId()).isNull(); } - public @Test void testConfigRemoveEvent_ServiceInfo_Workspace() { + @Test + void testConfigRemoveEvent_ServiceInfo_Workspace() { ServiceInfo service = new WMSInfoImpl(); service.setName("WMS"); service.setWorkspace(testData.workspaceC); @@ -231,7 +244,8 @@ public void before() { assertThat(event.getWorkspaceId()).isEqualTo(testData.workspaceC.getId()); } - public @Test void testGeoServerInfoMetadatamapWithCogSettings() { + @Test + void testGeoServerInfoMetadatamapWithCogSettings() { GeoServerInfo global = geoserver.getGlobal(); assertNotNull(global); diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/autoconfigure/catalog/event/UpdateSequenceController.java b/src/catalog/events/src/main/java/org/geoserver/cloud/autoconfigure/catalog/event/UpdateSequenceController.java index b1d8f1b33..c90d907cb 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/autoconfigure/catalog/event/UpdateSequenceController.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/autoconfigure/catalog/event/UpdateSequenceController.java @@ -54,7 +54,6 @@ public UpdateSeq nextVal() { } protected long observed() { - long observed = geoServer.getGlobal().getUpdateSequence(); - return observed; + return geoServer.getGlobal().getUpdateSequence(); } } diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/config/catalog/events/CatalogApplicationEventPublisher.java b/src/catalog/events/src/main/java/org/geoserver/cloud/config/catalog/events/CatalogApplicationEventPublisher.java index f6a6bfd6f..9972200ce 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/config/catalog/events/CatalogApplicationEventPublisher.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/config/catalog/events/CatalogApplicationEventPublisher.java @@ -65,7 +65,7 @@ @RequiredArgsConstructor class CatalogApplicationEventPublisher { - private final @NonNull Consumer> eventPublisher; + private final @NonNull Consumer> eventPublisher; private final @NonNull Catalog catalog; private final @NonNull GeoServer geoServer; private final @NonNull Supplier updateSequenceIncrementor; @@ -81,7 +81,7 @@ class CatalogApplicationEventPublisher { geoServer.addListener(publishingConfigListener); } - void publish(@NonNull InfoEvent event) { + void publish(@NonNull InfoEvent event) { eventPublisher.accept(event); } @@ -104,7 +104,7 @@ public static class LocalCatalogEventPublisher implements CatalogListener { * @throws CatalogException meaning the operation that generated the event should be * reverted (as handled by Catalog.event()) */ - private void publish(InfoEvent event) throws CatalogException { + private void publish(InfoEvent event) throws CatalogException { try { publisher.publish(event); } catch (RuntimeException e) { @@ -112,20 +112,23 @@ private void publish(InfoEvent event) throws CatalogException { } } - public @Override void handleAddEvent(CatalogAddEvent event) throws CatalogException { + @Override + public void handleAddEvent(CatalogAddEvent event) throws CatalogException { publish(CatalogInfoAdded.createLocal(incrementSequence(), event)); } - public @Override void handleRemoveEvent(CatalogRemoveEvent event) throws CatalogException { + @Override + public void handleRemoveEvent(CatalogRemoveEvent event) throws CatalogException { publish(CatalogInfoRemoved.createLocal(incrementSequence(), event.getSource())); } - public @Override void handleModifyEvent(CatalogModifyEvent event) throws CatalogException { + @Override + public void handleModifyEvent(CatalogModifyEvent event) throws CatalogException { // no-op } - public @Override void handlePostModifyEvent(CatalogPostModifyEvent event) - throws CatalogException { + @Override + public void handlePostModifyEvent(CatalogPostModifyEvent event) throws CatalogException { publish(CatalogInfoModified.createLocal(incrementSequence(), event)); } @@ -134,7 +137,8 @@ private void publish(InfoEvent event) throws CatalogException { * *

no-op. */ - public @Override void reloaded() {} + @Override + public void reloaded() {} } @RequiredArgsConstructor @@ -176,13 +180,12 @@ private void push(String objectId, Patch patch) { return patch; } - private void publish(InfoEvent event) { + private void publish(InfoEvent event) { publisher.publish(event); } private void preparePreModify( @NonNull String id, - Info info, List propertyNames, List oldValues, List newValues) { @@ -197,20 +200,22 @@ private void publishPostModify(@NonNull String id, @NonNull Info info) { publish(ConfigInfoModified.createLocal(incrementSequence(), info, patch)); } - public @Override void handleGlobalChange( + @Override + public void handleGlobalChange( GeoServerInfo global, List propertyNames, List oldValues, List newValues) { String id = InfoEvent.resolveId(global); - preparePreModify(id, global, propertyNames, oldValues, newValues); + preparePreModify(id, propertyNames, oldValues, newValues); } /** * Note: GeoServerImpl sends a post-modify event on setGlobal(), but no pre-event nor * add-event exists */ - public @Override void handlePostGlobalChange(GeoServerInfo global) { + @Override + public void handlePostGlobalChange(GeoServerInfo global) { final String id = InfoEvent.resolveId(global); final Patch patch = pop(id); if (patch == null) { @@ -219,17 +224,19 @@ private void publishPostModify(@NonNull String id, @NonNull Info info) { publish(ConfigInfoAdded.createLocal(incrementSequence(), global)); } else { // already called pop() - ConfigInfoModified event = + ConfigInfoModified event = ConfigInfoModified.createLocal(incrementSequence(), global, patch); publish(event); } } - public @Override void handleSettingsAdded(SettingsInfo settings) { + @Override + public void handleSettingsAdded(SettingsInfo settings) { publish(ConfigInfoAdded.createLocal(incrementSequence(), settings)); } - public @Override void handleSettingsModified( + @Override + public void handleSettingsModified( SettingsInfo settings, List propertyNames, List oldValues, @@ -239,28 +246,31 @@ private void publishPostModify(@NonNull String id, @NonNull Info info) { OwsUtils.set(settings, "id", UUID.randomUUID().toString()); } - preparePreModify(settings.getId(), settings, propertyNames, oldValues, newValues); + preparePreModify(settings.getId(), propertyNames, oldValues, newValues); } - public @Override void handleSettingsPostModified(SettingsInfo settings) { + @Override + public void handleSettingsPostModified(SettingsInfo settings) { publishPostModify(settings.getId(), settings); } - public @Override void handleSettingsRemoved(SettingsInfo settings) { + @Override + public void handleSettingsRemoved(SettingsInfo settings) { publish(ConfigInfoRemoved.createLocal(incrementSequence(), settings)); } - public @Override void handleLoggingChange( + @Override + public void handleLoggingChange( LoggingInfo logging, List propertyNames, List oldValues, List newValues) { // LoggingInfo has no-id - preparePreModify( - InfoEvent.resolveId(logging), logging, propertyNames, oldValues, newValues); + preparePreModify(InfoEvent.resolveId(logging), propertyNames, oldValues, newValues); } - public @Override void handlePostLoggingChange(LoggingInfo logging) { + @Override + public void handlePostLoggingChange(LoggingInfo logging) { // LoggingInfo has no-id final String id = InfoEvent.resolveId(logging); Patch patch = pop(id); @@ -273,13 +283,14 @@ private void publishPostModify(@NonNull String id, @NonNull Info info) { } } - public @Override void handleServiceChange( + @Override + public void handleServiceChange( ServiceInfo service, List propertyNames, List oldValues, List newValues) { - preparePreModify(service.getId(), service, propertyNames, oldValues, newValues); + preparePreModify(service.getId(), propertyNames, oldValues, newValues); } /** @@ -288,7 +299,8 @@ private void publishPostModify(@NonNull String id, @NonNull Info info) { * in {@link ConfigurationListener}. This method will identify that situation and fire a * {@link ConfigInfoAdded} instead of a {@link ConfigInfoModified}. */ - public @Override void handlePostServiceChange(ServiceInfo service) { + @Override + public void handlePostServiceChange(ServiceInfo service) { Patch patch = pop(service.getId()); if (patch == null) { // means there was no handleServiceChange() call and this is an add instead, shame's @@ -300,7 +312,8 @@ private void publishPostModify(@NonNull String id, @NonNull Info info) { } } - public @Override void handleServiceRemove(ServiceInfo service) { + @Override + public void handleServiceRemove(ServiceInfo service) { publish(ConfigInfoRemoved.createLocal(incrementSequence(), service)); } } diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/config/catalog/events/CatalogApplicationEventsConfiguration.java b/src/catalog/events/src/main/java/org/geoserver/cloud/config/catalog/events/CatalogApplicationEventsConfiguration.java index 995f03a04..cfba6f5c6 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/config/catalog/events/CatalogApplicationEventsConfiguration.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/config/catalog/events/CatalogApplicationEventsConfiguration.java @@ -5,6 +5,7 @@ package org.geoserver.cloud.config.catalog.events; import org.geoserver.catalog.Catalog; +import org.geoserver.catalog.Info; import org.geoserver.cloud.event.info.InfoEvent; import org.geoserver.config.GeoServer; import org.geoserver.platform.config.UpdateSequence; @@ -27,7 +28,7 @@ CatalogApplicationEventPublisher localApplicationEventPublisher( // UpdateSequence updateSequence // ) { - Consumer> publisher = localContextPublisher::publishEvent; + Consumer> publisher = localContextPublisher::publishEvent; Supplier updateSequenceIncrementor = updateSequence::nextValue; return new CatalogApplicationEventPublisher( publisher, catalog, geoServer, updateSequenceIncrementor); diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/GeoServerEvent.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/GeoServerEvent.java index 8d3c41410..fa7209a5a 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/GeoServerEvent.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/GeoServerEvent.java @@ -19,11 +19,13 @@ import org.geoserver.config.LoggingInfo; import org.springframework.core.style.ToStringCreator; +import java.io.Serializable; import java.util.Optional; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonSubTypes({@JsonSubTypes.Type(value = UpdateSequenceEvent.class)}) -public abstract class GeoServerEvent { +@SuppressWarnings("serial") +public abstract class GeoServerEvent implements Serializable { @JsonIgnore private @Setter boolean remote; @@ -44,24 +46,25 @@ protected GeoServerEvent(long timestamp, String author) { } @SuppressWarnings("unchecked") - public Optional local() { - return Optional.ofNullable(isLocal() ? (SELF) this : null); + public Optional local() { + return Optional.ofNullable(isLocal() ? (T) this : null); } @SuppressWarnings("unchecked") - public Optional remote() { - return Optional.ofNullable(isRemote() ? (SELF) this : null); + public Optional remote() { + return Optional.ofNullable(isRemote() ? (T) this : null); } public boolean isLocal() { - return !isRemote(); // source != null; + return !isRemote(); } public boolean isRemote() { return remote; } - public @Override String toString() { + @Override + public String toString() { return toStringBuilder().toString(); } diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/UpdateSequenceEvent.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/UpdateSequenceEvent.java index 4c0961f45..e645ca9d3 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/UpdateSequenceEvent.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/UpdateSequenceEvent.java @@ -23,7 +23,8 @@ @JsonSubTypes.Type(value = SecurityConfigChanged.class) }) @JsonTypeName("UpdateSequence") -public class UpdateSequenceEvent extends GeoServerEvent { +@SuppressWarnings("serial") +public class UpdateSequenceEvent extends GeoServerEvent { /** * The provided {@link GeoServerInfo}'s {@link GeoServerInfo#getUpdateSequence() update * sequence}. Being the most frequently updated property, it's readily available for remote @@ -47,8 +48,7 @@ private static String resolveAuthor() { return null == authentication ? null : authentication.getName(); } - @SuppressWarnings("rawtypes") - public static UpdateSequenceEvent createLocal(long value) { - return new UpdateSequenceEvent<>(value); + public static UpdateSequenceEvent createLocal(long value) { + return new UpdateSequenceEvent(value); } } diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/CatalogInfoAdded.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/CatalogInfoAdded.java index 26ae8d6a6..9d62645f0 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/CatalogInfoAdded.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/CatalogInfoAdded.java @@ -13,9 +13,12 @@ import org.geoserver.catalog.event.CatalogAddEvent; import org.geoserver.cloud.event.info.InfoAdded; +import java.util.Optional; + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName("CatalogInfoAdded") -public class CatalogInfoAdded extends InfoAdded { +@SuppressWarnings("serial") +public class CatalogInfoAdded extends InfoAdded { protected CatalogInfoAdded() {} @@ -23,6 +26,12 @@ protected CatalogInfoAdded() {} super(updateSequence, object); } + @Override + @SuppressWarnings("unchecked") + public Optional remote() { + return super.remote(); + } + public static CatalogInfoAdded createLocal( long updateSequence, @NonNull CatalogAddEvent event) { return new CatalogInfoAdded(updateSequence, event.getSource()); diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/CatalogInfoModified.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/CatalogInfoModified.java index ae73f3aac..8dfe7c0f0 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/CatalogInfoModified.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/CatalogInfoModified.java @@ -30,7 +30,8 @@ @JsonSubTypes.Type(value = DefaultWorkspaceSet.class), @JsonSubTypes.Type(value = DefaultDataStoreSet.class), }) -public class CatalogInfoModified extends InfoModified { +@SuppressWarnings("serial") +public class CatalogInfoModified extends InfoModified { protected CatalogInfoModified() {} @@ -42,6 +43,12 @@ protected CatalogInfoModified( super(updateSequence, objectId, objectType, patch); } + @Override + @SuppressWarnings("unchecked") + public Optional remote() { + return super.remote(); + } + public static CatalogInfoModified createLocal( long updateSequence, @NonNull CatalogInfo info, @NonNull Patch patch) { diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/CatalogInfoRemoved.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/CatalogInfoRemoved.java index d2c4d75f0..3b079468e 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/CatalogInfoRemoved.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/CatalogInfoRemoved.java @@ -13,9 +13,12 @@ import org.geoserver.cloud.event.info.ConfigInfoType; import org.geoserver.cloud.event.info.InfoRemoved; +import java.util.Optional; + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName("CatalogInfoRemoved") -public class CatalogInfoRemoved extends InfoRemoved { +@SuppressWarnings("serial") +public class CatalogInfoRemoved extends InfoRemoved { protected CatalogInfoRemoved() {} @@ -23,6 +26,12 @@ protected CatalogInfoRemoved() {} super(updateSequence, id, type); } + @Override + @SuppressWarnings("unchecked") + public Optional remote() { + return super.remote(); + } + public static CatalogInfoRemoved createLocal(long updateSequence, @NonNull CatalogInfo info) { String id = resolveId(info); ConfigInfoType type = ConfigInfoType.valueOf(info); diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/DefaultDataStoreSet.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/DefaultDataStoreSet.java index 56047e7fa..b640108bc 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/DefaultDataStoreSet.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/DefaultDataStoreSet.java @@ -28,6 +28,7 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName("DefaultDataStoreSet") @EqualsAndHashCode(callSuper = true) +@SuppressWarnings("serial") public class DefaultDataStoreSet extends CatalogInfoModified { private @Getter String workspaceId; diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/DefaultNamespaceSet.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/DefaultNamespaceSet.java index 847dcbd5b..771298bc3 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/DefaultNamespaceSet.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/DefaultNamespaceSet.java @@ -18,6 +18,7 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName("DefaultNamespaceSet") +@SuppressWarnings("serial") public class DefaultNamespaceSet extends CatalogInfoModified { private @Getter String newNamespaceId; diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/DefaultWorkspaceSet.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/DefaultWorkspaceSet.java index ba455d10a..62126efcf 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/DefaultWorkspaceSet.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/catalog/DefaultWorkspaceSet.java @@ -19,6 +19,7 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName("DefaultWorkspaceSet") +@SuppressWarnings("serial") public class DefaultWorkspaceSet extends CatalogInfoModified { private @Getter @Setter String newWorkspaceId; 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 85b15782e..e11ecb8d4 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 @@ -24,34 +24,35 @@ @JsonSubTypes.Type(value = ServiceAdded.class), @JsonSubTypes.Type(value = SettingsAdded.class), }) -public abstract class ConfigInfoAdded extends InfoAdded +@SuppressWarnings("serial") +public abstract class ConfigInfoAdded extends InfoAdded implements ConfigInfoEvent { protected ConfigInfoAdded() { // default constructor, needed for deserialization } - public ConfigInfoAdded(long updateSequence, INFO object) { + protected ConfigInfoAdded(long updateSequence, INFO object) { super(updateSequence, object); } @SuppressWarnings("unchecked") - public static @NonNull ConfigInfoAdded createLocal( + public static @NonNull ConfigInfoAdded createLocal( long updateSequence, @NonNull I info) { final ConfigInfoType type = ConfigInfoType.valueOf(info); switch (type) { case GeoServerInfo: - return (ConfigInfoAdded) + return (ConfigInfoAdded) GeoServerInfoSet.createLocal(updateSequence, (GeoServerInfo) info); case ServiceInfo: - return (ConfigInfoAdded) + return (ConfigInfoAdded) ServiceAdded.createLocal(updateSequence, (ServiceInfo) info); case SettingsInfo: - return (ConfigInfoAdded) + return (ConfigInfoAdded) SettingsAdded.createLocal(updateSequence, (SettingsInfo) info); case LoggingInfo: - return (ConfigInfoAdded) + return (ConfigInfoAdded) LoggingInfoSet.createLocal(updateSequence, (LoggingInfo) info); default: throw new IllegalArgumentException( 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 da9ba9c60..2f7e081ab 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 @@ -25,7 +25,8 @@ @JsonSubTypes.Type(value = ServiceModified.class), @JsonSubTypes.Type(value = SettingsModified.class), }) -public abstract class ConfigInfoModified extends InfoModified +@SuppressWarnings("serial") +public abstract class ConfigInfoModified extends InfoModified implements ConfigInfoEvent { protected ConfigInfoModified() { @@ -41,27 +42,27 @@ protected ConfigInfoModified( } @SuppressWarnings("unchecked") - public static @NonNull ConfigInfoModified createLocal( + public static @NonNull ConfigInfoModified createLocal( long updateSequence, @NonNull Info info, @NonNull Patch patch) { final ConfigInfoType type = ConfigInfoType.valueOf(info); switch (type) { case GeoServerInfo: { - return (ConfigInfoModified) + return (ConfigInfoModified) GeoServerInfoModified.createLocal( updateSequence, (GeoServerInfo) info, patch); } case ServiceInfo: ServiceInfo service = (ServiceInfo) info; - return (ConfigInfoModified) + return (ConfigInfoModified) ServiceModified.createLocal(updateSequence, service, patch); case SettingsInfo: SettingsInfo settings = (SettingsInfo) info; - return (ConfigInfoModified) + return (ConfigInfoModified) SettingsModified.createLocal(updateSequence, settings, patch); case LoggingInfo: - return (ConfigInfoModified) + return (ConfigInfoModified) LoggingInfoModified.createLocal(updateSequence, (LoggingInfo) info, patch); default: throw new IllegalArgumentException( 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 9930c2bd3..a5085e6a9 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 @@ -20,33 +20,31 @@ @JsonSubTypes.Type(value = ServiceRemoved.class, name = "ServiceInfoRemoved"), @JsonSubTypes.Type(value = SettingsRemoved.class, name = "SettingsInfoRemoved"), }) -public abstract class ConfigInfoRemoved extends InfoRemoved +@SuppressWarnings("serial") +public abstract class ConfigInfoRemoved extends InfoRemoved implements ConfigInfoEvent { protected ConfigInfoRemoved() { // default constructor, needed for deserialization } - public ConfigInfoRemoved( + protected ConfigInfoRemoved( long updateSequence, @NonNull String objectId, @NonNull ConfigInfoType type) { super(updateSequence, objectId, type); } @SuppressWarnings("unchecked") - public static @NonNull ConfigInfoRemoved createLocal( + public static @NonNull ConfigInfoRemoved createLocal( long updateSequence, @NonNull I info) { final ConfigInfoType type = ConfigInfoType.valueOf(info); - switch (type) { - case ServiceInfo: - return (ConfigInfoRemoved) - ServiceRemoved.createLocal(updateSequence, (ServiceInfo) info); - case SettingsInfo: - return (ConfigInfoRemoved) - SettingsRemoved.createLocal(updateSequence, (SettingsInfo) info); - default: - throw new IllegalArgumentException( - "Uknown or unsupported config Info type: " + type + ". " + 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); + }; } } diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/GeoServerInfoModified.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/GeoServerInfoModified.java index 7daac73cc..db9bd1136 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/GeoServerInfoModified.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/GeoServerInfoModified.java @@ -17,7 +17,8 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName("GeoServerInfoModified") @EqualsAndHashCode(callSuper = true) -public class GeoServerInfoModified extends ConfigInfoModified +@SuppressWarnings("serial") +public class GeoServerInfoModified extends ConfigInfoModified implements ConfigInfoEvent { protected GeoServerInfoModified() { diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/GeoServerInfoSet.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/GeoServerInfoSet.java index b83dc3927..c4328e0e7 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/GeoServerInfoSet.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/GeoServerInfoSet.java @@ -13,8 +13,8 @@ /** Event sent when {@link GeoServer#setGlobal(GeoServerInfo)} is called */ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName("GeoServerInfoSet") -public class GeoServerInfoSet extends ConfigInfoAdded - implements ConfigInfoEvent { +@SuppressWarnings("serial") +public class GeoServerInfoSet extends ConfigInfoAdded implements ConfigInfoEvent { protected GeoServerInfoSet() { // default constructor, needed for deserialization diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/LoggingInfoModified.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/LoggingInfoModified.java index 20ffc547a..b980e9d78 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/LoggingInfoModified.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/LoggingInfoModified.java @@ -17,7 +17,8 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName("LoggingInfoModified") @EqualsAndHashCode(callSuper = true) -public class LoggingInfoModified extends ConfigInfoModified +@SuppressWarnings("serial") +public class LoggingInfoModified extends ConfigInfoModified implements ConfigInfoEvent { protected LoggingInfoModified() { diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/LoggingInfoSet.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/LoggingInfoSet.java index a020e9bc9..bb5a01429 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/LoggingInfoSet.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/LoggingInfoSet.java @@ -13,8 +13,8 @@ /** Event sent when {@link GeoServer#setLogging(LoggingInfo)} is called on a node */ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName("LoggingInfoSet") -public class LoggingInfoSet extends ConfigInfoAdded - implements ConfigInfoEvent { +@SuppressWarnings("serial") +public class LoggingInfoSet extends ConfigInfoAdded implements ConfigInfoEvent { protected LoggingInfoSet() { // default constructor, needed for deserialization diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ServiceAdded.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ServiceAdded.java index f812e53a2..cc0be30cf 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ServiceAdded.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ServiceAdded.java @@ -16,8 +16,8 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName("ServiceAdded") @EqualsAndHashCode(callSuper = true) -public class ServiceAdded extends ConfigInfoAdded - implements ConfigInfoEvent { +@SuppressWarnings("serial") +public class ServiceAdded extends ConfigInfoAdded implements ConfigInfoEvent { protected ServiceAdded() { // default constructor, needed for deserialization diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ServiceModified.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ServiceModified.java index b74e49c80..70444d221 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ServiceModified.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ServiceModified.java @@ -21,8 +21,8 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName("ServiceModified") @EqualsAndHashCode(callSuper = true) -public class ServiceModified extends ConfigInfoModified - implements ConfigInfoEvent { +@SuppressWarnings("serial") +public class ServiceModified extends ConfigInfoModified implements ConfigInfoEvent { private @Getter String workspaceId; diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ServiceRemoved.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ServiceRemoved.java index 749414144..1a6d9600c 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ServiceRemoved.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/ServiceRemoved.java @@ -17,7 +17,8 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName("ServiceInfoRemoved") @EqualsAndHashCode(callSuper = true) -public class ServiceRemoved extends ConfigInfoRemoved { +@SuppressWarnings("serial") +public class ServiceRemoved extends ConfigInfoRemoved { private @Getter String workspaceId; diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/SettingsAdded.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/SettingsAdded.java index 8b51dd3bb..f5c306a6d 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/SettingsAdded.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/SettingsAdded.java @@ -19,8 +19,8 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName("SettingsAdded") @EqualsAndHashCode(callSuper = true) -public class SettingsAdded extends ConfigInfoAdded - implements ConfigInfoEvent { +@SuppressWarnings("serial") +public class SettingsAdded extends ConfigInfoAdded implements ConfigInfoEvent { protected SettingsAdded() { // default constructor, needed for deserialization diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/SettingsModified.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/SettingsModified.java index 39cdb44df..60cac5d03 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/SettingsModified.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/SettingsModified.java @@ -20,8 +20,8 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName("SettingsModified") @EqualsAndHashCode(callSuper = true) -public class SettingsModified extends ConfigInfoModified - implements ConfigInfoEvent { +@SuppressWarnings("serial") +public class SettingsModified extends ConfigInfoModified implements ConfigInfoEvent { private @Getter String workspaceId; diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/SettingsRemoved.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/SettingsRemoved.java index 4d58f9ec6..d8f2263ca 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/SettingsRemoved.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/config/SettingsRemoved.java @@ -15,7 +15,8 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName("SettingsInfoRemoved") -public class SettingsRemoved extends ConfigInfoRemoved { +@SuppressWarnings("serial") +public class SettingsRemoved extends ConfigInfoRemoved { private @Getter String workspaceId; diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/info/InfoAdded.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/info/InfoAdded.java index 0217f8a7f..19bc0c6b3 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/info/InfoAdded.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/info/InfoAdded.java @@ -20,7 +20,8 @@ @JsonSubTypes.Type(value = CatalogInfoAdded.class), @JsonSubTypes.Type(value = ConfigInfoAdded.class), }) -public abstract class InfoAdded extends InfoEvent { +@SuppressWarnings("serial") +public abstract class InfoAdded extends InfoEvent { private @Getter @Setter I object; diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/info/InfoEvent.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/info/InfoEvent.java index da0851fa6..b7a126d24 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/info/InfoEvent.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/info/InfoEvent.java @@ -23,7 +23,8 @@ @JsonSubTypes.Type(value = InfoModified.class), @JsonSubTypes.Type(value = InfoRemoved.class) }) -public abstract class InfoEvent extends UpdateSequenceEvent { +@SuppressWarnings("serial") +public abstract class InfoEvent extends UpdateSequenceEvent { private @Getter String objectId; @@ -34,7 +35,6 @@ protected InfoEvent() {} protected InfoEvent( long updateSequence, @NonNull String objectId, @NonNull ConfigInfoType objectType) { super(updateSequence); - // this.source = source; this.objectId = objectId; this.objectType = objectType; } diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/info/InfoModified.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/info/InfoModified.java index 5b573d641..8f998c903 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/info/InfoModified.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/info/InfoModified.java @@ -24,7 +24,8 @@ @JsonSubTypes.Type(value = CatalogInfoModified.class), @JsonSubTypes.Type(value = ConfigInfoModified.class), }) -public abstract class InfoModified extends InfoEvent { +@SuppressWarnings("serial") +public abstract class InfoModified extends InfoEvent { private @Getter @Setter Patch patch; diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/info/InfoRemoved.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/info/InfoRemoved.java index f8e922316..df7281bc5 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/info/InfoRemoved.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/info/InfoRemoved.java @@ -18,7 +18,8 @@ @JsonSubTypes.Type(value = CatalogInfoRemoved.class, name = "CatalogInfoRemoved"), @JsonSubTypes.Type(value = ConfigInfoRemoved.class, name = "ConfigInfoRemoved"), }) -public abstract class InfoRemoved extends InfoEvent { +@SuppressWarnings("serial") +public abstract class InfoRemoved extends InfoEvent { protected InfoRemoved() {} diff --git a/src/catalog/events/src/main/java/org/geoserver/cloud/event/security/SecurityConfigChanged.java b/src/catalog/events/src/main/java/org/geoserver/cloud/event/security/SecurityConfigChanged.java index 3b184c8a8..bbc504883 100644 --- a/src/catalog/events/src/main/java/org/geoserver/cloud/event/security/SecurityConfigChanged.java +++ b/src/catalog/events/src/main/java/org/geoserver/cloud/event/security/SecurityConfigChanged.java @@ -20,7 +20,8 @@ */ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName("SecurityConfigChanged") -public class SecurityConfigChanged extends UpdateSequenceEvent { +@SuppressWarnings("serial") +public class SecurityConfigChanged extends UpdateSequenceEvent { private @Getter String reason; diff --git a/src/catalog/events/src/test/java/org/geoserver/cloud/config/catalog/events/CatalogApplicationEventsConfigurationTest.java b/src/catalog/events/src/test/java/org/geoserver/cloud/config/catalog/events/CatalogApplicationEventsConfigurationTest.java index d272914ba..c59aac578 100644 --- a/src/catalog/events/src/test/java/org/geoserver/cloud/config/catalog/events/CatalogApplicationEventsConfigurationTest.java +++ b/src/catalog/events/src/test/java/org/geoserver/cloud/config/catalog/events/CatalogApplicationEventsConfigurationTest.java @@ -61,7 +61,7 @@ ApplicationEventCapturingListener.class }) @EnableAutoConfiguration -public class CatalogApplicationEventsConfigurationTest { +class CatalogApplicationEventsConfigurationTest { private @Autowired GeoServer geoserver; private @Autowired Catalog catalog; @@ -81,7 +81,8 @@ public class CatalogApplicationEventsConfigurationTest { testData.after(); } - public @Test void testCatalogEventBroadcasterHasSetUpItself() { + @Test + void testCatalogEventBroadcasterHasSetUpItself() { Optional publiherListener = catalog.getListeners().stream() .filter( @@ -94,7 +95,8 @@ public class CatalogApplicationEventsConfigurationTest { assertTrue(publiherListener.isPresent()); } - public @Test void testConfigEventBroadcasterHasSetUpItself() { + @Test + void testConfigEventBroadcasterHasSetUpItself() { Optional publiherListener = geoserver.getListeners().stream() .filter( @@ -107,7 +109,8 @@ public class CatalogApplicationEventsConfigurationTest { assertTrue(publiherListener.isPresent()); } - public @Test void testCatalogSetDefaultWorkspace() { + @Test + void testCatalogSetDefaultWorkspace() { listener.stop(); catalog.add(testData.workspaceA); catalog.add(testData.workspaceB); @@ -123,7 +126,8 @@ public class CatalogApplicationEventsConfigurationTest { testModify(catalog, "defaultWorkspace", testData.workspaceC, testData.workspaceB); } - public @Test void testCatalogSetDefaultNamespace() { + @Test + void testCatalogSetDefaultNamespace() { listener.stop(); catalog.add(testData.namespaceA); catalog.add(testData.namespaceB); @@ -139,7 +143,8 @@ public class CatalogApplicationEventsConfigurationTest { testModify(catalog, "defaultNamespace", testData.namespaceC, testData.namespaceB); } - public @Test void testCatalogAddedEvents() { + @Test + void testCatalogAddedEvents() { Class eventType = CatalogInfoAdded.class; testAddEvent(testData.workspaceA, catalog::add, eventType); testAddEvent(testData.namespaceA, catalog::add, eventType); @@ -152,7 +157,8 @@ public class CatalogApplicationEventsConfigurationTest { testAddEvent(testData.style1, catalog::add, eventType); } - public @Test void testCatalogRemoveEvents() { + @Test + void testCatalogRemoveEvents() { listener.stop(); testData.addObjects(); listener.start(); @@ -160,7 +166,8 @@ public class CatalogApplicationEventsConfigurationTest { testRemove(testData.layerGroup1, catalog::remove, CatalogInfoRemoved.class); } - public @Test void testConfigAddEvents() { + @Test + void testConfigAddEvents() { catalog.add(testData.workspaceB); assertNotNull(catalog.getWorkspace(testData.workspaceB.getId())); assertSame(catalog, geoserver.getCatalog()); @@ -182,7 +189,8 @@ public class CatalogApplicationEventsConfigurationTest { testAddEvent(workspaceSettings, geoserver::add, eventType); } - public @Test void testConfigModifyEvents_GeoServerInfo() { + @Test + void testConfigModifyEvents_GeoServerInfo() { catalog.add(testData.workspaceA); catalog.add(testData.workspaceB); geoserver.setGlobal(testData.global); @@ -207,7 +215,8 @@ public class CatalogApplicationEventsConfigurationTest { eventType); } - public @Test void testConfigPrePostModifyEvents_SettingsInfo() { + @Test + void testConfigPrePostModifyEvents_SettingsInfo() { catalog.add(testData.workspaceA); catalog.add(testData.workspaceB); geoserver.setGlobal(testData.global); @@ -244,7 +253,8 @@ public class CatalogApplicationEventsConfigurationTest { eventType); } - public @Test void testConfigModifyEvents_LoggingInfo() { + @Test + void testConfigModifyEvents_LoggingInfo() { catalog.add(testData.workspaceA); catalog.add(testData.workspaceB); geoserver.setLogging(testData.logging); @@ -263,7 +273,8 @@ public class CatalogApplicationEventsConfigurationTest { eventType); } - public @Test void testConfigPrePostModifyEvents_ServiceInfo() { + @Test + void testConfigPrePostModifyEvents_ServiceInfo() { catalog.add(testData.workspaceA); catalog.add(testData.workspaceB); @@ -301,7 +312,8 @@ private void testConfigModifyService(ServiceInfo service) { postEventType); } - public @Test void testConfigRemoveEvents() { + @Test + void testConfigRemoveEvents() { listener.stop(); ServiceInfo service = new WMSInfoImpl(); geoserver.add(service); @@ -318,7 +330,7 @@ private void testRemove( listener.start(); remover.accept(info); @SuppressWarnings("unchecked") - InfoRemoved event = listener.expectOne(eventType); + InfoRemoved event = listener.expectOne(eventType); assertEquals(info.getId(), event.getObjectId()); assertEquals(ConfigInfoType.valueOf(info), event.getObjectType()); } @@ -364,7 +376,7 @@ private void testModify( modifier.accept(info); saver.accept(info); - InfoModified post = listener.expectOne(postEventType); + InfoModified post = listener.expectOne(postEventType); assertEquals(proxy.getId(), post.getObjectId()); assertEquals(expected, post.getPatch()); } diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/CatalogInfoDeserializer.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/CatalogInfoDeserializer.java index 1beda8c9a..350d3e51b 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/CatalogInfoDeserializer.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/CatalogInfoDeserializer.java @@ -5,7 +5,6 @@ package org.geoserver.jackson.databind.catalog; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; @@ -20,11 +19,10 @@ public class CatalogInfoDeserializer extends JsonDeserial private static final CatalogInfoMapper mapper = Mappers.getMapper(CatalogInfoMapper.class); - public @Override I deserialize(JsonParser parser, DeserializationContext ctxt) - throws IOException, JsonProcessingException { + @Override + public I deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException { CatalogInfoDto dto = parser.readValueAs(CatalogInfoDto.class); - I info = mapper.map(dto); - return info; + return mapper.map(dto); } } diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/CatalogInfoSerializer.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/CatalogInfoSerializer.java index 7f7e914df..8086bc0ec 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/CatalogInfoSerializer.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/CatalogInfoSerializer.java @@ -30,14 +30,16 @@ protected CatalogInfoSerializer(Class infoType) { this.infoType = infoType; } - public @Override void serialize( - CatalogInfo info, JsonGenerator gen, SerializerProvider provider) throws IOException { + @Override + public void serialize(CatalogInfo info, JsonGenerator gen, SerializerProvider provider) + throws IOException { CatalogInfoDto dto = mapper.map(info); gen.writeObject(dto); } - public @Override void serializeWithType( + @Override + public void serializeWithType( I value, JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/GeoServerCatalogModule.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/GeoServerCatalogModule.java index ba517daa5..565953322 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/GeoServerCatalogModule.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/GeoServerCatalogModule.java @@ -98,9 +98,6 @@ public class GeoServerCatalogModule extends SimpleModule { static final PatchMapper PATCH_MAPPER = Mappers.getMapper(PatchMapper.class); static final ValueMappers VALUE_MAPPER = Mappers.getMapper(ValueMappers.class); - private final CatalogInfoDeserializer deserializer = - new CatalogInfoDeserializer<>(); - public GeoServerCatalogModule() { super(GeoServerCatalogModule.class.getSimpleName(), new Version(1, 0, 0, null, null, null)); @@ -133,10 +130,9 @@ private void addSerializer(Class clazz) { super.addSerializer(new CatalogInfoSerializer<>(clazz)); } - @SuppressWarnings("unchecked") private void addDeserializer(Class clazz) { log.trace("registering deserializer for {}", clazz.getSimpleName()); - super.addDeserializer(clazz, (CatalogInfoDeserializer) deserializer); + super.addDeserializer(clazz, new CatalogInfoDeserializer<>()); } private void addMapperSerializer( diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/VersionDeserializer.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/VersionDeserializer.java index ab0988727..4d97c558a 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/VersionDeserializer.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/VersionDeserializer.java @@ -5,7 +5,6 @@ package org.geoserver.jackson.databind.catalog; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; @@ -16,8 +15,8 @@ public class VersionDeserializer extends JsonDeserializer { - public @Override Version deserialize(JsonParser parser, DeserializationContext ctxt) - throws IOException, JsonProcessingException { + @Override + public Version deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException { VersionDto dto = parser.readValueAs(VersionDto.class); return VersionSerializer.mapper.dtoToVersion(dto); diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/VersionSerializer.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/VersionSerializer.java index 3c2bb1342..92ad9c01b 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/VersionSerializer.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/VersionSerializer.java @@ -27,7 +27,8 @@ protected VersionSerializer() { super(Version.class); } - public @Override void serializeWithType( + @Override + public void serializeWithType( Version value, JsonGenerator gen, SerializerProvider serializers, @@ -42,7 +43,8 @@ protected VersionSerializer() { typeSer.writeTypeSuffix(gen, typeIdDef); } - public @Override void serialize(Version version, JsonGenerator gen, SerializerProvider provider) + @Override + public void serialize(Version version, JsonGenerator gen, SerializerProvider provider) throws IOException { VersionDto dto = mapper.versionToDto(version); diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/CatalogInfoMapper.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/CatalogInfoMapper.java index a04d1f77c..84afb9599 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/CatalogInfoMapper.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/CatalogInfoMapper.java @@ -36,13 +36,13 @@ public interface CatalogInfoMapper { @SuppressWarnings("unchecked") default I map(CatalogInfoDto dto) { if (dto == null) return null; - if (dto instanceof Workspace) return (I) WORKSPACE_MAPPER.map((Workspace) dto); - if (dto instanceof Namespace) return (I) NAMESPACE_MAPPER.map((Namespace) dto); - if (dto instanceof Store) return (I) STORE_MAPPER.map((Store) dto); - if (dto instanceof Resource) return (I) RESOURCE_MAPPER.map((Resource) dto); - if (dto instanceof Published) return (I) PUBLISHED_MAPPER.map((Published) dto); - if (dto instanceof Style) return (I) STYLE_MAPPER.map((Style) dto); - if (dto instanceof Map) return (I) MAP_MAPPER.map((Map) dto); + if (dto instanceof Workspace ws) return (I) WORKSPACE_MAPPER.map(ws); + if (dto instanceof Namespace ns) return (I) NAMESPACE_MAPPER.map(ns); + if (dto instanceof Store store) return (I) STORE_MAPPER.map(store); + if (dto instanceof Resource res) return (I) RESOURCE_MAPPER.map(res); + if (dto instanceof Published published) return (I) PUBLISHED_MAPPER.map(published); + if (dto instanceof Style style) return (I) STYLE_MAPPER.map(style); + if (dto instanceof Map map) return (I) MAP_MAPPER.map(map); throw new IllegalArgumentException( "Unknown CatalogInfoDto type: " + dto.getClass().getCanonicalName()); @@ -50,13 +50,13 @@ default I map(CatalogInfoDto dto) { default CatalogInfoDto map(CatalogInfo info) { if (info == null) return null; - if (info instanceof WorkspaceInfo) return WORKSPACE_MAPPER.map((WorkspaceInfo) info); - if (info instanceof NamespaceInfo) return NAMESPACE_MAPPER.map((NamespaceInfo) info); - if (info instanceof StoreInfo) return STORE_MAPPER.map((StoreInfo) info); - if (info instanceof ResourceInfo) return RESOURCE_MAPPER.map((ResourceInfo) info); - if (info instanceof PublishedInfo) return PUBLISHED_MAPPER.map((PublishedInfo) info); - if (info instanceof StyleInfo) return STYLE_MAPPER.map((StyleInfo) info); - if (info instanceof MapInfo) return MAP_MAPPER.map((MapInfo) info); + if (info instanceof WorkspaceInfo ws) return WORKSPACE_MAPPER.map(ws); + if (info instanceof NamespaceInfo ns) return NAMESPACE_MAPPER.map(ns); + if (info instanceof StoreInfo store) return STORE_MAPPER.map(store); + if (info instanceof ResourceInfo res) return RESOURCE_MAPPER.map(res); + if (info instanceof PublishedInfo published) return PUBLISHED_MAPPER.map(published); + if (info instanceof StyleInfo style) return STYLE_MAPPER.map(style); + if (info instanceof MapInfo map) return MAP_MAPPER.map(map); if (info instanceof CatalogInfo) return null; throw new IllegalArgumentException( "Unknown CatalogInfo type: " + info.getClass().getCanonicalName()); diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/PublishedMapper.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/PublishedMapper.java index 37ae0ab0f..6cf0a4069 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/PublishedMapper.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/PublishedMapper.java @@ -19,8 +19,8 @@ public interface PublishedMapper { default PublishedInfo map(Published dto) { if (dto == null) return null; - if (dto instanceof Layer) return map((Layer) dto); - if (dto instanceof LayerGroup) return map((LayerGroup) dto); + if (dto instanceof Layer l) return map(l); + if (dto instanceof LayerGroup lg) return map(lg); throw new IllegalArgumentException( "Unknown Published type: " + dto.getClass().getCanonicalName()); @@ -28,8 +28,8 @@ default PublishedInfo map(Published dto) { default Published map(PublishedInfo info) { if (info == null) return null; - if (info instanceof LayerInfo) return map((LayerInfo) info); - if (info instanceof LayerGroupInfo) return map((LayerGroupInfo) info); + if (info instanceof LayerInfo l) return map(l); + if (info instanceof LayerGroupInfo lg) return map(lg); throw new IllegalArgumentException( "Unknown PublishedInfo type: " + info.getClass().getCanonicalName()); diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/ResourceMapper.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/ResourceMapper.java index fa052131e..96031e42b 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/ResourceMapper.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/ResourceMapper.java @@ -22,19 +22,19 @@ public interface ResourceMapper { default Resource map(ResourceInfo o) { if (o == null) return null; - if (o instanceof FeatureTypeInfo) return map((FeatureTypeInfo) o); - if (o instanceof CoverageInfo) return map((CoverageInfo) o); - if (o instanceof WMSLayerInfo) return map((WMSLayerInfo) o); - if (o instanceof WMTSLayerInfo) return map((WMTSLayerInfo) o); + if (o instanceof FeatureTypeInfo ft) return map(ft); + if (o instanceof CoverageInfo cov) return map(cov); + if (o instanceof WMSLayerInfo wms) return map(wms); + if (o instanceof WMTSLayerInfo wmts) return map(wmts); throw new IllegalArgumentException("Unknown ResourceInfo type: " + o); } default ResourceInfo map(Resource o) { if (o == null) return null; - if (o instanceof FeatureType) return map((FeatureType) o); - if (o instanceof Coverage) return map((Coverage) o); - if (o instanceof WMSLayer) return map((WMSLayer) o); - if (o instanceof WMTSLayer) return map((WMTSLayer) o); + if (o instanceof FeatureType ft) return map(ft); + if (o instanceof Coverage cov) return map(cov); + if (o instanceof WMSLayer wms) return map(wms); + if (o instanceof WMTSLayer wmts) return map(wmts); throw new IllegalArgumentException("Unknown Resource type: " + o); } diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/StoreMapper.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/StoreMapper.java index df07af99c..d5f2d1f8e 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/StoreMapper.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/StoreMapper.java @@ -22,20 +22,20 @@ public interface StoreMapper { default Store map(StoreInfo o) { if (o == null) return null; - if (o instanceof DataStoreInfo) return map((DataStoreInfo) o); - if (o instanceof CoverageStoreInfo) return map((CoverageStoreInfo) o); - if (o instanceof WMSStoreInfo) return map((WMSStoreInfo) o); - if (o instanceof WMTSStoreInfo) return map((WMTSStoreInfo) o); + if (o instanceof DataStoreInfo ds) return map(ds); + if (o instanceof CoverageStoreInfo cs) return map(cs); + if (o instanceof WMSStoreInfo wms) return map(wms); + if (o instanceof WMTSStoreInfo wmts) return map(wmts); throw new IllegalArgumentException("Unknown StoreInfo type: " + o); } default StoreInfo map(Store o) { if (o == null) return null; - if (o instanceof DataStore) return map((DataStore) o); - if (o instanceof CoverageStore) return map((CoverageStore) o); - if (o instanceof WMSStore) return map((WMSStore) o); - if (o instanceof WMTSStore) return map((WMTSStore) o); + if (o instanceof DataStore ds) return map(ds); + if (o instanceof CoverageStore cs) return map(cs); + if (o instanceof WMSStore wms) return map(wms); + if (o instanceof WMTSStore wmts) return map(wmts); throw new IllegalArgumentException("Unknown Store type: " + o); } diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/ValueMappers.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/ValueMappers.java index d8ec3d4e6..00613a2f8 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/ValueMappers.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/catalog/mapper/ValueMappers.java @@ -114,18 +114,18 @@ default NumberRange dtoToNumberRange(NumberRangeDto source) { Number min = source.getMin(); Number max = source.getMax(); - if (Long.class.isInstance(min) || Long.class.isInstance(max)) + if (min instanceof Long || max instanceof Long) return NumberRange.create(min.longValue(), minIncluded, max.longValue(), maxIncluded); - if (Double.class.isInstance(min) || Double.class.isInstance(max)) + if (min instanceof Double || max instanceof Double) return NumberRange.create( min.doubleValue(), minIncluded, max.doubleValue(), maxIncluded); - if (Float.class.isInstance(min) || Float.class.isInstance(max)) + if (min instanceof Float || max instanceof Float) return NumberRange.create(min.floatValue(), minIncluded, max.floatValue(), maxIncluded); - if (Integer.class.isInstance(min) || Integer.class.isInstance(max)) + if (min instanceof Integer || max instanceof Integer) return NumberRange.create(min.intValue(), minIncluded, max.intValue(), maxIncluded); - if (Short.class.isInstance(min) || Short.class.isInstance(max)) + if (min instanceof Short || max instanceof Short) return NumberRange.create(min.shortValue(), minIncluded, max.shortValue(), maxIncluded); - if (Byte.class.isInstance(min) || Byte.class.isInstance(max)) + if (min instanceof Byte || max instanceof Byte) return NumberRange.create(min.byteValue(), minIncluded, max.byteValue(), maxIncluded); return NumberRange.create(min.doubleValue(), minIncluded, max.doubleValue(), maxIncluded); @@ -135,7 +135,7 @@ default String measureToString(Measure value) { try { return measure2Str.convert(value, String.class); } catch (Exception e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -143,7 +143,7 @@ default Measure stringToMeasure(String value) { try { return str2Measure.convert(value, Measure.class); } catch (Exception e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -183,8 +183,7 @@ default GridGeometryDto gridGeometry2DToDto(GridGeometry value) { default double[] affineTransform(MathTransform tx) { double[] flatmatrix = null; - if (tx instanceof AffineTransform) { - AffineTransform atx = (AffineTransform) tx; + if (tx instanceof AffineTransform atx) { flatmatrix = new double[6]; atx.getMatrix(flatmatrix); } @@ -253,9 +252,6 @@ default VirtualTable dtoToVirtualTable(VirtualTableDto dto) { return new VirtualTable(dto.getName(), dto.getSql(), dto.isEscapeSql()); } - // there's no implementation for ImagingInfo and ImageFormatInfo, looks like dead code - // ImageFormatInfo infoToDto(); - default String localeToString(Locale locale) { return locale == null ? "" : locale.toLanguageTag(); } @@ -265,8 +261,7 @@ default Locale stringToLocale(String s) { } default Map internationalStringToDto(InternationalString s) { - if (s instanceof GrowableInternationalString) { - GrowableInternationalString gs = (GrowableInternationalString) s; + if (s instanceof GrowableInternationalString gs) { Set locales = gs.getLocales(); Map dto = new HashMap<>(locales.size()); locales.forEach(locale -> dto.put(localeToString(locale), gs.toString(locale))); @@ -279,9 +274,8 @@ default Map internationalStringToDto(InternationalString s) { LoggerFactory.getLogger(getClass()) .warn( - "Uknown InternationalString implementation: " - + s.getClass().getName() - + ". Returning null"); + "Uknown InternationalString implementation: {}. Returning null", + s.getClass().getName()); return null; } diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/ConfigInfoDeserializer.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/ConfigInfoDeserializer.java index 9517153ed..d873dc7df 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/ConfigInfoDeserializer.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/ConfigInfoDeserializer.java @@ -19,6 +19,6 @@ public class ConfigInfoDeserializer Mappers.getMapper(GeoServerConfigMapper.class); public ConfigInfoDeserializer(@NonNull Class from) { - super(from, dto -> mapper.toInfo(dto)); + super(from, mapper::toInfo); } } diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/GeoServer.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/GeoServer.java index 6ea16dd81..a0faf9239 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/GeoServer.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/GeoServer.java @@ -17,7 +17,7 @@ @EqualsAndHashCode(callSuper = true) @JsonTypeName("GeoServerInfo") public @Data @Generated class GeoServer extends ConfigInfoDto { - public static enum ResourceErrorHandling { + public enum ResourceErrorHandling { OGC_EXCEPTION_REPORT, SKIP_MISCONFIGURED_LAYERS } @@ -32,8 +32,6 @@ public static enum WebUIMode { private JaiDto JAI; private CoverageAccess coverageAccess; private MetadataMapDto metadata; - // not used - // private Map clientProperties; private long updateSequence; private String adminUsername; private String adminPassword; diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/JaiDto.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/JaiDto.java index 76f290184..d166fe794 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/JaiDto.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/JaiDto.java @@ -13,7 +13,7 @@ /** DTO for {@link JAIInfo} */ public @Data @Generated class JaiDto { - public static enum PngEncoderType { + public enum PngEncoderType { JDK, NATIVE, PNGJ diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/Service.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/Service.java index d5b8144dc..947f006ec 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/Service.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/Service.java @@ -65,9 +65,6 @@ private boolean verbose; private MetadataMapDto metadata; - // not used - // Map clientProperties; - /** * @since geoserver 2.20.0 */ diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/Settings.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/Settings.java index c29ea564e..c25ac606e 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/Settings.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/Settings.java @@ -30,8 +30,6 @@ private boolean verbose; private boolean verboseExceptions; private MetadataMapDto metadata; - // seems not to be used at all in geoserver - // Map clientProperties; private boolean localWorkspaceIncludesPrefix; private boolean showCreatedTimeColumnsInAdminList; private boolean showModifiedTimeColumnsInAdminList; diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/mapper/GeoServerConfigMapper.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/mapper/GeoServerConfigMapper.java index 83076ef21..8ddb46afe 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/mapper/GeoServerConfigMapper.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/config/dto/mapper/GeoServerConfigMapper.java @@ -4,6 +4,8 @@ */ package org.geoserver.jackson.databind.config.dto.mapper; +import static java.util.stream.Collectors.toCollection; + import org.geoserver.catalog.CatalogInfo; import org.geoserver.catalog.Info; import org.geoserver.cog.CogSettings; @@ -44,8 +46,8 @@ import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; +import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; /** Mapper to/from GeoServer config objects and their respective DTO representations */ @Mapper(config = ConfigInfoMapperConfig.class) @@ -55,8 +57,8 @@ public interface GeoServerConfigMapper { default T toInfo(InfoDto dto) { if (dto == null) return null; - if (dto instanceof ConfigInfoDto) return toInfo((ConfigInfoDto) dto); - if (dto instanceof CatalogInfoDto) return catalogInfoMapper.map((CatalogInfoDto) dto); + if (dto instanceof ConfigInfoDto configInfo) return toInfo(configInfo); + if (dto instanceof CatalogInfoDto catalogInfo) return catalogInfoMapper.map(catalogInfo); throw new IllegalArgumentException( "Unknown config DTO type: " + dto.getClass().getCanonicalName()); } @@ -64,11 +66,11 @@ default T toInfo(InfoDto dto) { @SuppressWarnings("unchecked") default T toDto(Info info) { if (info == null) return null; - if (info instanceof GeoServerInfo) return (T) toDto((GeoServerInfo) info); - if (info instanceof SettingsInfo) return (T) toDto((SettingsInfo) info); - if (info instanceof LoggingInfo) return (T) toDto((LoggingInfo) info); - if (info instanceof ServiceInfo) return (T) toDto((ServiceInfo) info); - if (info instanceof CatalogInfo) return (T) catalogInfoMapper.map((CatalogInfo) info); + if (info instanceof GeoServerInfo gs) return (T) toDto(gs); + if (info instanceof SettingsInfo settings) return (T) toDto(settings); + if (info instanceof LoggingInfo logging) return (T) toDto(logging); + if (info instanceof ServiceInfo service) return (T) toDto(service); + if (info instanceof CatalogInfo catInfo) return (T) catalogInfoMapper.map(catInfo); throw new IllegalArgumentException( "Unknown config info type: " + info.getClass().getCanonicalName()); @@ -77,10 +79,10 @@ default T toDto(Info info) { @SuppressWarnings("unchecked") default T toInfo(ConfigInfoDto dto) { if (dto == null) return null; - if (dto instanceof GeoServer) return (T) toInfo((GeoServer) dto); - if (dto instanceof Settings) return (T) toInfo((Settings) dto); - if (dto instanceof Logging) return (T) toInfo((Logging) dto); - if (dto instanceof Service) return (T) toInfo((Service) dto); + if (dto instanceof GeoServer gs) return (T) toInfo(gs); + if (dto instanceof Settings settings) return (T) toInfo(settings); + if (dto instanceof Logging logging) return (T) toInfo(logging); + if (dto instanceof Service service) return (T) toInfo(service); throw new IllegalArgumentException( "Unknown config DTO type: " + dto.getClass().getCanonicalName()); @@ -121,12 +123,12 @@ default T toInfo(ConfigInfoDto dto) { default ServiceInfo toInfo(Service dto) { if (dto == null) return null; - if (dto instanceof Service.WmsService) return toInfo((Service.WmsService) dto); - if (dto instanceof Service.WfsService) return toInfo((Service.WfsService) dto); - if (dto instanceof Service.WcsService) return toInfo((Service.WcsService) dto); - if (dto instanceof Service.WpsService) return toInfo((Service.WpsService) dto); - if (dto instanceof Service.WmtsService) return toInfo((Service.WmtsService) dto); - if (dto instanceof Service.GenericService) return toInfo((Service.GenericService) dto); + if (dto instanceof Service.WmsService wms) return toInfo(wms); + if (dto instanceof Service.WfsService wfs) return toInfo(wfs); + if (dto instanceof Service.WcsService wcs) return toInfo(wcs); + if (dto instanceof Service.WpsService wps) return toInfo(wps); + if (dto instanceof Service.WmtsService wmts) return toInfo(wmts); + if (dto instanceof Service.GenericService s) return toInfo(s); throw new IllegalArgumentException( "Unknown ServiceInfo type: " + dto.getClass().getCanonicalName()); @@ -134,11 +136,11 @@ default ServiceInfo toInfo(Service dto) { default Service toDto(ServiceInfo info) { if (info == null) return null; - if (info instanceof WMSInfo) return toDto((WMSInfo) info); - if (info instanceof WFSInfo) return toDto((WFSInfo) info); - if (info instanceof WCSInfo) return toDto((WCSInfo) info); - if (info instanceof WPSInfo) return toDto((WPSInfo) info); - if (info instanceof WMTSInfo) return toDto((WMTSInfo) info); + if (info instanceof WMSInfo wms) return toDto(wms); + if (info instanceof WFSInfo wfs) return toDto(wfs); + if (info instanceof WCSInfo wcs) return toDto(wcs); + if (info instanceof WPSInfo wps) return toDto(wps); + if (info instanceof WMTSInfo wmts) return toDto(wmts); if (info.getClass().equals(ServiceInfoImpl.class)) return toGenericService(info); throw new IllegalArgumentException( @@ -150,7 +152,9 @@ default Service toDto(ServiceInfo info) { * {@code List} as is */ default List stringListToVersionList(List list) { - return list == null ? null : list.stream().map(Version::new).collect(Collectors.toList()); + return list == null + ? null + : list.stream().map(Version::new).collect(toCollection(ArrayList::new)); } @Mapping(target = "clientProperties", ignore = true) diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/mapper/InfoReferenceMapper.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/mapper/InfoReferenceMapper.java index e12fac2e0..553adf5c5 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/mapper/InfoReferenceMapper.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/mapper/InfoReferenceMapper.java @@ -149,7 +149,6 @@ public T referenceToInfo(InfoReference ref) { Objects.requireNonNull(id, () -> "Object Reference has no id: " + ref); @SuppressWarnings("unchecked") Class type = (Class) ref.getType().getInterface(); - T proxy = ResolvingProxy.create(id, type); - return proxy; + return ResolvingProxy.create(id, type); } } diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/mapper/PatchMapper.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/mapper/PatchMapper.java index c84b2b6b6..dcb353a97 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/mapper/PatchMapper.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/mapper/PatchMapper.java @@ -38,7 +38,7 @@ }) public abstract class PatchMapper { - private static InfoReferenceMapper REFS = Mappers.getMapper(InfoReferenceMapper.class); + private static final InfoReferenceMapper REFS = Mappers.getMapper(InfoReferenceMapper.class); @Mapping(target = "propertyNames", ignore = true) public abstract Patch dtoToPatch(PatchDto dto); @@ -57,10 +57,9 @@ protected Object literalDtoToValueObject(Literal l) { private Object dtoToValue(final Object valueDto) { Object value = valueDto; - if (valueDto instanceof InfoReference) { - value = REFS.referenceToInfo((InfoReference) valueDto); - } else if (valueDto instanceof Collection) { - Collection c = (Collection) valueDto; + if (valueDto instanceof InfoReference infoRef) { + value = REFS.referenceToInfo(infoRef); + } else if (valueDto instanceof Collection c) { value = copyOf(c, this::dtoToValue); } else if (value instanceof Map) { @SuppressWarnings("unchecked") @@ -78,13 +77,11 @@ private Object dtoToValue(final Object valueDto) { private R valueToDto(final V value) { R dto = (R) value; - if (value instanceof Info) { - Info info = (Info) dto; + if (value instanceof Info info) { if (ProxyUtils.encodeByReference(info)) { dto = (R) REFS.infoToReference(info); } - } else if (value instanceof Collection) { - Collection c = (Collection) value; + } else if (value instanceof Collection c) { dto = (R) copyOf(c, this::valueToDto); } else if (value instanceof Map) { Map fromMap = (Map) value; diff --git a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/mapper/SharedMappers.java b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/mapper/SharedMappers.java index 1cadac57e..3c97906c3 100644 --- a/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/mapper/SharedMappers.java +++ b/src/catalog/jackson-bindings/geoserver/src/main/java/org/geoserver/jackson/databind/mapper/SharedMappers.java @@ -109,7 +109,7 @@ public CoordinateReferenceSystem crs(CRS source) { } return org.geotools.referencing.CRS.parseWKT(source.getWKT()); } catch (FactoryException e) { - throw new RuntimeException(e); + throw new IllegalArgumentException(e); } } diff --git a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/GeoServerCatalogModuleTest.java b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/GeoServerCatalogModuleTest.java index 43f0c864e..25a49aae0 100644 --- a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/GeoServerCatalogModuleTest.java +++ b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/GeoServerCatalogModuleTest.java @@ -175,7 +175,8 @@ private T catalogInfoRoundtripTest(final T orig) return decoded; } - public @Test void testWorkspace() throws Exception { + @Test + void testWorkspace() throws Exception { catalogInfoRoundtripTest(data.workspaceA); data.workspaceB.setIsolated(true); @@ -184,7 +185,8 @@ private T catalogInfoRoundtripTest(final T orig) catalogInfoRoundtripTest(data.workspaceB); } - public @Test void testNamespace() throws Exception { + @Test + void testNamespace() throws Exception { catalogInfoRoundtripTest(data.namespaceA); data.namespaceB.setIsolated(true); @@ -193,17 +195,20 @@ private T catalogInfoRoundtripTest(final T orig) catalogInfoRoundtripTest(data.workspaceB); } - public @Test void testDataStore() throws Exception { + @Test + void testDataStore() throws Exception { catalogInfoRoundtripTest(data.dataStoreA); catalogInfoRoundtripTest(data.dataStoreB); catalogInfoRoundtripTest(data.dataStoreC); } - public @Test void testCoverageStore() throws Exception { + @Test + void testCoverageStore() throws Exception { catalogInfoRoundtripTest(data.coverageStoreA); } - public @Test void testCoverageStore_COG() throws Exception { + @Test + void testCoverageStore_COG() throws Exception { CoverageStoreInfo store = data.coverageStoreA; CogSettingsStore cogSettings = new CogSettingsStore(); cogSettings.setRangeReaderSettings(RangeReaderType.Azure); @@ -216,15 +221,18 @@ private T catalogInfoRoundtripTest(final T orig) assertThat(deserializedCogSettings, CoreMatchers.instanceOf(CogSettingsStore.class)); } - public @Test void testWmsStore() throws Exception { + @Test + void testWmsStore() throws Exception { catalogInfoRoundtripTest(data.wmsStoreA); } - public @Test void testWmtsStore() throws Exception { + @Test + void testWmtsStore() throws Exception { catalogInfoRoundtripTest(data.wmtsStoreA); } - public @Test void testFeatureType() throws Exception { + @Test + void testFeatureType() throws Exception { KeywordInfo k = new Keyword("value"); k.setLanguage("es"); FeatureTypeInfo ft = data.featureTypeA; @@ -271,26 +279,31 @@ private List createTestAttributes(FeatureTypeInfo info) return new CatalogBuilder(new CatalogPlugin()).getAttributes(ft, info); } - public @Test void testCoverage() throws Exception { + @Test + void testCoverage() throws Exception { catalogInfoRoundtripTest(data.coverageA); } - public @Test void testWmsLayer() throws Exception { + @Test + void testWmsLayer() throws Exception { catalogInfoRoundtripTest(data.wmsLayerA); } - public @Test void testWtmsLayer() throws Exception { + @Test + void testWtmsLayer() throws Exception { catalogInfoRoundtripTest(data.wmtsLayerA); } - public @Test void testLayer() throws Exception { + @Test + void testLayer() throws Exception { LayerInfo layer = data.layerFeatureTypeA; layer.getStyles().add(data.style1); layer.getStyles().add(data.style2); catalogInfoRoundtripTest(layer); } - public @Test void testLayerGroup() throws Exception { + @Test + void testLayerGroup() throws Exception { LayerGroupInfo lg = data.layerGroup1; lg.setTitle("LG Title"); lg.setAbstract("LG abstract"); @@ -333,12 +346,14 @@ private List createTestAttributes(FeatureTypeInfo info) catalogInfoRoundtripTest(lg); } - public @Test void testLayerGroupWorkspace() throws Exception { + @Test + void testLayerGroupWorkspace() throws Exception { data.layerGroup1.setWorkspace(data.workspaceC); catalogInfoRoundtripTest(data.layerGroup1); } - public @Test void testStyle() throws Exception { + @Test + void testStyle() throws Exception { StyleInfo style1 = data.style1; style1.setFormatVersion(SLDHandler.VERSION_10); style1.setFormat(SLDHandler.FORMAT); @@ -351,7 +366,8 @@ private List createTestAttributes(FeatureTypeInfo info) catalogInfoRoundtripTest(style2); } - public @Test void testStyleWorkspace() throws Exception { + @Test + void testStyleWorkspace() throws Exception { data.style1.setWorkspace(data.workspaceA); data.style2.setWorkspace(data.workspaceB); catalogInfoRoundtripTest(data.style1); @@ -373,7 +389,8 @@ protected AttributionInfoImpl attInfo(String id) throws Exception { return attinfo; } - public @Test void testFilterWithInfoLiterals() throws JsonProcessingException { + @Test + void testFilterWithInfoLiterals() throws JsonProcessingException { testFilterLiteral(forceNonProxy(data.workspaceA)); testFilterLiteral(forceProxy(data.workspaceA)); @@ -486,7 +503,8 @@ private V roundTrip(T orig, Class source, Class tar return decoded; } - public @Test void testValueKeywordInfo() throws JsonProcessingException { + @Test + void testValueKeywordInfo() throws JsonProcessingException { KeywordInfo keyword = new org.geoserver.catalog.Keyword("value"); keyword.setLanguage("en"); keyword.setVocabulary("bad"); @@ -495,22 +513,26 @@ private V roundTrip(T orig, Class source, Class tar assertEquals(keyword, testFilterLiteral(keyword)); } - public @Test void testValueCoordinateReferenceSystemGeographicLatLon() throws Exception { + @Test + void testValueCoordinateReferenceSystemGeographicLatLon() throws Exception { CoordinateReferenceSystem wgs84LatLon = CRS.decode("EPSG:4326", false); testValueCoordinateReferenceSystem(wgs84LatLon); } - public @Test void testValueCoordinateReferenceSystemGeographicLonLat() throws Exception { + @Test + void testValueCoordinateReferenceSystemGeographicLonLat() throws Exception { CoordinateReferenceSystem wgs84LonLat = CRS.decode("EPSG:4326", true); testValueCoordinateReferenceSystem(wgs84LonLat); } - public @Test void testValueCoordinateReferenceSystemProjected() throws Exception { + @Test + void testValueCoordinateReferenceSystemProjected() throws Exception { CoordinateReferenceSystem webMercator = CRS.decode("EPSG:3857", true); testValueCoordinateReferenceSystem(webMercator); } - public @Test void testValueCoordinateReferenceSystemCustomCRS() throws Exception { + @Test + void testValueCoordinateReferenceSystemCustomCRS() throws Exception { String customWKT = "PROJCS[ \"UTM Zone 10, Northern Hemisphere\",\n" + " GEOGCS[\"GRS 1980(IUGG, 1980)\",\n" @@ -559,7 +581,8 @@ private void testValueWithEquals(final T value, Class type) throws Except assertEquals(value, decoded); } - public @Test void testValueNumberRange() throws Exception { + @Test + void testValueNumberRange() throws Exception { testValueWithEquals(NumberRange.create(Double.MIN_VALUE, 0d), NumberRange.class); testValueWithEquals(NumberRange.create(0L, false, Long.MAX_VALUE, true), NumberRange.class); testValueWithEquals( @@ -567,12 +590,14 @@ private void testValueWithEquals(final T value, Class type) throws Except NumberRange.class); } - public @Test void testValueMeasure() throws Exception { + @Test + void testValueMeasure() throws Exception { testValueWithEquals(new Measure(1000, SI.METRE), Measure.class); testValueWithEquals(new Measure(.75, SI.RADIAN_PER_SECOND), Measure.class); } - public @Test void testValueReferencedEnvelope() throws Exception { + @Test + void testValueReferencedEnvelope() throws Exception { CoordinateReferenceSystem wgs84LatLon = CRS.decode("EPSG:4326", false); CoordinateReferenceSystem wgs84LonLat = CRS.decode("EPSG:4326", true); @@ -582,7 +607,8 @@ private void testValueWithEquals(final T value, Class type) throws Except new ReferencedEnvelope(-90, 90, -180, 180, wgs84LatLon), ReferencedEnvelope.class); } - public @Test void testValueGridGeometry2D() throws Exception { + @Test + void testValueGridGeometry2D() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:4326", true); ReferencedEnvelope env = new ReferencedEnvelope(-180, 180, -90, 90, crs); GridEnvelope range = new GeneralGridEnvelope(new int[] {0, 0}, new int[] {1024, 768}); @@ -590,19 +616,22 @@ private void testValueWithEquals(final T value, Class type) throws Except testValueWithEquals(gridGeometry, GridGeometry.class); } - public @Test void testValueAuthorityURLInfo() throws Exception { + @Test + void testValueAuthorityURLInfo() throws Exception { AuthorityURL info = new AuthorityURL(); info.setHref("href"); info.setName("name"); testValueWithEquals(info, AuthorityURLInfo.class); } - public @Test void testValueCoverageDimensionInfo() throws Exception { + @Test + void testValueCoverageDimensionInfo() throws Exception { CoverageDimensionInfo cdi = data.faker().coverageDimensionInfo(); testValueWithEquals(cdi, CoverageDimensionInfo.class); } - public @Test void testValueDimensionInfo() throws Exception { + @Test + void testValueDimensionInfo() throws Exception { DimensionInfo di = data.faker().dimensionInfo(); // bad equals implementation on DimensionInfoImpl @@ -623,17 +652,20 @@ private void testValueWithEquals(final T value, Class type) throws Except assertEquals(di.getPresentation(), actual.getPresentation()); } - public @Test void testValueDataLinkInfo() throws Exception { + @Test + void testValueDataLinkInfo() throws Exception { DataLinkInfo dl = data.faker().dataLinkInfo(); testValueWithEquals(dl, DataLinkInfo.class); } - public @Test void testValueLayerIdentifierInfo() throws Exception { + @Test + void testValueLayerIdentifierInfo() throws Exception { org.geoserver.catalog.impl.LayerIdentifier li = data.faker().layerIdentifierInfo(); testValueWithEquals(li, LayerIdentifierInfo.class); } - public @Test void testValueLegendInfo() throws Exception { + @Test + void testValueLegendInfo() throws Exception { LegendInfoImpl l = new LegendInfoImpl(); l.setFormat("format"); l.setHeight(10); @@ -649,16 +681,19 @@ private void testValueWithEquals(final T value, Class type) throws Except assertEquals(l.getOnlineResource(), parsed.getOnlineResource()); } - public @Test void testValueMetadataLinkInfo() throws Exception { + @Test + void testValueMetadataLinkInfo() throws Exception { testValueWithEquals(data.faker().metadataLink(), MetadataLinkInfo.class); } - public @Test void testValueVirtualTable() throws Exception { + @Test + void testValueVirtualTable() throws Exception { VirtualTable vt = new VirtualTable("testvt", "select * from test;", true); testValueWithEquals(vt, VirtualTable.class); } - public @Test void testValueMetadataMap() throws Exception { + @Test + void testValueMetadataMap() throws Exception { MetadataMap mdm = new MetadataMap(); mdm.put("k1", "v1"); mdm.put("k2", "v2"); @@ -670,7 +705,8 @@ private void testValueWithEquals(final T value, Class type) throws Except assertEquals(mdm, decoded); } - public @Test void testQuery() throws Exception { + @Test + void testQuery() throws Exception { Arrays.stream(ClassMappings.values()) .map(ClassMappings::getInterface) .filter(CatalogInfo.class::isAssignableFrom) diff --git a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/GeoServerCatalogModule_JsonTest.java b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/GeoServerCatalogModule_JsonTest.java index 160d02baf..51a4b898b 100644 --- a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/GeoServerCatalogModule_JsonTest.java +++ b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/GeoServerCatalogModule_JsonTest.java @@ -11,7 +11,7 @@ /** * @since 1.0 */ -public class GeoServerCatalogModule_JsonTest extends GeoServerCatalogModuleTest { +class GeoServerCatalogModule_JsonTest extends GeoServerCatalogModuleTest { protected @Override ObjectMapper newObjectMapper() { return ObjectMapperUtil.newObjectMapper(); diff --git a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/GeoServerCatalogModule_YamlTest.java b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/GeoServerCatalogModule_YamlTest.java index 6f4e1c885..2beb43464 100644 --- a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/GeoServerCatalogModule_YamlTest.java +++ b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/GeoServerCatalogModule_YamlTest.java @@ -11,7 +11,7 @@ /** * @since 1.0 */ -public class GeoServerCatalogModule_YamlTest extends GeoServerCatalogModuleTest { +class GeoServerCatalogModule_YamlTest extends GeoServerCatalogModuleTest { protected @Override ObjectMapper newObjectMapper() { return ObjectMapperUtil.newYAMLObjectMapper(); diff --git a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/PatchSerializationTest.java b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/PatchSerializationTest.java index f5b9f6f69..a2a38beeb 100644 --- a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/PatchSerializationTest.java +++ b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/PatchSerializationTest.java @@ -155,7 +155,8 @@ private List createTestAttributes(FeatureTypeInfo info) return new CatalogBuilder(new CatalogPlugin()).getAttributes(ft, info); } - public @Test void simpleTypes() throws Exception { + @Test + void simpleTypes() throws Exception { testPatch("nullvalue", null); testPatch("int", Integer.MAX_VALUE); testPatch("long", Long.MAX_VALUE); @@ -163,67 +164,82 @@ private List createTestAttributes(FeatureTypeInfo info) testPatch("string", "string value"); } - public @Test void arrayTypes_scalar() throws Exception { + @Test + void arrayTypes_scalar() throws Exception { testPatch("bytea", new byte[] {0x01, 0x02, 0x03}); testPatch("booleana", new boolean[] {false, true, false}); testPatch("chararray", new char[] {'a', 'b', 'c', 'd'}); } - public @Test void arrayTypes_non_scalar() throws Exception { + @Test + void arrayTypes_non_scalar() throws Exception { testPatch( "ns_array", new NamespaceInfo[] {data.namespaceA, data.namespaceB, data.namespaceC}); } - public @Test void workspace() throws Exception { + @Test + void workspace() throws Exception { testPatch("workspace", data.workspaceA); } - public @Test void namespaceInfo() throws Exception { + @Test + void namespaceInfo() throws Exception { testPatch("namespace", data.namespaceA); } - public @Test void dataStoreInfo() throws Exception { + @Test + void dataStoreInfo() throws Exception { testPatch("dataStore", data.dataStoreA); } - public @Test void coverageStoreInfo() throws Exception { + @Test + void coverageStoreInfo() throws Exception { testPatch("coverageStore", data.coverageStoreA); } - public @Test void wmsStoreInfo() throws Exception { + @Test + void wmsStoreInfo() throws Exception { testPatch("wms", data.wmsStoreA); } - public @Test void wmtsStoreInfo() throws Exception { + @Test + void wmtsStoreInfo() throws Exception { testPatch("wmts", data.wmtsStoreA); } - public @Test void featureTypeInfo() throws Exception { + @Test + void featureTypeInfo() throws Exception { testPatch("ft", data.featureTypeA); } - public @Test void coverageInfo() throws Exception { + @Test + void coverageInfo() throws Exception { testPatch("coverage", data.coverageA); } - public @Test void wmsLayerInfo() throws Exception { + @Test + void wmsLayerInfo() throws Exception { testPatch("wmsl", data.wmsLayerA); } - public @Test void wmtsLayerInfo() throws Exception { + @Test + void wmtsLayerInfo() throws Exception { testPatch("wmtsl", data.wmtsLayerA); } - public @Test void layerInfo() throws Exception { + @Test + void layerInfo() throws Exception { testPatch("layer", data.layerFeatureTypeA); } - public @Test void layerGroupInfo() throws Exception { + @Test + void layerGroupInfo() throws Exception { testPatch("layer", data.layerGroup1); } - public @Test void layerInfo_references() throws Exception { + @Test + void layerInfo_references() throws Exception { LayerInfo layer = data.layerFeatureTypeA; StyleInfo s1 = data.faker().styleInfo("s1"); StyleInfo s2 = data.faker().styleInfo("s2"); @@ -255,7 +271,8 @@ private List createTestAttributes(FeatureTypeInfo info) styles.forEach(this::assertResolvingProxy); } - public @Test void layerInfo_value_object_properties() throws Exception { + @Test + void layerInfo_value_object_properties() throws Exception { LayerInfo layer = data.layerFeatureTypeA; layer.setLegend(data.faker().legendInfo()); @@ -279,80 +296,97 @@ private List createTestAttributes(FeatureTypeInfo info) assertValueObject(legend, LegendInfo.class); } - public @Test void styleInfo() throws Exception { + @Test + void styleInfo() throws Exception { testPatch("style", data.style1); } - public @Test void geoserverInfo() throws Exception { + @Test + void geoserverInfo() throws Exception { testPatch("global", data.global); } - public @Test void loggingInfo() throws Exception { + @Test + void loggingInfo() throws Exception { testPatch("logging", data.logging); } - public @Test void settingsInfo() throws Exception { + @Test + void settingsInfo() throws Exception { testPatch("settings", data.faker().settingsInfo(null)); } - public @Test void settingsInfo_workspace() throws Exception { + @Test + void settingsInfo_workspace() throws Exception { Patch resolved = testPatch("settings", data.faker().settingsInfo(data.workspaceA)); SettingsInfo setting = resolved.get("settings").orElseThrow().value(); assertModificationProxy(setting.getWorkspace()); } - public @Test void wmsInfo() throws Exception { + @Test + void wmsInfo() throws Exception { testPatch("wmsService", data.wmsService); } - public @Test void wcsInfo() throws Exception { + @Test + void wcsInfo() throws Exception { // WCSInfoImpl.equals is broken, we're still checking it's sent as a reference testPatchNoEquals(patch("wcsService", data.wcsService)); } - public @Test void wfsInfo() throws Exception { + @Test + void wfsInfo() throws Exception { testPatch("wfsService", data.wfsService); } - public @Test void wpsInfo() throws Exception { + @Test + void wpsInfo() throws Exception { Patch patch = patch("wpsService", data.wpsService); // WPSInfoImpl.equals is broken, we're still checking it's sent as a reference testPatchNoEquals(patch); } - public @Test void attributionInfo() throws Exception { + @Test + void attributionInfo() throws Exception { testPatch("attribution", data.faker().attributionInfo()); } - public @Test void contactInfo() throws Exception { + @Test + void contactInfo() throws Exception { testPatch("contact", data.faker().contactInfo()); } - public @Test void keywordInfo() throws Exception { + @Test + void keywordInfo() throws Exception { CatalogFaker faker = data.faker(); testPatch("kw", faker.keywordInfo()); } - public @Test void keywordInfo_list() throws Exception { + @Test + void keywordInfo_list() throws Exception { CatalogFaker faker = data.faker(); testPatch("keywords", Arrays.asList(faker.keywordInfo(), null, faker.keywordInfo())); } - public @Test void name() throws Exception { + @Test + void name() throws Exception { org.geotools.api.feature.type.Name name = new NameImpl("localname"); testPatch("name", name); } - public @Test void name_with_ns() throws Exception { + @Test + void name_with_ns() throws Exception { org.geotools.api.feature.type.Name name = new NameImpl("http://name.space", "localname"); testPatch("name", name); } - public @Test void version() throws Exception { + @Test + void version() throws Exception { testPatch("version", new org.geotools.util.Version("1.0.1")); } - public @Test void version_list() throws Exception { + @Test + void version_list() throws Exception { testPatch( "version", List.of( @@ -360,15 +394,18 @@ private List createTestAttributes(FeatureTypeInfo info) new org.geotools.util.Version("1.0.2"))); } - public @Test void class_property() throws Exception { + @Test + void class_property() throws Exception { testPatch("binding", org.geotools.util.Version.class); } - public @Test void metadataLinkInfo() throws Exception { + @Test + void metadataLinkInfo() throws Exception { testPatch("metadataLink", data.faker().metadataLink()); } - public @Test void coordinateReferenceSystem() throws Exception { + @Test + void coordinateReferenceSystem() throws Exception { final boolean longitudeFirst = true; CoordinateReferenceSystem crs = CRS.decode("EPSG:3857", longitudeFirst); Patch resolved = testPatchNoEquals(patch("crs", crs)); @@ -378,26 +415,30 @@ private List createTestAttributes(FeatureTypeInfo info) assertTrue(CRS.equalsIgnoreMetadata(crs, roundtripped)); } - public @Test void referencedEnvelope() throws Exception { + @Test + void referencedEnvelope() throws Exception { final boolean longitudeFirst = true; CoordinateReferenceSystem crs = CRS.decode("EPSG:3857", longitudeFirst); ReferencedEnvelope env = new ReferencedEnvelope(0, 1000, -1, -1000, crs); testPatch("bounds", env); } - public @Test void numberRange() throws Exception { + @Test + void numberRange() throws Exception { testPatch("range", NumberRange.create(-1, 1)); // testPatch("range", NumberRange.create(-1.1f, 1.1f)); // testPatch("range", NumberRange.create((short) 10, (short) 15)); testPatch("range", NumberRange.create(Double.MIN_VALUE, 1.01)); } - public @Test void measure() throws Exception { + @Test + void measure() throws Exception { testPatch("meters", new Measure(1000, SI.METRE)); testPatch("radians", new Measure(.75, SI.RADIAN_PER_SECOND)); } - public @Test void gridGeometry() throws Exception { + @Test + void gridGeometry() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:4326", true); ReferencedEnvelope env = new ReferencedEnvelope(-180, 180, -90, 90, crs); GridEnvelope range = new GeneralGridEnvelope(new int[] {0, 0}, new int[] {1024, 768}); @@ -405,46 +446,56 @@ private List createTestAttributes(FeatureTypeInfo info) testPatch("gridGeometry", gridGeometry); } - public @Test void modificationProxy_workspace() throws Exception { + @Test + void modificationProxy_workspace() throws Exception { testPatch("workspace", forceProxy(data.workspaceA, WorkspaceInfo.class)); } - public @Test void modificationProxy_namespace() throws Exception { + @Test + void modificationProxy_namespace() throws Exception { testPatch("namespace", forceProxy(data.namespaceA, NamespaceInfo.class)); } - public @Test void modificationProxy_dataStore() throws Exception { + @Test + void modificationProxy_dataStore() throws Exception { testPatch("dataStore", forceProxy(data.dataStoreA, DataStoreInfo.class)); } - public @Test void modificationProxy_coverageStore() throws Exception { + @Test + void modificationProxy_coverageStore() throws Exception { testPatch("coverageStore", forceProxy(data.coverageStoreA, CoverageStoreInfo.class)); } - public @Test void modificationProxy_layer() throws Exception { + @Test + void modificationProxy_layer() throws Exception { testPatch("layer", forceProxy(data.layerFeatureTypeA, LayerInfo.class)); } - public @Test void modificationProxy_style() throws Exception { + @Test + void modificationProxy_style() throws Exception { testPatch("style", forceProxy(data.style1, StyleInfo.class)); } - public @Test void modificationProxy_geoserverInfo() throws Exception { + @Test + void modificationProxy_geoserverInfo() throws Exception { testPatch("global", forceProxy(data.global, GeoServerInfo.class)); } - public @Test void modificationProxy_wmsInfo() throws Exception { + @Test + void modificationProxy_wmsInfo() throws Exception { testPatch("wmsService", forceProxy(data.wmsService, WMSInfo.class)); } - public @Test void modificationProxy_settingsInfo() throws Exception { + @Test + void modificationProxy_settingsInfo() throws Exception { testPatch( "settings", forceProxy(data.faker().settingsInfo(data.workspaceA), SettingsInfo.class)); } /** Though ContactInfo is a value object, webui will save a ModificationProxy */ - public @Test void modificationProxy_settingsInfo_with_proxy_contact_info() throws Exception { + @Test + void modificationProxy_settingsInfo_with_proxy_contact_info() throws Exception { WorkspaceInfo workspaceProxy = forceProxy(data.workspaceA, WorkspaceInfo.class); SettingsInfo settings = data.faker().settingsInfo(workspaceProxy); ContactInfo contactInfo = data.faker().contactInfo(); @@ -461,13 +512,15 @@ private List createTestAttributes(FeatureTypeInfo info) } /** Though ContactInfo is a value object, webui will save a ModificationProxy */ - public @Test void modificationProxy_contactInfo() throws Exception { + @Test + void modificationProxy_contactInfo() throws Exception { ContactInfo contactInfo = data.faker().contactInfo(); Patch received = testPatch("contact", forceProxy(contactInfo, ContactInfo.class)); assertValueObject(received.get("contact").orElseThrow().getValue(), ContactInfo.class); } - public @Test void testPatchWithListProperty() throws Exception { + @Test + void testPatchWithListProperty() throws Exception { testPatch("nullvalue", newArrayList(null, null)); testPatch("int", List.of(Integer.MAX_VALUE, Integer.MIN_VALUE)); testPatch("long", List.of(Long.MAX_VALUE, Long.MIN_VALUE)); @@ -491,7 +544,8 @@ private List createTestAttributes(FeatureTypeInfo info) // testPatch("serviceInfos", List.of(data.wcsService)); } - public @Test void attributeTypeInfo_list() throws Exception { + @Test + void attributeTypeInfo_list() throws Exception { FeatureTypeInfo ft = data.featureTypeA; List attributes = createTestAttributes(ft); @@ -504,7 +558,8 @@ private List createTestAttributes(FeatureTypeInfo info) } } - public @Test void testPatchWithSetProperty() throws Exception { + @Test + void testPatchWithSetProperty() throws Exception { WorkspaceInfo wsa = catalog.getWorkspace(data.workspaceA.getId()); WorkspaceInfo wsb = catalog.getWorkspace(data.workspaceB.getId()); Set workspaces = Set.of(wsa, wsb); @@ -535,7 +590,8 @@ private List createTestAttributes(FeatureTypeInfo info) testPatch("serviceInfos", services); } - public @Test void simpleInternationalString() throws Exception { + @Test + void simpleInternationalString() throws Exception { InternationalString simpleI18n = new SimpleInternationalString("simpleI18n"); Patch patch = new Patch(); patch.add("simpleI18n", simpleI18n); @@ -550,11 +606,13 @@ private List createTestAttributes(FeatureTypeInfo info) assertEquals(expected, decoded); } - public @Test void authorityURLInfo() throws Exception { + @Test + void authorityURLInfo() throws Exception { testPatch("authorityURL", data.faker().authorityURLInfo()); } - public @Test void coverageAccessInfo() throws Exception { + @Test + void coverageAccessInfo() throws Exception { CoverageAccessInfo coverageInfo = new CoverageAccessInfoImpl(); coverageInfo.setCorePoolSize(10); coverageInfo.setQueueType(QueueType.UNBOUNDED); @@ -562,33 +620,39 @@ private List createTestAttributes(FeatureTypeInfo info) testPatch("coverageInfo", coverageInfo); } - public @Test void jaiInfo() throws Exception { + @Test + void jaiInfo() throws Exception { JAIInfo jaiInfo = data.faker().jaiInfo(); testPatch("jaiInfo", jaiInfo); } - public @Test void wmsInterpolation() throws Exception { + @Test + void wmsInterpolation() throws Exception { WMSInterpolation v = WMSInterpolation.Bicubic; testPatch("defaultWmsInterpolation", v); } - public @Test void publishedType() throws Exception { + @Test + void publishedType() throws Exception { PublishedType v = PublishedType.REMOTE; testPatch("publishedType", v); } - public @Test void growableInternationalString() throws Exception { + @Test + void growableInternationalString() throws Exception { GrowableInternationalString growableI18n = new GrowableInternationalString("default lang"); growableI18n.add(Locale.forLanguageTag("es-AR"), "en argentino"); growableI18n.add(Locale.forLanguageTag("es"), "en español"); testPatch("growableI18n", growableI18n); } - public @Test void coverageDimensionInfo() throws Exception { + @Test + void coverageDimensionInfo() throws Exception { testPatch("coverageDimensionInfo", data.faker().coverageDimensionInfo()); } - public @Test void dimensionInfo() throws Exception { + @Test + void dimensionInfo() throws Exception { // equals is broken DimensionInfo expected = data.faker().dimensionInfo(); Patch patch = testPatchNoEquals(patch("dimensionInfo", expected)); @@ -612,15 +676,18 @@ private List createTestAttributes(FeatureTypeInfo info) assertEquals(expected.getPresentation(), actual.getPresentation()); } - public @Test void dataLinkInfo() throws Exception { + @Test + void dataLinkInfo() throws Exception { testPatch("dl", data.faker().dataLinkInfo()); } - public @Test void layerIdentifierInfo() throws Exception { + @Test + void layerIdentifierInfo() throws Exception { testPatch("layerIdentifier", data.faker().layerIdentifierInfo()); } - public @Test void metadataMap() throws Exception { + @Test + void metadataMap() throws Exception { MetadataMap md = data.faker().metadataMap("k1", "v1", "k2", 2); Patch patch = testPatch("metadata", md); assertThat(patch.get("metadata").orElseThrow().getValue()).isInstanceOf(HashMap.class); @@ -629,7 +696,8 @@ private List createTestAttributes(FeatureTypeInfo info) assertEquals(md, s.getMetadata()); } - public @Test void metadataMapWithCogSettings() throws Exception { + @Test + void metadataMapWithCogSettings() throws Exception { CogSettings cog = new CogSettings(); cog.setRangeReaderSettings(RangeReaderType.Azure); cog.setUseCachingStream(true); @@ -757,8 +825,7 @@ private T forceProxy(T info, Class iface) { protected String typeName(Object mp) { if (mp == null) return null; - if (mp instanceof Info) { - Info info = (Info) mp; + if (mp instanceof Info info) { if (ProxyUtils.isResolvingProxy(info)) return "ResolvingProxy"; if (ProxyUtils.isModificationProxy(info)) return "ModificationProxy"; } @@ -772,8 +839,7 @@ private void assertCatalogSet(Info value) { } protected void assertNotAProxy(Object value) { - if (value instanceof Info) { - Info info = (Info) value; + if (value instanceof Info info) { assertThat(ProxyUtils.isResolvingProxy(info)) .as( () -> @@ -823,14 +889,14 @@ protected void assertResolvingProxy(Info info) { } private void assertValueObject(Object valueObject, Class valueType) { - if (valueObject instanceof Info) { + if (valueObject instanceof Info info) { Supplier msg = () -> String.format( "expected pure value object of type %s, got %s", valueType.getCanonicalName(), typeName(valueObject)); - assertThat(ProxyUtils.isResolvingProxy((Info) valueObject)).as(msg).isFalse(); - assertThat(ProxyUtils.isModificationProxy((Info) valueObject)).as(msg).isFalse(); + assertThat(ProxyUtils.isResolvingProxy(info)).as(msg).isFalse(); + assertThat(ProxyUtils.isModificationProxy(info)).as(msg).isFalse(); } assertThat(valueObject).isInstanceOf(valueType); } diff --git a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/PatchSerialization_JsonTest.java b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/PatchSerialization_JsonTest.java index 2b9168260..683fe0592 100644 --- a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/PatchSerialization_JsonTest.java +++ b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/PatchSerialization_JsonTest.java @@ -8,7 +8,7 @@ import org.geotools.jackson.databind.util.ObjectMapperUtil; -public class PatchSerialization_JsonTest extends PatchSerializationTest { +class PatchSerialization_JsonTest extends PatchSerializationTest { protected @Override ObjectMapper newObjectMapper() { return ObjectMapperUtil.newObjectMapper(); diff --git a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/PatchSerialization_YamlTest.java b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/PatchSerialization_YamlTest.java index cf03c675e..dee7b02ae 100644 --- a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/PatchSerialization_YamlTest.java +++ b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/catalog/PatchSerialization_YamlTest.java @@ -8,7 +8,7 @@ import org.geotools.jackson.databind.util.ObjectMapperUtil; -public class PatchSerialization_YamlTest extends PatchSerializationTest { +class PatchSerialization_YamlTest extends PatchSerializationTest { protected @Override ObjectMapper newObjectMapper() { return ObjectMapperUtil.newYAMLObjectMapper(); diff --git a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/config/GeoServerConfigModuleTest.java b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/config/GeoServerConfigModuleTest.java index 46ea2e602..b36125baa 100644 --- a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/config/GeoServerConfigModuleTest.java +++ b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/config/GeoServerConfigModuleTest.java @@ -97,64 +97,74 @@ private void roundtripTest(@NonNull final T orig) OwsUtils.resolveCollections(resolved); assertEquals(orig, resolved); testData.assertInternationalStringPropertiesEqual(orig, resolved); - if (orig instanceof SettingsInfo) { + if (orig instanceof SettingsInfo settings) { // SettingsInfoImpl's equals() doesn't check workspace - assertEquals( - ((SettingsInfo) orig).getWorkspace(), ((SettingsInfo) resolved).getWorkspace()); + assertEquals(settings.getWorkspace(), ((SettingsInfo) resolved).getWorkspace()); } } - public @Test void geoServerInfo() throws Exception { + @Test + void geoServerInfo() throws Exception { GeoServerInfo global = testData.global; global.setJAI(null); roundtripTest(global); } - public @Test void settingsInfo() throws Exception { + @Test + void settingsInfo() throws Exception { roundtripTest(testData.workspaceASettings); } - public @Test void loggingInfo() throws Exception { + @Test + void loggingInfo() throws Exception { roundtripTest(testData.logging); } - public @Test void wmsServiceInfo() throws Exception { + @Test + void wmsServiceInfo() throws Exception { roundtripTest(testData.wmsService); } - public @Test void wcsServiceInfo() throws Exception { + @Test + void wcsServiceInfo() throws Exception { WCSInfo wcsService = testData.wcsService; // WCSInfoImpl.equals() is broken, set a value for this property to workaround it wcsService.setMaxRequestedDimensionValues(10); roundtripTest(wcsService); } - public @Test void wfsServiceInfo() throws Exception { + @Test + void wfsServiceInfo() throws Exception { WFSInfo wfs = testData.wfsService; wfs.getGML().put(WFSInfo.Version.V_10, testData.faker().gmlInfo()); wfs.getGML().put(WFSInfo.Version.V_20, testData.faker().gmlInfo()); roundtripTest(wfs); } - public @Test void wpsServiceInfo() throws Exception { + @Test + void wpsServiceInfo() throws Exception { roundtripTest(testData.wpsService); } - public @Test void wmtsServiceInfo() throws Exception { + @Test + void wmtsServiceInfo() throws Exception { WMTSInfo wmtsService = testData.faker().serviceInfo("wmts", WMTSInfoImpl::new); roundtripTest(wmtsService); } - public @Test void contactInfo() throws Exception { + @Test + void contactInfo() throws Exception { ContactInfo contact = testData.faker().contactInfo(); roundtripTest(contact); } - public @Test void setingsInfo() throws Exception { + @Test + void setingsInfo() throws Exception { roundtripTest(testData.faker().settingsInfo(null)); } - public @Test void setingsInfoWithWorkspace() throws Exception { + @Test + void setingsInfoWithWorkspace() throws Exception { SettingsInfo settings = testData.faker().settingsInfo(testData.workspaceA); roundtripTest(settings); } diff --git a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/config/GeoSeververConfigModule_JsonTest.java b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/config/GeoSeververConfigModule_JsonTest.java index 977ac9ed1..fc81bba4c 100644 --- a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/config/GeoSeververConfigModule_JsonTest.java +++ b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/config/GeoSeververConfigModule_JsonTest.java @@ -11,7 +11,7 @@ /** * @since 1.0 */ -public class GeoSeververConfigModule_JsonTest extends GeoServerConfigModuleTest { +class GeoSeververConfigModule_JsonTest extends GeoServerConfigModuleTest { protected @Override ObjectMapper newObjectMapper() { return ObjectMapperUtil.newObjectMapper(); diff --git a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/config/GeoSeververConfigModule_YamlTest.java b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/config/GeoSeververConfigModule_YamlTest.java index 4e78837d2..a2b4a0a79 100644 --- a/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/config/GeoSeververConfigModule_YamlTest.java +++ b/src/catalog/jackson-bindings/geoserver/src/test/java/org/geoserver/jackson/databind/config/GeoSeververConfigModule_YamlTest.java @@ -11,7 +11,7 @@ /** * @since 1.0 */ -public class GeoSeververConfigModule_YamlTest extends GeoServerConfigModuleTest { +class GeoSeververConfigModule_YamlTest extends GeoServerConfigModuleTest { protected @Override ObjectMapper newObjectMapper() { return ObjectMapperUtil.newYAMLObjectMapper(); diff --git a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/dto/Literal.java b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/dto/Literal.java index f2a7e7f38..9eb290d09 100644 --- a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/dto/Literal.java +++ b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/dto/Literal.java @@ -22,10 +22,11 @@ private Object value; public static Literal valueOf(Object value) { - return value instanceof Literal ? (Literal) value : new Literal().setValue(value); + return value instanceof Literal l ? l : new Literal().setValue(value); } - public @Override boolean equals(Object o) { + @Override + public boolean equals(Object o) { if (!(o instanceof Literal)) return false; final Object v1 = value; @@ -43,20 +44,18 @@ public static boolean valueEquals(final Object v1, final Object v2) { final Class componentType = v1.getClass().getComponentType(); if (componentType.isPrimitive()) { - boolean equals = - switch (componentType.getCanonicalName()) { - case "byte" -> Arrays.equals((byte[]) v1, (byte[]) v2); - case "boolean" -> Arrays.equals((boolean[]) v1, (boolean[]) v2); - case "char" -> Arrays.equals((char[]) v1, (char[]) v2); - case "short" -> Arrays.equals((short[]) v1, (short[]) v2); - case "int" -> Arrays.equals((int[]) v1, (int[]) v2); - case "long" -> Arrays.equals((long[]) v1, (long[]) v2); - case "float" -> Arrays.equals((float[]) v1, (float[]) v2); - case "double" -> Arrays.equals((double[]) v1, (double[]) v2); - default -> throw new IllegalArgumentException( - "Unexpected value: " + componentType); - }; - return equals; + return switch (componentType.getCanonicalName()) { + case "byte" -> Arrays.equals((byte[]) v1, (byte[]) v2); + case "boolean" -> Arrays.equals((boolean[]) v1, (boolean[]) v2); + case "char" -> Arrays.equals((char[]) v1, (char[]) v2); + case "short" -> Arrays.equals((short[]) v1, (short[]) v2); + case "int" -> Arrays.equals((int[]) v1, (int[]) v2); + case "long" -> Arrays.equals((long[]) v1, (long[]) v2); + case "float" -> Arrays.equals((float[]) v1, (float[]) v2); + case "double" -> Arrays.equals((double[]) v1, (double[]) v2); + default -> throw new IllegalArgumentException( + "Unexpected value: " + componentType); + }; } else { Object[] a1 = (Object[]) v1; Object[] a2 = (Object[]) v2; @@ -66,7 +65,8 @@ public static boolean valueEquals(final Object v1, final Object v2) { return false; } - public @Override int hashCode() { + @Override + public int hashCode() { return Objects.hash(Literal.class, value); } } diff --git a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/dto/LiteralDeserializer.java b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/dto/LiteralDeserializer.java index e3591af80..e69b82ab3 100644 --- a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/dto/LiteralDeserializer.java +++ b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/dto/LiteralDeserializer.java @@ -4,12 +4,13 @@ */ package org.geotools.jackson.databind.filter.dto; -import static org.geotools.jackson.databind.filter.dto.LiteralSerializer.*; +import static org.geotools.jackson.databind.filter.dto.LiteralSerializer.COLLECTION_CONTENT_TYPE_KEY; +import static org.geotools.jackson.databind.filter.dto.LiteralSerializer.TYPE_KEY; +import static org.geotools.jackson.databind.filter.dto.LiteralSerializer.VALUE_KEY; import static java.util.Objects.requireNonNull; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; @@ -47,8 +48,8 @@ public class LiteralDeserializer extends JsonDeserializer { private ValueMappers classNameMapper = Mappers.getMapper(ValueMappers.class); - public @Override Literal deserialize(JsonParser parser, DeserializationContext ctxt) - throws IOException, JsonProcessingException { + @Override + public Literal deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException { expect(parser.currentToken(), JsonToken.START_OBJECT); final Class type = readType(parser); @@ -158,8 +159,8 @@ private List readList( item = null; } else { item = ctxt.readValue(parser, contentType); - if (item instanceof Literal) { - item = ((Literal) item).getValue(); + if (item instanceof Literal literal) { + item = literal.getValue(); } } value.add(item); @@ -187,8 +188,7 @@ private Class readType(JsonParser parser) throws IOException { expectFieldName(typeFieldName, TYPE_KEY); final String typeString = parser.nextTextValue(); requireNonNull(typeString, "type is null"); - final Class type = classNameMapper.canonicalNameToClass(typeString); - return type; + return classNameMapper.canonicalNameToClass(typeString); } /** diff --git a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/dto/LiteralSerializer.java b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/dto/LiteralSerializer.java index 87c94e018..f1f3ef4f3 100644 --- a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/dto/LiteralSerializer.java +++ b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/dto/LiteralSerializer.java @@ -56,12 +56,17 @@ public class LiteralSerializer extends StdSerializer { private static final long serialVersionUID = 1L; - private ValueMappers classNameMapper = Mappers.getMapper(ValueMappers.class); + private transient ValueMappers classNameMapper = Mappers.getMapper(ValueMappers.class); public LiteralSerializer() { super(Literal.class); } + private ValueMappers classNameMapper() { + if (classNameMapper == null) classNameMapper = Mappers.getMapper(ValueMappers.class); + return classNameMapper; + } + @Override public void serializeWithType( Literal value, JsonGenerator g, SerializerProvider provider, TypeSerializer typeSer) @@ -73,8 +78,9 @@ public void serializeWithType( typeSer.writeTypeSuffix(g, typeIdDef); } - public @Override void serialize( - Literal literal, JsonGenerator gen, SerializerProvider serializers) throws IOException { + @Override + public void serialize(Literal literal, JsonGenerator gen, SerializerProvider serializers) + throws IOException { final Object value = literal.getValue(); @@ -96,7 +102,7 @@ protected void writeValue(final Object value, JsonGenerator gen, SerializerProvi } else if (Collection.class.isAssignableFrom(type)) { writeCollection((Collection) value, gen, provider); } else if (Map.class.isAssignableFrom(type)) { - writeMap((Map) value, gen, provider); + writeMap((Map) value, gen); } else { if (type.isAnonymousClass()) { Class enclosingClass = type.getEnclosingClass(); @@ -111,7 +117,7 @@ protected void writeValue(final Object value, JsonGenerator gen, SerializerProvi JsonSerializer valueSerializer = findValueSerializer(provider, type); final Class handledType = valueSerializer.handledType(); String typeName = - classNameMapper.classToCanonicalName(type.isEnum() ? type : handledType); + classNameMapper().classToCanonicalName(type.isEnum() ? type : handledType); gen.writeStringField(TYPE_KEY, typeName); gen.writeFieldName(VALUE_KEY); valueSerializer.serialize(value, gen, provider); @@ -130,9 +136,8 @@ protected JsonSerializer findValueSerializer( return valueSerializer; } - private void writeMap(Map value, JsonGenerator gen, SerializerProvider provider) - throws IOException { - gen.writeStringField(TYPE_KEY, classNameMapper.classToCanonicalName(Map.class)); + private void writeMap(Map value, JsonGenerator gen) throws IOException { + gen.writeStringField(TYPE_KEY, classNameMapper().classToCanonicalName(Map.class)); gen.writeFieldName(VALUE_KEY); gen.writeStartObject(); @@ -147,7 +152,7 @@ private void writeMap(Map value, JsonGenerator gen, SerializerProvider pro private void writeArray(Object array, JsonGenerator gen, SerializerProvider provider) throws IOException { // e.g. int[], java.lang.String[], etc. - final String arrayTypeStr = classNameMapper.classToCanonicalName(array.getClass()); + final String arrayTypeStr = classNameMapper().classToCanonicalName(array.getClass()); gen.writeStringField(TYPE_KEY, arrayTypeStr); gen.writeFieldName(VALUE_KEY); @@ -176,7 +181,7 @@ private void writeCollection( Literal.class.equals(contentType) ? Literal::valueOf : Function.identity(); gen.writeStringField( - TYPE_KEY, classNameMapper.classToCanonicalName(collectionType(collection))); + TYPE_KEY, classNameMapper().classToCanonicalName(collectionType(collection))); if (null != contentType) { String singleContentTypeValue = classNameMapper.classToCanonicalName(contentType); diff --git a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/dto/SortBy.java b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/dto/SortBy.java index 404c54906..70ae6ef78 100644 --- a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/dto/SortBy.java +++ b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/dto/SortBy.java @@ -14,7 +14,7 @@ @AllArgsConstructor public @Data @Generated class SortBy { - public static enum SortOrder { + public enum SortOrder { ASCENDING, DESCENDING } diff --git a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/DtoToFilterMapper.java b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/DtoToFilterMapper.java index a2b04ada6..2b871607b 100644 --- a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/DtoToFilterMapper.java +++ b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/DtoToFilterMapper.java @@ -83,7 +83,6 @@ import org.geotools.filter.temporal.TEqualsImpl; import org.geotools.filter.temporal.TOverlapsImpl; import org.geotools.jackson.databind.filter.dto.Filter; -import org.geotools.jackson.databind.filter.dto.Filter.Id.ResourceId; import org.mapstruct.IterableMapping; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -113,13 +112,13 @@ public org.geotools.api.filter.Filter map(org.geotools.jackson.databind.filter.d try { mapperMethod = getClass().getMethod("toFilter", dtoFilterType); } catch (NoSuchMethodException | SecurityException e) { - throw new RuntimeException(e); + throw new IllegalArgumentException(e); } org.geotools.api.filter.Filter filter; try { filter = (org.geotools.api.filter.Filter) mapperMethod.invoke(this, dto); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - throw new RuntimeException(e); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new IllegalArgumentException(e); } return filter; } @@ -186,8 +185,7 @@ public Id toFilter(Filter.Id dto) { } Identifier toIdentifier(Filter.Id.FeatureId dto) { - if (dto instanceof Filter.Id.ResourceId) { - Filter.Id.ResourceId rid = (ResourceId) dto; + if (dto instanceof Filter.Id.ResourceId rid) { if (rid.getStartTime() != null || rid.getEndTime() != null) return ff.resourceId(rid.getId(), rid.getStartTime(), rid.getEndTime()); @@ -195,7 +193,7 @@ Identifier toIdentifier(Filter.Id.FeatureId dto) { } if (dto instanceof Filter.Id.FeatureId) { String id = dto.getId(); - String featureVersion = ((Filter.Id.FeatureId) dto).getFeatureVersion(); + String featureVersion = dto.getFeatureVersion(); if (featureVersion == null) { return ff.featureId(id); } diff --git a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/ExpressionMapper.java b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/ExpressionMapper.java index a0de2d781..4a31107f7 100644 --- a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/ExpressionMapper.java +++ b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/ExpressionMapper.java @@ -35,43 +35,51 @@ public abstract class ExpressionMapper { private final ExpressionVisitor visitor = new ExpressionVisitor() { - public @Override Subtract visit( + @Override + public Subtract visit( org.geotools.api.filter.expression.Subtract expression, Object extraData) { return map(expression); } - public @Override PropertyName visit( + @Override + public PropertyName visit( org.geotools.api.filter.expression.PropertyName expression, Object extraData) { return map(expression); } - public @Override Multiply visit( + @Override + public Multiply visit( org.geotools.api.filter.expression.Multiply expression, Object extraData) { return map(expression); } - public @Override Literal visit( + @Override + public Literal visit( org.geotools.api.filter.expression.Literal expression, Object extraData) { return map(expression); } - public @Override Function visit( + @Override + public Function visit( org.geotools.api.filter.expression.Function expression, Object extraData) { return map(expression); } - public @Override Divide visit( + @Override + public Divide visit( org.geotools.api.filter.expression.Divide expression, Object extraData) { return map(expression); } - public @Override Add visit( + @Override + public Add visit( org.geotools.api.filter.expression.Add expression, Object extraData) { return map(expression); } - public @Override Expression visit(NilExpression expression, Object extraData) { + @Override + public Expression visit(NilExpression expression, Object extraData) { return map(expression); } }; @@ -82,13 +90,13 @@ public Expression map(org.geotools.api.filter.expression.Expression source) { public org.geotools.api.filter.expression.Expression map(Expression source) { if (source == null) return null; - if (source instanceof Literal) return map((Literal) source); - if (source instanceof PropertyName) return map((PropertyName) source); - if (source instanceof Add) return map((Add) source); - if (source instanceof Subtract) return map((Subtract) source); - if (source instanceof Multiply) return map((Multiply) source); - if (source instanceof Divide) return map((Divide) source); - if (source instanceof Function) return map((Function) source); + if (source instanceof Literal literal) return map(literal); + if (source instanceof PropertyName prop) return map(prop); + if (source instanceof Add add) return map(add); + if (source instanceof Subtract subtract) return map(subtract); + if (source instanceof Multiply multiply) return map(multiply); + if (source instanceof Divide divide) return map(divide); + if (source instanceof Function function) return map(function); throw new IllegalArgumentException( "Unrecognized expression type " + source.getClass().getName() + ": " + source); } diff --git a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/FilterToDtoMapper.java b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/FilterToDtoMapper.java index 7e31570cc..6e8d07b88 100644 --- a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/FilterToDtoMapper.java +++ b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/FilterToDtoMapper.java @@ -123,13 +123,10 @@ BinaryComparisonOperator.PropertyIsGreaterThanOrEqualTo toDto( default Filter.Id.FeatureId map(org.geotools.api.filter.identity.Identifier id) { if (id == null) return null; Filter.Id.FeatureId fid; - if (id instanceof ResourceId) { - ResourceId rid = (ResourceId) id; + if (id instanceof ResourceId rid) { Filter.Id.ResourceId resourceId = new Filter.Id.ResourceId(); fid = resourceId; resourceId.setStartTime(rid.getStartTime()).setEndTime(rid.getEndTime()); - // .setVersion(rid.getVersion() == null ? null : - // rid.getVersion().toString()); } else if (id instanceof FeatureId) { fid = new Filter.Id.FeatureId(); } else { diff --git a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/MappingFilterVisitor.java b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/MappingFilterVisitor.java index 5b064e24b..7ce41783d 100644 --- a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/MappingFilterVisitor.java +++ b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/MappingFilterVisitor.java @@ -58,175 +58,218 @@ class MappingFilterVisitor implements FilterVisitor { this.mapper = mapper; } - public @Override Object visitNullFilter(Object extraData) { + @Override + public Object visitNullFilter(Object extraData) { throw new UnsupportedOperationException("not yet implemented"); } - public @Override Object visit(NativeFilter filter, Object extraData) { + @Override + public Object visit(NativeFilter filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(TOverlaps filter, Object extraData) { + @Override + public Object visit(TOverlaps filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(TEquals filter, Object extraData) { + @Override + public Object visit(TEquals filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(TContains filter, Object extraData) { + @Override + public Object visit(TContains filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(OverlappedBy filter, Object extraData) { + @Override + public Object visit(OverlappedBy filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(MetBy filter, Object extraData) { + @Override + public Object visit(MetBy filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(Meets filter, Object extraData) { + @Override + public Object visit(Meets filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(Ends filter, Object extraData) { + @Override + public Object visit(Ends filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(EndedBy filter, Object extraData) { + @Override + public Object visit(EndedBy filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(During filter, Object extraData) { + @Override + public Object visit(During filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(BegunBy filter, Object extraData) { + @Override + public Object visit(BegunBy filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(Begins filter, Object extraData) { + @Override + public Object visit(Begins filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(Before filter, Object extraData) { + @Override + public Object visit(Before filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(AnyInteracts filter, Object extraData) { + @Override + public Object visit(AnyInteracts filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(After filter, Object extraData) { + @Override + public Object visit(After filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(Within filter, Object extraData) { + @Override + public Object visit(Within filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(Touches filter, Object extraData) { + @Override + public Object visit(Touches filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(Overlaps filter, Object extraData) { + @Override + public Object visit(Overlaps filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(Intersects filter, Object extraData) { + @Override + public Object visit(Intersects filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(Equals filter, Object extraData) { + @Override + public Object visit(Equals filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(DWithin filter, Object extraData) { + @Override + public Object visit(DWithin filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(Disjoint filter, Object extraData) { + @Override + public Object visit(Disjoint filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(Crosses filter, Object extraData) { + @Override + public Object visit(Crosses filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(Contains filter, Object extraData) { + @Override + public Object visit(Contains filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(Beyond filter, Object extraData) { + @Override + public Object visit(Beyond filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(BBOX filter, Object extraData) { + @Override + public Object visit(BBOX filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(PropertyIsNil filter, Object extraData) { + @Override + public Object visit(PropertyIsNil filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(PropertyIsNull filter, Object extraData) { + @Override + public Object visit(PropertyIsNull filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(PropertyIsLike filter, Object extraData) { + @Override + public Object visit(PropertyIsLike filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(PropertyIsLessThanOrEqualTo filter, Object extraData) { + @Override + public Object visit(PropertyIsLessThanOrEqualTo filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(PropertyIsLessThan filter, Object extraData) { + @Override + public Object visit(PropertyIsLessThan filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(PropertyIsGreaterThanOrEqualTo filter, Object extraData) { + @Override + public Object visit(PropertyIsGreaterThanOrEqualTo filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(PropertyIsGreaterThan filter, Object extraData) { + @Override + public Object visit(PropertyIsGreaterThan filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(PropertyIsNotEqualTo filter, Object extraData) { + @Override + public Object visit(PropertyIsNotEqualTo filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(PropertyIsEqualTo filter, Object extraData) { + @Override + public Object visit(PropertyIsEqualTo filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(PropertyIsBetween filter, Object extraData) { + @Override + public Object visit(PropertyIsBetween filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(Or filter, Object extraData) { + @Override + public Object visit(Or filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(Not filter, Object extraData) { + @Override + public Object visit(Not filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(Id filter, Object extraData) { + @Override + public Object visit(Id filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(And filter, Object extraData) { + @Override + public Object visit(And filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(IncludeFilter filter, Object extraData) { + @Override + public Object visit(IncludeFilter filter, Object extraData) { return mapper.toDto(filter); } - public @Override Object visit(ExcludeFilter filter, Object extraData) { + @Override + public Object visit(ExcludeFilter filter, Object extraData) { return mapper.toDto(filter); } } diff --git a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/ValueMappers.java b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/ValueMappers.java index 6de6de2e7..22829f186 100644 --- a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/ValueMappers.java +++ b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/filter/mapper/ValueMappers.java @@ -29,7 +29,7 @@ public abstract org.geotools.api.filter.MultiValuedFilter.MatchAction matchActio public NamespaceSupport map(Map map) { if (map == null) return null; NamespaceSupport s = new NamespaceSupport(); - map.forEach((prefix, uri) -> s.declarePrefix(prefix, uri)); + map.forEach(s::declarePrefix); return s; } @@ -62,10 +62,9 @@ public Class canonicalNameToClass(String value) { if (null == value) return null; try { - Class clazz = Class.forName(value); - return clazz; + return Class.forName(value); } catch (ClassNotFoundException e) { - throw new RuntimeException(e); + throw new IllegalArgumentException(e); } } diff --git a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/geojson/geometry/GeometryDeserializer.java b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/geojson/geometry/GeometryDeserializer.java index 504cdebf6..4e4335ede 100644 --- a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/geojson/geometry/GeometryDeserializer.java +++ b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/geojson/geometry/GeometryDeserializer.java @@ -5,7 +5,6 @@ package org.geotools.jackson.databind.geojson.geometry; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; @@ -37,6 +36,8 @@ public class GeometryDeserializer extends JsonDeserializer { + private static final String COORDINATES_PROPERTY = "coordinates"; + private static final GeometryFactory DEFAULT_GF = new GeometryFactory(new PackedCoordinateSequenceFactory()); @@ -51,8 +52,8 @@ public GeometryDeserializer(GeometryFactory geometryFactory) { } @SuppressWarnings("unchecked") - public @Override T deserialize(JsonParser p, DeserializationContext ctxt) - throws IOException, JsonProcessingException { + @Override + public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { return (T) readGeometry(p.readValueAsTree()); } @@ -88,23 +89,23 @@ private Geometry readGeometry(ObjectNode geometryNode, int dimensions, boolean h private int getDimensions(ObjectNode geometryNode) { JsonNode dimensionsProperty = geometryNode.findValue("dimensions"); - if (dimensionsProperty instanceof NumericNode) { - return ((NumericNode) dimensionsProperty).asInt(); + if (dimensionsProperty instanceof NumericNode numericNode) { + return numericNode.asInt(); } return 2; } private boolean resolveHasM(ObjectNode geometryNode) { JsonNode hasMProperty = geometryNode.findValue("hasM"); - if (hasMProperty instanceof BooleanNode) { - return ((BooleanNode) hasMProperty).asBoolean(); + if (hasMProperty instanceof BooleanNode booleanNode) { + return booleanNode.asBoolean(); } return false; } private MultiLineString readMultiLineString( ObjectNode geometryNode, int dimensions, boolean hasM) { - ArrayNode coordinates = (ArrayNode) geometryNode.findValue("coordinates"); + ArrayNode coordinates = (ArrayNode) geometryNode.findValue(COORDINATES_PROPERTY); if (coordinates.isEmpty()) { return geometryFactory.createMultiLineString(); } @@ -120,7 +121,7 @@ private MultiLineString readMultiLineString( } private MultiPolygon readMultiPolygon(ObjectNode geometryNode, int dimensions, boolean hasM) { - ArrayNode coordinates = (ArrayNode) geometryNode.findValue("coordinates"); + ArrayNode coordinates = (ArrayNode) geometryNode.findValue(COORDINATES_PROPERTY); if (coordinates.isEmpty()) { return geometryFactory.createMultiPolygon(); } @@ -147,7 +148,7 @@ private GeometryCollection readGeometryCollection( } private Polygon readPolygon(ObjectNode geometryNode, int dimensions, boolean hasM) { - ArrayNode coordinates = (ArrayNode) geometryNode.findValue("coordinates"); + ArrayNode coordinates = (ArrayNode) geometryNode.findValue(COORDINATES_PROPERTY); return readPolygon(coordinates, dimensions, hasM); } @@ -181,7 +182,7 @@ private LinearRing readLinearRing(ArrayNode coordinates, int dimensions, boolean } private LineString readLineString(ObjectNode geometryNode, int dimensions, boolean hasM) { - ArrayNode coordinates = (ArrayNode) geometryNode.findValue("coordinates"); + ArrayNode coordinates = (ArrayNode) geometryNode.findValue(COORDINATES_PROPERTY); if (coordinates.isEmpty()) { return geometryFactory.createLineString(); } @@ -190,7 +191,7 @@ private LineString readLineString(ObjectNode geometryNode, int dimensions, boole } private MultiPoint readMultiPoint(ObjectNode geometryNode, int dimensions, boolean hasM) { - ArrayNode coordinates = (ArrayNode) geometryNode.findValue("coordinates"); + ArrayNode coordinates = (ArrayNode) geometryNode.findValue(COORDINATES_PROPERTY); if (null == coordinates || coordinates.isEmpty()) { return geometryFactory.createMultiPoint(); } @@ -214,7 +215,7 @@ private CoordinateSequence readCoordinateSequence( } private Point readPoint(ObjectNode geometryNode, int dimensions, boolean hasM) { - ArrayNode coordinateArray = (ArrayNode) geometryNode.findValue("coordinates"); + ArrayNode coordinateArray = (ArrayNode) geometryNode.findValue(COORDINATES_PROPERTY); if (null == coordinateArray || coordinateArray.isEmpty()) { return geometryFactory.createPoint(); } @@ -230,7 +231,7 @@ public static boolean isGeometry(JsonNode value) { return false; } JsonNode typeNode = value.get("type"); - return typeNode instanceof TextNode && isGeometry(((TextNode) typeNode).asText()); + return typeNode instanceof TextNode textNode && isGeometry(textNode.asText()); } private static final Set geomTypes = diff --git a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/geojson/geometry/GeometrySerializer.java b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/geojson/geometry/GeometrySerializer.java index 5da5b8363..a26f4e4f5 100644 --- a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/geojson/geometry/GeometrySerializer.java +++ b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/geojson/geometry/GeometrySerializer.java @@ -32,7 +32,8 @@ public GeometrySerializer() { super(Geometry.class); } - public @Override void serializeWithType( + @Override + public void serializeWithType( Geometry value, JsonGenerator gen, SerializerProvider serializers, @@ -47,8 +48,9 @@ public GeometrySerializer() { typeSer.writeTypeSuffix(gen, typeIdDef); } - public @Override void serialize( - Geometry value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + @Override + public void serialize(Geometry value, JsonGenerator gen, SerializerProvider serializers) + throws IOException { serialize(value, gen); } @@ -109,18 +111,18 @@ private void writeDimensions(Geometry geometry, JsonGenerator generator) throws private CoordinateSequence findSampleSequence(Geometry g) { if (g == null || g.isEmpty()) return null; - if (g instanceof GeometryCollection) { - return findSampleSequence(g.getGeometryN(0)); + if (g instanceof GeometryCollection col) { + return findSampleSequence(col.getGeometryN(0)); } - if (g instanceof Point) return ((Point) g).getCoordinateSequence(); - if (g instanceof LineString) return ((LineString) g).getCoordinateSequence(); - if (g instanceof Polygon) return findSampleSequence(((Polygon) g).getExteriorRing()); + if (g instanceof Point point) return point.getCoordinateSequence(); + if (g instanceof LineString line) return line.getCoordinateSequence(); + if (g instanceof Polygon poly) return findSampleSequence(poly.getExteriorRing()); return null; } private void writeGeometry(Geometry geometry, JsonGenerator generator) throws IOException { - if (geometry instanceof GeometryCollection) { - writeMultiGeom((GeometryCollection) geometry, generator); + if (geometry instanceof GeometryCollection col) { + writeMultiGeom(col, generator); } else { writeSimpleGeom(geometry, generator); } @@ -141,11 +143,9 @@ private void writeSimpleGeom(Geometry geometry, JsonGenerator generator) throws generator.writeEndArray(); return; } - if (geometry instanceof Point) { - Point p = (Point) geometry; + if (geometry instanceof Point p) { writeCoordinate(p.getCoordinateSequence(), 0, generator); - } else if (geometry instanceof Polygon) { - Polygon poly = (Polygon) geometry; + } else if (geometry instanceof Polygon poly) { generator.writeStartArray(); writeCoordinateSequence(poly.getExteriorRing(), generator); for (int r = 0; r < poly.getNumInteriorRing(); r++) { @@ -162,15 +162,18 @@ private void writeCoordinateSequence(Geometry simpleGeom, JsonGenerator generato final AtomicReference seqRef = new AtomicReference<>(); simpleGeom.apply( new CoordinateSequenceFilter() { - public @Override void filter(CoordinateSequence seq, int i) { + @Override + public void filter(CoordinateSequence seq, int i) { seqRef.set(seq); } - public @Override boolean isGeometryChanged() { + @Override + public boolean isGeometryChanged() { return false; } - public @Override boolean isDone() { + @Override + public boolean isDone() { return true; } }); diff --git a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/util/MapperDeserializer.java b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/util/MapperDeserializer.java index 1c8d84849..f7e799b89 100644 --- a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/util/MapperDeserializer.java +++ b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/util/MapperDeserializer.java @@ -5,7 +5,6 @@ package org.geotools.jackson.databind.util; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; @@ -27,8 +26,8 @@ public class MapperDeserializer extends JsonDeserializer { private final @NonNull Class from; private final Function mapper; - public @Override T deserialize(JsonParser parser, DeserializationContext ctxt) - throws IOException, JsonProcessingException { + @Override + public T deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException { DTO dto; T value; diff --git a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/util/MapperSerializer.java b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/util/MapperSerializer.java index 45398e46c..e174216a9 100644 --- a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/util/MapperSerializer.java +++ b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/util/MapperSerializer.java @@ -26,7 +26,7 @@ public class MapperSerializer extends StdSerializer { private static final long serialVersionUID = 1L; - private Function mapper; + private final transient Function mapper; private Class type; @@ -36,7 +36,8 @@ public MapperSerializer(Class type, java.util.function.Function seria this.mapper = serializerMapper; } - public @Override void serializeWithType( + @Override + public void serializeWithType( I value, JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { @@ -48,7 +49,8 @@ public MapperSerializer(Class type, java.util.function.Function seria typeSer.writeTypeSuffix(gen, typeIdDef); } - public @Override void serialize(I value, JsonGenerator gen, SerializerProvider provider) + @Override + public void serialize(I value, JsonGenerator gen, SerializerProvider provider) throws IOException { DTO dto; diff --git a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/util/ObjectMapperUtil.java b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/util/ObjectMapperUtil.java index 2d9d79568..8efdf2273 100644 --- a/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/util/ObjectMapperUtil.java +++ b/src/catalog/jackson-bindings/geotools/src/main/java/org/geotools/jackson/databind/util/ObjectMapperUtil.java @@ -11,11 +11,14 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; +import lombok.experimental.UtilityClass; + import org.yaml.snakeyaml.DumperOptions.Version; /** * @since 1.0 */ +@UtilityClass public class ObjectMapperUtil { public static ObjectMapper newObjectMapper() { diff --git a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/ExpressionRoundtripTest.java b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/ExpressionRoundtripTest.java index 6677158a3..ab95f8eee 100644 --- a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/ExpressionRoundtripTest.java +++ b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/ExpressionRoundtripTest.java @@ -46,7 +46,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.IntStream; /** @@ -67,17 +66,20 @@ protected void print(String logmsg, Object... args) { protected abstract Expression.FunctionName roundtripTest(Expression.FunctionName dto) throws Exception; - public @Test void propertySimple() throws Exception { + @Test + void propertySimple() throws Exception { PropertyName dto = propertyName("states"); roundtripTest(dto); } - public @Test void propertyNamePrefixedNoNamespaceContext() throws Exception { + @Test + void propertyNamePrefixedNoNamespaceContext() throws Exception { PropertyName dto = propertyName("topp:states"); roundtripTest(dto); } - public @Test void propertyNameNamespaceContext() throws Exception { + @Test + void propertyNameNamespaceContext() throws Exception { PropertyName dto = propertyName("topp:states"); Map context = new HashMap<>(); // automatically added by NamespaceSupport @@ -88,7 +90,8 @@ protected abstract Expression.FunctionName roundtripTest(Expression.FunctionName roundtripTest(dto); } - public @Test void binaryExpressionAdd() throws Exception { + @Test + void binaryExpressionAdd() throws Exception { BinaryExpression dto = new Add() .setExpression1(propertyName("name")) @@ -96,45 +99,54 @@ protected abstract Expression.FunctionName roundtripTest(Expression.FunctionName roundtripTest(dto); } - public @Test void binaryExpressionSubtract() throws Exception { + @Test + void binaryExpressionSubtract() throws Exception { BinaryExpression dto = new Subtract().setExpression1(propertyName("name")).setExpression2(literal(1000)); roundtripTest(dto); } - public @Test void binaryExpressionDivide() throws Exception { + @Test + void binaryExpressionDivide() throws Exception { BinaryExpression dto = new Divide().setExpression1(propertyName("name")).setExpression2(literal(1000)); roundtripTest(dto); } - public @Test void binaryExpressionMultiply() throws Exception { + @Test + void binaryExpressionMultiply() throws Exception { BinaryExpression dto = new Multiply().setExpression1(propertyName("name")).setExpression2(literal(1000)); roundtripTest(dto); } - public @Test void literalNull() throws Exception { + @Test + void literalNull() throws Exception { roundtripTest(literal(null)); } - public @Test void literalInteger() throws Exception { + @Test + void literalInteger() throws Exception { roundtripTest(literal(Integer.MIN_VALUE)); } - public @Test void literalLong() throws Exception { + @Test + void literalLong() throws Exception { roundtripTest(literal(Long.MAX_VALUE)); } - public @Test void literalDouble() throws Exception { + @Test + void literalDouble() throws Exception { roundtripTest(literal(0.5d)); } - public @Test void literalFloat() throws Exception { + @Test + void literalFloat() throws Exception { roundtripTest(literal(Float.MIN_VALUE)); } - public @Test void literalBigInteger() throws Exception { + @Test + void literalBigInteger() throws Exception { roundtripTest( literal( BigInteger.valueOf(Long.MAX_VALUE) @@ -145,51 +157,61 @@ protected abstract Expression.FunctionName roundtripTest(Expression.FunctionName .subtract(BigInteger.valueOf(Long.MAX_VALUE)))); } - public @Test void literalBigDecimal() throws Exception { + @Test + void literalBigDecimal() throws Exception { roundtripTest( literal( BigDecimal.valueOf(Double.MAX_VALUE) .add(BigDecimal.valueOf(Double.MAX_VALUE)))); } - public @Test void literalGeometry() throws Exception { + @Test + void literalGeometry() throws Exception { roundtripTest(literal(samplePoint())); } - public @Test void literalJavaUtilDate() throws Exception { + @Test + void literalJavaUtilDate() throws Exception { roundtripTest(literal(new java.util.Date())); } - public @Test void literalInstant() throws Exception { + @Test + void literalInstant() throws Exception { // use a value with rounded-up nanos, some JVM implementations will not get the same exact // value after marshalling/unmarshalling Instant literal = Instant.ofEpochMilli(Instant.now().toEpochMilli()).plusNanos(1000); roundtripTest(literal(literal)); } - public @Test void literalAwtColor() throws Exception { + @Test + void literalAwtColor() throws Exception { roundtripTest(literal(Color.GREEN)); } - public @Test void literalEnum() throws Exception { + @Test + void literalEnum() throws Exception { roundtripTest(literal(Geometries.MULTILINESTRING)); } @Disabled("no jackson module can handle serialization/deserialization") - public @Test void literalJavaxMeassureUnit() throws Exception { + @Test + void literalJavaxMeassureUnit() throws Exception { roundtripTest(literal(SI.ASTRONOMICAL_UNIT)); } - public @Test void literalList() throws Exception { + @Test + void literalList() throws Exception { roundtripTest(literal(List.of(1, 2, 3, 4))); roundtripTest(literal(List.of(new Date(1), new Date(2), new Date(3)))); } - public @Test void literalListEmpty() throws Exception { + @Test + void literalListEmpty() throws Exception { roundtripTest(literal(List.of())); } - public @Test void literalListMixedContent() throws Exception { + @Test + void literalListMixedContent() throws Exception { List value = Arrays.asList(1, null, new java.util.Date(1), List.of(4, 5, 6)); try { roundtripTest(literal(value)); @@ -199,39 +221,47 @@ protected abstract Expression.FunctionName roundtripTest(Expression.FunctionName } } - public @Test void literalSetEmpty() throws Exception { + @Test + void literalSetEmpty() throws Exception { roundtripTest(literal(Set.of())); } - public @Test void literalSet() throws Exception { + @Test + void literalSet() throws Exception { roundtripTest(literal(Set.of(1, 2, 3, 4))); roundtripTest(literal(Set.of(new Date(1), new Date(2), new Date(3)))); } - public @Test void literalSetMixedContent() throws Exception { + @Test + void literalSetMixedContent() throws Exception { Set value = Set.of(1, new java.util.Date(1), Set.of(4, 5, 6)); roundtripTest(literal(value)); } - public @Test void literalMapEmpty() throws Exception { + @Test + void literalMapEmpty() throws Exception { roundtripTest(literal(Map.of())); roundtripTest(literal(Collections.emptyMap())); roundtripTest(literal(new HashMap<>())); } - public @Test void literalMapSingle() throws Exception { + @Test + void literalMapSingle() throws Exception { roundtripTest(literal(Map.of("k1", 1))); } - public @Test void literalMap() throws Exception { + @Test + void literalMap() throws Exception { roundtripTest(literal(Map.of("k1", 1, "k2", 2, "k3", 3, "k4", 4))); } - public @Test void literalMapMixedContent() throws Exception { + @Test + void literalMapMixedContent() throws Exception { roundtripTest(literal(Map.of("k1", 1, "k2", 2L, "k3", 3F, "k4", 4D, "k5", "svalue"))); } - public @Test void literalArrayEmpty() throws Exception { + @Test + void literalArrayEmpty() throws Exception { roundtripTest(literal(new byte[0])); roundtripTest(literal(new char[0])); roundtripTest(literal(new boolean[0])); @@ -244,7 +274,8 @@ protected abstract Expression.FunctionName roundtripTest(Expression.FunctionName roundtripTest(literal(new Date[0])); } - public @Test void literalArray() throws Exception { + @Test + void literalArray() throws Exception { roundtripTest(literal(new byte[] {1})); roundtripTest(literal(new byte[] {0, 1, 2, 3})); @@ -286,7 +317,8 @@ private Geometry sampleLineString() { } } - public @Test void allAvailableFunctions() throws Exception { + @Test + void allAvailableFunctions() throws Exception { // build a list of ignored function names, due to inability to serialize/deserialize their // argument types Set ignore = @@ -321,12 +353,13 @@ private Geometry sampleLineString() { } } - public @Test void allAvailableFunctionNames() throws Exception { + @Test + void allAvailableFunctionNames() throws Exception { FunctionFinder finder = new FunctionFinder(null); List allFunctionDescriptions = finder.getAllFunctionDescriptions().stream() .sorted((f1, f2) -> f1.getName().compareTo(f2.getName())) - .collect(Collectors.toList()); + .toList(); for (FunctionName functionName : allFunctionDescriptions) { testFunctionNameRoundtrip(functionName); } @@ -389,9 +422,7 @@ private List buildParameters(int argumentCount, List> a private List buildSampleParameter(Parameter p) { int occurs = p.isRequired().booleanValue() ? p.getMinOccurs() : 1; - return IntStream.range(0, occurs) - .mapToObj(i -> buildSampleParam(i, p)) - .collect(Collectors.toList()); + return IntStream.range(0, occurs).mapToObj(i -> buildSampleParam(i, p)).toList(); } // static Set allFunctionParamTypes = new TreeSet<>(); diff --git a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/FilterRoundtripTest.java b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/FilterRoundtripTest.java index 2593cf729..13df5237a 100644 --- a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/FilterRoundtripTest.java +++ b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/FilterRoundtripTest.java @@ -44,22 +44,26 @@ public abstract class FilterRoundtripTest { protected abstract void roundtripTest(org.geotools.jackson.databind.filter.dto.SortBy dto) throws Exception; - public @Test void include() throws Exception { + @Test + void include() throws Exception { Filter filter = Filter.INCLUDE; roundtripTest(filter); } - public @Test void exclude() throws Exception { + @Test + void exclude() throws Exception { Filter filter = Filter.EXCLUDE; roundtripTest(filter); } - public @Test void nativeFilter() throws Exception { + @Test + void nativeFilter() throws Exception { Filter filter = new Filter.NativeFilter().setNative("select * from test_data;"); roundtripTest(filter); } - public @Test void idFilter_FeatureId_Simple() throws Exception { + @Test + void idFilter_FeatureId_Simple() throws Exception { Set identifiers = new HashSet<>(); identifiers.add(new Filter.Id.FeatureId().setId("states.1")); identifiers.add(new Filter.Id.FeatureId().setId("states.2")); @@ -67,7 +71,8 @@ protected abstract void roundtripTest(org.geotools.jackson.databind.filter.dto.S roundtripTest(filter); } - public @Test void idFilter_FeatureId_FeatureVersion() throws Exception { + @Test + void idFilter_FeatureId_FeatureVersion() throws Exception { Set identifiers = new HashSet<>(); identifiers.add(new Filter.Id.FeatureId().setFeatureVersion("v1").setId("states.1")); identifiers.add(new Filter.Id.FeatureId().setFeatureVersion("v1.1").setId("states.2")); @@ -75,7 +80,8 @@ protected abstract void roundtripTest(org.geotools.jackson.databind.filter.dto.S roundtripTest(filter); } - public @Test void idFilter_ResourceId_Date() throws Exception { + @Test + void idFilter_ResourceId_Date() throws Exception { Set identifiers = new HashSet<>(); identifiers.add( new Filter.Id.ResourceId() @@ -93,7 +99,8 @@ protected abstract void roundtripTest(org.geotools.jackson.databind.filter.dto.S roundtripTest(filter); } - public @Test void notFilter() throws Exception { + @Test + void notFilter() throws Exception { Set identifiers = new HashSet<>(); identifiers.add(new Filter.Id.FeatureId().setId("states.1")); identifiers.add(new Filter.Id.FeatureId().setId("states.2")); @@ -102,12 +109,14 @@ protected abstract void roundtripTest(org.geotools.jackson.databind.filter.dto.S roundtripTest(notInFilter); } - public @Test void propertyIsNul() throws Exception { + @Test + void propertyIsNul() throws Exception { Filter filter = isNullFilter(); roundtripTest(filter); } - public @Test void sortBy() throws Exception { + @Test + void sortBy() throws Exception { SortBy dto = new SortBy(propertyName("some.property.name"), SortBy.SortOrder.ASCENDING); roundtripTest(dto); dto = new SortBy(propertyName("collprop[1]"), SortBy.SortOrder.DESCENDING); @@ -119,7 +128,8 @@ private PropertyIsNull isNullFilter() { .setExpression(new Expression.PropertyName().setPropertyName("name")); } - public @Test void propertyIsNil() throws Exception { + @Test + void propertyIsNil() throws Exception { Filter filter = new Filter.PropertyIsNil() .setExpression(new Expression.PropertyName().setPropertyName("name")) @@ -127,7 +137,8 @@ private PropertyIsNull isNullFilter() { roundtripTest(filter); } - public @Test void propertyIsLike() throws Exception { + @Test + void propertyIsLike() throws Exception { MultiValuedFilter filter = new Filter.PropertyIsLike() .setExpression(propertyName("text")) @@ -140,7 +151,8 @@ private PropertyIsNull isNullFilter() { roundtripTest(filter); } - public @Test void propertyIsBetween() throws Exception { + @Test + void propertyIsBetween() throws Exception { MultiValuedFilter dto = new Filter.PropertyIsBetween() .setExpression(propertyName("count")) @@ -150,19 +162,22 @@ private PropertyIsNull isNullFilter() { roundtripTest(dto); } - public @Test void andFilter() throws Exception { + @Test + void andFilter() throws Exception { List children = Arrays.asList(Filter.INCLUDE, isNullFilter()); Filter filter = new Filter.BinaryLogicOperator.And().setChildren(children); roundtripTest(filter); } - public @Test void orFilter() throws Exception { + @Test + void orFilter() throws Exception { List children = Arrays.asList(Filter.INCLUDE, isNullFilter()); Filter filter = new Filter.BinaryLogicOperator.Or().setChildren(children); roundtripTest(filter); } - public @Test void binaryComparisonOperators() throws Exception { + @Test + void binaryComparisonOperators() throws Exception { testBinaryComparisonOperator(Filter.BinaryComparisonOperator.PropertyIsEqualTo::new); testBinaryComparisonOperator(Filter.BinaryComparisonOperator.PropertyIsNotEqualTo::new); testBinaryComparisonOperator(Filter.BinaryComparisonOperator.PropertyIsLessThan::new); @@ -183,7 +198,8 @@ private void testBinaryComparisonOperator(Supplier fac roundtripTest(filter); } - public @Test void binarySpatialOperators() throws Exception { + @Test + void binarySpatialOperators() throws Exception { testBinarySpatialOperator(Filter.BinarySpatialOperator.BBOX::new); testBinarySpatialOperator(Filter.BinarySpatialOperator.Contains::new); testBinarySpatialOperator(Filter.BinarySpatialOperator.Crosses::new); @@ -195,7 +211,8 @@ private void testBinaryComparisonOperator(Supplier fac testBinarySpatialOperator(Filter.BinarySpatialOperator.Within::new); } - public @Test void binaryTemporalOperators() throws Exception { + @Test + void binaryTemporalOperators() throws Exception { testBinaryTemporalOperator(Filter.BinaryTemporalOperator.After::new); testBinaryTemporalOperator(Filter.BinaryTemporalOperator.AnyInteracts::new); testBinaryTemporalOperator(Filter.BinaryTemporalOperator.Before::new); @@ -212,7 +229,8 @@ private void testBinaryComparisonOperator(Supplier fac testBinaryTemporalOperator(Filter.BinaryTemporalOperator.TOverlaps::new); } - public @Test void distanceBufferOperators() throws Exception { + @Test + void distanceBufferOperators() throws Exception { testDistanceBufferOperator(Filter.BinarySpatialOperator.Beyond::new); testDistanceBufferOperator(Filter.BinarySpatialOperator.DWithin::new); } diff --git a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleExpressionsTest.java b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleExpressionsTest.java index 2b2203649..155fa3704 100644 --- a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleExpressionsTest.java +++ b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleExpressionsTest.java @@ -47,15 +47,14 @@ public abstract class GeoToolsFilterModuleExpressionsTest extends ExpressionRoun objectMapper.readValue( serialized, org.geotools.api.filter.expression.Expression.class); - if (expected instanceof Function) { - assertTrue(deserialized instanceof Function); - Function f1 = (Function) expected; + if (expected instanceof Function f1) { + assertThat(deserialized).isInstanceOf(Function.class); Function f2 = (Function) deserialized; assertEquals(f1.getName(), f2.getName()); assertEquals(f1.getParameters(), f2.getParameters()); - } else if (expected instanceof Literal) { + } else if (expected instanceof Literal literal) { assertThat(deserialized).isInstanceOf(Literal.class); - Object v1 = ((Literal) expected).getValue(); + Object v1 = literal.getValue(); Object v2 = ((Literal) deserialized).getValue(); boolean valueEquals = org.geotools.jackson.databind.filter.dto.Literal.valueEquals(v1, v2); diff --git a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleExpressions_JsonTest.java b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleExpressions_JsonTest.java index 147f785b4..1a4f080ca 100644 --- a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleExpressions_JsonTest.java +++ b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleExpressions_JsonTest.java @@ -11,7 +11,7 @@ /** * @since 1.0 */ -public class GeoToolsFilterModuleExpressions_JsonTest extends GeoToolsFilterModuleExpressionsTest { +class GeoToolsFilterModuleExpressions_JsonTest extends GeoToolsFilterModuleExpressionsTest { protected @Override ObjectMapper newObjectMapper() { return ObjectMapperUtil.newObjectMapper(); diff --git a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleExpressions_YamlTest.java b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleExpressions_YamlTest.java index aeec8e11f..c0bf298ef 100644 --- a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleExpressions_YamlTest.java +++ b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleExpressions_YamlTest.java @@ -11,7 +11,7 @@ /** * @since 1.0 */ -public class GeoToolsFilterModuleExpressions_YamlTest extends GeoToolsFilterModuleExpressionsTest { +class GeoToolsFilterModuleExpressions_YamlTest extends GeoToolsFilterModuleExpressionsTest { protected @Override ObjectMapper newObjectMapper() { return ObjectMapperUtil.newYAMLObjectMapper(); diff --git a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleFiltersTest.java b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleFiltersTest.java index fa6518a66..37c1946b3 100644 --- a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleFiltersTest.java +++ b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleFiltersTest.java @@ -62,5 +62,6 @@ protected void print(String logmsg, Object... args) { @Disabled("revisit, ResourceIdImpl equals issue") @Override - public @Test void idFilter_ResourceId_Date() throws Exception {} + @Test + void idFilter_ResourceId_Date() throws Exception {} } diff --git a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleFilters_JsonTest.java b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleFilters_JsonTest.java index dc42d6903..c417a3a73 100644 --- a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleFilters_JsonTest.java +++ b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleFilters_JsonTest.java @@ -11,7 +11,7 @@ /** * @since 1.0 */ -public class GeoToolsFilterModuleFilters_JsonTest extends GeoToolsFilterModuleFiltersTest { +class GeoToolsFilterModuleFilters_JsonTest extends GeoToolsFilterModuleFiltersTest { protected @Override ObjectMapper newObjectMapper() { return ObjectMapperUtil.newObjectMapper(); diff --git a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleFilters_YamlTest.java b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleFilters_YamlTest.java index 6c18d9b0b..a065530f6 100644 --- a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleFilters_YamlTest.java +++ b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/GeoToolsFilterModuleFilters_YamlTest.java @@ -11,7 +11,7 @@ /** * @since 1.0 */ -public class GeoToolsFilterModuleFilters_YamlTest extends GeoToolsFilterModuleFiltersTest { +class GeoToolsFilterModuleFilters_YamlTest extends GeoToolsFilterModuleFiltersTest { protected @Override ObjectMapper newObjectMapper() { return ObjectMapperUtil.newYAMLObjectMapper(); diff --git a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/dto/ExpressionSerializationTest.java b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/dto/ExpressionSerializationTest.java index ef0742fac..b92265c11 100644 --- a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/dto/ExpressionSerializationTest.java +++ b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/dto/ExpressionSerializationTest.java @@ -13,7 +13,7 @@ import org.geotools.jackson.databind.util.ObjectMapperUtil; import org.junit.jupiter.api.BeforeAll; -public class ExpressionSerializationTest extends ExpressionRoundtripTest { +class ExpressionSerializationTest extends ExpressionRoundtripTest { private static ObjectMapper objectMapper; diff --git a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/dto/FilterSerializationTest.java b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/dto/FilterSerializationTest.java index b8cc49d45..d57fafed2 100644 --- a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/dto/FilterSerializationTest.java +++ b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/dto/FilterSerializationTest.java @@ -15,7 +15,7 @@ import org.junit.jupiter.api.BeforeAll; @Slf4j -public class FilterSerializationTest extends FilterRoundtripTest { +class FilterSerializationTest extends FilterRoundtripTest { protected void print(String logmsg, Object... args) { boolean debug = Boolean.getBoolean("debug"); diff --git a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/mapper/ExpressionMapperTest.java b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/mapper/ExpressionMapperTest.java index cc8fde7e8..5fa6ffa05 100644 --- a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/mapper/ExpressionMapperTest.java +++ b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/mapper/ExpressionMapperTest.java @@ -13,7 +13,7 @@ import org.junit.jupiter.api.BeforeEach; import org.mapstruct.factory.Mappers; -public class ExpressionMapperTest extends ExpressionRoundtripTest { +class ExpressionMapperTest extends ExpressionRoundtripTest { private ExpressionMapper expressions; diff --git a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/mapper/FilterMapperTest.java b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/mapper/FilterMapperTest.java index c5acfa0d7..34771bb53 100644 --- a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/mapper/FilterMapperTest.java +++ b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/filter/mapper/FilterMapperTest.java @@ -13,7 +13,7 @@ import org.junit.jupiter.api.BeforeEach; import org.mapstruct.factory.Mappers; -public class FilterMapperTest extends FilterRoundtripTest { +class FilterMapperTest extends FilterRoundtripTest { private FilterMapper filterMapper; diff --git a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/geojson/GeoToolsGeoJsonModuleTest.java b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/geojson/GeoToolsGeoJsonModuleTest.java index 757ce60ae..d4d19da99 100644 --- a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/geojson/GeoToolsGeoJsonModuleTest.java +++ b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/geojson/GeoToolsGeoJsonModuleTest.java @@ -50,7 +50,8 @@ protected void print(String logmsg, Object... args) { protected abstract ObjectMapper newObjectMapper(); - public @Test void testEmptyGeometries() throws JsonProcessingException { + @Test + void testEmptyGeometries() throws JsonProcessingException { roundtripTest("POINT EMPTY"); roundtripTest("LINESTRING EMPTY"); roundtripTest("POLYGON EMPTY"); @@ -60,35 +61,40 @@ protected void print(String logmsg, Object... args) { roundtripTest("GEOMETRYCOLLECTION EMPTY"); } - public @Test void testPoint() throws JsonProcessingException { + @Test + void testPoint() throws JsonProcessingException { roundtripTest("POINT(0 1)"); roundtripTest("POINT Z(0 1 2)"); roundtripTest("POINT M(0 1 3)"); roundtripTest("POINT ZM(0 1 2 3)"); } - public @Test void testMultiPoint() throws JsonProcessingException { + @Test + void testMultiPoint() throws JsonProcessingException { roundtripTest("MULTIPOINT(0 1, -1 -2)"); roundtripTest("MULTIPOINT Z(0 1 2, -1 -2 -3)"); roundtripTest("MULTIPOINT M(0 1 3, -1 -2 -4)"); roundtripTest("MULTIPOINT ZM(0 1 2 3, -1 -2 -3 -4)"); } - public @Test void testLineString() throws JsonProcessingException { + @Test + void testLineString() throws JsonProcessingException { roundtripTest("LINESTRING(0 1, 4 5)"); roundtripTest("LINESTRING Z(0 1 2, 4 5 6)"); roundtripTest("LINESTRING M(0 1 3, 4 5 7)"); roundtripTest("LINESTRING ZM(0 1 2 3, 4 5 6 7)"); } - public @Test void testMultiLineString() throws JsonProcessingException { + @Test + void testMultiLineString() throws JsonProcessingException { roundtripTest("MULTILINESTRING((0 1, 4 5), (-1 -2, -5 -6))"); roundtripTest("MULTILINESTRING Z((0 1 2, 4 5 6), (-1 -2 -3, -5 -6 -7))"); roundtripTest("MULTILINESTRING M((0 1 3, 4 5 7), (-1 -2 -4, -5 -6 -8))"); roundtripTest("MULTILINESTRING ZM((0 1 2 3, 4 5 6 7), (-1 -2 -3 -4, -5 -6 -7 -8))"); } - public @Test void testPolygon() throws JsonProcessingException { + @Test + void testPolygon() throws JsonProcessingException { roundtripTest("POLYGON ((0 0, 10 10, 20 0, 0 0),(1 1, 9 9, 19 1, 1 1))"); roundtripTest("POLYGON Z((0 0 0, 10 10 1, 20 0 2, 0 0 0),(1 1 1, 9 9 2, 19 1 3, 1 1 1))"); roundtripTest("POLYGON M((0 0 0, 10 10 1, 20 0 2, 0 0 0),(1 1 1, 9 9 2, 19 1 3, 1 1 1))"); @@ -96,7 +102,8 @@ protected void print(String logmsg, Object... args) { "POLYGON ZM((0 0 0 0, 10 10 1 1, 20 0 2 2, 0 0 0 0),(1 1 1 1, 9 9 2 2, 19 1 3 3, 1 1 1 1))"); } - public @Test void testMultiPolygon() throws JsonProcessingException { + @Test + void testMultiPolygon() throws JsonProcessingException { roundtripTest("MULTIPOLYGON (((0 0, 10 10, 20 0, 0 0)), ((1 1, 9 9, 19 1, 1 1)))"); roundtripTest( "MULTIPOLYGON Z(((0 0 0, 10 10 1, 20 0 2, 0 0 0)), ((1 1 1, 9 9 2, 19 1 3, 1 1 1)))"); @@ -106,7 +113,8 @@ protected void print(String logmsg, Object... args) { "MULTIPOLYGON ZM(((0 0 0 0, 10 10 1 1, 20 0 2 2, 0 0 0 0)), ((1 1 1 1, 9 9 2 2, 19 1 3 3, 1 1 1 1)))"); } - public @Test void testGeometryCollection() throws JsonProcessingException { + @Test + void testGeometryCollection() throws JsonProcessingException { roundtripTest( "GEOMETRYCOLLECTION(POINT EMPTY," + "POLYGON ((0 0, 10 10, 20 0, 0 0),(1 1, 9 9, 19 1, 1 1))," @@ -177,12 +185,12 @@ private String toWKT(Geometry orig) { private CoordinateSequence findCoordSeq(Geometry g) { if (g == null || g.isEmpty()) return null; - if (g instanceof GeometryCollection) { - return findCoordSeq(g.getGeometryN(0)); + if (g instanceof GeometryCollection col) { + return findCoordSeq(col.getGeometryN(0)); } - if (g instanceof Point) return ((Point) g).getCoordinateSequence(); - if (g instanceof LineString) return ((LineString) g).getCoordinateSequence(); - if (g instanceof Polygon) return findCoordSeq(((Polygon) g).getExteriorRing()); + if (g instanceof Point point) return point.getCoordinateSequence(); + if (g instanceof LineString line) return line.getCoordinateSequence(); + if (g instanceof Polygon poly) return findCoordSeq(poly.getExteriorRing()); return null; } diff --git a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/geojson/GeoToolsGeoJsonModule_JsonTest.java b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/geojson/GeoToolsGeoJsonModule_JsonTest.java index f1aeeecbd..a4cc04cad 100644 --- a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/geojson/GeoToolsGeoJsonModule_JsonTest.java +++ b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/geojson/GeoToolsGeoJsonModule_JsonTest.java @@ -11,7 +11,7 @@ /** * @since 1.0 */ -public class GeoToolsGeoJsonModule_JsonTest extends GeoToolsGeoJsonModuleTest { +class GeoToolsGeoJsonModule_JsonTest extends GeoToolsGeoJsonModuleTest { protected @Override ObjectMapper newObjectMapper() { return ObjectMapperUtil.newObjectMapper(); diff --git a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/geojson/GeoToolsGeoJsonModule_YamlTest.java b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/geojson/GeoToolsGeoJsonModule_YamlTest.java index 643b1cbe5..fc2076189 100644 --- a/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/geojson/GeoToolsGeoJsonModule_YamlTest.java +++ b/src/catalog/jackson-bindings/geotools/src/test/java/org/geotools/jackson/databind/geojson/GeoToolsGeoJsonModule_YamlTest.java @@ -11,7 +11,7 @@ /** * @since 1.0 */ -public class GeoToolsGeoJsonModule_YamlTest extends GeoToolsGeoJsonModuleTest { +class GeoToolsGeoJsonModule_YamlTest extends GeoToolsGeoJsonModuleTest { protected @Override ObjectMapper newObjectMapper() { return ObjectMapperUtil.newObjectMapper(); diff --git a/src/catalog/jackson-bindings/starter/src/test/java/org/geoserver/cloud/autoconfigure/jackson/GeoServerJacksonBindingsAutoConfigurationTest.java b/src/catalog/jackson-bindings/starter/src/test/java/org/geoserver/cloud/autoconfigure/jackson/GeoServerJacksonBindingsAutoConfigurationTest.java index 881700122..d0afb16ba 100644 --- a/src/catalog/jackson-bindings/starter/src/test/java/org/geoserver/cloud/autoconfigure/jackson/GeoServerJacksonBindingsAutoConfigurationTest.java +++ b/src/catalog/jackson-bindings/starter/src/test/java/org/geoserver/cloud/autoconfigure/jackson/GeoServerJacksonBindingsAutoConfigurationTest.java @@ -20,7 +20,7 @@ import java.util.Set; -public class GeoServerJacksonBindingsAutoConfigurationTest { +class GeoServerJacksonBindingsAutoConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() @@ -29,7 +29,8 @@ public class GeoServerJacksonBindingsAutoConfigurationTest { GeoServerJacksonBindingsAutoConfiguration.class, JacksonAutoConfiguration.class)); - public @Test void testObjectMapper() { + @Test + void testObjectMapper() { this.contextRunner.run(context -> assertThat(context).hasSingleBean(ObjectMapper.class)); Condition> condition = matching( diff --git a/src/catalog/jackson-bindings/starter/src/test/java/org/geoserver/cloud/autoconfigure/jackson/GeoToolsJacksonBindingsAutoConfigurationTest.java b/src/catalog/jackson-bindings/starter/src/test/java/org/geoserver/cloud/autoconfigure/jackson/GeoToolsJacksonBindingsAutoConfigurationTest.java index 2e3e361e5..cc8ec1ed2 100644 --- a/src/catalog/jackson-bindings/starter/src/test/java/org/geoserver/cloud/autoconfigure/jackson/GeoToolsJacksonBindingsAutoConfigurationTest.java +++ b/src/catalog/jackson-bindings/starter/src/test/java/org/geoserver/cloud/autoconfigure/jackson/GeoToolsJacksonBindingsAutoConfigurationTest.java @@ -22,7 +22,7 @@ import java.util.Set; -public class GeoToolsJacksonBindingsAutoConfigurationTest { +class GeoToolsJacksonBindingsAutoConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() @@ -31,7 +31,8 @@ public class GeoToolsJacksonBindingsAutoConfigurationTest { GeoToolsJacksonBindingsAutoConfiguration.class, JacksonAutoConfiguration.class)); - public @Test void testObjectMapper() { + @Test + void testObjectMapper() { this.contextRunner.run(context -> assertThat(context).hasSingleBean(ObjectMapper.class)); Condition> condition = matching( @@ -47,23 +48,27 @@ public class GeoToolsJacksonBindingsAutoConfigurationTest { .has(condition)); } - public @Test void testFilterModuleAutoConfiguration() { + @Test + void testFilterModuleAutoConfiguration() { this.contextRunner.run( context -> assertThat(context).hasSingleBean(GeoToolsFilterModule.class)); } - public @Test void testGeoJsonModuleAutoConfiguration() { + @Test + void testGeoJsonModuleAutoConfiguration() { this.contextRunner.run( context -> assertThat(context).hasSingleBean(GeoToolsGeoJsonModule.class)); } - public @Test void testFilterModuleNotInClassPath() { + @Test + void testFilterModuleNotInClassPath() { this.contextRunner .withClassLoader(new FilteredClassLoader(GeoToolsFilterModule.class)) .run(context -> assertThat(context).doesNotHaveBean(GeoToolsFilterModule.class)); } - public @Test void testGeoJsonModuleNotInClassPath() { + @Test + void testGeoJsonModuleNotInClassPath() { this.contextRunner .withClassLoader(new FilteredClassLoader(GeoToolsFilterModule.class)) .run(context -> assertThat(context).doesNotHaveBean(GeoToolsGeoJsonModule.class)); diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogFacadeExtensionAdapter.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogFacadeExtensionAdapter.java index e256cbc86..33bc030cc 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogFacadeExtensionAdapter.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogFacadeExtensionAdapter.java @@ -73,7 +73,8 @@ public CatalogFacadeExtensionAdapter(CatalogFacade facade) { } } - public @Override void setCatalog(Catalog catalog) { + @Override + public void setCatalog(Catalog catalog) { if (catalog != null) { if (!(catalog instanceof CatalogPlugin)) { throw new IllegalArgumentException( @@ -97,7 +98,8 @@ public CatalogFacadeExtensionAdapter(CatalogFacade facade) { *

This would be unnecessary if {@link ExtendedCatalogFacade}'s {@code update()} is * incorporated to the official {@link CatalogFacade} interface. */ - public @Override I update(final I info, final Patch patch) { + @Override + public I update(final I info, final Patch patch) { final I orig = ModificationProxy.unwrap(info); ClassMappings cm = CatalogInfoTypeRegistry.determineKey(orig.getClass()); @SuppressWarnings("unchecked") @@ -113,7 +115,8 @@ private Consumer saving(ClassMappings cm) { } /** Adapts a {@link ExtendedCatalogFacade#query} call to {@link CatalogFacade#list} */ - public @Override Stream query(Query query) { + @Override + public Stream query(Query query) { Class of = query.getType(); Filter filter = query.getFilter(); Integer offset = query.getOffset(); @@ -160,30 +163,36 @@ public CatalogImpl getSubject() { return orig; } - public @Override void addListener(CatalogListener listener) { + @Override + public void addListener(CatalogListener listener) { LOGGER.fine("Suppressing catalog listener " + listener.getClass().getCanonicalName()); } - public @Override void setFacade(CatalogFacade facade) { + @Override + public void setFacade(CatalogFacade facade) { super.rawFacade = facade; super.facade = facade; } - public @Override void fireAdded(CatalogInfo object) { + @Override + public void fireAdded(CatalogInfo object) { LOGGER.fine("Suppressing catalog add event from legacy CatalogFacade"); } - public @Override void fireModified( + @Override + public void fireModified( CatalogInfo object, List propertyNames, List oldValues, List newValues) { LOGGER.fine("Suppressing catalog pre-modify event from legacy CatalogFacade"); } - public @Override void firePostModified( + @Override + public void firePostModified( CatalogInfo object, List propertyNames, List oldValues, List newValues) { LOGGER.fine("Suppressing catalog post-modify event from legacy CatalogFacade"); } - public @Override void fireRemoved(CatalogInfo object) { + @Override + public void fireRemoved(CatalogInfo object) { LOGGER.fine("Suppressing catalog removed event from legacy CatalogFacade"); } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogInfoLookup.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogInfoLookup.java index c1ba6ca9a..33f0fab7b 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogInfoLookup.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogInfoLookup.java @@ -133,7 +133,8 @@ protected CatalogInfoLookup(Class type, Function nameMapper) { this.infoType = type; } - public @Override Class getContentType() { + @Override + public Class getContentType() { return infoType; } @@ -157,7 +158,8 @@ private static void checkNotAProxy(CatalogInfo value) { } } - public @Override void add(T value) { + @Override + public void add(T value) { requireNonNull(value); checkNotAProxy(value); Map idMap = getMapForValue(idMultiMap, value); @@ -173,7 +175,6 @@ private static void checkNotAProxy(CatalogInfo value) { value.getId(), nameMapper.apply(value).getLocalPart()); LOGGER.warning(msg); - // throw new IllegalArgumentException(msg); } Name name = nameMapper.apply(value); nameMap.put(name, value); @@ -181,7 +182,8 @@ private static void checkNotAProxy(CatalogInfo value) { } } - public @Override void remove(T value) { + @Override + public void remove(T value) { requireNonNull(value); checkNotAProxy(value); Map idMap = getMapForValue(idMultiMap, value); @@ -196,7 +198,8 @@ private static void checkNotAProxy(CatalogInfo value) { } @SuppressWarnings("unchecked") - public @Override I update(final I value, Patch patch) { + @Override + public I update(final I value, Patch patch) { requireNonNull(value); requireNonNull(patch); checkNotAProxy(value); @@ -227,7 +230,8 @@ private static void checkNotAProxy(CatalogInfo value) { return (I) storedValue; } - public @Override void dispose() { + @Override + public void dispose() { clear(); } @@ -244,7 +248,8 @@ protected void clear() { * @param propertyName the property name of the objects of type {@code type} to sort by * @see org.geoserver.catalog.CatalogFacade#canSort(java.lang.Class, java.lang.String) */ - public @Override boolean canSortBy(String propertyName) { + @Override + public boolean canSortBy(String propertyName) { return CatalogInfoLookup.canSort(propertyName, getContentType()); } @@ -263,8 +268,7 @@ public static boolean canSort(String propertyName, Class if (i == path.length - 1) { boolean primitive = clazz.isPrimitive(); boolean comparable = Comparable.class.isAssignableFrom(clazz); - boolean canSort = primitive || comparable; - return canSort; + return primitive || comparable; } } throw new IllegalStateException("empty property name"); @@ -286,7 +290,8 @@ public Stream findAll(Query query) { return stream; } - public @Override long count(Class type, Filter filter) { + @Override + public long count(Class type, Filter filter) { return Filter.INCLUDE.equals(filter) ? idMultiMap.entrySet().stream() .filter(k -> type.isAssignableFrom(k.getKey())) @@ -313,13 +318,14 @@ private static Comparator providedOrder() { } protected Predicate toPredicate(Filter filter) { - return o -> filter.evaluate(o); + return filter::evaluate; } private static Comparator comparator(final SortBy sortOrder) { Comparator comparator = new Comparator<>() { - public @Override int compare(U o1, U o2) { + @Override + public int compare(U o1, U o2) { Object v1 = OwsUtils.get(o1, sortOrder.getPropertyName().getPropertyName()); Object v2 = OwsUtils.get(o2, sortOrder.getPropertyName().getPropertyName()); if (v1 == null) { @@ -361,7 +367,7 @@ Stream list( requireNonNull(clazz); requireNonNull(predicate); requireNonNull(comparator); - List result = new ArrayList(); + List result = new ArrayList<>(); for (Class key : nameMultiMap.keySet()) { if (clazz.isAssignableFrom(key)) { Map valueMap = getMapForType(nameMultiMap, key); @@ -385,7 +391,8 @@ public Optional findById(String id) { } /** Looks up a CatalogInfo by class and identifier */ - public @Override Optional findById(String id, Class clazz) { + @Override + public Optional findById(String id, Class clazz) { requireNonNull(id, () -> "id is null, class: " + clazz); requireNonNull(clazz); for (Class key : idMultiMap.keySet()) { @@ -402,8 +409,8 @@ public Optional findById(String id) { } /** Looks up a CatalogInfo by class and name */ - public @Override Optional findFirstByName( - String name, @Nullable Class clazz) { + @Override + public Optional findFirstByName(String name, @Nullable Class clazz) { requireNonNull(name); requireNonNull(clazz); return findFirst(clazz, i -> name.equals(nameMapper.apply(i).getLocalPart())); @@ -449,10 +456,10 @@ Optional findFirst(Class clazz, Predicate predi return Optional.empty(); } - public @Override void syncTo(CatalogInfoRepository target) { + @Override + public void syncTo(CatalogInfoRepository target) { requireNonNull(target); - if (target instanceof CatalogInfoLookup) { - CatalogInfoLookup other = (CatalogInfoLookup) target; + if (target instanceof CatalogInfoLookup other) { other.clear(); other.idMultiMap.putAll(this.idMultiMap); other.nameMultiMap.putAll(this.nameMultiMap); @@ -466,7 +473,7 @@ static class NamespaceInfoLookup extends CatalogInfoLookup implements NamespaceRepository { private ConcurrentHashMap> index = new ConcurrentHashMap<>(); - private static Comparator VALUE_ORDER = + private static final Comparator VALUE_ORDER = (n1, n2) -> n1.getId().compareTo(n2.getId()); /** guards modifications to the index and its ArrayList values */ @@ -478,34 +485,39 @@ public NamespaceInfoLookup() { super(NamespaceInfo.class, NAMESPACE_NAME_MAPPER); } - public @Override Optional findFirstByName( - String name, Class clazz) { + @Override + public Optional findFirstByName(String name, Class clazz) { requireNonNull(name); requireNonNull(clazz); return findByName(new NameImpl(name), clazz); } - public @Override void setDefaultNamespace(NamespaceInfo namespace) { + @Override + public void setDefaultNamespace(NamespaceInfo namespace) { requireNonNull(namespace); this.defaultNamespace = findById(namespace.getId(), NamespaceInfo.class) .orElseThrow(NoSuchElementException::new); } - public @Override void unsetDefaultNamespace() { + @Override + public void unsetDefaultNamespace() { defaultNamespace = null; } - public @Override Optional getDefaultNamespace() { + @Override + public Optional getDefaultNamespace() { return Optional.ofNullable(defaultNamespace); } - public @Override Optional findOneByURI(String uri) { + @Override + public Optional findOneByURI(String uri) { requireNonNull(uri); return valueList(uri, false).stream().findFirst(); } - public @Override Stream findAllByURI(String uri) { + @Override + public Stream findAllByURI(String uri) { requireNonNull(uri); lock.readLock().lock(); try { @@ -611,24 +623,28 @@ public WorkspaceInfoLookup() { super(WorkspaceInfo.class, WORKSPACE_NAME_MAPPER); } - public @Override Optional findFirstByName( + @Override + public Optional findFirstByName( String name, @Nullable Class clazz) { requireNonNull(name); requireNonNull(clazz); return findByName(new NameImpl(name), clazz); } - public @Override void setDefaultWorkspace(WorkspaceInfo workspace) { + @Override + public void setDefaultWorkspace(WorkspaceInfo workspace) { this.defaultWorkspace = findById(workspace.getId(), WorkspaceInfo.class) .orElseThrow(NoSuchElementException::new); } - public @Override Optional getDefaultWorkspace() { + @Override + public Optional getDefaultWorkspace() { return Optional.ofNullable(defaultWorkspace); } - public @Override void unsetDefaultWorkspace() { + @Override + public void unsetDefaultWorkspace() { defaultWorkspace = null; } } @@ -641,7 +657,8 @@ public StoreInfoLookup() { super(StoreInfo.class, STORE_NAME_MAPPER); } - public @Override void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo store) { + @Override + public void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo store) { requireNonNull(workspace); requireNonNull(store); String wsId = workspace.getId(); @@ -651,37 +668,44 @@ public StoreInfoLookup() { defaultStores.compute(wsId, (ws, oldDefaultStore) -> localStore); } - public @Override void unsetDefaultDataStore(WorkspaceInfo workspace) { + @Override + public void unsetDefaultDataStore(WorkspaceInfo workspace) { requireNonNull(workspace); defaultStores.remove(workspace.getId()); } - public @Override Optional getDefaultDataStore(WorkspaceInfo workspace) { + @Override + public Optional getDefaultDataStore(WorkspaceInfo workspace) { return Optional.ofNullable(defaultStores.get(workspace.getId())); } - public @Override Stream getDefaultDataStores() { + @Override + public Stream getDefaultDataStores() { return defaultStores.values().stream(); } - public @Override void dispose() { + @Override + public void dispose() { super.dispose(); defaultStores.clear(); } - public @Override Stream findAllByWorkspace( + @Override + public Stream findAllByWorkspace( WorkspaceInfo workspace, Class clazz) { requireNonNull(workspace); requireNonNull(clazz); return list(clazz, s -> workspace.getId().equals(s.getWorkspace().getId())); } - public @Override Stream findAllByType(Class clazz) { + @Override + public Stream findAllByType(Class clazz) { requireNonNull(clazz); return list(clazz, CatalogInfoLookup.alwaysTrue()); } - public @Override Optional findByNameAndWorkspace( + @Override + public Optional findByNameAndWorkspace( String name, WorkspaceInfo workspace, Class clazz) { requireNonNull(name); requireNonNull(workspace); @@ -696,11 +720,13 @@ public LayerGroupInfoLookup() { super(LayerGroupInfo.class, LAYERGROUP_NAME_MAPPER); } - public @Override Stream findAllByWorkspaceIsNull() { + @Override + public Stream findAllByWorkspaceIsNull() { return list(LayerGroupInfo.class, lg -> lg.getWorkspace() == null); } - public @Override Stream findAllByWorkspace(WorkspaceInfo workspace) { + @Override + public Stream findAllByWorkspace(WorkspaceInfo workspace) { requireNonNull(workspace); return list( LayerGroupInfo.class, @@ -709,12 +735,14 @@ public LayerGroupInfoLookup() { && lg.getWorkspace().getId().equals(workspace.getId())); } - public @Override Optional findByNameAndWorkspaceIsNull(String name) { + @Override + public Optional findByNameAndWorkspaceIsNull(String name) { requireNonNull(name); return findByName(new NameImpl(null, name), LayerGroupInfo.class); } - public @Override Optional findByNameAndWorkspace( + @Override + public Optional findByNameAndWorkspace( String name, WorkspaceInfo workspace) { requireNonNull(name); requireNonNull(workspace); @@ -742,7 +770,8 @@ public ResourceInfoLookup(LayerInfoLookup layers) { this.layers = layers; } - public @Override R update(R value, Patch patch) { + @Override + public R update(R value, Patch patch) { requireNonNull(value); requireNonNull(patch); Name oldName = getMapForValue(idToMameMultiMap, value).get(value.getId()); @@ -754,19 +783,22 @@ public ResourceInfoLookup(LayerInfoLookup layers) { return updated; } - public @Override Stream findAllByType(Class clazz) { + @Override + public Stream findAllByType(Class clazz) { requireNonNull(clazz); return list(clazz, CatalogInfoLookup.alwaysTrue()); } - public @Override Stream findAllByNamespace( + @Override + public Stream findAllByNamespace( NamespaceInfo ns, Class clazz) { requireNonNull(ns); requireNonNull(clazz); return list(clazz, r -> ns.equals(r.getNamespace())); } - public @Override Optional findByStoreAndName( + @Override + public Optional findByStoreAndName( StoreInfo store, String name, Class clazz) { requireNonNull(store); requireNonNull(name); @@ -776,14 +808,15 @@ public ResourceInfoLookup(LayerInfoLookup layers) { r -> name.equals(r.getName()) && store.getId().equals(r.getStore().getId())); } - public @Override Stream findAllByStore( - StoreInfo store, Class clazz) { + @Override + public Stream findAllByStore(StoreInfo store, Class clazz) { requireNonNull(store); requireNonNull(clazz); return list(clazz, r -> store.equals(r.getStore())); } - public @Override Optional findByNameAndNamespace( + @Override + public Optional findByNameAndNamespace( String name, NamespaceInfo namespace, Class clazz) { requireNonNull(name); requireNonNull(namespace); @@ -812,7 +845,8 @@ void updateName(Name oldName, Name newName) { } /** Override to remove by name instead of by id */ - public @Override void remove(LayerInfo value) { + @Override + public void remove(LayerInfo value) { requireNonNull(value); checkNotAProxy(value); ConcurrentMap nameMap = getMapForValue(nameMultiMap, value); @@ -826,19 +860,22 @@ void updateName(Name oldName, Name newName) { } } - public @Override Optional findOneByName(String name) { + @Override + public Optional findOneByName(String name) { requireNonNull(name); return findFirst(LayerInfo.class, li -> name.equals(li.getName())); } - public @Override Stream findAllByDefaultStyleOrStyles(StyleInfo style) { + @Override + public Stream findAllByDefaultStyleOrStyles(StyleInfo style) { requireNonNull(style); return list( LayerInfo.class, li -> style.equals(li.getDefaultStyle()) || li.getStyles().contains(style)); } - public @Override Stream findAllByResource(ResourceInfo resource) { + @Override + public Stream findAllByResource(ResourceInfo resource) { requireNonNull(resource); // in the current setup we cannot have multiple layers associated to the same // resource, as they would all share the same name (the one of the resource) so @@ -853,24 +890,27 @@ public StyleInfoLookup() { super(StyleInfo.class, STYLE_NAME_MAPPER); } - public @Override Stream findAllByNullWorkspace() { + @Override + public Stream findAllByNullWorkspace() { return list(StyleInfo.class, s -> s.getWorkspace() == null); } - public @Override Stream findAllByWorkspace(WorkspaceInfo ws) { + @Override + public Stream findAllByWorkspace(WorkspaceInfo ws) { requireNonNull(ws); return list( StyleInfo.class, s -> s.getWorkspace() != null && s.getWorkspace().getId().equals(ws.getId())); } - public @Override Optional findByNameAndWordkspaceNull(String name) { + @Override + public Optional findByNameAndWordkspaceNull(String name) { requireNonNull(name); return findByName(new NameImpl(null, name), StyleInfo.class); } - public @Override Optional findByNameAndWorkspace( - String name, WorkspaceInfo workspace) { + @Override + public Optional findByNameAndWorkspace(String name, WorkspaceInfo workspace) { requireNonNull(name); requireNonNull(workspace); return findByName(new NameImpl(workspace.getId(), name), StyleInfo.class); diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogInfoRepositoryHolderImpl.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogInfoRepositoryHolderImpl.java index d74e3ee02..664f29414 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogInfoRepositoryHolderImpl.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogInfoRepositoryHolderImpl.java @@ -37,86 +37,102 @@ public class CatalogInfoRepositoryHolderImpl implements CatalogInfoRepositoryHol new CatalogInfoTypeRegistry<>(); @SuppressWarnings("unchecked") - public @Override > R repository( - Class of) { + @Override + public > R repository(Class of) { return (R) repos.of(of); } @SuppressWarnings("unchecked") - public @Override > R repositoryFor( - T info) { + @Override + public > R repositoryFor(T info) { return (R) repos.forObject(info); } - public @Override void setNamespaceRepository(NamespaceRepository namespaces) { + @Override + public void setNamespaceRepository(NamespaceRepository namespaces) { this.namespaces = namespaces; repos.register(NamespaceInfo.class, namespaces); } - public @Override NamespaceRepository getNamespaceRepository() { + @Override + public NamespaceRepository getNamespaceRepository() { return namespaces; } - public @Override void setWorkspaceRepository(WorkspaceRepository workspaces) { + @Override + public void setWorkspaceRepository(WorkspaceRepository workspaces) { this.workspaces = workspaces; repos.register(WorkspaceInfo.class, workspaces); } - public @Override WorkspaceRepository getWorkspaceRepository() { + @Override + public WorkspaceRepository getWorkspaceRepository() { return workspaces; } - public @Override void setStoreRepository(StoreRepository stores) { + @Override + public void setStoreRepository(StoreRepository stores) { this.stores = stores; repos.registerRecursively(StoreInfo.class, stores); } - public @Override StoreRepository getStoreRepository() { + @Override + public StoreRepository getStoreRepository() { return stores; } - public @Override void setResourceRepository(ResourceRepository resources) { + @Override + public void setResourceRepository(ResourceRepository resources) { this.resources = resources; repos.registerRecursively(ResourceInfo.class, resources); } - public @Override ResourceRepository getResourceRepository() { + @Override + public ResourceRepository getResourceRepository() { return resources; } - public @Override void setLayerRepository(LayerRepository layers) { + @Override + public void setLayerRepository(LayerRepository layers) { this.layers = layers; repos.register(LayerInfo.class, layers); } - public @Override LayerRepository getLayerRepository() { + @Override + public LayerRepository getLayerRepository() { return layers; } - public @Override void setLayerGroupRepository(LayerGroupRepository layerGroups) { + @Override + public void setLayerGroupRepository(LayerGroupRepository layerGroups) { this.layerGroups = layerGroups; repos.register(LayerGroupInfo.class, layerGroups); } - public @Override LayerGroupRepository getLayerGroupRepository() { + @Override + public LayerGroupRepository getLayerGroupRepository() { return layerGroups; } - public @Override void setStyleRepository(StyleRepository styles) { + @Override + public void setStyleRepository(StyleRepository styles) { this.styles = styles; repos.register(StyleInfo.class, styles); } - public @Override StyleRepository getStyleRepository() { + @Override + public StyleRepository getStyleRepository() { return styles; } - public @Override void setMapRepository(MapRepository maps) { + @Override + public void setMapRepository(MapRepository maps) { this.maps = maps; repos.register(MapInfo.class, maps); } - public @Override MapRepository getMapRepository() { + @Override + public MapRepository getMapRepository() { return maps; } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogInfoTypeRegistry.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogInfoTypeRegistry.java index 1e6bc1ce7..2a90f51ee 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogInfoTypeRegistry.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogInfoTypeRegistry.java @@ -129,13 +129,6 @@ public static ClassMappings determineKey(Class type) { if (cm != null) { return cm; } - // // don't really care if it's a proxy, can't assume ModificationProxy and - // // ResolvingProxy are the only ones - // for (int i = 0; i < instanceOfLookup.size(); i++) { - // if (instanceOfLookup.get(i).isAssignableFrom(type)) { - // return determineKey(instanceOfLookup.get(i)); - // } - // } throw new IllegalArgumentException( "Unable to determine CatalogInfo subtype from class " + type.getName()); } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogPlugin.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogPlugin.java index 7db3c2c31..7664df072 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogPlugin.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/CatalogPlugin.java @@ -133,30 +133,12 @@ public class CatalogPlugin extends CatalogImpl implements Catalog { * a {@link ResolvingCatalogFacadeDecorator}. If not, {@link #facade} will be a resolving * decorator to allow traits to be added. */ - protected CatalogFacade rawFacade; - - /** - * Resolving catalog facade to use inside this catalog. The {@link #rawFacade} will be wrapped - * on a resolving decorator if it's not already a {@link ResolvingCatalogFacade}. - * - *

This catalog will add inbound and outbound traits to make sure no {@link CatalogInfo} - * leaves the facade without being decorated with a {@link ModificationProxy}, nor gets into the - * facade without its {@link ModificationProxy} decorator being removed. - */ - // protected ResolvingCatalogFacade facade; - - /** listeners */ - // protected List listeners = new CopyOnWriteArrayList<>(); - - /** resources */ - // protected ResourcePool resourcePool; - - // protected GeoServerResourceLoader resourceLoader; + protected transient CatalogFacade rawFacade; /** Handles {@link CatalogInfo} validation rules before adding or updating an object */ - protected final CatalogValidationRules validationSupport; + protected final transient CatalogValidationRules validationSupport; - private final CatalogBusinessRules businessRules = new CatalogBusinessRules(); + private final transient CatalogBusinessRules businessRules = new CatalogBusinessRules(); protected final boolean isolated; @@ -197,11 +179,13 @@ private CatalogPlugin(CatalogPlugin catalog) { * of the Isolated Workspace one, nothing is filtered or hidden. Only for usage by the * ResolvingProxy, should otherwise never be used. */ - public @Override CatalogPlugin getRawCatalog() { + @Override + public CatalogPlugin getRawCatalog() { return new CatalogPlugin(this); } - public @Override ExtendedCatalogFacade getFacade() { + @Override + public ExtendedCatalogFacade getFacade() { return (ExtendedCatalogFacade) facade; } @@ -215,26 +199,24 @@ public CatalogFacade getRawFacade() { *

This is not part of the public api, it is used for testing purposes where we have to * bootstrap catalog contents. */ + @Override public void setExtendedValidation(boolean extendedValidation) { validationSupport.setExtendedValidation(extendedValidation); } + @Override public boolean isExtendedValidation() { return validationSupport.isExtendedValidation(); } + @Override public void setFacade(CatalogFacade facade) { - // final GeoServerConfigurationLock configurationLock; - // configurationLock = GeoServerExtensions.bean(GeoServerConfigurationLock.class); - // if (configurationLock != null) { - // facade = LockingCatalogFacade.create(facade, configurationLock); - // } this.rawFacade = facade; ExtendedCatalogFacade efacade; Function outboundResolver; Function inboundResolver; - if (facade instanceof ExtendedCatalogFacade) { - efacade = (ExtendedCatalogFacade) rawFacade; + if (facade instanceof ExtendedCatalogFacade extended) { + efacade = extended; // make sure no object leaves the catalog without being proxied, nor enters the facade // as a proxy. Note it is ok if the provided facade is already a ResolvingCatalogFacade. // This catalog doesn't care which object resolution chain the provided facade needs to @@ -257,23 +239,27 @@ public void setFacade(CatalogFacade facade) { this.facade.setCatalog(this); } - public @Override String getId() { + @Override + public String getId() { return "catalog"; } - public @Override CatalogFactory getFactory() { + @Override + public CatalogFactory getFactory() { return new CatalogFactoryImpl(this); } // Store methods - public @Override void add(StoreInfo store) { + @Override + public void add(StoreInfo store) { if (store.getWorkspace() == null) { store.setWorkspace(getDefaultWorkspace()); } doAdd(store, facade::add); } - public @Override ValidationResult validate(StoreInfo store, boolean isNew) { + @Override + public ValidationResult validate(StoreInfo store, boolean isNew) { return validationSupport.validate(store, isNew); } @@ -284,13 +270,15 @@ public ValidationResult validate(MapInfo map, boolean isNew) { return validationSupport.validate(map, isNew); } - public @Override void remove(StoreInfo store) { + @Override + public void remove(StoreInfo store) { doRemove(store, facade::remove); } // TODO: move the namespace update logic to validationrules.onBefore/AfterSave and just call // doSave(store) - public @Override void save(StoreInfo store) { + @Override + public void save(StoreInfo store) { if (store.getId() == null) { // some code uses save() when it should use add() add(store); @@ -360,26 +348,31 @@ public ValidationResult validate(MapInfo map, boolean isNew) { // override, super calls facade.save and depends on it throwing the events @VisibleForTesting - public @Override void updateNamespace(ResourceInfo resource, NamespaceInfo newNamespace) { + @Override + public void updateNamespace(ResourceInfo resource, NamespaceInfo newNamespace) { resource.setNamespace(newNamespace); doSave(resource); } - public @Override T detach(T store) { + @Override + public T detach(T store) { return detach(store, facade.detach(store)); } - public @Override T getStore(String id, Class clazz) { + @Override + public T getStore(String id, Class clazz) { return facade.getStore(id, clazz); } @SuppressFBWarnings("NP_NONNULL_PARAM_VIOLATION") - public @Override T getStoreByName(String name, Class clazz) { + @Override + public T getStoreByName(String name, Class clazz) { return getStoreByName((WorkspaceInfo) null, name, clazz); } @SuppressFBWarnings("NP_NONNULL_PARAM_VIOLATION") - public @Override T getStoreByName( + @Override + public T getStoreByName( WorkspaceInfo workspace, String name, Class clazz) { WorkspaceInfo ws = workspace; @@ -400,7 +393,8 @@ public ValidationResult validate(MapInfo map, boolean isNew) { return store; } - public @Override T getStoreByName( + @Override + public T getStoreByName( String workspaceName, String name, Class clazz) { WorkspaceInfo workspace = getWorkspaceByName(workspaceName); @@ -410,7 +404,8 @@ public ValidationResult validate(MapInfo map, boolean isNew) { return null; } - public @Override List getStoresByWorkspace( + @Override + public List getStoresByWorkspace( String workspaceName, Class clazz) { WorkspaceInfo workspace = null; @@ -424,65 +419,80 @@ public ValidationResult validate(MapInfo map, boolean isNew) { return getStoresByWorkspace(workspace, clazz); } - public @Override List getStoresByWorkspace( + @Override + public List getStoresByWorkspace( WorkspaceInfo workspace, Class clazz) { return unmodifiableList(facade.getStoresByWorkspace(workspace, clazz)); } - public @Override List getStores(Class clazz) { + @Override + public List getStores(Class clazz) { return unmodifiableList(facade.getStores(clazz)); } - public @Override WMSStoreInfo getWMSStore(String id) { + @Override + public WMSStoreInfo getWMSStore(String id) { return getStore(id, WMSStoreInfo.class); } - public @Override WMSStoreInfo getWMSStoreByName(String name) { + @Override + public WMSStoreInfo getWMSStoreByName(String name) { return getStoreByName(name, WMSStoreInfo.class); } - public @Override WMTSStoreInfo getWMTSStore(String id) { + @Override + public WMTSStoreInfo getWMTSStore(String id) { return getStore(id, WMTSStoreInfo.class); } - public @Override WMTSStoreInfo getWMTSStoreByName(String name) { + @Override + public WMTSStoreInfo getWMTSStoreByName(String name) { return getStoreByName(name, WMTSStoreInfo.class); } - public @Override DataStoreInfo getDataStore(String id) { - return (DataStoreInfo) getStore(id, DataStoreInfo.class); + @Override + public DataStoreInfo getDataStore(String id) { + return getStore(id, DataStoreInfo.class); } - public @Override DataStoreInfo getDataStoreByName(String name) { - return (DataStoreInfo) getStoreByName(name, DataStoreInfo.class); + @Override + public DataStoreInfo getDataStoreByName(String name) { + return getStoreByName(name, DataStoreInfo.class); } - public @Override DataStoreInfo getDataStoreByName(String workspaceName, String name) { - return (DataStoreInfo) getStoreByName(workspaceName, name, DataStoreInfo.class); + @Override + public DataStoreInfo getDataStoreByName(String workspaceName, String name) { + return getStoreByName(workspaceName, name, DataStoreInfo.class); } - public @Override DataStoreInfo getDataStoreByName(WorkspaceInfo workspace, String name) { - return (DataStoreInfo) getStoreByName(workspace, name, DataStoreInfo.class); + @Override + public DataStoreInfo getDataStoreByName(WorkspaceInfo workspace, String name) { + return getStoreByName(workspace, name, DataStoreInfo.class); } - public @Override List getDataStoresByWorkspace(String workspaceName) { + @Override + public List getDataStoresByWorkspace(String workspaceName) { return getStoresByWorkspace(workspaceName, DataStoreInfo.class); } - public @Override List getDataStoresByWorkspace(WorkspaceInfo workspace) { + @Override + public List getDataStoresByWorkspace(WorkspaceInfo workspace) { return getStoresByWorkspace(workspace, DataStoreInfo.class); } - public @Override List getDataStores() { + @Override + public List getDataStores() { return getStores(DataStoreInfo.class); } - public @Override DataStoreInfo getDefaultDataStore(WorkspaceInfo workspace) { + @Override + public DataStoreInfo getDefaultDataStore(WorkspaceInfo workspace) { return facade.getDefaultDataStore(workspace); } - public @Override void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo store) { + @Override + public void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo store) { if (store != null) { // basic sanity check if (store.getWorkspace() == null) { @@ -510,37 +520,44 @@ public ValidationResult validate(MapInfo map, boolean isNew) { firePostModified(this, asList("defaultDataStore"), asList(old), asList(store)); } - public @Override CoverageStoreInfo getCoverageStore(String id) { - return (CoverageStoreInfo) getStore(id, CoverageStoreInfo.class); + @Override + public CoverageStoreInfo getCoverageStore(String id) { + return getStore(id, CoverageStoreInfo.class); } - public @Override CoverageStoreInfo getCoverageStoreByName(String name) { - return (CoverageStoreInfo) getStoreByName(name, CoverageStoreInfo.class); + @Override + public CoverageStoreInfo getCoverageStoreByName(String name) { + return getStoreByName(name, CoverageStoreInfo.class); } - public @Override CoverageStoreInfo getCoverageStoreByName(String workspaceName, String name) { + @Override + public CoverageStoreInfo getCoverageStoreByName(String workspaceName, String name) { return getStoreByName(workspaceName, name, CoverageStoreInfo.class); } - public @Override CoverageStoreInfo getCoverageStoreByName( - WorkspaceInfo workspace, String name) { + @Override + public CoverageStoreInfo getCoverageStoreByName(WorkspaceInfo workspace, String name) { return getStoreByName(workspace, name, CoverageStoreInfo.class); } - public @Override List getCoverageStoresByWorkspace(String workspaceName) { + @Override + public List getCoverageStoresByWorkspace(String workspaceName) { return getStoresByWorkspace(workspaceName, CoverageStoreInfo.class); } - public @Override List getCoverageStoresByWorkspace(WorkspaceInfo workspace) { + @Override + public List getCoverageStoresByWorkspace(WorkspaceInfo workspace) { return getStoresByWorkspace(workspace, CoverageStoreInfo.class); } - public @Override List getCoverageStores() { + @Override + public List getCoverageStores() { return getStores(CoverageStoreInfo.class); } // Resource methods - public @Override void add(ResourceInfo resource) { + @Override + public void add(ResourceInfo resource) { if (resource.getNamespace() == null) { // default to default namespace resource.setNamespace(getDefaultNamespace()); @@ -551,29 +568,34 @@ public ValidationResult validate(MapInfo map, boolean isNew) { doAdd(resource, facade::add); } - public @Override ValidationResult validate(ResourceInfo resource, boolean isNew) { + @Override + public ValidationResult validate(ResourceInfo resource, boolean isNew) { return validationSupport.validate(resource, isNew); } - public @Override void remove(ResourceInfo resource) { + @Override + public void remove(ResourceInfo resource) { doRemove(resource, facade::remove); } - public @Override void save(ResourceInfo resource) { + @Override + public void save(ResourceInfo resource) { doSave(resource); } - public @Override T detach(T resource) { + @Override + public T detach(T resource) { return detach(resource, facade.detach(resource)); } - public @Override T getResource(String id, Class clazz) { + @Override + public T getResource(String id, Class clazz) { return facade.getResource(id, clazz); } @SuppressFBWarnings("NP_NONNULL_PARAM_VIOLATION") - public @Override T getResourceByName( - String ns, String name, Class clazz) { + @Override + public T getResourceByName(String ns, String name, Class clazz) { if ("".equals(ns)) { ns = null; } @@ -595,7 +617,8 @@ public ValidationResult validate(MapInfo map, boolean isNew) { } @SuppressFBWarnings("NP_NONNULL_PARAM_VIOLATION") - public @Override T getResourceByName( + @Override + public T getResourceByName( NamespaceInfo ns, String name, Class clazz) { NamespaceInfo namespace = ns; @@ -609,12 +632,14 @@ public ValidationResult validate(MapInfo map, boolean isNew) { return resource; } - public @Override T getResourceByName(Name name, Class clazz) { + @Override + public T getResourceByName(Name name, Class clazz) { return getResourceByName(name.getNamespaceURI(), name.getLocalPart(), clazz); } @SuppressFBWarnings("NP_NONNULL_PARAM_VIOLATION") - public @Override T getResourceByName(String name, Class clazz) { + @Override + public T getResourceByName(String name, Class clazz) { // check is the name is a fully qualified one int colon = name.indexOf(':'); if (colon != -1) { @@ -626,17 +651,19 @@ public ValidationResult validate(MapInfo map, boolean isNew) { } } - public @Override /* List */ List getResources( - Class /* */ clazz) { + @Override + public /* List */ List getResources(Class /* */ clazz) { return unmodifiableList(facade.getResources(clazz)); } - public @Override /* List */ List getResourcesByNamespace( + @Override + public /* List */ List getResourcesByNamespace( NamespaceInfo namespace, Class /* */ clazz) { return unmodifiableList(facade.getResourcesByNamespace(namespace, clazz)); } - public @Override List getResourcesByNamespace( + @Override + public List getResourcesByNamespace( String namespace, Class clazz) { if (namespace == null) { return getResourcesByNamespace((NamespaceInfo) null, clazz); @@ -653,120 +680,145 @@ public ValidationResult validate(MapInfo map, boolean isNew) { return getResourcesByNamespace(ns, clazz); } - public @Override T getResourceByStore( + @Override + public T getResourceByStore( StoreInfo store, String name, Class clazz) { return facade.getResourceByStore(store, name, clazz); } - public @Override List getResourcesByStore( - StoreInfo store, Class clazz) { + @Override + public List getResourcesByStore(StoreInfo store, Class clazz) { return unmodifiableList(facade.getResourcesByStore(store, clazz)); } - public @Override FeatureTypeInfo getFeatureType(String id) { - return (FeatureTypeInfo) getResource(id, FeatureTypeInfo.class); + @Override + public FeatureTypeInfo getFeatureType(String id) { + return getResource(id, FeatureTypeInfo.class); } - public @Override FeatureTypeInfo getFeatureTypeByName(String ns, String name) { - return (FeatureTypeInfo) getResourceByName(ns, name, FeatureTypeInfo.class); + @Override + public FeatureTypeInfo getFeatureTypeByName(String ns, String name) { + return getResourceByName(ns, name, FeatureTypeInfo.class); } - public @Override FeatureTypeInfo getFeatureTypeByName(NamespaceInfo ns, String name) { + @Override + public FeatureTypeInfo getFeatureTypeByName(NamespaceInfo ns, String name) { return getResourceByName(ns, name, FeatureTypeInfo.class); } - public @Override FeatureTypeInfo getFeatureTypeByName(Name name) { + @Override + public FeatureTypeInfo getFeatureTypeByName(Name name) { return getResourceByName(name, FeatureTypeInfo.class); } - public @Override FeatureTypeInfo getFeatureTypeByName(String name) { - return (FeatureTypeInfo) getResourceByName(name, FeatureTypeInfo.class); + @Override + public FeatureTypeInfo getFeatureTypeByName(String name) { + return getResourceByName(name, FeatureTypeInfo.class); } - public @Override List getFeatureTypes() { + @Override + public List getFeatureTypes() { return getResources(FeatureTypeInfo.class); } - public @Override List getFeatureTypesByNamespace(NamespaceInfo namespace) { + @Override + public List getFeatureTypesByNamespace(NamespaceInfo namespace) { return getResourcesByNamespace(namespace, FeatureTypeInfo.class); } - public @Override FeatureTypeInfo getFeatureTypeByDataStore( - DataStoreInfo dataStore, String name) { + @Override + public FeatureTypeInfo getFeatureTypeByDataStore(DataStoreInfo dataStore, String name) { return getResourceByStore(dataStore, name, FeatureTypeInfo.class); } - public @Override List getFeatureTypesByDataStore(DataStoreInfo store) { + @Override + public List getFeatureTypesByDataStore(DataStoreInfo store) { return getResourcesByStore(store, FeatureTypeInfo.class); } - public @Override CoverageInfo getCoverage(String id) { - return (CoverageInfo) getResource(id, CoverageInfo.class); + @Override + public CoverageInfo getCoverage(String id) { + return getResource(id, CoverageInfo.class); } - public @Override CoverageInfo getCoverageByName(String ns, String name) { - return (CoverageInfo) getResourceByName(ns, name, CoverageInfo.class); + @Override + public CoverageInfo getCoverageByName(String ns, String name) { + return getResourceByName(ns, name, CoverageInfo.class); } - public @Override CoverageInfo getCoverageByName(NamespaceInfo ns, String name) { - return (CoverageInfo) getResourceByName(ns, name, CoverageInfo.class); + @Override + public CoverageInfo getCoverageByName(NamespaceInfo ns, String name) { + return getResourceByName(ns, name, CoverageInfo.class); } - public @Override CoverageInfo getCoverageByName(Name name) { + @Override + public CoverageInfo getCoverageByName(Name name) { return getResourceByName(name, CoverageInfo.class); } - public @Override CoverageInfo getCoverageByName(String name) { - return (CoverageInfo) getResourceByName(name, CoverageInfo.class); + @Override + public CoverageInfo getCoverageByName(String name) { + return getResourceByName(name, CoverageInfo.class); } - public @Override List getCoverages() { + @Override + public List getCoverages() { return getResources(CoverageInfo.class); } - public @Override List getCoveragesByNamespace(NamespaceInfo namespace) { + @Override + public List getCoveragesByNamespace(NamespaceInfo namespace) { return getResourcesByNamespace(namespace, CoverageInfo.class); } - public @Override List getCoveragesByStore(CoverageStoreInfo store) { + @Override + public List getCoveragesByStore(CoverageStoreInfo store) { return getResourcesByStore(store, CoverageInfo.class); } - public @Override CoverageInfo getCoverageByCoverageStore( - CoverageStoreInfo coverageStore, String name) { + @Override + public CoverageInfo getCoverageByCoverageStore(CoverageStoreInfo coverageStore, String name) { return getResourceByStore(coverageStore, name, CoverageInfo.class); } - public @Override List getCoveragesByCoverageStore(CoverageStoreInfo store) { + @Override + public List getCoveragesByCoverageStore(CoverageStoreInfo store) { return getResourcesByStore(store, CoverageInfo.class); } // Layer methods - public @Override void add(LayerInfo layer) { + @Override + public void add(LayerInfo layer) { doAdd(layer, facade::add); } - public @Override ValidationResult validate(LayerInfo layer, boolean isNew) { + @Override + public ValidationResult validate(LayerInfo layer, boolean isNew) { return validationSupport.validate(layer, isNew); } - public @Override void remove(LayerInfo layer) { + @Override + public void remove(LayerInfo layer) { doRemove(layer, facade::remove); } - public @Override void save(LayerInfo layer) { + @Override + public void save(LayerInfo layer) { doSave(layer); } - public @Override LayerInfo detach(LayerInfo layer) { + @Override + public LayerInfo detach(LayerInfo layer) { return detach(layer, facade.detach(layer)); } - public @Override LayerInfo getLayer(String id) { + @Override + public LayerInfo getLayer(String id) { return facade.getLayer(id); } - public @Override LayerInfo getLayerByName(Name name) { + @Override + public LayerInfo getLayerByName(Name name) { if (name.getNamespaceURI() != null) { NamespaceInfo ns = getNamespaceByURI(name.getNamespaceURI()); if (ns != null) { @@ -777,7 +829,8 @@ public ValidationResult validate(MapInfo map, boolean isNew) { return getLayerByName(name.getLocalPart()); } - public @Override LayerInfo getLayerByName(String name) { + @Override + public LayerInfo getLayerByName(String name) { LayerInfo result = null; int colon = name.indexOf(':'); if (colon != -1) { @@ -814,56 +867,69 @@ public static LayerInfo getLayerByName(Catalog catalog, String workspace, String } } - public @Override List getLayers(ResourceInfo resource) { + @Override + public List getLayers(ResourceInfo resource) { return unmodifiableList(facade.getLayers(resource)); } - public @Override List getLayers(StyleInfo style) { + @Override + public List getLayers(StyleInfo style) { return unmodifiableList(facade.getLayers(style)); } - public @Override List getLayers() { + @Override + public List getLayers() { return unmodifiableList(facade.getLayers()); } // Map methods - public @Override MapInfo getMap(String id) { + @Override + public MapInfo getMap(String id) { return facade.getMap(id); } - public @Override MapInfo getMapByName(String name) { + @Override + public MapInfo getMapByName(String name) { return facade.getMapByName(name); } - public @Override List getMaps() { + @Override + public List getMaps() { return unmodifiableList(facade.getMaps()); } - public @Override void add(LayerGroupInfo layerGroup) { + @Override + public void add(LayerGroupInfo layerGroup) { doAdd(layerGroup, facade::add); } - public @Override ValidationResult validate(LayerGroupInfo layerGroup, boolean isNew) { + @Override + public ValidationResult validate(LayerGroupInfo layerGroup, boolean isNew) { return validationSupport.validate(layerGroup, isNew); } - public @Override void remove(LayerGroupInfo layerGroup) { + @Override + public void remove(LayerGroupInfo layerGroup) { doRemove(layerGroup, facade::remove); } - public @Override void save(LayerGroupInfo layerGroup) { + @Override + public void save(LayerGroupInfo layerGroup) { doSave(layerGroup); } - public @Override LayerGroupInfo detach(LayerGroupInfo layerGroup) { + @Override + public LayerGroupInfo detach(LayerGroupInfo layerGroup) { return detach(layerGroup, facade.detach(layerGroup)); } - public @Override List getLayerGroups() { + @Override + public List getLayerGroups() { return unmodifiableList(facade.getLayerGroups()); } - public @Override List getLayerGroupsByWorkspace(String workspaceName) { + @Override + public List getLayerGroupsByWorkspace(String workspaceName) { WorkspaceInfo workspace = null; if (workspaceName != null) { workspace = getWorkspaceByName(workspaceName); @@ -875,16 +941,19 @@ public static LayerInfo getLayerByName(Catalog catalog, String workspace, String return getLayerGroupsByWorkspace(workspace); } - public @Override List getLayerGroupsByWorkspace(WorkspaceInfo workspace) { + @Override + public List getLayerGroupsByWorkspace(WorkspaceInfo workspace) { return unmodifiableList(facade.getLayerGroupsByWorkspace(workspace)); } - public @Override LayerGroupInfo getLayerGroup(String id) { + @Override + public LayerGroupInfo getLayerGroup(String id) { return facade.getLayerGroup(id); } @SuppressFBWarnings("NP_NONNULL_PARAM_VIOLATION") - public @Override LayerGroupInfo getLayerGroupByName(String name) { + @Override + public LayerGroupInfo getLayerGroupByName(String name) { final LayerGroupInfo layerGroup = getLayerGroupByName((String) null, name); @@ -909,7 +978,8 @@ public static LayerInfo getLayerByName(Catalog catalog, String workspace, String return getLayerGroupByName(workspaceName, layerGroupName); } - public @Override LayerGroupInfo getLayerGroupByName(String workspaceName, String name) { + @Override + public LayerGroupInfo getLayerGroupByName(String workspaceName, String name) { WorkspaceInfo workspace = null; if (workspaceName != null) { workspace = getWorkspaceByName(workspaceName); @@ -921,38 +991,44 @@ public static LayerInfo getLayerByName(Catalog catalog, String workspace, String return getLayerGroupByName(workspace, name); } - public @Override LayerGroupInfo getLayerGroupByName(WorkspaceInfo workspace, String name) { + @Override + public LayerGroupInfo getLayerGroupByName(WorkspaceInfo workspace, String name) { if (null == workspace) { workspace = DefaultCatalogFacade.NO_WORKSPACE; } - LayerGroupInfo layerGroup = facade.getLayerGroupByName(workspace, name); - return layerGroup; + return facade.getLayerGroupByName(workspace, name); } - public @Override void add(MapInfo map) { + @Override + public void add(MapInfo map) { doAdd(map, facade::add); } - public @Override void remove(MapInfo map) { + @Override + public void remove(MapInfo map) { doRemove(map, facade::remove); } - public @Override void save(MapInfo map) { + @Override + public void save(MapInfo map) { doSave(map); } - public @Override MapInfo detach(MapInfo map) { + @Override + public MapInfo detach(MapInfo map) { return detach(map, facade.detach(map)); } // Namespace methods - public @Override NamespaceInfo getNamespace(String id) { + @Override + public NamespaceInfo getNamespace(String id) { return facade.getNamespace(id); } - public @Override NamespaceInfo getNamespaceByPrefix(String prefix) { + @Override + public NamespaceInfo getNamespaceByPrefix(String prefix) { if (prefix == null || Catalog.DEFAULT.equals(prefix)) { NamespaceInfo ns = getDefaultNamespace(); if (ns != null) { @@ -963,39 +1039,48 @@ public static LayerInfo getLayerByName(Catalog catalog, String workspace, String return facade.getNamespaceByPrefix(prefix); } - public @Override NamespaceInfo getNamespaceByURI(String uri) { + @Override + public NamespaceInfo getNamespaceByURI(String uri) { return facade.getNamespaceByURI(uri); } - public @Override List getNamespaces() { + @Override + public List getNamespaces() { return unmodifiableList(facade.getNamespaces()); } - public @Override void add(NamespaceInfo namespace) { + @Override + public void add(NamespaceInfo namespace) { doAdd(namespace, facade::add); } - public @Override ValidationResult validate(NamespaceInfo namespace, boolean isNew) { + @Override + public ValidationResult validate(NamespaceInfo namespace, boolean isNew) { return validationSupport.validate(namespace, isNew); } - public @Override void remove(NamespaceInfo namespace) { + @Override + public void remove(NamespaceInfo namespace) { doRemove(namespace, facade::remove); } - public @Override void save(NamespaceInfo namespace) { + @Override + public void save(NamespaceInfo namespace) { doSave(namespace); } - public @Override NamespaceInfo detach(NamespaceInfo namespace) { + @Override + public NamespaceInfo detach(NamespaceInfo namespace) { return detach(namespace, facade.detach(namespace)); } - public @Override NamespaceInfo getDefaultNamespace() { + @Override + public NamespaceInfo getDefaultNamespace() { return facade.getDefaultNamespace(); } - public @Override void setDefaultNamespace(NamespaceInfo defaultNamespace) { + @Override + public void setDefaultNamespace(NamespaceInfo defaultNamespace) { if (defaultNamespace != null) { NamespaceInfo ns = getNamespaceByPrefix(defaultNamespace.getPrefix()); if (ns == null) { @@ -1017,31 +1102,38 @@ public static LayerInfo getLayerByName(Catalog catalog, String workspace, String } // Workspace methods - public @Override void add(WorkspaceInfo workspace) { + @Override + public void add(WorkspaceInfo workspace) { doAdd(workspace, facade::add); } - public @Override ValidationResult validate(WorkspaceInfo workspace, boolean isNew) { + @Override + public ValidationResult validate(WorkspaceInfo workspace, boolean isNew) { return validationSupport.validate(workspace, isNew); } - public @Override void remove(WorkspaceInfo workspace) { + @Override + public void remove(WorkspaceInfo workspace) { doRemove(workspace, facade::remove); } - public @Override void save(WorkspaceInfo workspace) { + @Override + public void save(WorkspaceInfo workspace) { doSave(workspace); } - public @Override WorkspaceInfo detach(WorkspaceInfo workspace) { + @Override + public WorkspaceInfo detach(WorkspaceInfo workspace) { return detach(workspace, facade.detach(workspace)); } - public @Override WorkspaceInfo getDefaultWorkspace() { + @Override + public WorkspaceInfo getDefaultWorkspace() { return facade.getDefaultWorkspace(); } - public @Override void setDefaultWorkspace(WorkspaceInfo defaultWorkspace) { + @Override + public void setDefaultWorkspace(WorkspaceInfo defaultWorkspace) { if (defaultWorkspace != null) { WorkspaceInfo ws = facade.getWorkspaceByName(defaultWorkspace.getName()); if (ws == null) { @@ -1061,15 +1153,18 @@ public static LayerInfo getLayerByName(Catalog catalog, String workspace, String firePostModified(this, asList("defaultWorkspace"), asList(old), asList(defaultWorkspace)); } - public @Override List getWorkspaces() { + @Override + public List getWorkspaces() { return unmodifiableList(facade.getWorkspaces()); } - public @Override WorkspaceInfo getWorkspace(String id) { + @Override + public WorkspaceInfo getWorkspace(String id) { return facade.getWorkspace(id); } - public @Override WorkspaceInfo getWorkspaceByName(String name) { + @Override + public WorkspaceInfo getWorkspaceByName(String name) { if (name == null || Catalog.DEFAULT.equals(name)) { WorkspaceInfo ws = getDefaultWorkspace(); if (ws != null) { @@ -1080,11 +1175,13 @@ public static LayerInfo getLayerByName(Catalog catalog, String workspace, String } // Style methods - public @Override StyleInfo getStyle(String id) { + @Override + public StyleInfo getStyle(String id) { return facade.getStyle(id); } - public @Override StyleInfo getStyleByName(String name) { + @Override + public StyleInfo getStyleByName(String name) { StyleInfo result = null; int colon = name.indexOf(':'); if (colon != -1) { @@ -1107,7 +1204,8 @@ public static LayerInfo getLayerByName(Catalog catalog, String workspace, String return result; } - public @Override StyleInfo getStyleByName(String workspaceName, String name) { + @Override + public StyleInfo getStyleByName(String workspaceName, String name) { if (workspaceName == null) { return getStyleByName((WorkspaceInfo) null, name); } @@ -1119,19 +1217,21 @@ public static LayerInfo getLayerByName(Catalog catalog, String workspace, String return null; } - public @Override StyleInfo getStyleByName(WorkspaceInfo workspace, String name) { + @Override + public StyleInfo getStyleByName(WorkspaceInfo workspace, String name) { if (workspace == null) { workspace = DefaultCatalogFacade.NO_WORKSPACE; } - StyleInfo style = facade.getStyleByName(workspace, name); - return style; + return facade.getStyleByName(workspace, name); } - public @Override List getStyles() { + @Override + public List getStyles() { return unmodifiableList(facade.getStyles()); } - public @Override List getStylesByWorkspace(String workspaceName) { + @Override + public List getStylesByWorkspace(String workspaceName) { WorkspaceInfo workspace = null; if (workspaceName != null) { workspace = getWorkspaceByName(workspaceName); @@ -1143,83 +1243,100 @@ public static LayerInfo getLayerByName(Catalog catalog, String workspace, String return getStylesByWorkspace(workspace); } - public @Override List getStylesByWorkspace(WorkspaceInfo workspace) { + @Override + public List getStylesByWorkspace(WorkspaceInfo workspace) { return unmodifiableList(facade.getStylesByWorkspace(workspace)); } - public @Override void add(StyleInfo style) { + @Override + public void add(StyleInfo style) { doAdd(style, facade::add); } - public @Override ValidationResult validate(StyleInfo style, boolean isNew) { + @Override + public ValidationResult validate(StyleInfo style, boolean isNew) { return validationSupport.validate(style, isNew); } - public @Override void remove(StyleInfo style) { + @Override + public void remove(StyleInfo style) { doRemove(style, facade::remove); } - public @Override void save(StyleInfo style) { + @Override + public void save(StyleInfo style) { doSave(style); } - public @Override StyleInfo detach(StyleInfo style) { + @Override + public StyleInfo detach(StyleInfo style) { return detach(style, facade.detach(style)); } // Event methods - public @Override Collection getListeners() { + @Override + public Collection getListeners() { return super.getListeners(); } - public @Override void addListener(CatalogListener listener) { + @Override + public void addListener(CatalogListener listener) { super.addListener(listener); } - public @Override void removeListener(CatalogListener listener) { + @Override + public void removeListener(CatalogListener listener) { super.removeListener(listener); } - public @Override void removeListeners(Class listenerClass) { + @Override + public void removeListeners(Class listenerClass) { super.removeListeners(listenerClass); } - public @Override ResourcePool getResourcePool() { + @Override + public ResourcePool getResourcePool() { return resourcePool; } - public @Override void setResourcePool(ResourcePool resourcePool) { + @Override + public void setResourcePool(ResourcePool resourcePool) { this.resourcePool = resourcePool; } - public @Override GeoServerResourceLoader getResourceLoader() { + @Override + public GeoServerResourceLoader getResourceLoader() { return resourceLoader; } - public @Override void setResourceLoader(GeoServerResourceLoader resourceLoader) { + @Override + public void setResourceLoader(GeoServerResourceLoader resourceLoader) { this.resourceLoader = resourceLoader; } - public @Override void dispose() { + @Override + public void dispose() { if (resourcePool != null) resourcePool.dispose(); facade.dispose(); } - // @Override TODO: add to the interface + @Override public void fireBeforeAdded(CatalogInfo object) { CatalogBeforeAddEventImpl event = new CatalogBeforeAddEventImpl(); event.setSource(object); event(event); } - public @Override void fireAdded(CatalogInfo object) { + @Override + public void fireAdded(CatalogInfo object) { CatalogAddEventImpl event = new CatalogAddEventImpl(); event.setSource(object); event(event); } - public @Override void fireModified( + @Override + public void fireModified( CatalogInfo object, List propertyNames, List oldValues, List newValues) { CatalogModifyEventImpl event = new CatalogModifyEventImpl(); @@ -1231,7 +1348,8 @@ public void fireBeforeAdded(CatalogInfo object) { event(event); } - public @Override void firePostModified( + @Override + public void firePostModified( CatalogInfo object, List propertyNames, List oldValues, List newValues) { CatalogPostModifyEventImpl event = new CatalogPostModifyEventImpl(); event.setSource(object); @@ -1241,14 +1359,16 @@ public void fireBeforeAdded(CatalogInfo object) { event(event); } - public @Override void fireRemoved(CatalogInfo object) { + @Override + public void fireRemoved(CatalogInfo object) { CatalogRemoveEventImpl event = new CatalogRemoveEventImpl(); event.setSource(object); event(event); } - public @Override void sync(CatalogImpl other) { + @Override + public void sync(CatalogImpl other) { other.getFacade().syncTo(facade); removeListeners(CatalogListener.class); other.getListeners().forEach(this::addListener); @@ -1266,21 +1386,25 @@ public void fireBeforeAdded(CatalogInfo object) { resourceLoader = other.getResourceLoader(); } - public @Override void accept(CatalogVisitor visitor) { + @Override + public void accept(CatalogVisitor visitor) { visitor.visit(this); } - public @Override int count(final Class of, final Filter filter) { + @Override + public int count(final Class of, final Filter filter) { final CatalogFacade facade = getFacade(); return facade.count(of, filter); } - public @Override CloseableIterator list( + @Override + public CloseableIterator list( final Class of, final Filter filter) { return list(of, filter, null, null, null); } - public @Override CloseableIterator list( + @Override + public CloseableIterator list( final Class of, final Filter filter, Integer offset, @@ -1298,10 +1422,10 @@ public void fireBeforeAdded(CatalogInfo object) { Query query = Query.valueOf(of, filter, offset, count, sortOrder); Stream stream = getFacade().query(query); - return new CloseableIteratorAdapter<>(stream.iterator(), () -> stream.close()); + return new CloseableIteratorAdapter<>(stream.iterator(), stream::close); } - public Optional findById(@NonNull String id) { + public Optional findById(@NonNull String id) { FilterFactory ff = CommonFactoryFinder.getFilterFactory(); final Filter filter = ff.id(ff.featureId(id)); @@ -1316,10 +1440,12 @@ public Optional findById(@NonNull String id) { MapInfo.class) .map(type -> get(type, filter)) .filter(Objects::nonNull) + .map(CatalogInfo.class::cast) .findFirst(); } - public @Override T get(Class type, Filter filter) + @Override + public T get(Class type, Filter filter) throws IllegalArgumentException { // try optimizing by querying by id first, defer to regular filter query if filter is not // and Id filter @@ -1389,16 +1515,15 @@ private T findOneById(String id, Class type) { private Optional getIdIfIdFilter(Filter filter) { String id = null; - if (filter instanceof Id) { - Set identifiers = ((Id) filter).getIdentifiers(); + if (filter instanceof Id idFilter) { + Set identifiers = idFilter.getIdentifiers(); if (identifiers.size() == 1) { id = identifiers.iterator().next().toString(); } - } else if (filter instanceof PropertyIsEqualTo) { - PropertyIsEqualTo eq = (PropertyIsEqualTo) filter; + } else if (filter instanceof PropertyIsEqualTo eq) { boolean idProperty = - (eq.getExpression1() instanceof PropertyName) - && "id".equals(((PropertyName) eq.getExpression1()).getPropertyName()); + (eq.getExpression1() instanceof PropertyName prop) + && "id".equals(prop.getPropertyName()); if (idProperty && eq.getExpression2() instanceof Literal) { id = Converters.convert(eq.getExpression2().evaluate(null), String.class); } @@ -1411,7 +1536,8 @@ protected Optional classMapping(Class .or(() -> Optional.ofNullable(ClassMappings.fromImpl(type))); } - public @Override CatalogCapabilities getCatalogCapabilities() { + @Override + public CatalogCapabilities getCatalogCapabilities() { return facade.getCatalogCapabilities(); } @@ -1550,18 +1676,10 @@ public void remove(CatalogInfo info) { case NAMESPACE: remove((NamespaceInfo) info); break; - case STORE: - case COVERAGESTORE: - case DATASTORE: - case WMSSTORE: - case WMTSSTORE: + case STORE, COVERAGESTORE, DATASTORE, WMSSTORE, WMTSSTORE: remove((StoreInfo) info); break; - case RESOURCE: - case FEATURETYPE: - case COVERAGE: - case WMSLAYER: - case WMTSLAYER: + case RESOURCE, FEATURETYPE, COVERAGE, WMSLAYER, WMTSLAYER: remove((ResourceInfo) info); break; case LAYER: diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/DefaultMemoryCatalogFacade.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/DefaultMemoryCatalogFacade.java index 4fc4f75d7..131ca7362 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/DefaultMemoryCatalogFacade.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/DefaultMemoryCatalogFacade.java @@ -66,7 +66,8 @@ public DefaultMemoryCatalogFacade(Catalog catalog) { setStyleRepository(new StyleInfoLookup()); } - public @Override void resolve() { + @Override + public void resolve() { // JD creation checks are done here b/c when xstream depersists // some members may be left null workspaces = resolve(workspaces, WorkspaceInfoLookup::new); @@ -159,27 +160,27 @@ private void resolveLayerGroupStyles( private void resolveLayerGroupLayers(List layers) { for (int i = 0; i < layers.size(); i++) { - PublishedInfo l = layers.get(i); + PublishedInfo published = layers.get(i); - if (l != null) { + if (published != null) { PublishedInfo resolved; - if (l instanceof LayerGroupInfo) { - resolved = unwrap(ResolvingProxy.resolve(getCatalog(), (LayerGroupInfo) l)); - // special case to handle catalog loading, when nested publishibles might not be + if (published instanceof LayerGroupInfo lg) { + resolved = unwrap(ResolvingProxy.resolve(getCatalog(), lg)); + // special case to handle catalog loading, when nested publishables might not be // loaded. if (resolved == null) { - resolved = l; + resolved = published; } - } else if (l instanceof LayerInfo) { - resolved = unwrap(ResolvingProxy.resolve(getCatalog(), (LayerInfo) l)); - // special case to handle catalog loading, when nested publishibles might not be + } else if (published instanceof LayerInfo l) { + resolved = unwrap(ResolvingProxy.resolve(getCatalog(), l)); + // special case to handle catalog loading, when nested publishables might not be // loaded. if (resolved == null) { - resolved = l; + resolved = published; } } else { // Special case for null layer (style group) - resolved = unwrap(ResolvingProxy.resolve(getCatalog(), l)); + resolved = unwrap(ResolvingProxy.resolve(getCatalog(), published)); } layers.set(i, resolved); } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/ExtendedCatalogFacade.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/ExtendedCatalogFacade.java index d6c584ea6..cc12f8085 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/ExtendedCatalogFacade.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/ExtendedCatalogFacade.java @@ -65,7 +65,7 @@ public interface ExtendedCatalogFacade extends CatalogFacade { Stream stream = query(query); final Closeable closeable = stream::close; - return new CloseableIteratorAdapter(stream.iterator(), closeable); + return new CloseableIteratorAdapter<>(stream.iterator(), closeable); } /** diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/IsolatedCatalogFacade.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/IsolatedCatalogFacade.java index e66cc6638..d86b309a3 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/IsolatedCatalogFacade.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/IsolatedCatalogFacade.java @@ -26,13 +26,11 @@ import org.geotools.api.filter.Filter; import org.geotools.api.filter.sort.SortBy; -import java.io.Closeable; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.function.Predicate; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nullable; @@ -243,10 +241,11 @@ public CloseableIterator list( if (count != null) { filtered = Iterators.limit(filtered, count.intValue()); } - return new CloseableIteratorAdapter<>(filtered, (Closeable) all); + return new CloseableIteratorAdapter<>(filtered, all); } - public @Override Stream query(Query query) { + @Override + public Stream query(Query query) { return ((ExtendedCatalogFacade) facade) .query(query) .map(this::enforceIsolation) @@ -272,13 +271,11 @@ private WorkspaceInfo getLocalWorkspace() { @SuppressWarnings("unchecked") private T enforceIsolation(T info) { - if (StoreInfo.class.isInstance(info)) return (T) enforceStoreIsolation((StoreInfo) info); - if (ResourceInfo.class.isInstance(info)) - return (T) enforceResourceIsolation((ResourceInfo) info); - if (LayerInfo.class.isInstance(info)) return (T) enforceLayerIsolation((LayerInfo) info); - if (LayerGroupInfo.class.isInstance(info)) - return (T) enforceLayerGroupIsolation((LayerGroupInfo) info); - if (StyleInfo.class.isInstance(info)) return (T) enforceStyleIsolation((StyleInfo) info); + if (info instanceof StoreInfo store) return (T) enforceStoreIsolation(store); + if (info instanceof ResourceInfo resource) return (T) enforceResourceIsolation(resource); + if (info instanceof LayerInfo layer) return (T) enforceLayerIsolation(layer); + if (info instanceof LayerGroupInfo lg) return (T) enforceLayerGroupIsolation(lg); + if (info instanceof StyleInfo style) return (T) enforceStyleIsolation(style); return info; } @@ -429,8 +426,7 @@ private List filterIsolated( List unwrapped = ModificationProxy.unwrap(objects); // filter the non visible catalog objects and wrap the resulting list with a modification // proxy - return ModificationProxy.createList( - unwrapped.stream().filter(filter).collect(Collectors.toList()), type); + return ModificationProxy.createList(unwrapped.stream().filter(filter).toList(), type); } /** diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/Patch.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/Patch.java index a04bbb000..c8ea67ca2 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/Patch.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/Patch.java @@ -36,11 +36,13 @@ public V value() { return (V) value; } - public @Override boolean equals(Object o) { - return o instanceof Property && valueEquals(value(), ((Property) o).value()); + @Override + public boolean equals(Object o) { + return o instanceof Property p && valueEquals(value(), p.value()); } - public @Override int hashCode() { + @Override + public int hashCode() { return Objects.hash(Property.class, value); } @@ -54,20 +56,18 @@ public static boolean valueEquals(final Object v1, final Object v2) { final Class componentType = v1.getClass().getComponentType(); if (componentType.isPrimitive()) { - boolean equals = - switch (componentType.getCanonicalName()) { - case "byte" -> Arrays.equals((byte[]) v1, (byte[]) v2); - case "boolean" -> Arrays.equals((boolean[]) v1, (boolean[]) v2); - case "char" -> Arrays.equals((char[]) v1, (char[]) v2); - case "short" -> Arrays.equals((short[]) v1, (short[]) v2); - case "int" -> Arrays.equals((int[]) v1, (int[]) v2); - case "long" -> Arrays.equals((long[]) v1, (long[]) v2); - case "float" -> Arrays.equals((float[]) v1, (float[]) v2); - case "double" -> Arrays.equals((double[]) v1, (double[]) v2); - default -> throw new IllegalArgumentException( - "Unexpected value: " + componentType); - }; - return equals; + return switch (componentType.getCanonicalName()) { + case "byte" -> Arrays.equals((byte[]) v1, (byte[]) v2); + case "boolean" -> Arrays.equals((boolean[]) v1, (boolean[]) v2); + case "char" -> Arrays.equals((char[]) v1, (char[]) v2); + case "short" -> Arrays.equals((short[]) v1, (short[]) v2); + case "int" -> Arrays.equals((int[]) v1, (int[]) v2); + case "long" -> Arrays.equals((long[]) v1, (long[]) v2); + case "float" -> Arrays.equals((float[]) v1, (float[]) v2); + case "double" -> Arrays.equals((double[]) v1, (double[]) v2); + default -> throw new IllegalArgumentException( + "Unexpected value: " + componentType); + }; } else { Object[] a1 = (Object[]) v1; Object[] a2 = (Object[]) v2; @@ -181,7 +181,8 @@ private static boolean isCollection(Method getter) { return Collection.class.isAssignableFrom(getter.getReturnType()); } - public @Override String toString() { + @Override + public String toString() { String props = this.getPatches().stream() .map(p -> String.format("(%s: %s)", p.getName(), p.getValue())) diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/PropertyDiff.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/PropertyDiff.java index fe8a05abc..0177cd124 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/PropertyDiff.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/PropertyDiff.java @@ -110,8 +110,7 @@ public List getNewValues() { * @return a "clean copy", where no-op changes are ignored */ public PropertyDiff clean() { - return new PropertyDiff( - changes.stream().filter(c -> !c.isNoChange()).collect(Collectors.toList())); + return new PropertyDiff(changes.stream().filter(Change::isNotEmpty).toList()); } public boolean isEmpty() { @@ -123,8 +122,12 @@ public boolean isEmpty() { public static @Data class Change implements Serializable { private static final long serialVersionUID = 1L; private @NonNull String propertyName; - private Object oldValue; - private Object newValue; + private transient Object oldValue; + private transient Object newValue; + + boolean isNotEmpty() { + return !isNoChange(); + } public boolean isNoChange() { if (Objects.equals(oldValue, newValue)) return true; @@ -166,9 +169,9 @@ private String toStringOrNull(Object o) { private boolean isNullOrEmpty(Object o) { if (o == null) return true; - if (o instanceof String) return ((String) o).isEmpty(); - if (o instanceof Collection) return ((Collection) o).isEmpty(); - if (o instanceof Map) return ((Map) o).isEmpty(); + if (o instanceof String s) return s.isEmpty(); + if (o instanceof Collection c) return c.isEmpty(); + if (o instanceof Map m) return m.isEmpty(); return false; } @@ -200,7 +203,8 @@ public static Change valueOf(String propertyName, Object oldValue, Object newVal return new Change(propertyName, oldValue, newValue); } - public @Override String toString() { + @Override + public String toString() { return String.format("%s: {old: %s, new: %s}", propertyName, oldValue, newValue); } } @@ -241,7 +245,7 @@ private static Object hanldeProxy(Object value) { return value; } - private static Set> IGNORE = + private static final Set> IGNORE = Set.of(Info.class, Catalog.class, ServiceInfo.class, PublishedInfo.class); @SuppressWarnings("unchecked") @@ -322,12 +326,10 @@ public PropertyDiffBuilder with(String property, Object oldValue, Object newV return this; } - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"unchecked"}) public static V copySafe(V val) { - if (val instanceof Collection) return (V) copyOf((Collection) val); - if (val instanceof Map) { - return (V) copyOf((Map) val); - } + if (val instanceof Collection c) return (V) copyOf(c); + if (val instanceof Map m) return (V) copyOf(m); return val; } @@ -340,15 +342,15 @@ public static Collection copyOf( Stream stream = val.stream().map(PropertyDiffBuilder::copySafe).map(mapper); - if (val instanceof SortedSet) { + if (val instanceof SortedSet set) { @SuppressWarnings("unchecked") - Comparator comparator = ((SortedSet) val).comparator(); + Comparator comparator = (Comparator) set.comparator(); return stream.collect(Collectors.toCollection(() -> new TreeSet<>(comparator))); } - if (val instanceof Set) { + if (val instanceof Set) { return stream.collect(Collectors.toCollection(HashSet::new)); } - return stream.collect(Collectors.toList()); + return stream.toList(); } public static Map copyOf(final Map val) { @@ -360,8 +362,8 @@ public static Map copyOf(final Map val, Function val Map target; if (val instanceof MetadataMap) { target = new MetadataMap(); - } else if (val instanceof SortedMap) { - Comparator comparator = ((SortedMap) val).comparator(); + } else if (val instanceof SortedMap sortedMap) { + Comparator comparator = sortedMap.comparator(); target = new TreeMap<>(comparator); } else { target = new HashMap<>(); diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/Query.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/Query.java index e3fb44c9f..7cb911f34 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/Query.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/Query.java @@ -16,11 +16,11 @@ import org.geotools.api.filter.sort.SortBy; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.OptionalInt; -import java.util.stream.Collectors; +import java.util.stream.Stream; /** */ @NoArgsConstructor @@ -83,9 +83,7 @@ public static Query valueOf( List sortBy = sortOrder == null ? Collections.emptyList() - : Arrays.asList(sortOrder).stream() - .filter(s -> s != null) - .collect(Collectors.toList()); + : Stream.of(sortOrder).filter(Objects::nonNull).toList(); filter = filter == null ? Filter.INCLUDE : filter; return new Query<>((Class) type) diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/RepositoryCatalogFacadeImpl.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/RepositoryCatalogFacadeImpl.java index 537e9a13f..da0d766ec 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/RepositoryCatalogFacadeImpl.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/RepositoryCatalogFacadeImpl.java @@ -36,7 +36,6 @@ import java.util.function.Supplier; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import java.util.stream.Stream; public class RepositoryCatalogFacadeImpl extends CatalogInfoRepositoryHolderImpl @@ -55,19 +54,23 @@ public RepositoryCatalogFacadeImpl(Catalog catalog) { setCatalog(catalog); } - public @Override CatalogCapabilities getCatalogCapabilities() { + @Override + public CatalogCapabilities getCatalogCapabilities() { return capabilities; } - public @Override void setCatalog(Catalog catalog) { + @Override + public void setCatalog(Catalog catalog) { this.catalog = catalog; } - public @Override Catalog getCatalog() { + @Override + public Catalog getCatalog() { return catalog; } - public @Override void resolve() { + @Override + public void resolve() { // no-op, override as appropriate } @@ -82,19 +85,23 @@ protected I add( // // Stores // - public @Override StoreInfo add(StoreInfo store) { + @Override + public StoreInfo add(StoreInfo store) { return add(store, StoreInfo.class, stores); } - public @Override void remove(StoreInfo store) { + @Override + public void remove(StoreInfo store) { stores.remove(store); } - public @Override T getStore(String id, Class clazz) { + @Override + public T getStore(String id, Class clazz) { return stores.findById(id, clazz).orElse(null); } - public @Override T getStoreByName( + @Override + public T getStoreByName( WorkspaceInfo workspace, String name, Class clazz) { Optional result; @@ -106,7 +113,8 @@ protected I add( return result.orElse(null); } - public @Override List getStoresByWorkspace( + @Override + public List getStoresByWorkspace( WorkspaceInfo workspace, Class clazz) { // TODO: support ANY_WORKSPACE? final WorkspaceInfo ws; @@ -119,15 +127,18 @@ protected I add( return toList(() -> stores.findAllByWorkspace(ws, clazz)); } - public @Override List getStores(Class clazz) { + @Override + public List getStores(Class clazz) { return toList(() -> stores.findAllByType(clazz)); } - public @Override DataStoreInfo getDefaultDataStore(WorkspaceInfo workspace) { + @Override + public DataStoreInfo getDefaultDataStore(WorkspaceInfo workspace) { return stores.getDefaultDataStore(workspace).orElse(null); } - public @Override void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo store) { + @Override + public void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo store) { if (store != null) { Objects.requireNonNull(store.getWorkspace()); Assert.isTrue( @@ -142,19 +153,23 @@ protected I add( // // Resources // - public @Override ResourceInfo add(ResourceInfo resource) { + @Override + public ResourceInfo add(ResourceInfo resource) { return add(resource, ResourceInfo.class, resources); } - public @Override void remove(ResourceInfo resource) { + @Override + public void remove(ResourceInfo resource) { resources.remove(resource); } - public @Override T getResource(String id, Class clazz) { + @Override + public T getResource(String id, Class clazz) { return resources.findById(id, clazz).orElse(null); } - public @Override T getResourceByName( + @Override + public T getResourceByName( NamespaceInfo namespace, String name, Class clazz) { Optional result; if (namespace == ANY_NAMESPACE) { @@ -166,18 +181,21 @@ protected I add( return result.orElse(null); } - public @Override List getResources(Class clazz) { + @Override + public List getResources(Class clazz) { return toList(() -> resources.findAllByType(clazz)); } - public @Override List getResourcesByNamespace( + @Override + public List getResourcesByNamespace( NamespaceInfo namespace, Class clazz) { // TODO: support ANY_NAMESPACE? NamespaceInfo ns = namespace == null ? getDefaultNamespace() : namespace; return toList(() -> resources.findAllByNamespace(ns, clazz)); } - public @Override T getResourceByStore( + @Override + public T getResourceByStore( StoreInfo store, String name, Class clazz) { Optional resource; NamespaceInfo ns = null; @@ -198,81 +216,97 @@ protected I add( return resource.orElse(null); } - public @Override List getResourcesByStore( - StoreInfo store, Class clazz) { + @Override + public List getResourcesByStore(StoreInfo store, Class clazz) { return toList(() -> resources.findAllByStore(store, clazz)); } // // Layers // - public @Override LayerInfo add(LayerInfo layer) { + @Override + public LayerInfo add(LayerInfo layer) { return add(layer, LayerInfo.class, layers); } - public @Override void remove(LayerInfo layer) { + @Override + public void remove(LayerInfo layer) { layers.remove(layer); } - public @Override LayerInfo getLayer(String id) { + @Override + public LayerInfo getLayer(String id) { return layers.findById(id, LayerInfo.class).orElse(null); } - public @Override LayerInfo getLayerByName(String name) { + @Override + public LayerInfo getLayerByName(String name) { return layers.findOneByName(name).orElse(null); } - public @Override List getLayers(ResourceInfo resource) { + @Override + public List getLayers(ResourceInfo resource) { return toList(() -> layers.findAllByResource(resource)); } - public @Override List getLayers(StyleInfo style) { + @Override + public List getLayers(StyleInfo style) { return toList(() -> layers.findAllByDefaultStyleOrStyles(style)); } - public @Override List getLayers() { + @Override + public List getLayers() { return toList(layers::findAll); } // // Maps // - public @Override MapInfo add(MapInfo map) { + @Override + public MapInfo add(MapInfo map) { return add(map, MapInfo.class, maps); } - public @Override void remove(MapInfo map) { + @Override + public void remove(MapInfo map) { maps.remove(map); } - public @Override MapInfo getMap(String id) { + @Override + public MapInfo getMap(String id) { return maps.findById(id, MapInfo.class).orElse(null); } - public @Override MapInfo getMapByName(String name) { + @Override + public MapInfo getMapByName(String name) { return maps.findFirstByName(name, MapInfo.class).orElse(null); } - public @Override List getMaps() { + @Override + public List getMaps() { return toList(maps::findAll); } // // Layer groups // - public @Override LayerGroupInfo add(LayerGroupInfo layerGroup) { + @Override + public LayerGroupInfo add(LayerGroupInfo layerGroup) { return add(layerGroup, LayerGroupInfo.class, getLayerGroupRepository()); } - public @Override void remove(LayerGroupInfo layerGroup) { + @Override + public void remove(LayerGroupInfo layerGroup) { getLayerGroupRepository().remove(layerGroup); } - public @Override List getLayerGroups() { + @Override + public List getLayerGroups() { return toList(getLayerGroupRepository()::findAll); } - public @Override List getLayerGroupsByWorkspace(WorkspaceInfo workspace) { + @Override + public List getLayerGroupsByWorkspace(WorkspaceInfo workspace) { // TODO: support ANY_WORKSPACE? WorkspaceInfo ws; @@ -290,15 +324,18 @@ protected I add( return toList(() -> matches); } - public @Override LayerGroupInfo getLayerGroup(String id) { + @Override + public LayerGroupInfo getLayerGroup(String id) { return getLayerGroupRepository().findById(id, LayerGroupInfo.class).orElse(null); } - public @Override LayerGroupInfo getLayerGroupByName(String name) { + @Override + public LayerGroupInfo getLayerGroupByName(String name) { return getLayerGroupByName(NO_WORKSPACE, name); } - public @Override LayerGroupInfo getLayerGroupByName(WorkspaceInfo workspace, String name) { + @Override + public LayerGroupInfo getLayerGroupByName(WorkspaceInfo workspace, String name) { if (workspace == NO_WORKSPACE) return getLayerGroupRepository().findByNameAndWorkspaceIsNull(name).orElse(null); @@ -314,11 +351,13 @@ protected I add( // // Namespaces // - public @Override NamespaceInfo add(NamespaceInfo namespace) { + @Override + public NamespaceInfo add(NamespaceInfo namespace) { return add(namespace, NamespaceInfo.class, namespaces); } - public @Override void remove(NamespaceInfo namespace) { + @Override + public void remove(NamespaceInfo namespace) { NamespaceInfo defaultNamespace = getDefaultNamespace(); if (defaultNamespace != null && namespace.getId().equals(defaultNamespace.getId())) { setDefaultNamespace(null); @@ -326,32 +365,39 @@ protected I add( namespaces.remove(namespace); } - public @Override NamespaceInfo getDefaultNamespace() { + @Override + public NamespaceInfo getDefaultNamespace() { return namespaces.getDefaultNamespace().orElse(null); } - public @Override void setDefaultNamespace(NamespaceInfo defaultNamnespace) { + @Override + public void setDefaultNamespace(NamespaceInfo defaultNamnespace) { if (defaultNamnespace == null) namespaces.unsetDefaultNamespace(); else namespaces.setDefaultNamespace(defaultNamnespace); } - public @Override NamespaceInfo getNamespace(String id) { + @Override + public NamespaceInfo getNamespace(String id) { return namespaces.findById(id, NamespaceInfo.class).orElse(null); } - public @Override NamespaceInfo getNamespaceByPrefix(String prefix) { + @Override + public NamespaceInfo getNamespaceByPrefix(String prefix) { return namespaces.findFirstByName(prefix, NamespaceInfo.class).orElse(null); } - public @Override NamespaceInfo getNamespaceByURI(String uri) { + @Override + public NamespaceInfo getNamespaceByURI(String uri) { return namespaces.findOneByURI(uri).orElse(null); } - public @Override List getNamespacesByURI(String uri) { + @Override + public List getNamespacesByURI(String uri) { return toList(() -> namespaces.findAllByURI(uri)); } - public @Override List getNamespaces() { + @Override + public List getNamespaces() { return toList(namespaces::findAll); } @@ -359,11 +405,13 @@ protected I add( // Workspaces // // Workspace methods - public @Override WorkspaceInfo add(WorkspaceInfo workspace) { + @Override + public WorkspaceInfo add(WorkspaceInfo workspace) { return add(workspace, WorkspaceInfo.class, workspaces); } - public @Override void remove(WorkspaceInfo workspace) { + @Override + public void remove(WorkspaceInfo workspace) { WorkspaceInfo defaultWorkspace = getDefaultWorkspace(); if (defaultWorkspace != null && workspace.getId().equals(defaultWorkspace.getId())) { workspaces.unsetDefaultWorkspace(); @@ -371,44 +419,53 @@ protected I add( workspaces.remove(workspace); } - public @Override WorkspaceInfo getDefaultWorkspace() { + @Override + public WorkspaceInfo getDefaultWorkspace() { return workspaces.getDefaultWorkspace().orElse(null); } - public @Override void setDefaultWorkspace(WorkspaceInfo workspace) { + @Override + public void setDefaultWorkspace(WorkspaceInfo workspace) { WorkspaceInfo ws = workspace; if (ws == null) workspaces.unsetDefaultWorkspace(); else workspaces.setDefaultWorkspace(ws); } - public @Override List getWorkspaces() { + @Override + public List getWorkspaces() { return toList(workspaces::findAll); } - public @Override WorkspaceInfo getWorkspace(String id) { + @Override + public WorkspaceInfo getWorkspace(String id) { return workspaces.findById(id, WorkspaceInfo.class).orElse(null); } - public @Override WorkspaceInfo getWorkspaceByName(String name) { + @Override + public WorkspaceInfo getWorkspaceByName(String name) { return workspaces.findFirstByName(name, WorkspaceInfo.class).orElse(null); } // // Styles // - public @Override StyleInfo add(StyleInfo style) { + @Override + public StyleInfo add(StyleInfo style) { return add(style, StyleInfo.class, styles); } - public @Override void remove(StyleInfo style) { + @Override + public void remove(StyleInfo style) { styles.remove(style); } - public @Override StyleInfo getStyle(String id) { + @Override + public StyleInfo getStyle(String id) { return styles.findById(id, StyleInfo.class).orElse(null); } - public @Override StyleInfo getStyleByName(String name) { + @Override + public StyleInfo getStyleByName(String name) { Optional match = styles.findByNameAndWordkspaceNull(name); if (match.isEmpty()) { match = styles.findFirstByName(name, StyleInfo.class); @@ -416,7 +473,8 @@ protected I add( return match.orElse(null); } - public @Override StyleInfo getStyleByName(WorkspaceInfo workspace, String name) { + @Override + public StyleInfo getStyleByName(WorkspaceInfo workspace, String name) { Objects.requireNonNull(workspace, "workspace"); Objects.requireNonNull(name, "name"); @@ -432,11 +490,13 @@ protected I add( return match.orElse(null); } - public @Override List getStyles() { + @Override + public List getStyles() { return toList(styles::findAll); } - public @Override List getStylesByWorkspace(WorkspaceInfo workspace) { + @Override + public List getStylesByWorkspace(WorkspaceInfo workspace) { // TODO: support ANY_WORKSPACE? Stream matches; if (workspace == NO_WORKSPACE) { @@ -456,11 +516,12 @@ protected I add( protected List toList(Supplier> supplier) { try (Stream stream = supplier.get()) { - return stream.collect(Collectors.toList()); + return stream.toList(); } } - public @Override void dispose() { + @Override + public void dispose() { dispose(stores); dispose(resources); dispose(namespaces); @@ -475,11 +536,11 @@ private void dispose(CatalogInfoRepository repository) { if (repository != null) repository.dispose(); } - public @Override void syncTo(CatalogFacade to) { + @Override + public void syncTo(CatalogFacade to) { final CatalogFacade dao = ProxyUtils.unwrap(to, LockingCatalogFacade.class); - if (dao instanceof CatalogInfoRepositoryHolder) { + if (dao instanceof CatalogInfoRepositoryHolder other) { // do an optimized sync - CatalogInfoRepositoryHolder other = (CatalogInfoRepositoryHolder) dao; this.workspaces.syncTo(other.getWorkspaceRepository()); this.namespaces.syncTo(other.getNamespaceRepository()); this.stores.syncTo(other.getStoreRepository()); @@ -514,7 +575,8 @@ private void sync(Supplier> from, Consumer } } - public @Override int count(final Class of, final Filter filter) { + @Override + public int count(final Class of, final Filter filter) { long count; if (PublishedInfo.class.equals(of)) { long layers = count(LayerInfo.class, filter); @@ -526,10 +588,10 @@ private void sync(Supplier> from, Consumer } catch (RuntimeException e) { LOGGER.log( Level.SEVERE, - "Error obtaining count of " - + of.getSimpleName() - + " with filter " - + filter); + e, + () -> + "Error obtaining count of %s with filter %s" + .formatted(of.getSimpleName(), filter)); throw e; } } @@ -544,8 +606,8 @@ private void sync(Supplier> from, Consumer * @param propertyName the property name of the objects of type {@code type} to sort by * @see CatalogInfoRepository#canSortBy(String) */ - public @Override boolean canSort( - final Class type, final String propertyName) { + @Override + public boolean canSort(final Class type, final String propertyName) { if (PublishedInfo.class.equals(type)) { return canSort(LayerInfo.class, propertyName) || canSort(LayerGroupInfo.class, propertyName); @@ -566,7 +628,8 @@ private void checkCanSort(final Class type, SortBy or } } - public @Override Stream query(Query query) { + @Override + public Stream query(Query query) { Stream stream; if (PublishedInfo.class.equals(query.getType())) { Query lq = new Query<>(LayerInfo.class, query); @@ -580,14 +643,15 @@ private void checkCanSort(final Class type, SortBy or checkCanSort(query); stream = repository(query.getType()).findAll(query); } catch (RuntimeException e) { - LOGGER.log(Level.SEVERE, "Error obtaining stream: " + query, e); + LOGGER.log(Level.SEVERE, e, () -> "Error obtaining stream: " + query); throw e; } } return stream; } - public @Override I update(I info, Patch patch) { + @Override + public I update(I info, Patch patch) { checkNotAProxy(info); CatalogInfoRepository repo = repositoryFor(info); return repo.update(info, patch); diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingCatalog.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingCatalog.java index c8786113c..b1732b254 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingCatalog.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingCatalog.java @@ -68,584 +68,721 @@ public Catalog getSubject() { return catalog; } - public @Override String getId() { + @Override + public String getId() { return catalog.getId(); } - public @Override void accept(CatalogVisitor visitor) { + @Override + public void accept(CatalogVisitor visitor) { catalog.accept(visitor); } - public @Override Date getDateModified() { + @Override + public Date getDateModified() { return catalog.getDateModified(); } - public @Override Date getDateCreated() { + @Override + public Date getDateCreated() { return catalog.getDateCreated(); } - public @Override void setDateCreated(Date dateCreated) { + @Override + public void setDateCreated(Date dateCreated) { catalog.setDateCreated(dateCreated); } - public @Override void setDateModified(Date dateModified) { + @Override + public void setDateModified(Date dateModified) { catalog.setDateModified(dateModified); } - public @Override CatalogFacade getFacade() { + @Override + public CatalogFacade getFacade() { return catalog.getFacade(); } - public @Override CatalogFactory getFactory() { + @Override + public CatalogFactory getFactory() { return catalog.getFactory(); } - public @Override void add(StoreInfo store) { + @Override + public void add(StoreInfo store) { catalog.add(store); } - public @Override ValidationResult validate(StoreInfo store, boolean isNew) { + @Override + public ValidationResult validate(StoreInfo store, boolean isNew) { return catalog.validate(store, isNew); } - public @Override void remove(StoreInfo store) { + @Override + public void remove(StoreInfo store) { catalog.remove(store); } - public @Override void save(StoreInfo store) { + @Override + public void save(StoreInfo store) { catalog.save(store); } - public @Override T getStore(String id, Class clazz) { + @Override + public T getStore(String id, Class clazz) { return catalog.getStore(id, clazz); } - public @Override T getStoreByName(String name, Class clazz) { + @Override + public T getStoreByName(String name, Class clazz) { return catalog.getStoreByName(name, clazz); } - public @Override T getStoreByName( + @Override + public T getStoreByName( String workspaceName, String name, Class clazz) { return catalog.getStoreByName(workspaceName, name, clazz); } - public @Override T getStoreByName( + @Override + public T getStoreByName( WorkspaceInfo workspace, String name, Class clazz) { return catalog.getStoreByName(workspace, name, clazz); } - public @Override List getStores(Class clazz) { + @Override + public List getStores(Class clazz) { return catalog.getStores(clazz); } - public @Override WMSStoreInfo getWMSStore(String id) { + @Override + public WMSStoreInfo getWMSStore(String id) { return catalog.getWMSStore(id); } - public @Override WMSStoreInfo getWMSStoreByName(String name) { + @Override + public WMSStoreInfo getWMSStoreByName(String name) { return catalog.getWMSStoreByName(name); } - public @Override WMTSStoreInfo getWMTSStore(String id) { + @Override + public WMTSStoreInfo getWMTSStore(String id) { return catalog.getWMTSStore(id); } - public @Override WMTSStoreInfo getWMTSStoreByName(String name) { + @Override + public WMTSStoreInfo getWMTSStoreByName(String name) { return catalog.getWMTSStoreByName(name); } - public @Override List getStoresByWorkspace( + @Override + public List getStoresByWorkspace( WorkspaceInfo workspace, Class clazz) { return catalog.getStoresByWorkspace(workspace, clazz); } - public @Override List getStoresByWorkspace( + @Override + public List getStoresByWorkspace( String workspaceName, Class clazz) { return catalog.getStoresByWorkspace(workspaceName, clazz); } - public @Override DataStoreInfo getDataStore(String id) { + @Override + public DataStoreInfo getDataStore(String id) { return catalog.getDataStore(id); } - public @Override DataStoreInfo getDataStoreByName(String name) { + @Override + public DataStoreInfo getDataStoreByName(String name) { return catalog.getDataStoreByName(name); } - public @Override DataStoreInfo getDataStoreByName(String workspaceName, String name) { + @Override + public DataStoreInfo getDataStoreByName(String workspaceName, String name) { return catalog.getDataStoreByName(workspaceName, name); } - public @Override DataStoreInfo getDataStoreByName(WorkspaceInfo workspace, String name) { + @Override + public DataStoreInfo getDataStoreByName(WorkspaceInfo workspace, String name) { return catalog.getDataStoreByName(workspace, name); } - public @Override List getDataStoresByWorkspace(String workspaceName) { + @Override + public List getDataStoresByWorkspace(String workspaceName) { return catalog.getDataStoresByWorkspace(workspaceName); } - public @Override List getDataStoresByWorkspace(WorkspaceInfo workspace) { + @Override + public List getDataStoresByWorkspace(WorkspaceInfo workspace) { return catalog.getDataStoresByWorkspace(workspace); } - public @Override List getDataStores() { + @Override + public List getDataStores() { return catalog.getDataStores(); } - public @Override DataStoreInfo getDefaultDataStore(WorkspaceInfo workspace) { + @Override + public DataStoreInfo getDefaultDataStore(WorkspaceInfo workspace) { return catalog.getDefaultDataStore(workspace); } - public @Override void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo defaultStore) { + @Override + public void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo defaultStore) { catalog.setDefaultDataStore(workspace, defaultStore); } - public @Override CoverageStoreInfo getCoverageStore(String id) { + @Override + public CoverageStoreInfo getCoverageStore(String id) { return catalog.getCoverageStore(id); } - public @Override CoverageStoreInfo getCoverageStoreByName(String name) { + @Override + public CoverageStoreInfo getCoverageStoreByName(String name) { return catalog.getCoverageStoreByName(name); } - public @Override CoverageStoreInfo getCoverageStoreByName(String workspaceName, String name) { + @Override + public CoverageStoreInfo getCoverageStoreByName(String workspaceName, String name) { return catalog.getCoverageStoreByName(workspaceName, name); } - public @Override CoverageStoreInfo getCoverageStoreByName( - WorkspaceInfo workspace, String name) { + @Override + public CoverageStoreInfo getCoverageStoreByName(WorkspaceInfo workspace, String name) { return catalog.getCoverageStoreByName(workspace, name); } - public @Override List getCoverageStoresByWorkspace(String workspaceName) { + @Override + public List getCoverageStoresByWorkspace(String workspaceName) { return catalog.getCoverageStoresByWorkspace(workspaceName); } - public @Override List getCoverageStoresByWorkspace(WorkspaceInfo workspace) { + @Override + public List getCoverageStoresByWorkspace(WorkspaceInfo workspace) { return catalog.getCoverageStoresByWorkspace(workspace); } - public @Override List getCoverageStores() { + @Override + public List getCoverageStores() { return catalog.getCoverageStores(); } - public @Override T getResource(String id, Class clazz) { + @Override + public T getResource(String id, Class clazz) { return catalog.getResource(id, clazz); } - public @Override T getResourceByName( - String ns, String name, Class clazz) { + @Override + public T getResourceByName(String ns, String name, Class clazz) { return catalog.getResourceByName(ns, name, clazz); } - public @Override T getResourceByName( + @Override + public T getResourceByName( NamespaceInfo ns, String name, Class clazz) { return catalog.getResourceByName(ns, name, clazz); } - public @Override T getResourceByName(Name name, Class clazz) { + @Override + public T getResourceByName(Name name, Class clazz) { return catalog.getResourceByName(name, clazz); } - public @Override T getResourceByName(String name, Class clazz) { + @Override + public T getResourceByName(String name, Class clazz) { return catalog.getResourceByName(name, clazz); } - public @Override void add(ResourceInfo resource) { + @Override + public void add(ResourceInfo resource) { catalog.add(resource); } - public @Override ValidationResult validate(ResourceInfo resource, boolean isNew) { + @Override + public ValidationResult validate(ResourceInfo resource, boolean isNew) { return catalog.validate(resource, isNew); } - public @Override void remove(ResourceInfo resource) { + @Override + public void remove(ResourceInfo resource) { catalog.remove(resource); } - public @Override void save(ResourceInfo resource) { + @Override + public void save(ResourceInfo resource) { catalog.save(resource); } - public @Override T detach(T resource) { + @Override + public T detach(T resource) { return catalog.detach(resource); } - public @Override T detach(T store) { + @Override + public T detach(T store) { return catalog.detach(store); } - public @Override List getResources(Class clazz) { + @Override + public List getResources(Class clazz) { return catalog.getResources(clazz); } - public @Override List getResourcesByNamespace( + @Override + public List getResourcesByNamespace( NamespaceInfo namespace, Class clazz) { return catalog.getResourcesByNamespace(namespace, clazz); } - public @Override List getResourcesByNamespace( + @Override + public List getResourcesByNamespace( String namespace, Class clazz) { return catalog.getResourcesByNamespace(namespace, clazz); } - public @Override T getResourceByStore( + @Override + public T getResourceByStore( StoreInfo store, String name, Class clazz) { return catalog.getResourceByStore(store, name, clazz); } - public @Override List getResourcesByStore( - StoreInfo store, Class clazz) { + @Override + public List getResourcesByStore(StoreInfo store, Class clazz) { return catalog.getResourcesByStore(store, clazz); } - public @Override FeatureTypeInfo getFeatureType(String id) { + @Override + public FeatureTypeInfo getFeatureType(String id) { return catalog.getFeatureType(id); } - public @Override FeatureTypeInfo getFeatureTypeByName(String ns, String name) { + @Override + public FeatureTypeInfo getFeatureTypeByName(String ns, String name) { return catalog.getFeatureTypeByName(ns, name); } - public @Override FeatureTypeInfo getFeatureTypeByName(NamespaceInfo ns, String name) { + @Override + public FeatureTypeInfo getFeatureTypeByName(NamespaceInfo ns, String name) { return catalog.getFeatureTypeByName(ns, name); } - public @Override FeatureTypeInfo getFeatureTypeByName(Name name) { + @Override + public FeatureTypeInfo getFeatureTypeByName(Name name) { return catalog.getFeatureTypeByName(name); } - public @Override FeatureTypeInfo getFeatureTypeByName(String name) { + @Override + public FeatureTypeInfo getFeatureTypeByName(String name) { return catalog.getFeatureTypeByName(name); } - public @Override List getFeatureTypes() { + @Override + public List getFeatureTypes() { return catalog.getFeatureTypes(); } - public @Override List getFeatureTypesByNamespace(NamespaceInfo namespace) { + @Override + public List getFeatureTypesByNamespace(NamespaceInfo namespace) { return catalog.getFeatureTypesByNamespace(namespace); } - public @Override FeatureTypeInfo getFeatureTypeByDataStore( - DataStoreInfo dataStore, String name) { + @Override + public FeatureTypeInfo getFeatureTypeByDataStore(DataStoreInfo dataStore, String name) { return catalog.getFeatureTypeByDataStore(dataStore, name); } - public @Override List getFeatureTypesByDataStore(DataStoreInfo store) { + @Override + public List getFeatureTypesByDataStore(DataStoreInfo store) { return catalog.getFeatureTypesByDataStore(store); } - public @Override CoverageInfo getCoverage(String id) { + @Override + public CoverageInfo getCoverage(String id) { return catalog.getCoverage(id); } - public @Override CoverageInfo getCoverageByName(String ns, String name) { + @Override + public CoverageInfo getCoverageByName(String ns, String name) { return catalog.getCoverageByName(ns, name); } - public @Override CoverageInfo getCoverageByName(NamespaceInfo ns, String name) { + @Override + public CoverageInfo getCoverageByName(NamespaceInfo ns, String name) { return catalog.getCoverageByName(ns, name); } - public @Override CoverageInfo getCoverageByName(Name name) { + @Override + public CoverageInfo getCoverageByName(Name name) { return catalog.getCoverageByName(name); } - public @Override CoverageInfo getCoverageByName(String name) { + @Override + public CoverageInfo getCoverageByName(String name) { return catalog.getCoverageByName(name); } - public @Override List getCoverages() { + @Override + public List getCoverages() { return catalog.getCoverages(); } - public @Override List getCoveragesByNamespace(NamespaceInfo namespace) { + @Override + public List getCoveragesByNamespace(NamespaceInfo namespace) { return catalog.getCoveragesByNamespace(namespace); } - public @Override CoverageInfo getCoverageByCoverageStore( - CoverageStoreInfo coverageStore, String name) { + @Override + public CoverageInfo getCoverageByCoverageStore(CoverageStoreInfo coverageStore, String name) { return catalog.getCoverageByCoverageStore(coverageStore, name); } - public @Override List getCoveragesByCoverageStore(CoverageStoreInfo store) { + @Override + public List getCoveragesByCoverageStore(CoverageStoreInfo store) { return catalog.getCoveragesByCoverageStore(store); } - public @Override void add(LayerInfo layer) { + @Override + public void add(LayerInfo layer) { catalog.add(layer); } - public @Override ValidationResult validate(LayerInfo layer, boolean isNew) { + @Override + public ValidationResult validate(LayerInfo layer, boolean isNew) { return catalog.validate(layer, isNew); } - public @Override void remove(LayerInfo layer) { + @Override + public void remove(LayerInfo layer) { catalog.remove(layer); } - public @Override void save(LayerInfo layer) { + @Override + public void save(LayerInfo layer) { catalog.save(layer); } - public @Override LayerInfo detach(LayerInfo layer) { + @Override + public LayerInfo detach(LayerInfo layer) { return catalog.detach(layer); } - public @Override List getCoveragesByStore(CoverageStoreInfo store) { + @Override + public List getCoveragesByStore(CoverageStoreInfo store) { return catalog.getCoveragesByStore(store); } - public @Override LayerInfo getLayer(String id) { + @Override + public LayerInfo getLayer(String id) { return catalog.getLayer(id); } - public @Override LayerInfo getLayerByName(String name) { + @Override + public LayerInfo getLayerByName(String name) { return catalog.getLayerByName(name); } - public @Override LayerInfo getLayerByName(Name name) { + @Override + public LayerInfo getLayerByName(Name name) { return catalog.getLayerByName(name); } - public @Override List getLayers() { + @Override + public List getLayers() { return catalog.getLayers(); } - public @Override List getLayers(ResourceInfo resource) { + @Override + public List getLayers(ResourceInfo resource) { return catalog.getLayers(resource); } - public @Override List getLayers(StyleInfo style) { + @Override + public List getLayers(StyleInfo style) { return catalog.getLayers(style); } - public @Override void add(MapInfo map) { + @Override + public void add(MapInfo map) { catalog.add(map); } - public @Override void remove(MapInfo map) { + @Override + public void remove(MapInfo map) { catalog.remove(map); } - public @Override void save(MapInfo map) { + @Override + public void save(MapInfo map) { catalog.save(map); } - public @Override MapInfo detach(MapInfo map) { + @Override + public MapInfo detach(MapInfo map) { return catalog.detach(map); } - public @Override List getMaps() { + @Override + public List getMaps() { return catalog.getMaps(); } - public @Override MapInfo getMap(String id) { + @Override + public MapInfo getMap(String id) { return catalog.getMap(id); } - public @Override MapInfo getMapByName(String name) { + @Override + public MapInfo getMapByName(String name) { return catalog.getMapByName(name); } - public @Override void add(LayerGroupInfo layerGroup) { + @Override + public void add(LayerGroupInfo layerGroup) { catalog.add(layerGroup); } - public @Override ValidationResult validate(LayerGroupInfo layerGroup, boolean isNew) { + @Override + public ValidationResult validate(LayerGroupInfo layerGroup, boolean isNew) { return catalog.validate(layerGroup, isNew); } - public @Override void remove(LayerGroupInfo layerGroup) { + @Override + public void remove(LayerGroupInfo layerGroup) { catalog.remove(layerGroup); } - public @Override void save(LayerGroupInfo layerGroup) { + @Override + public void save(LayerGroupInfo layerGroup) { catalog.save(layerGroup); } - public @Override LayerGroupInfo detach(LayerGroupInfo layerGroup) { + @Override + public LayerGroupInfo detach(LayerGroupInfo layerGroup) { return catalog.detach(layerGroup); } - public @Override List getLayerGroups() { + @Override + public List getLayerGroups() { return catalog.getLayerGroups(); } - public @Override List getLayerGroupsByWorkspace(String workspaceName) { + @Override + public List getLayerGroupsByWorkspace(String workspaceName) { return catalog.getLayerGroupsByWorkspace(workspaceName); } - public @Override List getLayerGroupsByWorkspace(WorkspaceInfo workspace) { + @Override + public List getLayerGroupsByWorkspace(WorkspaceInfo workspace) { return catalog.getLayerGroupsByWorkspace(workspace); } - public @Override LayerGroupInfo getLayerGroup(String id) { + @Override + public LayerGroupInfo getLayerGroup(String id) { return catalog.getLayerGroup(id); } - public @Override LayerGroupInfo getLayerGroupByName(String name) { + @Override + public LayerGroupInfo getLayerGroupByName(String name) { return catalog.getLayerGroupByName(name); } - public @Override LayerGroupInfo getLayerGroupByName(String workspaceName, String name) { + @Override + public LayerGroupInfo getLayerGroupByName(String workspaceName, String name) { return catalog.getLayerGroupByName(workspaceName, name); } - public @Override LayerGroupInfo getLayerGroupByName(WorkspaceInfo workspace, String name) { + @Override + public LayerGroupInfo getLayerGroupByName(WorkspaceInfo workspace, String name) { return catalog.getLayerGroupByName(workspace, name); } - public @Override void add(StyleInfo style) { + @Override + public void add(StyleInfo style) { catalog.add(style); } - public @Override ValidationResult validate(StyleInfo style, boolean isNew) { + @Override + public ValidationResult validate(StyleInfo style, boolean isNew) { return catalog.validate(style, isNew); } - public @Override void remove(StyleInfo style) { + @Override + public void remove(StyleInfo style) { catalog.remove(style); } - public @Override void save(StyleInfo style) { + @Override + public void save(StyleInfo style) { catalog.save(style); } - public @Override StyleInfo detach(StyleInfo style) { + @Override + public StyleInfo detach(StyleInfo style) { return catalog.detach(style); } - public @Override StyleInfo getStyle(String id) { + @Override + public StyleInfo getStyle(String id) { return catalog.getStyle(id); } - public @Override StyleInfo getStyleByName(String workspaceName, String name) { + @Override + public StyleInfo getStyleByName(String workspaceName, String name) { return catalog.getStyleByName(workspaceName, name); } - public @Override StyleInfo getStyleByName(WorkspaceInfo workspace, String name) { + @Override + public StyleInfo getStyleByName(WorkspaceInfo workspace, String name) { return catalog.getStyleByName(workspace, name); } - public @Override StyleInfo getStyleByName(String name) { + @Override + public StyleInfo getStyleByName(String name) { return catalog.getStyleByName(name); } - public @Override List getStyles() { + @Override + public List getStyles() { return catalog.getStyles(); } - public @Override List getStylesByWorkspace(String workspaceName) { + @Override + public List getStylesByWorkspace(String workspaceName) { return catalog.getStylesByWorkspace(workspaceName); } - public @Override List getStylesByWorkspace(WorkspaceInfo workspace) { + @Override + public List getStylesByWorkspace(WorkspaceInfo workspace) { return catalog.getStylesByWorkspace(workspace); } - public @Override void add(NamespaceInfo namespace) { + @Override + public void add(NamespaceInfo namespace) { catalog.add(namespace); } - public @Override ValidationResult validate(NamespaceInfo namespace, boolean isNew) { + @Override + public ValidationResult validate(NamespaceInfo namespace, boolean isNew) { return catalog.validate(namespace, isNew); } - public @Override void remove(NamespaceInfo namespace) { + @Override + public void remove(NamespaceInfo namespace) { catalog.remove(namespace); } - public @Override void save(NamespaceInfo namespace) { + @Override + public void save(NamespaceInfo namespace) { catalog.save(namespace); } - public @Override NamespaceInfo detach(NamespaceInfo namespace) { + @Override + public NamespaceInfo detach(NamespaceInfo namespace) { return catalog.detach(namespace); } - public @Override NamespaceInfo getNamespace(String id) { + @Override + public NamespaceInfo getNamespace(String id) { return catalog.getNamespace(id); } - public @Override NamespaceInfo getNamespaceByPrefix(String prefix) { + @Override + public NamespaceInfo getNamespaceByPrefix(String prefix) { return catalog.getNamespaceByPrefix(prefix); } - public @Override NamespaceInfo getNamespaceByURI(String uri) { + @Override + public NamespaceInfo getNamespaceByURI(String uri) { return catalog.getNamespaceByURI(uri); } - public @Override NamespaceInfo getDefaultNamespace() { + @Override + public NamespaceInfo getDefaultNamespace() { return catalog.getDefaultNamespace(); } - public @Override void setDefaultNamespace(NamespaceInfo defaultNamespace) { + @Override + public void setDefaultNamespace(NamespaceInfo defaultNamespace) { catalog.setDefaultNamespace(defaultNamespace); } - public @Override List getNamespaces() { + @Override + public List getNamespaces() { return catalog.getNamespaces(); } - public @Override void add(WorkspaceInfo workspace) { + @Override + public void add(WorkspaceInfo workspace) { catalog.add(workspace); } - public @Override ValidationResult validate(WorkspaceInfo workspace, boolean isNew) { + @Override + public ValidationResult validate(WorkspaceInfo workspace, boolean isNew) { return catalog.validate(workspace, isNew); } - public @Override void remove(WorkspaceInfo workspace) { + @Override + public void remove(WorkspaceInfo workspace) { catalog.remove(workspace); } - public @Override void save(WorkspaceInfo workspace) { + @Override + public void save(WorkspaceInfo workspace) { catalog.save(workspace); } - public @Override WorkspaceInfo detach(WorkspaceInfo workspace) { + @Override + public WorkspaceInfo detach(WorkspaceInfo workspace) { return catalog.detach(workspace); } - public @Override WorkspaceInfo getDefaultWorkspace() { + @Override + public WorkspaceInfo getDefaultWorkspace() { return catalog.getDefaultWorkspace(); } - public @Override void setDefaultWorkspace(WorkspaceInfo workspace) { + @Override + public void setDefaultWorkspace(WorkspaceInfo workspace) { catalog.setDefaultWorkspace(workspace); } - public @Override List getWorkspaces() { + @Override + public List getWorkspaces() { return catalog.getWorkspaces(); } - public @Override WorkspaceInfo getWorkspace(String id) { + @Override + public WorkspaceInfo getWorkspace(String id) { return catalog.getWorkspace(id); } - public @Override WorkspaceInfo getWorkspaceByName(String name) { + @Override + public WorkspaceInfo getWorkspaceByName(String name) { return catalog.getWorkspaceByName(name); } - public @Override Collection getListeners() { + @Override + public Collection getListeners() { return catalog.getListeners(); } - public @Override void addListener(CatalogListener listener) { + @Override + public void addListener(CatalogListener listener) { catalog.addListener(listener); } - public @Override void removeListener(CatalogListener listener) { + @Override + public void removeListener(CatalogListener listener) { catalog.removeListener(listener); } - public @Override void fireAdded(CatalogInfo object) { + @Override + public void fireAdded(CatalogInfo object) { catalog.fireAdded(object); } - public @Override void fireModified( + @Override + public void fireModified( CatalogInfo object, List propertyNames, List oldValues, @@ -653,7 +790,8 @@ public Catalog getSubject() { catalog.fireModified(object, propertyNames, oldValues, newValues); } - public @Override void firePostModified( + @Override + public void firePostModified( CatalogInfo object, List propertyNames, List oldValues, @@ -661,53 +799,65 @@ public Catalog getSubject() { catalog.firePostModified(object, propertyNames, oldValues, newValues); } - public @Override void fireRemoved(CatalogInfo object) { + @Override + public void fireRemoved(CatalogInfo object) { catalog.fireRemoved(object); } - public @Override ResourcePool getResourcePool() { + @Override + public ResourcePool getResourcePool() { return catalog.getResourcePool(); } - public @Override void setResourcePool(ResourcePool resourcePool) { + @Override + public void setResourcePool(ResourcePool resourcePool) { catalog.setResourcePool(resourcePool); } - public @Override GeoServerResourceLoader getResourceLoader() { + @Override + public GeoServerResourceLoader getResourceLoader() { return catalog.getResourceLoader(); } - public @Override void setResourceLoader(GeoServerResourceLoader resourceLoader) { + @Override + public void setResourceLoader(GeoServerResourceLoader resourceLoader) { catalog.setResourceLoader(resourceLoader); } - public @Override void dispose() { + @Override + public void dispose() { catalog.dispose(); } - public @Override int count(Class of, Filter filter) { + @Override + public int count(Class of, Filter filter) { return catalog.count(of, filter); } - public @Override T get(Class type, Filter filter) + @Override + public T get(Class type, Filter filter) throws IllegalArgumentException { return catalog.get(type, filter); } - public @Override CloseableIterator list(Class of, Filter filter) { + @Override + public CloseableIterator list(Class of, Filter filter) { return catalog.list(of, filter); } - public @Override CloseableIterator list( + @Override + public CloseableIterator list( Class of, Filter filter, Integer offset, Integer count, SortBy sortBy) { return catalog.list(of, filter, offset, count, sortBy); } - public @Override void removeListeners(Class listenerClass) { + @Override + public void removeListeners(Class listenerClass) { catalog.removeListeners(listenerClass); } - public @Override CatalogCapabilities getCatalogCapabilities() { + @Override + public CatalogCapabilities getCatalogCapabilities() { return catalog.getCatalogCapabilities(); } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingCatalogFacade.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingCatalogFacade.java index 1fb6fe7ee..7a30ae64f 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingCatalogFacade.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingCatalogFacade.java @@ -50,337 +50,418 @@ public CatalogFacade getSubject() { return facade; } - public @Override Catalog getCatalog() { + @Override + public Catalog getCatalog() { return facade.getCatalog(); } - public @Override void setCatalog(Catalog catalog) { + @Override + public void setCatalog(Catalog catalog) { facade.setCatalog(catalog); } - public @Override StoreInfo add(StoreInfo store) { + @Override + public StoreInfo add(StoreInfo store) { return facade.add(store); } - public @Override void remove(StoreInfo store) { + @Override + public void remove(StoreInfo store) { facade.remove(store); } - public @Override void save(StoreInfo store) { + @Override + public void save(StoreInfo store) { facade.save(store); } - public @Override T detach(T store) { + @Override + public T detach(T store) { return facade.detach(store); } - public @Override T getStore(String id, Class clazz) { + @Override + public T getStore(String id, Class clazz) { return facade.getStore(id, clazz); } - public @Override T getStoreByName( + @Override + public T getStoreByName( WorkspaceInfo workspace, String name, Class clazz) { return facade.getStoreByName(workspace, name, clazz); } - public @Override List getStoresByWorkspace( + @Override + public List getStoresByWorkspace( WorkspaceInfo workspace, Class clazz) { return facade.getStoresByWorkspace(workspace, clazz); } - public @Override List getStores(Class clazz) { + @Override + public List getStores(Class clazz) { return facade.getStores(clazz); } - public @Override DataStoreInfo getDefaultDataStore(WorkspaceInfo workspace) { + @Override + public DataStoreInfo getDefaultDataStore(WorkspaceInfo workspace) { return facade.getDefaultDataStore(workspace); } - public @Override void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo store) { + @Override + public void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo store) { facade.setDefaultDataStore(workspace, store); } - public @Override ResourceInfo add(ResourceInfo resource) { + @Override + public ResourceInfo add(ResourceInfo resource) { return facade.add(resource); } - public @Override void remove(ResourceInfo resource) { + @Override + public void remove(ResourceInfo resource) { facade.remove(resource); } - public @Override void save(ResourceInfo resource) { + @Override + public void save(ResourceInfo resource) { facade.save(resource); } - public @Override T detach(T resource) { + @Override + public T detach(T resource) { return facade.detach(resource); } - public @Override T getResource(String id, Class clazz) { + @Override + public T getResource(String id, Class clazz) { return facade.getResource(id, clazz); } - public @Override T getResourceByName( + @Override + public T getResourceByName( NamespaceInfo namespace, String name, Class clazz) { return facade.getResourceByName(namespace, name, clazz); } - public @Override List getResources(Class clazz) { + @Override + public List getResources(Class clazz) { return facade.getResources(clazz); } - public @Override List getResourcesByNamespace( + @Override + public List getResourcesByNamespace( NamespaceInfo namespace, Class clazz) { return facade.getResourcesByNamespace(namespace, clazz); } - public @Override T getResourceByStore( + @Override + public T getResourceByStore( StoreInfo store, String name, Class clazz) { return facade.getResourceByStore(store, name, clazz); } - public @Override List getResourcesByStore( - StoreInfo store, Class clazz) { + @Override + public List getResourcesByStore(StoreInfo store, Class clazz) { return facade.getResourcesByStore(store, clazz); } - public @Override LayerInfo add(LayerInfo layer) { + @Override + public LayerInfo add(LayerInfo layer) { return facade.add(layer); } - public @Override void remove(LayerInfo layer) { + @Override + public void remove(LayerInfo layer) { facade.remove(layer); } - public @Override void save(LayerInfo layer) { + @Override + public void save(LayerInfo layer) { facade.save(layer); } - public @Override LayerInfo detach(LayerInfo layer) { + @Override + public LayerInfo detach(LayerInfo layer) { return facade.detach(layer); } - public @Override LayerInfo getLayer(String id) { + @Override + public LayerInfo getLayer(String id) { return facade.getLayer(id); } - public @Override LayerInfo getLayerByName(String name) { + @Override + public LayerInfo getLayerByName(String name) { return facade.getLayerByName(name); } - public @Override List getLayers(ResourceInfo resource) { + @Override + public List getLayers(ResourceInfo resource) { return facade.getLayers(resource); } - public @Override List getLayers(StyleInfo style) { + @Override + public List getLayers(StyleInfo style) { return facade.getLayers(style); } - public @Override List getLayers() { + @Override + public List getLayers() { return facade.getLayers(); } - public @Override MapInfo add(MapInfo map) { + @Override + public MapInfo add(MapInfo map) { return facade.add(map); } - public @Override void remove(MapInfo map) { + @Override + public void remove(MapInfo map) { facade.remove(map); } - public @Override void save(MapInfo map) { + @Override + public void save(MapInfo map) { facade.save(map); } - public @Override MapInfo detach(MapInfo map) { + @Override + public MapInfo detach(MapInfo map) { return facade.detach(map); } - public @Override MapInfo getMap(String id) { + @Override + public MapInfo getMap(String id) { return facade.getMap(id); } - public @Override MapInfo getMapByName(String name) { + @Override + public MapInfo getMapByName(String name) { return facade.getMapByName(name); } - public @Override List getMaps() { + @Override + public List getMaps() { return facade.getMaps(); } - public @Override LayerGroupInfo add(LayerGroupInfo layerGroup) { + @Override + public LayerGroupInfo add(LayerGroupInfo layerGroup) { return facade.add(layerGroup); } - public @Override void remove(LayerGroupInfo layerGroup) { + @Override + public void remove(LayerGroupInfo layerGroup) { facade.remove(layerGroup); } - public @Override void save(LayerGroupInfo layerGroup) { + @Override + public void save(LayerGroupInfo layerGroup) { facade.save(layerGroup); } - public @Override LayerGroupInfo detach(LayerGroupInfo layerGroup) { + @Override + public LayerGroupInfo detach(LayerGroupInfo layerGroup) { return facade.detach(layerGroup); } - public @Override LayerGroupInfo getLayerGroup(String id) { + @Override + public LayerGroupInfo getLayerGroup(String id) { return facade.getLayerGroup(id); } - public @Override LayerGroupInfo getLayerGroupByName(String name) { + @Override + public LayerGroupInfo getLayerGroupByName(String name) { return facade.getLayerGroupByName(name); } - public @Override LayerGroupInfo getLayerGroupByName(WorkspaceInfo workspace, String name) { + @Override + public LayerGroupInfo getLayerGroupByName(WorkspaceInfo workspace, String name) { return facade.getLayerGroupByName(workspace, name); } - public @Override List getLayerGroups() { + @Override + public List getLayerGroups() { return facade.getLayerGroups(); } - public @Override List getLayerGroupsByWorkspace(WorkspaceInfo workspace) { + @Override + public List getLayerGroupsByWorkspace(WorkspaceInfo workspace) { return facade.getLayerGroupsByWorkspace(workspace); } - public @Override NamespaceInfo add(NamespaceInfo namespace) { + @Override + public NamespaceInfo add(NamespaceInfo namespace) { return facade.add(namespace); } - public @Override void remove(NamespaceInfo namespace) { + @Override + public void remove(NamespaceInfo namespace) { facade.remove(namespace); } - public @Override void save(NamespaceInfo namespace) { + @Override + public void save(NamespaceInfo namespace) { facade.save(namespace); } - public @Override NamespaceInfo detach(NamespaceInfo namespace) { + @Override + public NamespaceInfo detach(NamespaceInfo namespace) { return facade.detach(namespace); } - public @Override NamespaceInfo getDefaultNamespace() { + @Override + public NamespaceInfo getDefaultNamespace() { return facade.getDefaultNamespace(); } - public @Override void setDefaultNamespace(NamespaceInfo defaultNamespace) { + @Override + public void setDefaultNamespace(NamespaceInfo defaultNamespace) { facade.setDefaultNamespace(defaultNamespace); } - public @Override NamespaceInfo getNamespace(String id) { + @Override + public NamespaceInfo getNamespace(String id) { return facade.getNamespace(id); } - public @Override NamespaceInfo getNamespaceByPrefix(String prefix) { + @Override + public NamespaceInfo getNamespaceByPrefix(String prefix) { return facade.getNamespaceByPrefix(prefix); } - public @Override NamespaceInfo getNamespaceByURI(String uri) { + @Override + public NamespaceInfo getNamespaceByURI(String uri) { return facade.getNamespaceByURI(uri); } - public @Override List getNamespacesByURI(String uri) { + @Override + public List getNamespacesByURI(String uri) { return facade.getNamespacesByURI(uri); } - public @Override List getNamespaces() { + @Override + public List getNamespaces() { return facade.getNamespaces(); } - public @Override WorkspaceInfo add(WorkspaceInfo workspace) { + @Override + public WorkspaceInfo add(WorkspaceInfo workspace) { return facade.add(workspace); } - public @Override void remove(WorkspaceInfo workspace) { + @Override + public void remove(WorkspaceInfo workspace) { facade.remove(workspace); } - public @Override void save(WorkspaceInfo workspace) { + @Override + public void save(WorkspaceInfo workspace) { facade.save(workspace); } - public @Override WorkspaceInfo detach(WorkspaceInfo workspace) { + @Override + public WorkspaceInfo detach(WorkspaceInfo workspace) { return facade.detach(workspace); } - public @Override WorkspaceInfo getDefaultWorkspace() { + @Override + public WorkspaceInfo getDefaultWorkspace() { return facade.getDefaultWorkspace(); } - public @Override void setDefaultWorkspace(WorkspaceInfo workspace) { + @Override + public void setDefaultWorkspace(WorkspaceInfo workspace) { facade.setDefaultWorkspace(workspace); } - public @Override WorkspaceInfo getWorkspace(String id) { + @Override + public WorkspaceInfo getWorkspace(String id) { return facade.getWorkspace(id); } - public @Override WorkspaceInfo getWorkspaceByName(String name) { + @Override + public WorkspaceInfo getWorkspaceByName(String name) { return facade.getWorkspaceByName(name); } - public @Override List getWorkspaces() { + @Override + public List getWorkspaces() { return facade.getWorkspaces(); } - public @Override StyleInfo add(StyleInfo style) { + @Override + public StyleInfo add(StyleInfo style) { return facade.add(style); } - public @Override void remove(StyleInfo style) { + @Override + public void remove(StyleInfo style) { facade.remove(style); } - public @Override void save(StyleInfo style) { + @Override + public void save(StyleInfo style) { facade.save(style); } - public @Override StyleInfo detach(StyleInfo style) { + @Override + public StyleInfo detach(StyleInfo style) { return facade.detach(style); } - public @Override StyleInfo getStyle(String id) { + @Override + public StyleInfo getStyle(String id) { return facade.getStyle(id); } - public @Override StyleInfo getStyleByName(String name) { + @Override + public StyleInfo getStyleByName(String name) { return facade.getStyleByName(name); } - public @Override StyleInfo getStyleByName(WorkspaceInfo workspace, String name) { + @Override + public StyleInfo getStyleByName(WorkspaceInfo workspace, String name) { return facade.getStyleByName(workspace, name); } - public @Override List getStyles() { + @Override + public List getStyles() { return facade.getStyles(); } - public @Override List getStylesByWorkspace(WorkspaceInfo workspace) { + @Override + public List getStylesByWorkspace(WorkspaceInfo workspace) { return facade.getStylesByWorkspace(workspace); } - public @Override void dispose() { + @Override + public void dispose() { facade.dispose(); } - public @Override void resolve() { + @Override + public void resolve() { facade.resolve(); } - public @Override void syncTo(CatalogFacade other) { + @Override + public void syncTo(CatalogFacade other) { facade.syncTo(other); } - public @Override int count(Class of, Filter filter) { + @Override + public int count(Class of, Filter filter) { return facade.count(of, filter); } - public @Override boolean canSort(Class type, String propertyName) { + @Override + public boolean canSort(Class type, String propertyName) { return facade.canSort(type, propertyName); } - public @Override CloseableIterator list( + @Override + public CloseableIterator list( Class of, Filter filter, @Nullable Integer offset, @@ -389,7 +470,8 @@ public CatalogFacade getSubject() { return facade.list(of, filter, offset, count, sortOrder); } - public @Override CatalogCapabilities getCatalogCapabilities() { + @Override + public CatalogCapabilities getCatalogCapabilities() { return facade.getCatalogCapabilities(); } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingCatalogRepository.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingCatalogRepository.java index 894cabbd8..18daedd1c 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingCatalogRepository.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingCatalogRepository.java @@ -21,56 +21,67 @@ public abstract class ForwardingCatalogRepository< protected S subject; - public ForwardingCatalogRepository(S subject) { + protected ForwardingCatalogRepository(S subject) { this.subject = subject; } - public @Override Class getContentType() { + @Override + public Class getContentType() { return subject.getContentType(); } - public @Override boolean canSortBy(@NonNull String propertyName) { + @Override + public boolean canSortBy(@NonNull String propertyName) { return subject.canSortBy(propertyName); } - public @Override void add(I value) { + @Override + public void add(I value) { subject.add(value); } - public @Override void remove(I value) { + @Override + public void remove(I value) { subject.remove(value); } - public @Override T update(T value, Patch patch) { + @Override + public T update(T value, Patch patch) { return subject.update(value, patch); } - public @Override void dispose() { + @Override + public void dispose() { subject.dispose(); } - public @Override Stream findAll() { + @Override + public Stream findAll() { return subject.findAll(); } - public @Override Stream findAll(Query query) { + @Override + public Stream findAll(Query query) { return subject.findAll(query); } - public @Override long count(final Class of, final Filter filter) { + @Override + public long count(final Class of, final Filter filter) { return subject.count(of, filter); } - public @Override Optional findById(String id, Class clazz) { + @Override + public Optional findById(String id, Class clazz) { return subject.findById(id, clazz); } - public @Override Optional findFirstByName( - @NonNull String name, Class clazz) { + @Override + public Optional findFirstByName(@NonNull String name, Class clazz) { return subject.findFirstByName(name, clazz); } - public @Override void syncTo(CatalogInfoRepository target) { + @Override + public void syncTo(CatalogInfoRepository target) { subject.syncTo(target); } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingExtendedCatalogFacade.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingExtendedCatalogFacade.java index b1dea93eb..639139b7b 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingExtendedCatalogFacade.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingExtendedCatalogFacade.java @@ -20,11 +20,13 @@ public ForwardingExtendedCatalogFacade(ExtendedCatalogFacade facade) { super(facade); } - public @Override I update(final I info, final Patch patch) { + @Override + public I update(final I info, final Patch patch) { return facade().update(info, patch); } - public @Override Stream query(Query query) { + @Override + public Stream query(Query query) { return facade().query(query); } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingLayerGroupRepository.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingLayerGroupRepository.java index 2a5a99487..89b87f35d 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingLayerGroupRepository.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingLayerGroupRepository.java @@ -21,20 +21,23 @@ public ForwardingLayerGroupRepository(LayerGroupRepository subject) { super(subject); } - public @Override Stream findAllByWorkspaceIsNull() { + @Override + public Stream findAllByWorkspaceIsNull() { return subject.findAllByWorkspaceIsNull(); } - public @Override Stream findAllByWorkspace(WorkspaceInfo workspace) { + @Override + public Stream findAllByWorkspace(WorkspaceInfo workspace) { return subject.findAllByWorkspace(workspace); } - public @Override Optional findByNameAndWorkspaceIsNull(@NonNull String name) { + @Override + public Optional findByNameAndWorkspaceIsNull(@NonNull String name) { return subject.findByNameAndWorkspaceIsNull(name); } - public @Override Optional findByNameAndWorkspace( - String name, WorkspaceInfo workspace) { + @Override + public Optional findByNameAndWorkspace(String name, WorkspaceInfo workspace) { return subject.findByNameAndWorkspace(name, workspace); } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingLayerRepository.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingLayerRepository.java index 10201508c..b243cd52e 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingLayerRepository.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingLayerRepository.java @@ -19,15 +19,18 @@ public ForwardingLayerRepository(LayerRepository subject) { super(subject); } - public @Override Optional findOneByName(String name) { + @Override + public Optional findOneByName(String name) { return subject.findOneByName(name); } - public @Override Stream findAllByDefaultStyleOrStyles(StyleInfo style) { + @Override + public Stream findAllByDefaultStyleOrStyles(StyleInfo style) { return subject.findAllByDefaultStyleOrStyles(style); } - public @Override Stream findAllByResource(ResourceInfo resource) { + @Override + public Stream findAllByResource(ResourceInfo resource) { return subject.findAllByResource(resource); } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingNamespaceRepository.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingNamespaceRepository.java index 5ccd39fe0..b6f4a5287 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingNamespaceRepository.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingNamespaceRepository.java @@ -18,23 +18,28 @@ public ForwardingNamespaceRepository(NamespaceRepository subject) { super(subject); } - public @Override void setDefaultNamespace(NamespaceInfo namespace) { + @Override + public void setDefaultNamespace(NamespaceInfo namespace) { subject.setDefaultNamespace(namespace); } - public @Override Optional getDefaultNamespace() { + @Override + public Optional getDefaultNamespace() { return subject.getDefaultNamespace(); } - public @Override Optional findOneByURI(String uri) { + @Override + public Optional findOneByURI(String uri) { return subject.findOneByURI(uri); } - public @Override Stream findAllByURI(String uri) { + @Override + public Stream findAllByURI(String uri) { return subject.findAllByURI(uri); } - public @Override void unsetDefaultNamespace() { + @Override + public void unsetDefaultNamespace() { subject.unsetDefaultNamespace(); } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingRepositoryCatalogFacade.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingRepositoryCatalogFacade.java index d6af44bdc..da1adb84f 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingRepositoryCatalogFacade.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingRepositoryCatalogFacade.java @@ -31,81 +31,98 @@ public ForwardingRepositoryCatalogFacade(RepositoryCatalogFacade facade) { super(facade); } - public @Override void setNamespaceRepository(NamespaceRepository namespaces) { + @Override + public void setNamespaceRepository(NamespaceRepository namespaces) { facade().setNamespaceRepository(namespaces); } - public @Override void setWorkspaceRepository(WorkspaceRepository workspaces) { + @Override + public void setWorkspaceRepository(WorkspaceRepository workspaces) { facade().setWorkspaceRepository(workspaces); } - public @Override void setStoreRepository(StoreRepository stores) { + @Override + public void setStoreRepository(StoreRepository stores) { facade().setStoreRepository(stores); } - public @Override void setResourceRepository(ResourceRepository resources) { + @Override + public void setResourceRepository(ResourceRepository resources) { facade().setResourceRepository(resources); } - public @Override void setLayerRepository(LayerRepository layers) { + @Override + public void setLayerRepository(LayerRepository layers) { facade().setLayerRepository(layers); } - public @Override void setLayerGroupRepository(LayerGroupRepository layerGroups) { + @Override + public void setLayerGroupRepository(LayerGroupRepository layerGroups) { facade().setLayerGroupRepository(layerGroups); } - public @Override void setStyleRepository(StyleRepository styles) { + @Override + public void setStyleRepository(StyleRepository styles) { facade().setStyleRepository(styles); } - public @Override void setMapRepository(MapRepository maps) { + @Override + public void setMapRepository(MapRepository maps) { facade().setMapRepository(maps); } - public @Override NamespaceRepository getNamespaceRepository() { + @Override + public NamespaceRepository getNamespaceRepository() { return facade().getNamespaceRepository(); } - public @Override WorkspaceRepository getWorkspaceRepository() { + @Override + public WorkspaceRepository getWorkspaceRepository() { return facade().getWorkspaceRepository(); } - public @Override StoreRepository getStoreRepository() { + @Override + public StoreRepository getStoreRepository() { return facade().getStoreRepository(); } - public @Override ResourceRepository getResourceRepository() { + @Override + public ResourceRepository getResourceRepository() { return facade().getResourceRepository(); } - public @Override LayerRepository getLayerRepository() { + @Override + public LayerRepository getLayerRepository() { return facade().getLayerRepository(); } - public @Override LayerGroupRepository getLayerGroupRepository() { + @Override + public LayerGroupRepository getLayerGroupRepository() { return facade().getLayerGroupRepository(); } - public @Override StyleRepository getStyleRepository() { + @Override + public StyleRepository getStyleRepository() { return facade().getStyleRepository(); } - public @Override MapRepository getMapRepository() { + @Override + public MapRepository getMapRepository() { return facade().getMapRepository(); } + @Override protected RepositoryCatalogFacade facade() { return (RepositoryCatalogFacade) facade; } - public @Override > R repository( - Class of) { + @Override + public > R repository(Class of) { return facade().repository(of); } - public @Override > R repositoryFor( - T info) { + @Override + public > R repositoryFor(T info) { return facade().repositoryFor(info); } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingResourceRepository.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingResourceRepository.java index 1e8c2a9cd..3f3970f52 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingResourceRepository.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingResourceRepository.java @@ -22,26 +22,29 @@ public ForwardingResourceRepository(ResourceRepository subject) { super(subject); } - public @Override Stream findAllByType(Class clazz) { + @Override + public Stream findAllByType(Class clazz) { return subject.findAllByType(clazz); } - public @Override Stream findAllByNamespace( - NamespaceInfo ns, Class clazz) { + @Override + public Stream findAllByNamespace(NamespaceInfo ns, Class clazz) { return subject.findAllByNamespace(ns, clazz); } - public @Override Optional findByStoreAndName( + @Override + public Optional findByStoreAndName( StoreInfo store, String name, Class clazz) { return subject.findByStoreAndName(store, name, clazz); } - public @Override Stream findAllByStore( - StoreInfo store, Class clazz) { + @Override + public Stream findAllByStore(StoreInfo store, Class clazz) { return subject.findAllByStore(store, clazz); } - public @Override Optional findByNameAndNamespace( + @Override + public Optional findByNameAndNamespace( @NonNull String name, @NonNull NamespaceInfo namespace, Class clazz) { return subject.findByNameAndNamespace(name, namespace, clazz); } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingStoreRepository.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingStoreRepository.java index 66ee0c985..ca2a6e822 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingStoreRepository.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingStoreRepository.java @@ -21,33 +21,40 @@ public ForwardingStoreRepository(StoreRepository subject) { super(subject); } - public @Override void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo dataStore) { + @Override + public void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo dataStore) { subject.setDefaultDataStore(workspace, dataStore); } - public @Override Optional getDefaultDataStore(WorkspaceInfo workspace) { + @Override + public Optional getDefaultDataStore(WorkspaceInfo workspace) { return subject.getDefaultDataStore(workspace); } - public @Override Stream getDefaultDataStores() { + @Override + public Stream getDefaultDataStores() { return subject.getDefaultDataStores(); } - public @Override Stream findAllByWorkspace( + @Override + public Stream findAllByWorkspace( WorkspaceInfo workspace, Class clazz) { return subject.findAllByWorkspace(workspace, clazz); } - public @Override Stream findAllByType(Class clazz) { + @Override + public Stream findAllByType(Class clazz) { return subject.findAllByType(clazz); } - public @Override Optional findByNameAndWorkspace( + @Override + public Optional findByNameAndWorkspace( String name, WorkspaceInfo workspace, Class clazz) { return subject.findByNameAndWorkspace(name, workspace, clazz); } - public @Override void unsetDefaultDataStore(@NonNull WorkspaceInfo workspace) { + @Override + public void unsetDefaultDataStore(@NonNull WorkspaceInfo workspace) { subject.unsetDefaultDataStore(workspace); } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingStyleRepository.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingStyleRepository.java index 71158662d..508cb76fc 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingStyleRepository.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingStyleRepository.java @@ -18,20 +18,23 @@ public ForwardingStyleRepository(StyleRepository subject) { super(subject); } - public @Override Stream findAllByNullWorkspace() { + @Override + public Stream findAllByNullWorkspace() { return subject.findAllByNullWorkspace(); } - public @Override Stream findAllByWorkspace(WorkspaceInfo ws) { + @Override + public Stream findAllByWorkspace(WorkspaceInfo ws) { return subject.findAllByWorkspace(ws); } - public @Override Optional findByNameAndWordkspaceNull(String name) { + @Override + public Optional findByNameAndWordkspaceNull(String name) { return subject.findByNameAndWordkspaceNull(name); } - public @Override Optional findByNameAndWorkspace( - String name, WorkspaceInfo workspace) { + @Override + public Optional findByNameAndWorkspace(String name, WorkspaceInfo workspace) { return subject.findByNameAndWorkspace(name, workspace); } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingWorkspaceRepository.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingWorkspaceRepository.java index ca7a7cab1..ef55b76f8 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingWorkspaceRepository.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/forwarding/ForwardingWorkspaceRepository.java @@ -17,15 +17,18 @@ public ForwardingWorkspaceRepository(WorkspaceRepository subject) { super(subject); } - public @Override void setDefaultWorkspace(WorkspaceInfo workspace) { + @Override + public void setDefaultWorkspace(WorkspaceInfo workspace) { subject.setDefaultWorkspace(workspace); } - public @Override Optional getDefaultWorkspace() { + @Override + public Optional getDefaultWorkspace() { return subject.getDefaultWorkspace(); } - public @Override void unsetDefaultWorkspace() { + @Override + public void unsetDefaultWorkspace() { subject.unsetDefaultWorkspace(); } } 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 55440b406..3615df398 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 @@ -91,8 +91,8 @@ public ResolvingCatalogFacadeDecorator(ExtendedCatalogFacade facade) { * Function applied to all outgoing {@link CatalogInfo} objects returned by the decorated facade * before leaving this decorator facade */ - public @Override void setOutboundResolver( - Function resolvingFunction) { + @Override + public void setOutboundResolver(Function resolvingFunction) { Objects.requireNonNull(resolvingFunction); this.outboundResolver = resolvingFunction; } @@ -106,7 +106,8 @@ public ResolvingCatalogFacadeDecorator(ExtendedCatalogFacade facade) { * to filter out objects based on some externally defined conditions, returning {@code null} if * an object is to be discarded from the final outcome */ - public @Override Function getOutboundResolver() { + @Override + public Function getOutboundResolver() { return this.outboundResolver; } @@ -114,7 +115,8 @@ public ResolvingCatalogFacadeDecorator(ExtendedCatalogFacade facade) { * Function applied to all incoming {@link CatalogInfo} objects before deferring to the * decorated facade */ - public @Override void setInboundResolver(Function resolvingFunction) { + @Override + public void setInboundResolver(Function resolvingFunction) { Objects.requireNonNull(resolvingFunction); this.inboundResolver = resolvingFunction; } @@ -126,7 +128,8 @@ public ResolvingCatalogFacadeDecorator(ExtendedCatalogFacade facade) { *

Use {@code facade.setInboundResolver(facade.getInboundResolver().andThen(myFunction))} to * add traits to the current resolver */ - public @Override Function getInboundResolver() { + @Override + public Function getInboundResolver() { return this.inboundResolver; } @@ -140,12 +143,14 @@ protected Function inbound() { return (Function) inboundResolver; } - public @Override C resolveOutbound(C info) { + @Override + public C resolveOutbound(C info) { Function outboundResolve = outbound(); return outboundResolve.apply(info); } - public @Override C resolveInbound(C info) { + @Override + public C resolveInbound(C info) { Function inboundResolve = inbound(); return inboundResolve.apply(info); } @@ -154,273 +159,338 @@ protected List resolveOutbound(List info) { return Lists.transform(info, this::resolveOutbound); } - public @Override I update(I info, Patch patch) { + @Override + public I update(I info, Patch patch) { return resolveOutbound(super.update(resolveInbound(info), patch)); } - public @Override StoreInfo add(StoreInfo store) { + @Override + public StoreInfo add(StoreInfo store) { return resolveOutbound(super.add(resolveInbound(store))); } - public @Override T getStore(String id, Class clazz) { + @Override + public T getStore(String id, Class clazz) { return resolveOutbound(super.getStore(id, clazz)); } - public @Override T getStoreByName( + @Override + public T getStoreByName( WorkspaceInfo workspace, String name, Class clazz) { return resolveOutbound(super.getStoreByName(workspace, name, clazz)); } - public @Override List getStoresByWorkspace( + @Override + public List getStoresByWorkspace( WorkspaceInfo workspace, Class clazz) { return resolveOutbound(super.getStoresByWorkspace(workspace, clazz)); } - public @Override List getStores(Class clazz) { + @Override + public List getStores(Class clazz) { return resolveOutbound(super.getStores(clazz)); } - public @Override DataStoreInfo getDefaultDataStore(WorkspaceInfo workspace) { + @Override + public DataStoreInfo getDefaultDataStore(WorkspaceInfo workspace) { return resolveOutbound(super.getDefaultDataStore(workspace)); } - public @Override ResourceInfo add(ResourceInfo resource) { + @Override + public ResourceInfo add(ResourceInfo resource) { return resolveOutbound(super.add(resolveInbound(resource))); } - public @Override T getResource(String id, Class clazz) { + @Override + public T getResource(String id, Class clazz) { return resolveOutbound(super.getResource(id, clazz)); } - public @Override T getResourceByName( + @Override + public T getResourceByName( NamespaceInfo namespace, String name, Class clazz) { return resolveOutbound(super.getResourceByName(namespace, name, clazz)); } - public @Override List getResources(Class clazz) { + @Override + public List getResources(Class clazz) { return resolveOutbound(super.getResources(clazz)); } - public @Override List getResourcesByNamespace( + @Override + public List getResourcesByNamespace( NamespaceInfo namespace, Class clazz) { return resolveOutbound(super.getResourcesByNamespace(namespace, clazz)); } - public @Override T getResourceByStore( + @Override + public T getResourceByStore( StoreInfo store, String name, Class clazz) { return resolveOutbound(super.getResourceByStore(store, name, clazz)); } - public @Override List getResourcesByStore( - StoreInfo store, Class clazz) { + @Override + public List getResourcesByStore(StoreInfo store, Class clazz) { return resolveOutbound(super.getResourcesByStore(store, clazz)); } - public @Override LayerInfo add(LayerInfo layer) { + @Override + public LayerInfo add(LayerInfo layer) { return resolveOutbound(super.add(resolveInbound(layer))); } - public @Override LayerInfo getLayer(String id) { + @Override + public LayerInfo getLayer(String id) { return resolveOutbound(super.getLayer(id)); } - public @Override LayerInfo getLayerByName(String name) { + @Override + public LayerInfo getLayerByName(String name) { return resolveOutbound(super.getLayerByName(name)); } - public @Override List getLayers(ResourceInfo resource) { + @Override + public List getLayers(ResourceInfo resource) { return resolveOutbound(super.getLayers(resource)); } - public @Override List getLayers(StyleInfo style) { + @Override + public List getLayers(StyleInfo style) { return resolveOutbound(super.getLayers(style)); } - public @Override List getLayers() { + @Override + public List getLayers() { return resolveOutbound(super.getLayers()); } - public @Override MapInfo add(MapInfo map) { + @Override + public MapInfo add(MapInfo map) { return resolveOutbound(super.add(resolveInbound(map))); } - public @Override MapInfo getMap(String id) { + @Override + public MapInfo getMap(String id) { return resolveOutbound(super.getMap(id)); } - public @Override MapInfo getMapByName(String name) { + @Override + public MapInfo getMapByName(String name) { return resolveOutbound(super.getMapByName(name)); } - public @Override List getMaps() { + @Override + public List getMaps() { return resolveOutbound(super.getMaps()); } - public @Override LayerGroupInfo add(LayerGroupInfo layerGroup) { + @Override + public LayerGroupInfo add(LayerGroupInfo layerGroup) { return resolveOutbound(super.add(resolveInbound(layerGroup))); } - public @Override LayerGroupInfo getLayerGroup(String id) { + @Override + public LayerGroupInfo getLayerGroup(String id) { return resolveOutbound(super.getLayerGroup(id)); } - public @Override LayerGroupInfo getLayerGroupByName(String name) { + @Override + public LayerGroupInfo getLayerGroupByName(String name) { return resolveOutbound(super.getLayerGroupByName(name)); } - public @Override LayerGroupInfo getLayerGroupByName(WorkspaceInfo workspace, String name) { + @Override + public LayerGroupInfo getLayerGroupByName(WorkspaceInfo workspace, String name) { return resolveOutbound(super.getLayerGroupByName(workspace, name)); } - public @Override List getLayerGroups() { + @Override + public List getLayerGroups() { return resolveOutbound(super.getLayerGroups()); } - public @Override List getLayerGroupsByWorkspace(WorkspaceInfo workspace) { + @Override + public List getLayerGroupsByWorkspace(WorkspaceInfo workspace) { return resolveOutbound(super.getLayerGroupsByWorkspace(workspace)); } - public @Override NamespaceInfo add(NamespaceInfo namespace) { + @Override + public NamespaceInfo add(NamespaceInfo namespace) { return resolveOutbound(super.add(resolveInbound(namespace))); } - public @Override NamespaceInfo getDefaultNamespace() { + @Override + public NamespaceInfo getDefaultNamespace() { return resolveOutbound(super.getDefaultNamespace()); } - public @Override void setDefaultNamespace(NamespaceInfo defaultNamespace) { + @Override + public void setDefaultNamespace(NamespaceInfo defaultNamespace) { super.setDefaultNamespace(resolveInbound(defaultNamespace)); } - public @Override NamespaceInfo getNamespace(String id) { + @Override + public NamespaceInfo getNamespace(String id) { return resolveOutbound(super.getNamespace(id)); } - public @Override NamespaceInfo getNamespaceByPrefix(String prefix) { + @Override + public NamespaceInfo getNamespaceByPrefix(String prefix) { return resolveOutbound(super.getNamespaceByPrefix(prefix)); } - public @Override NamespaceInfo getNamespaceByURI(String uri) { + @Override + public NamespaceInfo getNamespaceByURI(String uri) { return resolveOutbound(super.getNamespaceByURI(uri)); } - public @Override List getNamespaces() { + @Override + public List getNamespaces() { return resolveOutbound(super.getNamespaces()); } - public @Override WorkspaceInfo add(WorkspaceInfo workspace) { + @Override + public WorkspaceInfo add(WorkspaceInfo workspace) { return resolveOutbound(super.add(resolveInbound(workspace))); } - public @Override WorkspaceInfo getDefaultWorkspace() { + @Override + public WorkspaceInfo getDefaultWorkspace() { return resolveOutbound(super.getDefaultWorkspace()); } - public @Override void setDefaultWorkspace(WorkspaceInfo workspace) { + @Override + public void setDefaultWorkspace(WorkspaceInfo workspace) { super.setDefaultWorkspace(resolveInbound(workspace)); } - public @Override WorkspaceInfo getWorkspace(String id) { + @Override + public WorkspaceInfo getWorkspace(String id) { return resolveOutbound(super.getWorkspace(id)); } - public @Override WorkspaceInfo getWorkspaceByName(String name) { + @Override + public WorkspaceInfo getWorkspaceByName(String name) { return resolveOutbound(super.getWorkspaceByName(name)); } - public @Override List getWorkspaces() { + @Override + public List getWorkspaces() { return resolveOutbound(super.getWorkspaces()); } - public @Override StyleInfo add(StyleInfo style) { + @Override + public StyleInfo add(StyleInfo style) { return resolveOutbound(super.add(resolveInbound(style))); } - public @Override StyleInfo getStyle(String id) { + @Override + public StyleInfo getStyle(String id) { return resolveOutbound(super.getStyle(id)); } - public @Override StyleInfo getStyleByName(String name) { + @Override + public StyleInfo getStyleByName(String name) { return resolveOutbound(super.getStyleByName(name)); } - public @Override StyleInfo getStyleByName(WorkspaceInfo workspace, String name) { + @Override + public StyleInfo getStyleByName(WorkspaceInfo workspace, String name) { return resolveOutbound(super.getStyleByName(workspace, name)); } - public @Override List getStyles() { + @Override + public List getStyles() { return resolveOutbound(super.getStyles()); } - public @Override List getStylesByWorkspace(WorkspaceInfo workspace) { + @Override + public List getStylesByWorkspace(WorkspaceInfo workspace) { return resolveOutbound(super.getStylesByWorkspace(workspace)); } - public @Override void save(WorkspaceInfo info) { + @Override + public void save(WorkspaceInfo info) { super.save(resolveInbound(info)); } - public @Override void save(NamespaceInfo info) { + @Override + public void save(NamespaceInfo info) { super.save(resolveInbound(info)); } - public @Override void save(StoreInfo info) { + @Override + public void save(StoreInfo info) { super.save(resolveInbound(info)); } - public @Override void save(ResourceInfo info) { + @Override + public void save(ResourceInfo info) { super.save(resolveInbound(info)); } - public @Override void save(LayerInfo info) { + @Override + public void save(LayerInfo info) { super.save(resolveInbound(info)); } - public @Override void save(LayerGroupInfo info) { + @Override + public void save(LayerGroupInfo info) { super.save(resolveInbound(info)); } - public @Override void save(StyleInfo info) { + @Override + public void save(StyleInfo info) { super.save(resolveInbound(info)); } - public @Override void save(MapInfo info) { + @Override + public void save(MapInfo info) { super.save(resolveInbound(info)); } - public @Override void remove(WorkspaceInfo info) { + @Override + public void remove(WorkspaceInfo info) { super.remove(resolveInbound(info)); } - public @Override void remove(NamespaceInfo info) { + @Override + public void remove(NamespaceInfo info) { super.remove(resolveInbound(info)); } - public @Override void remove(StoreInfo info) { + @Override + public void remove(StoreInfo info) { super.remove(resolveInbound(info)); } - public @Override void remove(ResourceInfo info) { + @Override + public void remove(ResourceInfo info) { super.remove(resolveInbound(info)); } - public @Override void remove(LayerInfo info) { + @Override + public void remove(LayerInfo info) { super.remove(resolveInbound(info)); } - public @Override void remove(LayerGroupInfo info) { + @Override + public void remove(LayerGroupInfo info) { super.remove(resolveInbound(info)); } - public @Override void remove(StyleInfo info) { + @Override + public void remove(StyleInfo info) { super.remove(resolveInbound(info)); } - public @Override void remove(MapInfo info) { + @Override + public void remove(MapInfo info) { super.remove(resolveInbound(info)); } - public @Override CloseableIterator list( + @Override + public CloseableIterator list( Class of, Filter filter, Integer offset, Integer count, SortBy... sortOrder) { @SuppressWarnings("deprecation") @@ -428,7 +498,8 @@ protected List resolveOutbound(List info) { return CloseableIteratorAdapter.transform(orig, this::resolveOutbound); } - public @Override Stream query(Query query) { + @Override + public Stream query(Query query) { return super.query(query).map(this::resolveOutbound).filter(i -> i != null); } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/ConfigInfoType.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/ConfigInfoType.java index 94e21f649..03e234a3e 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/ConfigInfoType.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/ConfigInfoType.java @@ -34,25 +34,25 @@ @Generated // make test coverage tools ignore it @RequiredArgsConstructor(access = AccessLevel.PRIVATE) enum ConfigInfoType { - Catalog(Catalog.class), // - WorkspaceInfo(WorkspaceInfo.class), // - NamespaceInfo(NamespaceInfo.class), // - CoverageStoreInfo(CoverageStoreInfo.class), // - DataStoreInfo(DataStoreInfo.class), // - WmsStoreInfo(WMSStoreInfo.class), // - WmtsStoreInfo(WMTSStoreInfo.class), // - FeatureTypeInfo(FeatureTypeInfo.class), // - CoverageInfo(CoverageInfo.class), // - WmsLayerInfo(WMSLayerInfo.class), // - WmtsLayerInfo(WMTSLayerInfo.class), // - LayerInfo(LayerInfo.class), // - LayerGroupInfo(LayerGroupInfo.class), // - MapInfo(MapInfo.class), // - StyleInfo(StyleInfo.class), // - GeoServerInfo(GeoServerInfo.class), // - ServiceInfo(ServiceInfo.class), // - SettingsInfo(SettingsInfo.class), // - LoggingInfo(LoggingInfo.class); // + CATALOG(Catalog.class), // + WORKSPACEINFO(WorkspaceInfo.class), // + NAMESPACEINFO(NamespaceInfo.class), // + COVERAGESTOREINFO(CoverageStoreInfo.class), // + DATASTOREINFO(DataStoreInfo.class), // + WMSSTOREINFO(WMSStoreInfo.class), // + WMTSSTOREINFO(WMTSStoreInfo.class), // + FEATURETYPEINFO(FeatureTypeInfo.class), // + COVERAGEINFO(CoverageInfo.class), // + WMSLAYERINFO(WMSLayerInfo.class), // + WMTSLAYERINFO(WMTSLayerInfo.class), // + LAYERINFO(LayerInfo.class), // + LAYERGROUPINFO(LayerGroupInfo.class), // + MAPINFO(MapInfo.class), // + STYLEINFO(StyleInfo.class), // + GEOSERVERINFO(GeoServerInfo.class), // + SERVICEINFO(ServiceInfo.class), // + SETTINGSINFO(SettingsInfo.class), // + LOGGINGINFO(LoggingInfo.class); // private final @Getter @NonNull Class type; diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/LockProviderGeoServerConfigurationLock.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/LockProviderGeoServerConfigurationLock.java index c7429313a..0ea4f8cbb 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/LockProviderGeoServerConfigurationLock.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/LockProviderGeoServerConfigurationLock.java @@ -69,7 +69,8 @@ public LockProviderGeoServerConfigurationLock(@NonNull LockProvider lockProvider this.lockProvider = lockProvider; } - public @Override boolean isWriteLocked() { + @Override + public boolean isWriteLocked() { if (isEnabled()) { final boolean jvmWriteLocked = super.isWriteLocked(); final boolean globalWriteLocked = GLOBAL.get().isWriteLocked(); @@ -103,7 +104,8 @@ private void lockGloblal() { } } - public @Override void lock(LockType type) { + @Override + public void lock(LockType type) { if (isEnabled()) { // JVM lock super.lock(type); @@ -114,7 +116,8 @@ private void lockGloblal() { } } - public @Override boolean tryLock(LockType type) { + @Override + public boolean tryLock(LockType type) { if (isEnabled()) { final boolean jvmLock = super.tryLock(type); if (jvmLock && WRITE == type) { @@ -125,13 +128,15 @@ private void lockGloblal() { return true; } - public @Override void tryUpgradeLock() { + @Override + public void tryUpgradeLock() { if (isEnabled()) { super.tryUpgradeLock(); } } - public @Override void unlock() { + @Override + public void unlock() { if (isEnabled()) { try { unlockGloblal(); diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/LockingCatalog.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/LockingCatalog.java index eb5a2a31a..3a00252b9 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/LockingCatalog.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/LockingCatalog.java @@ -40,8 +40,8 @@ @SuppressWarnings("serial") public class LockingCatalog extends CatalogPlugin { - private final GeoServerConfigurationLock configurationLock; - private LockingSupport locking; + private final transient GeoServerConfigurationLock configurationLock; + private transient LockingSupport locking; public LockingCatalog(@NonNull GeoServerConfigurationLock configurationLock) { super(); @@ -79,8 +79,8 @@ public void disableLocking() { this.locking = LockingSupport.ignoringLocking(); } - public @Override void setDefaultDataStore( - @NonNull WorkspaceInfo workspace, DataStoreInfo store) { + @Override + public void setDefaultDataStore(@NonNull WorkspaceInfo workspace, DataStoreInfo store) { locking.runInWriteLock( () -> super.setDefaultDataStore(workspace, store), format( @@ -88,7 +88,8 @@ public void disableLocking() { workspace.getName(), store == null ? "null" : store.getName())); } - public @Override void setDefaultNamespace(NamespaceInfo defaultNamespace) { + @Override + public void setDefaultNamespace(NamespaceInfo defaultNamespace) { locking.runInWriteLock( () -> super.setDefaultNamespace(defaultNamespace), format( @@ -96,7 +97,8 @@ public void disableLocking() { defaultNamespace == null ? "null" : defaultNamespace.getName())); } - public @Override void setDefaultWorkspace(WorkspaceInfo defaultWorkspace) { + @Override + public void setDefaultWorkspace(WorkspaceInfo defaultWorkspace) { locking.runInWriteLock( () -> super.setDefaultWorkspace(defaultWorkspace), format( @@ -126,7 +128,8 @@ public void disableLocking() { // TODO: Remove once CatalogPlugin moves the namespace update logic to // validationrules.onBefore/AfterSave and just call doSave(store) - public @Override void save(StoreInfo store) { + @Override + public void save(StoreInfo store) { locking.runInWriteLock( () -> super.save(store), format("save(%s[%s])", typeOf(store), nameOf(store))); } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/LockingGeoServer.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/LockingGeoServer.java index 70805d4cd..713e936c1 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/LockingGeoServer.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/LockingGeoServer.java @@ -52,54 +52,64 @@ public void disableLocking() { return this.configurationLock; } - public @Override void setGlobal(GeoServerInfo global) { + @Override + public void setGlobal(GeoServerInfo global) { lockingSupport.runInWriteLock( () -> super.setGlobal(global), format("setGlobal(%s)", nameOf(global))); } - public @Override void save(GeoServerInfo geoServer) { + @Override + public void save(GeoServerInfo geoServer) { lockingSupport.runInWriteLock( () -> super.save(geoServer), format("save(%s)", nameOf(geoServer))); } - public @Override void add(SettingsInfo settings) { + @Override + public void add(SettingsInfo settings) { lockingSupport.runInWriteLock( () -> super.add(settings), format("add(%s[%s])", typeOf(settings), nameOf(settings))); } - public @Override void save(SettingsInfo settings) { + @Override + public void save(SettingsInfo settings) { lockingSupport.runInWriteLock( () -> super.save(settings), format("save(%s[%s])", typeOf(settings), nameOf(settings))); } - public @Override void remove(SettingsInfo settings) { + @Override + public void remove(SettingsInfo settings) { lockingSupport.runInWriteLock( () -> super.remove(settings), format("remove(%s[%s])", typeOf(settings), nameOf(settings))); } - public @Override void setLogging(LoggingInfo logging) { + @Override + public void setLogging(LoggingInfo logging) { lockingSupport.runInWriteLock(() -> super.setLogging(logging), "setLogging(LoggingInfo)"); } - public @Override void save(LoggingInfo logging) { + @Override + public void save(LoggingInfo logging) { lockingSupport.runInWriteLock(() -> super.save(logging), "save(LoggingInfo)"); } - public @Override void add(ServiceInfo service) { + @Override + public void add(ServiceInfo service) { lockingSupport.runInWriteLock( () -> super.add(service), format("add(%s[%s])", typeOf(service), nameOf(service))); } - public @Override void remove(ServiceInfo service) { + @Override + public void remove(ServiceInfo service) { lockingSupport.runInWriteLock( () -> super.remove(service), format("remove(%s[%s])", typeOf(service), nameOf(service))); } - public @Override void save(ServiceInfo service) { + @Override + public void save(ServiceInfo service) { lockingSupport.runInWriteLock( () -> super.save(service), format("save(%s[%s])", typeOf(service), nameOf(service))); diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/LockingSupport.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/LockingSupport.java index a74b0ab0a..6293f3498 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/LockingSupport.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/locking/LockingSupport.java @@ -79,9 +79,9 @@ public void runInWriteLock(Runnable action, String reason) { }, reason); } catch (Exception e) { - if (e instanceof IOException) throw new UncheckedIOException((IOException) e); - if (e instanceof RuntimeException) throw (RuntimeException) e; - throw new RuntimeException(e); + if (e instanceof IOException ioe) throw new UncheckedIOException(ioe); + if (e instanceof RuntimeException rte) throw rte; + throw new IllegalStateException(e); } } @@ -92,7 +92,7 @@ public V callInWriteLock( return action.call(); } catch (Exception e) { if (exceptionType.isInstance(e)) throw exceptionType.cast(e); - throw new RuntimeException(e); + throw new IllegalStateException(e); } finally { unlock(reason); } @@ -101,26 +101,28 @@ public V callInWriteLock( private static class Calling extends LockingSupport { - public @Override void runInWriteLock(Runnable action, String reason) { + @Override + public void runInWriteLock(Runnable action, String reason) { action.run(); } - public @Override V callInWriteLock( + @Override + public V callInWriteLock( Class exceptionType, Callable action, String reason) throws E { try { return action.call(); } catch (Exception e) { if (exceptionType.isInstance(e)) throw exceptionType.cast(e); - throw new RuntimeException(e); + throw new IllegalStateException(e); } } } public static String nameOf(Info object) { if (null == object) return null; - if (object instanceof SettingsInfo) { - WorkspaceInfo ws = ((SettingsInfo) object).getWorkspace(); + if (object instanceof SettingsInfo settings) { + WorkspaceInfo ws = settings.getWorkspace(); if (ws != null) return ws.getName(); } String property = object instanceof NamespaceInfo ? "prefix" : "name"; diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/CatalogPropertyResolver.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/CatalogPropertyResolver.java index 571cb72bb..266405fad 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/CatalogPropertyResolver.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/CatalogPropertyResolver.java @@ -48,17 +48,18 @@ public static CatalogPropertyResolver of(Catalog catalog) { return new CatalogPropertyResolver<>(catalog); } - public @Override T apply(T i) { + @Override + public T apply(T i) { return resolve(i); } private I resolve(I i) { i = null == i ? null : ModificationProxy.unwrap(i); - if (i instanceof StoreInfo) setCatalog((StoreInfo) i); - else if (i instanceof ResourceInfo) setCatalog((ResourceInfo) i); - else if (i instanceof StyleInfo) setCatalog((StyleInfo) i); - else if (i instanceof PublishedInfo) setCatalog((PublishedInfo) i); - else if (i instanceof LayerGroupStyle) setCatalog((LayerGroupStyle) i); + if (i instanceof StoreInfo store) setCatalog(store); + else if (i instanceof ResourceInfo resource) setCatalog(resource); + else if (i instanceof StyleInfo style) setCatalog(style); + else if (i instanceof PublishedInfo published) setCatalog(published); + else if (i instanceof LayerGroupStyle lgs) setCatalog(lgs); return i; } @@ -67,8 +68,8 @@ private void resolve(Collection list) { } private void setCatalog(@NonNull PublishedInfo i) { - if (i instanceof LayerInfo) setCatalog((LayerInfo) i); - else if (i instanceof LayerGroupInfo) setCatalog((LayerGroupInfo) i); + if (i instanceof LayerInfo li) setCatalog(li); + else if (i instanceof LayerGroupInfo lg) setCatalog(lg); } private void setCatalog(@NonNull LayerInfo i) { @@ -93,18 +94,18 @@ private void setCatalog(@NonNull LayerGroupStyle i) { } private void setCatalog(@NonNull StoreInfo i) { - if (i instanceof StoreInfoImpl) ((StoreInfoImpl) i).setCatalog(catalog); + if (i instanceof StoreInfoImpl store) store.setCatalog(catalog); } private void setCatalog(@NonNull ResourceInfo i) { i.setCatalog(catalog); resolve(i.getStore()); - if (i instanceof WMSLayerInfo) { - resolve(((WMSLayerInfo) i).getAllAvailableRemoteStyles()); + if (i instanceof WMSLayerInfo wmsLayer) { + resolve(wmsLayer.getAllAvailableRemoteStyles()); } } private void setCatalog(@NonNull StyleInfo i) { - if (i instanceof StyleInfoImpl) ((StyleInfoImpl) i).setCatalog(catalog); + if (i instanceof StyleInfoImpl style) style.setCatalog(catalog); } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/CollectionPropertiesInitializer.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/CollectionPropertiesInitializer.java index 671bd3b80..e9403694b 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/CollectionPropertiesInitializer.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/CollectionPropertiesInitializer.java @@ -18,10 +18,11 @@ */ public class CollectionPropertiesInitializer implements UnaryOperator { - private static CollectionPropertiesInitializer INSTANCE = + private static final CollectionPropertiesInitializer INSTANCE = new CollectionPropertiesInitializer<>(); - public @Override T apply(T value) { + @Override + public T apply(T value) { if (value != null) { OwsUtils.resolveCollections(value); } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/ModificationProxyDecorator.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/ModificationProxyDecorator.java index 53709dfed..5f8414182 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/ModificationProxyDecorator.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/ModificationProxyDecorator.java @@ -4,6 +4,8 @@ */ package org.geoserver.catalog.plugin.resolving; +import lombok.experimental.UtilityClass; + import org.geoserver.catalog.CatalogInfo; import org.geoserver.catalog.impl.ClassMappings; import org.geoserver.catalog.impl.ModificationProxy; @@ -18,6 +20,7 @@ * * @see ModificationProxy#create(Object, Class) */ +@UtilityClass public class ModificationProxyDecorator { public static Function wrap() { diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/ProxyUtils.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/ProxyUtils.java index 1c2e41ae5..854267b45 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/ProxyUtils.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/ProxyUtils.java @@ -39,11 +39,13 @@ import org.geoserver.config.SettingsInfo; import java.lang.reflect.Proxy; +import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; /** */ @Slf4j @@ -99,17 +101,17 @@ public Patch resolve(Patch patch) { } private Object resolvePatchPropertyValue(Object orig) { - if (orig instanceof Info) { - return resolve((Info) orig); + if (orig instanceof Info info) { + return resolve(info); } - if (orig instanceof AttributeTypeInfo) { - return resolve((AttributeTypeInfo) orig); + if (orig instanceof AttributeTypeInfo att) { + return resolve(att); } if (orig instanceof List) { @SuppressWarnings("unchecked") List list = (List) orig; - resolve(list); - return list; + return resolve(list); + // return list; } if (orig instanceof Set) { @SuppressWarnings("unchecked") @@ -126,12 +128,10 @@ private AttributeTypeInfo resolve(AttributeTypeInfo orig) { return orig; } - private void resolve(List mutableList) { - for (int i = 0; i < mutableList.size(); i++) { - Object v = mutableList.get(i); - Object resolved = resolvePatchPropertyValue(v); - mutableList.set(i, resolved); - } + private List resolve(List mutableList) { + return mutableList.stream() + .map(this::resolvePatchPropertyValue) + .collect(Collectors.toCollection(ArrayList::new)); } private Set resolve(Set set) { @@ -147,7 +147,7 @@ private Set newSet(@SuppressWarnings("rawtypes") Class cl try { return class1.getConstructor().newInstance(); } catch (Exception e) { - return new HashSet(); + return new HashSet<>(); } } @@ -173,15 +173,13 @@ else if (info instanceof ServiceInfo && this.config.isPresent()) throw new IllegalArgumentException("Reference to " + unresolved.getId()); return null; } else if (!Proxy.isProxyClass(info.getClass())) { - if (info instanceof StyleInfo) resolveInternal((StyleInfo) info); - if (info instanceof LayerInfo) resolveInternal((LayerInfo) info); - if (info instanceof LayerGroupInfo) resolveInternal((LayerGroupInfo) info); - if (info instanceof ResourceInfo) resolveInternal((ResourceInfo) info); - if (info instanceof StoreInfo) resolveInternal((StoreInfo) info); - if (info instanceof SettingsInfo) resolveInternal((SettingsInfo) info); - if (info instanceof ServiceInfo) resolveInternal((ServiceInfo) info); - if (info instanceof GeoServerInfo) resolveInternal((GeoServerInfo) info); - if (info instanceof LoggingInfo) resolveInternal((LoggingInfo) info); + if (info instanceof StyleInfo s) resolveInternal(s); + if (info instanceof LayerInfo l) resolveInternal(l); + if (info instanceof LayerGroupInfo lg) resolveInternal(lg); + if (info instanceof ResourceInfo r) resolveInternal(r); + if (info instanceof StoreInfo s) resolveInternal(s); + if (info instanceof SettingsInfo s) resolveInternal(s); + if (info instanceof ServiceInfo s) resolveInternal(s); } return info; } @@ -212,10 +210,6 @@ public static boolean isModificationProxy(final T info) { return null != org.geoserver.catalog.impl.ProxyUtils.handler(info, ModificationProxy.class); } - private void resolveInternal(LoggingInfo info) {} - - private void resolveInternal(GeoServerInfo info) {} - protected void resolveInternal(SettingsInfo settings) { if (settings.getWorkspace() != null) { settings.setWorkspace(resolve(settings.getWorkspace())); @@ -231,7 +225,7 @@ protected void resolveInternal(ServiceInfo service) { protected void resolveInternal(LayerInfo layer) { layer.setResource(resolve(layer.getResource())); layer.setDefaultStyle(resolve(layer.getDefaultStyle())); - LinkedHashSet styles = new LinkedHashSet(); + LinkedHashSet styles = new LinkedHashSet<>(); for (StyleInfo s : layer.getStyles()) { styles.add(resolve(s)); } @@ -239,8 +233,8 @@ protected void resolveInternal(LayerInfo layer) { } protected T resolveInternal(T published) { - if (published instanceof LayerInfo) resolve((LayerInfo) published); - else if (published instanceof LayerGroupInfo) resolve((LayerGroupInfo) published); + if (published instanceof LayerInfo l) resolve(l); + else if (published instanceof LayerGroupInfo lg) resolve(lg); return published; } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/ResolvingProxyResolver.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/ResolvingProxyResolver.java index cdddb4be7..754aacafb 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/ResolvingProxyResolver.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/resolving/ResolvingProxyResolver.java @@ -100,7 +100,8 @@ public ResolvingProxyResolver memoizing() { return (ResolvingProxyResolver) new MemoizingProxyResolver(catalog, onNotFound); } - public @Override T apply(T info) { + @Override + public T apply(T info) { return resolve(info); } @@ -115,26 +116,26 @@ public I resolve(final I orig) { if (isResolvingProxy) { // may the object itself be a resolving proxy I resolved = doResolveProxy(orig); - if (resolved == null && orig instanceof CatalogInfo) { + if (resolved == null && orig instanceof CatalogInfo cinfo) { log.info("Proxy object {} not found, calling on-not-found consumer", orig.getId()); - onNotFound.accept((CatalogInfo) orig, resolvingProxy); + onNotFound.accept(cinfo, resolvingProxy); // return the proxied value if the consumer didn't throw an exception return orig; } return resolved; } - if (orig instanceof StyleInfo) return (I) resolveInternal((StyleInfo) orig); + if (orig instanceof StyleInfo style) return (I) resolveInternal(style); - if (orig instanceof PublishedInfo) return (I) resolveInternal((PublishedInfo) orig); + if (orig instanceof PublishedInfo published) return (I) resolveInternal(published); - if (orig instanceof ResourceInfo) return (I) resolveInternal((ResourceInfo) orig); + if (orig instanceof ResourceInfo resource) return (I) resolveInternal(resource); - if (orig instanceof StoreInfo) return (I) resolveInternal((StoreInfo) orig); + if (orig instanceof StoreInfo store) return (I) resolveInternal(store); - if (orig instanceof SettingsInfo) return (I) resolveInternal((SettingsInfo) orig); + if (orig instanceof SettingsInfo settings) return (I) resolveInternal(settings); - if (orig instanceof ServiceInfo) return (I) resolveInternal((ServiceInfo) orig); + if (orig instanceof ServiceInfo service) return (I) resolveInternal(service); return orig; } @@ -152,8 +153,8 @@ protected ResolvingProxy getResolvingProxy(final Info unresolved) { boolean isProxy = Proxy.isProxyClass(unresolved.getClass()); if (isProxy) { InvocationHandler invocationHandler = Proxy.getInvocationHandler(unresolved); - if (invocationHandler instanceof ResolvingProxy) { - return (ResolvingProxy) invocationHandler; + if (invocationHandler instanceof ResolvingProxy resolvingProxy) { + return resolvingProxy; } } } @@ -162,10 +163,9 @@ protected ResolvingProxy getResolvingProxy(final Info unresolved) { @SuppressWarnings("unchecked") protected

P resolveInternal(P published) { - if (published instanceof LayerInfo) return (P) resolveInternal((LayerInfo) published); + if (published instanceof LayerInfo layer) return (P) resolveInternal(layer); - if (published instanceof LayerGroupInfo) - return (P) resolveInternal((LayerGroupInfo) published); + if (published instanceof LayerGroupInfo lg) return (P) resolveInternal(lg); return published; } @@ -257,7 +257,7 @@ protected ResourceInfo resolveInternal(ResourceInfo resource) { private static class MemoizingProxyResolver extends ResolvingProxyResolver { - private Map resolved = new ConcurrentHashMap<>(); + private Map resolvedById = new ConcurrentHashMap<>(); public MemoizingProxyResolver( Catalog catalog, BiConsumer onNotFound) { @@ -267,14 +267,20 @@ public MemoizingProxyResolver( @SuppressWarnings("unchecked") protected @Override I doResolveProxy(final I orig) { String id = orig.getId(); - I resolved = (I) this.resolved.get(id); + I resolved = (I) this.resolvedById.get(id); if (null == resolved) { log.trace("Memoized cache miss, resolving proxy reference {}", id); - resolved = (I) this.resolved.computeIfAbsent(id, key -> super.doResolveProxy(orig)); + resolved = computeIfAbsent(orig); } else { log.trace("Memoized cache hit for {}", resolved.getId()); } return resolved; } + + @SuppressWarnings("unchecked") + private I computeIfAbsent(final I orig) { + return (I) + resolvedById.computeIfAbsent(orig.getId(), key -> super.doResolveProxy(orig)); + } } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/rules/DefaultNamespaceInfoRules.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/rules/DefaultNamespaceInfoRules.java index 952da58b5..f1fb7c4c9 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/rules/DefaultNamespaceInfoRules.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/rules/DefaultNamespaceInfoRules.java @@ -22,7 +22,8 @@ public class DefaultNamespaceInfoRules implements CatalogInfoBusinessRules context) { + @Override + public void beforeAdd(CatalogOpContext context) { NamespaceInfo defaultNamespace = context.getCatalog().getDefaultNamespace(); Boolean needsSetDefault = defaultNamespace == null; context.setContextOption(SET_DEFAULT, needsSetDefault); @@ -32,7 +33,8 @@ public class DefaultNamespaceInfoRules implements CatalogInfoBusinessRules context) { + @Override + public void afterAdd(CatalogOpContext context) { setAsDefaultIfThereWasNoDefaultNamespace(context); } @@ -50,7 +52,8 @@ protected void setAsDefaultIfThereWasNoDefaultNamespace( * Selects a new catalog default namespace if as the result of removing the namespace referred * to by {@code context.getObject()}, the catalog has no default one. */ - public @Override void afterRemove(CatalogOpContext context) { + @Override + public void afterRemove(CatalogOpContext context) { if (context.isSuccess()) { selectNewDefaultNamespaceIfRemoved(context.getCatalog(), context.getObject()); } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/rules/DefaultStoreInfoRules.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/rules/DefaultStoreInfoRules.java index 8be040f3c..41061723d 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/rules/DefaultStoreInfoRules.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/rules/DefaultStoreInfoRules.java @@ -24,7 +24,8 @@ public class DefaultStoreInfoRules implements CatalogInfoBusinessRules context) { + @Override + public void beforeAdd(CatalogOpContext context) { if (context.getObject() instanceof DataStoreInfo) { WorkspaceInfo workspace = context.getObject().getWorkspace(); Catalog catalog = context.getCatalog(); @@ -36,13 +37,15 @@ public class DefaultStoreInfoRules implements CatalogInfoBusinessRules context) { + @Override + public void afterAdd(CatalogOpContext context) { if (context.getObject() instanceof DataStoreInfo) { setAsDefaultDataStoreInWorkspace(context.as(DataStoreInfo.class)); } } - public @Override void beforeRemove(CatalogOpContext context) { + @Override + public void beforeRemove(CatalogOpContext context) { if (context.getObject() instanceof DataStoreInfo) { StoreInfo toRemove = context.getObject(); WorkspaceInfo workspace = toRemove.getWorkspace(); @@ -60,7 +63,8 @@ public class DefaultStoreInfoRules implements CatalogInfoBusinessRules context) { + @Override + public void afterRemove(CatalogOpContext context) { if (context.getObject() instanceof DataStoreInfo) { selectNewDefaultDataStoreIfRemoved(context.as(DataStoreInfo.class)); } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/rules/DefaultStyleInfoRules.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/rules/DefaultStyleInfoRules.java index 885693906..e8650a894 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/rules/DefaultStyleInfoRules.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/rules/DefaultStyleInfoRules.java @@ -33,7 +33,8 @@ public class DefaultStyleInfoRules implements CatalogInfoBusinessRules context) { + @Override + public void beforeSave(CatalogOpContext context) { PropertyDiff diff = context.getDiff(); Optional nameChange = diff.get("name"); nameChange.ifPresent( @@ -50,7 +51,8 @@ public class DefaultStyleInfoRules implements CatalogInfoBusinessRules context) { + @Override + public void afterSave(CatalogOpContext context) { if (context.isSuccess()) { return; } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/rules/DefaultWorkspaceInfoRules.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/rules/DefaultWorkspaceInfoRules.java index dc55613e0..3517d263f 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/rules/DefaultWorkspaceInfoRules.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/rules/DefaultWorkspaceInfoRules.java @@ -22,7 +22,8 @@ public class DefaultWorkspaceInfoRules implements CatalogInfoBusinessRules context) { + @Override + public void beforeAdd(CatalogOpContext context) { WorkspaceInfo defaultWorkspace = context.getCatalog().getDefaultWorkspace(); Boolean needsSetDefault = defaultWorkspace == null; context.setContextOption(SET_DEFAULT, needsSetDefault); @@ -32,7 +33,8 @@ public class DefaultWorkspaceInfoRules implements CatalogInfoBusinessRules context) { + @Override + public void afterAdd(CatalogOpContext context) { // there's only this rule so far: setAsDefaultIfThereWasNoDefaultWorkspace(context); } @@ -41,7 +43,8 @@ public class DefaultWorkspaceInfoRules implements CatalogInfoBusinessRules context) { + @Override + public void afterRemove(CatalogOpContext context) { if (context.isSuccess()) { selectNewDefaultWorkspaceIfRemoved(context.getCatalog(), context.getObject()); } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/validation/CatalogValidationRules.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/validation/CatalogValidationRules.java index 289743293..e832f47c0 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/validation/CatalogValidationRules.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/validation/CatalogValidationRules.java @@ -95,32 +95,32 @@ public ValidationResult validate(T object, boolean isNew private T workAroundModificationProxyBugCallingVisitorWithUnwrappedObject( T info, CatalogVisitor visitor) { - if (info instanceof LayerGroupInfo) { - visitor.visit((LayerGroupInfo) info); - } else if (info instanceof LayerInfo) { - visitor.visit((LayerInfo) info); - } else if (info instanceof NamespaceInfo) { - visitor.visit((NamespaceInfo) info); - } else if (info instanceof CoverageInfo) { - visitor.visit((CoverageInfo) info); - } else if (info instanceof FeatureTypeInfo) { - visitor.visit((FeatureTypeInfo) info); - } else if (info instanceof WMSLayerInfo) { - visitor.visit((WMSLayerInfo) info); - } else if (info instanceof WMTSLayerInfo) { - visitor.visit((WMTSLayerInfo) info); - } else if (info instanceof CoverageStoreInfo) { - visitor.visit((CoverageStoreInfo) info); - } else if (info instanceof DataStoreInfo) { - visitor.visit((DataStoreInfo) info); - } else if (info instanceof WMSStoreInfo) { - visitor.visit((WMSStoreInfo) info); - } else if (info instanceof WMTSStoreInfo) { - visitor.visit((WMTSStoreInfo) info); - } else if (info instanceof StyleInfo) { - visitor.visit((StyleInfo) info); - } else if (info instanceof WorkspaceInfo) { - visitor.visit((WorkspaceInfo) info); + if (info instanceof LayerGroupInfo lg) { + visitor.visit(lg); + } else if (info instanceof LayerInfo l) { + visitor.visit(l); + } else if (info instanceof NamespaceInfo ns) { + visitor.visit(ns); + } else if (info instanceof CoverageInfo coverage) { + visitor.visit(coverage); + } else if (info instanceof FeatureTypeInfo ft) { + visitor.visit(ft); + } else if (info instanceof WMSLayerInfo wmsLayer) { + visitor.visit(wmsLayer); + } else if (info instanceof WMTSLayerInfo wmtsLayer) { + visitor.visit(wmtsLayer); + } else if (info instanceof CoverageStoreInfo cs) { + visitor.visit(cs); + } else if (info instanceof DataStoreInfo ds) { + visitor.visit(ds); + } else if (info instanceof WMSStoreInfo wmss) { + visitor.visit(wmss); + } else if (info instanceof WMTSStoreInfo wmtss) { + visitor.visit(wmtss); + } else if (info instanceof StyleInfo style) { + visitor.visit(style); + } else if (info instanceof WorkspaceInfo ws) { + visitor.visit(ws); } else { throw new IllegalArgumentException("Unknown resource type: " + info); } @@ -128,22 +128,22 @@ T workAroundModificationProxyBugCallingVisitorWithUnwrappedObject( } public void beforeRemove(T info) { - if (info instanceof LayerGroupInfo) { - beforeRemove((LayerGroupInfo) info); - } else if (info instanceof LayerInfo) { - beforeRemove((LayerInfo) info); - } else if (info instanceof MapInfo) { - beforeRemove((MapInfo) info); - } else if (info instanceof NamespaceInfo) { - beforeRemove((NamespaceInfo) info); - } else if (info instanceof ResourceInfo) { - beforeRemove((ResourceInfo) info); - } else if (info instanceof StoreInfo) { - beforeRemove((StoreInfo) info); - } else if (info instanceof StyleInfo) { - beforeRemove((StyleInfo) info); - } else if (info instanceof WorkspaceInfo) { - beforeRemove((WorkspaceInfo) info); + if (info instanceof LayerGroupInfo lg) { + beforeRemove(lg); + } else if (info instanceof LayerInfo l) { + beforeRemove(l); + } else if (info instanceof MapInfo map) { + // no-op + } else if (info instanceof NamespaceInfo ns) { + beforeRemove(ns); + } else if (info instanceof ResourceInfo res) { + beforeRemove(res); + } else if (info instanceof StoreInfo s) { + beforeRemove(s); + } else if (info instanceof StyleInfo style) { + beforeRemove(style); + } else if (info instanceof WorkspaceInfo ws) { + beforeRemove(ws); } else { throw new IllegalArgumentException("Unknown resource type: " + info); } @@ -224,12 +224,8 @@ private void beforeRemove(StyleInfo style) { checkArgument(!isDefaultStyle(style), "Unable to delete a default style"); } - private void beforeRemove(MapInfo map) { - // no-op - } - private ValidationResult postValidate(CatalogInfo info, boolean isNew) { - List errors = new ArrayList(); + List errors = new ArrayList<>(); if (!extendedValidation) { return new ValidationResult(null); @@ -255,57 +251,71 @@ static class CatalogValidatorVisitor implements CatalogVisitor { this.isNew = isNew; } - public @Override void visit(Catalog catalog) {} + @Override + public void visit(Catalog catalog) {} - public @Override void visit(WorkspaceInfo workspace) { + @Override + public void visit(WorkspaceInfo workspace) { validator.validate(workspace, isNew); } - public @Override void visit(NamespaceInfo namespace) { + @Override + public void visit(NamespaceInfo namespace) { validator.validate(namespace, isNew); } - public @Override void visit(DataStoreInfo dataStore) { + @Override + public void visit(DataStoreInfo dataStore) { validator.validate(dataStore, isNew); } - public @Override void visit(CoverageStoreInfo coverageStore) { + @Override + public void visit(CoverageStoreInfo coverageStore) { validator.validate(coverageStore, isNew); } - public @Override void visit(WMSStoreInfo wmsStore) { + @Override + public void visit(WMSStoreInfo wmsStore) { validator.validate(wmsStore, isNew); } - public @Override void visit(WMTSStoreInfo wmtsStore) { + @Override + public void visit(WMTSStoreInfo wmtsStore) { validator.validate(wmtsStore, isNew); } - public @Override void visit(FeatureTypeInfo featureType) { + @Override + public void visit(FeatureTypeInfo featureType) { validator.validate(featureType, isNew); } - public @Override void visit(CoverageInfo coverage) { + @Override + public void visit(CoverageInfo coverage) { validator.validate(coverage, isNew); } - public @Override void visit(LayerInfo layer) { + @Override + public void visit(LayerInfo layer) { validator.validate(layer, isNew); } - public @Override void visit(StyleInfo style) { + @Override + public void visit(StyleInfo style) { validator.validate(style, isNew); } - public @Override void visit(LayerGroupInfo layerGroup) { + @Override + public void visit(LayerGroupInfo layerGroup) { validator.validate(layerGroup, isNew); } - public @Override void visit(WMSLayerInfo wmsLayer) { + @Override + public void visit(WMSLayerInfo wmsLayer) { validator.validate(wmsLayer, isNew); } - public @Override void visit(WMTSLayerInfo wmtsLayer) { + @Override + public void visit(WMTSLayerInfo wmtsLayer) { validator.validate(wmtsLayer, isNew); } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/validation/DefaultCatalogValidator.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/validation/DefaultCatalogValidator.java index 55c49cd8c..01d8405bd 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/validation/DefaultCatalogValidator.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/validation/DefaultCatalogValidator.java @@ -52,7 +52,8 @@ public DefaultCatalogValidator(Catalog catalog) { this.newObjectPropertiesResolver = new DefaultPropertyValuesResolver(catalog); } - public @Override void validate(WorkspaceInfo workspace, boolean isNew) { + @Override + public void validate(WorkspaceInfo workspace, boolean isNew) { checkNotEmpty(workspace.getName(), "workspace name must not be null"); checkArgument( !Catalog.DEFAULT.equals(workspace.getName()), @@ -75,7 +76,8 @@ public DefaultCatalogValidator(Catalog catalog) { workspace.getName()); } - public @Override void validate(NamespaceInfo namespace, boolean isNew) { + @Override + public void validate(NamespaceInfo namespace, boolean isNew) { checkNotEmpty(namespace.getPrefix(), "Namespace prefix must not be null"); checkNotEmpty(namespace.getURI(), "Namespace uri must not be null"); if (isNew) { @@ -120,7 +122,8 @@ public DefaultCatalogValidator(Catalog catalog) { } } - public @Override void validate(StoreInfo store, boolean isNew) { + @Override + public void validate(StoreInfo store, boolean isNew) { if (isNew) { newObjectPropertiesResolver.resolve(store); } @@ -140,14 +143,15 @@ public DefaultCatalogValidator(Catalog catalog) { } } - public @Override void validate(ResourceInfo resource, boolean isNew) { + @Override + public void validate(ResourceInfo resource, boolean isNew) { checkNotEmpty(resource.getName(), "Resource name must not be null"); if (isNew) { newObjectPropertiesResolver.resolve(resource); } if (isNullOrEmpty(resource.getNativeName()) - && !(resource instanceof CoverageInfo - && ((CoverageInfo) resource).getNativeCoverageName() != null)) { + && !(resource instanceof CoverageInfo coverage + && coverage.getNativeCoverageName() != null)) { throw new NullPointerException("Resource native name must not be null"); } checkNotNull(resource.getStore(), "Resource must be part of a store"); @@ -173,11 +177,8 @@ public DefaultCatalogValidator(Catalog catalog) { validateKeywords(resource.getKeywords()); } - public @Override void validate(LayerInfo layer, boolean isNew) { - // TODO: bring back when the layer/publishing split is in act - // if ( isNull(layer.getName()) ) { - // throw new NullPointerException( "Layer name must not be null" ); - // } + @Override + public void validate(LayerInfo layer, boolean isNew) { final ResourceInfo resource = layer.getResource(); checkNotNull(resource, "Layer resource must not be null"); if (isNew) { @@ -203,35 +204,34 @@ public DefaultCatalogValidator(Catalog catalog) { // if the style is missing associate a default one, to avoid breaking WMS if (layer.getDefaultStyle() == null) { try { - LOGGER.log( - Level.INFO, - "Layer " - + layer.prefixedName() - + " is missing the default style, assigning one automatically"); + LOGGER.info( + () -> + "Layer %s is missing the default style, assigning one automatically" + .formatted(layer.prefixedName())); StyleInfo style = new CatalogBuilder(catalog).getDefaultStyle(resource); layer.setDefaultStyle(style); } catch (IOException e) { LOGGER.log( Level.WARNING, - "Layer " - + layer.prefixedName() - + " is missing the default style, " - + "failed to associate one automatically", - e); + e, + () -> + "Layer %s is missing the default style, failed to associate one automatically" + .formatted(layer.prefixedName())); } } // clean up eventual dangling references to missing alternate styles Set styles = layer.getStyles(); for (Iterator it = styles.iterator(); it.hasNext(); ) { - StyleInfo styleInfo = (StyleInfo) it.next(); + StyleInfo styleInfo = it.next(); if (styleInfo == null) { it.remove(); } } } - public @Override void validate(LayerGroupInfo layerGroup, boolean isNew) { + @Override + public void validate(LayerGroupInfo layerGroup, boolean isNew) { checkNotEmpty(layerGroup.getName(), "Layer group name must not be null"); if (isNew) { newObjectPropertiesResolver.resolve(layerGroup); @@ -323,7 +323,8 @@ public DefaultCatalogValidator(Catalog catalog) { } } - public @Override void validate(StyleInfo style, boolean isNew) { + @Override + public void validate(StyleInfo style, boolean isNew) { if (isNew) { newObjectPropertiesResolver.resolve(style); } @@ -392,10 +393,10 @@ private void checkLayerGroupResourceIsInWorkspace(LayerGroupInfo layerGroup, Wor checkLayerGroupResourceIsInWorkspace(layerGroup.getRootLayerStyle(), ws); if (layerGroup.getLayers() != null) { for (PublishedInfo p : layerGroup.getLayers()) { - if (p instanceof LayerGroupInfo) { - checkLayerGroupResourceIsInWorkspace((LayerGroupInfo) p, ws); - } else if (p instanceof LayerInfo) { - checkLayerGroupResourceIsInWorkspace((LayerInfo) p, ws); + if (p instanceof LayerGroupInfo lg) { + checkLayerGroupResourceIsInWorkspace(lg, ws); + } else if (p instanceof LayerInfo l) { + checkLayerGroupResourceIsInWorkspace(l, ws); } } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/validation/DefaultPropertyValuesResolver.java b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/validation/DefaultPropertyValuesResolver.java index 2a22bcfb1..fd4e17cca 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/validation/DefaultPropertyValuesResolver.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/validation/DefaultPropertyValuesResolver.java @@ -43,22 +43,22 @@ public DefaultPropertyValuesResolver(Catalog catalog) { } public void resolve(CatalogInfo info) { - if (info instanceof LayerGroupInfo) { - resolve((LayerGroupInfo) info); - } else if (info instanceof LayerInfo) { - resolve((LayerInfo) info); - } else if (info instanceof MapInfo) { - resolve((MapInfo) info); - } else if (info instanceof NamespaceInfo) { - resolve((NamespaceInfo) info); - } else if (info instanceof ResourceInfo) { - resolve((ResourceInfo) info); - } else if (info instanceof StoreInfo) { - resolve((StoreInfo) info); - } else if (info instanceof StyleInfo) { - resolve((StyleInfo) info); - } else if (info instanceof WorkspaceInfo) { - resolve((WorkspaceInfo) info); + if (info instanceof LayerGroupInfo lg) { + resolve(lg); + } else if (info instanceof LayerInfo l) { + resolve(l); + } else if (info instanceof MapInfo m) { + resolve(m); + } else if (info instanceof NamespaceInfo ns) { + resolve(ns); + } else if (info instanceof ResourceInfo res) { + resolve(res); + } else if (info instanceof StoreInfo st) { + resolve(st); + } else if (info instanceof StyleInfo style) { + resolve(style); + } else if (info instanceof WorkspaceInfo ws) { + resolve(ws); } else { throw new IllegalArgumentException("Unknown resource type: " + info); } @@ -83,27 +83,26 @@ private void resolve(ResourceInfo resource) { ResourceInfoImpl r = (ResourceInfoImpl) resource; r.setCatalog(catalog); - if (resource instanceof FeatureTypeInfo) { - resolve((FeatureTypeInfo) resource); + if (resource instanceof FeatureTypeInfo ft) { + resolve(ft); } - if (r instanceof CoverageInfo) { - resolve((CoverageInfo) resource); + if (r instanceof CoverageInfo c) { + resolve(c); } - if (r instanceof WMSLayerInfo) { - resolve((WMSLayerInfo) resource); + if (r instanceof WMSLayerInfo wms) { + resolve(wms); } - if (r instanceof WMTSLayerInfo) { - resolve((WMTSLayerInfo) resource); + if (r instanceof WMTSLayerInfo wmts) { + resolve(wmts); } } private CoverageInfo resolve(CoverageInfo r) { - if (r instanceof CoverageInfoImpl) { - CoverageInfoImpl c = (CoverageInfoImpl) r; + if (r instanceof CoverageInfoImpl c) { if (c.getDimensions() != null) { for (CoverageDimensionInfo dim : c.getDimensions()) { if (dim.getNullValues() == null) { - ((CoverageDimensionImpl) dim).setNullValues(new ArrayList()); + ((CoverageDimensionImpl) dim).setNullValues(new ArrayList<>()); } } } @@ -122,16 +121,14 @@ private void resolve(FeatureTypeInfo featureType) { } private WMSLayerInfo resolve(WMSLayerInfo wmsLayer) { - if (wmsLayer instanceof WMSLayerInfoImpl) { - WMSLayerInfoImpl impl = (WMSLayerInfoImpl) wmsLayer; + if (wmsLayer instanceof WMSLayerInfoImpl impl) { resolveCollections(impl); } return wmsLayer; } private WMTSLayerInfo resolve(WMTSLayerInfo wmtsLayer) { - if (wmtsLayer instanceof WMTSLayerInfoImpl) { - WMTSLayerInfoImpl impl = (WMTSLayerInfoImpl) wmtsLayer; + if (wmtsLayer instanceof WMTSLayerInfoImpl impl) { resolveCollections(impl); } return wmtsLayer; diff --git a/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/ConfigRepository.java b/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/ConfigRepository.java index 30ec1e554..3c16a770e 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/ConfigRepository.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/ConfigRepository.java @@ -73,10 +73,10 @@ public interface ConfigRepository { S update(S service, Patch patch); /** GeoServer global services (not attached to any Workspace) */ - Stream getGlobalServices(); + Stream getGlobalServices(); /** GeoServer services specific to the specified workspace. */ - Stream getServicesByWorkspace(WorkspaceInfo workspace); + Stream getServicesByWorkspace(WorkspaceInfo workspace); /** * GeoServer global service filtered by type. diff --git a/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/GeoServerImpl.java b/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/GeoServerImpl.java index 272ec18ad..a263d615f 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/GeoServerImpl.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/GeoServerImpl.java @@ -76,7 +76,7 @@ public class GeoServerImpl implements GeoServer, ApplicationContextAware { private GeoServerFacade facade; /** listeners */ - private List listeners = new ArrayList(); + private List listeners = new ArrayList<>(); public GeoServerImpl() { this(new RepositoryGeoServerFacadeImpl()); @@ -86,62 +86,64 @@ public GeoServerImpl(GeoServerFacade facade) { setFacade(facade); } - public @Override GeoServerFacade getFacade() { + @Override + public GeoServerFacade getFacade() { return facade; } public void setFacade(GeoServerFacade facade) { this.facade = facade; facade.setGeoServer(this); - // if (facade.getGlobal() == null) { - // facade.setGlobal(getFactory().createGlobal()); - // } - // if (facade.getLogging() == null) { - // facade.setLogging(getFactory().createLogging()); - // } } - public @Override void setApplicationContext(ApplicationContext context) throws BeansException { - if (factory instanceof ApplicationContextAware) { - ((ApplicationContextAware) factory).setApplicationContext(context); + @Override + public void setApplicationContext(ApplicationContext context) throws BeansException { + if (factory instanceof ApplicationContextAware appcAware) { + appcAware.setApplicationContext(context); } } - public @Override GeoServerFactory getFactory() { + @Override + public GeoServerFactory getFactory() { return factory; } - public @Override void setFactory(GeoServerFactory factory) { + @Override + public void setFactory(GeoServerFactory factory) { this.factory = factory; } - public @Override Catalog getCatalog() { + @Override + public Catalog getCatalog() { return catalog; } - public @Override void setCatalog(Catalog catalog) { + @Override + public void setCatalog(Catalog catalog) { this.catalog = catalog; // This instance of check is has to be here because this Geoserver cannot be injected // into LocalWorkspaceCatalog because it causes a circular reference - if (catalog instanceof LocalWorkspaceCatalog) { - LocalWorkspaceCatalog lwCatalog = (LocalWorkspaceCatalog) catalog; + if (catalog instanceof LocalWorkspaceCatalog lwCatalog) { lwCatalog.setGeoServer(this); } } - public @Override GeoServerInfo getGlobal() { + @Override + public GeoServerInfo getGlobal() { return facade.getGlobal(); } - public @Override void setGlobal(GeoServerInfo global) { + @Override + public void setGlobal(GeoServerInfo global) { facade.setGlobal(global); // fire the modification event fireGlobalPostModified(); } - public @Override SettingsInfo getSettings() { + @Override + public SettingsInfo getSettings() { SettingsInfo settings = null; if (LocalWorkspace.get() != null) { settings = getSettings(LocalWorkspace.get()); @@ -149,11 +151,13 @@ public void setFacade(GeoServerFacade facade) { return settings != null ? settings : getGlobal().getSettings(); } - public @Override SettingsInfo getSettings(WorkspaceInfo workspace) { + @Override + public SettingsInfo getSettings(WorkspaceInfo workspace) { return facade.getSettings(workspace); } - public @Override void add(SettingsInfo settings) { + @Override + public void add(SettingsInfo settings) { validate(settings); resolve(settings); @@ -167,14 +171,16 @@ public void setFacade(GeoServerFacade facade) { fireSettingsAdded(settings); } - public @Override void save(SettingsInfo settings) { + @Override + public void save(SettingsInfo settings) { validate(settings); facade.save(settings); fireSettingsPostModified(settings); } - public @Override void remove(SettingsInfo settings) { + @Override + public void remove(SettingsInfo settings) { facade.remove(settings); fireSettingsRemoved(settings); @@ -185,9 +191,8 @@ void validate(SettingsInfo settings) { if (workspace == null) { throw new IllegalArgumentException("Settings must be part of a workspace"); } - Catalog catalog = getCatalog(); // make sure the workspace exists and is not dettached from the catalog - final WorkspaceInfo realws = catalog.getWorkspace(workspace.getId()); + final WorkspaceInfo realws = getCatalog().getWorkspace(workspace.getId()); Objects.requireNonNull( realws, () -> @@ -206,15 +211,13 @@ void fireSettingsAdded(SettingsInfo settings) { try { l.handleSettingsAdded(settings); } catch (Exception e) { - LOGGER.log( - Level.SEVERE, - "Error occurred processing a configuration change listener", - e); + logListenerError(e); } } } - public @Override void fireSettingsModified( + @Override + public void fireSettingsModified( SettingsInfo settings, List changed, List oldValues, @@ -223,10 +226,7 @@ void fireSettingsAdded(SettingsInfo settings) { try { l.handleSettingsModified(settings, changed, oldValues, newValues); } catch (Exception e) { - LOGGER.log( - Level.SEVERE, - "Error occurred processing a configuration change listener", - e); + logListenerError(e); } } } @@ -236,10 +236,7 @@ void fireSettingsPostModified(SettingsInfo settings) { try { l.handleSettingsPostModified(settings); } catch (Exception e) { - LOGGER.log( - Level.SEVERE, - "Error occurred processing a configuration change listener", - e); + logListenerError(e); } } } @@ -249,24 +246,24 @@ void fireSettingsRemoved(SettingsInfo settings) { try { l.handleSettingsRemoved(settings); } catch (Exception e) { - LOGGER.log( - Level.SEVERE, - "Error occurred processing a configuration change listener", - e); + logListenerError(e); } } } - public @Override LoggingInfo getLogging() { + @Override + public LoggingInfo getLogging() { return facade.getLogging(); } - public @Override void setLogging(LoggingInfo logging) { + @Override + public void setLogging(LoggingInfo logging) { facade.setLogging(logging); fireLoggingPostModified(); } - public @Override void add(ServiceInfo service) { + @Override + public void add(ServiceInfo service) { if (service.getId() != null && facade.getService(service.getId(), ServiceInfo.class) != null) { throw new IllegalArgumentException( @@ -300,28 +297,33 @@ public static T unwrap(T obj) { return RepositoryGeoServerFacadeImpl.unwrap(obj); } - public @Override T getService(Class clazz) { + @Override + public T getService(Class clazz) { WorkspaceInfo ws = LocalWorkspace.get(); T service = ws != null ? facade.getService(ws, clazz) : null; service = service != null ? service : facade.getService(clazz); if (service == null) { - LOGGER.log( - Level.SEVERE, - "Could not locate service of type " + clazz + ", local workspace is " + ws); + LOGGER.severe( + () -> + "Could not locate service of type %s, local workspace is %s" + .formatted(clazz, ws)); } return service; } - public @Override T getService(WorkspaceInfo workspace, Class clazz) { + @Override + public T getService(WorkspaceInfo workspace, Class clazz) { return facade.getService(workspace, clazz); } - public @Override T getService(String id, Class clazz) { + @Override + public T getService(String id, Class clazz) { return facade.getService(id, clazz); } - public @Override T getServiceByName(String name, Class clazz) { + @Override + public T getServiceByName(String name, Class clazz) { T service = LocalWorkspace.get() != null ? facade.getServiceByName(name, LocalWorkspace.get(), clazz) @@ -329,12 +331,14 @@ public static T unwrap(T obj) { return service != null ? service : facade.getServiceByName(name, clazz); } - public @Override T getServiceByName( + @Override + public T getServiceByName( WorkspaceInfo workspace, String name, Class clazz) { return facade.getServiceByName(name, workspace, clazz); } - public @Override Collection getServices() { + @Override + public Collection getServices() { WorkspaceInfo localWorkspace = LocalWorkspace.get(); Collection services; if (localWorkspace == null) { @@ -345,24 +349,28 @@ public static T unwrap(T obj) { return services; } - public @Override Collection getServices(WorkspaceInfo workspace) { + @Override + public Collection getServices(WorkspaceInfo workspace) { return facade.getServices(workspace); } - public @Override void remove(ServiceInfo service) { + @Override + public void remove(ServiceInfo service) { facade.remove(service); fireServiceRemoved(service); } - public @Override void save(GeoServerInfo geoServer) { + @Override + public void save(GeoServerInfo geoServer) { facade.save(geoServer); // fire post modification event fireGlobalPostModified(); } - public @Override void save(LoggingInfo logging) { + @Override + public void save(LoggingInfo logging) { facade.save(logging); // fire post modification event @@ -378,12 +386,12 @@ private void notifyPost(ConfigurationListener l, GeoServerInfo global) { try { l.handlePostGlobalChange(global); } catch (Exception e) { - LOGGER.log( - Level.SEVERE, "Error occurred processing a configuration change listener", e); + logListenerError(e); } } - public @Override void fireGlobalModified( + @Override + public void fireGlobalModified( GeoServerInfo global, List changed, List oldValues, @@ -393,15 +401,13 @@ private void notifyPost(ConfigurationListener l, GeoServerInfo global) { try { l.handleGlobalChange(global, changed, oldValues, newValues); } catch (Exception e) { - LOGGER.log( - Level.SEVERE, - "Error occurred processing a configuration change listener", - e); + logListenerError(e); } } } - public @Override void fireLoggingModified( + @Override + public void fireLoggingModified( LoggingInfo logging, List changed, List oldValues, @@ -411,10 +417,7 @@ private void notifyPost(ConfigurationListener l, GeoServerInfo global) { try { l.handleLoggingChange(logging, changed, oldValues, newValues); } catch (Exception e) { - LOGGER.log( - Level.SEVERE, - "Error occurred processing a configuration change listener", - e); + logListenerError(e); } } } @@ -428,12 +431,12 @@ protected void notifyPost(LoggingInfo logging, ConfigurationListener l) { try { l.handlePostLoggingChange(logging); } catch (Exception e) { - LOGGER.log( - Level.SEVERE, "Error occurred processing a configuration change listener", e); + logListenerError(e); } } - public @Override void save(ServiceInfo service) { + @Override + public void save(ServiceInfo service) { validate(service); facade.save(service); @@ -446,7 +449,8 @@ void validate(ServiceInfo service) { CatalogImpl.validateKeywords(service.getKeywords()); } - public @Override void fireServiceModified( + @Override + public void fireServiceModified( ServiceInfo service, List changed, List oldValues, @@ -456,10 +460,7 @@ void validate(ServiceInfo service) { try { l.handleServiceChange(service, changed, oldValues, newValues); } catch (Exception e) { - LOGGER.log( - Level.SEVERE, - "Error occurred processing a configuration change listener", - e); + logListenerError(e); } } } @@ -469,10 +470,7 @@ void firePostServiceModified(ServiceInfo service) { try { l.handlePostServiceChange(service); } catch (Exception e) { - LOGGER.log( - Level.SEVERE, - "Error occurred processing a configuration change listener", - e); + logListenerError(e); } } } @@ -482,27 +480,28 @@ void fireServiceRemoved(ServiceInfo service) { try { l.handleServiceRemove(service); } catch (Exception e) { - LOGGER.log( - Level.SEVERE, - "Error occurred processing a configuration change listener", - e); + logListenerError(e); } } } - public @Override void addListener(ConfigurationListener listener) { + @Override + public void addListener(ConfigurationListener listener) { listeners.add(listener); } - public @Override void removeListener(ConfigurationListener listener) { + @Override + public void removeListener(ConfigurationListener listener) { listeners.remove(listener); } - public @Override Collection getListeners() { + @Override + public Collection getListeners() { return listeners; } - public @Override void dispose() { + @Override + public void dispose() { // look for pluggable handlers for (GeoServerLifecycleHandler handler : GeoServerExtensions.extensions(GeoServerLifecycleHandler.class)) { @@ -522,11 +521,13 @@ void fireServiceRemoved(ServiceInfo service) { if (facade != null) facade.dispose(); } - public @Override void reload() throws Exception { + @Override + public void reload() throws Exception { this.reload(null); } - public @Override void reload(Catalog newCatalog) throws Exception { + @Override + public void reload(Catalog newCatalog) throws Exception { // notify start of reload List handlers = GeoServerExtensions.extensions(GeoServerLifecycleHandler.class); @@ -556,8 +557,8 @@ void fireServiceRemoved(ServiceInfo service) { // reload catalog, make sure we reload the underlying catalog, not any wrappers Catalog catalog = getCatalog(); - if (catalog instanceof Wrapper) { - catalog = ((Wrapper) getCatalog()).unwrap(Catalog.class); + if (catalog instanceof Wrapper catalogWrapper) { + catalog = catalogWrapper.unwrap(Catalog.class); } ((CatalogImpl) catalog).sync((CatalogImpl) newCatalog); @@ -581,7 +582,8 @@ void fireServiceRemoved(ServiceInfo service) { } } - public @Override void reset() { + @Override + public void reset() { // drop all the catalog store/feature types/raster caches catalog.getResourcePool().dispose(); @@ -601,4 +603,8 @@ void fireServiceRemoved(ServiceInfo service) { } } } + + private void logListenerError(Exception e) { + LOGGER.log(Level.SEVERE, "Error occurred processing a configuration change listener", e); + } } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/MemoryConfigRepository.java b/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/MemoryConfigRepository.java index d4476c6ca..f94d0ddc1 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/MemoryConfigRepository.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/MemoryConfigRepository.java @@ -31,7 +31,8 @@ public class MemoryConfigRepository implements ConfigRepository { protected final ConcurrentMap settings = new ConcurrentHashMap<>(); protected final ConcurrentMap services = new ConcurrentHashMap<>(); - public @Override Optional getGlobal() { + @Override + public Optional getGlobal() { return Optional.ofNullable(global); } @@ -42,17 +43,20 @@ private static void checkNotAProxy(Info value) { } } - public @Override void setGlobal(GeoServerInfo global) { + @Override + public void setGlobal(GeoServerInfo global) { requireNonNull(global); checkNotAProxy(global); this.global = global; } - public @Override Optional getSettingsById(String id) { + @Override + public Optional getSettingsById(String id) { return Optional.ofNullable(settings.get(id)); } - public @Override Optional getSettingsByWorkspace(WorkspaceInfo workspace) { + @Override + public Optional getSettingsByWorkspace(WorkspaceInfo workspace) { requireNonNull(workspace); requireNonNull(workspace.getId()); return settings.values().stream() @@ -60,14 +64,16 @@ private static void checkNotAProxy(Info value) { .findFirst(); } - public @Override void add(SettingsInfo settings) { + @Override + public void add(SettingsInfo settings) { requireNonNull(settings); requireNonNull(settings.getId()); checkNotAProxy(settings); this.settings.put(settings.getId(), settings); } - public @Override SettingsInfo update(SettingsInfo settings, Patch patch) { + @Override + public SettingsInfo update(SettingsInfo settings, Patch patch) { requireNonNull(settings); requireNonNull(patch); requireNonNull(settings.getId()); @@ -81,23 +87,27 @@ private static void checkNotAProxy(Info value) { return localCopy; } - public @Override void remove(SettingsInfo settings) { + @Override + public void remove(SettingsInfo settings) { requireNonNull(settings); requireNonNull(settings.getId()); this.settings.remove(settings.getId()); } - public @Override Optional getLogging() { + @Override + public Optional getLogging() { return Optional.ofNullable(logging); } - public @Override void setLogging(LoggingInfo logging) { + @Override + public void setLogging(LoggingInfo logging) { requireNonNull(logging); checkNotAProxy(logging); this.logging = logging; } - public @Override void add(ServiceInfo service) { + @Override + public void add(ServiceInfo service) { requireNonNull(service); requireNonNull(service.getId()); checkNotAProxy(service); @@ -105,13 +115,15 @@ private static void checkNotAProxy(Info value) { this.services.put(service.getId(), service); } - public @Override void remove(ServiceInfo service) { + @Override + public void remove(ServiceInfo service) { requireNonNull(service); requireNonNull(service.getId()); this.services.remove(service.getId()); } - public @Override S update(S service, Patch patch) { + @Override + public S update(S service, Patch patch) { requireNonNull(service); requireNonNull(service.getId()); checkNotAProxy(service); @@ -125,11 +137,13 @@ private static void checkNotAProxy(Info value) { return localCopy; } - public @Override Stream getGlobalServices() { + @Override + public Stream getGlobalServices() { return this.services.values().stream().filter(s -> s.getWorkspace() == null); } - public @Override Stream getServicesByWorkspace(WorkspaceInfo workspace) { + @Override + public Stream getServicesByWorkspace(WorkspaceInfo workspace) { requireNonNull(workspace); requireNonNull(workspace.getId()); return this.services.values().stream() @@ -139,7 +153,8 @@ private static void checkNotAProxy(Info value) { && workspace.getId().equals(s.getWorkspace().getId())); } - public @Override Optional getGlobalService(Class clazz) { + @Override + public Optional getGlobalService(Class clazz) { requireNonNull(clazz); return this.services.values().stream() .filter(clazz::isInstance) @@ -148,7 +163,8 @@ private static void checkNotAProxy(Info value) { .findFirst(); } - public @Override Optional getServiceByWorkspace( + @Override + public Optional getServiceByWorkspace( WorkspaceInfo workspace, Class clazz) { requireNonNull(workspace); requireNonNull(workspace.getId()); @@ -163,15 +179,16 @@ private static void checkNotAProxy(Info value) { .findFirst(); } - public @Override Optional getServiceById(String id, Class clazz) { + @Override + public Optional getServiceById(String id, Class clazz) { requireNonNull(id); requireNonNull(clazz); ServiceInfo service = services.get(id); return clazz.isInstance(service) ? Optional.of(clazz.cast(service)) : Optional.empty(); } - public @Override Optional getServiceByName( - String name, Class clazz) { + @Override + public Optional getServiceByName(String name, Class clazz) { requireNonNull(name); requireNonNull(clazz); return this.services.values().stream() @@ -181,7 +198,8 @@ private static void checkNotAProxy(Info value) { .findFirst(); } - public @Override Optional getServiceByNameAndWorkspace( + @Override + public Optional getServiceByNameAndWorkspace( String name, WorkspaceInfo workspace, Class clazz) { requireNonNull(name); requireNonNull(workspace); @@ -198,7 +216,8 @@ private static void checkNotAProxy(Info value) { .findFirst(); } - public @Override void dispose() { + @Override + public void dispose() { global = null; logging = null; settings.clear(); diff --git a/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/RepositoryGeoServerFacadeImpl.java b/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/RepositoryGeoServerFacadeImpl.java index 7ce8d3f28..7bc018cfa 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/RepositoryGeoServerFacadeImpl.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/RepositoryGeoServerFacadeImpl.java @@ -33,7 +33,6 @@ import java.util.Optional; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import javax.annotation.Nullable; @@ -61,30 +60,36 @@ public RepositoryGeoServerFacadeImpl(ConfigRepository repository) { this.repository = repository; } - public @Override void setRepository(ConfigRepository repository) { + @Override + public void setRepository(ConfigRepository repository) { requireNonNull(repository); this.repository = repository; } - public @Override void setGeoServer(GeoServer geoServer) { + @Override + public void setGeoServer(GeoServer geoServer) { this.geoServer = geoServer; } - public @Override GeoServer getGeoServer() { + @Override + public GeoServer getGeoServer() { return geoServer; } - public @Override GeoServerInfo getGlobal() { + @Override + public GeoServerInfo getGlobal() { return wrap(resolve(repository.getGlobal().orElse(null)), GeoServerInfo.class); } - public @Override void setGlobal(GeoServerInfo global) { + @Override + public void setGlobal(GeoServerInfo global) { resolve(global); setId(global.getSettings()); repository.setGlobal(global); } - public @Override void save(GeoServerInfo global) { + @Override + public void save(GeoServerInfo global) { ModificationProxy proxy = (ModificationProxy) Proxy.getInvocationHandler(global); PropertyDiff diff = PropertyDiff.valueOf(proxy); @@ -98,20 +103,23 @@ public RepositoryGeoServerFacadeImpl(ConfigRepository repository) { repository.setGlobal(unwrap(global)); } - public @Override SettingsInfo getSettings(WorkspaceInfo workspace) { + @Override + public SettingsInfo getSettings(WorkspaceInfo workspace) { requireNonNull(workspace); return wrap( resolve(repository.getSettingsByWorkspace(workspace).orElse(null)), SettingsInfo.class); } - public @Override void add(SettingsInfo s) { + @Override + public void add(SettingsInfo s) { s = unwrap(s); setId(s); repository.add(s); } - public @Override void save(SettingsInfo settings) { + @Override + public void save(SettingsInfo settings) { ModificationProxy proxy = (ModificationProxy) Proxy.getInvocationHandler(settings); PropertyDiff diff = PropertyDiff.valueOf(proxy); @@ -128,21 +136,25 @@ public RepositoryGeoServerFacadeImpl(ConfigRepository repository) { proxy.commit(); } - public @Override void remove(SettingsInfo s) { + @Override + public void remove(SettingsInfo s) { s = unwrap(s); repository.remove(s); } - public @Override LoggingInfo getLogging() { + @Override + public LoggingInfo getLogging() { return wrap(repository.getLogging().orElse(null), LoggingInfo.class); } - public @Override void setLogging(LoggingInfo logging) { + @Override + public void setLogging(LoggingInfo logging) { requireNonNull(logging); repository.setLogging(logging); } - public @Override void save(LoggingInfo logging) { + @Override + public void save(LoggingInfo logging) { ModificationProxy proxy = (ModificationProxy) Proxy.getInvocationHandler(logging); PropertyDiff diff = PropertyDiff.valueOf(proxy); @@ -156,7 +168,8 @@ public RepositoryGeoServerFacadeImpl(ConfigRepository repository) { repository.setLogging(unwrap(logging)); } - public @Override void add(ServiceInfo service) { + @Override + public void add(ServiceInfo service) { // may be adding a proxy, need to unwrap service = unwrap(service); setId(service); @@ -165,7 +178,8 @@ public RepositoryGeoServerFacadeImpl(ConfigRepository repository) { repository.add(service); } - public @Override void save(ServiceInfo service) { + @Override + public void save(ServiceInfo service) { ModificationProxy proxy = ModificationProxy.handler(service); PropertyDiff diff = PropertyDiff.valueOf(proxy); @@ -180,19 +194,23 @@ public RepositoryGeoServerFacadeImpl(ConfigRepository repository) { proxy.commit(); } - public @Override void remove(ServiceInfo service) { + @Override + public void remove(ServiceInfo service) { repository.remove(service); } - public @Override T getService(Class clazz) { + @Override + public T getService(Class clazz) { return find(clazz, null); } - public @Override T getService(WorkspaceInfo workspace, Class clazz) { + @Override + public T getService(WorkspaceInfo workspace, Class clazz) { return find(clazz, workspace); } - public @Override T getService(String id, Class type) { + @Override + public T getService(String id, Class type) { requireNonNull(id); requireNonNull(type); Optional service = repository.getServiceById(id, type); @@ -202,31 +220,32 @@ public RepositoryGeoServerFacadeImpl(ConfigRepository repository) { return wrap(resolve(service.orElse(null)), type); } - public @Override T getServiceByName(String name, Class clazz) { + @Override + public T getServiceByName(String name, Class clazz) { return findByName(name, null, clazz); } - public @Override T getServiceByName( + @Override + public T getServiceByName( String name, WorkspaceInfo workspace, Class clazz) { return findByName(name, workspace, clazz); } - public @Override Collection getServices() { - List all = - repository.getGlobalServices().map(this::resolve).collect(Collectors.toList()); + @Override + public Collection getServices() { + List all = repository.getGlobalServices().map(this::resolve).toList(); return ModificationProxy.createList(all, ServiceInfo.class); } - public @Override Collection getServices(WorkspaceInfo workspace) { + @Override + public Collection getServices(WorkspaceInfo workspace) { List services = - repository - .getServicesByWorkspace(workspace) - .map(this::resolve) - .collect(Collectors.toList()); + repository.getServicesByWorkspace(workspace).map(this::resolve).toList(); return ModificationProxy.createList(services, ServiceInfo.class); } - public @Override void dispose() { + @Override + public void dispose() { repository.dispose(); } @@ -245,7 +264,7 @@ protected GeoServerInfo resolve(GeoServerInfo info) { global.setMetadata(new MetadataMap()); } if (global.getClientProperties() == null) { - global.setClientProperties(new HashMap()); + global.setClientProperties(new HashMap<>()); } if (global.getCoverageAccess() == null) { global.setCoverageAccess(new CoverageAccessInfoImpl()); @@ -263,7 +282,9 @@ protected T find(Class type, @Nullable WorkspaceInfo service = repository.getServiceByWorkspace(workspace, type); } if (service.isEmpty() && LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine("Could not locate service of type " + type + " in workspace " + workspace); + LOGGER.fine( + "Could not locate service of type %s in workspace %s" + .formatted(type, workspace)); } return wrap(resolve(service.orElse(null)), type); @@ -280,13 +301,8 @@ protected T findByName( } if (service.isEmpty() && LOGGER.isLoggable(Level.FINE)) { LOGGER.fine( - "Could not locate service of type " - + type - + " in workspace " - + workspace - + " and name '" - + name - + "'"); + "Could not locate service of type %s in workspace %s and name '%s'" + .formatted(type, workspace, name)); } return wrap(resolve(service.orElse(null)), type); } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/forwarding/ForwardingGeoServerFacade.java b/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/forwarding/ForwardingGeoServerFacade.java index 49ac66e00..3d4768457 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/forwarding/ForwardingGeoServerFacade.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/config/plugin/forwarding/ForwardingGeoServerFacade.java @@ -34,110 +34,134 @@ public GeoServerFacade getSubject() { return facade; } - public @Override void setRepository(ConfigRepository repository) { - if (facade instanceof RepositoryGeoServerFacade) - ((RepositoryGeoServerFacade) facade).setRepository(repository); + @Override + public void setRepository(ConfigRepository repository) { + if (facade instanceof RepositoryGeoServerFacade repoFacade) + repoFacade.setRepository(repository); throw new IllegalStateException( "subject GeoServerFacade is not a RepositoryGeoServerFacade"); } - public @Override GeoServer getGeoServer() { + @Override + public GeoServer getGeoServer() { return facade.getGeoServer(); } - public @Override void setGeoServer(GeoServer geoServer) { + @Override + public void setGeoServer(GeoServer geoServer) { facade.setGeoServer(geoServer); } - public @Override GeoServerInfo getGlobal() { + @Override + public GeoServerInfo getGlobal() { return facade.getGlobal(); } - public @Override void setGlobal(GeoServerInfo global) { + @Override + public void setGlobal(GeoServerInfo global) { facade.setGlobal(global); } - public @Override void save(GeoServerInfo geoServer) { + @Override + public void save(GeoServerInfo geoServer) { facade.save(geoServer); } - public @Override SettingsInfo getSettings(WorkspaceInfo workspace) { + @Override + public SettingsInfo getSettings(WorkspaceInfo workspace) { return facade.getSettings(workspace); } - public @Override void add(SettingsInfo settings) { + @Override + public void add(SettingsInfo settings) { facade.add(settings); } - public @Override void save(SettingsInfo settings) { + @Override + public void save(SettingsInfo settings) { facade.save(settings); } - public @Override void remove(SettingsInfo settings) { + @Override + public void remove(SettingsInfo settings) { facade.remove(settings); } - public @Override LoggingInfo getLogging() { + @Override + public LoggingInfo getLogging() { return facade.getLogging(); } - public @Override void setLogging(LoggingInfo logging) { + @Override + public void setLogging(LoggingInfo logging) { facade.setLogging(logging); } - public @Override void save(LoggingInfo logging) { + @Override + public void save(LoggingInfo logging) { facade.save(logging); } - public @Override void add(ServiceInfo service) { + @Override + public void add(ServiceInfo service) { facade.add(service); } - public @Override void remove(ServiceInfo service) { + @Override + public void remove(ServiceInfo service) { facade.remove(service); } - public @Override void save(ServiceInfo service) { + @Override + public void save(ServiceInfo service) { facade.save(service); } - public @Override Collection getServices() { + @Override + public Collection getServices() { return facade.getServices(); } - public @Override Collection getServices(WorkspaceInfo workspace) { + @Override + public Collection getServices(WorkspaceInfo workspace) { return facade.getServices(workspace); } - public @Override T getService(Class clazz) { + @Override + public T getService(Class clazz) { return facade.getService(clazz); } - public @Override T getService(WorkspaceInfo workspace, Class clazz) { + @Override + public T getService(WorkspaceInfo workspace, Class clazz) { return facade.getService(workspace, clazz); } - public @Override T getService(String id, Class clazz) { + @Override + public T getService(String id, Class clazz) { return facade.getService(id, clazz); } - public @Override T getServiceByName(String name, Class clazz) { + @Override + public T getServiceByName(String name, Class clazz) { return facade.getServiceByName(name, clazz); } - public @Override T getServiceByName( + @Override + public T getServiceByName( String name, WorkspaceInfo workspace, Class clazz) { return facade.getServiceByName(name, workspace, clazz); } - public @Override void dispose() { + @Override + public void dispose() { facade.dispose(); } - public @Override SettingsInfo getSettings(String id) { - if (facade instanceof RepositoryGeoServerFacade) - ((RepositoryGeoServerFacade) facade).getSettings(id); + @Override + public SettingsInfo getSettings(String id) { + if (facade instanceof RepositoryGeoServerFacade repoFacade) repoFacade.getSettings(id); throw new UnsupportedOperationException(); } diff --git a/src/catalog/plugin/src/main/java/org/geoserver/platform/config/DefaultUpdateSequence.java b/src/catalog/plugin/src/main/java/org/geoserver/platform/config/DefaultUpdateSequence.java index b75babf54..76f7f22aa 100644 --- a/src/catalog/plugin/src/main/java/org/geoserver/platform/config/DefaultUpdateSequence.java +++ b/src/catalog/plugin/src/main/java/org/geoserver/platform/config/DefaultUpdateSequence.java @@ -36,11 +36,13 @@ public DefaultUpdateSequence(@NonNull GeoServer gs) { .orElse(0L)); } - public @Override long currValue() { + @Override + public long currValue() { return info().map(GeoServerInfo::getUpdateSequence).orElse(0L); } - public @Override long nextValue() { + @Override + public long nextValue() { lock.lock(); try { GeoServerInfo global = info().orElse(null); diff --git a/src/catalog/plugin/src/test/java/org/geoserver/catalog/CatalogTestData.java b/src/catalog/plugin/src/test/java/org/geoserver/catalog/CatalogTestData.java index e085e24d0..a04d16112 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/catalog/CatalogTestData.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/catalog/CatalogTestData.java @@ -46,7 +46,6 @@ import java.util.Map; import java.util.function.Consumer; import java.util.function.Supplier; -import java.util.stream.Collectors; /** * Provides or populates a catalog; use {@link CatalogTestData#empty @@ -529,8 +528,7 @@ public FeatureTypeInfo createFeatureType( public void assertEqualsLenientConnectionParameters(Info info1, Info info2) { if (info1 != null && info2 != null) { - if (info1 instanceof DataStoreInfo) { - DataStoreInfo ds1 = (DataStoreInfo) info1; + if (info1 instanceof DataStoreInfo ds1) { DataStoreInfo ds2 = (DataStoreInfo) info2; Map p1 = new HashMap<>(ds1.getConnectionParameters()); Map p2 = new HashMap<>(ds2.getConnectionParameters()); @@ -553,7 +551,7 @@ public void assertInternationalStringPropertiesEqual(Info info1, Info info2) { List istringProps = props.properties().stream() .filter(p -> props.getter(p, InternationalString.class) != null) - .collect(Collectors.toList()); + .toList(); for (String isp : istringProps) { InternationalString i1 = (InternationalString) OwsUtils.get(info1, isp); InternationalString i2 = (InternationalString) OwsUtils.get(info2, isp); diff --git a/src/catalog/plugin/src/test/java/org/geoserver/catalog/faker/CatalogFaker.java b/src/catalog/plugin/src/test/java/org/geoserver/catalog/faker/CatalogFaker.java index 3ab5c05d0..c4dd9fe31 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/catalog/faker/CatalogFaker.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/catalog/faker/CatalogFaker.java @@ -92,7 +92,6 @@ import java.util.Locale; import java.util.Objects; import java.util.function.Supplier; -import java.util.stream.Collectors; import java.util.stream.IntStream; @Accessors(fluent = true) @@ -566,9 +565,7 @@ public AuthorityURLInfo authorityURLInfo() { } public List authUrls(int count) { - return IntStream.range(0, count) - .mapToObj(i -> this.authorityURLInfo()) - .collect(Collectors.toList()); + return IntStream.range(0, count).mapToObj(i -> this.authorityURLInfo()).toList(); } public InternationalString internationalString(String val) { diff --git a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/CatalogConformanceTest.java b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/CatalogConformanceTest.java index cda4d5983..fddb108ae 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/CatalogConformanceTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/CatalogConformanceTest.java @@ -283,7 +283,7 @@ protected LayerGroupInfo addLayerGroup() { } @Test - public void testAddNamespace() { + void testAddNamespace() { assertTrue(catalog.getNamespaces().isEmpty()); catalog.add(data.namespaceA); assertEquals(1, catalog.getNamespaces().size()); @@ -322,7 +322,7 @@ public void testAddNamespace() { } @Test - public void testAddIsolatedNamespace() { + void testAddIsolatedNamespace() { // create non isolated namespace NamespaceInfoImpl namespace1 = new NamespaceInfoImpl(); namespace1.setPrefix("isolated_namespace_1"); @@ -366,7 +366,7 @@ public void testAddIsolatedNamespace() { } @Test - public void testRemoveNamespace() { + void testRemoveNamespace() { catalog.add(data.namespaceA); assertEquals(1, catalog.getNamespaces().size()); @@ -381,7 +381,7 @@ public void testRemoveNamespace() { } @Test - public void testGetNamespaceById() { + void testGetNamespaceById() { catalog.add(data.namespaceA); NamespaceInfo ns2 = catalog.getNamespace(data.namespaceA.getId()); @@ -391,7 +391,7 @@ public void testGetNamespaceById() { } @Test - public void testGetNamespaceByPrefix() { + void testGetNamespaceByPrefix() { catalog.add(data.namespaceA); NamespaceInfo ns2 = catalog.getNamespaceByPrefix(data.namespaceA.getPrefix()); @@ -411,7 +411,7 @@ public void testGetNamespaceByPrefix() { } @Test - public void testGetNamespaceByURI() { + void testGetNamespaceByURI() { catalog.add(data.namespaceA); NamespaceInfo ns2 = catalog.getNamespaceByURI(data.namespaceA.getURI()); @@ -421,7 +421,7 @@ public void testGetNamespaceByURI() { } @Test - public void testSetDefaultNamespaceInvalid() { + void testSetDefaultNamespaceInvalid() { try { catalog.setDefaultNamespace(data.namespaceA); fail("Default namespace must exist in catalog"); @@ -431,7 +431,7 @@ public void testSetDefaultNamespaceInvalid() { } @Test - public void testModifyNamespace() { + void testModifyNamespace() { catalog.add(data.namespaceA); NamespaceInfo ns2 = catalog.getNamespaceByPrefix(data.namespaceA.getPrefix()); @@ -466,7 +466,7 @@ public void testModifyNamespace() { } @Test - public void testNamespaceEvents() { + void testNamespaceEvents() { TestListener l = new TestListener(); catalog.addListener(l); @@ -508,7 +508,7 @@ public void testNamespaceEvents() { } @Test - public void testAddWorkspace() { + void testAddWorkspace() { assertTrue(catalog.getWorkspaces().isEmpty()); catalog.add(data.workspaceA); assertEquals(1, catalog.getWorkspaces().size()); @@ -532,7 +532,7 @@ public void testAddWorkspace() { } @Test - public void testRemoveWorkspace() { + void testRemoveWorkspace() { catalog.add(data.workspaceA); assertEquals(1, catalog.getWorkspaces().size()); @@ -547,7 +547,7 @@ public void testRemoveWorkspace() { } @Test - public void testAddIsolatedWorkspace() { + void testAddIsolatedWorkspace() { // create isolated workspace WorkspaceInfoImpl workspace = new WorkspaceInfoImpl(); workspace.setName("isolated_workspace"); @@ -565,7 +565,7 @@ public void testAddIsolatedWorkspace() { } @Test - public void testAutoSetDefaultWorkspace() { + void testAutoSetDefaultWorkspace() { catalog.add(data.workspaceA); assertEquals(1, catalog.getWorkspaces().size()); assertEquals(data.workspaceA, catalog.getDefaultWorkspace()); @@ -573,7 +573,7 @@ public void testAutoSetDefaultWorkspace() { } @Test - public void testRemoveDefaultWorkspace() { + void testRemoveDefaultWorkspace() { catalog.add(data.workspaceA); assertNotNull(catalog.getDefaultWorkspace()); catalog.remove(data.workspaceA); @@ -581,7 +581,7 @@ public void testRemoveDefaultWorkspace() { } @Test - public void testAutoCascadeDefaultWorksapce() { + void testAutoCascadeDefaultWorksapce() { CatalogFactory factory = catalog.getFactory(); WorkspaceInfo ws1 = factory.createWorkspace(); ws1.setName("ws1Name"); @@ -595,21 +595,21 @@ public void testAutoCascadeDefaultWorksapce() { } @Test - public void testAutoSetDefaultNamespace() { + void testAutoSetDefaultNamespace() { catalog.add(data.namespaceA); assertEquals(1, catalog.getNamespaces().size()); assertEquals(data.namespaceA, catalog.getDefaultNamespace()); } @Test - public void testRemoveDefaultNamespace() { + void testRemoveDefaultNamespace() { catalog.add(data.namespaceA); catalog.remove(data.namespaceA); assertNull(catalog.getDefaultNamespace()); } @Test - public void testAutoCascadeDefaultNamespace() { + void testAutoCascadeDefaultNamespace() { CatalogFactory factory = catalog.getFactory(); NamespaceInfo ns1 = factory.createNamespace(); ns1.setPrefix("1"); @@ -625,7 +625,7 @@ public void testAutoCascadeDefaultNamespace() { } @Test - public void testAutoSetDefaultStore() { + void testAutoSetDefaultStore() { catalog.add(data.workspaceA); catalog.add(data.dataStoreA); assertEquals(1, catalog.getDataStores().size()); @@ -633,7 +633,7 @@ public void testAutoSetDefaultStore() { } @Test - public void testRemoveDefaultStore() { + void testRemoveDefaultStore() { catalog.add(data.workspaceA); catalog.add(data.dataStoreA); catalog.remove(data.dataStoreA); @@ -641,7 +641,7 @@ public void testRemoveDefaultStore() { } @Test - public void testGetWorkspaceById() { + void testGetWorkspaceById() { catalog.add(data.workspaceA); WorkspaceInfo ws2 = catalog.getWorkspace(data.workspaceA.getId()); @@ -651,7 +651,7 @@ public void testGetWorkspaceById() { } @Test - public void testGetWorkspaceByName() { + void testGetWorkspaceByName() { catalog.add(data.workspaceA); WorkspaceInfo ws2 = catalog.getWorkspaceByName(data.workspaceA.getName()); @@ -671,7 +671,7 @@ public void testGetWorkspaceByName() { } @Test - public void testSetDefaultWorkspaceInvalid() { + void testSetDefaultWorkspaceInvalid() { try { catalog.setDefaultWorkspace(data.workspaceA); fail("Default workspace must exist in catalog"); @@ -681,7 +681,7 @@ public void testSetDefaultWorkspaceInvalid() { } @Test - public void testModifyWorkspace() { + void testModifyWorkspace() { catalog.add(data.workspaceA); WorkspaceInfo ws2 = catalog.getWorkspaceByName(data.workspaceA.getName()); @@ -704,7 +704,7 @@ public void testModifyWorkspace() { } @Test - public void testWorkspaceEvents() { + void testWorkspaceEvents() { TestListener l = new TestListener(); catalog.addListener(l); @@ -740,7 +740,7 @@ public void testWorkspaceEvents() { } @Test - public void testAddDataStore() { + void testAddDataStore() { assertTrue(catalog.getDataStores().isEmpty()); data.dataStoreA.setWorkspace(null); @@ -781,7 +781,7 @@ public void testAddDataStore() { } @Test - public void testAddDataStoreDefaultWorkspace() { + void testAddDataStoreDefaultWorkspace() { catalog.add(data.workspaceA); catalog.setDefaultWorkspace(data.workspaceA); @@ -793,7 +793,7 @@ public void testAddDataStoreDefaultWorkspace() { } @Test - public void testRemoveDataStore() { + void testRemoveDataStore() { addDataStore(); assertEquals(1, catalog.getDataStores().size()); @@ -808,7 +808,7 @@ public void testRemoveDataStore() { } @Test - public void testGetDataStoreById() { + void testGetDataStoreById() { addDataStore(); DataStoreInfo ds2 = catalog.getDataStore(data.dataStoreA.getId()); @@ -819,7 +819,7 @@ public void testGetDataStoreById() { } @Test - public void testGetDataStoreByName() { + void testGetDataStoreByName() { addDataStore(); DataStoreInfo ds2 = catalog.getDataStoreByName(data.dataStoreA.getName()); @@ -845,7 +845,7 @@ public void testGetDataStoreByName() { } @Test - public void testGetStoreByName() { + void testGetStoreByName() { addDataStore(); StoreInfo ds2 = catalog.getStoreByName(data.dataStoreA.getName(), StoreInfo.class); @@ -881,7 +881,7 @@ public void testGetStoreByName() { } @Test - public void testModifyDataStore() { + void testModifyDataStore() { addDataStore(); DataStoreInfo ds2 = catalog.getDataStoreByName(data.dataStoreA.getName()); @@ -900,13 +900,13 @@ public void testModifyDataStore() { } @Test - public void testChangeDataStoreWorkspace_no_resources() throws Exception { + void testChangeDataStoreWorkspace_no_resources() throws Exception { addDataStore(); testChangeStoreWorkspace(data.dataStoreA); } @Test - public void testChangeDataStoreWorkspaceUpdatesResourcesNamespace() throws Exception { + void testChangeDataStoreWorkspaceUpdatesResourcesNamespace() throws Exception { addFeatureType(); DataStoreInfo store = data.dataStoreA; StoreInfo updated = testChangeStoreWorkspace(store); @@ -914,7 +914,7 @@ public void testChangeDataStoreWorkspaceUpdatesResourcesNamespace() throws Excep } @Test - public void testChangeCoverageStoreWorkspaceUpdatesResourcesNamespace() throws Exception { + void testChangeCoverageStoreWorkspaceUpdatesResourcesNamespace() throws Exception { addCoverage(); StoreInfo store = data.coverageStoreA; StoreInfo updated = testChangeStoreWorkspace(store); @@ -922,7 +922,7 @@ public void testChangeCoverageStoreWorkspaceUpdatesResourcesNamespace() throws E } @Test - public void testChangeWMSStoreWorkspaceUpdatesResourcesNamespace() throws Exception { + void testChangeWMSStoreWorkspaceUpdatesResourcesNamespace() throws Exception { addWMSLayer(); StoreInfo store = data.wmsStoreA; StoreInfo updated = testChangeStoreWorkspace(store); @@ -930,7 +930,7 @@ public void testChangeWMSStoreWorkspaceUpdatesResourcesNamespace() throws Except } @Test - public void testChangeWTMSStoreWorkspaceUpdatesResourcesNamespace() throws Exception { + void testChangeWTMSStoreWorkspaceUpdatesResourcesNamespace() throws Exception { addWMTSLayer(); StoreInfo store = data.wmtsStoreA; StoreInfo updated = testChangeStoreWorkspace(store); @@ -938,7 +938,7 @@ public void testChangeWTMSStoreWorkspaceUpdatesResourcesNamespace() throws Excep } @Test - public void testChangeDataStoreWorkspace_fails_on_no_matching_namespace() throws Exception { + void testChangeDataStoreWorkspace_fails_on_no_matching_namespace() throws Exception { addDataStore(); WorkspaceInfo ws2 = addWorkspace("newWorkspace"); @@ -956,8 +956,7 @@ public void testChangeDataStoreWorkspace_fails_on_no_matching_namespace() throws } @Test - public void testSaveDataStoreRollbacksStoreWhenFailsToUpdateResourcesNamespace() - throws Exception { + void testSaveDataStoreRollbacksStoreWhenFailsToUpdateResourcesNamespace() throws Exception { Assumptions.assumeTrue(catalog instanceof CatalogPlugin); addFeatureType(); @@ -995,7 +994,7 @@ public void testSaveDataStoreRollbacksStoreWhenFailsToUpdateResourcesNamespace() } @Test - public void testSaveDataStoreRollbacksBothStoreAndResources() throws Exception { + protected void testSaveDataStoreRollbacksBothStoreAndResources() throws Exception { Assumptions.assumeTrue(catalog instanceof CatalogPlugin); addFeatureType(); @@ -1077,7 +1076,7 @@ private void verifyNamespaceOfStoreResources(StoreInfo store) { } @Test - public void testDataStoreEvents() { + void testDataStoreEvents() { addWorkspace(); TestListener l = new TestListener(); @@ -1129,7 +1128,7 @@ public void testDataStoreEvents() { } @Test - public void testAddFeatureType() { + void testAddFeatureType() { assertTrue(catalog.getFeatureTypes().isEmpty()); addFeatureType(); @@ -1167,7 +1166,7 @@ public void testAddFeatureType() { } @Test - public void testAddCoverage() { + void testAddCoverage() { // set a default namespace assertNotNull(catalog.getCoverages()); assertTrue(catalog.getCoverages().isEmpty()); @@ -1209,7 +1208,7 @@ public void testAddCoverage() { } @Test - public void testAddWMSLayer() { + void testAddWMSLayer() { // set a default namespace assertTrue(catalog.getResources(WMSLayerInfo.class).isEmpty()); addWMSLayer(); @@ -1217,14 +1216,14 @@ public void testAddWMSLayer() { } @Test - public void testAddWMTSLayer() { + void testAddWMTSLayer() { assertTrue(catalog.getResources(WMTSLayerInfo.class).isEmpty()); addWMTSLayer(); assertEquals(1, catalog.getResources(WMTSLayerInfo.class).size()); } @Test - public void testRemoveFeatureType() { + void testRemoveFeatureType() { addFeatureType(); assertFalse(catalog.getFeatureTypes().isEmpty()); @@ -1239,7 +1238,7 @@ public void testRemoveFeatureType() { } @Test - public void testRemoveWMSLayer() { + void testRemoveWMSLayer() { addWMSLayer(); assertFalse(catalog.getResources(WMSLayerInfo.class).isEmpty()); @@ -1248,7 +1247,7 @@ public void testRemoveWMSLayer() { } @Test - public void testRemoveWMTSLayer() { + void testRemoveWMTSLayer() { addWMTSLayer(); assertFalse(catalog.getResources(WMTSLayerInfo.class).isEmpty()); @@ -1257,7 +1256,7 @@ public void testRemoveWMTSLayer() { } @Test - public void testGetFeatureTypeById() { + void testGetFeatureTypeById() { addFeatureType(); FeatureTypeInfo ft2 = catalog.getFeatureType(data.featureTypeA.getId()); @@ -1268,7 +1267,7 @@ public void testGetFeatureTypeById() { } @Test - public void testGetFeatureTypeByName() { + void testGetFeatureTypeByName() { addFeatureType(); FeatureTypeInfo ft2 = catalog.getFeatureTypeByName(data.featureTypeA.getName()); @@ -1300,7 +1299,7 @@ public void testGetFeatureTypeByName() { } @Test - public void testGetFeatureTypesByStore() { + void testGetFeatureTypesByStore() { catalog.add(data.namespaceA); catalog.add(data.workspaceA); @@ -1343,7 +1342,7 @@ public void testGetFeatureTypesByStore() { } @Test - public void testModifyFeatureType() { + void testModifyFeatureType() { addFeatureType(); FeatureTypeInfo ft2 = catalog.getFeatureTypeByName(data.featureTypeA.getName()); @@ -1363,7 +1362,7 @@ public void testModifyFeatureType() { } @Test - public void testModifyMetadataLinks() { + void testModifyMetadataLinks() { addFeatureType(); FeatureTypeInfo ft2 = catalog.getFeatureTypeByName(data.featureTypeA.getName()); @@ -1392,7 +1391,7 @@ public void testModifyMetadataLinks() { } @Test - public void testModifyDataLinks() { + void testModifyDataLinks() { addFeatureType(); FeatureTypeInfo ft2 = catalog.getFeatureTypeByName(data.featureTypeA.getName()); @@ -1420,7 +1419,7 @@ public void testModifyDataLinks() { } @Test - public void testFeatureTypeEvents() { + void testFeatureTypeEvents() { // set default namespace addNamespace(); addDataStore(); @@ -1461,7 +1460,7 @@ public void testFeatureTypeEvents() { } @Test - public void testModifyMetadata() { + void testModifyMetadata() { // set default namespace addNamespace(); addDataStore(); @@ -1492,7 +1491,7 @@ public void testModifyMetadata() { } @Test - public void testAddLayer() { + void testAddLayer() { assertTrue(catalog.getLayers().isEmpty()); addLayer(); @@ -1533,7 +1532,7 @@ public void testAddLayer() { } @Test - public void testGetLayerById() { + void testGetLayerById() { addLayer(); LayerInfo l2 = catalog.getLayer(data.layerFeatureTypeA.getId()); @@ -1543,12 +1542,11 @@ public void testGetLayerById() { assertSame(catalog, l2.getResource().getCatalog()); StyleInfo defaultStyle = l2.getDefaultStyle(); defaultStyle = ModificationProxy.unwrap(defaultStyle); - if (defaultStyle instanceof StyleInfoImpl) - assertSame(catalog, ((StyleInfoImpl) defaultStyle).getCatalog()); + if (defaultStyle instanceof StyleInfoImpl impl) assertSame(catalog, impl.getCatalog()); } @Test - public void testGetLayerByName() { + void testGetLayerByName() { addLayer(); LayerInfo l2 = catalog.getLayerByName(data.layerFeatureTypeA.getName()); @@ -1558,7 +1556,7 @@ public void testGetLayerByName() { } @Test - public void testGetLayerByNameWithoutColon() { + void testGetLayerByNameWithoutColon() { // create two workspaces catalog.add(data.namespaceB); catalog.add(data.namespaceC); @@ -1648,7 +1646,7 @@ public void testGetLayerByNameWithoutColon() { } @Test - public void testGetLayerByNameWithColon() { + void testGetLayerByNameWithColon() { addNamespace(); addDataStore(); FeatureTypeInfo ft = catalog.getFactory().createFeatureType(); @@ -1673,7 +1671,7 @@ public void testGetLayerByNameWithColon() { } @Test - public void testGetLayerByResource() { + void testGetLayerByResource() { addLayer(); List layers = catalog.getLayers(data.featureTypeA); @@ -1685,7 +1683,7 @@ public void testGetLayerByResource() { } @Test - public void testRemoveLayer() { + void testRemoveLayer() { addLayer(); assertEquals(1, catalog.getLayers().size()); @@ -1694,7 +1692,7 @@ public void testRemoveLayer() { } @Test - public void testRemoveLayerAndAssociatedDataRules() throws IOException { + void testRemoveLayerAndAssociatedDataRules() throws IOException { DataAccessRuleDAO dao = this.dataAccessRuleDAO; CatalogListener listener = new SecuredResourceNameChangeListener(catalog, dao); addLayer(); @@ -1724,7 +1722,7 @@ private boolean layerHasSecurityRule( } @Test - public void testModifyLayer() { + void testModifyLayer() { addLayer(); LayerInfo l2 = catalog.getLayerByName(data.layerFeatureTypeA.getName()); @@ -1757,7 +1755,7 @@ public void testModifyLayer() { } @Test - public void testModifyLayerDefaultStyle() { + void testModifyLayerDefaultStyle() { // create new style CatalogFactory factory = catalog.getFactory(); StyleInfo s2 = factory.createStyle(); @@ -1778,7 +1776,7 @@ public void testModifyLayerDefaultStyle() { } @Test - public void testEnableLayer() { + void testEnableLayer() { addLayer(); LayerInfo l2 = catalog.getLayerByName(data.layerFeatureTypeA.getName()); @@ -1799,7 +1797,7 @@ public void testEnableLayer() { } @Test - public void testLayerEvents() { + void testLayerEvents() { addFeatureType(); addStyle(); @@ -1834,7 +1832,7 @@ public void testLayerEvents() { } @Test - public void testAddStyle() { + void testAddStyle() { assertTrue(catalog.getStyles().isEmpty()); addStyle(); @@ -1866,7 +1864,7 @@ public void testAddStyle() { } @Test - public void testAddStyleWithNameConflict() throws Exception { + void testAddStyleWithNameConflict() throws Exception { addWorkspace(); addStyle(); @@ -1909,7 +1907,7 @@ public void testAddStyleWithNameConflict() throws Exception { } @Test - public void testGetStyleById() { + void testGetStyleById() { addStyle(); StyleInfo s2 = catalog.getStyle(data.style1.getId()); @@ -1919,7 +1917,7 @@ public void testGetStyleById() { } @Test - public void testGetStyleByName() { + void testGetStyleByName() { addStyle(); StyleInfo s2 = catalog.getStyleByName(data.style1.getName()); @@ -1929,7 +1927,7 @@ public void testGetStyleByName() { } @Test - public void testGetStyleByNameWithWorkspace() { + void testGetStyleByNameWithWorkspace() { addWorkspace(); addStyle(); @@ -1950,7 +1948,7 @@ public void testGetStyleByNameWithWorkspace() { } @Test - public void testGetStyleByNameWithWorkspace2() throws Exception { + void testGetStyleByNameWithWorkspace2() throws Exception { addWorkspace(); WorkspaceInfo ws2 = catalog.getFactory().createWorkspace(); @@ -1980,7 +1978,7 @@ public void testGetStyleByNameWithWorkspace2() throws Exception { } @Test - public void testGetStyles() { + void testGetStyles() { addWorkspace(); addStyle(); @@ -2002,7 +2000,7 @@ public void testGetStyles() { } @Test - public void testModifyStyle() { + void testModifyStyle() { addStyle(); StyleInfo s2 = catalog.getStyleByName(data.style1.getName()); @@ -2037,7 +2035,7 @@ public void testModifyStyle() { } @Test - public void testModifyDefaultStyle() { + void testModifyDefaultStyle() { addWorkspace(); addDefaultStyle(); StyleInfo s = catalog.getStyleByName(StyleInfo.DEFAULT_LINE); @@ -2060,7 +2058,7 @@ public void testModifyDefaultStyle() { } @Test - public void testRemoveStyle() { + void testRemoveStyle() { addStyle(); assertEquals(1, catalog.getStyles().size()); @@ -2069,7 +2067,7 @@ public void testRemoveStyle() { } @Test - public void testRemoveDefaultStyle() { + void testRemoveDefaultStyle() { addWorkspace(); addDefaultStyle(); StyleInfo s = catalog.getStyleByName(StyleInfo.DEFAULT_LINE); @@ -2082,7 +2080,7 @@ public void testRemoveDefaultStyle() { } @Test - public void testStyleEvents() { + void testStyleEvents() { TestListener l = new TestListener(); catalog.addListener(l); @@ -2115,7 +2113,7 @@ public void testStyleEvents() { } @Test - public void testProxyBehaviour() throws Exception { + void testProxyBehaviour() throws Exception { testAddLayer(); // l = catalog.getLayerByName( "layerName"); @@ -2136,7 +2134,7 @@ public void testProxyBehaviour() throws Exception { } @Test - public void testProxyListBehaviour() throws Exception { + void testProxyListBehaviour() throws Exception { catalog.add(data.style1); StyleInfo s2 = catalog.getFactory().createStyle(); @@ -2170,7 +2168,7 @@ public int compare(StyleInfo o1, StyleInfo o2) { } @Test - public void testExceptionThrowingListener() throws Exception { + void testExceptionThrowingListener() throws Exception { ExceptionThrowingListener l = new ExceptionThrowingListener(); catalog.addListener(l); @@ -2195,7 +2193,7 @@ public void testExceptionThrowingListener() throws Exception { } @Test - public void testAddWMSStore() { + void testAddWMSStore() { assertTrue(catalog.getStores(WMSStoreInfo.class).isEmpty()); addWMSStore(); assertEquals(1, catalog.getStores(WMSStoreInfo.class).size()); @@ -2213,7 +2211,7 @@ public void testAddWMSStore() { } @Test - public void testAddWMTSStore() { + void testAddWMTSStore() { assertTrue(catalog.getStores(WMTSStoreInfo.class).isEmpty()); addWMTSStore(); assertEquals(1, catalog.getStores(WMTSStoreInfo.class).size()); @@ -2280,7 +2278,7 @@ public void testGetLayerByIdWithConcurrentAdd() throws Exception { } @Test - public void testAddLayerGroupNameConflict() throws Exception { + void testAddLayerGroupNameConflict() throws Exception { addLayerGroup(); LayerGroupInfo lg2 = catalog.getFactory().createLayerGroup(); @@ -2300,7 +2298,7 @@ public void testAddLayerGroupNameConflict() throws Exception { } @Test - public void testAddLayerGroupWithWorkspaceWithResourceFromAnotherWorkspace() { + void testAddLayerGroupWithWorkspaceWithResourceFromAnotherWorkspace() { WorkspaceInfo ws = catalog.getFactory().createWorkspace(); ws.setName("other"); catalog.add(ws); @@ -2318,7 +2316,7 @@ public void testAddLayerGroupWithWorkspaceWithResourceFromAnotherWorkspace() { } @Test - public void testGetLayerGroupByName() { + void testGetLayerGroupByName() { addLayerGroup(); assertNotNull(catalog.getLayerGroupByName("layerGroup")); assertNotNull(catalog.getLayerGroupByName((WorkspaceInfo) null, "layerGroup")); @@ -2353,7 +2351,7 @@ public void testGetLayerGroupByName() { } @Test - public void testRemoveLayerGroupAndAssociatedDataRules() throws IOException { + void testRemoveLayerGroupAndAssociatedDataRules() throws IOException { DataAccessRuleDAO dao = this.dataAccessRuleDAO; CatalogListener listener = new SecuredResourceNameChangeListener(catalog, dao); addLayer(); @@ -2377,7 +2375,7 @@ public void testRemoveLayerGroupAndAssociatedDataRules() throws IOException { } @Test - public void testGetLayerGroupByNameWithColon() { + void testGetLayerGroupByNameWithColon() { addLayer(); CatalogFactory factory = catalog.getFactory(); LayerGroupInfo lg = factory.createLayerGroup(); @@ -2400,7 +2398,7 @@ public void testGetLayerGroupByNameWithColon() { } @Test - public void testGetLayerGroupByNameWithWorkspace() { + void testGetLayerGroupByNameWithWorkspace() { addLayer(); assertEquals(data.workspaceA, catalog.getDefaultWorkspace()); @@ -2473,7 +2471,7 @@ public void testGetLayerGroupByNameWithWorkspace() { } @Test - public void testGetLayerGroups() { + void testGetLayerGroups() { addLayerGroup(); assertEquals(1, catalog.getLayerGroups().size()); assertEquals(0, catalog.getLayerGroupsByWorkspace(data.workspaceA.getName()).size()); @@ -2494,7 +2492,7 @@ public void testGetLayerGroups() { } @Test - public void testLayerGroupTitle() { + void testLayerGroupTitle() { addLayer(); LayerGroupInfo lg2 = catalog.getFactory().createLayerGroup(); // lg2.setWorkspace(catalog.getDefaultWorkspace()); @@ -2517,7 +2515,7 @@ public void testLayerGroupTitle() { } @Test - public void testLayerGroupAbstract() { + void testLayerGroupAbstract() { addLayer(); LayerGroupInfo lg2 = catalog.getFactory().createLayerGroup(); // lg2.setWorkspace(catalog.getDefaultWorkspace()); @@ -2540,7 +2538,7 @@ public void testLayerGroupAbstract() { } @Test - public void testLayerGroupType() { + void testLayerGroupType() { addLayer(); LayerGroupInfo lg2 = catalog.getFactory().createLayerGroup(); lg2.setWorkspace(null); @@ -2563,7 +2561,7 @@ public void testLayerGroupType() { } @Test - public void testLayerGroupRootLayer() { + void testLayerGroupRootLayer() { addLayer(); LayerGroupInfo lg2 = catalog.getFactory().createLayerGroup(); lg2.setWorkspace(null); @@ -2625,7 +2623,7 @@ public void testLayerGroupRootLayer() { } @Test - public void testLayerGroupNullLayerReferences() { + void testLayerGroupNullLayerReferences() { addLayer(); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); lg.setWorkspace(null); @@ -2645,7 +2643,7 @@ public void testLayerGroupNullLayerReferences() { } @Test - public void testLayerGroupRenderingLayers() { + void testLayerGroupRenderingLayers() { addDataStore(); addNamespace(); FeatureTypeInfo ft1, ft2, ft3; @@ -2710,7 +2708,7 @@ public void testLayerGroupRenderingLayers() { } @Test - public void testRemoveLayerGroupInLayerGroup() throws Exception { + void testRemoveLayerGroupInLayerGroup() throws Exception { addLayerGroup(); LayerGroupInfo lg2 = catalog.getFactory().createLayerGroup(); @@ -2809,7 +2807,7 @@ protected void runInternal() throws Exception { ; @Test - public void testGet() { + void testGet() { addDataStore(); addNamespace(); @@ -2903,7 +2901,7 @@ public void testGet() { } @Test - public void testListPredicate() { + void testListPredicate() { addDataStore(); addNamespace(); @@ -2989,7 +2987,7 @@ public void testListPredicate() { * This tests more advanced filters: multi-valued filters, opposite equations, field equations */ @Test - public void testListPredicateExtended() { + void testListPredicateExtended() { addDataStore(); addNamespace(); @@ -3201,7 +3199,7 @@ public void testListPredicateExtended() { } @Test - public void testOrderBy() { + void testOrderBy() { addDataStore(); addNamespace(); @@ -3304,7 +3302,7 @@ private void testOrderBy( } @Test - public void testFullTextSearch() { + void testFullTextSearch() { // test layer title search data.featureTypeA.setTitle("Global .5 deg Air Temperature [C]"); data.coverageA.setTitle("Global .5 deg Dewpoint Depression [C]"); @@ -3359,7 +3357,7 @@ public void testFullTextSearch() { } @Test - public void testFullTextSearchLayerGroupTitle() { + void testFullTextSearchLayerGroupTitle() { addLayer(); // geos-6882 data.layerGroup1.setTitle("LayerGroup title"); @@ -3372,7 +3370,7 @@ public void testFullTextSearchLayerGroupTitle() { } @Test - public void testFullTextSearchLayerGroupName() { + void testFullTextSearchLayerGroupName() { addLayer(); // geos-6882 catalog.add(data.layerGroup1); @@ -3382,7 +3380,7 @@ public void testFullTextSearchLayerGroupName() { } @Test - public void testFullTextSearchLayerGroupAbstract() { + void testFullTextSearchLayerGroupAbstract() { addLayer(); data.layerGroup1.setAbstract("GeoServer OpenSource GIS"); catalog.add(data.layerGroup1); @@ -3392,7 +3390,7 @@ public void testFullTextSearchLayerGroupAbstract() { } @Test - public void testFullTextSearchKeywords() { + void testFullTextSearchKeywords() { data.featureTypeA.getKeywords().add(new Keyword("air_temp")); data.featureTypeA.getKeywords().add(new Keyword("temperatureAir")); data.coverageA.getKeywords().add(new Keyword("dwpt_dprs")); @@ -3439,7 +3437,7 @@ public void testFullTextSearchKeywords() { } @Test - public void testFullTextSearchAddedKeyword() { + void testFullTextSearchAddedKeyword() { data.featureTypeA.getKeywords().add(new Keyword("air_temp")); data.featureTypeA.getKeywords().add(new Keyword("temperatureAir")); @@ -3496,7 +3494,7 @@ protected FeatureTypeInfo newFeatureType(String name, DataStoreInfo ds) { } @Test - public void testConcurrentCatalogModification() throws Exception { + void testConcurrentCatalogModification() throws Exception { Logger logger = Logging.getLogger(CatalogImpl.class); final int tasks = 8; ExecutorService executor = Executors.newFixedThreadPool(tasks / 2); @@ -3546,7 +3544,7 @@ public void testConcurrentCatalogModification() throws Exception { } @Test - public void testChangeLayerGroupOrder() { + void testChangeLayerGroupOrder() { addLayerGroup(); // create second layer @@ -3590,7 +3588,7 @@ public void testChangeLayerGroupOrder() { } @Test - public void testIterablesHaveCatalogSet() { + void testIterablesHaveCatalogSet() { data.addObjects(); { CloseableIterator stores = catalog.list(StoreInfo.class, acceptAll()); @@ -3621,8 +3619,7 @@ public void testIterablesHaveCatalogSet() { List layers = g.getLayers(); layers.forEach( p -> { - if (p instanceof LayerInfo) { - LayerInfo l = (LayerInfo) p; + if (p instanceof LayerInfo l) { assertSame(catalog, l.getResource().getCatalog()); assertSame( catalog, l.getResource().getStore().getCatalog()); @@ -3632,7 +3629,8 @@ public void testIterablesHaveCatalogSet() { } } - public @Test void testCountIncludeFilter() { + @Test + void testCountIncludeFilter() { data.addObjects(); Filter filter = acceptAll(); assertEquals(3, catalog.count(WorkspaceInfo.class, filter)); @@ -3657,7 +3655,8 @@ public void testIterablesHaveCatalogSet() { assertEquals(2, catalog.count(StyleInfo.class, filter)); } - public @Test void testCountIdFilter() { + @Test + void testCountIdFilter() { data.addObjects(); assertEquals(1, catalog.count(WorkspaceInfo.class, equal("id", data.workspaceA.getId()))); assertEquals(0, catalog.count(NamespaceInfo.class, equal("id", data.workspaceA.getId()))); diff --git a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/CatalogFacadeExtensionAdapterTest.java b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/CatalogFacadeExtensionAdapterTest.java index 78b872082..22cc1b14b 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/CatalogFacadeExtensionAdapterTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/CatalogFacadeExtensionAdapterTest.java @@ -20,7 +20,7 @@ * catalog events, and that {@link CatalogFacadeExtensionAdapter#update} correctly forwards to * legacy {@link CatalogFacade#save} methods */ -public class CatalogFacadeExtensionAdapterTest extends CatalogConformanceTest { +class CatalogFacadeExtensionAdapterTest extends CatalogConformanceTest { private CatalogPlugin catalog; @@ -33,7 +33,8 @@ public class CatalogFacadeExtensionAdapterTest extends CatalogConformanceTest { return catalog; } - public @Test void testCatalogDecoratesLegacyFacade() { + @Test + void testCatalogDecoratesLegacyFacade() { catalog.setFacade(legacyFacade); assertSame(legacyFacade, catalog.getRawFacade()); assertThat(catalog.getFacade(), instanceOf(ResolvingCatalogFacadeDecorator.class)); @@ -47,7 +48,8 @@ public class CatalogFacadeExtensionAdapterTest extends CatalogConformanceTest { assertSame(legacyFacade, adapter.getSubject()); } - public @Test void testProvidedDecorator() { + @Test + void testProvidedDecorator() { CatalogFacadeExtensionAdapter adapter = new CatalogFacadeExtensionAdapter(legacyFacade); catalog.setFacade(adapter); assertSame(adapter, catalog.getRawFacade()); @@ -58,7 +60,8 @@ public class CatalogFacadeExtensionAdapterTest extends CatalogConformanceTest { assertSame(adapter, isolated.getSubject()); } - public @Test void testAdapterReplacesLegacyCatalogFacadeCatalog() { + @Test + void testAdapterReplacesLegacyCatalogFacadeCatalog() { CatalogFacadeExtensionAdapter adapter = new CatalogFacadeExtensionAdapter(legacyFacade); assertSame(legacyFacade, adapter.getSubject()); @@ -76,7 +79,7 @@ public class CatalogFacadeExtensionAdapterTest extends CatalogConformanceTest { assertNotSame(decoratorAtFacadeConstructor, legacyFacade.getCatalog()); } - // public @Test void testQuery() { + // @Test void testQuery() { // catalog.list(of, filter); // } } diff --git a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/CatalogPluginConformanceTest.java b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/CatalogPluginConformanceTest.java index bc4451abf..2365e6248 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/CatalogPluginConformanceTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/CatalogPluginConformanceTest.java @@ -4,7 +4,7 @@ */ package org.geoserver.catalog.plugin; -public class CatalogPluginConformanceTest extends CatalogConformanceTest { +class CatalogPluginConformanceTest extends CatalogConformanceTest { protected @Override CatalogPlugin createCatalog() { return new org.geoserver.catalog.plugin.CatalogPlugin(); diff --git a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/NamespaceInfoLookupTest.java b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/NamespaceInfoLookupTest.java index f02393eca..7fc124171 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/NamespaceInfoLookupTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/NamespaceInfoLookupTest.java @@ -18,7 +18,7 @@ import java.util.List; /** Test suite for {@link NamespaceInfoLookup} */ -public class NamespaceInfoLookupTest { +class NamespaceInfoLookupTest { private static final String URI_1 = "http://gs.test.com/ns1"; private static final String URI_2 = "http://gs.test.com/ns2"; @@ -49,7 +49,7 @@ private void addAll(NamespaceInfo... values) { } @Test - public void testAdd() { + void testAdd() { lookup.add(uri1_2); assertEquals(List.of(uri1_2), lookup.valueList(URI_1, false)); @@ -61,14 +61,14 @@ public void testAdd() { } @Test - public void testClear() { + void testClear() { addAll(uri1_1, uri1_2, uri2_1, uri2_2); lookup.clear(); assertEquals(List.of(), lookup.findAll().toList()); } @Test - public void testRemove() { + void testRemove() { addAll(uri1_1, uri1_2, uri2_1, uri2_2); testRemove(uri1_1); testRemove(uri1_2); @@ -84,7 +84,7 @@ private void testRemove(NamespaceInfo ns) { } @Test - public void testUpdate() { + void testUpdate() { addAll(uri1_1, uri1_2, uri2_1, uri2_2); testUpdate(uri1_1, URI_2, List.of(uri1_1, uri2_1, uri2_2)); @@ -104,7 +104,7 @@ private void testUpdate(NamespaceInfo ns, String newUri, List exp } @Test - public void testFindAllByUri() { + void testFindAllByUri() { assertThat(lookup.findAllByURI(URI_1)).isEmpty(); assertThat(lookup.findAllByURI(URI_2)).isEmpty(); @@ -122,7 +122,7 @@ public void testFindAllByUri() { } @Test - public void testFindAllByUri_stable_order() { + void testFindAllByUri_stable_order() { addAll(uri1_1, uri1_2); final List expected = List.of(uri1_1, uri1_2); @@ -136,7 +136,7 @@ public void testFindAllByUri_stable_order() { } @Test - public void testFindOneByURI() { + void testFindOneByURI() { addAll(uri1_1); assertThat(lookup.findOneByURI(URI_1)).get().isEqualTo(uri1_1); addAll(uri1_1, uri2_1); diff --git a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/PropertyDiffTest.java b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/PropertyDiffTest.java index e4735549d..ef8c36ed7 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/PropertyDiffTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/PropertyDiffTest.java @@ -30,7 +30,7 @@ import java.util.HashMap; import java.util.HashSet; -public class PropertyDiffTest { +class PropertyDiffTest { private PropertyDiffTestSupport support = new PropertyDiffTestSupport(); public CatalogTestData data; @@ -40,13 +40,15 @@ public class PropertyDiffTest { data = CatalogTestData.empty(() -> catalog, () -> null).initConfig(false).initialize(); } - public @Test void empty() { + @Test + void empty() { PropertyDiff diff = support.createTestDiff(); assertTrue(diff.isEmpty()); assertTrue(diff.getChanges().isEmpty()); } - public @Test void simpleStringProp() { + @Test + void simpleStringProp() { PropertyDiff diff = support.createTestDiff("prop1", "oldValue", "newValue"); assertEquals(1, diff.size()); Change change = diff.get(0); @@ -56,7 +58,8 @@ public class PropertyDiffTest { assertEquals("newValue", change.getNewValue()); } - public @Test void cleanToEmpty() { + @Test + void cleanToEmpty() { PropertyDiff diff = support.createTestDiff( // "leftListNull", @@ -88,7 +91,8 @@ public class PropertyDiffTest { assertEquals(0, clean.getChanges().size()); } - public @Test void cleanToEmpty_InternationalString() { + @Test + void cleanToEmpty_InternationalString() { PropertyDiff diff = support.createTestDiff( // "leftListNull", @@ -111,7 +115,8 @@ public class PropertyDiffTest { assertEquals(0, clean.getChanges().size()); } - public @Test void clean() { + @Test + void clean() { PropertyDiff diff = support.createTestDiff( // "prop1", @@ -143,7 +148,8 @@ public class PropertyDiffTest { assertEquals(Integer.valueOf(2), clean.get(1).getNewValue()); } - public @Test void builderToEmpty() { + @Test + void builderToEmpty() { WorkspaceInfo ws = data.workspaceA; ws.setDateCreated(new Date()); @@ -158,7 +164,8 @@ public class PropertyDiffTest { assertTrue(diff.clean().isEmpty()); } - public @Test void applyWorkspace() { + @Test + void applyWorkspace() { WorkspaceInfo ws = data.workspaceA; ws.setDateCreated(null); ws.setDateModified(null); diff --git a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/XmlCatalogInfoLookup.java b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/XmlCatalogInfoLookup.java index b87d23d51..165f29325 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/XmlCatalogInfoLookup.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/XmlCatalogInfoLookup.java @@ -106,7 +106,8 @@ protected T deserialize(String serialized) { return deserialize(serialized, getContentType()); } - public @Override void add(T value) { + @Override + public void add(T value) { checkNotAProxy(value); String serialized = serialize(value); @@ -119,12 +120,14 @@ protected T deserialize(String serialized) { } } - public @Override void remove(T value) { + @Override + public void remove(T value) { checkNotAProxy(value); idMap.remove(value.getId()); } - public @Override I update(final I value, Patch patch) { + @Override + public I update(final I value, Patch patch) { checkNotAProxy(value); T storedValue; // for the sake of correctness, get the stored value, contract does not force the supplied @@ -155,15 +158,18 @@ protected Stream allOf(Class clazz) { return all().filter(clazz::isInstance).map(clazz::cast); } - public @Override void dispose() { + @Override + public void dispose() { idMap.clear(); } - public @Override boolean canSortBy(String propertyName) { + @Override + public boolean canSortBy(String propertyName) { return CatalogInfoLookup.canSort(propertyName, getContentType()); } - public @Override Stream findAll(Query query) { + @Override + public Stream findAll(Query query) { Comparator comparator = toComparator(query); Predicate predicate = toPredicate(query.getFilter()); Stream stream = @@ -173,7 +179,8 @@ protected Stream allOf(Class clazz) { return stream; } - public @Override long count(Class type, Filter filter) { + @Override + public long count(Class type, Filter filter) { return Filter.INCLUDE.equals(filter) && getContentType().equals(type) ? idMap.size() : findAll(Query.valueOf(type, filter)).count(); @@ -202,7 +209,8 @@ protected Predicate toPredicate(Filter filter) { private static Comparator comparator(final SortBy sortOrder) { Comparator comparator = new Comparator<>() { - public @Override int compare(U o1, U o2) { + @Override + public int compare(U o1, U o2) { Object v1 = OwsUtils.get(o1, sortOrder.getPropertyName().getPropertyName()); Object v2 = OwsUtils.get(o2, sortOrder.getPropertyName().getPropertyName()); if (v1 == null) { @@ -238,7 +246,8 @@ Stream list( } /** Looks up a CatalogInfo by class and identifier */ - public @Override Optional findById(String id, Class clazz) { + @Override + public Optional findById(String id, Class clazz) { T deserialized = deserialize(idMap.get(id)); return Optional.ofNullable( clazz.isInstance(deserialized) ? clazz.cast(deserialized) : null); @@ -248,7 +257,8 @@ Optional findFirst(Class clazz, Predicate predicate) { return allOf(clazz).filter(predicate).findFirst(); } - public @Override void syncTo(CatalogInfoRepository target) { + @Override + public void syncTo(CatalogInfoRepository target) { all().forEach(target::add); } @@ -261,37 +271,43 @@ public NamespaceInfoLookup(XStreamPersister codec) { private String defaultNamespaceId; - public @Override void setDefaultNamespace(NamespaceInfo namespace) { + @Override + public void setDefaultNamespace(NamespaceInfo namespace) { this.defaultNamespaceId = findById(namespace.getId(), NamespaceInfo.class) .map(NamespaceInfo::getId) .orElseThrow(NoSuchElementException::new); } - public @Override Optional getDefaultNamespace() { + @Override + public Optional getDefaultNamespace() { return defaultNamespaceId == null ? Optional.empty() : findById(defaultNamespaceId, NamespaceInfo.class); } - public @Override Optional findOneByURI(String uri) { + @Override + public Optional findOneByURI(String uri) { return findFirst(NamespaceInfo.class, ns -> uri.equals(ns.getURI())); } - public @Override Stream findAllByURI(String uri) { + @Override + public Stream findAllByURI(String uri) { return all().filter(ns -> ns.getURI().equals(uri)); } - public @Override void unsetDefaultNamespace() { + @Override + public void unsetDefaultNamespace() { defaultNamespaceId = null; } - public @Override Class getContentType() { + @Override + public Class getContentType() { return NamespaceInfo.class; } - public @Override Optional findFirstByName( - String name, Class clazz) { + @Override + public Optional findFirstByName(String name, Class clazz) { return allOf(clazz).filter(ns -> ns.getPrefix().equals(name)).findFirst(); } } @@ -305,26 +321,30 @@ public WorkspaceInfoLookup(XStreamPersister codec) { private WorkspaceInfo defaultWorkspace; - public @Override void setDefaultWorkspace(WorkspaceInfo workspace) { + @Override + public void setDefaultWorkspace(WorkspaceInfo workspace) { this.defaultWorkspace = findById(workspace.getId(), WorkspaceInfo.class) .orElseThrow(NoSuchElementException::new); } - public @Override Optional getDefaultWorkspace() { + @Override + public Optional getDefaultWorkspace() { return Optional.ofNullable(defaultWorkspace); } - public @Override void unsetDefaultWorkspace() { + @Override + public void unsetDefaultWorkspace() { defaultWorkspace = null; } - public @Override Class getContentType() { + @Override + public Class getContentType() { return WorkspaceInfo.class; } - public @Override Optional findFirstByName( - String name, Class clazz) { + @Override + public Optional findFirstByName(String name, Class clazz) { return all().map(clazz::cast).filter(w -> name.equals(w.getName())).findFirst(); } } @@ -339,7 +359,8 @@ public StoreInfoLookup(XStreamPersister codec) { /** The default store id keyed by workspace id */ protected ConcurrentMap defaultStores = new ConcurrentHashMap<>(); - public @Override void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo store) { + @Override + public void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo store) { String wsId = workspace.getId(); final DataStoreInfo localStore = super.findById(store.getId(), DataStoreInfo.class) @@ -347,25 +368,30 @@ public StoreInfoLookup(XStreamPersister codec) { defaultStores.put(wsId, localStore.getId()); } - public @Override void unsetDefaultDataStore(WorkspaceInfo workspace) { + @Override + public void unsetDefaultDataStore(WorkspaceInfo workspace) { defaultStores.remove(workspace.getId()); } - public @Override Optional getDefaultDataStore(WorkspaceInfo workspace) { + @Override + public Optional getDefaultDataStore(WorkspaceInfo workspace) { String storeId = defaultStores.get(workspace.getId()); return storeId == null ? Optional.empty() : findById(storeId, DataStoreInfo.class); } - public @Override Stream getDefaultDataStores() { + @Override + public Stream getDefaultDataStores() { return defaultStores.values().stream().map(s -> deserialize(s, DataStoreInfo.class)); } - public @Override void dispose() { + @Override + public void dispose() { super.dispose(); defaultStores.clear(); } - public @Override Stream findAllByWorkspace( + @Override + public Stream findAllByWorkspace( WorkspaceInfo workspace, Class clazz) { return all().filter(clazz::isInstance) @@ -373,11 +399,13 @@ public StoreInfoLookup(XStreamPersister codec) { .filter(s -> s.getWorkspace().getId().equals(workspace.getId())); } - public @Override Stream findAllByType(Class clazz) { + @Override + public Stream findAllByType(Class clazz) { return all().filter(clazz::isInstance).map(clazz::cast); } - public @Override Optional findByNameAndWorkspace( + @Override + public Optional findByNameAndWorkspace( String name, WorkspaceInfo workspace, Class clazz) { return findAllByWorkspace(workspace, clazz) @@ -385,12 +413,13 @@ public StoreInfoLookup(XStreamPersister codec) { .findFirst(); } - public @Override Class getContentType() { + @Override + public Class getContentType() { return StoreInfo.class; } - public @Override Optional findFirstByName( - String name, Class clazz) { + @Override + public Optional findFirstByName(String name, Class clazz) { return all().filter(clazz::isInstance) .map(clazz::cast) .filter(s -> name.equals(s.getName())) @@ -405,11 +434,13 @@ public LayerGroupInfoLookup(XStreamPersister codec) { super(codec); } - public @Override Stream findAllByWorkspaceIsNull() { + @Override + public Stream findAllByWorkspaceIsNull() { return all().filter(lg -> lg.getWorkspace() == null); } - public @Override Stream findAllByWorkspace(WorkspaceInfo workspace) { + @Override + public Stream findAllByWorkspace(WorkspaceInfo workspace) { Predicate predicate = lg -> lg.getWorkspace() != null @@ -417,23 +448,26 @@ public LayerGroupInfoLookup(XStreamPersister codec) { return all().filter(predicate); } - public @Override Optional findByNameAndWorkspaceIsNull(String name) { + @Override + public Optional findByNameAndWorkspaceIsNull(String name) { return findAllByWorkspaceIsNull().filter(lg -> lg.getName().equals(name)).findFirst(); } - public @Override Optional findByNameAndWorkspace( + @Override + public Optional findByNameAndWorkspace( String name, WorkspaceInfo workspace) { return findAllByWorkspace(workspace) .filter(lg -> lg.getName().equals(name)) .findFirst(); } - public @Override Class getContentType() { + @Override + public Class getContentType() { return LayerGroupInfo.class; } - public @Override Optional findFirstByName( - String name, Class clazz) { + @Override + public Optional findFirstByName(String name, Class clazz) { return all().filter(clazz::isInstance) .map(clazz::cast) .filter(s -> name.equals(s.getName())) @@ -448,12 +482,13 @@ protected MapInfoLookup(XStreamPersister codec) { super(codec); } - public @Override Class getContentType() { + @Override + public Class getContentType() { return MapInfo.class; } - public @Override Optional findFirstByName( - String name, Class clazz) { + @Override + public Optional findFirstByName(String name, Class clazz) { return all().filter(clazz::isInstance) .map(clazz::cast) .filter(s -> name.equals(s.getName())) @@ -468,29 +503,33 @@ protected ResourceInfoLookup(XStreamPersister codec) { super(codec); } - public @Override Stream findAllByType(Class clazz) { + @Override + public Stream findAllByType(Class clazz) { return allOf(clazz); } - public @Override Stream findAllByNamespace( + @Override + public Stream findAllByNamespace( NamespaceInfo ns, Class clazz) { return allOf(clazz).filter(r -> ns.getId().equals(r.getNamespace().getId())); } - public @Override Optional findByStoreAndName( + @Override + public Optional findByStoreAndName( StoreInfo store, String name, Class clazz) { return findAllByStore(store, clazz).filter(r -> name.equals(r.getName())).findFirst(); } - public @Override Stream findAllByStore( - StoreInfo store, Class clazz) { + @Override + public Stream findAllByStore(StoreInfo store, Class clazz) { return allOf(clazz).filter(r -> store.getId().equals(r.getStore().getId())); } - public @Override Optional findByNameAndNamespace( + @Override + public Optional findByNameAndNamespace( String name, NamespaceInfo namespace, Class clazz) { return findAllByNamespace(namespace, clazz) @@ -498,12 +537,13 @@ protected ResourceInfoLookup(XStreamPersister codec) { .findFirst(); } - public @Override Class getContentType() { + @Override + public Class getContentType() { return ResourceInfo.class; } - public @Override Optional findFirstByName( - String name, Class clazz) { + @Override + public Optional findFirstByName(String name, Class clazz) { return all().filter(clazz::isInstance) .map(clazz::cast) .filter(s -> name.equals(s.getName())) @@ -518,11 +558,13 @@ public LayerInfoLookup(XStreamPersister codec) { super(codec); } - public @Override Optional findOneByName(String name) { + @Override + public Optional findOneByName(String name) { return findFirst(LayerInfo.class, li -> name.equals(li.getName())); } - public @Override Stream findAllByDefaultStyleOrStyles(StyleInfo style) { + @Override + public Stream findAllByDefaultStyleOrStyles(StyleInfo style) { String id = style.getId(); Predicate predicate = li -> @@ -534,7 +576,8 @@ public LayerInfoLookup(XStreamPersister codec) { return all().filter(predicate); } - public @Override Stream findAllByResource(ResourceInfo resource) { + @Override + public Stream findAllByResource(ResourceInfo resource) { return all().filter(l -> l.getResource().getId().equals(resource.getId())); } @@ -542,8 +585,8 @@ public Class getContentType() { return LayerInfo.class; } - public @Override Optional findFirstByName( - String name, Class clazz) { + @Override + public Optional findFirstByName(String name, Class clazz) { return all().filter(clazz::isInstance) .map(clazz::cast) .filter(s -> name.equals(s.getName())) @@ -558,31 +601,35 @@ public StyleInfoLookup(XStreamPersister codec) { super(codec); } - public @Override Stream findAllByNullWorkspace() { + @Override + public Stream findAllByNullWorkspace() { return all().filter(s -> s.getWorkspace() == null); } - public @Override Stream findAllByWorkspace(WorkspaceInfo ws) { + @Override + public Stream findAllByWorkspace(WorkspaceInfo ws) { return all().filter(s -> s.getWorkspace() != null) .filter(s -> s.getWorkspace().getId().equals(ws.getId())); } - public @Override Optional findByNameAndWordkspaceNull(String name) { + @Override + public Optional findByNameAndWordkspaceNull(String name) { return findAllByNullWorkspace().filter(s -> s.getName().equals(name)).findFirst(); } - public @Override Optional findByNameAndWorkspace( - String name, WorkspaceInfo workspace) { + @Override + public Optional findByNameAndWorkspace(String name, WorkspaceInfo workspace) { return findAllByWorkspace(workspace).filter(s -> s.getName().equals(name)).findFirst(); } - public @Override Class getContentType() { + @Override + public Class getContentType() { return StyleInfo.class; } - public @Override Optional findFirstByName( - String name, Class clazz) { + @Override + public Optional findFirstByName(String name, Class clazz) { return all().filter(clazz::isInstance) .map(clazz::cast) .filter(s -> name.equals(s.getName())) diff --git a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/XmlCatalogInfoLookupConformanceTest.java b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/XmlCatalogInfoLookupConformanceTest.java index e8a62e9f4..a5e6dad8d 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/XmlCatalogInfoLookupConformanceTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/XmlCatalogInfoLookupConformanceTest.java @@ -13,7 +13,7 @@ import org.geoserver.config.util.XStreamPersisterFactory; import org.junit.jupiter.api.Disabled; -public class XmlCatalogInfoLookupConformanceTest extends CatalogConformanceTest { +class XmlCatalogInfoLookupConformanceTest extends CatalogConformanceTest { protected @Override CatalogPlugin createCatalog() { CatalogPlugin catalog = new org.geoserver.catalog.plugin.CatalogPlugin(); @@ -47,9 +47,11 @@ public class XmlCatalogInfoLookupConformanceTest extends CatalogConformanceTest revisit, seems to be just a problem of ordering or equals with the \ returned ft/ft2 where mockito is not throwing the expected exception """) - public @Override void testSaveDataStoreRollbacksBothStoreAndResources() throws Exception {} + @Override + public void testSaveDataStoreRollbacksBothStoreAndResources() throws Exception {} @Disabled( "don't care it can't save the resourceinfo when saving a layer, it's just a demo implementation") - public @Override void testEnableLayer() {} + @Override + public void testEnableLayer() {} } diff --git a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/locking/LockProviderGeoServerConfigurationLockTest.java b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/locking/LockProviderGeoServerConfigurationLockTest.java index ca2ac83de..f8452b847 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/locking/LockProviderGeoServerConfigurationLockTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/locking/LockProviderGeoServerConfigurationLockTest.java @@ -38,21 +38,21 @@ class LockProviderGeoServerConfigurationLockTest { private LockProviderGeoServerConfigurationLock lock; @BeforeEach - public void beforeEach() { + void beforeEach() { System.setProperty("CONFIGURATION_TRYLOCK_TIMEOUT", "100"); LockProvider lockProvider = new FileLockProvider(mockDataDir); lock = new LockProviderGeoServerConfigurationLock(lockProvider); } @AfterEach - public void afterEach() { + void afterEach() { System.clearProperty("CONFIGURATION_TRYLOCK_TIMEOUT"); assertFalse(lock.isWriteLocked(), "all locks shall have been released"); } @Test @Timeout(1) - public void testLock_WriteLock() { + void testLock_WriteLock() { assertNull(lock.getCurrentLock()); lock.lock(WRITE); assertEquals(WRITE, lock.getCurrentLock()); @@ -62,7 +62,7 @@ public void testLock_WriteLock() { @Test @Timeout(1) - public void testLock_ReadLock() { + void testLock_ReadLock() { assertNull(lock.getCurrentLock()); lock.lock(READ); assertEquals(READ, lock.getCurrentLock()); @@ -72,7 +72,7 @@ public void testLock_ReadLock() { @Test @Timeout(1) - public void testLock_ReadLock_preserves_write_lock_if_alread_held() { + void testLock_ReadLock_preserves_write_lock_if_alread_held() { assertNull(lock.getCurrentLock()); lock.lock(WRITE); assertEquals(WRITE, lock.getCurrentLock()); @@ -87,7 +87,7 @@ public void testLock_ReadLock_preserves_write_lock_if_alread_held() { @Test @Timeout(1) - public void testTryUpgradeLock_fais_if_no_previous_lock_is_held() { + void testTryUpgradeLock_fais_if_no_previous_lock_is_held() { assertNull(lock.getCurrentLock()); IllegalStateException ex = assertThrows(IllegalStateException.class, lock::tryUpgradeLock); assertThat(ex.getMessage(), containsString("No lock currently held")); @@ -95,7 +95,7 @@ public void testTryUpgradeLock_fais_if_no_previous_lock_is_held() { @Test @Timeout(1) - public void testTryUpgradeLock_fails_if_already_holds_a_write_lock() { + void testTryUpgradeLock_fails_if_already_holds_a_write_lock() { assertNull(lock.getCurrentLock()); lock.lock(WRITE); @@ -109,7 +109,7 @@ public void testTryUpgradeLock_fails_if_already_holds_a_write_lock() { @Test @Timeout(1) - public void testTryUpgradeLock() throws InterruptedException, ExecutionException { + void testTryUpgradeLock() throws InterruptedException, ExecutionException { ExecutorService secondThread = Executors.newSingleThreadExecutor(); try { lock.lock(READ); @@ -146,7 +146,7 @@ public void testTryUpgradeLock() throws InterruptedException, ExecutionException @Test @Timeout(1) - public void testTryLock() { + void testTryLock() { assertTrue(lock.tryLock(READ)); assertEquals(READ, lock.getCurrentLock()); lock.unlock(); @@ -160,7 +160,7 @@ public void testTryLock() { @Test @Timeout(1) - public void testTryLock_false_if_write_lock_requested_while_holding_a_read_lock() { + void testTryLock_false_if_write_lock_requested_while_holding_a_read_lock() { assertNull(lock.getCurrentLock()); assertTrue(lock.tryLock(READ)); @@ -174,7 +174,7 @@ public void testTryLock_false_if_write_lock_requested_while_holding_a_read_lock( @Test @Timeout(1) - public void testTryLock_true_if_read_lock_requested_while_holding_a_write_lock() { + void testTryLock_true_if_read_lock_requested_while_holding_a_write_lock() { assertTrue(lock.tryLock(WRITE)); assertEquals(WRITE, lock.getCurrentLock()); @@ -191,7 +191,7 @@ public void testTryLock_true_if_read_lock_requested_while_holding_a_write_lock() @Test @Timeout(1) - public void testUnlock() { + void testUnlock() { assertNull(lock.getCurrentLock()); lock.unlock(); lock.unlock(); @@ -208,13 +208,13 @@ public void testUnlock() { @Test @Timeout(1) - public void testLock_ReadLockIsReentrant() { + void testLock_ReadLockIsReentrant() { testLockIsReentrant(READ); } @Test @Timeout(1) - public void testLock_WriteLockIsReentrant() { + void testLock_WriteLockIsReentrant() { testLockIsReentrant(WRITE); } @@ -244,13 +244,13 @@ private void testLockIsReentrant(LockType lockType) { @Test @Timeout(1) - public void testTryReadLockIsReentrant() { + void testTryReadLockIsReentrant() { testTryLockIsReentrant(READ); } @Test @Timeout(1) - public void testTryWriteLockIsReentrant() { + void testTryWriteLockIsReentrant() { testTryLockIsReentrant(WRITE); } diff --git a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/locking/LockingCatalogDataDirectoryTest.java b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/locking/LockingCatalogDataDirectoryTest.java index 067999630..b8a98dc48 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/locking/LockingCatalogDataDirectoryTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/locking/LockingCatalogDataDirectoryTest.java @@ -16,7 +16,7 @@ /** * @since 1.0 */ -public class LockingCatalogDataDirectoryTest extends LockingCatalogTest { +class LockingCatalogDataDirectoryTest extends LockingCatalogTest { @TempDir File tmpDir; diff --git a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/locking/LockingCatalogTest.java b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/locking/LockingCatalogTest.java index 75c88279b..47bee9251 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/locking/LockingCatalogTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/catalog/plugin/locking/LockingCatalogTest.java @@ -156,18 +156,17 @@ private void batchUpdate(List infos) { configLock.lock(LockType.WRITE); try { for (CatalogInfo info : infos) { - if (info instanceof WorkspaceInfo) ((WorkspaceInfo) info).setName(faker.name()); - else if (info instanceof NamespaceInfo) ((NamespaceInfo) info).setURI(faker.url()); - else if (info instanceof DataStoreInfo) { - ((DataStoreInfo) info).setName(faker.name()); - ((DataStoreInfo) info).getConnectionParameters().put("someparam", "somevalue"); - ((DataStoreInfo) info).getMetadata().put("somekey", "key value"); - } else if (info instanceof FeatureTypeInfo) - ((FeatureTypeInfo) info).setName(faker.name()); - else if (info instanceof LayerInfo) ((LayerInfo) info).setAdvertised(false); - else if (info instanceof StyleInfo) { - ((StyleInfo) info).setDateModified(new Date()); - ((StyleInfo) info).getMetadata().put("somekey", "key value"); + if (info instanceof WorkspaceInfo ws) ws.setName(faker.name()); + else if (info instanceof NamespaceInfo ns) ns.setURI(faker.url()); + else if (info instanceof DataStoreInfo ds) { + ds.setName(faker.name()); + ds.getConnectionParameters().put("someparam", "somevalue"); + ds.getMetadata().put("somekey", "key value"); + } else if (info instanceof FeatureTypeInfo ft) ft.setName(faker.name()); + else if (info instanceof LayerInfo l) l.setAdvertised(false); + else if (info instanceof StyleInfo s) { + s.setDateModified(new Date()); + s.getMetadata().put("somekey", "key value"); } else { throw new IllegalStateException("Unexpected catalog info type " + info); } diff --git a/src/catalog/plugin/src/test/java/org/geoserver/cloud/test/ApplicationEventCapturingListener.java b/src/catalog/plugin/src/test/java/org/geoserver/cloud/test/ApplicationEventCapturingListener.java index 6e7d72b00..ab3a35287 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/cloud/test/ApplicationEventCapturingListener.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/cloud/test/ApplicationEventCapturingListener.java @@ -14,7 +14,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; @Component public class ApplicationEventCapturingListener { @@ -68,10 +67,7 @@ public T expectOne(Class type) { } public List allOf(Class type) { - return captured.stream() - .filter(type::isInstance) - .map(type::cast) - .collect(Collectors.toList()); + return captured.stream().filter(type::isInstance).map(type::cast).toList(); } public Optional first(Class type) { diff --git a/src/catalog/plugin/src/test/java/org/geoserver/config/GeoServerConfigConformanceTest.java b/src/catalog/plugin/src/test/java/org/geoserver/config/GeoServerConfigConformanceTest.java index f805a1871..4921c596b 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/config/GeoServerConfigConformanceTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/config/GeoServerConfigConformanceTest.java @@ -56,7 +56,7 @@ protected ServiceInfo createService() { } @Test - public void testGlobal() throws Exception { + void testGlobal() throws Exception { GeoServerInfo global = geoServer.getFactory().createGlobal(); geoServer.setGlobal(global); @@ -66,7 +66,7 @@ public void testGlobal() throws Exception { // GEOS-7890 @Test - public void testEquals() throws Exception { + void testEquals() throws Exception { GeoServerInfo global1 = geoServer.getFactory().createGlobal(); GeoServerInfo global2 = geoServer.getFactory().createGlobal(); global1.setGlobalServices(Boolean.valueOf(true)); @@ -82,7 +82,7 @@ public void testEquals() throws Exception { } @Test - public void testModifyGlobal() throws Exception { + void testModifyGlobal() throws Exception { GeoServerInfo global = geoServer.getFactory().createGlobal(); geoServer.setGlobal(global); @@ -98,7 +98,7 @@ public void testModifyGlobal() throws Exception { } @Test - public void testAddService() throws Exception { + void testAddService() throws Exception { ServiceInfo service = createService(); service.setName("wms"); geoServer.add(service); @@ -122,7 +122,7 @@ public void testAddService() throws Exception { } @Test - public void testModifyService() throws Exception { + void testModifyService() throws Exception { ServiceInfo service = createService(); ((ServiceInfoImpl) service).setId("id"); service.setName("wms"); @@ -142,7 +142,7 @@ public void testModifyService() throws Exception { } @Test - public void testGlobalEvents() throws Exception { + void testGlobalEvents() throws Exception { TestListener tl = new TestListener(); geoServer.addListener(tl); @@ -195,7 +195,7 @@ public void handleServiceChange( } @Test - public void testSetClientPropsHasEffect() throws Exception { + void testSetClientPropsHasEffect() throws Exception { GeoServerInfoImpl gsii = new GeoServerInfoImpl(geoServer); Map before = gsii.getClientProperties(); @@ -207,7 +207,7 @@ public void testSetClientPropsHasEffect() throws Exception { } @Test - public void testGetSettings() throws Exception { + void testGetSettings() throws Exception { GeoServerInfo global = geoServer.getFactory().createGlobal(); geoServer.setGlobal(global); @@ -239,7 +239,7 @@ public void testGetSettings() throws Exception { } @Test - public void testModifySettings() throws Exception { + void testModifySettings() throws Exception { WorkspaceInfo ws = geoServer.getCatalog().getFactory().createWorkspace(); ws.setName("acme"); geoServer.getCatalog().add(ws); @@ -264,7 +264,7 @@ public void testModifySettings() throws Exception { @SuppressWarnings("unchecked") @Test - public void testServiceWithWorkspace() throws Exception { + void testServiceWithWorkspace() throws Exception { // Make a workspace WorkspaceInfo ws1 = geoServer.getCatalog().getFactory().createWorkspace(); ws1.setName("TEST-WORKSPACE-1"); @@ -316,7 +316,7 @@ public void testServiceWithWorkspace() throws Exception { } @Test - public void testModifyLogging() { + void testModifyLogging() { geoServer.setLogging(geoServer.getFactory().createLogging()); LoggingInfo logging = geoServer.getLogging(); diff --git a/src/catalog/plugin/src/test/java/org/geoserver/config/impl/CatalogImplConformanceTest.java b/src/catalog/plugin/src/test/java/org/geoserver/config/impl/CatalogImplConformanceTest.java index df3632f30..23cdd7c39 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/config/impl/CatalogImplConformanceTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/config/impl/CatalogImplConformanceTest.java @@ -12,7 +12,7 @@ * {@link CatalogConformanceTest} for the traditional {@link CatalogImpl} with {@link * DefaultCatalogFacade} */ -public class CatalogImplConformanceTest extends CatalogConformanceTest { +class CatalogImplConformanceTest extends CatalogConformanceTest { protected @Override CatalogImpl createCatalog() { return new org.geoserver.catalog.impl.CatalogImpl(); diff --git a/src/catalog/plugin/src/test/java/org/geoserver/config/impl/GeoServerImplConformanceTest.java b/src/catalog/plugin/src/test/java/org/geoserver/config/impl/GeoServerImplConformanceTest.java index 0943f95bf..64476aa43 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/config/impl/GeoServerImplConformanceTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/config/impl/GeoServerImplConformanceTest.java @@ -9,7 +9,7 @@ import org.geoserver.config.GeoServerConfigConformanceTest; /** {@link GeoServerConfigConformanceTest} for the traditional {@link GeoServerImpl} */ -public class GeoServerImplConformanceTest extends GeoServerConfigConformanceTest { +class GeoServerImplConformanceTest extends GeoServerConfigConformanceTest { protected @Override GeoServer createGeoServer() { GeoServerImpl gs = new GeoServerImpl(); diff --git a/src/catalog/plugin/src/test/java/org/geoserver/config/plugin/GeoServerImplConformanceTest.java b/src/catalog/plugin/src/test/java/org/geoserver/config/plugin/GeoServerImplConformanceTest.java index 55b528819..d0dbf8193 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/config/plugin/GeoServerImplConformanceTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/config/plugin/GeoServerImplConformanceTest.java @@ -12,7 +12,7 @@ * {@link GeoServerConfigConformanceTest} for {@link GeoServerImpl} with {@link * RepositoryGeoServerFacade} backed by {@link MemoryConfigRepository} and a {@link CatalogPlugin} */ -public class GeoServerImplConformanceTest extends GeoServerConfigConformanceTest { +class GeoServerImplConformanceTest extends GeoServerConfigConformanceTest { protected @Override GeoServer createGeoServer() { GeoServerImpl gs = new GeoServerImpl(); diff --git a/src/catalog/plugin/src/test/java/org/geoserver/config/plugin/XmlSerializedConfigRepository.java b/src/catalog/plugin/src/test/java/org/geoserver/config/plugin/XmlSerializedConfigRepository.java index 304012ccd..9df0d67ea 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/config/plugin/XmlSerializedConfigRepository.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/config/plugin/XmlSerializedConfigRepository.java @@ -74,7 +74,8 @@ private ServiceInfo toService(String serialized) { return deserialize(serialized, ServiceInfo.class); } - public @Override Optional getGlobal() { + @Override + public Optional getGlobal() { return Optional.ofNullable(deserialize(global, GeoServerInfo.class)); } @@ -85,29 +86,34 @@ private static void checkNotAProxy(Info value) { } } - public @Override void setGlobal(GeoServerInfo global) { + @Override + public void setGlobal(GeoServerInfo global) { checkNotAProxy(global); this.global = serialize(global); } - public @Override Optional getSettingsById(String id) { + @Override + public Optional getSettingsById(String id) { return Optional.ofNullable(toSettings(settings.get(id))); } - public @Override Optional getSettingsByWorkspace(WorkspaceInfo workspace) { + @Override + public Optional getSettingsByWorkspace(WorkspaceInfo workspace) { return settings.values().stream() .map(this::toSettings) .filter(s -> s.getWorkspace().getId().equals(workspace.getId())) .findFirst(); } - public @Override void add(SettingsInfo settings) { + @Override + public void add(SettingsInfo settings) { checkNotAProxy(settings); String serialized = serialize(settings); this.settings.put(settings.getId(), serialized); } - public @Override SettingsInfo update(SettingsInfo settings, Patch patch) { + @Override + public SettingsInfo update(SettingsInfo settings, Patch patch) { checkNotAProxy(settings); String localCopy = this.settings.get(settings.getId()); @@ -119,31 +125,37 @@ private static void checkNotAProxy(Info value) { } } - public @Override void remove(SettingsInfo settings) { + @Override + public void remove(SettingsInfo settings) { this.services.remove(settings.getId()); } - public @Override Optional getLogging() { + @Override + public Optional getLogging() { return Optional.ofNullable(deserialize(logging, LoggingInfo.class)); } - public @Override void setLogging(LoggingInfo logging) { + @Override + public void setLogging(LoggingInfo logging) { this.logging = serialize(logging); } - public @Override void add(ServiceInfo service) { + @Override + public void add(ServiceInfo service) { checkNotAProxy(service); String serialized = serialize(service); this.services.put(service.getId(), serialized); } - public @Override void remove(ServiceInfo service) { + @Override + public void remove(ServiceInfo service) { this.services.remove(service.getId()); } @SuppressWarnings("unchecked") - public @Override S update(S service, Patch patch) { + @Override + public S update(S service, Patch patch) { checkNotAProxy(service); String localCopy = services.get(service.getId()); @@ -155,17 +167,20 @@ private static void checkNotAProxy(Info value) { } } - public @Override Stream getGlobalServices() { + @Override + public Stream getGlobalServices() { return services().filter(s -> s.getWorkspace() == null); } - public @Override Stream getServicesByWorkspace(WorkspaceInfo workspace) { + @Override + public Stream getServicesByWorkspace(WorkspaceInfo workspace) { return services() .filter(s -> s.getWorkspace() != null) .filter(s -> workspace.getId().equals(s.getWorkspace().getId())); } - public @Override Optional getGlobalService(Class clazz) { + @Override + public Optional getGlobalService(Class clazz) { return services() .filter(clazz::isInstance) .filter(s -> s.getWorkspace() == null) @@ -173,7 +188,8 @@ private static void checkNotAProxy(Info value) { .findFirst(); } - public @Override Optional getServiceByWorkspace( + @Override + public Optional getServiceByWorkspace( WorkspaceInfo workspace, Class clazz) { return getServicesByWorkspace(workspace) @@ -182,14 +198,15 @@ private static void checkNotAProxy(Info value) { .findFirst(); } - public @Override Optional getServiceById(String id, Class clazz) { + @Override + public Optional getServiceById(String id, Class clazz) { ServiceInfo service = toService(services.get(id)); return clazz.isInstance(service) ? Optional.of(clazz.cast(service)) : Optional.empty(); } - public @Override Optional getServiceByName( - String name, Class clazz) { + @Override + public Optional getServiceByName(String name, Class clazz) { return getGlobalServices() .filter(clazz::isInstance) @@ -198,7 +215,8 @@ private static void checkNotAProxy(Info value) { .findFirst(); } - public @Override Optional getServiceByNameAndWorkspace( + @Override + public Optional getServiceByNameAndWorkspace( String name, WorkspaceInfo workspace, Class clazz) { return getServicesByWorkspace(workspace) @@ -212,7 +230,8 @@ private Stream services() { return this.services.values().stream().map(this::toService); } - public @Override void dispose() { + @Override + public void dispose() { global = null; logging = null; settings.clear(); diff --git a/src/catalog/plugin/src/test/java/org/geoserver/config/plugin/XmlSerializedConfigRepositoryConformanceTest.java b/src/catalog/plugin/src/test/java/org/geoserver/config/plugin/XmlSerializedConfigRepositoryConformanceTest.java index 15e886dc8..a501d8311 100644 --- a/src/catalog/plugin/src/test/java/org/geoserver/config/plugin/XmlSerializedConfigRepositoryConformanceTest.java +++ b/src/catalog/plugin/src/test/java/org/geoserver/config/plugin/XmlSerializedConfigRepositoryConformanceTest.java @@ -11,7 +11,7 @@ import org.geoserver.config.util.XStreamPersister; import org.geoserver.config.util.XStreamPersisterFactory; -public class XmlSerializedConfigRepositoryConformanceTest extends GeoServerConfigConformanceTest { +class XmlSerializedConfigRepositoryConformanceTest extends GeoServerConfigConformanceTest { protected @Override GeoServer createGeoServer() { Catalog catalog = new CatalogPlugin(); diff --git a/src/catalog/plugin/src/test/resources/logback-test.xml b/src/catalog/plugin/src/test/resources/logback-test.xml new file mode 100644 index 000000000..e1e13bc45 --- /dev/null +++ b/src/catalog/plugin/src/test/resources/logback-test.xml @@ -0,0 +1,15 @@ + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n + + + + + + + + + + + diff --git a/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/gwc/integration/WMSIntegrationAutoConfiguration.java b/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/gwc/integration/WMSIntegrationAutoConfiguration.java index 06c232736..63fe6080d 100644 --- a/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/gwc/integration/WMSIntegrationAutoConfiguration.java +++ b/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/gwc/integration/WMSIntegrationAutoConfiguration.java @@ -171,8 +171,8 @@ public WebMap getMap(ProceedingJoinPoint joinPoint) throws Throwable { final byte[] tileBytes; { final Resource mapContents = cachedTile.getBlob(); - if (mapContents instanceof ByteArrayResource) { - tileBytes = ((ByteArrayResource) mapContents).getContents(); + if (mapContents instanceof ByteArrayResource bar) { + tileBytes = bar.getContents(); } else { ByteArrayOutputStream out = new ByteArrayOutputStream(); mapContents.transferTo(Channels.newChannel(out)); @@ -202,7 +202,7 @@ public WebMap getMap(ProceedingJoinPoint joinPoint) throws Throwable { GWC.setConditionalGetHeaders( headers, cachedTile, etag, request.getHttpRequestHeader("If-Modified-Since")); GWC.setCacheMetadataHeaders(headers, cachedTile, layer); - headers.forEach((k, v) -> map.setResponseHeader(k, v)); + headers.forEach(map::setResponseHeader); return map; } diff --git a/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/web/gwc/GeoWebCacheUIAutoConfiguration.java b/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/web/gwc/GeoWebCacheUIAutoConfiguration.java index a65a00bf6..39f5aee81 100644 --- a/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/web/gwc/GeoWebCacheUIAutoConfiguration.java +++ b/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/web/gwc/GeoWebCacheUIAutoConfiguration.java @@ -9,6 +9,7 @@ import org.geoserver.cloud.autoconfigure.gwc.ConditionalOnGeoWebCacheRestConfigEnabled; import org.geoserver.cloud.autoconfigure.gwc.ConditionalOnWebUIEnabled; import org.geoserver.cloud.gwc.config.core.GeoWebCacheConfigurationProperties; +import org.geowebcache.GeoWebCacheDispatcher; import org.geowebcache.rest.controller.ByteStreamController; import org.gwc.web.rest.GeoWebCacheController; import org.springframework.boot.autoconfigure.AutoConfiguration; @@ -27,8 +28,8 @@ public class GeoWebCacheUIAutoConfiguration { } @Bean - GeoWebCacheController gwcController() { - return new GeoWebCacheController(); + GeoWebCacheController gwcController(GeoWebCacheDispatcher gwcDispatcher) { + return new GeoWebCacheController(gwcDispatcher); } /** diff --git a/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/blobstore/AzureBlobstoreAutoConfigurationTest.java b/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/blobstore/AzureBlobstoreAutoConfigurationTest.java index 0c522d788..8ecae883c 100644 --- a/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/blobstore/AzureBlobstoreAutoConfigurationTest.java +++ b/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/blobstore/AzureBlobstoreAutoConfigurationTest.java @@ -38,7 +38,8 @@ void setUp() throws Exception { AutoConfigurations.of(AzureBlobstoreAutoConfiguration.class)); } - public @Test void disabledByDefault() { + @Test + void disabledByDefault() { runner.run( context -> { assertThat(context).doesNotHaveBean(AzureBlobStoreConfigProvider.class); @@ -47,7 +48,8 @@ void setUp() throws Exception { }); } - public @Test void blobstoreEnabledGeoServerWebUiDisabled() { + @Test + void blobstoreEnabledGeoServerWebUiDisabled() { runner.withPropertyValues("gwc.blobstores.azure=true", "geoserver.web-ui.gwc.enabled=false") .run( context -> { @@ -57,7 +59,8 @@ void setUp() throws Exception { }); } - public @Test void blobstoreEnabledGeoServerWebUiEnabled() { + @Test + void blobstoreEnabledGeoServerWebUiEnabled() { runner.withPropertyValues("gwc.blobstores.azure=true", "geoserver.web-ui.gwc.enabled=true") .run( context -> { @@ -67,7 +70,8 @@ void setUp() throws Exception { }); } - public @Test void blobstoreEnabledGeoServerWebUiEnabledGsWebGwcNotInClassPath() { + @Test + void blobstoreEnabledGeoServerWebUiEnabledGsWebGwcNotInClassPath() { runner.withClassLoader(new FilteredClassLoader(GWCSettingsPage.class)) .withPropertyValues( "gwc.blobstores.azure=true", "geoserver.web-ui.gwc.enabled=true") diff --git a/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/blobstore/S3BlobstoreAutoConfigurationTest.java b/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/blobstore/S3BlobstoreAutoConfigurationTest.java index 793dcc089..60ae380be 100644 --- a/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/blobstore/S3BlobstoreAutoConfigurationTest.java +++ b/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/blobstore/S3BlobstoreAutoConfigurationTest.java @@ -38,7 +38,8 @@ void setUp() throws Exception { AutoConfigurations.of(S3BlobstoreAutoConfiguration.class)); } - public @Test void disabledByDefault() { + @Test + void disabledByDefault() { runner.run( context -> { assertThat(context).doesNotHaveBean(S3BlobStoreConfigProvider.class); @@ -47,7 +48,8 @@ void setUp() throws Exception { }); } - public @Test void blobstoreEnabledGeoServerWebUiDisabled() { + @Test + void blobstoreEnabledGeoServerWebUiDisabled() { runner.withPropertyValues("gwc.blobstores.s3=true", "geoserver.web-ui.gwc.enabled=false") .run( context -> { @@ -57,7 +59,8 @@ void setUp() throws Exception { }); } - public @Test void blobstoreEnabledGeoServerWebUiEnabled() { + @Test + void blobstoreEnabledGeoServerWebUiEnabled() { runner.withPropertyValues("gwc.blobstores.s3=true", "geoserver.web-ui.gwc.enabled=true") .run( context -> { @@ -67,7 +70,8 @@ void setUp() throws Exception { }); } - public @Test void blobstoreEnabledGeoServerWebUiEnabledGsWebGwcNotInClassPath() { + @Test + void blobstoreEnabledGeoServerWebUiEnabledGsWebGwcNotInClassPath() { runner.withClassLoader(new FilteredClassLoader(GWCSettingsPage.class)) .withPropertyValues("gwc.blobstores.s3=true", "geoserver.web-ui.gwc.enabled=true") .run( diff --git a/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/core/GwcCoreAutoConfigurationTest.java b/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/core/GwcCoreAutoConfigurationTest.java index bbb3c9ecc..7d7fb897d 100644 --- a/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/core/GwcCoreAutoConfigurationTest.java +++ b/src/gwc/autoconfigure/src/test/java/org/geoserver/cloud/autoconfigure/gwc/core/GwcCoreAutoConfigurationTest.java @@ -42,24 +42,28 @@ void setUp() throws Exception { runner = GeoWebCacheContextRunner.newMinimalGeoWebCacheContextRunner(tmpDir); } - public @Test void defaultCacheDirectoryConfigPropertyIsMandatory() { + @Test + void defaultCacheDirectoryConfigPropertyIsMandatory() { runner = runner.withPropertyValues("gwc.cache-directory="); // null-ify it assertContextLoadFails(InvalidPropertyException.class, "gwc.cache-directory is not set"); } - public @Test void defaultCacheDirectoryIsAbsolutePath() { + @Test + void defaultCacheDirectoryIsAbsolutePath() { runner = runner.withPropertyValues("gwc.cache-directory=relative/path"); assertContextLoadFails(BeanInitializationException.class, "must be an absolute path"); } - public @Test void defaultCacheDirectoryIsAFile() throws IOException { + @Test + void defaultCacheDirectoryIsAFile() throws IOException { File file = new File(tmpDir, "file"); assertTrue(file.createNewFile()); runner = runner.withPropertyValues("gwc.cache-directory=" + file.getAbsolutePath()); assertContextLoadFails(BeanInitializationException.class, "is not a directory"); } - public @Test void contextLoads() throws IOException { + @Test + void contextLoads() throws IOException { runner.run( context -> { assertTrue(context.isTypeMatch("gwcXmlConfig", CloudGwcXmlConfiguration.class)); diff --git a/src/gwc/backends/src/test/java/org/geoserver/cloud/gwc/config/blobstore/AzureBlobStoreTest.java b/src/gwc/backends/src/test/java/org/geoserver/cloud/gwc/config/blobstore/AzureBlobStoreTest.java index 27a104306..e21965485 100644 --- a/src/gwc/backends/src/test/java/org/geoserver/cloud/gwc/config/blobstore/AzureBlobStoreTest.java +++ b/src/gwc/backends/src/test/java/org/geoserver/cloud/gwc/config/blobstore/AzureBlobStoreTest.java @@ -5,7 +5,6 @@ package org.geoserver.cloud.gwc.config.blobstore; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -36,7 +35,7 @@ * @see AzuriteContainer */ @Testcontainers -public class AzureBlobStoreTest { +class AzureBlobStoreTest { @Container static AzuriteContainer azurite = new AzuriteContainer(); @@ -74,14 +73,16 @@ protected AzureBlobStoreInfo newAzureBlobStoreInfo() { stubAppContext.close(); } - public @Test void createBlobStore() throws StorageException { + @Test + void createBlobStore() throws StorageException { AzureBlobStoreInfo info = newAzureBlobStoreInfo(); BlobStore store = info.createInstance(mock(TileLayerDispatcher.class), new MemoryLockProvider()); assertThat(store).isInstanceOf(AzureBlobStore.class); } - public @Test void testPutGet() throws Exception { + @Test + void testPutGet() throws Exception { TileLayerDispatcher layers = mock(TileLayerDispatcher.class); AzureBlobStoreInfo info = newAzureBlobStoreInfo(); @@ -98,7 +99,7 @@ protected AzureBlobStoreInfo newAzureBlobStoreInfo() { TileLayer tileLayer = mock(TileLayer.class); when(tileLayer.getId()).thenReturn(layerName); - when(layers.getTileLayer(eq(layerName))).thenReturn(tileLayer); + when(layers.getTileLayer(layerName)).thenReturn(tileLayer); TileObject tile = TileObject.createCompleteTileObject( diff --git a/src/gwc/backends/src/test/java/org/geoserver/cloud/gwc/config/blobstore/AzureBlobStoreXmlConfigurationTest.java b/src/gwc/backends/src/test/java/org/geoserver/cloud/gwc/config/blobstore/AzureBlobStoreXmlConfigurationTest.java index 3bffa7bf6..17f81a5f8 100644 --- a/src/gwc/backends/src/test/java/org/geoserver/cloud/gwc/config/blobstore/AzureBlobStoreXmlConfigurationTest.java +++ b/src/gwc/backends/src/test/java/org/geoserver/cloud/gwc/config/blobstore/AzureBlobStoreXmlConfigurationTest.java @@ -10,7 +10,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -95,7 +94,7 @@ void testOnBlobStoreEvent_Created() throws Exception { remote.addBlobStore(bsi); assertTrue(remote.getBlobStore(bsi.getName()).isPresent()); assertFalse(local.getBlobStore(bsi.getName()).isPresent()); - verify(remoteListener).handleAddBlobStore(eq(bsi)); + verify(remoteListener).handleAddBlobStore(bsi); final Object unknownSource = new Object(); BlobStoreEvent event = new BlobStoreEvent(unknownSource); @@ -105,7 +104,7 @@ void testOnBlobStoreEvent_Created() throws Exception { local.onBlobStoreEvent(event); BlobStoreInfo actual = local.getBlobStore(bsi.getName()).orElse(null); assertEquals(bsi, actual); - verify(localListener).handleAddBlobStore(eq(bsi)); + verify(localListener).handleAddBlobStore(bsi); } @Test @@ -137,7 +136,7 @@ void testOnBlobStoreEvent_Modified() throws Exception { bsi.setServiceURL("http://fake/modified"); remote.modifyBlobStore(bsi); - verify(remoteListener).handleModifyBlobStore(eq(bsi)); + verify(remoteListener).handleModifyBlobStore(bsi); final Object unknownSource = new Object(); BlobStoreEvent event = new BlobStoreEvent(unknownSource); @@ -147,7 +146,7 @@ void testOnBlobStoreEvent_Modified() throws Exception { local.onBlobStoreEvent(event); BlobStoreInfo actual = local.getBlobStore(bsi.getName()).orElse(null); assertEquals(bsi, actual); - verify(localListener).handleModifyBlobStore(eq(bsi)); + verify(localListener).handleModifyBlobStore(bsi); } protected AzureBlobStoreInfo newAzureBlobStoreInfo() { @@ -213,7 +212,7 @@ void testOnBlobStoreEvent_Deleted() throws Exception { remote.removeBlobStore(bsi.getName()); assertFalse(remote.getBlobStore(bsi.getName()).isPresent()); assertTrue(local.getBlobStore(bsi.getName()).isPresent()); - verify(remoteListener).handleRemoveBlobStore(eq(bsi)); + verify(remoteListener).handleRemoveBlobStore(bsi); final Object unknownSource = new Object(); BlobStoreEvent event = new BlobStoreEvent(unknownSource); @@ -222,6 +221,6 @@ void testOnBlobStoreEvent_Deleted() throws Exception { local.onBlobStoreEvent(event); assertFalse(local.getBlobStore(bsi.getName()).isPresent()); - verify(localListener).handleRemoveBlobStore(eq(bsi)); + verify(localListener).handleRemoveBlobStore(bsi); } } diff --git a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/GeoServerIntegrationConfiguration.java b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/GeoServerIntegrationConfiguration.java index 7e9b35ed6..7de9fa13f 100644 --- a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/GeoServerIntegrationConfiguration.java +++ b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/GeoServerIntegrationConfiguration.java @@ -22,6 +22,9 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; import org.springframework.context.annotation.Primary; +import org.springframework.web.context.WebApplicationContext; + +import java.util.Optional; import javax.annotation.PostConstruct; @@ -68,7 +71,8 @@ TileLayerCatalog cachingTileLayerCatalog(ResourceStoreTileLayerCatalog delegate) @Bean ResourceStoreTileLayerCatalog resourceStoreTileLayerCatalog( - @Qualifier("resourceStoreImpl") ResourceStore resourceStore) { - return new ResourceStoreTileLayerCatalog(resourceStore); + @Qualifier("resourceStoreImpl") ResourceStore resourceStore, + Optional webappCtx) { + return new ResourceStoreTileLayerCatalog(resourceStore, webappCtx); } } diff --git a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/GeoWebCacheCoreConfiguration.java b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/GeoWebCacheCoreConfiguration.java index b86f0059b..a4b66ccbe 100644 --- a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/GeoWebCacheCoreConfiguration.java +++ b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/GeoWebCacheCoreConfiguration.java @@ -15,7 +15,6 @@ import org.geoserver.platform.resource.Resource; import org.geoserver.platform.resource.ResourceStore; import org.geoserver.platform.resource.Resources; -import org.geowebcache.config.ConfigurationException; import org.geowebcache.config.ConfigurationResourceProvider; import org.geowebcache.config.XMLConfiguration; import org.geowebcache.config.XMLFileResourceProvider; @@ -165,8 +164,7 @@ private Supplier gwcDefaultConfigDirectory( @Bean ConfigurationResourceProvider gwcXmlConfigResourceProvider( GeoWebCacheConfigurationProperties config, - @Qualifier("resourceStoreImpl") ResourceStore resourceStore) - throws ConfigurationException { + @Qualifier("resourceStoreImpl") ResourceStore resourceStore) { Supplier configDirSupplier = this.gwcDefaultConfigDirectory(config, resourceStore); @@ -291,7 +289,8 @@ protected ServletRequest adaptRequest(HttpServletRequest request) { final String pathInfo = requestURI.substring(pathToGwc.length()); return new HttpServletRequestWrapper(request) { - public @Override String getPathInfo() { + @Override + public String getPathInfo() { return pathInfo; } }; diff --git a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/GeoWebCacheLocalEventsConfiguration.java b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/GeoWebCacheLocalEventsConfiguration.java index 406f3941e..4d9ba1b8e 100644 --- a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/GeoWebCacheLocalEventsConfiguration.java +++ b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/GeoWebCacheLocalEventsConfiguration.java @@ -5,6 +5,9 @@ package org.geoserver.cloud.gwc.config.core; import org.geoserver.cloud.gwc.event.TileLayerEventPublisher; +import org.geoserver.gwc.layer.TileLayerCatalog; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -15,7 +18,9 @@ public class GeoWebCacheLocalEventsConfiguration { @Bean - TileLayerEventPublisher tileLayerEventPublisher() { - return new TileLayerEventPublisher(); + TileLayerEventPublisher tileLayerEventPublisher( + ApplicationEventPublisher localContextPublisher, + @Qualifier("GeoSeverTileLayerCatalog") TileLayerCatalog tileLayerCatalog) { + return new TileLayerEventPublisher(localContextPublisher, tileLayerCatalog); } } diff --git a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/WebMapServiceCacheSeedingConfiguration.java b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/WebMapServiceCacheSeedingConfiguration.java index 3595f0592..c153712ac 100644 --- a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/WebMapServiceCacheSeedingConfiguration.java +++ b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/WebMapServiceCacheSeedingConfiguration.java @@ -82,10 +82,8 @@ public WebMap getMap(ProceedingJoinPoint joinPoint) throws Throwable { protected boolean isInternalRequestForSeeding(final GetMapRequest request) { final Map rawKvp = request.getRawKvp(); - boolean isSeedingRequest = - rawKvp != null - && rawKvp.containsKey(GeoServerTileLayer.GWC_SEED_INTERCEPT_TOKEN); - return isSeedingRequest; + return rawKvp != null + && rawKvp.containsKey(GeoServerTileLayer.GWC_SEED_INTERCEPT_TOKEN); } } } diff --git a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/event/GeoWebCacheEvent.java b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/event/GeoWebCacheEvent.java index a97ad001f..bc1f5ab2a 100644 --- a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/event/GeoWebCacheEvent.java +++ b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/event/GeoWebCacheEvent.java @@ -21,7 +21,7 @@ public abstract class GeoWebCacheEvent extends ApplicationEvent { private static final long serialVersionUID = 1L; - public static enum Type { + public enum Type { CREATED, MODIFIED, DELETED @@ -30,16 +30,17 @@ public static enum Type { private @Getter @Setter Type eventType; private @Getter @Setter String id; - public GeoWebCacheEvent(Object source) { + protected GeoWebCacheEvent(Object source) { this(source, null); } - public GeoWebCacheEvent(Object source, Type eventType) { + protected GeoWebCacheEvent(Object source, Type eventType) { super(source); this.eventType = eventType; } - public @Override String toString() { + @Override + public String toString() { return String.format( "%s[%s '%s' id: %s timestamp: %s]", getClass().getSimpleName(), getEventType(), getObjectId(), getId(), getTimestamp()); diff --git a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/event/TileLayerEvent.java b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/event/TileLayerEvent.java index 2dad7b375..5ac50ce22 100644 --- a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/event/TileLayerEvent.java +++ b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/event/TileLayerEvent.java @@ -32,7 +32,8 @@ public TileLayerEvent(Object source, @NonNull Type eventType, @NonNull String la this.layerId = layerId; } - public @Override String toString() { + @Override + public String toString() { return String.format("%s[%s]", getClass().getSimpleName(), getLayerId()); } diff --git a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/event/TileLayerEventPublisher.java b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/event/TileLayerEventPublisher.java index 58f3c20ea..3916c0f6a 100644 --- a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/event/TileLayerEventPublisher.java +++ b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/event/TileLayerEventPublisher.java @@ -6,15 +6,11 @@ import com.google.common.annotations.VisibleForTesting; -import lombok.AccessLevel; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import lombok.Setter; import org.geoserver.gwc.layer.TileLayerCatalog; import org.geoserver.gwc.layer.TileLayerCatalogListener; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; @@ -30,13 +26,11 @@ * * @see TileLayerEvent */ +@RequiredArgsConstructor public class TileLayerEventPublisher { - @Setter(value = AccessLevel.PACKAGE) - private @Autowired ApplicationEventPublisher localContextPublisher; - - @Setter(value = AccessLevel.PACKAGE) - private @Autowired @Qualifier("GeoSeverTileLayerCatalog") TileLayerCatalog tileLayerCatalog; + private final @NonNull ApplicationEventPublisher localContextPublisher; + private final @NonNull TileLayerCatalog tileLayerCatalog; private LocalTileEventPublisher tileLayerListener; @@ -67,7 +61,8 @@ TileLayerEvent toEvent(@NonNull String layerId, @NonNull TileLayerCatalogListene static class LocalTileEventPublisher implements TileLayerCatalogListener { private final TileLayerEventPublisher publisher; - public @Override void onEvent(String layerId, TileLayerCatalogListener.Type type) { + @Override + public void onEvent(String layerId, TileLayerCatalogListener.Type type) { TileLayerEvent event = publisher.toEvent(layerId, type); publisher.publish(event); } diff --git a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CachingTileLayerCatalog.java b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CachingTileLayerCatalog.java index 43b35840b..dfcaef64d 100644 --- a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CachingTileLayerCatalog.java +++ b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CachingTileLayerCatalog.java @@ -65,7 +65,8 @@ public void evictById(@NonNull String id) { } } - public @Override synchronized void initialize() { + @Override + public synchronized void initialize() { delegate.initialize(); idCache = cacheManager.getCache(TILE_LAYERS_BY_ID); nameCache = cacheManager.getCache(TILE_LAYERS_BY_NAME); @@ -73,7 +74,8 @@ public void evictById(@NonNull String id) { preLoad(); } - public @Override synchronized void reset() { + @Override + public synchronized void reset() { if (idCache != null) { idCache.clear(); idCache = null; @@ -103,28 +105,34 @@ private void cacheIdentifiers(@NonNull GeoServerTileLayerInfo info) { namesById.put(info.getId(), info.getName()); } - public @Override void addListener(TileLayerCatalogListener listener) { + @Override + public void addListener(TileLayerCatalogListener listener) { delegate.addListener(listener); } - public @Override Set getLayerIds() { + @Override + public Set getLayerIds() { return new HashSet<>(namesById.keySet()); } - public @Override Set getLayerNames() { + @Override + public Set getLayerNames() { return new HashSet<>(namesById.values()); } - public @Override String getLayerId(@NonNull String layerName) { + @Override + public String getLayerId(@NonNull String layerName) { GeoServerTileLayerInfo layer = getLayerByName(layerName); return layer == null ? null : layer.getId(); } - public @Override String getLayerName(@NonNull String layerId) { + @Override + public String getLayerName(@NonNull String layerId) { return namesById.get(layerId); } - public @Override GeoServerTileLayerInfo getLayerById(@NonNull String id) { + @Override + public GeoServerTileLayerInfo getLayerById(@NonNull String id) { try { return idCache.get(id, () -> loadLayerById(id)); } catch (ValueRetrievalException e) { @@ -133,7 +141,8 @@ private void cacheIdentifiers(@NonNull GeoServerTileLayerInfo info) { } } - public @Override GeoServerTileLayerInfo getLayerByName(@NonNull String layerName) { + @Override + public GeoServerTileLayerInfo getLayerByName(@NonNull String layerName) { try { return nameCache.get(layerName, () -> loadLayerByName(layerName)); } catch (ValueRetrievalException e) { @@ -160,19 +169,23 @@ private GeoServerTileLayerInfo loadLayerByName(String name) { return info; } - public @Override GeoServerTileLayerInfo delete(@NonNull String tileLayerId) { + @Override + public GeoServerTileLayerInfo delete(@NonNull String tileLayerId) { return delegate.delete(tileLayerId); } - public @Override GeoServerTileLayerInfo save(@NonNull GeoServerTileLayerInfo newValue) { + @Override + public GeoServerTileLayerInfo save(@NonNull GeoServerTileLayerInfo newValue) { return delegate.save(newValue); } - public @Override boolean exists(@NonNull String layerId) { + @Override + public boolean exists(@NonNull String layerId) { return delegate.exists(layerId); } - public @Override String getPersistenceLocation() { + @Override + public String getPersistenceLocation() { return delegate.getPersistenceLocation(); } } diff --git a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CloudCatalogConfiguration.java b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CloudCatalogConfiguration.java index d0dce3a55..cb6f7a8d1 100644 --- a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CloudCatalogConfiguration.java +++ b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CloudCatalogConfiguration.java @@ -52,7 +52,7 @@ public CloudCatalogConfiguration( (LoadingCache) FieldUtils.readField(this, "layerCache", true); } catch (IllegalAccessException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -84,9 +84,6 @@ public synchronized void addLayer(final TileLayer tl) { private void setMissingConfig(GeoServerTileLayerInfo info, GeoServerTileLayerInfo defaults) { - // defaults.isAutoCacheStyles(); - // defaults.isEnabled(); - // defaults.isInMemoryCached(); String blobStoreId = defaults.getBlobStoreId(); Set cacheWarningSkips = defaults.getCacheWarningSkips(); int expireCache = defaults.getExpireCache(); diff --git a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CloudDefaultStorageFinder.java b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CloudDefaultStorageFinder.java index d8c65e98d..bf0e52b1b 100644 --- a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CloudDefaultStorageFinder.java +++ b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CloudDefaultStorageFinder.java @@ -21,7 +21,8 @@ public class CloudDefaultStorageFinder extends DefaultStorageFinder { static final ApplicationContextProvider NOOP = new ApplicationContextProvider() { - public @Override WebApplicationContext getApplicationContext() { + @Override + public WebApplicationContext getApplicationContext() { return null; } }; @@ -34,11 +35,13 @@ public CloudDefaultStorageFinder(Path defaultCacheDirectory, Environment environ this.environment = environment; } - public @Override String getDefaultPath() throws ConfigurationException { // NOSONAR + @Override + public String getDefaultPath() throws ConfigurationException { // NOSONAR return defaultCacheDirectory.toString(); } - public @Override String findEnvVar(String varStr) { + @Override + public String findEnvVar(String varStr) { return environment.getProperty(varStr); } } diff --git a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CloudGwcXmlConfiguration.java b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CloudGwcXmlConfiguration.java index 0aa7fbff0..8aa233367 100644 --- a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CloudGwcXmlConfiguration.java +++ b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CloudGwcXmlConfiguration.java @@ -76,7 +76,7 @@ public CloudGwcXmlConfiguration( // FieldUtils.readField(this, "blobStoreListeners", true); } catch (IllegalAccessException e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } } @@ -85,9 +85,7 @@ public boolean onGridsetEvent(GridsetEvent event) throws Exception { if (isLocal(event)) return false; switch (event.getEventType()) { - case CREATED: - case DELETED: - case MODIFIED: + case CREATED, DELETED, MODIFIED: reload(event); break; default: @@ -147,7 +145,8 @@ private synchronized void reload(GeoWebCacheEvent event) throws Exception { log.debug("configuration reloaded successfully"); } - public @Override void addGridSet(GridSet gridSet) { + @Override + public void addGridSet(GridSet gridSet) { lock.writeLock().lock(); try { super.addGridSet(gridSet); @@ -157,7 +156,8 @@ private synchronized void reload(GeoWebCacheEvent event) throws Exception { publisher.accept(new GridsetEvent(this, CREATED, gridSet.getName())); } - public @Override void modifyGridSet(GridSet gridSet) { + @Override + public void modifyGridSet(GridSet gridSet) { lock.writeLock().lock(); try { super.modifyGridSet(gridSet); @@ -167,7 +167,8 @@ private synchronized void reload(GeoWebCacheEvent event) throws Exception { publisher.accept(new GridsetEvent(this, MODIFIED, gridSet.getName())); } - public @Override void removeGridSet(String gridSetName) { + @Override + public void removeGridSet(String gridSetName) { lock.writeLock().lock(); try { super.removeGridSet(gridSetName); @@ -177,7 +178,8 @@ private synchronized void reload(GeoWebCacheEvent event) throws Exception { publisher.accept(new GridsetEvent(this, DELETED, gridSetName)); } - public @Override void addBlobStore(final BlobStoreInfo bs) throws IllegalArgumentException { + @Override + public void addBlobStore(final BlobStoreInfo bs) throws IllegalArgumentException { lock.writeLock().lock(); try { super.addBlobStore(bs); @@ -187,7 +189,8 @@ private synchronized void reload(GeoWebCacheEvent event) throws Exception { publisher.accept(new BlobStoreEvent(this, CREATED, bs.getName())); } - public @Override void modifyBlobStore(final BlobStoreInfo bs) { + @Override + public void modifyBlobStore(final BlobStoreInfo bs) { lock.writeLock().lock(); try { super.modifyBlobStore(bs); @@ -197,7 +200,8 @@ private synchronized void reload(GeoWebCacheEvent event) throws Exception { publisher.accept(new BlobStoreEvent(this, MODIFIED, bs.getName())); } - public @Override void renameBlobStore(final String oldName, final String newName) { + @Override + public void renameBlobStore(final String oldName, final String newName) { lock.writeLock().lock(); try { super.renameBlobStore(oldName, newName); @@ -207,7 +211,8 @@ private synchronized void reload(GeoWebCacheEvent event) throws Exception { publisher.accept(new BlobStoreEvent(this, MODIFIED, oldName, newName)); } - public @Override void removeBlobStore(final String blobStoreName) { + @Override + public void removeBlobStore(final String blobStoreName) { lock.writeLock().lock(); try { super.removeBlobStore(blobStoreName); @@ -233,7 +238,8 @@ private T runInReadLock(Supplier action) { } } - public @Override void afterPropertiesSet() throws GeoWebCacheException { + @Override + public void afterPropertiesSet() throws GeoWebCacheException { lock.writeLock().lock(); try { super.afterPropertiesSet(); @@ -242,11 +248,13 @@ private T runInReadLock(Supplier action) { } } - public @Override Boolean isRuntimeStatsEnabled() { + @Override + public Boolean isRuntimeStatsEnabled() { return runInReadLock(super::isRuntimeStatsEnabled); } - public @Override void setRuntimeStatsEnabled(Boolean isEnabled) throws IOException { + @Override + public void setRuntimeStatsEnabled(Boolean isEnabled) throws IOException { lock.writeLock().lock(); try { super.setRuntimeStatsEnabled(isEnabled); @@ -255,11 +263,13 @@ private T runInReadLock(Supplier action) { } } - public @Override ServiceInformation getServiceInformation() { + @Override + public ServiceInformation getServiceInformation() { return runInReadLock(super::getServiceInformation); } - public @Override void setServiceInformation(ServiceInformation serviceInfo) throws IOException { + @Override + public void setServiceInformation(ServiceInformation serviceInfo) throws IOException { lock.writeLock().lock(); try { super.setServiceInformation(serviceInfo); @@ -268,7 +278,8 @@ private T runInReadLock(Supplier action) { } } - public @Override void setDefaultValues(TileLayer layer) { + @Override + public void setDefaultValues(TileLayer layer) { lock.writeLock().lock(); try { super.setDefaultValues(layer); @@ -277,7 +288,8 @@ private T runInReadLock(Supplier action) { } } - public @Override void addLayer(TileLayer tl) throws IllegalArgumentException { + @Override + public void addLayer(TileLayer tl) throws IllegalArgumentException { lock.writeLock().lock(); try { super.addLayer(tl); @@ -286,7 +298,8 @@ private T runInReadLock(Supplier action) { } } - public @Override void modifyLayer(TileLayer tl) throws NoSuchElementException { + @Override + public void modifyLayer(TileLayer tl) throws NoSuchElementException { lock.writeLock().lock(); try { super.modifyLayer(tl); @@ -295,7 +308,8 @@ private T runInReadLock(Supplier action) { } } - public @Override void renameLayer(String oldName, String newName) + @Override + public void renameLayer(String oldName, String newName) throws NoSuchElementException, IllegalArgumentException { lock.writeLock().lock(); try { @@ -305,7 +319,8 @@ private T runInReadLock(Supplier action) { } } - public @Override void removeLayer(final String layerName) + @Override + public void removeLayer(final String layerName) throws NoSuchElementException, IllegalArgumentException { lock.writeLock().lock(); try { @@ -315,45 +330,55 @@ private T runInReadLock(Supplier action) { } } - public @Override Collection getLayers() { + @Override + public Collection getLayers() { return runInReadLock(super::getLayers); } - public @Override Optional getLayer(String layerName) { + @Override + public Optional getLayer(String layerName) { return runInReadLock(() -> super.getLayer(layerName)); } @SuppressWarnings("deprecation") - public @Override TileLayer getTileLayer(String layerName) { + @Override + public TileLayer getTileLayer(String layerName) { return runInReadLock(() -> super.getTileLayer(layerName)); } @SuppressWarnings("deprecation") - public @Override TileLayer getTileLayerById(String layerId) { + @Override + public TileLayer getTileLayerById(String layerId) { return runInReadLock(() -> super.getTileLayerById(layerId)); } - public @Override boolean containsLayer(String layerId) { + @Override + public boolean containsLayer(String layerId) { return runInReadLock(() -> super.containsLayer(layerId)); } - public @Override int getLayerCount() { + @Override + public int getLayerCount() { return runInReadLock(super::getLayerCount); } - public @Override Set getLayerNames() { + @Override + public Set getLayerNames() { return runInReadLock(super::getLayerNames); } - public @Override String getVersion() { + @Override + public String getVersion() { return runInReadLock(super::getVersion); } - public @Override Boolean isFullWMS() { + @Override + public Boolean isFullWMS() { return runInReadLock(super::isFullWMS); } - public @Override void setFullWMS(Boolean isFullWMS) throws IOException { + @Override + public void setFullWMS(Boolean isFullWMS) throws IOException { lock.writeLock().lock(); try { super.setFullWMS(isFullWMS); @@ -362,31 +387,38 @@ private T runInReadLock(Supplier action) { } } - public @Override List getBlobStores() { + @Override + public List getBlobStores() { return runInReadLock(super::getBlobStores); } - public @Override int getBlobStoreCount() { + @Override + public int getBlobStoreCount() { return runInReadLock(super::getBlobStoreCount); } - public @Override Set getBlobStoreNames() { + @Override + public Set getBlobStoreNames() { return runInReadLock(super::getBlobStoreNames); } - public @Override Optional getBlobStore(String name) { + @Override + public Optional getBlobStore(String name) { return runInReadLock(() -> super.getBlobStore(name)); } - public @Override boolean containsBlobStore(String name) { + @Override + public boolean containsBlobStore(String name) { return runInReadLock(() -> super.containsBlobStore(name)); } - public @Override LockProvider getLockProvider() { + @Override + public LockProvider getLockProvider() { return runInReadLock(super::getLockProvider); } - public @Override void setLockProvider(LockProvider lockProvider) throws IOException { + @Override + public void setLockProvider(LockProvider lockProvider) throws IOException { lock.writeLock().lock(); try { super.setLockProvider(lockProvider); @@ -395,11 +427,13 @@ private T runInReadLock(Supplier action) { } } - public @Override Boolean isWmtsCiteCompliant() { + @Override + public Boolean isWmtsCiteCompliant() { return runInReadLock(super::isWmtsCiteCompliant); } - public @Override void setWmtsCiteCompliant(Boolean wmtsCiteStrictCompliant) throws IOException { + @Override + public void setWmtsCiteCompliant(Boolean wmtsCiteStrictCompliant) throws IOException { lock.writeLock().lock(); try { super.setWmtsCiteCompliant(wmtsCiteStrictCompliant); @@ -408,11 +442,13 @@ private T runInReadLock(Supplier action) { } } - public @Override Integer getBackendTimeout() { + @Override + public Integer getBackendTimeout() { return runInReadLock(super::getBackendTimeout); } - public @Override void setBackendTimeout(Integer backendTimeout) throws IOException { + @Override + public void setBackendTimeout(Integer backendTimeout) throws IOException { lock.writeLock().lock(); try { super.setBackendTimeout(backendTimeout); @@ -421,11 +457,13 @@ private T runInReadLock(Supplier action) { } } - public @Override Boolean isCacheBypassAllowed() { + @Override + public Boolean isCacheBypassAllowed() { return runInReadLock(super::isCacheBypassAllowed); } - public @Override void setCacheBypassAllowed(Boolean cacheBypassAllowed) throws IOException { + @Override + public void setCacheBypassAllowed(Boolean cacheBypassAllowed) throws IOException { lock.writeLock().lock(); try { super.setCacheBypassAllowed(cacheBypassAllowed); @@ -434,11 +472,13 @@ private T runInReadLock(Supplier action) { } } - public @Override Optional getGridSet(String name) { + @Override + public Optional getGridSet(String name) { return runInReadLock(() -> super.getGridSet(name)); } - public @Override Collection getGridSets() { + @Override + public Collection getGridSets() { return runInReadLock(super::getGridSets); } } diff --git a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CloudXMLResourceProvider.java b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CloudXMLResourceProvider.java index 594d382f5..d8110bb5b 100644 --- a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CloudXMLResourceProvider.java +++ b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/CloudXMLResourceProvider.java @@ -69,7 +69,7 @@ public void setTemplate(final String templateLocation) { this.templateLocation = templateLocation; } - private Resource findConfigFile() throws IOException { + private Resource findConfigFile() { Resource dir = getConfigDirectory(); return dir.get(configFileName); } diff --git a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/ResourceStoreTileLayerCatalog.java b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/ResourceStoreTileLayerCatalog.java index a4c788b09..9ef98fa09 100644 --- a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/ResourceStoreTileLayerCatalog.java +++ b/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/repository/ResourceStoreTileLayerCatalog.java @@ -25,7 +25,6 @@ import org.geowebcache.config.ContextualConfigurationProvider.Context; import org.geowebcache.config.XMLConfiguration; import org.geowebcache.storage.blobstore.file.FilePathUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.context.WebApplicationContext; import java.io.IOException; @@ -67,7 +66,7 @@ public class ResourceStoreTileLayerCatalog implements TileLayerCatalog { * to lookup implementations of {@link org.geowebcache.config.XMLConfigurationProvider}, such as * {@code S3BlobStoreConfigProvider}, etc. This could be improved. */ - private @Autowired WebApplicationContext applicationContext; + private final Optional applicationContext; private final AtomicBoolean initialized = new AtomicBoolean(); private final List listeners = new CopyOnWriteArrayList<>(); @@ -76,43 +75,51 @@ public class ResourceStoreTileLayerCatalog implements TileLayerCatalog { private XStream serializer; private String baseDirectory; - public @Override void reset() { + @Override + public void reset() { if (initialized.compareAndSet(true, false)) { xstreamProvider = null; serializer = null; } } - public @Override void initialize() { + @Override + public void initialize() { if (initialized.compareAndSet(false, true)) { this.baseDirectory = "gwc-layers"; this.xstreamProvider = () -> XMLConfiguration.getConfiguredXStreamWithContext( - new SecureXStream(), applicationContext, Context.PERSIST); + new SecureXStream(), + applicationContext.orElse(null), + Context.PERSIST); this.serializer = newXStream(); } } - public @Override void addListener(TileLayerCatalogListener listener) { + @Override + public void addListener(TileLayerCatalogListener listener) { if (null != listener) listeners.add(listener); } - public @Override Set getLayerIds() { + @Override + public Set getLayerIds() { checkInitialized(); try (Stream all = findAll()) { return all.map(GeoServerTileLayerInfo::getId).collect(Collectors.toSet()); } } - public @Override Set getLayerNames() { + @Override + public Set getLayerNames() { checkInitialized(); try (Stream all = findAll()) { return all.map(GeoServerTileLayerInfo::getName).collect(Collectors.toSet()); } } - public @Override String getLayerId(@NonNull String layerName) { + @Override + public String getLayerId(@NonNull String layerName) { checkInitialized(); try (Stream all = findAll()) { return all.filter(l -> layerName.equals(l.getName())) @@ -122,7 +129,8 @@ public class ResourceStoreTileLayerCatalog implements TileLayerCatalog { } } - public @Override String getLayerName(String layerId) { + @Override + public String getLayerName(String layerId) { checkInitialized(); try (Stream all = findAll()) { return all.filter(l -> layerId.equals(l.getId())) @@ -132,19 +140,22 @@ public class ResourceStoreTileLayerCatalog implements TileLayerCatalog { } } - public @Override GeoServerTileLayerInfo getLayerById(@NonNull String id) { + @Override + public GeoServerTileLayerInfo getLayerById(@NonNull String id) { checkInitialized(); return findFile(id).map(this::depersist).orElse(null); } - public @Override GeoServerTileLayerInfo getLayerByName(String layerName) { + @Override + public GeoServerTileLayerInfo getLayerByName(String layerName) { checkInitialized(); try (Stream all = findAll()) { return all.filter(l -> layerName.equals(l.getName())).findFirst().orElse(null); } } - public @Override GeoServerTileLayerInfo delete(@NonNull String tileLayerId) { + @Override + public GeoServerTileLayerInfo delete(@NonNull String tileLayerId) { checkInitialized(); GeoServerTileLayerInfo info = null; Optional resource = findFile(tileLayerId); @@ -164,7 +175,8 @@ public class ResourceStoreTileLayerCatalog implements TileLayerCatalog { return null; } - public @Override GeoServerTileLayerInfo save(@NonNull GeoServerTileLayerInfo newValue) { + @Override + public GeoServerTileLayerInfo save(@NonNull GeoServerTileLayerInfo newValue) { checkInitialized(); final String layerId = newValue.getId(); Objects.requireNonNull(layerId); @@ -175,12 +187,14 @@ public class ResourceStoreTileLayerCatalog implements TileLayerCatalog { return prev; } - public @Override boolean exists(String layerId) { + @Override + public boolean exists(String layerId) { checkInitialized(); return findFile(layerId).isPresent(); } - public @Override String getPersistenceLocation() { + @Override + public String getPersistenceLocation() { return resourceStore.get(baseDirectory).path(); } @@ -271,13 +285,13 @@ private Stream findAllTileLayerResources(Path basePath) { throw new UncheckedIOException(e); } - final Resource baseDirectory = baseDirectory(); + final Resource baseDir = baseDirectory(); return Streams.stream(directoryStream) .onClose(() -> closeSilently(directoryStream)) .map(Path::getFileName) .map(Path::toString) .peek(name -> log.trace("found potential tile layer file {}", name)) - .map(baseDirectory::get); + .map(baseDir::get); } private void closeSilently(DirectoryStream directoryStream) { @@ -321,13 +335,13 @@ private void notify(TileLayerCatalogListener l, String layerId, Type eventType) } private XStream newXStream() { - XStream serializer = this.xstreamProvider.get(); - serializer.allowTypeHierarchy(GeoServerTileLayerInfo.class); - serializer.allowTypes(new Class[] {DimensionWarning.WarningType.class}); + XStream xstream = this.xstreamProvider.get(); + xstream.allowTypeHierarchy(GeoServerTileLayerInfo.class); + xstream.allowTypes(new Class[] {DimensionWarning.WarningType.class}); // have to use a string here because UnmodifiableSet is private - serializer.allowTypes(new String[] {"java.util.Collections$UnmodifiableSet"}); - serializer.addDefaultImplementation(LinkedHashSet.class, Set.class); - serializer.alias("warning", DimensionWarning.WarningType.class); - return serializer; + xstream.allowTypes(new String[] {"java.util.Collections$UnmodifiableSet"}); + xstream.addDefaultImplementation(LinkedHashSet.class, Set.class); + xstream.alias("warning", DimensionWarning.WarningType.class); + return xstream; } } diff --git a/src/gwc/core/src/test/java/org/geoserver/cloud/gwc/repository/CloudGwcXmlConfigurationTest.java b/src/gwc/core/src/test/java/org/geoserver/cloud/gwc/repository/CloudGwcXmlConfigurationTest.java index 5c3afe136..c3aee1e96 100644 --- a/src/gwc/core/src/test/java/org/geoserver/cloud/gwc/repository/CloudGwcXmlConfigurationTest.java +++ b/src/gwc/core/src/test/java/org/geoserver/cloud/gwc/repository/CloudGwcXmlConfigurationTest.java @@ -13,7 +13,6 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -273,7 +272,7 @@ void testOnBlobStoreEvent_Created() throws Exception { remote.addBlobStore(bsi); assertTrue(remote.getBlobStore(bsi.getName()).isPresent()); assertFalse(local.getBlobStore(bsi.getName()).isPresent()); - verify(remoteListener).handleAddBlobStore(eq(bsi)); + verify(remoteListener).handleAddBlobStore(bsi); final Object unknownSource = new Object(); BlobStoreEvent event = new BlobStoreEvent(unknownSource); @@ -283,7 +282,7 @@ void testOnBlobStoreEvent_Created() throws Exception { local.onBlobStoreEvent(event); BlobStoreInfo actual = local.getBlobStore(bsi.getName()).orElse(null); assertEquals(bsi, actual); - verify(localListener).handleAddBlobStore(eq(bsi)); + verify(localListener).handleAddBlobStore(bsi); } @Test @@ -308,7 +307,7 @@ void testOnBlobStoreEvent_Modified_FileBlobStore() throws Exception { bsi.setBaseDirectory("/tmp/newdir"); remote.modifyBlobStore(bsi); - verify(remoteListener).handleModifyBlobStore(eq(bsi)); + verify(remoteListener).handleModifyBlobStore(bsi); final Object unknownSource = new Object(); BlobStoreEvent event = new BlobStoreEvent(unknownSource); @@ -318,7 +317,7 @@ void testOnBlobStoreEvent_Modified_FileBlobStore() throws Exception { local.onBlobStoreEvent(event); BlobStoreInfo actual = local.getBlobStore(bsi.getName()).orElse(null); assertEquals(bsi, actual); - verify(localListener).handleModifyBlobStore(eq(bsi)); + verify(localListener).handleModifyBlobStore(bsi); } @Test @@ -373,7 +372,7 @@ void testOnBlobStoreEvent_Deleted() throws Exception { remote.removeBlobStore(bsi.getName()); assertFalse(remote.getBlobStore(bsi.getName()).isPresent()); assertTrue(local.getBlobStore(bsi.getName()).isPresent()); - verify(remoteListener).handleRemoveBlobStore(eq(bsi)); + verify(remoteListener).handleRemoveBlobStore(bsi); final Object unknownSource = new Object(); BlobStoreEvent event = new BlobStoreEvent(unknownSource); @@ -382,7 +381,7 @@ void testOnBlobStoreEvent_Deleted() throws Exception { local.onBlobStoreEvent(event); assertFalse(local.getBlobStore(bsi.getName()).isPresent()); - verify(localListener).handleRemoveBlobStore(eq(bsi)); + verify(localListener).handleRemoveBlobStore(bsi); } private void expect(GridsetEvent expected) { diff --git a/src/gwc/core/src/test/java/org/geoserver/cloud/gwc/repository/ResourceStoreTileLayerCatalogTest.java b/src/gwc/core/src/test/java/org/geoserver/cloud/gwc/repository/ResourceStoreTileLayerCatalogTest.java index c410311b3..a5e22cc88 100644 --- a/src/gwc/core/src/test/java/org/geoserver/cloud/gwc/repository/ResourceStoreTileLayerCatalogTest.java +++ b/src/gwc/core/src/test/java/org/geoserver/cloud/gwc/repository/ResourceStoreTileLayerCatalogTest.java @@ -24,6 +24,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import org.springframework.web.context.WebApplicationContext; import java.io.File; import java.io.IOException; @@ -31,6 +32,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; +import java.util.Optional; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; @@ -49,12 +51,13 @@ class ResourceStoreTileLayerCatalogTest { void setUp() throws Exception { resourceLoader = new GeoServerResourceLoader(baseDirectory); new File(baseDirectory, "gwc-layers").mkdir(); - catalog = new ResourceStoreTileLayerCatalog(resourceLoader); + Optional webappCtx = Optional.empty(); + catalog = new ResourceStoreTileLayerCatalog(resourceLoader, webappCtx); catalog.initialize(); } @Test - public void testGetLayerById() { + void testGetLayerById() { GeoServerTileLayerInfo info = new GeoServerTileLayerInfoImpl(); info.setId("id1"); info.setName("name1"); @@ -65,7 +68,7 @@ public void testGetLayerById() { } @Test - public void testGetLayerByName() { + void testGetLayerByName() { GeoServerTileLayerInfo info = new GeoServerTileLayerInfoImpl(); info.setId("id1"); info.setName("name1"); @@ -76,7 +79,7 @@ public void testGetLayerByName() { } @Test - public void testDelete() { + void testDelete() { GeoServerTileLayerInfo info = new GeoServerTileLayerInfoImpl(); info.setId("id1"); info.setName("name1"); @@ -93,7 +96,7 @@ public void testDelete() { } @Test - public void testSave() { + void testSave() { final GeoServerTileLayerInfo original; { final GeoServerTileLayerInfo info = new GeoServerTileLayerInfoImpl(); @@ -126,7 +129,7 @@ public void testSave() { } @Test - public void testSaveWithEmptyStyleParamFilter() { + void testSaveWithEmptyStyleParamFilter() { final GeoServerTileLayerInfo original; { final GeoServerTileLayerInfo info = new GeoServerTileLayerInfoImpl(); @@ -163,7 +166,7 @@ public void testSaveWithEmptyStyleParamFilter() { } @Test - public void testEvents() throws IOException, InterruptedException { + void testEvents() throws IOException, InterruptedException { AtomicBoolean hasBeenCreated = new AtomicBoolean(false); AtomicBoolean hasBeenModified = new AtomicBoolean(false); AtomicBoolean hasBeenDeleted = new AtomicBoolean(false); @@ -216,7 +219,7 @@ public void testEvents() throws IOException, InterruptedException { } @Test - public void testSavedXML() throws Exception { + void testSavedXML() throws Exception { // checking that the persistence looks as expected final GeoServerTileLayerInfo original; { diff --git a/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/GeoWebCacheRemoteEventsBroker.java b/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/GeoWebCacheRemoteEventsBroker.java index 41a02ec58..b1c2f1c59 100644 --- a/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/GeoWebCacheRemoteEventsBroker.java +++ b/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/GeoWebCacheRemoteEventsBroker.java @@ -78,7 +78,8 @@ private boolean isFromSelf(RemoteGeoWebCacheEvent remoteEvent) { return busServiceMatcher.apply(remoteEvent); } - public @Override String toString() { + @Override + public String toString() { return String.format("%s(%s)", getClass().getSimpleName(), originService()); } } diff --git a/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteBlobStoreEvent.java b/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteBlobStoreEvent.java index 042385bde..70ca071b1 100644 --- a/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteBlobStoreEvent.java +++ b/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteBlobStoreEvent.java @@ -4,6 +4,7 @@ */ package org.geoserver.cloud.gwc.bus; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -13,6 +14,7 @@ * @since 1.0 */ @NoArgsConstructor +@EqualsAndHashCode(callSuper = true) public class RemoteBlobStoreEvent extends RemoteGeoWebCacheEvent { private static final long serialVersionUID = 1L; diff --git a/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteEventMapper.java b/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteEventMapper.java index 25d5b3b2a..adcceed9c 100644 --- a/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteEventMapper.java +++ b/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteEventMapper.java @@ -25,23 +25,17 @@ default RemoteGeoWebCacheEvent toRemote( @NonNull GeoWebCacheEvent local, @NonNull Object source, @NonNull String originService) { - if (local instanceof TileLayerEvent) - return toRemote((TileLayerEvent) local, source, originService); - if (local instanceof GridsetEvent) - return toRemote((GridsetEvent) local, source, originService); - if (local instanceof BlobStoreEvent) - return toRemote((BlobStoreEvent) local, source, originService); + if (local instanceof TileLayerEvent tle) return toRemote(tle, source, originService); + if (local instanceof GridsetEvent gse) return toRemote(gse, source, originService); + if (local instanceof BlobStoreEvent bse) return toRemote(bse, source, originService); throw new IllegalArgumentException("unknown GeoWebCacheEvent type: " + local); } default GeoWebCacheEvent toLocal( @NonNull RemoteGeoWebCacheEvent remote, @NonNull Object source) { - if (remote instanceof RemoteTileLayerEvent) - return toLocal((RemoteTileLayerEvent) remote, source); - if (remote instanceof RemoteGridsetEvent) - return toLocal((RemoteGridsetEvent) remote, source); - if (remote instanceof RemoteBlobStoreEvent) - return toLocal((RemoteBlobStoreEvent) remote, source); + if (remote instanceof RemoteTileLayerEvent remoteTle) return toLocal(remoteTle, source); + if (remote instanceof RemoteGridsetEvent remoteGse) return toLocal(remoteGse, source); + if (remote instanceof RemoteBlobStoreEvent remoteBse) return toLocal(remoteBse, source); throw new IllegalArgumentException("unknown RemoteGeoWebCacheEvent type: " + remote); } diff --git a/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteGeoWebCacheEvent.java b/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteGeoWebCacheEvent.java index dd9dcfc64..8b560f00d 100644 --- a/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteGeoWebCacheEvent.java +++ b/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteGeoWebCacheEvent.java @@ -4,6 +4,7 @@ */ package org.geoserver.cloud.gwc.bus; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -16,11 +17,12 @@ * @since 1.0 */ @NoArgsConstructor +@EqualsAndHashCode(callSuper = true) public abstract class RemoteGeoWebCacheEvent extends RemoteApplicationEvent { private static final long serialVersionUID = 1L; - public static enum Type { + public enum Type { CREATED, MODIFIED, DELETED @@ -30,17 +32,18 @@ public static enum Type { private @Getter @Setter Type eventType; - public RemoteGeoWebCacheEvent(Object source, @NonNull String originService) { + protected RemoteGeoWebCacheEvent(Object source, @NonNull String originService) { super(source, originService, ALL); } - public RemoteGeoWebCacheEvent( + protected RemoteGeoWebCacheEvent( Object source, @NonNull String originService, @NonNull Type eventType) { super(source, originService, ALL); this.eventType = eventType; } - public @Override String toString() { + @Override + public String toString() { return String.format( "%s[%s '%s' id: %s origin: %s destination: %s timestamp: %s]", getClass().getSimpleName(), diff --git a/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteGridsetEvent.java b/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteGridsetEvent.java index 201d0f9a2..cc35dafb9 100644 --- a/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteGridsetEvent.java +++ b/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteGridsetEvent.java @@ -4,6 +4,7 @@ */ package org.geoserver.cloud.gwc.bus; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -13,6 +14,7 @@ * @since 1.0 */ @NoArgsConstructor +@EqualsAndHashCode(callSuper = true) public class RemoteGridsetEvent extends RemoteGeoWebCacheEvent { private static final long serialVersionUID = 1L; diff --git a/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteTileLayerEvent.java b/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteTileLayerEvent.java index feda5e2d6..40791e1cd 100644 --- a/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteTileLayerEvent.java +++ b/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/RemoteTileLayerEvent.java @@ -4,6 +4,7 @@ */ package org.geoserver.cloud.gwc.bus; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -19,6 +20,7 @@ * @since 1.0 */ @NoArgsConstructor +@EqualsAndHashCode(callSuper = true) public class RemoteTileLayerEvent extends RemoteGeoWebCacheEvent { private static final long serialVersionUID = 1L; diff --git a/src/gwc/services/src/main/java/org/geoserver/cloud/gwc/config/services/RESTConfigConfiguration.java b/src/gwc/services/src/main/java/org/geoserver/cloud/gwc/config/services/RESTConfigConfiguration.java index d530c0a84..485ebd3b0 100644 --- a/src/gwc/services/src/main/java/org/geoserver/cloud/gwc/config/services/RESTConfigConfiguration.java +++ b/src/gwc/services/src/main/java/org/geoserver/cloud/gwc/config/services/RESTConfigConfiguration.java @@ -66,9 +66,9 @@ public class RESTConfigConfiguration { * * @param appCtx */ - @SuppressWarnings("rawtypes") @Bean - GWCConverter gwcConverter(ApplicationContextProvider appCtx) { + @SuppressWarnings("rawtypes") + GWCConverter gwcConverter(ApplicationContextProvider appCtx) { return new GWCConverter(appCtx); } diff --git a/src/gwc/services/src/main/java/org/gwc/web/gmaps/GoogleMapsController.java b/src/gwc/services/src/main/java/org/gwc/web/gmaps/GoogleMapsController.java index 841774bca..0cd7191c4 100644 --- a/src/gwc/services/src/main/java/org/gwc/web/gmaps/GoogleMapsController.java +++ b/src/gwc/services/src/main/java/org/gwc/web/gmaps/GoogleMapsController.java @@ -4,8 +4,10 @@ */ package org.gwc.web.gmaps; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import org.geoserver.ows.Dispatcher; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -20,9 +22,10 @@ "/{virtualservice}/gwc/service/gmaps", "/{virtualservice}/{layer}/gwc/service/gmaps" }) +@RequiredArgsConstructor public class GoogleMapsController { - private @Autowired Dispatcher geoserverDispatcher; + private final @NonNull Dispatcher geoserverDispatcher; @GetMapping(path = "/**") public void serviceRequest(HttpServletRequest request, HttpServletResponse response) diff --git a/src/gwc/services/src/main/java/org/gwc/web/kml/KMLController.java b/src/gwc/services/src/main/java/org/gwc/web/kml/KMLController.java index 2908dad43..0f0a8c26a 100644 --- a/src/gwc/services/src/main/java/org/gwc/web/kml/KMLController.java +++ b/src/gwc/services/src/main/java/org/gwc/web/kml/KMLController.java @@ -4,8 +4,10 @@ */ package org.gwc.web.kml; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import org.geoserver.ows.Dispatcher; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -20,9 +22,10 @@ "/{virtualservice}/gwc/service/kml", "/{virtualservice}/{layer}/gwc/service/kml" }) +@RequiredArgsConstructor public class KMLController { - private @Autowired Dispatcher geoserverDispatcher; + private final @NonNull Dispatcher geoserverDispatcher; @GetMapping(path = "/**") public void serviceRequest(HttpServletRequest request, HttpServletResponse response) diff --git a/src/gwc/services/src/main/java/org/gwc/web/mgmaps/MGMapsController.java b/src/gwc/services/src/main/java/org/gwc/web/mgmaps/MGMapsController.java index f67ec7110..36ee05611 100644 --- a/src/gwc/services/src/main/java/org/gwc/web/mgmaps/MGMapsController.java +++ b/src/gwc/services/src/main/java/org/gwc/web/mgmaps/MGMapsController.java @@ -4,8 +4,10 @@ */ package org.gwc.web.mgmaps; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import org.geoserver.ows.Dispatcher; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -20,9 +22,10 @@ "/{virtualservice}/gwc/service/mgmaps", "/{virtualservice}/{layer}/gwc/service/mgmaps" }) +@RequiredArgsConstructor public class MGMapsController { - private @Autowired Dispatcher geoserverDispatcher; + private final @NonNull Dispatcher geoserverDispatcher; @GetMapping(path = "/**") public void serviceRequest(HttpServletRequest request, HttpServletResponse response) diff --git a/src/gwc/services/src/main/java/org/gwc/web/rest/GeoWebCacheController.java b/src/gwc/services/src/main/java/org/gwc/web/rest/GeoWebCacheController.java index b4de323ae..021920b80 100644 --- a/src/gwc/services/src/main/java/org/gwc/web/rest/GeoWebCacheController.java +++ b/src/gwc/services/src/main/java/org/gwc/web/rest/GeoWebCacheController.java @@ -4,10 +4,12 @@ */ package org.gwc.web.rest; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import org.geoserver.gwc.dispatch.GeoServerGWCDispatcherController; import org.geowebcache.GeoWebCacheDispatcher; import org.geowebcache.controller.GeoWebCacheDispatcherController; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -24,9 +26,10 @@ */ @Controller @RequestMapping("/gwc") +@RequiredArgsConstructor public class GeoWebCacheController { - private @Autowired GeoWebCacheDispatcher gwcDispatcher; + private final @NonNull GeoWebCacheDispatcher gwcDispatcher; @GetMapping( path = { diff --git a/src/gwc/services/src/main/java/org/gwc/web/tms/TMSController.java b/src/gwc/services/src/main/java/org/gwc/web/tms/TMSController.java index 5d02fd9cd..d3347658a 100644 --- a/src/gwc/services/src/main/java/org/gwc/web/tms/TMSController.java +++ b/src/gwc/services/src/main/java/org/gwc/web/tms/TMSController.java @@ -4,8 +4,10 @@ */ package org.gwc.web.tms; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import org.geoserver.ows.Dispatcher; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -20,9 +22,10 @@ "/{virtualservice}/gwc/service/tms", "/{virtualservice}/{layer}/gwc/service/tms" }) +@RequiredArgsConstructor public class TMSController { - private @Autowired Dispatcher geoserverDispatcher; + private final @NonNull Dispatcher geoserverDispatcher; @GetMapping(path = "/**") public void serviceRequest(HttpServletRequest request, HttpServletResponse response) diff --git a/src/gwc/services/src/main/java/org/gwc/web/wms/WMSController.java b/src/gwc/services/src/main/java/org/gwc/web/wms/WMSController.java index becdb7897..dad13fade 100644 --- a/src/gwc/services/src/main/java/org/gwc/web/wms/WMSController.java +++ b/src/gwc/services/src/main/java/org/gwc/web/wms/WMSController.java @@ -4,8 +4,10 @@ */ package org.gwc.web.wms; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import org.geoserver.ows.Dispatcher; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -20,9 +22,10 @@ "/{virtualservice}/gwc/service/wms", "/{virtualservice}/{layer}/gwc/service/wms" }) +@RequiredArgsConstructor public class WMSController { - private @Autowired Dispatcher geoserverDispatcher; + private final @NonNull Dispatcher geoserverDispatcher; @GetMapping(path = "/**") public void serviceRequest(HttpServletRequest request, HttpServletResponse response) diff --git a/src/gwc/services/src/main/java/org/gwc/web/wmts/WMTSController.java b/src/gwc/services/src/main/java/org/gwc/web/wmts/WMTSController.java index 35055a7d9..e7de24e61 100644 --- a/src/gwc/services/src/main/java/org/gwc/web/wmts/WMTSController.java +++ b/src/gwc/services/src/main/java/org/gwc/web/wmts/WMTSController.java @@ -4,8 +4,10 @@ */ package org.gwc.web.wmts; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import org.geoserver.ows.Dispatcher; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -20,9 +22,10 @@ "/{virtualservice}/gwc/service/wmts", "/{virtualservice}/{layer}/gwc/service/wmts" }) +@RequiredArgsConstructor public class WMTSController { - private @Autowired Dispatcher geoserverDispatcher; + private final @NonNull Dispatcher geoserverDispatcher; @GetMapping(path = "/**") public void serviceRequest(HttpServletRequest request, HttpServletResponse response) diff --git a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/AbstractCatalogServiceClientRepositoryTest.java b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/AbstractCatalogServiceClientRepositoryTest.java index f5be4a09a..09fead422 100644 --- a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/AbstractCatalogServiceClientRepositoryTest.java +++ b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/AbstractCatalogServiceClientRepositoryTest.java @@ -169,7 +169,7 @@ protected final void assertCatalogInfoEquals(C expected, C actual) { */ protected abstract void assertPropertriesEqual(C expected, C actual); - public @Test void testFindByIdNotFound() throws IOException { + @Test void testFindByIdNotFound() throws IOException { assertTrue(repository().findById("non-existent-ws-id", infoType).isEmpty()); } diff --git a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/LayerGroupRepositoryTest.java b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/LayerGroupRepositoryTest.java index d82555f3a..6c8e9418f 100644 --- a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/LayerGroupRepositoryTest.java +++ b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/LayerGroupRepositoryTest.java @@ -23,7 +23,7 @@ @EnableAutoConfiguration @Accessors(fluent = true) -public class LayerGroupRepositoryTest +class LayerGroupRepositoryTest extends AbstractCatalogServiceClientRepositoryTest { private @Autowired @Getter LayerGroupRepository repository; @@ -60,21 +60,21 @@ public LayerGroupRepositoryTest() { assertEquals(expected.getLayers(), actual.getLayers()); } - public @Override @Test void testFindAll() { + @Override public @Test void testFindAll() { super.testFindAll(testData.layerGroup1); serverCatalog.add(lg1WorkspaceA); super.testFindAll(testData.layerGroup1, lg1WorkspaceA); } - public @Override @Test void testFindById() { + @Override public @Test void testFindById() { super.testFindById(testData.layerGroup1); } - public @Override @Test void testFindAllByType() { + @Override public @Test void testFindAllByType() { testFindAll(testData.layerGroup1); } - public @Override @Test void testQueryFilter() { + @Override public @Test void testQueryFilter() { LayerGroupInfo lg1 = testData.layerGroup1; serverCatalog.add(lg1WorkspaceA); @@ -88,7 +88,7 @@ public LayerGroupRepositoryTest() { super.testQueryFilter(cql, lg1); } - public @Test void testLayerGroupCRUD_NoWorkspace() { + @Test void testLayerGroupCRUD_NoWorkspace() { WorkspaceInfo workspace = null; LayerGroupInfo layerGroup = testData.createLayerGroup( @@ -116,7 +116,7 @@ public LayerGroupRepositoryTest() { }); } - public @Test void testLayerGroupCRUD_Workspace() { + @Test void testLayerGroupCRUD_Workspace() { final WorkspaceInfo workspace = testData.workspaceA; LayerGroupInfo layerGroup = testData.createLayerGroup( @@ -137,7 +137,7 @@ public LayerGroupRepositoryTest() { }); } - public @Test void testUpdateLayers() { + @Test void testUpdateLayers() { WorkspaceInfo workspace = null; LayerGroupInfo layerGroup = testData.createLayerGroup( @@ -173,7 +173,7 @@ public LayerGroupRepositoryTest() { }); } - public @Test void testFindAllByWorkspaceIsNull() { + @Test void testFindAllByWorkspaceIsNull() { testFind(() -> repository.findAllByWorkspaceIsNull(), testData.layerGroup1); serverCatalog.add(lg1WorkspaceA); testFind(() -> repository.findAllByWorkspaceIsNull(), testData.layerGroup1); @@ -184,7 +184,7 @@ public LayerGroupRepositoryTest() { testFind(() -> repository.findAllByWorkspaceIsNull(), testData.layerGroup1, lg2); } - public @Test void testFindAllByWorkspace() { + @Test void testFindAllByWorkspace() { WorkspaceInfo workspace = testData.workspaceA; testFind(() -> repository.findAllByWorkspace(testData.workspaceA)); serverCatalog.add(lg1WorkspaceA); @@ -196,7 +196,7 @@ public LayerGroupRepositoryTest() { testFind(() -> repository.findAllByWorkspace(workspace), lg1WorkspaceA, lg2WorkspaceA); } - public @Test void testFindByNameAndWorkspaceIsNull() { + @Test void testFindByNameAndWorkspaceIsNull() { LayerGroupInfo global = testData.layerGroup1; assertEquals( global.getId(), @@ -205,7 +205,7 @@ public LayerGroupRepositoryTest() { assertTrue(repository.findByNameAndWorkspaceIsNull(lg1WorkspaceA.getName()).isEmpty()); } - public @Test void testFindByNameAndWorkspace() { + @Test void testFindByNameAndWorkspace() { LayerGroupInfo globalGroup = serverCatalog.getLayerGroup(testData.layerGroup1.getId()); WorkspaceInfo workspace = testData.workspaceA; serverCatalog.add(lg1WorkspaceA); diff --git a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/LayerRepositoryTest.java b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/LayerRepositoryTest.java index bf427b436..33c4b9a9c 100644 --- a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/LayerRepositoryTest.java +++ b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/LayerRepositoryTest.java @@ -21,7 +21,7 @@ @EnableAutoConfiguration @Accessors(fluent = true) -public class LayerRepositoryTest +class LayerRepositoryTest extends AbstractCatalogServiceClientRepositoryTest { private @Autowired @Getter LayerRepository repository; @@ -59,24 +59,24 @@ private void addLayers() { serverCatalog.add(layerWMTSA); } - public @Override @Test void testFindAll() { + @Override public @Test void testFindAll() { assertEquals(0, repository.findAll().count()); addLayers(); super.testFindAll(layerFTA, layerWMTSA, layerCVA); } - public @Override @Test void testFindAllByType() { + @Override public @Test void testFindAllByType() { testFindAllIncludeFilter(LayerInfo.class); addLayers(); testFindAllIncludeFilter(LayerInfo.class, layerFTA, layerCVA, layerWMTSA); } - public @Override @Test void testFindById() { + @Override public @Test void testFindById() { serverCatalog.add(testData.layerFeatureTypeA); super.testFindById(testData.layerFeatureTypeA); } - public @Override @Test void testQueryFilter() { + @Override public @Test void testQueryFilter() { serverCatalog.add(testData.layerFeatureTypeA); StyleInfo style1 = testData.style1; StyleInfo style2 = testData.style2; @@ -101,7 +101,7 @@ private void addLayers() { super.testQueryFilter(cql, layer1, layer2); } - public @Test void testLayerCRUD() { + @Test void testLayerCRUD() { LayerInfo layer = testData.layerFeatureTypeA; crudTest(layer, serverCatalog::getLayer, l -> { l.setDefaultStyle(testData.style2); @@ -110,7 +110,7 @@ private void addLayers() { }); } - public @Test void testUpdateStyles() { + @Test void testUpdateStyles() { LayerInfo layer = testData.layerFeatureTypeA; serverCatalog.add(layer); layer = serverCatalog.getLayer(layer.getId()); @@ -132,7 +132,7 @@ private void addLayers() { }); } - public @Test void testFindLayersByResource() { + @Test void testFindLayersByResource() { addLayers(); testFind(() -> repository.findAllByResource(layerFTA.getResource()), layerFTA); @@ -140,13 +140,13 @@ private void addLayers() { testFind(() -> repository.findAllByResource(layerWMTSA.getResource()), layerWMTSA); } - public @Test void testFindLayersByResource_NonExistentResource() { + @Test void testFindLayersByResource_NonExistentResource() { FeatureTypeInfo missingResource = testData.createFeatureType("not-added-to-catalog"); assertEquals(0, repository.findAllByResource(missingResource).count()); } - public @Test void testFindLayersWithStyle() { + @Test void testFindLayersWithStyle() { StyleInfo style1 = testData.style1; // on layer1 and layer2 StyleInfo style2 = testData.style2; // layer2's default style StyleInfo style3 = testData.createStyle("style3"); // on layer2 @@ -171,7 +171,7 @@ private void testFindLayersWithStyle(StyleInfo style, LayerInfo... expectedLayer testFind(() -> repository.findAllByDefaultStyleOrStyles(style), expectedLayers); } - public @Test void testFindOneByName() { + @Test void testFindOneByName() { addLayers(); assertEquals(layerFTA.getId(), repository.findOneByName(layerFTA.getName()).get().getId()); } diff --git a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/NamespaceRepositoryTest.java b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/NamespaceRepositoryTest.java index 6faeb5bdf..7e762b2b3 100644 --- a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/NamespaceRepositoryTest.java +++ b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/NamespaceRepositoryTest.java @@ -22,7 +22,7 @@ @EnableAutoConfiguration @Accessors(fluent = true) -public class NamespaceRepositoryTest +class NamespaceRepositoryTest extends AbstractCatalogServiceClientRepositoryTest { private @Autowired @Getter NamespaceRepository repository; @@ -37,22 +37,22 @@ public NamespaceRepositoryTest() { assertEquals(expected.getURI(), actual.getURI()); } - public @Override @Test void testFindAll() { + @Override public @Test void testFindAll() { super.testFindAll(testData.namespaceA, testData.namespaceB, testData.namespaceC); } - public @Override @Test void testFindAllByType() { + @Override public @Test void testFindAllByType() { super.testFindAllIncludeFilter(NamespaceInfo.class, testData.namespaceA, testData.namespaceB, testData.namespaceC); } - public @Override @Test void testFindById() { + @Override public @Test void testFindById() { super.testFindById(testData.namespaceA); super.testFindById(testData.namespaceB); super.testFindById(testData.namespaceC); } - public @Override @Test void testQueryFilter() { + @Override public @Test void testQueryFilter() { NamespaceInfo ns1 = serverCatalog.getNamespace(testData.namespaceA.getId()); NamespaceInfo ns2 = serverCatalog.getNamespace(testData.namespaceB.getId()); NamespaceInfo ns3 = serverCatalog.getNamespace(testData.namespaceC.getId()); @@ -66,13 +66,13 @@ public NamespaceRepositoryTest() { super.testQueryFilter(String.format("URI = '%s'", ns1.getURI()), ns1, ns3); } - public @Test void testFindNamespaceById() { + @Test void testFindNamespaceById() { testFindById(testData.namespaceA); testFindById(testData.namespaceB); testFindById(testData.namespaceC); } - public @Test void testFindNamespacePrefix() { + @Test void testFindNamespacePrefix() { testFindByPrefix(testData.namespaceA); testFindByPrefix(testData.namespaceB); testFindByPrefix(testData.namespaceC); @@ -83,25 +83,25 @@ private void testFindByPrefix(NamespaceInfo expected) { repository.findFirstByName(expected.getPrefix(), NamespaceInfo.class).get()); } - public @Test void testNamespaceInfo_CRUD() throws IOException { + @Test void testNamespaceInfo_CRUD() throws IOException { NamespaceInfo ns = testData.faker().namespace(); crudTest(ns, serverCatalog::getNamespace, n -> n.setPrefix("modified-prefix"), (old, updated) -> assertEquals("modified-prefix", updated.getPrefix())); } - public @Test void testGetDefaultNamespace() { + @Test void testGetDefaultNamespace() { assertEquals(testData.namespaceA, repository.getDefaultNamespace().get()); serverCatalog.setDefaultNamespace(testData.namespaceB); assertEquals(testData.namespaceB, repository.getDefaultNamespace().get()); } - public @Test void testGetDefaultNamespaceNoDefaultExists() { + @Test void testGetDefaultNamespaceNoDefaultExists() { testData.deleteAll(); assertNull(serverCatalog.getDefaultNamespace()); assertTrue(repository.getDefaultNamespace().isEmpty()); } - public @Test void testSetDefaultNamespace() { + @Test void testSetDefaultNamespace() { assertEquals(testData.namespaceA, serverCatalog.getDefaultNamespace()); repository.setDefaultNamespace(testData.namespaceB); @@ -110,7 +110,7 @@ private void testFindByPrefix(NamespaceInfo expected) { assertEquals(testData.namespaceB, serverCatalog.getDefaultNamespace()); } - public @Test void testSetDefaultNamespaceNonExistent() { + @Test void testSetDefaultNamespaceNonExistent() { assertEquals(testData.namespaceA, serverCatalog.getDefaultNamespace()); NamespaceInfo nonExistent = testData.faker().namespace(); @@ -119,7 +119,7 @@ private void testFindByPrefix(NamespaceInfo expected) { assertEquals(testData.namespaceA, serverCatalog.getDefaultNamespace()); } - public @Test void testUnsetDefaultNamespace() { + @Test void testUnsetDefaultNamespace() { NamespaceInfo ns = testData.namespaceA; // preflight check serverCatalog.setDefaultNamespace(null); @@ -143,7 +143,7 @@ private void testFindByPrefix(NamespaceInfo expected) { assertTrue(repository.getDefaultNamespace().isEmpty()); } - public @Test void testFindOneNamespaceByURI() { + @Test void testFindOneNamespaceByURI() { NamespaceInfo ns1 = testData.namespaceA; NamespaceInfo ns2 = testData.faker().namespace(); ns2.setURI(ns1.getURI()); @@ -156,7 +156,7 @@ private void testFindByPrefix(NamespaceInfo expected) { assertTrue(found.getId().equals(ns1.getId()) || found.getId().equals(ns2.getId())); } - public @Test void testFindAllNamespacesByURI() { + @Test void testFindAllNamespacesByURI() { NamespaceInfo ns1 = testData.namespaceA; NamespaceInfo ns2 = testData.faker().namespace(); ns2.setURI(ns1.getURI()); @@ -170,7 +170,7 @@ private void testFindByPrefix(NamespaceInfo expected) { assertEquals(2, found.size()); } - public @Test void testCreateNamespaceDuplicateURI() { + @Test void testCreateNamespaceDuplicateURI() { NamespaceInfo ns1 = testData.namespaceA; NamespaceInfo ns2 = testData.faker().namespace(); ns2.setURI(ns1.getURI()); diff --git a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/ResourceRepositoryTest.java b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/ResourceRepositoryTest.java index 331a5e931..edaa41cbf 100644 --- a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/ResourceRepositoryTest.java +++ b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/ResourceRepositoryTest.java @@ -32,7 +32,7 @@ @EnableAutoConfiguration @Accessors(fluent = true) -public class ResourceRepositoryTest +class ResourceRepositoryTest extends AbstractCatalogServiceClientRepositoryTest { private @Autowired @Getter ResourceRepository repository; @@ -50,19 +50,19 @@ public ResourceRepositoryTest() { assertEquals(expected.getStore().getId(), actual.getStore().getId()); } - public @Override @Test void testFindAll() { + @Override public @Test void testFindAll() { super.testFindAll( testData.featureTypeA, testData.coverageA, testData.wmsLayerA, testData.wmtsLayerA); } - public @Override @Test void testFindById() { + @Override public @Test void testFindById() { super.testFindById(testData.featureTypeA); super.testFindById(testData.coverageA); super.testFindById(testData.wmsLayerA); super.testFindById(testData.wmtsLayerA); } - public @Override @Test void testFindAllByType() { + @Override public @Test void testFindAllByType() { super.testFindAllIncludeFilter( ResourceInfo.class, testData.featureTypeA, @@ -75,7 +75,7 @@ public ResourceRepositoryTest() { super.testFindAllIncludeFilter(WMTSLayerInfo.class, testData.wmtsLayerA); } - public @Test void testFindAllByNamespace() { + @Test void testFindAllByNamespace() { testFind( () -> repository.findAllByNamespace(testData.namespaceA, ResourceInfo.class), testData.featureTypeA, @@ -88,7 +88,7 @@ public ResourceRepositoryTest() { testData.featureTypeA); } - public @Test void testFindByStoreAndName() { + @Test void testFindByStoreAndName() { DataStoreInfo ds = testData.dataStoreA; FeatureTypeInfo ft = testData.featureTypeA; CoverageStoreInfo cs = testData.coverageStoreA; @@ -115,7 +115,7 @@ public ResourceRepositoryTest() { repository.findByStoreAndName(cs, cv.getName(), FeatureTypeInfo.class).isEmpty()); } - public @Test void testFindAllByStore() { + @Test void testFindAllByStore() { FeatureTypeInfo ftA2 = testData.createFeatureType("ftA2"); CoverageInfo cvA2 = testData.createCoverage("cvA2"); serverCatalog.add(ftA2); @@ -134,7 +134,7 @@ public ResourceRepositoryTest() { testFind(() -> repository.findAllByStore(testData.coverageStoreA, FeatureTypeInfo.class)); } - public @Override @Test void testQueryFilter() { + @Override public @Test void testQueryFilter() { FeatureTypeInfo ft = serverCatalog.getFeatureType(testData.featureTypeA.getId()); CoverageInfo cv = serverCatalog.getCoverage(testData.coverageA.getId()); WMSLayerInfo wms = @@ -155,7 +155,7 @@ public ResourceRepositoryTest() { super.testQueryFilter("enabled = false", wms, wmts); } - public @Test void testResourceInfoCRUD_FeatureTypeInfo() { + @Test void testResourceInfoCRUD_FeatureTypeInfo() { FeatureTypeInfo toCreate = testData.createFeatureType( "featureTypeCRUD", @@ -180,7 +180,7 @@ public ResourceRepositoryTest() { }); } - public @Test void testResourceInfoCRUD_CoverageInfo() { + @Test void testResourceInfoCRUD_CoverageInfo() { CoverageInfo toCreate = testData.createCoverage( "coverageCRUD", testData.coverageStoreA, "coverageCRUD_name"); @@ -209,7 +209,7 @@ public ResourceRepositoryTest() { * java.util.Collections$EmptySet (in module java.base) with modifiers "private"} */ @Disabled - public @Test void testResourceInfoCRUD_WMSLayerInfo() { + @Test void testResourceInfoCRUD_WMSLayerInfo() { WMSLayerInfo toCreate = testData.createWMSLayer( "wmsLayerCRUD", @@ -232,7 +232,7 @@ public ResourceRepositoryTest() { }); } - public @Test void testResourceInfoCRUD_WMTSLayerInfo() { + @Test void testResourceInfoCRUD_WMTSLayerInfo() { WMTSLayerInfo toCreate = testData.createWMTSLayer( "wmtsLayerCRUD", @@ -255,14 +255,14 @@ public ResourceRepositoryTest() { }); } - public @Test void testFindResourceInfoById() { + @Test void testFindResourceInfoById() { testFindById(testData.featureTypeA); testFindById(testData.coverageA); testFindById(testData.wmsLayerA); testFindById(testData.wmtsLayerA); } - public @Test void testFindResourceInfoById_SubtypeMismatch() throws IOException { + @Test void testFindResourceInfoById_SubtypeMismatch() throws IOException { ResourceRepository client = repository; assertTrue(client.findById(testData.featureTypeA.getId(), CoverageInfo.class).isEmpty()); assertTrue(client.findById(testData.coverageA.getId(), FeatureTypeInfo.class).isEmpty()); @@ -270,7 +270,7 @@ public ResourceRepositoryTest() { assertTrue(client.findById(testData.wmtsLayerA.getId(), WMSLayerInfo.class).isEmpty()); } - public @Test void testFindResourceByNamespaceIdAndName() { + @Test void testFindResourceByNamespaceIdAndName() { NamespaceInfo ns = testData.namespaceA; ResourceInfo ftA = testData.featureTypeA; @@ -286,7 +286,7 @@ public ResourceRepositoryTest() { assertTrue(client.findByNameAndNamespace(name, ns, CoverageInfo.class).isEmpty()); } - public @Test void testFindAllBySubtype() { + @Test void testFindAllBySubtype() { ResourceRepository client = repository; List all = diff --git a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/StoreRepositoryTest.java b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/StoreRepositoryTest.java index bbebe3322..980184caf 100644 --- a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/StoreRepositoryTest.java +++ b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/StoreRepositoryTest.java @@ -36,7 +36,7 @@ @EnableAutoConfiguration @Accessors(fluent = true) -public class StoreRepositoryTest +class StoreRepositoryTest extends AbstractCatalogServiceClientRepositoryTest { private @Autowired @Getter StoreRepository repository; @@ -62,16 +62,16 @@ public StoreRepositoryTest() { assertEquals(expected.getType(), actual.getType()); assertEquals(expected.getWorkspace(), actual.getWorkspace()); assertEquals(expected.isEnabled(), actual.isEnabled()); - if (expected instanceof CoverageStoreInfo) + if (expected instanceof CoverageStoreInfo cov) assertEquals( - ((CoverageStoreInfo) expected).getURL(), ((CoverageStoreInfo) actual).getURL()); - if (expected instanceof HTTPStoreInfo) + cov.getURL(), ((CoverageStoreInfo) actual).getURL()); + if (expected instanceof HTTPStoreInfo httpStore) assertEquals( - ((HTTPStoreInfo) expected).getCapabilitiesURL(), + httpStore.getCapabilitiesURL(), ((HTTPStoreInfo) actual).getCapabilitiesURL()); } - public @Override @Test void testFindAll() { + @Override public @Test void testFindAll() { super.testFindAll( testData.dataStoreA, testData.dataStoreB, @@ -81,14 +81,14 @@ public StoreRepositoryTest() { testData.wmtsStoreA); } - public @Override @Test void testFindById() { + @Override public @Test void testFindById() { super.testFindById(testData.dataStoreA); super.testFindById(testData.coverageStoreA); super.testFindById(testData.wmsStoreA); super.testFindById(testData.wmtsStoreA); } - public @Override @Test void testFindAllByType() { + @Override public @Test void testFindAllByType() { super.testFindAllIncludeFilter( StoreInfo.class, testData.dataStoreA, @@ -105,7 +105,7 @@ public StoreRepositoryTest() { super.testFindAllIncludeFilter(WMTSStoreInfo.class, testData.wmtsStoreA); } - public @Test void testFindAllByTypeStoreRepository() { + @Test void testFindAllByTypeStoreRepository() { testFind( () -> repository.findAllByType(StoreInfo.class), testData.dataStoreA, @@ -126,7 +126,7 @@ public StoreRepositoryTest() { testFind(() -> repository.findAllByType(WMTSStoreInfo.class), testData.wmtsStoreA); } - public @Test void testSetDefaultDataStore() { + @Test void testSetDefaultDataStore() { WorkspaceInfo ws = testData.workspaceA; DataStoreInfo ds1 = testData.dataStoreA; DataStoreInfo ds2 = testData.faker().dataStoreInfo("wsA-ds2", ws); @@ -138,7 +138,7 @@ public StoreRepositoryTest() { assertEquals(ds2.getId(), serverCatalog.getDefaultDataStore(ws).getId()); } - public @Test void testUnsetDefaultDataStore() { + @Test void testUnsetDefaultDataStore() { WorkspaceInfo ws = testData.workspaceA; DataStoreInfo store = testData.dataStoreA; // preflight check @@ -163,7 +163,7 @@ public StoreRepositoryTest() { assertTrue(repository.getDefaultDataStore(ws).isEmpty()); } - public @Test void getDefaultDataStore() { + @Test void getDefaultDataStore() { WorkspaceInfo wsA = testData.workspaceA; WorkspaceInfo wsB = testData.workspaceB; @@ -192,7 +192,7 @@ public StoreRepositoryTest() { assertTrue(repository.getDefaultDataStore(wsA).isEmpty()); } - public @Test void testGetDefaultDataStores() { + @Test void testGetDefaultDataStores() { WorkspaceInfo wsA = testData.workspaceA; WorkspaceInfo wsB = testData.workspaceB; DataStoreInfo dsA2 = testData.faker().dataStoreInfo("wsA-ds2", wsA); @@ -212,7 +212,7 @@ public StoreRepositoryTest() { testFind(() -> repository.getDefaultDataStores(), dsA2, dsB2, testData.dataStoreC); } - public @Override @Test void testQueryFilter() { + @Override public @Test void testQueryFilter() { DataStoreInfo ds1 = serverCatalog.getDataStore(testData.dataStoreA.getId()); DataStoreInfo ds2 = serverCatalog.getDataStore(testData.dataStoreB.getId()); DataStoreInfo ds3 = serverCatalog.getDataStore(testData.dataStoreC.getId()); @@ -237,7 +237,7 @@ public StoreRepositoryTest() { super.testQueryFilter(ecql, ds2); } - public @Test void testDataStoreInfo_CRUD() throws IOException { + @Test void testDataStoreInfo_CRUD() throws IOException { DataStoreInfo store = testData.faker().dataStoreInfo( "dataStoreCRUD-id", @@ -263,7 +263,7 @@ public StoreRepositoryTest() { }); } - public @Test void testCoverageStoreInfo_CRUD() { + @Test void testCoverageStoreInfo_CRUD() { CoverageStoreInfo store = testData.createCoverageStore( "coverageStoreCRUD", @@ -292,7 +292,7 @@ public StoreRepositoryTest() { }); } - public @Test void testWMSStoreInfo_CRUD() { + @Test void testWMSStoreInfo_CRUD() { WMSStoreInfo store = testData.createWebMapServer( "wmsStoreCRUD", @@ -319,7 +319,7 @@ public StoreRepositoryTest() { }); } - public @Test void testWMTSStoreInfo_CRUD() { + @Test void testWMTSStoreInfo_CRUD() { WMTSStoreInfo store = testData.createWebMapTileServer( "wmsStoreCRUD", @@ -346,7 +346,7 @@ public StoreRepositoryTest() { }); } - public @Test void testFindStoreById() throws IOException { + @Test void testFindStoreById() throws IOException { testFindById(testData.coverageStoreA); testFindById(testData.dataStoreA); testFindById(testData.dataStoreB); @@ -354,14 +354,14 @@ public StoreRepositoryTest() { testFindById(testData.wmtsStoreA); } - public @Test void testFindStoreById_SubtypeMismatch() throws IOException { + @Test void testFindStoreById_SubtypeMismatch() throws IOException { StoreRepository client = repository(); assertTrue(client.findById(testData.coverageStoreA.getId(), DataStoreInfo.class).isEmpty()); assertTrue(client.findById(testData.dataStoreA.getId(), CoverageStoreInfo.class).isEmpty()); assertTrue(client.findById(testData.dataStoreB.getId(), CoverageStoreInfo.class).isEmpty()); } - public @Test void testFindStoreByName() throws IOException { + @Test void testFindStoreByName() throws IOException { findStoreByName(testData.coverageStoreA); findStoreByName(testData.dataStoreA); findStoreByName(testData.dataStoreB); @@ -375,7 +375,7 @@ private void findStoreByName(StoreInfo store) { assertCatalogInfoEquals(store, resolved); } - public @Test void testFindStoreByWorkspaceAndName() throws IOException { + @Test void testFindStoreByWorkspaceAndName() throws IOException { testFindStoreByWorkspaceAndName(testData.coverageStoreA, StoreInfo.class); testFindStoreByWorkspaceAndName(testData.coverageStoreA, CoverageStoreInfo.class); @@ -402,7 +402,7 @@ private void testFindStoreByWorkspaceAndName(StoreInfo store, Class { private @Autowired @Getter StyleRepository repository; @@ -50,7 +50,7 @@ private void assertLegendEquals(LegendInfo expected, LegendInfo actual) { } } - public @Test void testStyleCRUD_NoWorkspace() { + @Test void testStyleCRUD_NoWorkspace() { StyleInfo style = testData.createStyle("styleCRUD", null, "styleCRUD", "styleCRUD.sld"); ((StyleInfoImpl) style).setFormat(SLDHandler.FORMAT); ((StyleInfoImpl) style).setFormatVersion(SLDHandler.VERSION_10); @@ -85,7 +85,7 @@ private void assertLegendEquals(LegendInfo expected, LegendInfo actual) { }); } - public @Test void testStyleCRUD_Workspace() { + @Test void testStyleCRUD_Workspace() { StyleInfo style = testData.createStyle( "styleCRUD_Workspace", @@ -157,7 +157,7 @@ private void assertLegendEquals(LegendInfo expected, LegendInfo actual) { super.testQueryFilter(cql, ws1s1, ws1s2); } - public @Test void testFindStyleByNameAndNullWorkspace() { + @Test void testFindStyleByNameAndNullWorkspace() { WorkspaceInfo ws1 = testData.workspaceA; StyleInfo ws1s1 = testData.createStyle("s1ws1", ws1); serverCatalog.add(ws1s1); @@ -171,7 +171,7 @@ private void assertLegendEquals(LegendInfo expected, LegendInfo actual) { assertTrue(repository.findByNameAndWordkspaceNull(ws1s1.getName()).isEmpty()); } - public @Test void testfindStyleByWorkspaceIdAndName() { + @Test void testfindStyleByWorkspaceIdAndName() { WorkspaceInfo ws1 = testData.workspaceA; WorkspaceInfo ws2 = testData.workspaceB; StyleInfo ws1s1 = testData.createStyle("s1ws1", ws1); @@ -190,14 +190,14 @@ private void assertLegendEquals(LegendInfo expected, LegendInfo actual) { assertTrue(repository.findByNameAndWorkspace(ws2s1.getName(), ws1).isEmpty()); } - public @Test void testFindStylesByNullWorkspace() { + @Test void testFindStylesByNullWorkspace() { StyleInfo ws1s1 = testData.createStyle("s1ws1", testData.workspaceA); serverCatalog.add(ws1s1); testFind(() -> repository.findAllByNullWorkspace(), testData.style1, testData.style2); } - public @Test void testFindStylesByWorkspaceId() { + @Test void testFindStylesByWorkspaceId() { WorkspaceInfo ws1 = testData.workspaceA; WorkspaceInfo ws2 = testData.workspaceB; diff --git a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/WorkspaceRepositoryTest.java b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/WorkspaceRepositoryTest.java index 073cd1c8b..84ae992ef 100644 --- a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/WorkspaceRepositoryTest.java +++ b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/catalog/client/reactivefeign/WorkspaceRepositoryTest.java @@ -20,7 +20,7 @@ @EnableAutoConfiguration @Accessors(fluent = true) -public class WorkspaceRepositoryTest +class WorkspaceRepositoryTest extends AbstractCatalogServiceClientRepositoryTest { private @Autowired @Getter WorkspaceRepository repository; @@ -34,22 +34,22 @@ public WorkspaceRepositoryTest() { assertEquals(expected.isIsolated(), actual.isIsolated()); } - public @Override @Test void testFindById() { + @Override public @Test void testFindById() { testFindById(testData.workspaceA); testFindById(testData.workspaceB); testFindById(testData.workspaceC); } - public @Override @Test void testFindAll() { + @Override public @Test void testFindAll() { super.testFindAll(testData.workspaceA, testData.workspaceB, testData.workspaceC); } - public @Override @Test void testFindAllByType() { + @Override public @Test void testFindAllByType() { super.testFindAllIncludeFilter( WorkspaceInfo.class, testData.workspaceA, testData.workspaceB, testData.workspaceC); } - public @Override @Test void testQueryFilter() { + @Override public @Test void testQueryFilter() { WorkspaceInfo wsA = serverCatalog.getWorkspace(testData.workspaceA.getId()); WorkspaceInfo wsB = serverCatalog.getWorkspace(testData.workspaceB.getId()); WorkspaceInfo wsC = serverCatalog.getWorkspace(testData.workspaceC.getId()); @@ -64,12 +64,12 @@ public WorkspaceRepositoryTest() { super.testQueryFilter(format("\"id\" = '%s'", wsA.getId()), wsA); } - public @Test void testFindByName() { + @Test void testFindByName() { WorkspaceInfo ws1 = testData.workspaceA; assertEquals(ws1, repository.findFirstByName(ws1.getName(), infoType).get()); } - public @Test void testWorkspaceCRUD() { + @Test void testWorkspaceCRUD() { WorkspaceInfo ws = testData.faker().workspaceInfo("workspaceCRUD"); crudTest( ws, @@ -84,20 +84,20 @@ public WorkspaceRepositoryTest() { }); } - public @Test void testGetDefaultWorkspace() { + @Test void testGetDefaultWorkspace() { WorkspaceInfo expected = serverCatalog.getDefaultWorkspace(); assertNotNull(expected); WorkspaceInfo actual = repository.getDefaultWorkspace().get(); assertEquals(expected, actual); } - public @Test void testGetDefaultWorkspaceIsNullOnEmptyCatalog() { + @Test void testGetDefaultWorkspaceIsNullOnEmptyCatalog() { testData.deleteAll(); assertNull(serverCatalog.getDefaultWorkspace()); assertFalse(repository.getDefaultWorkspace().isPresent()); } - public @Test void testSetDefaultWorkspace() { + @Test void testSetDefaultWorkspace() { WorkspaceInfo current = serverCatalog.getDefaultWorkspace(); assertNotNull(current); assertEquals(testData.workspaceA.getId(), current.getId()); @@ -110,7 +110,7 @@ public WorkspaceRepositoryTest() { assertEquals(expected, repository.getDefaultWorkspace().get()); } - public @Test void testUnsetDefaultWorkspace() { + @Test void testUnsetDefaultWorkspace() { WorkspaceInfo ws2 = testData.workspaceB; // preflight check serverCatalog.setDefaultWorkspace(null); diff --git a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/catalog/AbstractCatalogBackendIT.java b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/catalog/AbstractCatalogBackendIT.java index 8690990a6..c7909256c 100644 --- a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/catalog/AbstractCatalogBackendIT.java +++ b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/catalog/AbstractCatalogBackendIT.java @@ -28,7 +28,7 @@ public abstract class AbstractCatalogBackendIT extends CatalogConformanceTest { "https://wmts.geo.admin.ch/EPSG/3857/1.0.0/WMTSCapabilities.xml"; @Test - public void onlineWMTS_addStore() throws IOException { + void onlineWMTS_addStore() throws IOException { final WorkspaceInfo ws = addWorkspace(); WMTSStoreInfo store = addWMTSStore(ws, LIVE_WMTS_GETCAPS_URL); assertNotNull(store); @@ -42,7 +42,7 @@ public void onlineWMTS_addStore() throws IOException { } @Test - public void onlineWMTS_addResource() throws IOException { + void onlineWMTS_addResource() throws IOException { final WorkspaceInfo ws = addWorkspace(); final NamespaceInfo ns = addNamespace(); final WMTSStoreInfo store = addWMTSStore(ws, LIVE_WMTS_GETCAPS_URL); @@ -69,7 +69,7 @@ public void onlineWMTS_addResource() throws IOException { } @Test - public void onlineWMTS_addLayer() throws IOException { + void onlineWMTS_addLayer() throws IOException { final WorkspaceInfo ws = addWorkspace(); final NamespaceInfo ns = addNamespace(); final WMTSStoreInfo store = addWMTSStore(ws, LIVE_WMTS_GETCAPS_URL); diff --git a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/catalogservice/CatalogClientBackendIntegrationTest.java b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/catalogservice/CatalogClientBackendIntegrationTest.java index a4f0a3ffd..544417a8a 100644 --- a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/catalogservice/CatalogClientBackendIntegrationTest.java +++ b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/catalogservice/CatalogClientBackendIntegrationTest.java @@ -61,7 +61,7 @@ @ActiveProfiles("it.catalog-service") // REVISIT: fails if run with failsafe "ClassNotFoundException: // org.geoserver.cloud.catalog.client.reactivefeign.ReactiveCatalogClient" -public class CatalogClientBackendIntegrationTest extends AbstractCatalogBackendIT { +class CatalogClientBackendIntegrationTest extends AbstractCatalogBackendIT { /** * WebFlux catalog-service catalog with backend as configured by * bootstrap-it.catalog-service.yml @@ -84,7 +84,7 @@ public class CatalogClientBackendIntegrationTest extends AbstractCatalogBackendI super.data.deleteAll(serverCatalog); } - public @Test void testQueryFilterInstanceOf() { + @Test void testQueryFilterInstanceOf() { super.data.addObjects(); int expected = serverCatalog.getDataStores().size(); assertThat(expected, greaterThan(0)); diff --git a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/catalogservice/CatalogClientGeoServerFacadeConformanceTest.java b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/catalogservice/CatalogClientGeoServerFacadeConformanceTest.java index 52d1c2b70..54a22178a 100644 --- a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/catalogservice/CatalogClientGeoServerFacadeConformanceTest.java +++ b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/catalogservice/CatalogClientGeoServerFacadeConformanceTest.java @@ -46,7 +46,7 @@ "geoserver.backend.catalog-service.uri=http://localhost:${server.port}" }) @ActiveProfiles("it.catalog-service") -public class CatalogClientGeoServerFacadeConformanceTest extends GeoServerConfigConformanceTest { +class CatalogClientGeoServerFacadeConformanceTest extends GeoServerConfigConformanceTest { /** * WebFlux catalog-service catalog with backend as configured by @@ -81,7 +81,7 @@ public void deleteAll() { /** * Test works if run alone, but not if it runs after other tests cause server config is not null */ - public @Override @Test void testGlobal() throws Exception { + @Override public @Test void testGlobal() throws Exception { Assumptions.assumeTrue(serverConfig.getGlobal() == null); super.testGlobal(); } @@ -89,7 +89,7 @@ public void deleteAll() { /** * Test works if run alone, but not if it runs after other tests cause server config is not null */ - public @Override @Test void testModifyGlobal() throws Exception { + @Override public @Test void testModifyGlobal() throws Exception { Assumptions.assumeTrue(serverConfig.getGlobal() == null); super.testModifyGlobal(); } diff --git a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/datadirectory/DataDirectoryCatalogIT.java b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/datadirectory/DataDirectoryCatalogIT.java index 4d6257a84..80eaf5681 100644 --- a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/datadirectory/DataDirectoryCatalogIT.java +++ b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/datadirectory/DataDirectoryCatalogIT.java @@ -18,7 +18,7 @@ properties = {"geoserver.backend.data-directory.enabled=true", "spring.cloud.circuitbreaker.hystrix.enabled=false", "spring.cloud.config.retry.max-attempts=1"}) -public class DataDirectoryCatalogIT extends AbstractCatalogBackendIT { +class DataDirectoryCatalogIT extends AbstractCatalogBackendIT { private @Autowired @Qualifier("catalogFacade") CatalogFacade rawCatalogFacade; private @Autowired GeoServerResourceLoader resourceLoader; diff --git a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/jdbcconfig/JDBCConfigCatalogConcurrencyIT.java b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/jdbcconfig/JDBCConfigCatalogConcurrencyIT.java index c707fe65b..91d1559ae 100644 --- a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/jdbcconfig/JDBCConfigCatalogConcurrencyIT.java +++ b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/jdbcconfig/JDBCConfigCatalogConcurrencyIT.java @@ -46,7 +46,7 @@ , "logging.level.org.geoserver.jdbcconfig=info"// }) @Slf4j -public class JDBCConfigCatalogConcurrencyIT { +class JDBCConfigCatalogConcurrencyIT { private @Autowired @Qualifier("catalogFacade") ExtendedCatalogFacade jdbcCatalogFacade; private @Autowired @Qualifier("rawCatalog") Catalog rawCatalog; @@ -72,22 +72,22 @@ public void setUp() throws Exception { jdbcCatalogFacade.dispose(); // disposes internal caches } - public @Test void catalogConcurrency_1() { + @Test void catalogConcurrency_1() { data.addObjects(); concurrencyTest(1); } - public @Test void catalogConcurrency_4() { + @Test void catalogConcurrency_4() { data.addObjects(); concurrencyTest(4); } - public @Test void catalogConcurrency_16() { + @Test void catalogConcurrency_16() { data.addObjects(); concurrencyTest(16); } - public @Test void catalogConcurrency_32() { + @Test void catalogConcurrency_32() { data.addObjects(); concurrencyTest(32); } diff --git a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/jdbcconfig/JDBCConfigCatalogIT.java b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/jdbcconfig/JDBCConfigCatalogIT.java index 2e77ba85d..3df95ded6 100644 --- a/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/jdbcconfig/JDBCConfigCatalogIT.java +++ b/src/integration-tests/catalog-service-it/src/test/java/org/geoserver/cloud/integration/jdbcconfig/JDBCConfigCatalogIT.java @@ -20,7 +20,7 @@ "geoserver.backend.jdbcconfig.enabled=true", "logging.level.org.geoserver.cloud.autoconfigure.bus=ERROR" }) -public class JDBCConfigCatalogIT extends AbstractCatalogBackendIT { +class JDBCConfigCatalogIT extends AbstractCatalogBackendIT { private @Autowired @Qualifier("catalogFacade") ExtendedCatalogFacade jdbcCatalogFacade; private @Autowired GeoServerResourceLoader resourceLoader; diff --git a/src/library/spring-boot-simplejndi/src/main/java/org/geoserver/cloud/config/jndi/SimpleJNDIStaticContextInitializer.java b/src/library/spring-boot-simplejndi/src/main/java/org/geoserver/cloud/config/jndi/SimpleJNDIStaticContextInitializer.java index e43ac7223..22a87041d 100644 --- a/src/library/spring-boot-simplejndi/src/main/java/org/geoserver/cloud/config/jndi/SimpleJNDIStaticContextInitializer.java +++ b/src/library/spring-boot-simplejndi/src/main/java/org/geoserver/cloud/config/jndi/SimpleJNDIStaticContextInitializer.java @@ -26,6 +26,18 @@ public class SimpleJNDIStaticContextInitializer private static boolean initialized; + private static synchronized boolean initialize() { + if (initialized) { + return false; + } + if (NamingManager.hasInitialContextFactoryBuilder()) { + log.info("JNDI InitialContextFactoryBuilder already set"); + return false; + } + initialized = true; + return true; + } + /** * Register the context builder by registering it with the JNDI NamingManager. Note that once * this has been done, {@code new InitialContext()} will always return a context from this @@ -38,24 +50,16 @@ public class SimpleJNDIStaticContextInitializer */ @Override public void initialize(ConfigurableApplicationContext applicationContext) { - if (initialized) return; - initialized = true; - if (NamingManager.hasInitialContextFactoryBuilder()) { - log.info("JNDI InitialContextFactoryBuilder already set"); - return; - } - - log.info("Initializing JNDI InitialContextFactoryBuilder"); - try { - NamingManager.setInitialContextFactoryBuilder(new SimpleNamingContextBuilder()); - log.info( - "Registered JNDI implementation using " - + SimpleNamingContextBuilder.class.getName()); - } catch (NamingException e) { - throw new ApplicationContextException( - "Unexpected error installing JNDI " - + SimpleNamingContextBuilder.class.getSimpleName(), - e); + if (initialize()) { + log.info("Initializing JNDI InitialContextFactoryBuilder"); + final String builderClassName = SimpleNamingContextBuilder.class.getName(); + try { + NamingManager.setInitialContextFactoryBuilder(new SimpleNamingContextBuilder()); + log.info("Registered JNDI implementation using " + builderClassName); + } catch (NamingException e) { + throw new ApplicationContextException( + "Unexpected error installing JNDI " + builderClassName, e); + } } } } diff --git a/src/library/spring-boot-simplejndi/src/main/java/org/geoserver/cloud/jndi/NameClassPair.java b/src/library/spring-boot-simplejndi/src/main/java/org/geoserver/cloud/jndi/NameClassPair.java index 1b53eb31e..3d450f0c5 100644 --- a/src/library/spring-boot-simplejndi/src/main/java/org/geoserver/cloud/jndi/NameClassPair.java +++ b/src/library/spring-boot-simplejndi/src/main/java/org/geoserver/cloud/jndi/NameClassPair.java @@ -17,18 +17,22 @@ public NameClassPair(String name, String className) { super(name, className); } - public @Override boolean equals(Object o) { - if (!(o instanceof javax.naming.NameClassPair)) return false; - javax.naming.NameClassPair p = (javax.naming.NameClassPair) o; - return Objects.equals(getName(), p.getName()) - && Objects.equals(getClassName(), p.getClassName()); + @Override + public boolean equals(Object o) { + if (o instanceof javax.naming.NameClassPair p) { + return Objects.equals(getName(), p.getName()) + && Objects.equals(getClassName(), p.getClassName()); + } + return false; } - public @Override int hashCode() { + @Override + public int hashCode() { return Objects.hash(getName(), getClassName()); } - public @Override String toString() { + @Override + public String toString() { return super.toString(); } } diff --git a/src/library/spring-boot-simplejndi/src/main/java/org/geoserver/cloud/jndi/SimpleNamingContext.java b/src/library/spring-boot-simplejndi/src/main/java/org/geoserver/cloud/jndi/SimpleNamingContext.java index 1f9f887cc..4f8876a24 100644 --- a/src/library/spring-boot-simplejndi/src/main/java/org/geoserver/cloud/jndi/SimpleNamingContext.java +++ b/src/library/spring-boot-simplejndi/src/main/java/org/geoserver/cloud/jndi/SimpleNamingContext.java @@ -61,11 +61,13 @@ public SimpleNamingContext() { } } - public @Override NamingEnumeration list(String root) throws NamingException { + @Override + public NamingEnumeration list(String root) throws NamingException { return new NameClassPairEnumeration(this, rootName(root)); } - public @Override NamingEnumeration listBindings(String root) throws NamingException { + @Override + public NamingEnumeration listBindings(String root) throws NamingException { return new BindingEnumeration(this, rootName(root)); } @@ -74,7 +76,8 @@ private String rootName(@NonNull String root) { return root + "/"; } - public @Override Object lookup(@NonNull String lookupName) throws NameNotFoundException { + @Override + public Object lookup(@NonNull String lookupName) throws NameNotFoundException { final String name = this.contextRoot + lookupName; if (name.isEmpty()) { return new SimpleNamingContext(this.contextRoot, this.bindings, this.environment); @@ -94,29 +97,35 @@ private String rootName(@NonNull String root) { "'" + name + "' not bound. Bindings: " + this.bindings.keySet()); } - public @Override Object lookupLink(String name) throws NameNotFoundException { + @Override + public Object lookupLink(String name) throws NameNotFoundException { return lookup(name); } - public @Override void bind(String name, Object obj) { + @Override + public void bind(String name, Object obj) { this.bindings.put(this.contextRoot + name, obj); } - public @Override void unbind(String name) { + @Override + public void unbind(String name) { this.bindings.remove(this.contextRoot + name); } - public @Override void rebind(String name, Object obj) { + @Override + public void rebind(String name, Object obj) { bind(name, obj); } - public @Override void rename(String oldName, String newName) throws NameNotFoundException { + @Override + public void rename(String oldName, String newName) throws NameNotFoundException { Object obj = lookup(oldName); unbind(oldName); bind(newName, obj); } - public @Override Context createSubcontext(String name) { + @Override + public Context createSubcontext(String name) { final String subcontextName = rootName(this.contextRoot + name); Context subcontext = new SimpleNamingContext(subcontextName, this.bindings, this.environment); @@ -124,128 +133,147 @@ private String rootName(@NonNull String root) { return subcontext; } - public @Override void destroySubcontext(String name) { + @Override + public void destroySubcontext(String name) { unbind(name); } - public @Override String composeName(String name, String prefix) { + @Override + public String composeName(String name, String prefix) { return prefix + name; } - public @Override Hashtable getEnvironment() { + @Override + public Hashtable getEnvironment() { return this.environment; } - public @Override Object addToEnvironment(String propName, Object propVal) { + @Override + public Object addToEnvironment(String propName, Object propVal) { return this.environment.put(propName, propVal); } - public @Override Object removeFromEnvironment(String propName) { + @Override + public Object removeFromEnvironment(String propName) { return this.environment.remove(propName); } - public @Override void close() {} + @Override + public void close() {} /** * @throws OperationNotSupportedException javax.naming.Name is not supported */ - public @Override NamingEnumeration list(Name name) throws NamingException { + @Override + public NamingEnumeration list(Name name) throws NamingException { throw nameUnsupported(); } /** * @throws OperationNotSupportedException javax.naming.Name is not supported */ - public @Override NamingEnumeration listBindings(Name name) throws NamingException { + @Override + public NamingEnumeration listBindings(Name name) throws NamingException { throw nameUnsupported(); } /** * @throws OperationNotSupportedException javax.naming.Name is not supported */ - public @Override Object lookup(Name name) throws NamingException { + @Override + public Object lookup(Name name) throws NamingException { throw nameUnsupported(); } /** * @throws OperationNotSupportedException javax.naming.Name is not supported */ - public @Override Object lookupLink(Name name) throws NamingException { + @Override + public Object lookupLink(Name name) throws NamingException { throw nameUnsupported(); } /** * @throws OperationNotSupportedException javax.naming.Name is not supported */ - public @Override void bind(Name name, Object obj) throws NamingException { + @Override + public void bind(Name name, Object obj) throws NamingException { throw nameUnsupported(); } /** * @throws OperationNotSupportedException javax.naming.Name is not supported */ - public @Override void unbind(Name name) throws NamingException { + @Override + public void unbind(Name name) throws NamingException { throw nameUnsupported(); } /** * @throws OperationNotSupportedException javax.naming.Name is not supported */ - public @Override void rebind(Name name, Object obj) throws NamingException { + @Override + public void rebind(Name name, Object obj) throws NamingException { throw nameUnsupported(); } /** * @throws OperationNotSupportedException javax.naming.Name is not supported */ - public @Override void rename(Name oldName, Name newName) throws NamingException { + @Override + public void rename(Name oldName, Name newName) throws NamingException { throw nameUnsupported(); } /** * @throws OperationNotSupportedException javax.naming.Name is not supported */ - public @Override Context createSubcontext(Name name) throws NamingException { + @Override + public Context createSubcontext(Name name) throws NamingException { throw nameUnsupported(); } /** * @throws OperationNotSupportedException javax.naming.Name is not supported */ - public @Override void destroySubcontext(Name name) throws NamingException { + @Override + public void destroySubcontext(Name name) throws NamingException { throw nameUnsupported(); } /** * @throws OperationNotSupportedException javax.naming.Name is not supported */ - public @Override String getNameInNamespace() throws NamingException { + @Override + public String getNameInNamespace() throws NamingException { throw nameUnsupported(); } /** * @throws OperationNotSupportedException javax.naming.Name is not supported */ - public @Override NameParser getNameParser(Name name) throws NamingException { + @Override + public NameParser getNameParser(Name name) throws NamingException { throw nameUnsupported(); } /** * @throws OperationNotSupportedException javax.naming.Name is not supported */ - public @Override NameParser getNameParser(String name) throws NamingException { + @Override + public NameParser getNameParser(String name) throws NamingException { throw nameUnsupported(); } /** * @throws OperationNotSupportedException javax.naming.Name is not supported */ - public @Override Name composeName(Name name, Name prefix) throws NamingException { + @Override + public Name composeName(Name name, Name prefix) throws NamingException { throw nameUnsupported(); } - protected OperationNotSupportedException nameUnsupported() - throws OperationNotSupportedException { + protected OperationNotSupportedException nameUnsupported() { return new OperationNotSupportedException("javax.naming.Name is not supported"); } @@ -265,18 +293,10 @@ private BaseNamingEnumeration(SimpleNamingContext context, final String root) for (String boundName : context.bindings.keySet()) { if (boundName.startsWith(contextRoot)) { final String strippedName = extractSimpleName(contextRoot, boundName); - contents.computeIfAbsent( - strippedName, - name -> { - try { - return createObject(name, context.lookup(root + name)); - } catch (NameNotFoundException e) { - throw new RuntimeException("Should not happen", e); - } - }); + contents.computeIfAbsent(strippedName, name -> lookup(root, name, context)); } } - if (contents.size() == 0) { + if (contents.isEmpty()) { throw new NamingException("Invalid root '" + contextRoot + root + "'"); } this.iterator = contents.values().iterator(); @@ -285,32 +305,46 @@ private BaseNamingEnumeration(SimpleNamingContext context, final String root) protected String extractSimpleName(final String contextRoot, String boundName) { int startIndex = contextRoot.length(); int endIndex = boundName.indexOf('/', startIndex); - String strippedName = - (endIndex != -1 - ? boundName.substring(startIndex, endIndex) - : boundName.substring(startIndex)); - return strippedName; + return (endIndex != -1 + ? boundName.substring(startIndex, endIndex) + : boundName.substring(startIndex)); + } + + private T lookup(String root, String name, SimpleNamingContext context) { + Object lookup; + try { + lookup = context.lookup(root + name); + } catch (NameNotFoundException shouldNotHappen) { + throw new IllegalStateException( + "Subcontext lookup should not fail at this point", shouldNotHappen); + } + return createObject(name, lookup); } protected abstract T createObject(String simpleName, Object obj); - public @Override boolean hasMore() { + @Override + public boolean hasMore() { return this.iterator.hasNext(); } - public @Override T next() { + @Override + public T next() { return this.iterator.next(); } - public @Override boolean hasMoreElements() { + @Override + public boolean hasMoreElements() { return this.iterator.hasNext(); } - public @Override T nextElement() { + @Override + public T nextElement() { return this.iterator.next(); } - public @Override void close() {} + @Override + public void close() {} } private static final class NameClassPairEnumeration diff --git a/src/library/spring-factory/src/main/java/org/geoserver/cloud/config/factory/FilteringXmlBeanDefinitionReader.java b/src/library/spring-factory/src/main/java/org/geoserver/cloud/config/factory/FilteringXmlBeanDefinitionReader.java index 3c6842d4d..9664cbb1d 100644 --- a/src/library/spring-factory/src/main/java/org/geoserver/cloud/config/factory/FilteringXmlBeanDefinitionReader.java +++ b/src/library/spring-factory/src/main/java/org/geoserver/cloud/config/factory/FilteringXmlBeanDefinitionReader.java @@ -82,6 +82,8 @@ @Slf4j(topic = "org.geoserver.cloud.config.factory") public class FilteringXmlBeanDefinitionReader extends XmlBeanDefinitionReader { + private static final String XML_SPLIT_TOKEN = ".xml#"; + /** * Cache parsed XML documents by Resource URI, since many configurations can try to load * different sets of beans from the same xml document @@ -98,7 +100,7 @@ public class FilteringXmlBeanDefinitionReader extends XmlBeanDefinitionReader { * @see FilteringXmlBeanDefinitionReaderAutoConfiguration * @see #clearCaches() */ - private static Resource[] allClasspathBaseResources; + private static Resource[] classpathBaseResources; public FilteringXmlBeanDefinitionReader(BeanDefinitionRegistry registry) { super(registry); @@ -107,14 +109,14 @@ public FilteringXmlBeanDefinitionReader(BeanDefinitionRegistry registry) { /** * Clears any cached resource, expected to be called after the application context is refreshed */ - public static void clearCaches() { - if (!classpathDocuments.isEmpty() || null != allClasspathBaseResources) { + public static synchronized void clearCaches() { + if (!classpathDocuments.isEmpty() || null != classpathBaseResources) { log.debug( "Clearing cache of {} parsed xml documents and {} classpath resources", classpathDocuments.size(), - null == allClasspathBaseResources ? 0 : allClasspathBaseResources.length); + null == classpathBaseResources ? 0 : classpathBaseResources.length); classpathDocuments.clear(); - allClasspathBaseResources = null; + classpathBaseResources = null; } } @@ -127,15 +129,15 @@ public static void clearCaches() { log.trace("Loading document {}", r); return super.doLoadDocument(inputSource, resource); } catch (Exception e) { - if (e instanceof RuntimeException) throw (RuntimeException) e; + if (e instanceof RuntimeException rte) throw rte; throw (RuntimeException) new BeanDefinitionStoreException(e.getMessage()).initCause(e); } }); } - public @Override int loadBeanDefinitions( - String location, @Nullable Set actualResources) + @Override + public int loadBeanDefinitions(String location, @Nullable Set actualResources) throws BeanDefinitionStoreException { super.setDocumentReaderClass(FilteringBeanDefinitionDocumentReader.class); @@ -215,34 +217,37 @@ private int loadBeanDefinitionsApplyingFilters(String location, Set ac * @return * @throws IOException */ - private Resource[] getAllClasspathResources(ResourcePatternResolver patternResolver) - throws IOException { - if (null == allClasspathBaseResources) { + private static synchronized Resource[] getAllClasspathResources( + ResourcePatternResolver patternResolver) throws IOException { + if (null == classpathBaseResources) { StopWatch sw = new StopWatch(); sw.start(); - allClasspathBaseResources = patternResolver.getResources("classpath*:"); + classpathBaseResources = patternResolver.getResources("classpath*:"); sw.stop(); if (log.isTraceEnabled()) { log.trace( String.format( "Loaded %,d classpath resources in %,dms", - allClasspathBaseResources.length, sw.getTotalTimeMillis())); + classpathBaseResources.length, sw.getTotalTimeMillis())); } } - return allClasspathBaseResources; + return classpathBaseResources; } private String removeBeanFilterExpressions(String location) { - if (location.contains(".xml#")) { - location = location.substring(0, location.indexOf(".xml#") + ".xml#".length() - 1); + if (location.contains(XML_SPLIT_TOKEN)) { + location = + location.substring( + 0, location.indexOf(XML_SPLIT_TOKEN) + XML_SPLIT_TOKEN.length() - 1); } return location; } private void parseAndSetBeanInclusionFilters(String location) { - if (location.contains(".xml#")) { + if (location.contains(XML_SPLIT_TOKEN)) { String filterTypeAndRegularExpression = - location.substring(".xml#".length() + location.indexOf(".xml#")); + location.substring( + XML_SPLIT_TOKEN.length() + location.indexOf(XML_SPLIT_TOKEN)); if (hasText(filterTypeAndRegularExpression)) { String[] split = filterTypeAndRegularExpression.split("="); if (split.length != 2) { @@ -273,13 +278,13 @@ private IllegalArgumentException throwInvalidExpression( String.format( "Invalid bean filter expression (%s), expected name=>, resource: %s", regex, resourceLocation); - throw new IllegalArgumentException(msg); + throw new IllegalArgumentException(msg, cause); } public static class FilteringBeanDefinitionDocumentReader extends DefaultBeanDefinitionDocumentReader { - private static ThreadLocal>> MATCHERS = + private static final ThreadLocal>> MATCHERS = ThreadLocal.withInitial(ArrayList::new); public static void addMatcher(Predicate beanDefFilter) { @@ -308,8 +313,8 @@ private boolean isFiltering() { return !MATCHERS.get().isEmpty(); } - private Set blackListedBeanNames = new HashSet(); - private Map deferredNameToAlias = new HashMap(); + private Set blackListedBeanNames = new HashSet<>(); + private Map deferredNameToAlias = new HashMap<>(); protected @Override void doRegisterBeanDefinitions(Element root) { super.doRegisterBeanDefinitions(root); diff --git a/src/library/spring-factory/src/test/java/org/geoserver/cloud/config/factory/FilteringXmlBeanDefinitionReaderTest.java b/src/library/spring-factory/src/test/java/org/geoserver/cloud/config/factory/FilteringXmlBeanDefinitionReaderTest.java index 68f5d48d3..dae792c32 100644 --- a/src/library/spring-factory/src/test/java/org/geoserver/cloud/config/factory/FilteringXmlBeanDefinitionReaderTest.java +++ b/src/library/spring-factory/src/test/java/org/geoserver/cloud/config/factory/FilteringXmlBeanDefinitionReaderTest.java @@ -16,7 +16,7 @@ import java.util.TreeSet; import java.util.stream.Collectors; -public class FilteringXmlBeanDefinitionReaderTest { +class FilteringXmlBeanDefinitionReaderTest { private final String baseResource = "classpath:/org/geoserver/cloud/config/factory/FilteringXmlBeanDefinitionReaderTestData.xml"; @@ -45,7 +45,8 @@ public class FilteringXmlBeanDefinitionReaderTest { reader = new FilteringXmlBeanDefinitionReader(registry); } - public @Test void noFilterIncludesdAll() { + @Test + void noFilterIncludesdAll() { verify( baseResource, "filterFactory", @@ -54,51 +55,60 @@ public class FilteringXmlBeanDefinitionReaderTest { "nullLockProvider"); } - public @Test void includedAll_AnyWord() { + @Test + void includedAll_AnyWord() { String location = baseResource + "#name=\\w+"; verify(location, "filterFactory", "geoServer", "memoryLockProvider", "nullLockProvider"); } - public @Test void excludeAll_AnyWord() { + @Test + void excludeAll_AnyWord() { String location = baseResource + "#name=^(?!\\w+).*$"; verify(location); } - public @Test void excludeByName() { + @Test + void excludeByName() { String location = baseResource + "#name=^(?!nullLockProvider|memoryLockProvider).*$"; verify(location, "filterFactory", "geoServer"); } - public @Test void excludeAllExplicitlyByName() { + @Test + void excludeAllExplicitlyByName() { String location = baseResource + "#name=^(?!nullLockProvider|memoryLockProvider|filterFactory|geoServer)$"; verify(location); } - public @Test void includeAllExplicitly() { + @Test + void includeAllExplicitly() { String location = baseResource + "#name=^(nullLockProvider|memoryLockProvider|filterFactory|geoServer)$"; verify(location, "filterFactory", "geoServer", "memoryLockProvider", "nullLockProvider"); } - public @Test void excludeAllEndingWithProviderOrStartingWithFilter() { + @Test + void excludeAllEndingWithProviderOrStartingWithFilter() { String location = baseResource + "#name=^(?!.*Provider|.*Factory).*$"; verify(location, "geoServer"); } - public @Test void excludeByIdAttribute() { + @Test + void excludeByIdAttribute() { String location = baseResource + "#name=^(?!nullLockProvider|memoryLockProvider).*$"; verify(location, "filterFactory", "geoServer"); } - public @Test void excludeByNameAttribute() { + @Test + void excludeByNameAttribute() { String location = baseResource + "#name=^(?!filterFactory|geoServer).*$"; verify(location, "memoryLockProvider", "nullLockProvider"); } - public @Test void includeByNameAttribute() { + @Test + void includeByNameAttribute() { String location = baseResource + "#name=^(filterFactory|geoServer).*$"; verify(location, "filterFactory", "geoServer"); } diff --git a/src/starters/reactive/src/test/java/org/geoserver/cloud/autoconfigure/core/GeoServerMainAutoConfigurationTest.java b/src/starters/reactive/src/test/java/org/geoserver/cloud/autoconfigure/core/GeoServerMainAutoConfigurationTest.java index 635348944..f67f3993f 100644 --- a/src/starters/reactive/src/test/java/org/geoserver/cloud/autoconfigure/core/GeoServerMainAutoConfigurationTest.java +++ b/src/starters/reactive/src/test/java/org/geoserver/cloud/autoconfigure/core/GeoServerMainAutoConfigurationTest.java @@ -25,16 +25,18 @@ @SpringBootTest(classes = TestConfiguration.class) @EnableAutoConfiguration @ActiveProfiles("test") // see bootstrap-test.yml -public class GeoServerMainAutoConfigurationTest { +class GeoServerMainAutoConfigurationTest { private @Autowired ApplicationContext context; - public @Test void testContext() { + @Test + void testContext() { assertFalse(context instanceof WebApplicationContext); assertTrue(context instanceof ReactiveWebApplicationContext); } - public @Test void rawCatalog() { + @Test + void rawCatalog() { Catalog catalog = (Catalog) context.getBean("rawCatalog"); assertThat(catalog, instanceOf(org.geoserver.catalog.plugin.CatalogPlugin.class)); @@ -44,7 +46,8 @@ public class GeoServerMainAutoConfigurationTest { instanceOf(org.geoserver.catalog.plugin.DefaultMemoryCatalogFacade.class)); } - public @Test void catalog() { + @Test + void catalog() { Catalog catalog = (Catalog) context.getBean("catalog"); assertThat(catalog, instanceOf(LocalWorkspaceCatalog.class)); } diff --git a/src/starters/security/src/main/java/org/geoserver/cloud/autoconfigure/authzn/AuthKeyAutoConfiguration.java b/src/starters/security/src/main/java/org/geoserver/cloud/autoconfigure/authzn/AuthKeyAutoConfiguration.java index 1b68876fa..71b9bdad4 100644 --- a/src/starters/security/src/main/java/org/geoserver/cloud/autoconfigure/authzn/AuthKeyAutoConfiguration.java +++ b/src/starters/security/src/main/java/org/geoserver/cloud/autoconfigure/authzn/AuthKeyAutoConfiguration.java @@ -39,7 +39,7 @@ ModuleStatus authKeyExtension( "${" + GEOSERVER_SECURITY_AUTHKEY + ":" - + ConditionalOnAuthKeyEnabled.enabledByDefault + + ConditionalOnAuthKeyEnabled.ENABLED_BY_DEFAULT + "}") boolean enabled) { diff --git a/src/starters/security/src/main/java/org/geoserver/cloud/autoconfigure/authzn/ConditionalOnAuthKeyEnabled.java b/src/starters/security/src/main/java/org/geoserver/cloud/autoconfigure/authzn/ConditionalOnAuthKeyEnabled.java index 4000d7ebb..b191ae359 100644 --- a/src/starters/security/src/main/java/org/geoserver/cloud/autoconfigure/authzn/ConditionalOnAuthKeyEnabled.java +++ b/src/starters/security/src/main/java/org/geoserver/cloud/autoconfigure/authzn/ConditionalOnAuthKeyEnabled.java @@ -35,7 +35,7 @@ @ConditionalOnProperty( name = AuthKeyAutoConfiguration.GEOSERVER_SECURITY_AUTHKEY, havingValue = "true", - matchIfMissing = ConditionalOnAuthKeyEnabled.enabledByDefault) + matchIfMissing = ConditionalOnAuthKeyEnabled.ENABLED_BY_DEFAULT) public @interface ConditionalOnAuthKeyEnabled { - boolean enabledByDefault = false; + boolean ENABLED_BY_DEFAULT = false; } diff --git a/src/starters/security/src/test/java/org/geoserver/cloud/autoconfigure/authzn/AuthKeyAutoConfigurationTest.java b/src/starters/security/src/test/java/org/geoserver/cloud/autoconfigure/authzn/AuthKeyAutoConfigurationTest.java index 11d2451b8..160d9e319 100644 --- a/src/starters/security/src/test/java/org/geoserver/cloud/autoconfigure/authzn/AuthKeyAutoConfigurationTest.java +++ b/src/starters/security/src/test/java/org/geoserver/cloud/autoconfigure/authzn/AuthKeyAutoConfigurationTest.java @@ -30,7 +30,7 @@ * * @since 1.0 */ -public class AuthKeyAutoConfigurationTest { +class AuthKeyAutoConfigurationTest { private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() @@ -42,7 +42,8 @@ void mockBeanDependencies() { contextRunner = contextRunner.withBean(GeoServerSecurityManager.class, () -> mockSM); } - public @Test void testModuleStatus_disabled_by_default() { + @Test + void testModuleStatus_disabled_by_default() { contextRunner .run(context -> assertThat(context).hasBean("authKeyExtension")) .run( @@ -52,7 +53,8 @@ void mockBeanDependencies() { .hasFieldOrPropertyWithValue("enabled", false)); } - public @Test void testModuleStatus_enabled() { + @Test + void testModuleStatus_enabled() { contextRunner .withPropertyValues("geoserver.security.authkey=true") .run(context -> assertThat(context).hasBean("authKeyExtension")) @@ -63,7 +65,8 @@ void mockBeanDependencies() { .hasFieldOrPropertyWithValue("enabled", true)); } - public @Test void testModuleStatus_disabled() { + @Test + void testModuleStatus_disabled() { contextRunner .withPropertyValues("geoserver.security.authkey=false") .run(context -> assertThat(context).hasBean("authKeyExtension")) @@ -74,7 +77,8 @@ void mockBeanDependencies() { .hasFieldOrPropertyWithValue("enabled", false)); } - public @Test void testGeoServerAuthenticationKeyProvider_enabled_no_GsWebSecCore_InClasspath() { + @Test + void testGeoServerAuthenticationKeyProvider_enabled_no_GsWebSecCore_InClasspath() { contextRunner .withPropertyValues("geoserver.security.authkey=true") // AuthenticationFilterPanel is from gs-web-sec-core, used as @ConditionalOnClass to @@ -91,7 +95,8 @@ void mockBeanDependencies() { }); } - public @Test void testGeoServerAuthenticationKeyProvider_enabled() { + @Test + void testGeoServerAuthenticationKeyProvider_enabled() { contextRunner .withPropertyValues("geoserver.security.authkey=true") .run( diff --git a/src/starters/spring-boot/src/main/java/org/geoserver/cloud/app/ServiceIdFilterAutoConfiguration.java b/src/starters/spring-boot/src/main/java/org/geoserver/cloud/app/ServiceIdFilterAutoConfiguration.java index db155ef0c..5151fbb72 100644 --- a/src/starters/spring-boot/src/main/java/org/geoserver/cloud/app/ServiceIdFilterAutoConfiguration.java +++ b/src/starters/spring-boot/src/main/java/org/geoserver/cloud/app/ServiceIdFilterAutoConfiguration.java @@ -47,8 +47,7 @@ static class ServiceIdFilter implements javax.servlet.Filter { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - if (response instanceof HttpServletResponse) { - HttpServletResponse httpServletResponse = (HttpServletResponse) response; + if (response instanceof HttpServletResponse httpServletResponse) { httpServletResponse.addHeader("X-gs-cloud-service-id", instanceId); } chain.doFilter(request, response); diff --git a/src/starters/webmvc/src/main/java/org/geoserver/cloud/autoconfigure/context/GeoServerContextInitializer.java b/src/starters/webmvc/src/main/java/org/geoserver/cloud/autoconfigure/context/GeoServerContextInitializer.java index 08829be73..766339aa7 100644 --- a/src/starters/webmvc/src/main/java/org/geoserver/cloud/autoconfigure/context/GeoServerContextInitializer.java +++ b/src/starters/webmvc/src/main/java/org/geoserver/cloud/autoconfigure/context/GeoServerContextInitializer.java @@ -55,7 +55,8 @@ public void initialize(ConfigurableApplicationContext applicationContext) { protected ServletContext mockServletContext() { InvocationHandler handler = new InvocationHandler() { - public @Override Object invoke(Object proxy, Method method, Object[] args) + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { return null; } diff --git a/src/starters/webmvc/src/main/java/org/geoserver/cloud/config/servlet/GeoServerServletContextConfiguration.java b/src/starters/webmvc/src/main/java/org/geoserver/cloud/config/servlet/GeoServerServletContextConfiguration.java index ae8c08aa3..5c84bd5fc 100644 --- a/src/starters/webmvc/src/main/java/org/geoserver/cloud/config/servlet/GeoServerServletContextConfiguration.java +++ b/src/starters/webmvc/src/main/java/org/geoserver/cloud/config/servlet/GeoServerServletContextConfiguration.java @@ -12,6 +12,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.context.request.RequestContextListener; @@ -29,8 +30,8 @@ public class GeoServerServletContextConfiguration { // Listeners @Bean - GeoServerServletInitializer contextLoaderListener() { - return new GeoServerServletInitializer(); + GeoServerServletInitializer contextLoaderListener(ApplicationContext appContext) { + return new GeoServerServletInitializer(appContext); } @ConditionalOnMissingBean(RequestContextListener.class) diff --git a/src/starters/webmvc/src/main/java/org/geoserver/cloud/config/servlet/GeoServerServletInitializer.java b/src/starters/webmvc/src/main/java/org/geoserver/cloud/config/servlet/GeoServerServletInitializer.java index ea15d40a5..cfd41bdda 100644 --- a/src/starters/webmvc/src/main/java/org/geoserver/cloud/config/servlet/GeoServerServletInitializer.java +++ b/src/starters/webmvc/src/main/java/org/geoserver/cloud/config/servlet/GeoServerServletInitializer.java @@ -4,9 +4,11 @@ */ package org.geoserver.cloud.config.servlet; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import org.geoserver.platform.ContextLoadedEvent; import org.geoserver.platform.GeoServerContextLoaderListener; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationListener; @@ -22,13 +24,14 @@ * ContextRefreshedEvent}, since servlet context initialization happens too early during application * context initialization and some things like the event bus may not be ready. */ +@RequiredArgsConstructor public class GeoServerServletInitializer implements ApplicationListener { /** * Actual application context, held to check whether the context being refreshed is this one and * avoid sending multiple geoserver-specific {@link ContextLoadedEvent}s */ - private @Autowired ApplicationContext appContext; + private final @NonNull ApplicationContext appContext; @Override public void onApplicationEvent(ContextRefreshedEvent event) { diff --git a/src/starters/webmvc/src/main/java/org/geoserver/cloud/virtualservice/VirtualServiceVerifier.java b/src/starters/webmvc/src/main/java/org/geoserver/cloud/virtualservice/VirtualServiceVerifier.java index 720678fae..4501a9648 100644 --- a/src/starters/webmvc/src/main/java/org/geoserver/cloud/virtualservice/VirtualServiceVerifier.java +++ b/src/starters/webmvc/src/main/java/org/geoserver/cloud/virtualservice/VirtualServiceVerifier.java @@ -5,13 +5,12 @@ package org.geoserver.cloud.virtualservice; import lombok.NonNull; +import lombok.RequiredArgsConstructor; import org.geoserver.catalog.Catalog; import org.geoserver.catalog.LayerGroupInfo; import org.geoserver.catalog.PublishedInfo; import org.geoserver.catalog.WorkspaceInfo; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.http.HttpStatus; import org.springframework.web.server.ResponseStatusException; @@ -22,9 +21,10 @@ * * @since 1.0 */ +@RequiredArgsConstructor public class VirtualServiceVerifier { - private @Autowired @Qualifier("rawCatalog") Catalog catalog; + private final @NonNull Catalog rawCatalog; /** * @throws 404 ResponseStatusException if {@code virtualService} can't be mapped to a workspace @@ -49,18 +49,18 @@ public void checkVirtualService(String virtualService, String layer) { } private Optional findWorkspace(String workspace) { - return Optional.ofNullable(catalog.getWorkspaceByName(workspace)); + return Optional.ofNullable(rawCatalog.getWorkspaceByName(workspace)); } private Optional findGlobalLayerGroup(String name) { - return Optional.ofNullable(catalog.getLayerGroupByName(name)); + return Optional.ofNullable(rawCatalog.getLayerGroupByName(name)); } private Optional findPublished(String workspace, String layer) { - PublishedInfo l = catalog.getLayerGroupByName(workspace, layer); + PublishedInfo l = rawCatalog.getLayerGroupByName(workspace, layer); if (null == l) { String qualifiedName = workspace + ":" + layer; - l = catalog.getLayerByName(qualifiedName); + l = rawCatalog.getLayerByName(qualifiedName); } return Optional.ofNullable(l); } diff --git a/src/starters/webmvc/src/test/java/org/geoserver/cloud/autoconfigure/servlet/ServletContextConditionalFiltersTest.java b/src/starters/webmvc/src/test/java/org/geoserver/cloud/autoconfigure/servlet/ServletContextConditionalFiltersTest.java index 22520e050..46789ee03 100644 --- a/src/starters/webmvc/src/test/java/org/geoserver/cloud/autoconfigure/servlet/ServletContextConditionalFiltersTest.java +++ b/src/starters/webmvc/src/test/java/org/geoserver/cloud/autoconfigure/servlet/ServletContextConditionalFiltersTest.java @@ -34,7 +34,7 @@ "geoserver.servlet.filter.flush-safe.enabled=false" }) @ActiveProfiles("test") -public class ServletContextConditionalFiltersTest { +class ServletContextConditionalFiltersTest { private @Autowired ApplicationContext context; @@ -49,23 +49,28 @@ public void sessionDebugFilter() { () -> context.getBean(SessionDebugFilter.class)); } - public @Test void contextLoaderListener() { + @Test + void contextLoaderListener() { assertNotNull(context.getBean(GeoServerServletInitializer.class)); } - public @Test void requestContextListener() { + @Test + void requestContextListener() { assertNotNull(context.getBean(RequestContextListener.class)); } - public @Test void advancedDispatchFilter() { + @Test + void advancedDispatchFilter() { assertNotNull(context.getBean(AdvancedDispatchFilter.class)); } - public @Test void springDelegatingFilter() { + @Test + void springDelegatingFilter() { assertNotNull(context.getBean(SpringDelegatingFilter.class)); } - public @Test void threadLocalsCleanupFilter() { + @Test + void threadLocalsCleanupFilter() { assertNotNull(context.getBean(ThreadLocalsCleanupFilter.class)); } } diff --git a/src/starters/webmvc/src/test/java/org/geoserver/cloud/autoconfigure/servlet/ServletContextDisabledSmokeTest.java b/src/starters/webmvc/src/test/java/org/geoserver/cloud/autoconfigure/servlet/ServletContextDisabledSmokeTest.java index 5885a1166..376f0a189 100644 --- a/src/starters/webmvc/src/test/java/org/geoserver/cloud/autoconfigure/servlet/ServletContextDisabledSmokeTest.java +++ b/src/starters/webmvc/src/test/java/org/geoserver/cloud/autoconfigure/servlet/ServletContextDisabledSmokeTest.java @@ -35,12 +35,12 @@ }) @EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class) @ActiveProfiles("test") -public class ServletContextDisabledSmokeTest { +class ServletContextDisabledSmokeTest { private @Autowired ApplicationContext context; @Test - public void contextLoaderListener() { + void contextLoaderListener() { assertThrows( NoSuchBeanDefinitionException.class, () -> context.getBean(GeoServerServletInitializer.class)); diff --git a/src/starters/webmvc/src/test/java/org/geoserver/cloud/autoconfigure/servlet/ServletContextEnabledSmokeTest.java b/src/starters/webmvc/src/test/java/org/geoserver/cloud/autoconfigure/servlet/ServletContextEnabledSmokeTest.java index 1764f3438..bec398e14 100644 --- a/src/starters/webmvc/src/test/java/org/geoserver/cloud/autoconfigure/servlet/ServletContextEnabledSmokeTest.java +++ b/src/starters/webmvc/src/test/java/org/geoserver/cloud/autoconfigure/servlet/ServletContextEnabledSmokeTest.java @@ -28,35 +28,42 @@ properties = "reactive.feign.loadbalancer.enabled=false") @EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class) @ActiveProfiles("test") -public class ServletContextEnabledSmokeTest { +class ServletContextEnabledSmokeTest { private @Autowired ApplicationContext context; - public @Test void contextLoaderListener() { + @Test + void contextLoaderListener() { assertNotNull(context.getBean(GeoServerServletInitializer.class)); } - public @Test void requestContextListener() { + @Test + void requestContextListener() { assertNotNull(context.getBean(RequestContextListener.class)); } - public @Test void flushSafeFilter() { + @Test + void flushSafeFilter() { assertNotNull(context.getBean(FlushSafeFilter.class)); } - public @Test void sessionDebugFilter() { + @Test + void sessionDebugFilter() { assertNotNull(context.getBean(SessionDebugFilter.class)); } - public @Test void advancedDispatchFilter() { + @Test + void advancedDispatchFilter() { assertNotNull(context.getBean(AdvancedDispatchFilter.class)); } - public @Test void springDelegatingFilter() { + @Test + void springDelegatingFilter() { assertNotNull(context.getBean(SpringDelegatingFilter.class)); } - public @Test void threadLocalsCleanupFilter() { + @Test + void threadLocalsCleanupFilter() { assertNotNull(context.getBean(ThreadLocalsCleanupFilter.class)); } } diff --git a/src/starters/webmvc/src/test/java/org/geoserver/cloud/config/main/GeoServerMainConfigurationSmokeTest.java b/src/starters/webmvc/src/test/java/org/geoserver/cloud/config/main/GeoServerMainConfigurationSmokeTest.java index 434ce0b66..03e68cf35 100644 --- a/src/starters/webmvc/src/test/java/org/geoserver/cloud/config/main/GeoServerMainConfigurationSmokeTest.java +++ b/src/starters/webmvc/src/test/java/org/geoserver/cloud/config/main/GeoServerMainConfigurationSmokeTest.java @@ -22,12 +22,13 @@ classes = {TestConfiguration.class}, properties = "reactive.feign.loadbalancer.enabled=false") @ActiveProfiles("test") -public class GeoServerMainConfigurationSmokeTest { +class GeoServerMainConfigurationSmokeTest { private @Autowired @Qualifier("rawCatalog") Catalog rawCatalog; private @Autowired @Qualifier("secureCatalog") Catalog secureCatalog; - public @Test void contextLoads() { + @Test + void contextLoads() { assertThat(rawCatalog, instanceOf(CatalogImpl.class)); assertThat(secureCatalog, instanceOf(SecureCatalogImpl.class)); } diff --git a/src/starters/wms-extensions/src/main/java/org/geoserver/cloud/autoconfigure/wms/extensions/VectorTilesConfiguration.java b/src/starters/wms-extensions/src/main/java/org/geoserver/cloud/autoconfigure/wms/extensions/VectorTilesConfiguration.java index 51ad2dc50..ad1abdfb3 100644 --- a/src/starters/wms-extensions/src/main/java/org/geoserver/cloud/autoconfigure/wms/extensions/VectorTilesConfiguration.java +++ b/src/starters/wms-extensions/src/main/java/org/geoserver/cloud/autoconfigure/wms/extensions/VectorTilesConfiguration.java @@ -7,7 +7,6 @@ import org.geoserver.cloud.autoconfigure.wms.extensions.WmsExtensionsConfigProperties.Wms.WmsOutputFormatsConfigProperties.VectorTilesConfigProperties; import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; import org.geoserver.wms.vector.VectorTileMapOutputFormat; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -15,8 +14,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; -import javax.annotation.PostConstruct; - /** * @since 1.0 */ @@ -30,11 +27,11 @@ class VectorTilesConfiguration { static final String PREFIX = "geoserver.wms.output-formats.vector-tiles"; - private @Autowired @Qualifier("VectorTilesExtension") org.geoserver.platform.ModuleStatusImpl - extensionInfo; - private @Autowired WmsExtensionsConfigProperties config; + VectorTilesConfiguration( + @Qualifier("VectorTilesExtension") + org.geoserver.platform.ModuleStatusImpl extensionInfo, + WmsExtensionsConfigProperties config) { - public @PostConstruct void init() { VectorTilesConfigProperties vt = config.getWms().getOutputFormats().getVectorTiles(); extensionInfo.setEnabled(vt.anyEnabled()); } diff --git a/src/starters/wms-extensions/src/test/java/org/geoserver/cloud/autoconfigure/wms/extensions/CssStylingConfigurationTest.java b/src/starters/wms-extensions/src/test/java/org/geoserver/cloud/autoconfigure/wms/extensions/CssStylingConfigurationTest.java index 87fe1e7d6..bda5779a9 100644 --- a/src/starters/wms-extensions/src/test/java/org/geoserver/cloud/autoconfigure/wms/extensions/CssStylingConfigurationTest.java +++ b/src/starters/wms-extensions/src/test/java/org/geoserver/cloud/autoconfigure/wms/extensions/CssStylingConfigurationTest.java @@ -18,7 +18,7 @@ * * @since 1.0 */ -public class CssStylingConfigurationTest { +class CssStylingConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() diff --git a/src/starters/wms-extensions/src/test/java/org/geoserver/cloud/autoconfigure/wms/extensions/MapBoxStylingConfigurationTest.java b/src/starters/wms-extensions/src/test/java/org/geoserver/cloud/autoconfigure/wms/extensions/MapBoxStylingConfigurationTest.java index d726400fa..4bb62efa1 100644 --- a/src/starters/wms-extensions/src/test/java/org/geoserver/cloud/autoconfigure/wms/extensions/MapBoxStylingConfigurationTest.java +++ b/src/starters/wms-extensions/src/test/java/org/geoserver/cloud/autoconfigure/wms/extensions/MapBoxStylingConfigurationTest.java @@ -18,7 +18,7 @@ * * @since 1.0 */ -public class MapBoxStylingConfigurationTest { +class MapBoxStylingConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() diff --git a/src/starters/wms-extensions/src/test/java/org/geoserver/cloud/autoconfigure/wms/extensions/VectorTilesConfigurationTest.java b/src/starters/wms-extensions/src/test/java/org/geoserver/cloud/autoconfigure/wms/extensions/VectorTilesConfigurationTest.java index 2e6a6203d..3d3c60a36 100644 --- a/src/starters/wms-extensions/src/test/java/org/geoserver/cloud/autoconfigure/wms/extensions/VectorTilesConfigurationTest.java +++ b/src/starters/wms-extensions/src/test/java/org/geoserver/cloud/autoconfigure/wms/extensions/VectorTilesConfigurationTest.java @@ -16,7 +16,7 @@ * * @since 1.0 */ -public class VectorTilesConfigurationTest { +class VectorTilesConfigurationTest { private ApplicationContextRunner contextRunner = new ApplicationContextRunner()