Spring Castor Unmarshalling with Mapping - spring

I am trying to unmarshall an XML to Object using Castor OXM Unmarshalling in Spring.
XML:
<LevelA>
<LevelB>
<item name="itemA">value</item>
<item name="itemB">value</item>
<item name="itemC">value</item>
<item name="itemD">value</item>
<item name="itemE">value</item>
</LevelB>
</LevelA>
Object:
Class LevelA {
LevelB objLevelB;
//getter and setter
}
Class LevelB {
List<Items> item = new ArrayList<Items>();
//getter and setter
}
Class Items {
String Name;
String Value;
//getter and setter
}
Castor Mapping:
<mapping>
<class name="LevelA">
<map-to xml="LevelA" />
<field name="objLevelB" type="LevelB">
<bind-xml name="LevelB" />
<class name="LevelB">
<field name="item" type="Items" collection="arraylist">
<bind-xml name="item" node="element" />
<class name="Items">
<field name="Name" type="string">
<bind-xml name="name" node="attribute" />
</field>
<field name="Value" type="string">
<bind-xml node="text" />
</field>
</class>
</field>
</class>
</field>
</class>
</mapping>
I am getting the following error:
org.xml.sax.SAXException: unable to find FieldDescriptor for 'item' in ClassDescriptor of LevelB
I have tried several ways and spent enough time that I need some help from you all now.
Any help would be useful.

Figured out the way myself, here is the mapping that worked for me. I am sharing the answer to help others, in the same situation.
<?xml version="1.0" encoding="UTF-8"?>
<mapping>
<description> Provides Mapping to Convert Document to POJO</description>
<class name="LevelAClass">
<map-to xml="LevelA" />
<field name="objLevelB" type="LevelBClass">
<bind-xml name="LevelB" />
</field>
</class>
<class name="LevelBClass">
<field name="item" type="LevelCClass"
collection="arraylist">
<bind-xml name="item" />
</field>
</class>
<class name="LevelCClass">
<field name="Name">
<bind-xml name="name" node="attribute" />
</field>
<field name="Value">
<bind-xml name="item" node="text" />
</field>
</class>
</mapping>

Related

jpos Gateway : Not able to send back the response message received from the remote host to the client requested

