Skip to content

Commit

Permalink
Change ASN 856 parsing error messages (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkolla447 authored Dec 6, 2023
1 parent c7fa1bc commit 694f2cd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 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 @@
<groupId>com.walmartlabs.x12</groupId>
<artifactId>gozer</artifactId>
<name>gozer</name>
<version>0.3.5-SNAPSHOT</version>
<version>0.3.6-SNAPSHOT</version>
<packaging>takari-jar</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ private void parseShipmentLoop(X12Loop unparsedLoop, AsnTransactionSet asnTx) {
}
} else {
asnTx.addX12ErrorDetailForLoop(
new X12ErrorDetail("HL", "03", "first HL is not a shipment it was " + unparsedLoop.getCode()));
new X12ErrorDetail("HL", "03", "Invalid Looping Structure",
"first HL is not a shipment it was " + unparsedLoop.getCode()));
}
}

Expand Down Expand Up @@ -247,7 +248,7 @@ private void parseOrderLoop(X12Loop unparsedLoop, Shipment shipment, AsnTransact

} else {
asnTx.addX12ErrorDetailForLoop(
new X12ErrorDetail("HL", "03", "Unexpected child loop", "expected Order HL but got " + unparsedLoop.getCode()));
new X12ErrorDetail("HL", "03", "Invalid Looping Structure", "expected Order HL but got " + unparsedLoop.getCode()));
}
}

Expand Down Expand Up @@ -680,7 +681,8 @@ protected void handleLooping(SegmentIterator segments, AsnTransactionSet asnTx)
} else {
// doesn't start w/ HL
asnTx.addX12ErrorDetailForLoop(
new X12ErrorDetail(currentSegment.getIdentifier(), null, "missing shipment loop"));
new X12ErrorDetail(currentSegment.getIdentifier(), null, "Invalid Looping Structure",
"missing shipment loop"));
// we should back it up
// and let the parser keep going
// with that segment
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/walmartlabs/x12/util/loop/X12LoopUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@

public final class X12LoopUtil {

private static final String MISSING_PARENT_ERROR = "HL segment is missing parent";
private static final String ALREADY_EXISTS_ERROR = "HL segment already exists";

private static final String INVALID_LOOPING_STRUCTURE_ERROR = "Invalid Looping Structure";

/**
* check the segment for the start of HL
* @param segment
Expand Down Expand Up @@ -170,14 +169,14 @@ private static X12ErrorDetail loopAlreadyExistsErrorDetail(X12Loop loop) {
sb.append("HL segment with id (")
.append(loop.getHierarchicalId())
.append(") already exists");
return new X12ErrorDetail(X12Loop.HIERARCHY_LOOP_ID, null, ALREADY_EXISTS_ERROR, sb.toString());
return new X12ErrorDetail(X12Loop.HIERARCHY_LOOP_ID, null, INVALID_LOOPING_STRUCTURE_ERROR, sb.toString());
}

private static X12ErrorDetail loopMissingParentErrorDetail(X12Loop loop) {
StringBuilder sb = new StringBuilder();
sb.append("HL segment with id (").append(loop.getHierarchicalId()).append(")");
sb.append(" is missing parent (").append(loop.getParentHierarchicalId()).append(")");
return new X12ErrorDetail(X12Loop.HIERARCHY_LOOP_ID, null, MISSING_PARENT_ERROR, sb.toString());
return new X12ErrorDetail(X12Loop.HIERARCHY_LOOP_ID, null, INVALID_LOOPING_STRUCTURE_ERROR, sb.toString());
}

private X12LoopUtil() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void test_Parsing_Asn856_badLoops() throws IOException {
X12ErrorDetail loopError = loopErrors.get(0);
assertEquals("HL", loopError.getSegmentId());
assertNull(loopError.getElementId());
assertEquals("HL segment is missing parent", loopError.getIssueText());
assertEquals("Invalid Looping Structure", loopError.getIssueText());
assertEquals("HL segment with id (2) is missing parent (99)", loopError.getInvalidValue());

// BSN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ public void test_doParse_NoHierarchicalLoops() {
List<X12ErrorDetail> loopErrors = asnTx.getLoopingErrors();
assertNotNull(loopErrors);
assertEquals(1, loopErrors.size());
assertEquals("missing shipment loop", loopErrors.get(0).getIssueText());
assertEquals("Invalid Looping Structure", loopErrors.get(0).getIssueText());
assertEquals("missing shipment loop", loopErrors.get(0).getInvalidValue());

// BSN
assertEquals("05755986", asnTx.getShipmentIdentification());
Expand All @@ -175,7 +176,8 @@ public void test_doParse_FirstLoop_NotShipment() {
// looping check
List<X12ErrorDetail> loopErrors = asnTx.getLoopingErrors();
assertEquals(1, loopErrors.size());
assertEquals("first HL is not a shipment it was X", loopErrors.get(0).getIssueText());
assertEquals("Invalid Looping Structure", loopErrors.get(0).getIssueText());
assertEquals("first HL is not a shipment it was X", loopErrors.get(0).getInvalidValue());

// BSN
assertEquals("05755986", asnTx.getShipmentIdentification());
Expand All @@ -193,7 +195,7 @@ public void test_doParseSecondLoop_NotOrder() {
// looping check
List<X12ErrorDetail> loopErrors = asnTx.getLoopingErrors();
assertEquals(1, loopErrors.size());
assertEquals("Unexpected child loop", loopErrors.get(0).getIssueText());
assertEquals("Invalid Looping Structure", loopErrors.get(0).getIssueText());
assertEquals("expected Order HL but got X", loopErrors.get(0).getInvalidValue());

// BSN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,10 @@ public void test_Parsing_AdvanceShipNoticeDocument_bad_loop() {
assertNotNull(loopErrors);
assertEquals(2, loopErrors.size());
// loop error 1
assertEquals("HL segment already exists", loopErrors.get(0).getIssueText());
assertEquals("Invalid Looping Structure", loopErrors.get(0).getIssueText());
assertEquals("HL segment with id (1) already exists", loopErrors.get(0).getInvalidValue());
// loop error 2
assertEquals("HL segment is missing parent", loopErrors.get(1).getIssueText());
assertEquals("Invalid Looping Structure", loopErrors.get(1).getIssueText());
assertEquals("HL segment with id (3) is missing parent (2)", loopErrors.get(1).getInvalidValue());

// Shipment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void test_findHierarchicalLoops_one_loop_missing_parent() {
X12ErrorDetail loopError = loopErrors.get(0);
assertEquals("HL", loopError.getSegmentId());
assertNull(loopError.getElementId());
assertEquals("HL segment is missing parent", loopError.getIssueText());
assertEquals("Invalid Looping Structure", loopError.getIssueText());
assertEquals("HL segment with id (4) is missing parent (3)", loopError.getInvalidValue());
}

Expand Down Expand Up @@ -347,7 +347,7 @@ public void test_findHierarchicalLoops_one_loop_repeated_id() {
X12ErrorDetail loopError = loopErrors.get(0);
assertEquals("HL", loopError.getSegmentId());
assertNull(loopError.getElementId());
assertEquals("HL segment already exists", loopError.getIssueText());
assertEquals("Invalid Looping Structure", loopError.getIssueText());
assertEquals("HL segment with id (2) already exists", loopError.getInvalidValue());
}

Expand Down

0 comments on commit 694f2cd

Please sign in to comment.