xlate / staedi

StAEDI - Streaming API for EDI: Java library featuring a reader/parser, writer/generator, and validation
Apache License 2.0
119 stars 33 forks source link

Improper parse of simple 837 #475

Open cpotter1 opened 4 weeks ago

cpotter1 commented 4 weeks ago

Consider this simple x12:

ISA*01*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*`*00402*000003438*0*P*>
  GS*HC*99999999999*888888888888*20111219*1340*1377*X*005010X222
    ST*837*0001*005010X222
    SE*39*0001
  GE*1*1377
IEA*1*000003438

The stream of events I see is as follows:

event: START_INTERCHANGE at offset 106
event: START_SEGMENT in segment ISA at position 1
event: END_SEGMENT after segment ISA at position 1
event: START_GROUP in segment GS at position 2
event: START_SEGMENT in segment GS at position 2
event: END_SEGMENT after segment GS at position 2
event: START_TRANSACTION in segment ST at position 3
event: START_SEGMENT in segment ST at position 3
event: END_SEGMENT after segment ST at position 3
event: START_SEGMENT in segment SE at position 4
event: ELEMENT_DATA_ERROR in segment SE at position 4, element 1
event: ELEMENT_DATA_ERROR in segment SE at position 4, element 1
event: END_SEGMENT after segment SE at position 4
event: END_TRANSACTION in segment GE at position 5
event: START_SEGMENT in segment GE at position 5
event: END_SEGMENT after segment GE at position 5
event: END_GROUP in segment IEA at position 6
event: START_SEGMENT in segment IEA at position 6
event: END_SEGMENT after segment IEA at position 6
event: END_INTERCHANGE after segment IEA at position 6

There are a few concerns I have with this:

  1. I don't see a START_TRANSACTION/.../END_TRANSACTION for SE
  2. (Perhaps the above is related to ELEMENT_DATA_ERROR - but this doesn't seem like it should be a problem.
  3. I don't see a START_GROUP/...END_GROUP for GE

Please have a look.

Thanks!

MikeEdgar commented 3 weeks ago

Hi @cpotter1 , the "END" events are currently signaled at the start of the following segment but the "START" events do provide the starting segment name in the position information.

E.g.

I understand the confusion around the end event, but are you expecting something else for the start events?

cpotter1 commented 3 weeks ago

There are two transactions here - ST and SE. Where are the SE transaction events? That is my question #1.

MikeEdgar commented 3 weeks ago

ST is the start of a transaction, SE is the end. One transaction per ST/SE pair.

cpotter1 commented 3 weeks ago

Ok, so you see it part of the txn itself. Ok.

What about point 2 re: ELEMENT_DATA_ERROR ?

MikeEdgar commented 3 weeks ago

What about point 2 re: ELEMENT_DATA_ERROR ?

For this particular example, I suspect the reason for one of the errors was CONTROL_COUNT_DOES_NOT_MATCH_ACTUAL_COUNT. The count in SE01 it validated to be the number of segments in the transaction (including ST and SE), which in this case is 2. You can fetch the error type via EDIStreamReader#getErrorType() when the ELEMENT_DATA_ERROR occurs.