Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java Bean Wiring Not Working #45

Open
jeffgbradley2 opened this issue May 7, 2021 · 2 comments
Open

Java Bean Wiring Not Working #45

jeffgbradley2 opened this issue May 7, 2021 · 2 comments
Assignees
Labels
priority: low type: documentation Improvements or additions to documentation

Comments

@jeffgbradley2
Copy link

Wiring is not working for collections in segment groups unless the retain attribute is set to "yes" on the collection beans in the example below.

EDI File (with new lines added for legibility):

ISA*00*          *00*          *02*ODFL           *ZZ*ACMEINC        *170202*1244*U*00401*000001062*0*P*>~
GS*QM*ODFL*ACMEINC*20170202*124452*906*X*004010~
ST*214*0001~
B10*02625962200*NAMCLF0005633*ODFL~
L11*4550465693*PO~
N1*SH*MICHELIN AIRCRAFT TIRE~
N3*9801 TWIN LAKES PKWY~
N4*CHARLOTTE*NC*28269~
N1*CN*JETLBUE AIRWAYS CORP~
N3*14 TINKER AVE STE 2~
N4*LONDONDERRY*NH*03053~
LX*1~
AT7*D1*NS***20170202*1217*ET~
AT8*G*L*8142*15~
SE*13*0001~
GE*8*9185~
IEA*1*000015198~

Schema definition:

