Force decimal format in generated Edifact files

168 views
Skip to first unread message

Minitraktor

unread,
Dec 19, 2020, 12:01:49 PM12/19/20
to Smooks Users
Hi!

When I write Edifact order response files the quantities are written with a decimal number, but I would like to have them written as integers. I have tried to make a file myconfig.xml to force this using the below code


 D93AInterchangeFactory factory = D93AInterchangeFactory.getInstance();
 factory.toUNEdifact(edi, ediOutStream1);
 FileWriter write = new FileWriter("outputfile");

 InputStream resourceConfigStream = new FileInputStream("myconfig.xml");
 factory.addConfigurations(resourceConfigStream);

 factory.toUNEdifact(interchange, writer);


My assumption was that the below config would override the ORDRSP.Segment_Group_25.QTY.C186 bean, but it doesn't seem to do so - it has no effect at all.

Could anyone please guide me to what I am doing wrong.
 

<?xml version="1.0"?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
                     
xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.2.xsd"
                     
xmlns:edi="http://www.milyn.org/xsd/smooks/edi-1.2.xsd">

   
<params>
       
<param name="stream.filter.type">SAX</param>
   
</params>


   
<edi:reader mappingModel="/org/milyn/edi/unedifact/d93a/ORDRSP/edimappingconfig.xml" validate="false" />


   
<jb:bean beanId="ORDRSP.Segment_Group_25.QTY.C186" class="org.milyn.edi.unedifact.d93a.common.field.C186QuantityDetails" createOnElement="ORDRSP/Segment_Group_25/QTY/C186">
       
<jb:value property="e6063QuantityQualifier" data="ORDRSP/Segment_Group_25/QTY/C186/e6063" decoder="String" default="null" />
       
<jb:value property="e6060Quantity" data="ORDRSP/Segment_Group_25/QTY/C186/e6060" decoder="DABigDecimal" default="null">
             
<jb:decodeParam name="format">#,###</jb:decodeParam>
        </jb:value>
        
<jb:value property="e6411MeasureUnitQualifier" data="ORDRSP/Segment_Group_25/QTY/C186/e6411" decoder="String" default="null" />
   
</jb:bean>


</smooks-resource-list>

Minitraktor

unread,
Dec 20, 2020, 6:35:13 AM12/20/20
to Smooks Users

Claude

unread,
Dec 21, 2020, 3:43:39 AM12/21/20
to Smooks Users
I''m not sure I follow your code. Why isn't a unedifact:reader used like the one shown here: https://github.com/smooks/unedifact-examples/blob/master/to-xml/smooks-config.xml#L26 ? If this is a new project, might be easier to achieve what you want by upgrading to Smooks 2.0.0-M2.

Claude

Minitraktor

unread,
Dec 21, 2020, 6:58:32 AM12/21/20
to Smooks Users
Hi!

I copied the <edi:reader.... /> part from the file in my Maven Dependencies folder d93a-binding-1.7.1.0.jar\org\milyn\edi\unedifact\d93a\ORDRSP\bindingconfig.xml which I thought maybe was the file that I should override

I have tried changing it to <unedifact:reader..... /> but unfortunately then I get the error message

[Fatal Error] :13:177: The prefix "jb" for element "jb:bean" is not bound.

Sorry for my ignorance here but any help is appreciated. It is an existing project but I am ready to update to Smooks 2.0.0-M2 if necessary

Minitraktor

unread,
Dec 30, 2020, 3:37:45 AM12/30/20
to Smooks Users
Hi!

I know new year celebrations are coming up but please when anyone gets time I would appreciate any assistance with this question. Thanks!

Claude

unread,
Dec 30, 2020, 9:35:12 AM12/30/20
to Smooks Users
Let's return to the first Smooks 1.7 config you posted on this thread. How about changing the decoder from decoder="DABigDecimal" to decoder="Integer"? If this doesn't work, please post a link to a minimal functional project demonstrating the problem. I couldn't reproduce your app's behaviour because of a different unrelated error I'm getting.

Claude

Hashim Khan

