public static X12ParserException handleUnexpectedSegment(String expectedSegmentId, String actualSegmentId)
builds an {@link X12ParserException} w/ consistent message when an unexpected segment is encountered
the caller of the method must throw this exception if that is what is desired
expectedSegmentId —actualSegmentId —public static boolean isValidEnvelope(List<X12Segment> segmentList, String headerIdentifier, String trailerIdentifier)given a set of segment lines it will examine the first and last segments and evaluate whether they match the header and trailer values passed into the method
public static boolean verifyTransactionSetType(List<X12Segment> segmentList, String transactionType)The segment list should wrapped in valid transaction envelope (ST/SE) with the transaction type (ST01) matching the provided type
segmentList —transactionType —public static Integer parseVersion(String versionValue)return the numeric part of a version number
versionValue —public static List<X12Loop> findHierarchicalLoops(List<X12Segment> segmentList)generic method that takes a given a set of segment lines and it will break them up into separate hierarchical loops using the HL as the break since there is no terminating segment for the loop - only the start of the next loop
this method will only work when the first segment is an HL and when this set of segments has already been extracted from the ST/SE and the parts of the header and trailer of the transaction set
Returns: list of {@link X12Loop} or empty list if there is a problem
Exceptions: X12ParserException — if the first segment is not an HL or if the parent
that an HL loop has is not found
private static List<X12Loop> processLoops(List<X12Segment> segmentList)handle the loops and build nested structure as defined by the segment lines
segmentList —Returns: list of loops
an — {@link X12ParserException} if id is reused an HL segmentprivate static boolean isHierarchalLoopStart(X12Segment segment)check the segment for the start of HL
segment —private static void handleParentLoop(X12Loop loop, Map<String, X12Loop> loopMap)given a loop, look for the parent loop
loop —loopMap — <p>X12ParserException — if the parent loop is missingpublic interface X12TransactionSetImplementations should store the common ST/SE elements as well as the attributes specific to the particular transaction type.
String getTransactionSetIdentifierCode()The ST01 segment element contains the functional group code, which identifies the X12 transaction type
common X12 transaction types associated with retail are 856 (ASN), 850 (PO), and 812 (invoice).
String getHeaderControlNumber()The ST02 segment element contains the control number. This should match the control number on the corresponding transaction trailer segment.
Integer getExpectedNumberOfSegments()The SE01 segment element contains the number of segments that are in this transaction.
String getTrailerControlNumber()The SE02 segment element contains the control number. This should match the control number on the corresponding transaction header segment.
Defines the X12 Segment Class
Each line in an X12 document is called a segment Each segment contains one or more elements The first element identifies the type of segment
This class will parse a segment into the individual elements
public X12Segment(String segment)create the {@link X12Segment} using the default delimiter
segment —public X12Segment(String segment, Character dataElementDelimiter)create the {@link X12Segment} using the delimiter provided
segment —PatternSyntaxException — if the delimiter results in invalid regular expression@Override public String toString()returns the original segment value
public String getIdentifier()extracts the first data element in a segment which is the segment identifier otherwise return an empty String
public String getElement(int index)retrieve the element at a particular index in the segment
private List<String> splitSegmentIntoDataElements(String segment, Character dataElementDelimiter)parses the segment into a list of data elements each date element is separated by an asterisk (*)