diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7b4ad069..ff1e122d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,6 +2,10 @@ name: StAEDI Build on: push: + branches: + - master + tags: + - '**' paths-ignore: - '.gitignore' - '.travis.yml*' diff --git a/src/main/java/io/xlate/edi/internal/schema/SchemaReader.java b/src/main/java/io/xlate/edi/internal/schema/SchemaReader.java index 53a36ddf..7f9cdfd4 100644 --- a/src/main/java/io/xlate/edi/internal/schema/SchemaReader.java +++ b/src/main/java/io/xlate/edi/internal/schema/SchemaReader.java @@ -7,6 +7,10 @@ interface SchemaReader { - Map readTypes() throws EDISchemaException; + default Map readTypes() throws EDISchemaException { + return readTypes(true); + } + + Map readTypes(boolean setReferences) throws EDISchemaException; } diff --git a/src/main/java/io/xlate/edi/internal/schema/SchemaReaderBase.java b/src/main/java/io/xlate/edi/internal/schema/SchemaReaderBase.java index bd972ac5..26e041a7 100644 --- a/src/main/java/io/xlate/edi/internal/schema/SchemaReaderBase.java +++ b/src/main/java/io/xlate/edi/internal/schema/SchemaReaderBase.java @@ -69,6 +69,7 @@ abstract class SchemaReaderBase implements SchemaReader { final QName qnInterchange; final QName qnGroup; final QName qnTransaction; + final QName qnImplementation; final QName qnLoop; final QName qnSegment; final QName qnComposite; @@ -100,6 +101,7 @@ public SchemaReaderBase(String xmlns, XMLStreamReader reader, Map readTypes() throws EDISchemaException { + public Map readTypes(boolean setReferences) throws EDISchemaException { Map types = new HashMap<>(100); types.put(StaEDISchema.ANY_ELEMENT_ID, ANY_ELEMENT); types.put(StaEDISchema.ANY_COMPOSITE_ID, ANY_COMPOSITE); - try { - reader.nextTag(); - QName element = reader.getName(); - - if (qnInclude.equals(element)) { - readInclude(reader, types); - readImplementation(reader, types); - } else if (qnInterchange.equals(element)) { - readInterchange(reader, types); - } else if (qnTransaction.equals(element)) { - readTransaction(reader, types); - readImplementation(reader, types); - } else { - throw unexpectedElement(element, reader); - } + nextTag(reader, "advancing to first schema element"); + QName element = reader.getName(); - readTypeDefinitions(reader, types); - setReferences(types); + while (qnInclude.equals(element)) { + readInclude(reader, types); + element = reader.getName(); + } + + if (qnInterchange.equals(element)) { + readInterchange(reader, types); + } else if (qnTransaction.equals(element)) { + readTransaction(reader, types); + readImplementation(reader, types); + } else if (qnImplementation.equals(element)) { + readImplementation(reader, types); + } else if (!typeDefinitions.containsKey(reader.getName())) { + throw unexpectedElement(element, reader); + } + + readTypeDefinitions(reader, types); + + try { reader.next(); - requireEvent(XMLStreamConstants.END_DOCUMENT, reader); } catch (XMLStreamException xse) { - throw schemaException("XMLStreamException reading schema", reader, xse); + throw schemaException("XMLStreamException reading end of document", reader, xse); + } + + requireEvent(XMLStreamConstants.END_DOCUMENT, reader); + + if (setReferences) { + setReferences(types); } return types; @@ -234,6 +245,7 @@ void readInterchange(XMLStreamReader reader, Map types) { Collections.emptyList()); types.put(interchange.getId(), interchange); + nextTag(reader, "advancing after interchange"); } Reference readControlStructure(XMLStreamReader reader, @@ -299,10 +311,11 @@ Reference createControlReference(XMLStreamReader reader, String attributeName) { void readTransaction(XMLStreamReader reader, Map types) { QName element = reader.getName(); types.put(StaEDISchema.TRANSACTION_ID, readComplexType(reader, element, types)); + nextTag(reader, "seeking next element after transaction"); } void readTypeDefinitions(XMLStreamReader reader, Map types) { - boolean schemaEnd = false; + boolean schemaEnd = reader.getName().equals(qnSchema); // Cursor is already positioned on a type definition (e.g. from an earlier look-ahead) if (typeDefinitions.containsKey(reader.getName()) @@ -314,9 +327,7 @@ void readTypeDefinitions(XMLStreamReader reader, Map types) { if (nextTag(reader, "reading schema types") == XMLStreamConstants.START_ELEMENT) { readTypeDefinition(types, reader); } else { - if (reader.getName().equals(qnSchema)) { - schemaEnd = true; - } + schemaEnd = reader.getName().equals(qnSchema); } } } diff --git a/src/main/java/io/xlate/edi/internal/schema/SchemaReaderV3.java b/src/main/java/io/xlate/edi/internal/schema/SchemaReaderV3.java index 950bfed4..30ba8869 100644 --- a/src/main/java/io/xlate/edi/internal/schema/SchemaReaderV3.java +++ b/src/main/java/io/xlate/edi/internal/schema/SchemaReaderV3.java @@ -52,7 +52,6 @@ class SchemaReaderV3 extends SchemaReaderBase implements SchemaReader { private static final String ATTR_DISCRIMINATOR = "discriminator"; private static final String ATTR_TITLE = "title"; - final QName qnImplementation; final Deque implementedTypes = new LinkedList<>(); static class ValueSet { @@ -75,7 +74,6 @@ void clear() { protected SchemaReaderV3(String xmlns, XMLStreamReader reader, Map properties) { super(xmlns, reader, properties); - qnImplementation = new QName(xmlns, "implementation"); } public SchemaReaderV3(XMLStreamReader reader, Map properties) { @@ -106,12 +104,16 @@ protected void readInclude(XMLStreamReader reader, Map types) t @Override protected void readImplementation(XMLStreamReader reader, Map types) { - nextTag(reader, "reading implementation start"); QName element = reader.getName(); - LoopImplementation impl = readImplementation(reader, element, types); - if (impl != null) { - types.put(StaEDISchema.IMPLEMENTATION_ID, impl); + if (qnImplementation.equals(element)) { + LoopImplementation impl = readImplementation(reader, element, types); + + if (impl != null) { + types.put(StaEDISchema.IMPLEMENTATION_ID, impl); + } + + nextTag(reader, "seeking next element after implementation end"); } } @@ -201,10 +203,6 @@ LoopImplementation readImplementation(XMLStreamReader reader, QName complexType, Map types) { - if (!qnImplementation.equals(complexType)) { - return null; - } - LoopImplementation loop = readLoopImplementation(reader, complexType, true); String typeId = StaEDISchema.TRANSACTION_ID; EDIComplexType standard = (EDIComplexType) types.get(typeId); diff --git a/src/main/java/io/xlate/edi/internal/schema/SchemaReaderV4.java b/src/main/java/io/xlate/edi/internal/schema/SchemaReaderV4.java index e2d6c681..5febfb48 100644 --- a/src/main/java/io/xlate/edi/internal/schema/SchemaReaderV4.java +++ b/src/main/java/io/xlate/edi/internal/schema/SchemaReaderV4.java @@ -4,6 +4,7 @@ import java.net.URL; import java.util.Map; +import java.util.logging.Logger; import javax.xml.stream.XMLStreamReader; @@ -13,10 +14,19 @@ public class SchemaReaderV4 extends SchemaReaderV3 { + private static final Logger LOGGER = Logger.getLogger(SchemaReaderV4.class.getName()); + public SchemaReaderV4(XMLStreamReader reader, Map properties) { super(StaEDISchemaFactory.XMLNS_V4, reader, properties); } + @Override + void nameCheck(String name, Map types, XMLStreamReader reader) { + if (types.containsKey(name)) { + LOGGER.fine(() -> "Duplicate type name encountered: [" + name + ']'); + } + } + @Override protected String readReferencedId(XMLStreamReader reader) { return parseAttribute(reader, "type", String::valueOf); @@ -44,5 +54,7 @@ protected void readInclude(XMLStreamReader reader, Map types) t } catch (Exception e) { throw schemaException("Exception reading included schema", reader, e); } + + nextTag(reader, "seeking next element after include"); } } diff --git a/src/main/java/io/xlate/edi/internal/schema/SchemaUtils.java b/src/main/java/io/xlate/edi/internal/schema/SchemaUtils.java index b06f488b..a8b6463a 100644 --- a/src/main/java/io/xlate/edi/internal/schema/SchemaUtils.java +++ b/src/main/java/io/xlate/edi/internal/schema/SchemaUtils.java @@ -18,20 +18,21 @@ import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; +import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.util.Enumeration; import java.util.Map; import java.util.Map.Entry; +import java.util.NavigableMap; +import java.util.Properties; +import java.util.TreeMap; import io.xlate.edi.schema.EDISchemaException; import io.xlate.edi.schema.Schema; import io.xlate.edi.schema.SchemaFactory; import io.xlate.edi.stream.EDIStreamConstants.Standards; -import java.util.NavigableMap; -import java.util.Properties; -import java.util.TreeMap; - public class SchemaUtils { private SchemaUtils() { @@ -109,8 +110,18 @@ static boolean isValidEntry(Entry entry, String standard) { } private static Schema getXmlSchema(String resource) throws EDISchemaException { - SchemaFactory schemaFactory = SchemaFactory.newFactory(); URL location = getURL(resource); + URL locationContext; + + try { + locationContext = URI.create(location.toString()).resolve(".").toURL(); + } catch (MalformedURLException e) { + throw new EDISchemaException("Unable to resolve schema location context", e); + } + + SchemaFactory schemaFactory = SchemaFactory.newFactory(); + schemaFactory.setProperty(SchemaFactory.SCHEMA_LOCATION_URL_CONTEXT, locationContext); + return schemaFactory.createSchema(location); } } diff --git a/src/main/java/io/xlate/edi/internal/schema/StaEDISchemaFactory.java b/src/main/java/io/xlate/edi/internal/schema/StaEDISchemaFactory.java index 7b077d3b..87539034 100644 --- a/src/main/java/io/xlate/edi/internal/schema/StaEDISchemaFactory.java +++ b/src/main/java/io/xlate/edi/internal/schema/StaEDISchemaFactory.java @@ -62,7 +62,7 @@ public class StaEDISchemaFactory implements SchemaFactory { @Override public Schema createSchema(InputStream stream) throws EDISchemaException { - Map types = readSchemaTypes(stream, properties); + Map types = readSchemaTypes(stream, properties, true); StaEDISchema schema = new StaEDISchema(StaEDISchema.INTERCHANGE_ID, StaEDISchema.TRANSACTION_ID, @@ -122,15 +122,15 @@ static Map readSchemaTypes(URL location, Map pr LOGGER.fine(() -> "Reading schema from URL: " + location); try (InputStream stream = location.openStream()) { - return readSchemaTypes(stream, properties); + return readSchemaTypes(stream, properties, false); } catch (IOException e) { throw new EDISchemaException("Unable to read URL stream", e); } } - static Map readSchemaTypes(InputStream stream, Map properties) throws EDISchemaException { + static Map readSchemaTypes(InputStream stream, Map properties, boolean setReferences) throws EDISchemaException { try { - return getReader(stream, properties).readTypes(); + return getReader(stream, properties).readTypes(setReferences); } catch (StaEDISchemaReadException e) { throw wrapped(e); } diff --git a/src/main/java/io/xlate/edi/schema/SchemaFactory.java b/src/main/java/io/xlate/edi/schema/SchemaFactory.java index c58f1702..77c97690 100644 --- a/src/main/java/io/xlate/edi/schema/SchemaFactory.java +++ b/src/main/java/io/xlate/edi/schema/SchemaFactory.java @@ -28,6 +28,8 @@ public interface SchemaFactory { * processed by a SchemaFactory. Besides a java.net.URL, any class with a * toString method that returns a valid URL-formated String may be used as * the value for this property. + * + * @since 1.8 */ public static final String SCHEMA_LOCATION_URL_CONTEXT = "io.xlate.edi.schema.SCHEMA_LOCATION_URL_CONTEXT"; diff --git a/src/main/resources/X12/common.xml b/src/main/resources/X12/common.xml new file mode 100644 index 00000000..d946046c --- /dev/null +++ b/src/main/resources/X12/common.xml @@ -0,0 +1,641 @@ + + + + + + + 00 + 01 + 02 + 03 + 04 + 05 + 06 + + + + + + + + 00 + 01 + + + + + + + + 01 + 02 + 03 + 04 + 07 + 08 + 09 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + AM + NR + SA + SN + ZZ + + + + + + + + + + + + + + U + + + + + + 00200 + 00201 + 00204 + 00300 + 00301 + 00302 + 00303 + 00304 + 00305 + 00306 + 00307 + 00400 + 00401 + 00402 + 00403 + 00404 + 00405 + 00406 + 00500 + 00501 + 00502 + 00503 + 00504 + 00505 + 00600 + 00601 + 00602 + 00603 + 00604 + 00605 + 00700 + 00701 + 00702 + 00703 + 00800 + 00801 + + + + + + + + 1 + 0 + + + + + + T + P + I + + + + + + + + + + A + E + R + + + + + + 000 + 001 + 002 + 003 + 004 + 005 + 006 + 007 + 008 + 009 + 010 + 011 + 012 + 013 + 014 + 015 + 016 + 017 + 018 + 019 + 020 + 021 + 022 + 023 + 024 + 025 + 026 + 027 + 028 + 029 + 030 + 031 + 032 + + + + + + 0 + 1 + 2 + + + + + + + + + + 01 + 02 + 03 + 04 + 05 + 06 + 07 + 08 + 09 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + CD + CS + CT + ED + ES + ET + GM + LT + MD + MS + MT + PD + PS + PT + UT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AA + AB + AC + AD + AE + AF + AG + AH + AI + AK + AL + AM + AN + AO + AP + AQ + AR + AS + AT + AU + AV + AW + AX + AY + AZ + BA + BB + BC + BD + BE + BF + BL + BS + CA + CB + CC + CD + CE + CF + CH + CI + CJ + CK + CL + CM + CN + CO + CP + CQ + CR + CS + CT + CU + CV + CW + D3 + D4 + D5 + DA + DD + DF + DI + DM + DS + DX + EC + ED + EI + EN + EP + ER + ES + EV + EX + FA + FB + FC + FG + FR + FT + GC + GE + GF + GL + GP + GR + GT + HB + HC + HI + HN + HP + HR + HS + HU + HV + IA + IB + IC + ID + IE + IF + IG + IH + IJ + IM + IN + IO + IR + IS + JB + KM + LA + LB + LI + LN + LR + LS + LT + MA + MC + MD + ME + MF + MG + MH + MI + MJ + MK + MM + MN + MO + MP + MQ + MR + MS + MT + MV + MW + MX + MY + MZ + NC + NL + NP + NR + NT + OC + OG + OR + OW + PA + PB + PC + PD + PE + PF + PG + PH + PI + PJ + PK + PL + PN + PO + PQ + PR + PS + PT + PU + PV + PW + PY + QG + QM + QO + RA + RB + RC + RD + RE + RF + RG + RH + RI + RJ + RK + RL + RM + RN + RO + RP + RQ + RR + RS + RT + RU + RV + RW + RX + RY + RZ + SA + SB + SC + SD + SE + SH + SI + SJ + SL + SM + SN + SO + SP + SQ + SR + SS + ST + SU + SV + SW + TA + TB + TD + TE + TF + TI + TJ + TM + TN + TO + TP + TR + TS + TT + TU + TX + UA + UB + UC + UD + UI + UP + UW + VA + VB + VC + VD + VE + VH + VI + VS + WA + WB + WG + WI + WL + WR + WT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/X12/v00200.xml b/src/main/resources/X12/v00200.xml index 3da131a8..28e92403 100644 --- a/src/main/resources/X12/v00200.xml +++ b/src/main/resources/X12/v00200.xml @@ -16,6 +16,8 @@ --> + + @@ -30,554 +32,6 @@ - - - 00 - 01 - 02 - 03 - 04 - 05 - 06 - - - - - - - - 00 - 01 - - - - - - - - 01 - 02 - 03 - 04 - 07 - 08 - 09 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18 - 19 - 20 - 21 - 22 - 23 - 24 - 25 - 26 - 27 - 28 - 29 - 30 - 31 - 32 - 33 - 34 - 35 - 36 - 37 - 38 - AM - NR - SA - SN - ZZ - - - - - - - - - - - - - - U - - - - - - 00200 - 00201 - 00204 - 00300 - 00301 - 00302 - 00303 - 00304 - 00305 - 00306 - 00307 - 00400 - 00401 - - - - - - - - 1 - 0 - - - - - - T - P - I - - - - - - - - - - A - E - R - - - - - - 000 - 001 - 002 - 003 - 004 - 005 - 006 - 007 - 008 - 009 - 010 - 011 - 012 - 013 - 014 - 015 - 016 - 017 - 018 - 019 - 020 - 021 - 022 - 023 - 024 - 025 - 026 - 027 - 028 - 029 - 030 - 031 - 032 - - - - - - 0 - 1 - 2 - - - - - - - - - - 01 - 02 - 03 - 04 - 05 - 06 - 07 - 08 - 09 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18 - 19 - 20 - 21 - 22 - 23 - 24 - CD - CS - CT - ED - ES - ET - GM - LT - MD - MS - MT - PD - PS - PT - UT - - - - - - - - - - - - - - - - - - - - - - - - - AA - AB - AC - AD - AE - AF - AG - AH - AI - AK - AL - AM - AN - AO - AP - AQ - AR - AS - AT - AU - AV - AW - AX - AY - AZ - BA - BB - BC - BD - BE - BF - BL - BS - CA - CB - CC - CD - CE - CF - CH - CI - CJ - CK - CL - CM - CN - CO - CP - CQ - CR - CS - CT - CU - CV - CW - D3 - D4 - D5 - DA - DD - DF - DI - DM - DS - DX - EC - ED - EI - EN - EP - ER - ES - EV - EX - FA - FB - FC - FG - FR - FT - GC - GE - GF - GL - GP - GR - GT - HB - HC - HI - HN - HP - HR - HS - HU - HV - IA - IB - IC - ID - IE - IF - IG - IH - IJ - IM - IN - IO - IR - IS - JB - KM - LA - LB - LI - LN - LR - LS - LT - MA - MC - MD - ME - MF - MG - MH - MI - MJ - MK - MM - MN - MO - MP - MQ - MR - MS - MT - MV - MW - MX - MY - MZ - NC - NL - NP - NR - NT - OC - OG - OR - OW - PA - PB - PC - PD - PE - PF - PG - PH - PI - PJ - PK - PL - PN - PO - PQ - PR - PS - PT - PU - PV - PW - PY - QG - QM - QO - RA - RB - RC - RD - RE - RF - RG - RH - RI - RJ - RK - RL - RM - RN - RO - RP - RQ - RR - RS - RT - RU - RV - RW - RX - RY - RZ - SA - SB - SC - SD - SE - SH - SI - SJ - SL - SM - SN - SO - SP - SQ - SR - SS - ST - SU - SV - SW - TA - TB - TD - TE - TF - TI - TJ - TM - TN - TO - TP - TR - TS - TT - TU - TX - UA - UB - UC - UD - UI - UP - UW - VA - VB - VC - VD - VE - VH - VI - VS - WA - WB - WG - WI - WL - WR - WT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -598,35 +52,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/X12/v00402.xml b/src/main/resources/X12/v00402.xml index f917828c..dc2af999 100644 --- a/src/main/resources/X12/v00402.xml +++ b/src/main/resources/X12/v00402.xml @@ -16,6 +16,8 @@ --> + + @@ -30,566 +32,6 @@ - - - 00 - 01 - 02 - 03 - 04 - 05 - 06 - - - - - - - - 00 - 01 - - - - - - - - 01 - 02 - 03 - 04 - 07 - 08 - 09 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18 - 19 - 20 - 21 - 22 - 23 - 24 - 25 - 26 - 27 - 28 - 29 - 30 - 31 - 32 - 33 - 34 - 35 - 36 - 37 - 38 - AM - NR - SA - SN - ZZ - - - - - - - - - - - - - - 00402 - 00403 - 00404 - 00405 - 00406 - 00500 - 00501 - 00502 - 00503 - 00504 - 00505 - 00600 - 00601 - 00602 - 00603 - 00604 - 00605 - 00700 - 00701 - 00702 - 00703 - 00800 - 00801 - - - - - - - - 1 - 0 - - - - - - T - P - I - - - - - - - - - - A - E - R - - - - - - 000 - 001 - 002 - 003 - 004 - 005 - 006 - 007 - 008 - 009 - 010 - 011 - 012 - 013 - 014 - 015 - 016 - 017 - 018 - 019 - 020 - 021 - 022 - 023 - 024 - 025 - 026 - 027 - 028 - 029 - 030 - 031 - 032 - - - - - - 0 - 1 - 2 - - - - - - - - - - 01 - 02 - 03 - 04 - 05 - 06 - 07 - 08 - 09 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18 - 19 - 20 - 21 - 22 - 23 - 24 - CD - CS - CT - ED - ES - ET - GM - LT - MD - MS - MT - PD - PS - PT - UT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - AA - AB - AC - AD - AE - AF - AG - AH - AI - AK - AL - AM - AN - AO - AP - AQ - AR - AS - AT - AU - AV - AW - AX - AY - AZ - BA - BB - BC - BD - BE - BF - BL - BS - CA - CB - CC - CD - CE - CF - CH - CI - CJ - CK - CL - CM - CN - CO - CP - CQ - CR - CS - CT - CU - CV - CW - D3 - D4 - D5 - DA - DD - DF - DI - DM - DS - DX - EC - ED - EI - EN - EP - ER - ES - EV - EX - FA - FB - FC - FG - FR - FT - GC - GE - GF - GL - GP - GR - GT - HB - HC - HI - HN - HP - HR - HS - HU - HV - IA - IB - IC - ID - IE - IF - IG - IH - IJ - IM - IN - IO - IR - IS - JB - KM - LA - LB - LI - LN - LR - LS - LT - MA - MC - MD - ME - MF - MG - MH - MI - MJ - MK - MM - MN - MO - MP - MQ - MR - MS - MT - MV - MW - MX - MY - MZ - NC - NL - NP - NR - NT - OC - OG - OR - OW - PA - PB - PC - PD - PE - PF - PG - PH - PI - PJ - PK - PL - PN - PO - PQ - PR - PS - PT - PU - PV - PW - PY - QG - QM - QO - RA - RB - RC - RD - RE - RF - RG - RH - RI - RJ - RK - RL - RM - RN - RO - RP - RQ - RR - RS - RT - RU - RV - RW - RX - RY - RZ - SA - SB - SC - SD - SE - SH - SI - SJ - SL - SM - SN - SO - SP - SQ - SR - SS - ST - SU - SV - SW - TA - TB - TD - TE - TF - TI - TJ - TM - TN - TO - TP - TR - TS - TT - TU - TX - UA - UB - UC - UD - UI - UP - UW - VA - VB - VC - VD - VE - VH - VI - VS - WA - WB - WG - WI - WL - WR - WT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -610,48 +52,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/schema/EDISchema-v4.xsd b/src/main/resources/schema/EDISchema-v4.xsd index 3cc5bd62..62726881 100644 --- a/src/main/resources/schema/EDISchema-v4.xsd +++ b/src/main/resources/schema/EDISchema-v4.xsd @@ -131,7 +131,7 @@ - + @@ -217,8 +217,8 @@ - - + + @@ -247,8 +247,8 @@ - - + + @@ -470,8 +470,15 @@ - + + + Optional reference to another schema file to include. + + + + + The transaction standard and optional implementation details @@ -479,11 +486,16 @@ + - The referenced transaction standard and implementation details + + The transaction implementation details. When + implementation is used without an associated + transaction element, the transaction must + have been declared in an 'include'd schema. + - @@ -585,7 +597,7 @@ - + diff --git a/src/test/java/io/xlate/edi/internal/schema/StaEDISchemaFactoryTest.java b/src/test/java/io/xlate/edi/internal/schema/StaEDISchemaFactoryTest.java index a634daa0..9993b0f9 100644 --- a/src/test/java/io/xlate/edi/internal/schema/StaEDISchemaFactoryTest.java +++ b/src/test/java/io/xlate/edi/internal/schema/StaEDISchemaFactoryTest.java @@ -33,12 +33,16 @@ import java.util.List; import java.util.Objects; import java.util.stream.Collectors; +import java.util.stream.Stream; import java.util.stream.StreamSupport; +import javax.xml.stream.XMLStreamException; + import org.junit.jupiter.api.Test; import io.xlate.edi.schema.EDIComplexType; import io.xlate.edi.schema.EDISchemaException; +import io.xlate.edi.schema.EDISimpleType; import io.xlate.edi.schema.EDIType; import io.xlate.edi.schema.Schema; import io.xlate.edi.schema.SchemaFactory; @@ -348,6 +352,35 @@ void testDuplicateElementTypeNames() { assertEquals("duplicate name: DE0004", cause.getMessage()); } + @Test + void testDuplicateElementTypeNames_v4_override() throws EDISchemaException { + SchemaFactory factory = SchemaFactory.newFactory(); + InputStream stream = new ByteArrayInputStream(("" + + "" + + "" + + "" + + " " + + " " + + " " + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "").getBytes()); + Schema schema = factory.createSchema(stream); + Stream.of("SG1","SG2","SG3","SG4","SG5","SG6") + .forEach(segmentTag -> { + assertEquals(1, ((EDISimpleType) ((EDIComplexType) schema.getType(segmentTag)).getReferences().get(0).getReferencedType()).getMinLength()); + assertEquals(10, ((EDISimpleType) ((EDIComplexType) schema.getType(segmentTag)).getReferences().get(0).getReferencedType()).getMaxLength()); + }); + } + @Test void testGetControlSchema() throws EDISchemaException { SchemaFactory factory = SchemaFactory.newFactory(); @@ -626,6 +659,22 @@ void testValidIncludeV4() throws EDISchemaException { assertNotNull(schema); } + @Test + void testExceptionAtDocumentEnd() throws EDISchemaException { + SchemaFactory factory = SchemaFactory.newFactory(); + InputStream stream = new ByteArrayInputStream(("" + + "" + + " " + + " " + + "" + + "").getBytes()); + + EDISchemaException thrown = assertThrows(EDISchemaException.class, () -> factory.createSchema(stream)); + assertEquals("XMLStreamException reading end of document", thrown.getOriginalMessage()); + assertTrue(thrown.getCause() instanceof StaEDISchemaReadException); + assertTrue(thrown.getCause().getCause() instanceof XMLStreamException); + } + @Test void testInvalidUrlIncludeV4() { SchemaFactory factory = SchemaFactory.newFactory(); diff --git a/src/test/java/io/xlate/edi/internal/schema/StaEDISchemaTest.java b/src/test/java/io/xlate/edi/internal/schema/StaEDISchemaTest.java index 33d18905..75eb6e51 100644 --- a/src/test/java/io/xlate/edi/internal/schema/StaEDISchemaTest.java +++ b/src/test/java/io/xlate/edi/internal/schema/StaEDISchemaTest.java @@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.InputStream; +import java.net.URL; import java.util.Collections; import java.util.Map; @@ -33,6 +34,7 @@ import io.xlate.edi.schema.EDIComplexType; import io.xlate.edi.schema.EDISchemaException; import io.xlate.edi.schema.EDIType; +import io.xlate.edi.schema.SchemaFactory; @SuppressWarnings("resource") class StaEDISchemaTest { @@ -44,31 +46,36 @@ void testSetTypesNullTypes() { } @Test - void testRootTypeIsInterchange_00200() throws EDISchemaException, XMLStreamException, FactoryConfigurationError { + void testRootTypeIsInterchange_00200() throws Exception { StaEDISchema schema = new StaEDISchema(StaEDISchema.INTERCHANGE_ID, StaEDISchema.TRANSACTION_ID); - InputStream schemaStream = getClass().getResourceAsStream("/X12/v00200.xml"); - XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(schemaStream); + URL schemaLocation = getClass().getResource("/X12/v00200.xml"); + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(schemaLocation.openStream()); reader.nextTag(); // Pass by element - Map types = new SchemaReaderV4(reader, Collections.emptyMap()).readTypes(); + Map types = new SchemaReaderV4(reader, + Collections.singletonMap(SchemaFactory.SCHEMA_LOCATION_URL_CONTEXT, + schemaLocation.toURI().resolve(".").toURL())).readTypes(); schema.setTypes(types); assertEquals(EDIType.Type.INTERCHANGE, schema.getType(StaEDISchema.INTERCHANGE_ID).getType()); } @Test - void testRootTypeIsInterchange_00402() throws EDISchemaException, XMLStreamException, FactoryConfigurationError { + void testRootTypeIsInterchange_00402() throws Exception { StaEDISchema schema = new StaEDISchema(StaEDISchema.INTERCHANGE_ID, StaEDISchema.TRANSACTION_ID); - InputStream schemaStream = getClass().getResourceAsStream("/X12/v00402.xml"); - XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(schemaStream); + URL schemaLocation = getClass().getResource("/X12/v00402.xml"); + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(schemaLocation.openStream()); reader.nextTag(); // Pass by element - Map types = new SchemaReaderV4(reader, Collections.emptyMap()).readTypes(); + Map types = new SchemaReaderV4(reader, + Collections.singletonMap(SchemaFactory.SCHEMA_LOCATION_URL_CONTEXT, + schemaLocation.toURI().resolve(".").toURL())).readTypes(); schema.setTypes(types); assertEquals(EDIType.Type.INTERCHANGE, schema.getType(StaEDISchema.INTERCHANGE_ID).getType()); } @Test - void testLoadV3TransactionMultipleSyntaxElements_EDIFACT_CONTRL() throws EDISchemaException, XMLStreamException, FactoryConfigurationError { + void testLoadV3TransactionMultipleSyntaxElements_EDIFACT_CONTRL() + throws EDISchemaException, XMLStreamException, FactoryConfigurationError { StaEDISchema schema = new StaEDISchema(StaEDISchema.INTERCHANGE_ID, StaEDISchema.TRANSACTION_ID); InputStream schemaStream = getClass().getResourceAsStream("/EDIFACT/CONTRL-v4r02.xml"); XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(schemaStream); diff --git a/src/test/resources/EDIFACT/fragment-uci-duplicate-element-names.xml b/src/test/resources/EDIFACT/fragment-uci-duplicate-element-names.xml index a1f5e34f..061e8cf5 100644 --- a/src/test/resources/EDIFACT/fragment-uci-duplicate-element-names.xml +++ b/src/test/resources/EDIFACT/fragment-uci-duplicate-element-names.xml @@ -1,5 +1,6 @@ +