unread,
Jan 2, 2021, 3:47:58 PM1/2/21
to smook...@googlegroups.com
Hi! Very strange, changing for DABigDecimal to Integer just doesn't give any effect at all. 

Np I will try making a minimal functional project in some days but please let me know if you have any other idea what the problem could be in the meantime.


--
You received this message because you are subscribed to a topic in the Google Groups "Smooks Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/smooks-user/6nybwaNVgS0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to smooks-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/smooks-user/c5fff270-9b40-4090-a5ef-34ab73c2b92an%40googlegroups.com.

Minitraktor

unread,
Jan 21, 2021, 8:51:57 AM1/21/21
to Smooks Users
I have made a minimal project for this now. It consists of the java class "SimpleTest" and the config file "myconfig.xml". But first, these are the dependencies in pom.xml:

<dependency>
    <groupId>org.milyn</groupId>
    <artifactId>milyn-smooks-javabean</artifactId>
    <version>1.7.1</version>
</dependency>
<dependency>  
<groupId>org.milyn.edi.unedifact</groupId>  
    <artifactId>d93a-binding</artifactId>  
    <version>1.7.1.0</version>  
</dependency>
<dependency>  
<groupId>org.milyn.edi.unedifact</groupId>  
    <artifactId>d93a-mapping</artifactId>  
    <version>1.7.1.0</version>  
</dependency>



This is the class SimpleTest:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.milyn.edi.unedifact.d93a.D93AInterchangeFactory;
import org.milyn.edi.unedifact.d93a.ORDRSP.Ordrsp;
import org.milyn.edi.unedifact.d93a.common.QTYQuantity;
import org.milyn.edi.unedifact.d93a.common.field.C186QuantityDetails;
import org.milyn.smooks.edi.unedifact.model.r41.UNEdifactInterchange41;
import org.milyn.smooks.edi.unedifact.model.r41.UNEdifactMessage41;

public class SimpleTest {

@Test
public void test() throws Exception {

D93AInterchangeFactory factory = D93AInterchangeFactory.getInstance();
InputStream resourceConfigStream = new FileInputStream("myconfig.xml");
factory.addConfigurations(resourceConfigStream);
File outFile = new File("test.edi");
UNEdifactInterchange41 interchange = new UNEdifactInterchange41();
List<UNEdifactMessage41> messages = new ArrayList<UNEdifactMessage41>();
interchange.setMessages(messages);
messages.add(new UNEdifactMessage41());
Ordrsp ordrsp = createOrdrspWithQuantity1();
messages.get(0).setMessage(ordrsp);

FileWriter fw = new FileWriter(outFile.getAbsolutePath());
factory.toUNEdifact(interchange, fw);

}
private Ordrsp createOrdrspWithQuantity1() {
Ordrsp ordrsp = new Ordrsp();
List<org.milyn.edi.unedifact.d93a.ORDRSP.SegmentGroup25> seg25List = new ArrayList<org.milyn.edi.unedifact.d93a.ORDRSP.SegmentGroup25>();
org.milyn.edi.unedifact.d93a.ORDRSP.SegmentGroup25 seg25 = new org.milyn.edi.unedifact.d93a.ORDRSP.SegmentGroup25();
seg25List.add(seg25);
ordrsp.setSegmentGroup25(seg25List);
List<QTYQuantity> quantities = new ArrayList<QTYQuantity>();
seg25.setQTYQuantity(quantities);
QTYQuantity delivQuantity = new QTYQuantity();
C186QuantityDetails delivQuantityDet = new C186QuantityDetails();
delivQuantityDet.setE6060Quantity(new BigDecimal(1));
delivQuantityDet.setE6411MeasureUnitQualifier("PCE");
delivQuantity.setC186QuantityDetails(delivQuantityDet);
quantities.add(delivQuantity);
return ordrsp;
}

This is the myconfig.xml file:

<?xml version="1.0"?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
                      xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.2.xsd"
                      xmlns:edi="http://www.milyn.org/xsd/smooks/edi-1.2.xsd">

    <params>
        <param name="stream.filter.type">SAX</param>
    </params>


    <edi:reader mappingModel="/org/milyn/edi/unedifact/d93a/ORDRSP/edimappingconfig.xml" validate="false" />


