Skip to content

Commit

Permalink
Merge pull request #1482 from synthetichealth/fix_config_cli
Browse files Browse the repository at this point in the history
Fix issue with setting config via CLI
  • Loading branch information
jawalonoski authored Jul 8, 2024
2 parents 8008933 + c56e7a9 commit 27e32d4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions src/main/java/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public static void main(String[] args) throws Exception {

boolean validArgs = true;
boolean overrideFutureDateError = false;
boolean reloadConfig = false;
if (args != null && args.length > 0) {
try {
Queue<String> argsQ = new LinkedList<String>(Arrays.asList(args));
Expand Down Expand Up @@ -104,6 +105,7 @@ public static void main(String[] args) throws Exception {
} else if (currArg.equalsIgnoreCase("-p")) {
String value = argsQ.poll();
options.population = Integer.parseInt(value);
Config.set("generate.default_population", value);
} else if (currArg.equalsIgnoreCase("-o")) {
String value = argsQ.poll();
options.overflow = Boolean.parseBoolean(value);
Expand Down Expand Up @@ -132,10 +134,7 @@ public static void main(String[] args) throws Exception {
String value = argsQ.poll();
File configFile = new File(value);
Config.load(configFile);
// Any options that are automatically set by reading the configuration
// file during options initialization need to be reset here.
options.population = Config.getAsInteger("generate.default_population", 1);
options.threadPoolSize = Config.getAsInteger("generate.thread_pool_size", -1);
reloadConfig = true;
} else if (currArg.equalsIgnoreCase("-d")) {
String value = argsQ.poll();
File localModuleDir = new File(value);
Expand Down Expand Up @@ -252,6 +251,7 @@ public static void main(String[] args) throws Exception {
}

Config.set(configSetting, value);
reloadConfig = true;
} else if (options.state == null) {
options.state = currArg;
} else {
Expand All @@ -266,12 +266,30 @@ public static void main(String[] args) throws Exception {
}
}

if (reloadConfig) {
resetOptionsFromConfig(options, exportOptions);
}

if (validArgs && validateConfig(options, overrideFutureDateError)) {
Generator generator = new Generator(options, exportOptions);
generator.run();
}
}

/**
* Reset the fields of the provided options to the current values in the Config.
*/
private static void resetOptionsFromConfig(Generator.GeneratorOptions options,
Exporter.ExporterRuntimeOptions exportOptions) {
// Any options that are automatically set by reading the configuration
// file during options initialization need to be reset here.
options.population = Config.getAsInteger("generate.default_population", 1);
options.threadPoolSize = Config.getAsInteger("generate.thread_pool_size", -1);

exportOptions.yearsOfHistory = Config.getAsInteger("exporter.years_of_history", 10);
exportOptions.terminologyService = !Config.get("generate.terminology_service_url", "").isEmpty();
}

private static boolean validateConfig(Generator.GeneratorOptions options,
boolean overrideFutureDateError) {
boolean valid = true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/mitre/synthea/export/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static class ExporterRuntimeOptions {
private List<Mapping> flexporterMappings;

public ExporterRuntimeOptions() {
yearsOfHistory = Integer.parseInt(Config.get("exporter.years_of_history"));
yearsOfHistory = Config.getAsInteger("exporter.years_of_history", 10);
}

/**
Expand Down

0 comments on commit 27e32d4

Please sign in to comment.