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

Fix issue with setting config via CLI #1482

Merged
merged 1 commit into from
Jul 8, 2024
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
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
Loading