Skip to content

Commit

Permalink
Merge pull request #471 from groldan/webui/default_homepage_selection…
Browse files Browse the repository at this point in the history
…_mode_text

Make GeoServerHomePage.selectionMode system property default to TEXT
  • Loading branch information
groldan authored May 16, 2024
2 parents 6dc6720 + 59d0af2 commit 5dc41b0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* (c) 2024 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.extern.slf4j.Slf4j;

import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.StringUtils;
import org.springframework.web.context.support.GenericWebApplicationContext;

/**
* @since 1.8.2
*/
@Slf4j
public class WebUIContextInitializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> {

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
// run once for the webapp context, ignore the actuator context
if (!(applicationContext instanceof GenericWebApplicationContext)) {
return;
}
setHomePageSelectionMode();
}

private void setHomePageSelectionMode() {

String systemProp = System.getProperty("GeoServerHomePage.selectionMode");
if (StringUtils.hasText(systemProp)) {
log.info(
"GeoServerHomePage.selectionMode set to '{}' through system property",
systemProp);
} else {
String selectionMode = "TEXT";
log.info("GeoServerHomePage.selectionMode set to '{}' as default value", selectionMode);
System.setProperty("GeoServerHomePage.selectionMode", selectionMode);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Initializers
org.springframework.context.ApplicationContextInitializer=\
org.geoserver.cloud.autoconfigure.web.core.WebUIContextInitializer

# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.geoserver.cloud.autoconfigure.web.core.WebUIApplicationAutoConfiguration,\
org.geoserver.cloud.autoconfigure.web.cloudnative.CloudNativeUIAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package org.geoserver.cloud.web.app;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

Expand Down Expand Up @@ -169,4 +170,12 @@ protected void assertHidden(String id) {
.formatted(id);
assertEquals("unused", tag.getAttribute("class"), msg);
}

/**
* @see WebUIContextInitializer
*/
@Test
void homePageSelectionModeDefaultsToTEXT() {
assertThat(System.getProperty("GeoServerHomePage.selectionMode")).isEqualTo("TEXT");
}
}

0 comments on commit 5dc41b0

Please sign in to comment.