diff --git a/src/com/belkast/soap/userVerify.java b/src/com/belkast/soap/userVerify.java index 84e9018..864b93f 100644 --- a/src/com/belkast/soap/userVerify.java +++ b/src/com/belkast/soap/userVerify.java @@ -2,6 +2,7 @@ package com.belkast.soap; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVRecord; +import org.apache.commons.csv.DuplicateHeaderMode; import java.io.*; import java.nio.file.Files; @@ -14,15 +15,22 @@ public class userVerify System.out.println(); Scanner myObj = new Scanner(System.in); // Create a Scanner object + debugProcessor.writer(false, ""); + debugProcessor.writer(true, "SOAP Client (03.01.2025 build) - Belkast Consulting (c) 2025"); + debugProcessor.writer(true, ""); + String varPrompt = "Please enter the name of the CSV file to validate : "; String varFileName; - while (true) { - System.out.print("Please enter the CSV filename to validate : "); - varFileName = myObj.nextLine(); // Read user input + while (true) + { + System.out.print(varPrompt); + varFileName = myObj.nextLine(); File thisFile = new File(varFileName); - if (thisFile.exists()) + Boolean isValidFile = fileProcessor.validFile(varFileName); + if ( thisFile.exists() && isValidFile ) { break; } + varPrompt = "\nEither the CSV file does not exist or the CSV file cannot be read!\nPlease enter the name of the CSV file to validate : "; } Boolean varUserBlockEmpty = false; @@ -34,22 +42,26 @@ public class userVerify valueMap.put("N", false); valueMap.put("n", false); - while (true) { - System.out.print("Invalidate the line on empty column values? (Y/n) : "); + while (true) + { + System.out.print("Invalidate a line if there are empty column values? (Y/n) : "); String varAnswer = myObj.nextLine(); + String varSanitized = varAnswer.toUpperCase().trim(); - if (varAnswer.toUpperCase().equals("Y") || varAnswer.toUpperCase().equals("N") || varAnswer == "") + if (varSanitized.equals("Y") || varSanitized.equals("N") || varSanitized.isEmpty()) { - varUserBlockEmpty = valueMap.get(varAnswer); + varUserBlockEmpty = valueMap.get(varSanitized); break; } } System.out.println(); - System.out.println("CSV filename to validate : " + varFileName); - System.out.println("CSV invalidate on empty : " + varUserBlockEmpty); + debugProcessor.writer(true, "CSV filename to validate : " + varFileName); + debugProcessor.writer(true, "CSV invalidate on empty : " + varUserBlockEmpty); + debugProcessor.writer(true, ""); + ArrayList thisCSV = readCSV(varFileName, true, varUserBlockEmpty); - System.out.println(); + debugProcessor.writer(true, ""); Iterator mapper1 = thisCSV.iterator(); int varIter = 0; @@ -61,13 +73,13 @@ public class userVerify while (it.hasNext()) { Map.Entry pair = it.next(); - System.out.println("record " + varIter + " : [" + pair.getKey() + "] => " + pair.getValue()); + debugProcessor.writer(true, "record " + varIter + " : [" + pair.getKey() + "] => " + pair.getValue()); } - System.out.println(); + debugProcessor.writer(true, ""); } boolean validfile = (!thisCSV.isEmpty()); - System.out.println("CSV file records : " + varIter); - System.out.println("CSV file is valid : " + validfile); + debugProcessor.writer(true, "CSV file records : " + varIter); + debugProcessor.writer(true, "CSV file is valid : " + validfile); System.out.println(); } @@ -77,7 +89,8 @@ public class userVerify int invalidNum = 0; ArrayList finalArray = new ArrayList(); File varFile = new File (thisFile); - if (!varFile.exists()) { + if (!varFile.exists()) + { System.out.println("CSV failure error : File not found. Please enter a valid filename!"); System.exit(0); } @@ -92,7 +105,8 @@ public class userVerify { String varHeader = new String(); varHeader = fileProcessor.readFirstLine(thisFile); - if (varHeader.length() == 0) { + if (varHeader.length() == 0) + { System.out.println("CSV failure error : Header line not found!"); return finalArray; } @@ -105,6 +119,7 @@ public class userVerify .setIgnoreSurroundingSpaces(true) .setIgnoreHeaderCase(true) .setTrim(true) + .setDuplicateHeaderMode(DuplicateHeaderMode.DISALLOW) .build(); Iterable records = csvFormat.parse(in); @@ -114,7 +129,8 @@ public class userVerify debugProcessor.writer(fromUser, "CSV header tokens : " + varHeader); debugProcessor.writer(fromUser, ""); - for (CSVRecord record : records) { + for (CSVRecord record : records) + { readNum++; lineNum = record.getParser().getCurrentLineNumber(); @@ -166,13 +182,12 @@ public class userVerify parsedCorrectly = true; } - if (readNum > 0) - { - debugProcessor.writer(fromUser,""); - } - debugProcessor.writer(fromUser, "CSV lines read : " + String.valueOf(readNum)); - debugProcessor.writer(fromUser, "CSV lines passed : " + String.valueOf(readNum - invalidNum)); - debugProcessor.writer(fromUser, "CSV lines failed : " + invalidNum); + debugProcessor.writer(fromUser,""); + debugProcessor.writer(fromUser, "CSV total lines : " + fileProcessor.numberOfLines(thisFile)); + debugProcessor.writer(fromUser, "CSV records read : " + String.valueOf(readNum)); + debugProcessor.writer(fromUser, "CSV records passed : " + String.valueOf(readNum - invalidNum)); + debugProcessor.writer(fromUser, "CSV records failed : " + invalidNum); + if (exceptionReason != null) { debugProcessor.writer(fromUser, "CSV failure error : " + exceptionReason); diff --git a/src/com/belkast/soap/webService.java b/src/com/belkast/soap/webService.java index ddb773f..60bc4a1 100644 --- a/src/com/belkast/soap/webService.java +++ b/src/com/belkast/soap/webService.java @@ -17,7 +17,11 @@ public class webService { static String varKey; static String varSalt = "1zcHJvdG9ubWFpbC9icmlkZ2UtdjMvdXNlcnMvYnJpZGdlLXZhdWx0LWtleQl0gx"; - public static void main(String... argv) throws Exception { + public static void main(String... argv) throws Exception + { + debugProcessor.writer(true, ""); + debugProcessor.writer(true, "SOAP Client (03.01.2025 build) - Belkast Consulting (c) 2025"); + debugProcessor.writer(true, ""); // @Parameter(names = "--props", // description = "Location of the Properties file")