Skip to content

Commit

Permalink
ISX release character support, X12 schema 007040 and above
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeEdgar committed Jul 13, 2020
1 parent ab50d10 commit 17eb730
Show file tree
Hide file tree
Showing 5 changed files with 365 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
public class X12Dialect implements Dialect {

private static final String ISA = "ISA";
private static final String ISX = "ISX";
private static final String GS = "GS";
private static final String ST = "ST";

private static final int RELEASE_ISX_SEGMENT = 704; // 007040 (Version 7, release 4)
private static final int RELEASE_ELEMENT_I65 = 402; // 004020 (Version 4, release 2)

static final char DFLT_SEGMENT_TERMINATOR = '~';
static final char DFLT_DATA_ELEMENT_SEPARATOR = '*';
static final char DFLT_COMPONENT_ELEMENT_SEPARATOR = ':';
Expand All @@ -39,10 +46,14 @@ public class X12Dialect implements Dialect {
private int index = -1;
private boolean initialized;
private boolean rejected;
private char sd = DFLT_SEGMENT_TERMINATOR;
private char ed = DFLT_DATA_ELEMENT_SEPARATOR;
private char cd = DFLT_COMPONENT_ELEMENT_SEPARATOR;
private char er = DFLT_REPETITION_SEPARATOR;

private CharacterSet characters;
private char segmentDelimiter = DFLT_SEGMENT_TERMINATOR;
private char elementDelimiter = DFLT_DATA_ELEMENT_SEPARATOR;
private char decimalMark = '.';
private char releaseIndicator = 0;
private char componentDelimiter = DFLT_COMPONENT_ELEMENT_SEPARATOR;
private char elementRepeater = DFLT_REPETITION_SEPARATOR;

private static final int TX_AGENCY = 0;
private static final int TX_VERSION = 1;
Expand Down Expand Up @@ -76,33 +87,38 @@ boolean initialize(CharacterSet characters) {
}
}

cd = header[X12_COMPONENT_OFFSET];
sd = header[X12_SEGMENT_OFFSET];
er = header[X12_REPEAT_OFFSET];
componentDelimiter = header[X12_COMPONENT_OFFSET];
segmentDelimiter = header[X12_SEGMENT_OFFSET];
elementRepeater = header[X12_REPEAT_OFFSET];

characters.setClass(cd, CharacterClass.COMPONENT_DELIMITER);
characters.setClass(sd, CharacterClass.SEGMENT_DELIMITER);
characters.setClass(componentDelimiter, CharacterClass.COMPONENT_DELIMITER);
characters.setClass(segmentDelimiter, CharacterClass.SEGMENT_DELIMITER);

try {
version = new String[] { new String(header, 84, 5) };
version = new String[] { new String(header, 84, 5) };

if (Integer.parseInt(version[0]) >= 402) {
characters.setClass(er, CharacterClass.ELEMENT_REPEATER);
} else {
er = '\0';
}
} catch (@SuppressWarnings("unused") NumberFormatException nfe) {
if (numericVersion() >= RELEASE_ELEMENT_I65) {
characters.setClass(elementRepeater, CharacterClass.ELEMENT_REPEATER);
} else {
/*
* Ignore exception - the ELEMENT_REPEATER will not be set due to a
* non-numeric version.
* Exception parsing the version or older version - the ELEMENT_REPEATER
* will not be set.
*/
er = '\0';
elementRepeater = '\0';
}

this.characters = characters;
initialized = true;
return true;
}

int numericVersion() {
try {
return Integer.parseInt(version[0]);
} catch (NumberFormatException nfe) {
return 0;
}
}

@Override
public void setHeaderTag(String tag) {
// No operation, can only be ISA
Expand Down Expand Up @@ -138,8 +154,8 @@ public boolean appendHeader(CharacterSet characters, char value) {
header = new char[X12_ISA_LENGTH];
break;
case X12_ELEMENT_OFFSET:
ed = value;
characters.setClass(ed, CharacterClass.ELEMENT_DELIMITER);
elementDelimiter = value;
characters.setClass(elementDelimiter, CharacterClass.ELEMENT_DELIMITER);
break;
default:
break;
Expand All @@ -161,32 +177,32 @@ public boolean appendHeader(CharacterSet characters, char value) {

@Override
public char getComponentElementSeparator() {
return cd;
return componentDelimiter;
}

@Override
public char getDataElementSeparator() {
return ed;
return elementDelimiter;
}

@Override
public char getDecimalMark() {
return '.';
return decimalMark;
}

@Override
public char getReleaseIndicator() {
return 0;
return releaseIndicator;
}

@Override
public char getRepetitionSeparator() {
return er;
return elementRepeater;
}

@Override
public char getSegmentTerminator() {
return sd;
return segmentDelimiter;
}

void clearTransactionVersion() {
Expand All @@ -203,7 +219,12 @@ void updateTransactionVersionString(String[] transactionVersion) {

@Override
public void elementData(CharSequence data, Location location) {
if ("GS".equals(location.getSegmentTag())) {
if (ISX.equals(location.getSegmentTag()) && numericVersion() >= RELEASE_ISX_SEGMENT) {
if (location.getElementPosition() == 1 && data.length() == 1) {
releaseIndicator = data.charAt(0);
characters.setClass(releaseIndicator, CharacterClass.RELEASE_CHARACTER);
}
} else if (GS.equals(location.getSegmentTag())) {
switch (location.getElementPosition()) {
case 1:
clearTransactionVersion();
Expand All @@ -220,7 +241,7 @@ public void elementData(CharSequence data, Location location) {
default:
break;
}
} else if ("ST".equals(location.getSegmentTag()) && location.getElementPosition() == 3 && data.length() > 0) {
} else if (ST.equals(location.getSegmentTag()) && location.getElementPosition() == 3 && data.length() > 0) {
transactionVersion[TX_VERSION] = data.toString();
updateTransactionVersionString(transactionVersion);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/X12/common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
<value>00701</value>
<value>00702</value>
<value>00703</value>
<value>00704</value>
<value>00800</value>
<value>00801</value>
</enumeration>
Expand Down
56 changes: 56 additions & 0 deletions src/main/resources/X12/v00704.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<!--
Copyright 2020 xlate.io LLC, http://www.xlate.io
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
-->
<schema xmlns="http://xlate.io/EDISchema/v4">

<include schemaLocation="common.xml"/>

<interchange header="ISA" trailer="IEA">
<sequence>
<segment type="ISB" title="Grade of Service Request"/>
<segment type="ISE" title="Deferred Delivery Request"/>
<segment type="TA1" title="Interchange Acknowledgment" maxOccurs="99999"/>
<segment type="ISX" title="Interchange Syntax Extension"/>

<group header="GS" trailer="GE">
<transaction header="ST" trailer="SE"/>
</group>

<transaction header="ST" trailer="SE" use="prohibited"/>
</sequence>
</interchange>

<segmentType name="ISA">
<sequence>
<element type="I01" minOccurs="1"/>
<element type="I02" minOccurs="1"/>
<element type="I03" minOccurs="1"/>
<element type="I04" minOccurs="1"/>
<element type="I05" minOccurs="1"/>
<element type="I06" minOccurs="1"/>
<element type="I05" minOccurs="1"/>
<element type="I07" minOccurs="1"/>
<element type="I08" minOccurs="1"/>
<element type="I09" minOccurs="1"/>
<element type="I65" minOccurs="1"/>
<element type="I11" minOccurs="1"/>
<element type="I12" minOccurs="1"/>
<element type="I13" minOccurs="1"/>
<element type="I14" minOccurs="1"/>
<element type="I15" minOccurs="1"/>
</sequence>
</segmentType>
</schema>
2 changes: 2 additions & 0 deletions src/main/resources/staedi-control-index.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#-------------------------------------------------------------------------------
X12.00200=/X12/v00200.xml
X12.00402=/X12/v00402.xml
X12.00704=/X12/v00704.xml

EDIFACT.1=/EDIFACT/v2.xml
EDIFACT.2=/EDIFACT/v2.xml
EDIFACT.3=/EDIFACT/v3.xml
Expand Down
Loading

0 comments on commit 17eb730

Please sign in to comment.