<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
            xmlns:ibmEdiFmt="http://www.ibm.com/dfdl/EDI/Format">

    <xsd:import namespace="http://www.ibm.com/dfdl/EDI/Format"
                schemaLocation="/EDIFACT-Common/IBM_EDI_Format.dfdl.xsd"/>

    <xsd:annotation>
        <xsd:appinfo source="http://www.ogf.org/dfdl/">
            <dfdl:format ref="ibmEdiFmt:EDIFormat"/>
        </xsd:appinfo>
    </xsd:annotation>

    <xsd:element name="shipment-status-message">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:sequence dfdl:initiatedContent="yes">
                    <xsd:element name="interchange" dfdl:initiator="ISA" dfdl:ref="ibmEdiFmt:EDISegmentFormat">
                        <xsd:complexType>
                            <xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
                                <xsd:element name="isa-1" type="xsd:string" />
                                <xsd:element name="isa-2" type="xsd:string" />
                                <xsd:element name="isa-3" type="xsd:string" />
                                <xsd:element name="isa-4" type="xsd:string" />
                                <xsd:element name="sender-qualifier" type="xsd:string" />
                                <xsd:element name="sender-id" type="xsd:string" />
                                <xsd:element name="receiver-qualifier" type="xsd:string" />
                                <xsd:element name="receiver-id" type="xsd:string" />
                                <xsd:element name="isa-5" type="xsd:string" />
                                <xsd:element name="isa-6" type="xsd:string" />
                                <xsd:element name="isa-7" type="xsd:string" />
                                <xsd:element name="isa-8" type="xsd:string" />
                                <xsd:element name="isa-9" type="xsd:string" />
                                <xsd:element name="isa-10" type="xsd:string" />
                                <xsd:element name="isa-11" type="xsd:string" />
                                <xsd:element name="isa-12" type="xsd:string" />
                            </xsd:sequence>
                        </xsd:complexType>
                    </xsd:element>
                    <xsd:element name="group" dfdl:initiator="GS" dfdl:ref="ibmEdiFmt:EDISegmentFormat">
                        <xsd:complexType>
                            <xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
                                <xsd:element name="gs-1" type="xsd:string" />
                                <xsd:element name="gs-2" type="xsd:string" />
                                <xsd:element name="gs-3" type="xsd:string" />
                                <xsd:element name="gs-4" type="xsd:string" />
                                <xsd:element name="gs-5" type="xsd:string" />
                                <xsd:element name="gs-6" type="xsd:string" />
                                <xsd:element name="gs-7" type="xsd:string" />
                                <xsd:element name="gs-8" type="xsd:string" />
                            </xsd:sequence>
                        </xsd:complexType>
                    </xsd:element>
                    <xsd:element name="transaction-set" dfdl:initiator="ST" maxOccurs="unbounded">
                        <xsd:complexType>
                            <xsd:sequence>
                                <xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentFormat">
                                    <xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
                                        <xsd:element name="id" type="xsd:string" />
                                        <xsd:element name="sequence" type="xsd:string" />
                                    </xsd:sequence>
                                </xsd:sequence>
                                <xsd:element name="message-header" dfdl:initiator="B10" dfdl:ref="ibmEdiFmt:EDISegmentFormat">
                                    <xsd:complexType>
                                        <xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
                                            <xsd:element name="reference-identification" type="xsd:string" />
                                            <xsd:element name="shipment-identification-number" type="xsd:string" />
                                            <xsd:element name="scac" type="xsd:string" />
                                        </xsd:sequence>
                                    </xsd:complexType>
                                </xsd:element>
                                <xsd:element name="reference-numbers" dfdl:initiator="L11" dfdl:ref="ibmEdiFmt:EDISegmentFormat">
                                    <xsd:complexType>
                                        <xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
                                            <xsd:element name="reference-identification" type="xsd:string" />
                                            <xsd:element name="reference-qualifier" type="xsd:string" />
                                        </xsd:sequence>
                                    </xsd:complexType>
                                </xsd:element>
                                <xsd:element name="party-identification" dfdl:initiator="N1" maxOccurs="unbounded">
                                    <xsd:complexType>
                                        <xsd:sequence>
                                            <xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentFormat">
                                                <xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
                                                    <xsd:element name="entity-identifier-code" type="xsd:string" />
                                                    <xsd:element name="name" type="xsd:string" />
                                                </xsd:sequence>
                                            </xsd:sequence>
                                            <xsd:element name="party-location" dfdl:initiator="N3" dfdl:ref="ibmEdiFmt:EDISegmentFormat">
                                                <xsd:complexType>
                                                    <xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
                                                        <xsd:element name="address-information" type="xsd:string" />
                                                    </xsd:sequence>
                                                </xsd:complexType>
                                            </xsd:element>
                                            <xsd:element name="geographic-location" dfdl:initiator="N4" dfdl:ref="ibmEdiFmt:EDISegmentFormat">
                                                <xsd:complexType>
                                                    <xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
                                                        <xsd:element name="city" type="xsd:string" />
                                                        <xsd:element name="state" type="xsd:string" />
                                                        <xsd:element name="postal-code" type="xsd:string" />
                                                    </xsd:sequence>
                                                </xsd:complexType>
                                            </xsd:element>
                                        </xsd:sequence>
                                    </xsd:complexType>
                                </xsd:element>
                                <xsd:element name="transaction-set-line-number" dfdl:initiator="LX" dfdl:ref="ibmEdiFmt:EDISegmentFormat">
                                    <xsd:complexType>
                                        <xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
                                            <xsd:element name="assigned-number" type="xsd:string" />
                                        </xsd:sequence>
                                    </xsd:complexType>
                                </xsd:element>
                                <xsd:element name="shipment-status-details" dfdl:initiator="AT7" dfdl:ref="ibmEdiFmt:EDISegmentFormat">
                                    <xsd:complexType>
                                        <xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
                                            <xsd:element name="indicator-code" type="xsd:string" />
                                            <xsd:element name="reason-code-1" type="xsd:string" />
                                            <xsd:element name="status-code" type="xsd:string" />
                                            <xsd:element name="reason-code-2" type="xsd:string" />
                                            <xsd:element name="date" type="xsd:string" />
                                            <xsd:element name="time" type="xsd:string" />
                                            <xsd:element name="time-code" type="xsd:string" />
                                        </xsd:sequence>
                                    </xsd:complexType>
                                </xsd:element>
                                <xsd:element name="shipment-weight-quantity-data" dfdl:initiator="AT8" dfdl:ref="ibmEdiFmt:EDISegmentFormat">
                                    <xsd:complexType>
                                        <xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
                                            <xsd:element name="weight-qualifier" type="xsd:string" />
                                            <xsd:element name="weight-unit-code" type="xsd:string" />
                                            <xsd:element name="weight" type="xsd:string" />
                                            <xsd:element name="lading-quantity" type="xsd:string" />
                                        </xsd:sequence>
                                    </xsd:complexType>
                                </xsd:element>
                                <xsd:element name="transaction-set-trailer" dfdl:initiator="SE" dfdl:ref="ibmEdiFmt:EDISegmentFormat">
                                    <xsd:complexType>
                                        <xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
                                            <xsd:element name="number-of-segments" type="xsd:string" />
                                            <xsd:element name="control-number" type="xsd:string" />
                                        </xsd:sequence>
                                    </xsd:complexType>
                                </xsd:element>
                            </xsd:sequence>
                        </xsd:complexType>
                    </xsd:element>
                    <xsd:element name="group-trailer" dfdl:initiator="GE" dfdl:ref="ibmEdiFmt:EDISegmentFormat">
                        <xsd:complexType>
                            <xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
                                <xsd:element name="gs-1" type="xsd:string" />
                                <xsd:element name="gs-2" type="xsd:string" />
                            </xsd:sequence>
                        </xsd:complexType>
                    </xsd:element>
                    <xsd:element name="interchange-trailer" dfdl:initiator="IEA" dfdl:ref="ibmEdiFmt:EDISegmentFormat">
                        <xsd:complexType>
                            <xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
                                <xsd:element name="isa-1" type="xsd:string" />
                                <xsd:element name="isa-2" type="xsd:string" />
                            </xsd:sequence>
                        </xsd:complexType>
                    </xsd:element>
                </xsd:sequence>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

