Automatic verification when call fails

This commit is contained in:
Keith Armstrong 2025-01-25 18:16:06 -05:00
parent fd18efe4b4
commit 5337728368
2 changed files with 57 additions and 24 deletions

View File

@ -18,19 +18,32 @@ public class userVerify
String varFileName; String varFileName;
Scanner myObj = new Scanner(System.in); // Create a Scanner object Scanner myObj = new Scanner(System.in); // Create a Scanner object
while (true)
if (args.length > 0)
{ {
System.out.print(varPrompt); System.out.println("Running verification [file] : " + args[0]);
varFileName = myObj.nextLine().trim(); System.out.println("Running verification [invalidate line] : " + args[1]);
File thisFile = new File(varFileName); System.out.println();
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 : ";
} }
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; boolean varUserBlockEmpty = false;
HashMap<String, Boolean> valueMap = new HashMap(); HashMap<String, Boolean> valueMap = new HashMap();
@ -38,19 +51,27 @@ public class userVerify
valueMap.put("N", false); valueMap.put("N", false);
valueMap.put("", true); 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 = args[1];
String varAnswer = myObj.nextLine(); varSanitized = varAnswer.toUpperCase().trim();
String 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()) if (varSanitized.equals("Y") || varSanitized.equals("N") || varSanitized.isEmpty())
{ {
varUserBlockEmpty = valueMap.get(varSanitized); break;
break; }
} }
} }
varUserBlockEmpty = valueMap.get(varSanitized);
System.out.println(); System.out.println();
debugProcessor.writer(true, "CSV filename to validate : " + varFileName); debugProcessor.writer(true, "CSV filename to validate : " + varFileName);
debugProcessor.writer(true, "CSV invalidate on empty : " + varUserBlockEmpty); debugProcessor.writer(true, "CSV invalidate on empty : " + varUserBlockEmpty);
@ -74,7 +95,7 @@ public class userVerify
debugProcessor.writer(true, ""); debugProcessor.writer(true, "");
} }
boolean validFile = (!thisCSV.isEmpty()); 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); debugProcessor.writer(true, "CSV file is valid : " + validFile);
System.out.println(); System.out.println();
} }
@ -103,7 +124,7 @@ public class userVerify
varHeader = fileProcessor.readFirstLine(thisFile); varHeader = fileProcessor.readFirstLine(thisFile);
if (varHeader.length() == 0) 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; return finalArray;
} }

View File

@ -232,12 +232,24 @@ public class webService {
boolean validFile = (!thisCSV.isEmpty()); boolean validFile = (!thisCSV.isEmpty());
debugProcessor.writer(varDebug, ""); debugProcessor.writer(varDebug, "");
debugProcessor.writer(true, "CSV file is valid : " + validFile); debugProcessor.writer(true, "CSV record count : " + thisCSV.size());
debugProcessor.writer(true, "CSV records to process : " + thisCSV.size()); debugProcessor.writer(true, "CSV file is valid : " + validFile);
if (!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<Boolean, String> 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; int varCount = 0;