I am new to jpos. trying to use jpos-2_1_3 out of the box. I can see the message forwarded to remote host and response back but the response message is not delivered to the requested client.Getting the below error
[HOST_UNREACHABLE] o.j.t.p.QueryHost.expired:111 'mux.rsc' does not respond
I checked the client status which is connected and waiting for the response
My config files are as below
50_server.xml
<server class="org.jpos.q2.iso.QServer" logger="Q2" name="bnet-server-7003" realm="bnet-server-8000">
<attr name="port" type="java.lang.Integer">6003</attr>
<channel class="org.jpos.iso.channel.NACChannel"
packager="org.jpos.iso.packager.GenericPackager"
type="server"
logger="Q2"
header="6000000000"
>
<property name="packager-config" value="cfg/packager/CISebcdic.xml" debug="True" />
<property name="timeout" value="18000"/>
</channel>
<request-listener class="org.jpos.iso.IncomingListener" logger="Q2" realm="incoming-request-listener">
<property name="space" value="tspace:default" />
<property name="queue" value="RSCTXNMGR" />
<property name="ctx.DESTINATION" value="rsc" />
</request-listener>
</server>
10_channel.xml
<?xml version="1.0" ?>
<channel-adaptor name='rsc-channel' class="org.jpos.q2.iso.ChannelAdaptor" logger="Q2">
<channel class="org.jpos.iso.channel.BCDChannel"
packager="org.jpos.iso.packager.GenericPackager" header="6000000000" logger="Q2" >
<property name="packager-config" value="cfg/packager/CISascii.xml" debug="True" />
<property name="host" value="127.0.0.1" />
<property name="port" value="9000" />
<property name="keep-alive" value="true" />
</channel>
<in>rscbnet-send</in>
<out>rscbnet-receive</out>
<reconnect-delay>10000</reconnect-delay>
</channel-adaptor>
20_mux.xml
<?xml version="1.0" ?>
<mux class="org.jpos.q2.iso.QMUX" logger="Q2" name="rsc">
<in>rscbnet-receive</in>
<out>rscbnet-send</out>
<ready>rsc-channel.ready</ready>
<key>41,11</key>
<unhandled>rsc-channel-unhandled</unhandled>
</mux>
30_txnmgr.xml
<?xml version='1.0'?>
<txnmgr class="org.jpos.transaction.TransactionManager" logger="Q2">
<property name="queue" value="RSCTXNMGR"/>
<property name="sessions" value="10"/>
<property name="max-sessions" value="128"/>
<property name="debug" value="true"/>
<participant class="org.jpos.transaction.participant.QueryHost" logger="Q2"/>
<participant class="org.jpos.transaction.participant.SendResponse" logger="Q2" />
</txnmgr>
in the log i can see message is send to the remote host and response is received
<log realm="channel/127.0.0.1:9000" at="2020-02-22T17:11:39.114">
<send>
<isomsg direction="outgoing">
<!-- org.jpos.iso.packager.GenericPackager[cfg/packager/CISascii.xml] -->
<header>6000000000</header>
<field id="0" value="0400"/>
<field id="2" value="4113550001234586"/>
<field id="3" value="003000"/>
<field id="4" value="000000005000"/>
<field id="7" value="0218135108"/>
<field id="11" value="570164"/>
<field id="12" value="005106"/>
<field id="13" value="0219"/>
<field id="14" value="1906"/>
<field id="18" value="7399"/>
<field id="22" value="812"/>
<field id="32" value="001529"/>
<field id="33" value="004601"/>
<field id="37" value="702011961044"/>
<field id="39" value="00"/>
<field id="41" value="W1Q99999"/>
<field id="42" value="25233065 "/>
<field id="43" value="Apple NZ GCS Sydney AU"/>
<field id="48" value="543432303730313033323130363331355649533237333634353032313920203230303153" type="binary"/>
<field id="49" value="036"/>
<field id="61" value="10251040066000362000"/>
<field id="90" value="010057016402181351080000000152900000004601"/>
</isomsg>
</send>
</log>
<log realm="channel/127.0.0.1:9000" at="2020-02-22T17:11:39.115" lifespan="179071ms">
<receive>
<isomsg direction="incoming">
<!-- org.jpos.iso.packager.GenericPackager[cfg/packager/CISascii.xml] -->
<header>6000000000</header>
<field id="0" value="0410"/>
<field id="2" value="4113550001234586"/>
<field id="3" value="003000"/>
<field id="4" value="000000005000"/>
<field id="7" value="0221223852"/>
<field id="11" value="620156"/>
<field id="12" value="093850"/>
<field id="13" value="0222"/>
<field id="14" value="1906"/>
<field id="18" value="7399"/>
<field id="22" value="812"/>
<field id="32" value="001529"/>
<field id="33" value="004601"/>
<field id="37" value="702011079220"/>
<field id="39" value="00"/>
<field id="41" value="W1Q99999"/>
<field id="42" value="25233065 "/>
<field id="43" value="Apple NZ GCS Sydney AU"/>
<field id="48" value="543432303730313033323130363331353030303030303030303030303020203230303153" type="binary"/>
<field id="49" value="036"/>
<field id="61" value="10251040066000362000"/>
<field id="90" value="010062015602212238520000000152900000004601"/>
</isomsg>
</receive>
</log>
<log realm="org.jpos.transaction.TransactionManager" at="2020-02-22T17:12:09.115" lifespan="30001ms">
<abort>
txnmgr-9:idle:2
<context>
TIMESTAMP: Sat Feb 22 17:11:39 AEDT 2020
SOURCE: org.jpos.iso.channel.NACChannel#795c411
REQUEST:
<isomsg direction="outgoing">
<!-- org.jpos.iso.packager.GenericPackager[cfg/packager/CISascii.xml] -->
<header>6000000000</header>
<field id="0" value="0400"/>
<field id="2" value="4113550001234586"/>
<field id="3" value="003000"/>
<field id="4" value="000000005000"/>
<field id="7" value="0218135108"/>
<field id="11" value="570164"/>
<field id="12" value="005106"/>
<field id="13" value="0219"/>
<field id="14" value="1906"/>
<field id="18" value="7399"/>
<field id="22" value="812"/>
<field id="32" value="001529"/>
<field id="33" value="004601"/>
<field id="37" value="702011961044"/>
<field id="39" value="00"/>
<field id="41" value="W1Q99999"/>
<field id="42" value="25233065 "/>
<field id="43" value="Apple NZ GCS Sydney AU"/>
<field id="48" value="543432303730313033323130363331355649533237333634353032313920203230303153" type="binary"/>
<field id="49" value="036"/>
<field id="61" value="10251040066000362000"/>
<field id="90" value="010057016402181351080000000152900000004601"/>
</isomsg>
DESTINATION: rsc
**RESULT:
<result>
<fail>
[HOST_UNREACHABLE] o.j.t.p.QueryHost.expired:111 'mux.rsc' does not respond
</fail>
</result>**
:paused_transaction:
id: 2
</context>
prepare: o.j.t.p.QueryHost PREPARED PAUSE READONLY NO_JOIN
prepare: o.j.t.p.SendResponse ABORTED READONLY NO_JOIN
in-transit=0, head=3, tail=3, paused=0, outstanding=0, active-sessions=10/128, tps=0, peak=1, avg=0.00, elapsed=30001ms
<profiler>
prepare: o.j.t.p.QueryHost [0.3/0.3]
resume [30000.5/30000.8]
prepare: o.j.t.p.SendResponse [0.1/30001.0]
end [1.1/30002.2]
</profiler>
</abort>
</log>
<log realm="Q2.system" at="2020-02-22T17:12:43.242">
it will be great if i get some help to solve this issue.thanks in advance.
To summarize in an answer what was explained in comments, problem was field 11 not being matched by response. Because of that the mux didn't know that the incoming message was a response for the request.
You can see default fields used to match responses to requests by QMUX, and learn how to configure a different set of keys in jPOS programmers guide section 8.3.2

