Smooks 1.5.1 EDIParser does not validate require field when defined as components

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Smooks 1.5.1 EDIParser does not validate require field when defined as components

Julio C. VERGARA-HEINRROTH
Given the following edi file content:
SV1*~
I have the following segment definition:
<medi:segment xmltag="professional-service" segcode="SV1" truncatable="true" minOccurs="0" maxOccurs="1">
                <medi:field xmltag="composite-medical-procedure-identifier-sv1" required="true" truncatable="true">
                    <medi:component xmltag="product-or-service-id-qualifier" required="true" minLength="2" maxLength="2"/>
                    <medi:component xmltag="procedure-code-start" required="true" minLength="1" maxLength="48"/>
                    <medi:component xmltag="procedure-modifier-1" required="false" minLength="2" maxLength="2"/>
                    <medi:component xmltag="procedure-modifier-2" required="false" minLength="2" maxLength="2"/>
                    <medi:component xmltag="procedure-modifier-3" required="false" minLength="2" maxLength="2"/>
                    <medi:component xmltag="procedure-modifier-4" required="false" minLength="2" maxLength="2"/>
                    <medi:component xmltag="procedure-code-description" required="false" minLength="1" maxLength="80"/>
                    <medi:component xmltag="procedure-code-end" required="false" minLength="1" maxLength="48"/>
                </medi:field>
                ...<!-- other optional segments -->
</medi:segment>

In the EDIParser, the mapfield method validates the require="true" attribute only if the field has not been defined as a component

private void mapField(String fieldMessageVal, Field expectedField, int fieldIndex, String segmentCode) throws SAXException {

              List<Component> expectedComponents = expectedField.getComponents();

 

              // If there are components defined on this field...

           if(expectedComponents.size() != 0) {

            Delimiters delimiters = segmentReader.getDelimiters();

                     String[] currentFieldComponents = EDIUtils.split(fieldMessageVal, delimiters.getComponent(), delimiters.getEscape());

 

            assertComponentsOK(expectedField, fieldIndex, segmentCode, expectedComponents, currentFieldComponents);

 

            if (currentFieldComponents.length > 0 || !ignoreEmptyNodes()) {

              startElement(expectedField, true);

                   // Iterate over the field components and map them...

                           for(int i = 0; i < currentFieldComponents.length; i++) {

                                  String componentMessageVal = currentFieldComponents[i];

                                  Component expectedComponent = expectedComponents.get(i);

      

                                  mapComponent(componentMessageVal, expectedComponent, fieldIndex, i, segmentCode, expectedField.getXmltag());

                           }

                      endElement(expectedField, true);

            }

              } else {

            if(expectedField.isRequired() && fieldMessageVal.length() == 0) {

                throw new EDIParseException(edifactModel.getEdimap(), "Segment [" + segmentCode + "], field " + (fieldIndex + 1) + " (" + expectedField.getXmltag() + ") expected to contain a value.  Currently at segment number " + segmentReader.getCurrentSegmentNumber() + ".", expectedField, segmentReader.getCurrentSegmentNumber(), segmentReader.getCurrentSegmentFields());

            }

 

            if (fieldMessageVal.length() > 0 || !ignoreEmptyNodes()) {

                startElement(expectedField, true);

                writeToContentHandler(fieldMessageVal);

                endElement(expectedField, false);

            }

              }

       }

 

Is this a defect?

Thanks,
Julio Vergara


Reply | Threaded
Open this post in threaded view
|

Re: Smooks 1.5.1 EDIParser does not validate require field when defined as components

Tom Fennelly
Hi Julio.

So we're talking about "composite-medical-procedure-identifier-sv1/product-or-service-id-qualifier", right?

It would appear as though the "if(expectedField.isRequired() && fieldMessageVal.length() == 0)" check in the else block is not right.  Instead of checking "fieldMessageVal.length()", it should probably do something like "if(expectedField.isRequired() && ((!expectedField.getComponents().isEmpty() && expectedField.getComponents().get(0).isRequired()) || fieldMessageVal.trim().length() == 0))" i.e. it should check that there are components configured and if the first component is required, then you get an error.  I think that would work in your case.

