Skip to content

Commit 035cf18

Browse files
authored
Add N1 support to Order loop & N1 as list on Pack for ASN 856 (#138)
1 parent b89e74d commit 035cf18

File tree

4 files changed

+94
-23
lines changed

4 files changed

+94
-23
lines changed

src/main/java/com/walmartlabs/x12/standard/txset/asn856/DefaultAsn856TransactionSetParser.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ private void parseShipmentLoop(X12Loop unparsedLoop, AsnTransactionSet asnTx) {
203203

204204
//
205205
// handle the children loops
206+
// expecting all Shipment children
207+
// to be an Order loop
206208
//
207209
List<X12Loop> shipmentChildLoops = unparsedLoop.getChildLoops();
208210
if (CollectionUtils.isNotEmpty(shipmentChildLoops)) {
@@ -245,7 +247,7 @@ private void parseOrderLoop(X12Loop unparsedLoop, Shipment shipment, AsnTransact
245247

246248
} else {
247249
asnTx.addX12ErrorDetailForLoop(
248-
new X12ErrorDetail("HL", "03", "expected Order HL but got " + unparsedLoop.getCode()));
250+
new X12ErrorDetail("HL", "03", "Unexpected child loop", "expected Order HL but got " + unparsedLoop.getCode()));
249251
}
250252
}
251253

@@ -455,6 +457,10 @@ private void doOrderSegments(X12Segment segment, SegmentIterator segmentIterator
455457
case TD1CarrierDetail.IDENTIFIER:
456458
order.addTD1CarrierDetail(TD1CarrierDetailParser.parse(segment));
457459
break;
460+
case N1PartyIdentification.IDENTIFIER:
461+
N1PartyIdentification n1 = N1PartyIdentificationParser.handleN1Loop(segment, segmentIterator);
462+
order.addN1PartyIdentification(n1);
463+
break;
458464
default:
459465
order.addUnparsedSegment(segment);
460466
break;
@@ -502,8 +508,8 @@ private void doPackSegments(X12Segment segment, SegmentIterator segmentIterator,
502508
break;
503509
case N1PartyIdentification.IDENTIFIER:
504510
N1PartyIdentification n1 = N1PartyIdentificationParser.handleN1Loop(segment, segmentIterator);
505-
pack.setN1PartyIdentification(n1);
506-
break;
511+
pack.addN1PartyIdentification(n1);
512+
break;
507513
case TD1CarrierDetail.IDENTIFIER:
508514
pack.addTD1CarrierDetail(TD1CarrierDetailParser.parse(segment));
509515
break;
@@ -654,7 +660,7 @@ protected void handleLooping(SegmentIterator segments, AsnTransactionSet asnTx)
654660
// assigning the parents and children accordingly
655661
X12LoopHolder loopHolder = X12LoopUtil.organizeHierarchicalLoops(loopSegments);
656662

657-
// add loop errors to tx (if any)
663+
// add loop errors to transaction set (if any)
658664
List<X12ErrorDetail> loopErrors = loopHolder.getLoopErrors();
659665
asnTx.addX12ErrorDetailForLoop(loopErrors);
660666

@@ -705,7 +711,7 @@ private int findIndexForSegmentAfterHierarchicalLoops(SegmentIterator segments)
705711
}
706712

707713
/**
708-
* currently enforcing only 1 top level Shipment HL in the transaction set
714+
* currently allowing only 1 top level Shipment HL in the transaction set
709715
*
710716
* @param loops
711717
* @param asnTx

src/main/java/com/walmartlabs/x12/standard/txset/asn856/loop/Order.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.walmartlabs.x12.standard.txset.asn856.loop;
1818

19+
import com.walmartlabs.x12.common.segment.N1PartyIdentification;
1920
import com.walmartlabs.x12.common.segment.REFReferenceInformation;
2021
import com.walmartlabs.x12.common.segment.TD1CarrierDetail;
2122
import com.walmartlabs.x12.standard.X12Loop;
@@ -48,6 +49,12 @@ public class Order extends X12ParsedLoop {
4849
* REF
4950
*/
5051
private List<REFReferenceInformation> refList;
52+
53+
/*
54+
* N1: Party Identifiers
55+
*/
56+
private List<N1PartyIdentification> n1PartyIdentifications;
57+
5158

5259
/**
5360
* returns true if the loop passed in is an Order loop
@@ -79,6 +86,17 @@ public void addReferenceInformation(REFReferenceInformation ref) {
7986
}
8087
refList.add(ref);
8188
}
89+
90+
/**
91+
* helper method to add N1 to list
92+
* @param n1
93+
*/
94+
public void addN1PartyIdentification(N1PartyIdentification n1) {
95+
if (CollectionUtils.isEmpty(n1PartyIdentifications)) {
96+
n1PartyIdentifications = new ArrayList<>();
97+
}
98+
n1PartyIdentifications.add(n1);
99+
}
82100

83101
public PRFPurchaseOrderReference getPrf() {
84102
return prf;
@@ -103,5 +121,13 @@ public List<TD1CarrierDetail> getTd1List() {
103121
public void setTd1List(List<TD1CarrierDetail> td1List) {
104122
this.td1List = td1List;
105123
}
124+
125+
public List<N1PartyIdentification> getN1PartyIdentifications() {
126+
return n1PartyIdentifications;
127+
}
128+
129+
public void setN1PartyIdentifications(List<N1PartyIdentification> n1PartyIdentifications) {
130+
this.n1PartyIdentifications = n1PartyIdentifications;
131+
}
106132

107133
}

src/main/java/com/walmartlabs/x12/standard/txset/asn856/loop/Pack.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,32 @@ public class Pack extends X12ParsedLoop {
4242
* MAN: Marking
4343
*/
4444
private List<MANMarkNumber> manList;
45+
4546
/*
4647
* N1: Party Identifiers
4748
*/
48-
private N1PartyIdentification n1PartyIdentification;
49+
private List<N1PartyIdentification> n1PartyIdentifications;
50+
4951
/*
5052
* PO4: Item Physical Details
5153
*/
5254
private PO4ItemPhysicalDetail po4;
55+
5356
/*
5457
* PID: Product Identification
5558
*/
5659
private List<PIDProductIdentification> productIdentifications;
60+
5761
/*
5862
* TD1: Carrier Details
5963
*/
6064
private List<TD1CarrierDetail> td1List;
65+
6166
/*
6267
* SN1: Item Detail
6368
*/
6469
private SN1ItemDetail sn1;
70+
6571
/*
6672
* LIN: Item Identification
6773
*/
@@ -121,7 +127,17 @@ public void addMANMarkNumber(MANMarkNumber man) {
121127
}
122128
manList.add(man);
123129
}
124-
130+
131+
/**
132+
* helper method to add N1 to list
133+
* @param n1
134+
*/
135+
public void addN1PartyIdentification(N1PartyIdentification n1) {
136+
if (CollectionUtils.isEmpty(n1PartyIdentifications)) {
137+
n1PartyIdentifications = new ArrayList<>();
138+
}
139+
n1PartyIdentifications.add(n1);
140+
}
125141

126142
public PO4ItemPhysicalDetail getPo4() {
127143
return po4;
@@ -155,14 +171,6 @@ public void setItemIdentifications(List<LINItemIdentification> itemIdentificatio
155171
this.itemIdentifications = itemIdentifications;
156172
}
157173

158-
public N1PartyIdentification getN1PartyIdentification() {
159-
return n1PartyIdentification;
160-
}
161-
162-
public void setN1PartyIdentification(N1PartyIdentification n1PartyIdentification) {
163-
this.n1PartyIdentification = n1PartyIdentification;
164-
}
165-
166174
public List<MANMarkNumber> getManList() {
167175
return manList;
168176
}
@@ -178,5 +186,13 @@ public List<TD1CarrierDetail> getTd1List() {
178186
public void setTd1List(List<TD1CarrierDetail> td1List) {
179187
this.td1List = td1List;
180188
}
189+
190+
public List<N1PartyIdentification> getN1PartyIdentifications() {
191+
return n1PartyIdentifications;
192+
}
193+
194+
public void setN1PartyIdentifications(List<N1PartyIdentification> n1PartyIdentifications) {
195+
this.n1PartyIdentifications = n1PartyIdentifications;
196+
}
181197

182198
}

src/test/java/com/walmartlabs/x12/standard/txset/asn856/DefaultAsn856TransactionSetParserTest.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.walmartlabs.x12.X12TransactionSet;
2121
import com.walmartlabs.x12.common.segment.DTMDateTimeReference;
2222
import com.walmartlabs.x12.common.segment.N1PartyIdentification;
23+
import com.walmartlabs.x12.common.segment.REFReferenceInformation;
2324
import com.walmartlabs.x12.exceptions.X12ErrorDetail;
2425
import com.walmartlabs.x12.exceptions.X12ParserException;
2526
import com.walmartlabs.x12.standard.X12Group;
@@ -29,6 +30,7 @@
2930
import com.walmartlabs.x12.standard.txset.asn856.loop.Shipment;
3031
import com.walmartlabs.x12.standard.txset.asn856.loop.Tare;
3132
import com.walmartlabs.x12.standard.txset.asn856.segment.MANMarkNumber;
33+
import com.walmartlabs.x12.standard.txset.asn856.segment.PRFPurchaseOrderReference;
3234
import org.junit.Before;
3335
import org.junit.Test;
3436

@@ -191,7 +193,8 @@ public void test_doParseSecondLoop_NotOrder() {
191193
// looping check
192194
List<X12ErrorDetail> loopErrors = asnTx.getLoopingErrors();
193195
assertEquals(1, loopErrors.size());
194-
assertEquals("expected Order HL but got X", loopErrors.get(0).getIssueText());
196+
assertEquals("Unexpected child loop", loopErrors.get(0).getIssueText());
197+
assertEquals("expected Order HL but got X", loopErrors.get(0).getInvalidValue());
195198

196199
// BSN
197200
assertEquals("05755986", asnTx.getShipmentIdentification());
@@ -293,8 +296,25 @@ public void test_doParse() {
293296
assertNotNull(orderLoop);
294297
assertTrue(orderLoop instanceof Order);
295298
assertEquals("O", orderLoop.getCode());
296-
299+
300+
// order segments
297301
Order order = ((Order)orderLoop);
302+
PRFPurchaseOrderReference prf = order.getPrf();
303+
assertNotNull(prf);
304+
assertEquals("471", prf.getPurchaseOrderNumber());
305+
assertEquals("20220130", prf.getDate());
306+
307+
List<REFReferenceInformation> refList = order.getRefList();
308+
assertNotNull(refList);
309+
assertEquals(2, refList.size());
310+
assertEquals("IA", refList.get(0).getReferenceIdentificationQualifier());
311+
assertEquals("IV", refList.get(1).getReferenceIdentificationQualifier());
312+
313+
List<N1PartyIdentification> n1List = order.getN1PartyIdentifications();
314+
assertNotNull(n1List);
315+
assertEquals(1, n1List.size());
316+
assertEquals("BY", n1List.get(0).getEntityIdentifierCode());
317+
298318
List<X12Loop> tares = order.getParsedChildrenLoops();
299319
assertNotNull(tares);
300320
assertEquals(1, tares.size());
@@ -314,6 +334,7 @@ public void test_doParse() {
314334
assertTrue(tareLoop instanceof Tare);
315335
assertEquals("T", tareLoop.getCode());
316336

337+
// tare segments
317338
Tare tare = (Tare) tareLoop;
318339
List<MANMarkNumber> manList = tare.getManList();
319340
MANMarkNumber man = manList.get(0);
@@ -332,7 +353,7 @@ public void test_doParse() {
332353
List<X12Loop> tareChildLoops = tare.getParsedChildrenLoops();
333354
assertNotNull(tareChildLoops);
334355
assertEquals(1, tareChildLoops.size());
335-
356+
336357
List<X12Loop> packs = tare.getParsedChildrenLoops();
337358
assertNotNull(packs);
338359
assertEquals(1, packs.size());
@@ -351,11 +372,11 @@ public void test_doParse() {
351372
assertEquals("UC", man.getQualifier());
352373
assertEquals("10081131916933", man.getNumber());
353374

354-
// List<N1PartyIdentification> n1List = pack.getN1PartyIdentifications();
355-
// assertNotNull(n1List);
356-
// assertEquals(2, n1List.size());
357-
// assertEquals("MF", n1List.get(0).getEntityIdentifierCode());
358-
// assertEquals("VN", n1List.get(1).getEntityIdentifierCode());
375+
n1List = pack.getN1PartyIdentifications();
376+
assertNotNull(n1List);
377+
assertEquals(2, n1List.size());
378+
assertEquals("MF", n1List.get(0).getEntityIdentifierCode());
379+
assertEquals("VN", n1List.get(1).getEntityIdentifierCode());
359380

360381
unparsedSegments = pack.getUnparsedSegments();
361382
assertNull(unparsedSegments);
@@ -473,6 +494,8 @@ private List<X12Segment> getTransactionSetSegments(String firstLoopCode, String
473494
// Pack
474495
txSegments.add(new X12Segment("HL*5*4*P"));
475496
txSegments.add(new X12Segment("MAN*UC*10081131916933"));
497+
txSegments.add(new X12Segment("N1*MF*Manufacturer*92*000062535"));
498+
txSegments.add(new X12Segment("N1*VN*Vendor*ZZ*0263"));
476499

477500
// Item
478501
txSegments.add(new X12Segment("HL*6*5*I"));

0 commit comments

Comments
 (0)