Solr dataimport jdbc multiple columns into one field

I am trying to implement a solr search for a project. Everything was fine so far, a first simple version worked. Now I try to import from a postgres data base where multiple columns should end up in the same field. My config:
<entity name="address" query="SELECT objectid, ags2, ags3, ags5, ags8, ags11, ags20, ags22, pt, stn, hnr_min, hnr_max, plz, ort, ortz, ot1, ot2 FROM variablen2018.ags22_tmp_solr LIMIT 10000;">
<field column="objectid" name="id" />
<field column="plz" name="plz" />
<field column="ort" name="ort" />
<field column="ortz" name="ort" />
<field column="ot1" name="ort" />
<field column="ot2" name="ort" />
<field column="ort" name="ort_res" />
<field column="stn" name="stn" />
<field column="stn" name="stn_res" />
<field column="ags2" name="ags2" />
<field column="ags3" name="ags3" />
<field column="ags5" name="ags5" />
<field column="ags8" name="ags8" />
<field column="ags11" name="ags11" />
<field column="ags20" name="ags20" />
<field column="ags22" name="ags22" />
<field column="pt" name="coord" />
<field column="hnr_min" name="hnr_min" />
<field column="hnr_max" name="hnr_max" />
</entity>
As you can see there are 4 columns from the DB (ort, ortz, ot1, ot2) going into one field (ort). Most of the times only one of the columns is populated at all, in which case the document is indexed normally. But when there are actually multiple entries the indexing of the document fails. The field is defined this way:
<field name="ort" type="text_de" uninvertible="true" indexed="true" required="true" stored="true"/>
DataImporthandler maps the result view of the query to a schema view and hence I don't think that you will be able to map multiple columns to one field. Instead you can assign each column to a new Solr field and then do a copy of them in your schema.
eg
<field name="ort" type="string" />
<field name="ortz" type="string" />
<field name="ot1" type="string" />
<field name="ot2" type="string" />
<field name="ortCombined" type="string" multiValued="true"/>
<copyField source="ort" dest="ortCombined" />
<copyField source="ortz" dest="ortCombined" />
<copyField source="ot1" dest="ortCombined" />
<copyField source="ot2" dest="ortCombined" />
Hope this helps !
you do it this way:
you concatenate all values into a single value in the Select:
select ...,ort||','||ortz||','||or1||','||ort2 AS ort_all FROM variablen2018.ags22_tmp_solr
and then split it into individual values when indexing into solr (this is done with RegexTransformer/splitBy)
< entity name="address" transformer="RegexTransformer"
...
< field column="ort_all" name="ort" splitBy=","/>
Note: inserted a space after < or the text does not show up here...
To watch out:
handle possible nulls, check concat_ws etc
handle possible , inside ort values (use another separator or replace , etc)