</xsd:schema>

Bean mapping file:

<?xml version="1.0" encoding="UTF-8" ?>
<smooks-resource-list
        xmlns="https://www.smooks.org/xsd/smooks-2.0.xsd"
        xmlns:jb="https://www.smooks.org/xsd/smooks/javabean-1.6.xsd"
        xmlns:edi="https://www.smooks.org/xsd/smooks/edi-2.0.xsd">

    <edi:parser schemaURI="/mappings/shipment-status-message.dfdl.xsd"
                segmentTerminator="~"
                dataElementSeparator="*"
                compositeDataElementSeparator="^"/>

    <jb:bean beanId="shipmentStatusMessage" class="org.smooks.examples.edi2java.model.ShipmentStatusMessage" createOnElement="message-header">
        <jb:value property="senderId" data="interchange/sender-id" />
        <jb:value property="receiverId" data="interchange/receiver-id" />
        <jb:value property="shipmentId" data="shipment-identification-number" />
        <jb:value property="scac" data="message-header/scac" />
        <jb:value property="referenceNumber" data="reference-identification" />
        <jb:wiring property="details" beanIdRef="details"/>
        <jb:wiring property="locationInformation" beanIdRef="locationInformationList" />
        <jb:wiring property="references" beanIdRef="references" />
        <jb:wiring property="quantities" beanIdRef="quantities" />
    </jb:bean>

    <jb:bean beanId="details" class="java.util.ArrayList" createOnElement="message-header" >
        <jb:wiring beanIdRef="detail" />
    </jb:bean>

    <jb:bean beanId="detail" class="org.smooks.examples.edi2java.model.ShipmentStatusMessageDetail" createOnElement="shipment-status-details">
        <jb:value property="statusCode" data="status-code" default="1" />
        <jb:value data="reason-code-1" property="statusReasonCode"/>
        <jb:value data="reason-code-2" property="appointmentReasonCode"/>
        <jb:value data="date" property="date" decoder="Date">
            <jb:decodeParam name="format">yyyyMMdd</jb:decodeParam>
        </jb:value>
        <jb:value data="time" property="time"/>
        <jb:value data="time-code" property="timeCode"/>
        <jb:value data="city" property="city"/>
        <jb:value data="state" property="state"/>
    </jb:bean>

    <jb:bean beanId="locationInformationList" class="java.util.ArrayList" createOnElement="message-header">
        <jb:wiring beanIdRef="locationInformation" />
    </jb:bean>

    <jb:bean beanId="locationInformation" class="org.smooks.examples.edi2java.model.ShipmentStatusLocationInformation" createOnElement="party-identification">
        <jb:value data="name" property="name" />
        <jb:value data="entity-identifier-code" property="entityIdentifierCode" />
        <jb:value data="party-location/address-information" property="addressLine1"/>
        <jb:value data="geographic-location/city" property="city" />
        <jb:value data="geographic-location/state" property="state" />
        <jb:value data="geographic-location/postal-code" property="postalCode" />
    </jb:bean>

    <jb:bean beanId="references" class="java.util.ArrayList" createOnElement="message-header">
        <jb:wiring beanIdRef="reference" />
    </jb:bean>

    <jb:bean beanId="reference" class="org.smooks.examples.edi2java.model.ShipmentStatusReference" createOnElement="reference-numbers">
        <jb:value data="reference-identification" property="referenceNumber" />
        <jb:value data="reference-qualifier" property="referenceQualifier" />
        <jb:value data="description" property="description" />
    </jb:bean>

    <jb:bean beanId="quantities" class="java.util.ArrayList" createOnElement="message-header" >
        <jb:wiring beanIdRef="quantity" />
    </jb:bean>

    <jb:bean beanId="quantity" class="org.smooks.examples.edi2java.model.ShipmentStatusQuantity" createOnElement="shipment-weight-quantity-data">
        <jb:value data="weight-qualifier" property="weightQualifier" />
        <jb:value data="weight-unit-code" property="weightUnitCode" />
        <jb:value data="weight" property="weight" />
        <jb:value data="lading-quantity" property="ladingQuantity" />
    </jb:bean>