T.


On 02/07/2014 18:52, Julio C. VERGARA-HEINRROTH wrote:
Given the following edi file content:
SV1*~
I have the following segment definition:
<medi:segment xmltag="professional-service" segcode="SV1" truncatable="true" minOccurs="0" maxOccurs="1">
                <medi:field xmltag="composite-medical-procedure-identifier-sv1" required="true" truncatable="true">
                    <medi:component xmltag="product-or-service-id-qualifier" required="true" minLength="2" maxLength="2"/>
                    <medi:component xmltag="procedure-code-start" required="true" minLength="1" maxLength="48"/>
                    <medi:component xmltag="procedure-modifier-1" required="false" minLength="2" maxLength="2"/>
                    <medi:component xmltag="procedure-modifier-2" required="false" minLength="2" maxLength="2"/>
                    <medi:component xmltag="procedure-modifier-3" required="false" minLength="2" maxLength="2"/>
                    <medi:component xmltag="procedure-modifier-4" required="false" minLength="2" maxLength="2"/>
                    <medi:component xmltag="procedure-code-description" required="false" minLength="1" maxLength="80"/>
                    <medi:component xmltag="procedure-code-end" required="false" minLength="1" maxLength="48"/>
                </medi:field>
                ...<!-- other optional segments -->
</medi:segment>

In the EDIParser, the mapfield method validates the require="true" attribute only if the field has not been defined as a component

private void mapField(String fieldMessageVal, Field expectedField, int fieldIndex, String segmentCode) throws SAXException {

              List<Component> expectedComponents = expectedField.getComponents();

 

              // If there are components defined on this field...

           if(expectedComponents.size() != 0) {

            Delimiters delimiters = segmentReader.getDelimiters();

                     String[] currentFieldComponents = EDIUtils.split(fieldMessageVal, delimiters.getComponent(), delimiters.getEscape());

 

            assertComponentsOK(expectedField, fieldIndex, segmentCode, expectedComponents, currentFieldComponents);

 

            if (currentFieldComponents.length > 0 || !ignoreEmptyNodes()) {

              startElement(expectedField, true);

                   // Iterate over the field components and map them...

                           for(int i = 0; i < currentFieldComponents.length; i++) {

                                  String componentMessageVal = currentFieldComponents[i];

                                  Component expectedComponent = expectedComponents.get(i);

      

                                  mapComponent(componentMessageVal, expectedComponent, fieldIndex, i, segmentCode, expectedField.getXmltag());

                           }

                      endElement(expectedField, true);

            }

              } else {

            if(expectedField.isRequired() && fieldMessageVal.length() == 0) {

                throw new EDIParseException(edifactModel.getEdimap(), "Segment [" + segmentCode + "], field " + (fieldIndex + 1) + " (" + expectedField.getXmltag() + ") expected to contain a value.  Currently at segment number " + segmentReader.getCurrentSegmentNumber() + ".", expectedField, segmentReader.getCurrentSegmentNumber(), segmentReader.getCurrentSegmentFields());

            }

 

            if (fieldMessageVal.length() > 0 || !ignoreEmptyNodes()) {

                startElement(expectedField, true);

                writeToContentHandler(fieldMessageVal);

                endElement(expectedField, false);

            }

              }

       }

 

Is this a defect?

Thanks,
Julio Vergara



Reply | Threaded
Open this post in threaded view
|

Re: Smooks 1.5.1 EDIParser does not validate require field when defined as components

Julio C. VERGARA-HEINRROTH
In reply to this post by Julio C. VERGARA-HEINRROTH
First of all, thank you for the prompt response. I really appreciate it.

Now. Yes, I'm referring to "composite-medical-procedure-identifier-sv1/product-or-service-id-qualifier". Is this consider a defect?

If so;
  • where do I log it
  • where can I find the branch code for 1.5, so I can fix my local copy

Or, if it has been already fixed in another release, please point it to me.

Thanks,
Julio V.