Sonata Project: Can't access media that referenced to SonataPage

I have a Page entity, that has many-to-one association to Media entity from Sonata MediaBundle
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity
name="Application\Sonata\PageBundle\Entity\Page"
table="page__page"
>
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>
<field name="shortContent" type="text" column="short_content" nullable="true" />
<many-to-one field="media" target-entity="Application\Sonata\MediaBundle\Entity\Media">
<join-column name="media_id" />
</many-to-one>
<lifecycle-callbacks>
<lifecycle-callback type="postPersist" method="postPersist"/>
</lifecycle-callbacks>
</entity>
</doctrine-mapping>
When I'm logged as admin - all is right and I can access media in twig with {{ page.getMedia() }}
But, if I open this page in Incognito window, the media of the page will be
null
Any one have any ideas ?
I found a solution for this case.
If we are not logged in as admin we see a snapshot of some page, and when we add a new field into Page entity, snapshot creator didn't know nothing about this field, so we need to extend Sonata\PageBundle\Model\Transformer model
Page.orm.xml
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity
name="Application\Sonata\PageBundle\Entity\Page"
table="page__page"
>
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>
<field name="shortContent" type="text" column="short_content" nullable="true" />
<many-to-one field="media" target-entity="Application\Sonata\MediaBundle\Entity\Media">
<join-column name="media_id" />
</many-to-one>
<lifecycle-callbacks>
<lifecycle-callback type="postPersist" method="postPersist"/>
</lifecycle-callbacks>
</entity>
</doctrine-mapping>
Snapshot.orm.xml
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
xsi="http://www.w3.org/2001/XMLSchema-instance"
schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity
name="Application\Sonata\PageBundle\Entity\Snapshot"
table="page__snapshot"
>
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>
<many-to-one field="media" target-entity="Application\Sonata\MediaBundle\Entity\Media">
<join-column name="media_id" />
</many-to-one>
<gedmo:loggable log-entry-class="Gedmo\Loggable\Entity\LogEntry"/>
</entity>
</doctrine-mapping>
And page to snapshot transformer class
PageTransformer.php
<?php
namespace Application\Sonata\PageBundle\Entity;
use Sonata\PageBundle\Entity\Transformer;
use Sonata\PageBundle\Model\PageInterface;
use Sonata\PageBundle\Model\SnapshotInterface;
class PageTransformer extends Transformer
{
public function create(PageInterface $page)
{
/** #var Snapshot $snapshot */
$snapshot = parent::create($page);
$content = $snapshot->getContent();
$snapshot->setContent($content);
$snapshot->setMedia($page->getMedia());
return $snapshot;
}
public function load(SnapshotInterface $snapshot)
{
$page = parent::load($snapshot);
$page->setMedia($snapshot->getMedia());
return $page;
}
}
Almost forget!!! We need to say Sonata to use our Transformer class
parameters.yml
parameters:
sonata.page.transformer.class: Application\Sonata\PageBundle\Entity\PageTransformer

Spring Batch Integration with BeanIO

