Skip to content

Commit

Permalink
Refactor to helper function to reduce duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Tara Drwenski committed Feb 23, 2024
1 parent 33a6b01 commit 857332f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions tds/src/main/java/thredds/server/config/TdsConfigMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ static void load(WmsConfigBean wmsConfig, TdsContext tdsContext) {
wmsConfig.setAllow(Boolean.parseBoolean(WMS_ALLOW.getValueFromThreddsConfig()));
wmsConfig.setAllowRemote(Boolean.parseBoolean(WMS_ALLOW_REMOTE.getValueFromThreddsConfig()));

String paletteLocation = WMS_PALETTE_LOCATION_DIR.getValueFromThreddsConfig();
if (paletteLocation == null)
paletteLocation = defaultPaletteLocation;
final String paletteLocation =
getValueFromThreddsConfigOrDefault(WMS_PALETTE_LOCATION_DIR, defaultPaletteLocation);
wmsConfig.setPaletteLocationDir(paletteLocation);
try {
ColourPalette.addPaletteDirectory(new File(paletteLocation));
Expand All @@ -224,9 +223,7 @@ static void load(WmsConfigBean wmsConfig, TdsContext tdsContext) {
}
}

String stylesLocation = WMS_STYLES_LOCATION_DIR.getValueFromThreddsConfig();
if (stylesLocation == null)
stylesLocation = defaultStylesLocation;
final String stylesLocation = getValueFromThreddsConfigOrDefault(WMS_STYLES_LOCATION_DIR, defaultStylesLocation);
wmsConfig.setStylesLocationDir(stylesLocation);
try {
SldTemplateStyleCatalogue.getStyleCatalogue().addStylesInDirectory(new File(stylesLocation));
Expand All @@ -236,9 +233,7 @@ static void load(WmsConfigBean wmsConfig, TdsContext tdsContext) {
}
}

String wmsConfigFile = WMS_CONFIG_FILE.getValueFromThreddsConfig();
if (wmsConfigFile == null)
wmsConfigFile = defaultWmsConfigFile;
final String wmsConfigFile = getValueFromThreddsConfigOrDefault(WMS_CONFIG_FILE, defaultWmsConfigFile);

WmsDetailedConfig wdc = WmsDetailedConfig.fromLocation(wmsConfigFile);
if (wdc == null) {
Expand Down Expand Up @@ -276,6 +271,14 @@ static void load(WmsConfigBean wmsConfig, TdsContext tdsContext) {
}
}

private static String getValueFromThreddsConfigOrDefault(WmsConfigMappings property, String defaultValue) {
final String value = property.getValueFromThreddsConfig();
if (value == null) {
return defaultValue;
}
return value;
}

enum TdsUpdateConfigMappings {
TDSUPDAATE_LOGVERSIONINFO("TdsUpdateConfig.logVersionInfo", null, "true");

Expand Down

0 comments on commit 857332f

Please sign in to comment.