Added functionality for missing values

This commit is contained in:
Keith Armstrong 2025-01-02 13:47:47 -05:00
parent a3d511dc12
commit eb333754a1
3 changed files with 74 additions and 32 deletions

View File

@ -1,8 +1,9 @@
SHIM_URL = https://test.mycompany.com:8443/IDMProv/role/service
PASSWORD = PT9TKHwFgJCxATJtAAMtMwtIF0UjFal6fo5riBN+ExY=
USERNAME = cn=keitha,ou=active,ou=users,o=belkast
XML_FILE = USER_TO_ROLE.xml
INPUT_FILE = msalah.csv
PASSWORD = PT9TKHwFgJCxATJtAAMtMwtIF0UjFal6fo5riBN+ExY=
SSL = true
JAVA_KS_LOCATION = ldap.keystore
JAVA_KS_PASSWORD = changeit
XML_FILE = USER_TO_ROLE.xml
CSV_FILE = msalah.csv
CSV_ALLOW_EMPTY_COLUMN_VALUES = true

View File

@ -26,9 +26,30 @@ public class userVerify
}
}
Boolean varUserBlockEmpty = false;
HashMap<String, Boolean> valueMap = new HashMap();
valueMap.put("", true);
valueMap.put("Y", true);
valueMap.put("y", true);
valueMap.put("N", false);
valueMap.put("n", false);
while (true) {
System.out.print("Block on empty column values (Y/n) : ");
String varAnswer = myObj.nextLine(); // Read user input
if (varAnswer.toUpperCase().equals("Y") || varAnswer.toUpperCase().equals("N") || varAnswer == "")
{
varUserBlockEmpty = valueMap.get(varAnswer);
break;
}
}
System.out.println();
System.out.println("CSV input file : " + varFileName);
ArrayList thisCSV = readCSV(varFileName, true);
System.out.println("CSV input file : " + varFileName);
System.out.println("CSV block on empty : " + varUserBlockEmpty);
ArrayList thisCSV = readCSV(varFileName, true, varUserBlockEmpty);
System.out.println();
Iterator<Map> mapper1 = thisCSV.iterator();
@ -41,8 +62,8 @@ public class userVerify
while (it.hasNext())
{
Map.Entry<Integer, Integer> pair = it.next();
System.out.println("record " + varIter + " key : " + pair.getKey());
System.out.println("record " + varIter + " val : " + pair.getValue());
System.out.println("record " + varIter + " token : " + pair.getKey());
System.out.println("record " + varIter + " value : " + pair.getValue());
}
System.out.println();
}
@ -52,7 +73,7 @@ public class userVerify
System.out.println();
}
public static ArrayList readCSV (String thisFile, boolean fromUser)
public static ArrayList readCSV (String thisFile, boolean fromUser, boolean blockEmpty)
{
int readNum = 0;
int invalidNum = 0;
@ -78,37 +99,53 @@ public class userVerify
return finalArray;
}
CSVFormat csvFormat = CSVFormat.RFC4180.builder()
.setHeader(varHeader.split(","))
.setSkipHeaderRecord(true)
CSVFormat csvFormat = CSVFormat.EXCEL.builder()
.setHeader()
.setSkipHeaderRecord(false)
.setAllowMissingColumnNames(false)
.setIgnoreEmptyLines(true)
.setIgnoreSurroundingSpaces(true)
.setIgnoreHeaderCase(true)
.setTrim(true)
.build();
int headerLen = csvFormat.getHeader().length;
Iterable<CSVRecord> records = csvFormat.parse(in);
debugProcessor.writer(fromUser, "CSV token count : " + headerLen);
debugProcessor.writer(fromUser, "CSV token list : " + varHeader);
debugProcessor.writer(fromUser, "CSV header tokens : " + varHeader);
debugProcessor.writer(fromUser, "");
for (CSVRecord record : records) {
readNum++;
lineNum = record.getParser().getCurrentLineNumber();
boolean isValid = record.isConsistent();
Boolean validValues = true;
if (isValid)
{
Map thisMap = record.toMap();
Iterator<Map.Entry<Integer, Integer>> it = thisMap.entrySet().iterator();
while (it.hasNext())
{
Map.Entry<Integer, Integer> pair = it.next();
String thisVal = String.valueOf(pair.getValue());
if (blockEmpty && (pair.getValue() == null || thisVal.isEmpty()))
{
validValues = false;
debugProcessor.writer(fromUser, "!! line " + lineNum + " [failed] : the " + pair.getKey() + " token value is empty");
}
}
}
if (isValid && validValues)
{
debugProcessor.writer(fromUser, "## line " + lineNum + " [passed]");
finalArray.add(record.toMap());
debugProcessor.writer(fromUser, "## " + lineNum + " [passed]");
}
else
{
invalidNum++;
String thisLine = Files.readAllLines(Paths.get(thisFile)).get(Math.toIntExact(lineNum - 1));
debugProcessor.writer(fromUser, "!! " + lineNum + " [failed] : " + thisLine);
debugProcessor.writer(fromUser, "!! " + lineNum + " [failed] : " + record.toMap().toString());
debugProcessor.writer(fromUser, "!! line " + lineNum + " [failed] : " + thisLine);
debugProcessor.writer(fromUser, "!! line " + lineNum + " [failed] : " + record.toMap().toString());
}
}
}
@ -125,9 +162,9 @@ public class userVerify
{
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, "CSV lines read : " + String.valueOf(readNum));
debugProcessor.writer(fromUser, "CSV lines passed : " + String.valueOf(readNum - invalidNum));
debugProcessor.writer(fromUser, "CSV lines failed : " + invalidNum);
if (exceptionReason != null)
{
debugProcessor.writer(fromUser, "CSV failure error : " + exceptionReason);

View File

@ -89,23 +89,27 @@ public class webService {
System.out.println();
String varURL = propertyProcessor.getProperty(thisProps, "SHIM_URL");
String varRoleFile = propertyProcessor.getProperty(thisProps, "INPUT_FILE");
String varInputFile = propertyProcessor.getProperty(thisProps, "XML_FILE");
String varUsername = propertyProcessor.getProperty(thisProps, "USERNAME");
String varPasswordTemp = propertyProcessor.getProperty(thisProps, "PASSWORD");
String varUseSSL = propertyProcessor.getProperty(thisProps, "SSL");
String varKeystore_LOC = propertyProcessor.getProperty(thisProps, "JAVA_KS_LOCATION");
String varKeystore_PW = propertyProcessor.getProperty(thisProps, "JAVA_KS_PASSWORD");
String varInputFile = propertyProcessor.getProperty(thisProps, "XML_FILE");
String varRoleFile = propertyProcessor.getProperty(thisProps, "CSV_FILE");
String varPropEmptyColumns = propertyProcessor.getProperty(thisProps, "CSV_ALLOW_EMPTY_COLUMN_VALUES");
Boolean varEmptyColumns = Boolean.valueOf(varPropEmptyColumns);
debugProcessor.writer(varDebug, thisProps + " => SOAP URL : " + varURL);
debugProcessor.writer(varDebug, thisProps + " => Username : " + varUsername);
debugProcessor.writer(varDebug, thisProps + " => Use SSL : " + varUseSSL);
debugProcessor.writer(varDebug, thisProps + " => JAVA Keystore : " + varKeystore_LOC);
debugProcessor.writer(varDebug, thisProps + " => JAVA Keystore password : " + varKeystore_PW);
debugProcessor.writer(varDebug, thisProps + " => Input File : " + varRoleFile);
debugProcessor.writer(varDebug, thisProps + " => XML File : " + varInputFile);
debugProcessor.writer(varDebug, thisProps + " => JAVA keystore : " + varKeystore_LOC);
debugProcessor.writer(varDebug, thisProps + " => JAVA keystore password : " + varKeystore_PW);
debugProcessor.writer(varDebug, thisProps + " => XML file : " + varInputFile);
debugProcessor.writer(varDebug, thisProps + " => CSV file : " + varRoleFile);
debugProcessor.writer(varDebug, thisProps + " => CSV allow empty : " + varEmptyColumns);
File checkInput = new File (varInputFile);
if (!checkInput.exists())
@ -129,15 +133,15 @@ public class webService {
System.exit(0);
}
ArrayList thisCSV = userVerify.readCSV(varRoleFile, false);
ArrayList thisCSV = userVerify.readCSV(varRoleFile, false, !varEmptyColumns);
boolean validfile = (thisCSV.size() > 0);
debugProcessor.writer(true, varRoleFile + " : CSV file is valid : " + validfile);
debugProcessor.writer(true, varRoleFile + " : records to process : " + thisCSV.size());
debugProcessor.writer(true, varRoleFile + " => CSV file is valid : " + validfile);
debugProcessor.writer(true, varRoleFile + " => records to process : " + thisCSV.size());
if (!validfile)
{
debugProcessor.writer(true, varRoleFile + " : verification failed. please verify the file with com.belkast.soap.userVerify!");
debugProcessor.writer(true, varRoleFile + " => verification failed : please verify the file with com.belkast.soap.userVerify!");
}
int varCount = 0;
Iterator<Map> mapper1 = thisCSV.iterator();