I am trying to integrate BeanIO with spring batch. Using BeanIO I am reading a fixed length stream file. I have tested and verified the code to read the flat file using a standalone class and it works seamlessly but when I tried to integrate it with Spring Batch the doRead() method of BeanIOFlatFileItemReader is not getting invoked and some how directly the RedemptionEventCustomProcessor written by me is getting invoked.
I get below stacktrace on console.:
:::::::::::::In Processor::::::::::::::::
Exit Status : FAILED job Id 0 [java.lang.NullPointerException]
Done
Please find the dependencies used below:
spring-batch-core version 2.1.9.RELEASE
spring-batch-infrastructure 2.1.9.RELEASE
beanio-2.1.0.M2
Please find below the resources files as mentioned below:
earn-api-batch - spring batch xml file
earn-api-batch-context - spring batch context xml file
earn-api-mapping.xml - BeanIO mapping xml file
earn-api-batch.xml:
<import resource="classpath:earn-api-batch-context.xml" />
<batch:job id="processEventJob">
<batch:step id="step">
<batch:tasklet>
<batch:chunk reader="RedemptionFileReader" writer="RedemptionEventCustomWriter" processor="RedemptionEventCustomProcessor" commit-interval="1"></batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="RedemptionFileReader" class="org.beanio.spring.BeanIOFlatFileItemReader">
<property name="streamMapping" value="classpath:/earn-api-mapping.xml" />
<property name="streamName" value="redemptionFile" />
<property name="resource" value="classpath:/RedemptionTest" />
</bean>
<bean id="RedemptionEventCustomWriter" class="org.beanio.spring.BeanIOFlatFileItemWriter">
<property name="streamMapping" value="classpath:/earn-api-mapping.xml" />
<property name="streamName" value="redemptionFile" />
<property name="resource" value="file:Redemption.txt" />
</bean>
earn-api-batch-context:
<context:component-scan base-package="com.aexp.earn.api.batch" />
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.SimpleJobRepository">
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapJobInstanceDao"/>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapJobExecutionDao" />
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapStepExecutionDao"/>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapExecutionContextDao"/>
</constructor-arg>
</bean>
<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
earn-api-mapping.xml:
<beanio xmlns="http://www.beanio.org/2012/03"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.beanio.org/2012/03 http://www.beanio.org /2012/03/mapping.xsd">
<stream name="redemptionFile" format="fixedlength">
<!-- 'class' binds the header record to a java.util.HashMap -->
<record name="header" class="map">
<!-- 'rid' indicates this field is used to identify the record -->
<field name="recordType" length="1" rid="true" literal="1" />
<field name="fileSeqNo" length="10" padding=" " justify="right" />
<!-- 'format' can be used to provide Date and Number formats -->
<field name="fileDate" length="8" type="date" format="yyyyMMdd" />
</record>
<record name="nar" class="com.aexp.earn.api.batch.vo.NonAirline">
<field name="recordType" length="1" ignore="true" />
<field name="redeemType" rid="true" literal="1" length="1" />
<field name="mmNo" length="10" />
<field name="cmNo" length="19" padding=" " justify="right" />
<field name="rewardProgCode" length="2" padding="0" justify="right" />
<field name="certNo" length="10"/>
<field name="certFaceValue" length="13" padding=" " justify="right" />
<field name="redeemTimeStamp" length="26" />
<field name="statusCode" length="2" />
<field name="statusTimeStamp" length="26" />
<field name="rewardCode" length="4" />
<field name="rewardSubCode" length="4" />
<field name="transId" length="15" />
<field name="transSrcId" length="3" />
<field name="narRequestId" length="14" />
<field name="narRequestLnId" length="5" padding=" " justify="right" />
</record>
<record name="ar" class="com.aexp.earn.api.batch.vo.Airline">
<field name="recordType" length="1" ignore="true" />
<field name="redeemType" rid="true" literal="2" length="1" />
<field name="partnerTransferType" length="1" />
<field name="mmNo" length="10" />
<field name="cmNo" length="19" padding=" " justify="right" />
<field name="rewardProgCode" length="2" />
<field name="frequentFlyerNo" length="15" />
<field name="partnerCode" length="2"/>
<field name="redeemTimeStamp" length="26" />
<field name="transferedMiles" length="12" padding=" " justify="right" />
<field name="transferedStatus" length="1" />
<field name="statusTimeStamp" length="26" />
<field name="originSourceCode" length="3" />
<field name="transId" length="15" />
<field name="transSrcId" length="3" />
<field name="arRequestId" length="14" />
<field name="arRequestLnId" length="5" padding=" " justify="right" />
</record>
<record name="pwp" class="com.aexp.earn.api.batch.vo.PWP">
<field name="recordType" length="1" ignore="true" />
<field name="redeemType" rid="true" literal="3" length="1" />
<field name="mmNo" length="10" />
<field name="cmNo" length="19" padding=" " justify="right" />
<field name="rewardProgCode" length="2" />
<field name="redeemTimeStamp" length="26" />
<field name="adjustMiles" length="12" />
<field name="adjustCD" length="4" />
<field name="transId" length="15" />
<field name="transSrcId" length="3" />
<field name="pwpRequestId" length="14" padding=" " justify="right" />
<field name="pwpRequestLnId" length="5" />
</record>
<record name="pap" class="com.aexp.earn.api.batch.vo.PAP">
<field name="recordType" length="1" ignore="true" />
<field name="redeemType" rid="true" literal="4" length="1" />
<field name="mmNo" length="10" />
<field name="cmNo" length="19" padding=" " justify="right" />
<field name="rewardProgCode" length="2" />
<field name="redeemTimeStamp" length="26" />
<field name="chnlPtnrId" length="5" />
<field name="orderId" length="32" />
<field name="partnerReserId" length="32" />
<field name="confirmId" length="16" padding=" " justify="right" />
<field name="actPtCnt" length="12" />
<field name="rewdActTypeCd" length="3" />
<field name="seqNo" length="5" />
</record>
<!-- 'target' binds the trailer record to the Integer record count field -->
<record name="trailer" target="recordCount">
<!-- 'literal' is used to define constant values -->
<field name="recordType" rid="true" literal="9" length="2" />
<!-- 'type' can be declared where bean introspection is not possible -->
<field name="recordCount" length="7" type="int" />
</record>
</stream>
</beanio>
Find below the classes:
Main class:
public class EventStart {
#SuppressWarnings("resource")
public static void main(String[] args) {
String[] springConfig =
{
"earn-api-batch.xml"
};
ClassPathXmlApplicationContext appContext = null;
appContext = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) appContext.getBean("jobLauncher");
Job job = (Job) appContext.getBean("processEventJob");
try {
JobExecution execution = jobLauncher.run(job, new JobParameters());
System.out.println("Exit Status : " + execution.getStatus() + " job Id " + execution.getJobId() + " " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
}
Reader Class:
#Component(value = "RedemptionFileReader")
#Scope("step")
public class RedemptionFileReader extends BeanIOFlatFileItemReader<Map<String,Object>>{
/* #Value("#{batchProps['redemption.server.file.path']}")
private Resource resource;*/
Map<String,Object> map = new HashMap<String,Object>();
/*#Override
public String read() throws Exception, UnexpectedInputException,
ParseException, NonTransientResourceException {
System.out.println("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
// TODO Auto-generated method stub
return null;
}*/
#Override
public Map<String,Object> doRead() throws Exception, UnexpectedInputException,
ParseException, NonTransientResourceException {
System.out.println("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH");
/*if (null != recordsCount) {
return null;
}*/
map = identifyRecord();
return map;
}
private Map<String,Object> identifyRecord() throws FileNotFoundException {
Map<String,Object> map=new HashMap<String,Object>();
ArrayList<NonAirline> narList = new ArrayList<NonAirline>();
ArrayList<Airline> arList = new ArrayList<Airline>();
ArrayList<PWP> pwpList = new ArrayList<PWP>();
ArrayList<PAP> papList = new ArrayList<PAP>();
// create a StreamFactory
StreamFactory factory = StreamFactory.newInstance();
// load the mapping file
factory.load("src/main/resources/earn-api-mapping.xml");
// use a StreamFactory to create a BeanReader
BeanReader in = factory.createReader("redemptionFile", new File("src/main/resources/RedemptionTest"));
Object record = null;
String recordCount = "";
while ((record = in.read()) != null) {
if ("header".equals(in.getRecordName())) {
//Map<String,Object> header = (Map<String,Object>) record;
//System.out.println(header.get("fileDate"));
System.out.println("Header");
}
else if ("nar".equals(in.getRecordName())) {
NonAirline nar = (NonAirline) record;
System.out.println("NAR Redeem Type: " + nar.getRedeemType());
System.out.println("NAR MM No.: " + nar.getMmNo());
System.out.println("NAR CM No.: " + nar.getCmNo());
narList.add(nar);
}
else if ("ar".equals(in.getRecordName())) {
Airline ar = (Airline) record;
System.out.println("AR Redeem Type: " + ar.getRedeemType());
System.out.println("AR MM No.: " + ar.getMmNo());
System.out.println("AR CM No.: " + ar.getCmNo());
arList.add(ar);
}
else if ("pwp".equals(in.getRecordName())) {
PWP pwp = (PWP) record;
System.out.println("PWP Redeem Type: " + pwp.getRedeemType());
System.out.println("PWP MM No.: " + pwp.getMmNo());
System.out.println("PWP CM No.: " + pwp.getCmNo());
pwpList.add(pwp);
}
else if ("pap".equals(in.getRecordName())) {
PAP pap = (PAP) record;
System.out.println("PAP Redeem Type: " + pap.getRedeemType());
System.out.println("PAP MM No.: " + pap.getMmNo());
System.out.println("PAP CM No.: " + pap.getCmNo());
papList.add(pap);
}
else if ("trailer".equals(in.getRecordName())) {
recordCount = (String) record;
System.out.println("Trailer");
System.out.println(recordCount + " contacts processed");
}
}
map.put("NAR", narList);
map.put("AR", arList);
map.put("PWP", pwpList);
map.put("PAP", papList);
in.close();
return map;
}
}
Processor Class:
#Component(value = "RedemptionEventCustomProcessor")
public class RedemptionEventCustomProcessor implements ItemProcessor<Map<String,Object>, Map<String,Object>> {
ArrayList<NonAirline> narList = new ArrayList<NonAirline>();
ArrayList<Airline> arList = new ArrayList<Airline>();
ArrayList<PWP> pwpList = new ArrayList<PWP>();
ArrayList<PAP> papList = new ArrayList<PAP>();
#SuppressWarnings("unchecked")
#Override
public Map<String,Object> process(Map<String,Object> map) throws Exception {
System.out.println(":::::::::::::In Processor::::::::::::::::");
narList = (ArrayList<NonAirline>) map.get("NAR");
for(int i=0; i <= narList.size(); i++)
{
NonAirline nar = narList.get(i);
System.out.println("CM No. " + nar.getCmNo());
}
return map;
}
}
Please let me know if any other information is required. Any help will be really appreciated, please consider I am new to both BeanIO and spring as well.
If anyone could share a working example of BeanIO using Spring Batch that should also help.
Thank You in advance.
I too am using beanio with spring batch. The error you are getting is perhaps for the version issue. Here is my xsd config from job xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:batch="http://www.springframework.org/schema/batch" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

How to configure Doctrine entities to handle compressed blobs in the database?

I'm using Doctrine 2 as an ORM to the database and i'm having an issue with compressed blobs.
I'm storing text in a compressed blob column in the database. How can i specify this in the entity mapping xml config? I'm currently using type="blob" for this column but this isn't returning a string. I could use type="text" but this returns garbage as it's not uncompressing it.
Can i specify somewhere in my entity config that this text need uncompressing on retrieval and compressing on persisting?
Here's my entity configuration:
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="AccountNote" table="tblAccountNote">
<id name="intAccountNoteId" type="integer">
<generator strategy="AUTO" />
</id>
<field name="intAccountId" type="integer" nullable="false" unique="no" />
<field name="bolHiddenNote" type="boolean" nullable="false" unique="no" />
<field name="binNote" type="blob" nullable="false" unique="no" />
<field name="strHash" type="string" length="32" nullable="true" unique="no" />
<field name="dtmCreated" type="datetime" nullable="false" unique="no" />
<field name="stmTimestamp" type="datetime" nullable="false" unique="no" />
<many-to-one field="objAccount" target-entity="Account" inversed-by="objNotes">
<join-column name="intAccountId" referenced-column-name="intAccountId" />
</many-to-one>
</entity>
</doctrine-mapping>
In the end we decided on handling the compression in the getter and setter and removing it from the schema.

Resources