From: "Tom Fennelly" <[hidden email]>
Sent: Thursday, July 3, 2014 3:13 AM
To: [hidden email]
Subject: Re: [milyn-user] Smooks 1.5.1 EDIParser does not validate require field when defined as components


Hi Julio.

So we're talking about "composite-medical-procedure-identifier-sv1/product-or-service-id-qualifier", right?

It would appear as though the "if(expectedField.isRequired() && fieldMessageVal.length() == 0)" check in the else block is not right.  Instead of checking "fieldMessageVal.length()", it should probably do something like "if(expectedField.isRequired() && ((!expectedField.getComponents().isEmpty() && expectedField.getComponents().get(0).isRequired()) || fieldMessageVal.trim().length() == 0))" i.e. it should check that there are components configured and if the first component is required, then you get an error.  I think that would work in your case.

T.


On 02/07/2014 18:52, Julio C. VERGARA-HEINRROTH wrote:
Given the following edi file content:
SV1*~
I have the following segment definition:
<medi:segment xmltag="professional-service" segcode="SV1" truncatable="true" minOccurs="0" maxOccurs="1">
                <medi:field xmltag="composite-medical-procedure-identifier-sv1" required="true" truncatable="true">
                    <medi:component xmltag="product-or-service-id-qualifier" required="true" minLength="2" maxLength="2"/>
                    <medi:component xmltag="procedure-code-start" required="true" minLength="1" maxLength="48"/>
                    <medi:component xmltag="procedure-modifier-1" required="false" minLength="2" maxLength="2"/>
                    <medi:component xmltag="procedure-modifier-2" required="false" minLength="2" maxLength="2"/>
                    <medi:component xmltag="procedure-modifier-3" required="false" minLength="2" maxLength="2"/>
                    <medi:component xmltag="procedure-modifier-4" required="false" minLength="2" maxLength="2"/>
                    <medi:component xmltag="procedure-code-description" required="false" minLength="1" maxLength="80"/>
                    <medi:component xmltag="procedure-code-end" required="false" minLength="1" maxLength="48"/>
                </medi:field>
                ...<!-- other optional segments -->
</medi:segment>

In the EDIParser, the mapfield method validates the require="true" attribute only if the field has not been defined as a component

private void mapField(String fieldMessageVal, Field expectedField, int fieldIndex, String segmentCode) throws SAXException {

              List<Component> expectedComponents = expectedField.getComponents();

 

              // If there are components defined on this field...

           if(expectedComponents.size() != 0) {

            Delimiters delimiters = segmentReader.getDelimiters();

                     String[] currentFieldComponents = EDIUtils.split(fieldMessageVal, delimiters.getComponent(), delimiters.getEscape());

 

            assertComponentsOK(expectedField, fieldIndex, segmentCode, expectedComponents, currentFieldComponents);

 

            if (currentFieldComponents.length > 0 || !ignoreEmptyNodes()) {

              startElement(expectedField, true);

                   // Iterate over the field components and map them...

                           for(int i = 0; i < currentFieldComponents.length; i++) {

                                  String componentMessageVal = currentFieldComponents[i];

                                  Component expectedComponent = expectedComponents.get(i);

      

                                  mapComponent(componentMessageVal, expectedComponent, fieldIndex, i, segmentCode, expectedField.getXmltag());

                           }

                      endElement(expectedField, true);

            }

              } else {

            if(expectedField.isRequired() && fieldMessageVal.length() == 0) {

                throw new EDIParseException(edifactModel.getEdimap(), "Segment [" + segmentCode + "], field " + (fieldIndex + 1) + " (" + expectedField.getXmltag() + ") expected to contain a value.  Currently at segment number " + segmentReader.getCurrentSegmentNumber() + ".", expectedField, segmentReader.getCurrentSegmentNumber(), segmentReader.getCurrentSegmentFields());

            }

 

            if (fieldMessageVal.length() > 0 || !ignoreEmptyNodes()) {

                startElement(expectedField, true);

                writeToContentHandler(fieldMessageVal);

                endElement(expectedField, false);

            }

              }

       }

 

Is this a defect?

Thanks,
Julio Vergara