Skip to content

Commit

Permalink
allowed for out of order column headers
Browse files Browse the repository at this point in the history
  • Loading branch information
cameroncaci committed Dec 19, 2023
1 parent a1be487 commit a3834dd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>com.milmove.trdmlambda</groupId>
<artifactId>trdm-lambda</artifactId>
<version>1.0.3.0</version>
<version>1.0.3.1</version>
<name>trdm java spring interface</name>
<description>Project for deploying a Java TRDM interfacer for TGET data.</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,19 @@ public List<LineOfAccounting> parse(byte[] fileContent, XMLGregorianCalendar trd
logger.info("skipping the first line and then gathering headers");
String[] columnHeaders = scanner.nextLine().split("\\|"); // Skip first line and gather headers immediately
logger.info("parsed these column headers from LOA attachment {}", Arrays.toString(columnHeaders));
// TODO: Possibly allow for unexpected column names and proceed with the columns
// we are familiar with. This will be a must for LOA.
if (!Arrays.equals(expectedColumnNames, columnHeaders)) {

// Sort both the expectedColumnNames and columnHeaders before comparing
String[] sortedExpectedColumnNames = Arrays.copyOf(expectedColumnNames, expectedColumnNames.length);
String[] sortedColumnHeaders = Arrays.copyOf(columnHeaders, columnHeaders.length);
Arrays.sort(sortedExpectedColumnNames);
Arrays.sort(sortedColumnHeaders);

if (!Arrays.equals(sortedExpectedColumnNames, sortedColumnHeaders)) {
String message = String.format("Column headers do not match expected format. Received %s and expected %s",
Arrays.toString(columnHeaders), Arrays.toString(expectedColumnNames));
throw new RuntimeException(message);
}

// Map their order for when processing the LOA values properly
for (int i = 0; i < columnHeaders.length; i++) {
columnNamesAndLocations.put(columnHeaders[i], i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ public List<TransportationAccountingCode> parse(byte[] fileContent, XMLGregorian
logger.info("skipping the first line and then gathering headers");
String[] columnHeaders = scanner.nextLine().split("\\|"); // Skip first line and gather headers immediately

// TODO: Possibly allow for unexpected column names and proceed with the columns
// we are familiar with. This will be a must for LOA.
if (!Arrays.equals(expectedColumnNames, columnHeaders)) {
// Sort both the expectedColumnNames and columnHeaders before comparing
String[] sortedExpectedColumnNames = Arrays.copyOf(expectedColumnNames, expectedColumnNames.length);
String[] sortedColumnHeaders = Arrays.copyOf(columnHeaders, columnHeaders.length);
Arrays.sort(sortedExpectedColumnNames);
Arrays.sort(sortedColumnHeaders);

if (!Arrays.equals(sortedExpectedColumnNames, sortedColumnHeaders)) {
String message = String.format("Column headers do not match expected format. Received %s and expected %s",
Arrays.toString(columnHeaders), Arrays.toString(expectedColumnNames));
throw new RuntimeException(message);
Expand Down

0 comments on commit a3834dd

Please sign in to comment.