From 5337728368f896511b628650f5c14086479a2981 Mon Sep 17 00:00:00 2001 From: Keith Armstrong Date: Sat, 25 Jan 2025 18:16:06 -0500 Subject: [PATCH] Automatic verification when call fails --- src/com/belkast/soap/userVerify.java | 63 ++++++++++++++++++---------- src/com/belkast/soap/webService.java | 18 ++++++-- 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/src/com/belkast/soap/userVerify.java b/src/com/belkast/soap/userVerify.java index 08f15a3..4cd4f9d 100644 --- a/src/com/belkast/soap/userVerify.java +++ b/src/com/belkast/soap/userVerify.java @@ -18,19 +18,32 @@ public class userVerify String varFileName; Scanner myObj = new Scanner(System.in); // Create a Scanner object - while (true) + + if (args.length > 0) { - System.out.print(varPrompt); - varFileName = myObj.nextLine().trim(); - File thisFile = new File(varFileName); - boolean isValidFile = fileProcessor.validFile(varFileName); - if ( thisFile.exists() && isValidFile ) - { - break; - } - varPrompt = "\nThe CSV file does not exist or cannot be read!\nPlease enter the name of the CSV file to validate : "; + System.out.println("Running verification [file] : " + args[0]); + System.out.println("Running verification [invalidate line] : " + args[1]); + System.out.println(); } + if (args.length > 0) + { + varFileName = args[0]; + System.out.println("Please enter the name of the CSV file to validate : " + varFileName); + } + else + { + while (true) { + System.out.print(varPrompt); + varFileName = myObj.nextLine().trim(); + File thisFile = new File(varFileName); + boolean isValidFile = fileProcessor.validFile(varFileName); + if (thisFile.exists() && isValidFile) { + break; + } + varPrompt = "\nThe CSV file does not exist or cannot be read!\nPlease enter the name of the CSV file to validate : "; + } + } boolean varUserBlockEmpty = false; HashMap valueMap = new HashMap(); @@ -38,19 +51,27 @@ public class userVerify valueMap.put("N", false); valueMap.put("", true); - while (true) + String varSanitized = new String(); + if (args.length > 0) { - System.out.print("Invalidate a line if there are empty column values? (Y/n) : "); - String varAnswer = myObj.nextLine(); - String varSanitized = varAnswer.toUpperCase().trim(); + String varAnswer = args[1]; + varSanitized = varAnswer.toUpperCase().trim(); + System.out.println("Invalidate a line if there are empty column values? (Y/n) : " + varAnswer); + } + else + { + while (true) { + System.out.print("Invalidate a line if there are empty column values? (Y/n) : "); + String varAnswer = myObj.nextLine(); + varSanitized = varAnswer.toUpperCase().trim(); - if (varSanitized.equals("Y") || varSanitized.equals("N") || varSanitized.isEmpty()) - { - varUserBlockEmpty = valueMap.get(varSanitized); - break; + if (varSanitized.equals("Y") || varSanitized.equals("N") || varSanitized.isEmpty()) + { + break; + } } } - + varUserBlockEmpty = valueMap.get(varSanitized); System.out.println(); debugProcessor.writer(true, "CSV filename to validate : " + varFileName); debugProcessor.writer(true, "CSV invalidate on empty : " + varUserBlockEmpty); @@ -74,7 +95,7 @@ public class userVerify debugProcessor.writer(true, ""); } boolean validFile = (!thisCSV.isEmpty()); - debugProcessor.writer(true, "CSV file records : " + varIter); + debugProcessor.writer(true, "CSV record count : " + varIter); debugProcessor.writer(true, "CSV file is valid : " + validFile); System.out.println(); } @@ -103,7 +124,7 @@ public class userVerify varHeader = fileProcessor.readFirstLine(thisFile); if (varHeader.length() == 0) { - System.out.println("CSV failure error : Header line not found!"); + System.out.println("CSV failure error : Header line not found!"); return finalArray; } diff --git a/src/com/belkast/soap/webService.java b/src/com/belkast/soap/webService.java index 8959dff..665ddbc 100644 --- a/src/com/belkast/soap/webService.java +++ b/src/com/belkast/soap/webService.java @@ -232,12 +232,24 @@ public class webService { boolean validFile = (!thisCSV.isEmpty()); debugProcessor.writer(varDebug, ""); - debugProcessor.writer(true, "CSV file is valid : " + validFile); - debugProcessor.writer(true, "CSV records to process : " + thisCSV.size()); + debugProcessor.writer(true, "CSV record count : " + thisCSV.size()); + debugProcessor.writer(true, "CSV file is valid : " + validFile); if (!validFile) { - debugProcessor.writer(true, varRoleFile + " => verification failed : please verify the file with com.belkast.soap.userVerify!"); + System.out.println(); + String response = credentialsProcessor.getCredential("To verify the " + varRoleFile + " file, please type yes", "^$|^.+$", false); + HashMap valueMap = new HashMap(); + valueMap.put(true, "Y"); + valueMap.put(false, "N"); + + if (response.equals("yes")) + { + String[] arguments = new String[] {varRoleFile,valueMap.get(!varEmptyColumns)}; + userVerify.main(arguments); + } + System.out.println(); + System.exit(0); } int varCount = 0;