Skip to content

Commit

Permalink
Refactored some repeated code into its own method, adjusted various l…
Browse files Browse the repository at this point in the history
…ogger.info messages for readability.
  • Loading branch information
Evan Chicoine committed Oct 2, 2024
1 parent ac3597d commit a33459a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void bundleResources(ArrayList<String> refreshedLibraryNames, String igPa
final Map<String, String> libraryPathMap = new ConcurrentHashMap<>(IOUtils.getLibraryPathMap(fhirContext));

if (resourcesMap.isEmpty()) {
logger.info("[INFO] No " + getResourceBundlerType() + "s found. Continuing...");
logger.info("\n\r" + "[INFO] No " + getResourceBundlerType() + "s found. Continuing...\n\r");
return;
}

Expand All @@ -169,7 +169,7 @@ public void bundleResources(ArrayList<String> refreshedLibraryNames, String igPa
tasks.add(() -> {
//check if resourceSourcePath has been processed before:
if (processedResources.contains(resourceSourcePath)) {
logger.info(getResourceBundlerType() + " processed already: " + resourceSourcePath);
logger.info("\n\r" + getResourceBundlerType() + " processed already: " + resourceSourcePath);
return null;
}
String resourceName = FilenameUtils.getBaseName(resourceSourcePath).replace(getResourcePrefix(), "");
Expand Down Expand Up @@ -296,7 +296,7 @@ public void bundleResources(ArrayList<String> refreshedLibraryNames, String igPa
//Output final report:
String summaryOutput = generateBundleProcessSummary(refreshedLibraryNames, fhirContext, fhirUri, verboseMessaging,
persistedFileReport, bundledResources, failedExceptionMessages, cqlTranslatorErrorMessages).toString();
logger.info(summaryOutput);
logger.info("\n\r" + summaryOutput);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void bundleIg(ArrayList<String> refreshedLibraryNames, String igPath, Lis

//run collected post calls last:
if (HttpClientUtils.hasPostTasksInQueue()) {
logger.info("[Persisting Files to " + fhirUri + "]");
logger.info("\n\r[Persisting Files to " + fhirUri + "]\n\r");
HttpClientUtils.postTaskCollection();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,19 @@ private static void reportProgress(HttpPOSTResourceType postType) {

String fileGroup = "";
if (postType != null) {
fileGroup = "Current POST group: " + postType.getDisplayName() + " " + getSectionPercentage(postType) + " ";
fileGroup = "Posting: " + postType.getDisplayName() + " (" + getSectionPercentage(postType) + ")";
}

double percentage = (double) currentCounter / getTotalTaskCount() * 100;
System.out.print("\rOverall Progress: " + String.format("%.2f%%", percentage) + ". " +
String progressStr = "\rOverall Progress: " + String.format("%.2f%%", percentage) + ". " +
"POST response pool size: " + runningPostTaskList.size() + ". " +
fileGroup);
fileGroup;


String repeatedString = " ".repeat(progressStr.length() * 2);
System.out.print(repeatedString);

System.out.print(progressStr);
}


Expand Down Expand Up @@ -420,21 +426,11 @@ public static void postTaskCollection() {
ExecutorService executorService = Executors.newFixedThreadPool(1);

try {
logger.info(getTotalTaskCount() + " POST calls to be made. Starting now. Please wait...");
double percentage = 0;
System.out.print("\rPOST: " + String.format("%.2f%%", percentage) + " done. ");

//execute the tasks for each priority ranking, sorted:
for (int i = 0; i < resourceTypePostOrder.size(); i++) {
//execute the tasks in order specified
if (mappedTasksByPriorityRank.containsKey(resourceTypePostOrder.get(i))) {
executeTasks(executorService, mappedTasksByPriorityRank.get(resourceTypePostOrder.get(i)));
}
}
logger.info("\n\r" + getTotalTaskCount() + " POST calls to be made. Starting now. Please wait..." + "\n\r");
runPostCalls(executorService);

reportProgress();

logger.info("Processing results...");
logger.info("\n\r" + "Processing results..."+ "\n\r");
Collections.sort(successfulPostCalls);

StringBuilder message = new StringBuilder();
Expand All @@ -446,7 +442,7 @@ public static void postTaskCollection() {
successfulPostCalls = new ArrayList<>();

if (!failedPostCalls.isEmpty()) {
logger.info(failedPostCalls.size() + " tasks failed to POST. Retry these failed posts? (Y/N)");
logger.info("\n\r" + failedPostCalls.size() + " tasks failed to POST. Retry these failed posts? (Y/N)");
Scanner scanner = new Scanner(System.in);
String userInput = scanner.nextLine().trim().toLowerCase();

Expand All @@ -468,16 +464,8 @@ public static void postTaskCollection() {
}
}

//execute any tasks marked as having priority:
//execute the tasks for each priority ranking, sorted:
for (int i = 0; i < resourceTypePostOrder.size(); i++) {
//execute the tasks in order specified
if (mappedTasksByPriorityRank.containsKey(resourceTypePostOrder.get(i))) {
executeTasks(executorService, mappedTasksByPriorityRank.get(resourceTypePostOrder.get(i)));
}
}
runPostCalls(executorService);

reportProgress();
if (failedPostCalls.isEmpty()) {
logger.info("\r\nRetry successful, all tasks successfully posted");
}
Expand Down Expand Up @@ -520,6 +508,22 @@ public static void postTaskCollection() {
}
}

/**
* Executes the tasks for each priority ranking, sorted:
* @param executorService
*/
private static void runPostCalls(ExecutorService executorService) {
//execute the tasks for each priority ranking, sorted:
for (int i = 0; i < resourceTypePostOrder.size(); i++) {
//execute the tasks in order specified
if (mappedTasksByPriorityRank.containsKey(resourceTypePostOrder.get(i))) {
executeTasks(executorService, mappedTasksByPriorityRank.get(resourceTypePostOrder.get(i)));
}
}

reportProgress();
}

/**
* Gives the user a log file containing failed POST attempts during postTaskCollection()
*
Expand Down

0 comments on commit a33459a

Please sign in to comment.