Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make GeoServerHomePage.selectionMode system property default to TEXT #471

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}
Loading