Question

I am writing a route using camel and smooks, with the producer as a JPA repository that produces a List of JPA Objects, which I need to send to an sftp server as a fixed width file.

Here is what I think is required for this to occur

  1. The repository which uses JPA to produce a list of Objects (I have this)
  2. A smooks to flatpack mapping which takes the xml version of the list mentioned above, and transforms it into a fixed width file
  3. A camel route which starts with the repository and ends with the file being send via sftp:

Here is the code I have for this:

public class RetirementRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {

        onException(Throwable.class)
                .maximumRedeliveries(3)
                .useExponentialBackOff()
                .backOffMultiplier(4)
                .logRetryAttempted(true)
                .handled(true)
                .log(LoggingLevel.ERROR, "Error transmitting file to miliman")
                .to("log:org.fuwt?level=ERROR&showAll=true");

        //define the fixed width mapping
        FlatpackDataFormat df = new FlatpackDataFormat();
        df.setDefinition(new ClassPathResource("META-INF/smooks/fuintegration/retirement-fixed-width-mapping.xml"));
        df.setFixed(true);
        df.setIgnoreFirstRecord(false);

        from("bean:retirementRepository?method=getRetirementMembers")
                .to("log:org.fuwt?level=INFO")
                .transacted("CRM_PROPAGATION_REQUIRED")
                .routeId("retirement_member_exchange")
                .aggregate(property("CamelCreatedTimestamp"), new RetirementAggregationStrategy()).completionFromBatchConsumer()
                .marshal(df).log("log:org.fuwt?level=ERROR&showAll=true")
                .to("file://Users/smohamed/tests/?fileName=marshal.test.txt");
    }
}

However, when I run a unit test, I get the following error:

ArrayList cannot be converted to RetirementMember

which I think means that flatpack doesn't know what to do with the list, and needs to work on an object per object basis.

Hence, what I'm looking for is a smooks mapping similar to freemaker template, but instead of a freemaker template, I want to use flatpack's columns definitions:

<?xml version='1.0'?>  
<!DOCTYPE PZMAP SYSTEM "flatpack.dtd" >  
<PZMAP>  
    <COLUMN name="ssn" length="11" />  
    <COLUMN name="lastName" length="20" />  
    <COLUMN name="firstName" length="15" />  
</PZMAP>

What is the best way to go about this? There isn't much documentation available and I've been searching for weeks

thanks

Sam

Was it helpful?

Solution

It turns out that the Flatpack Data Format requires not a java ArrayList object, but rather a List> object, where the Map contains each column's definition name in the ZMAP-XML mapping file, and the object which it stands for, so the field firstname for example would be in the map as map.put("firstname","Sam").

I found this out by downloading the apache camel source code, and looking at the unit tests for Flatpack, after which I was able to get my route to work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top