    <jb:bean beanId="ORDRSP.Segment_Group_25.QTY.C186" class="org.milyn.edi.unedifact.d93a.common.field.C186QuantityDetails" createOnElement="ORDRSP/Segment_Group_25/QTY/C186">
        <jb:value property="e6060Quantity" data="ORDRSP/Segment_Group_25/QTY/C186/e6060" decoder="Integer" default="null"/>
    </jb:bean>


</smooks-resource-list>


However, despite having written decoder="Integer" for the quantity in the config file, the result (test.edi) is the following:

QTY+:1.0:PCE'

I.e. the quantity is written as 1.0 instead of 1 :(
To unsubscribe from this group and all its topics, send an email to smooks-user+unsubscribe@googlegroups.com.

Minitraktor

unread,
Jan 23, 2021, 4:47:45 AM1/23/21
to Smooks Users
A reminder please about this, if anyone can find an error in this minimal project which prevents the config from being applied:

Minitraktor

unread,
Jan 31, 2021, 9:15:45 AM1/31/21
to Smooks Users
Hi, Just a reminder if anyone sees what is wrong in my minimal project. Let me know if i should commit the project somewhere.

To reiterate what the problem is, it is that the quantities in the output file remain having a decimal point despite me (attempting to) change this in the settings file. 

Thanks!


To unsubscribe from this group and all its topics, send an email to smooks-user...@googlegroups.com.

Minitraktor

unread,
Feb 8, 2021, 6:16:50 PM2/8/21
to Smooks Users
Alternatively if someone knows how to resolve the issue by updating to Smooks 2.0.0-M2. Thanks!

To unsubscribe from this group and all its topics, send an email to smooks-user+unsubscribe@googlegroups.com.

Minitraktor

unread,
Mar 18, 2021, 5:02:30 AM3/18/21
to Smooks Users
I really need to fix this problem. Is there anyone that can help? Claude?

Thanks!

Tom Fennelly

unread,
Mar 18, 2021, 5:16:57 AM3/18/21
to smook...@googlegroups.com
Did you try debugging your app with the smooks source code attached and look to see how the decoder is working?

Create a slimmed down p[roject that reproduces the issue ... debug it and determine why the decoder is not working as expected ... figure out is there a config option that helps ... implement a custom decoder if needs be.

The code is all there, so it should be possible for you to at least get a handle on why the data is not being decoded in the way you want ... dig into the code.

Thanks!
To unsubscribe from this group and all its topics, send an email to smooks-user...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Smooks Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to smooks-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/smooks-user/6f78fe83-a261-4018-a0c3-6c7009c793cbo%40googlegroups.com.

Hashim Khan

unread,
May 14, 2021, 11:14:54 AM5/14/21
to smook...@googlegroups.com
Hi Tom,

I missed your message and thought nobody responded so I gave up on this. But then today I decided to give it another try and then I saw your message, hence the late response.

I have added break points within the "IntegerDecoder" class and run debug mode, but this class is never called. So it seems by config code has just not had any effect and rather the default BigDecimal decoder is used.
 
Could the problem have to do with the files referred to in the smooks-resource-list tag being non-existent ("http://www.milyn.org/xsd/smooks/javabean-1.2.xsd" etc, since the http://www.milyn.org site is down)?

I have tried changing them to the newest smooks.org equivalents but then I get the error messages of the type "org.xml.sax.SAXException: Failed to locate XSD resource '/META-INF/xsd/smooks-1.2.xsd' on classpath" 
 

Claude Mamo

unread,
May 14, 2021, 11:47:19 AM5/14/21
to smook...@googlegroups.com
You should be referencing smooks-2.0.xsd from the config in Smooks 2. Check out the examples.

Claude

Tom Fennelly

unread,
May 17, 2021, 4:02:03 AM5/17/21
to smook...@googlegroups.com
Right, as Claude says ... update to the latest code.

It's been so long since I've been in Smooks code so I don't remember most of the details, but I'm sure if you locate in the code where the Decoders are instantiated/applied and add breakpoints there then you'll see what's happening.

Reply all
Reply to author
Forward
0 new messages