</smooks-resource-list>

Unit Test:

void mapODFLShipmentStatusMessage() {
        String ediMessage =
                "ISA*00*          *00*          *02*ODFL           *ZZ*M33MIAV        *170202*1244*U*00401*000001062*0*P*>~" +
                        "GS*QM*ODFL*M33MIAV*20170202*124452*906*X*004010~" +
                        "ST*214*0001~" +
                        "B10*02625962200*NAMCLF0005633*ODFL~" +
                        "L11*4550465693*PO~" +
                        "N1*SH*MICHELIN AIRCRAFT TIRE~" +
                        "N3*9801 TWIN LAKES PKWY~" +
                        "N4*CHARLOTTE*NC*28269~" +
                        "N1*CN*JETLBUE AIRWAYS CORP~" +
                        "N3*14 TINKER AVE STE 2~" +
                        "N4*LONDONDERRY*NH*03053~" +
                        "LX*1~" +
                        "AT7*D1*NS***20170202*1217*ET~" +
                        "AT8*G*L*8142*15~" +
                        "SE*13*0001~" +
                        "GE*8*9185~" +
                        "IEA*1*000015198~";
        //var config = getClass().getResource("/mappings/shipment-status-message.xml");
        Smooks smooks = new Smooks("/mappings/shipment-status-message.xml");
        try(ByteArrayInputStream stream = new ByteArrayInputStream(ediMessage.getBytes(StandardCharsets.UTF_8))) {
            ExecutionContext context = smooks.createExecutionContext();
            JavaResult result = new JavaResult();
            smooks.filterSource(context, new StreamSource(stream), result);
            ShipmentStatusMessage message = (ShipmentStatusMessage)result.getBean("shipmentStatusMessage");
            smooks.close();
            assertEquals("ODFL", message.getScac());
            assertEquals(1, message.getDetails().size());
            assertEquals(1, message.getReferences().size());
            assertEquals(2, message.getLocationInformation().size());
            assertEquals(1, message.getQuantities().size());
        }
    }
@cjmamo
Copy link
Member

cjmamo commented May 10, 2021

This is the expected behaviour according to the docs.

@jeffgbradley2
Copy link
Author

The docs you linked do not mention that wiring will not work unless the wired beans are explicitly retained.

@cjmamo cjmamo self-assigned this Dec 3, 2021
@cjmamo cjmamo added this to the v2.0.0-RC1 milestone Dec 3, 2021
@cjmamo cjmamo added type: documentation Improvements or additions to documentation priority: low labels Dec 3, 2021
@cjmamo cjmamo removed this from the v2.0.0-RC1 milestone Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low type: documentation Improvements or additions to documentation
Development

No branches or pull requests

2 participants