Skip to content

Commit

Permalink
Merge pull request #170 from LinuxForHealth/620-config-home-env
Browse files Browse the repository at this point in the history
620 config home env - allow using environment variable to set config.properties home
  • Loading branch information
evbaron authored Aug 20, 2021
2 parents 9090624 + 36af5eb commit a66a0ee
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,16 @@ The converter configuration file, config.properties, supports the following sett
| default.zoneid | ISO 8601 timezone offset (optional). The zoneid is applied to translations when the target FHIR resource field requires a timezone, but the source HL7 field does not include it. | +08:00 |
| additional.conceptmap | Path to additional concept map configuration. Concept maps are used for mapping one code system to another. | /opt/converter/concept-map.yaml |

The config.properties file location is set using the System property, `config.home`
### HL7 Converter Configuration Property Location

```
-Dconfig.home=/opt/converter/config
```
The config.properties file location is searched in the following order:

* HL7CONVERTER_CONFIG_HOME environment variable is checked first
* hl7converter.config.home system property is checked next

``` -Dhl7converter.config.home=/opt/converter/config_home_folder/```

* Lastly, the local classpath resource folder will be searched for config.properties

## Additional Documentation
* [Templating Configuration](./TEMPLATING.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

public class ConfigDirectoryLocationStrategy implements FileLocationStrategy {

private static final String CONF_PROP_HOME = "config.home";
private static final String CONF_PROP_HOME_SYSTEM_PROP = "hl7converter.config.home";
private static final String CONF_PROP_HOME_ENV_VAR = "HL7CONVERTER_CONFIG_HOME";

private static final Logger LOGGER =
LoggerFactory.getLogger(ConfigDirectoryLocationStrategy.class);

Expand Down Expand Up @@ -65,6 +67,9 @@ public URL locate(final FileSystem fileSystem, final FileLocator locator) {


private static String fetchHomeDirectory() {
return System.getProperty(CONF_PROP_HOME);
String homeDirectory = System.getenv(CONF_PROP_HOME_ENV_VAR);
if (homeDirectory==null || homeDirectory.trim().isEmpty())
return System.getProperty(CONF_PROP_HOME_SYSTEM_PROP);
return homeDirectory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import java.io.IOException;
import java.util.Properties;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

Expand All @@ -22,21 +24,40 @@

public class ConverterConfigurationTest {

@TempDir

private static final String CONF_PROP_HOME = "hl7converter.config.home";

@TempDir
static File folder;

static String originalConfigHome;

@BeforeAll
public static void saveConfigHomeProperty() {
originalConfigHome = System.getProperty(CONF_PROP_HOME);
}

@AfterEach
public void reset() {
System.clearProperty("config.home");
System.clearProperty(CONF_PROP_HOME);
ConverterConfiguration.reset();
UrlLookup.reset();
}
@AfterAll
public static void reloadPreviousConfigurations() {
if (originalConfigHome != null)
System.setProperty(CONF_PROP_HOME, originalConfigHome);
else
System.clearProperty(CONF_PROP_HOME);
UrlLookup.reset();
}


@Test
public void test_that_additional_conceptmap_values_are_loaded() throws IOException {
File configFile = new File(folder, "config.properties");
writeProperties(configFile);
System.setProperty("config.home", configFile.getParent());
System.setProperty(CONF_PROP_HOME, configFile.getParent());
ConverterConfiguration.reset();
UrlLookup.reset(Constants.CODING_SYSTEM_MAPPING);
String url = UrlLookup.getSystemUrl("LN");
Expand Down

0 comments on commit a66a0ee

Please sign in to comment.