I have to read a huge 5 GB xml file like below using spring batch and divide it into separate xml files for each record in below xml. These xml files will be sent to jms queue as writer. Is there any way in spring batch to read xml and divide it in multiple xmls based on tags. ?
<?xml version="1.0" encoding="UTF-8"?>
<company>
<record refId="1001">
<name>abc</name>
<age>31</age>
<dob>31/8/1982</dob>
<income>200,000</income>
</record>
<record refId="1002">
<name>xyz</name>
<age>30</age>
<dob>26/7/1983</dob>
<income>100,999</income>
</record>
<record refId="1003">
<name>pqr</name>
<age>29</age>
<dob>21/8/1984</dob>
<income>1,000,000</income>
</record>
<record refId="1004">
<name>leeyy</name>
<age>29</age>
<dob>21/3/1984</dob>
<income>80,000.89</income>
</record>
</company>
Based on the description + comments, I see no need to split the file into multiple xml files and then read those xml files to send them as messages to the JMS queue.
You can create a POJO representing a record tag and use a chunk-oriented step with a StaxEventItemReader<Record> and your custom writer.
Related
I need to import customers data with tags into res.partner with an XML when installing a custom module.
"Customers" data is stored in res.partner and "Tags" data is stored in res.partner.category, they have a relationship Many2many through res_partner_res_partner_category_rel.
I'm calling two XML files in the __manifest__.py:
The first one populates successfully res.partner.category:
<?xml version="1.0"?>
<odoo>
<record model="res.partner.category" id="res_partner_category_1">
<field name="name">Heavy metal</field>
<field name="active">1</field>
</record>
</odoo>
The second one inserts the partner data:
<?xml version="1.0"?>
<odoo>
<record model="res.partner" id="res_partner_predata_1">
<field name="name">Iron Maiden</field>
</record>
</odoo>
All I need is to insert this res.partner registry with the "Heavy metal" Tag with the installation of a custom module like this:
This is how it would look:
I will deeply appreciate any help.
I found the answer in the Odoo demo data:
When I created the category Heavy metal I assigned the id res_partner_predata_1, then I only have to add the next line (the one after the comment) to the res_partner registry like this:
<?xml version="1.0"?>
<odoo>
<record model="res.partner" id="res_partner_predata_1">
<field name="name">Iron Maiden</field>
<--! This line will add the category-->
<field eval="[(6, 0, [ref('module_name.res_partner_category_1')])]" name="category_id"/>
</record>
</odoo>
I faced the same question with odoo 14. In my case your solution did not work completely. Instead of:
<field eval="[(6, 0, [ref('module_name.res_partner_category_1')])]" name="category_id"/>
I had to set:
<field name="category_id" eval="[(6,0,[ref('res_partner_category_1')])]"/>
I programmatically got a Job object(instance of SimpleJob class).Then for some reason, I wanna convert this job object to job1.xml(xml-based job definition file). So that I can save the job on my hard disk. Is there any spring batch java api which can achieve this? Something like:
SimpleJob job1 = new SimpleJob("SomeJob");
job1.addSomeStep()... //create the details of the job
SomeConverter(job1, "job1.xml");//then we got the job1.xml on the hard disk.
No Idea why you want to do it that way,there should be some solid reason.
There is an Marshler and Unmarshler available in Spring-Oxm.
Spring oxm is - Spring Object XML Mappers
This module help in the mapping between java objects and XML documents
There is no need to write code over here ,
This is what you can refer exactly -
https://www.mkyong.com/spring3/spring-objectxml-mapping-example/
in the given answer # above link - you can use your SumpleJob object instead of customer - use the SimpleJob as shown below
<batch:job id="SimpleJob">
<batch:step id="step1">
......
</batch:step>
</batch:job>
You also need to create a class for SimpleJob - which will be used in mapping
<mapping>
<class name="com.test.SampleJob">
<map-to xml="sampleJob" />
<!-- and below here you need to mention all the , mapping using fields -->
<field name=".." type="..">
<bind-xml name=".." node=".." />
</field>
</class>
</mapping>
And because it is Mr.mkyoung - the code written on his site will always work :)
I have successfully imported several product templates into Odoo (version 8) and used External IDs for this. Now I want to import product description translations into ir.translation and want to use these External IDs. I guess, I have to put in field "Record ID" a reference to the product template - but this field unfortunately doesn't support External IDs in import screen.
How can I import translations for product templates with external IDs in an elegant way?
If I understood you well (you want to translate the field description of a product.template record which was introduced by XML code in a module you did before), you can try this and tell me if it works:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<record id="whatever_you_want" model="ir.translation">
<field name="name">product.template,description</field>
<field name="type">model</field>
<field name="res_id" ref="the_module_which_introduced_xml_records.the_xml_id_of_the_record_you_want_to_translate"/>
<field name="lang">de_DE</field> <!-- The code of the language you want to translate to -->
<field name="src">Your product template description</field>
<field name="value">Your translation (in this case to German)</field>
</record>
</data>
</openerp>
I am working with wmqfte. While creating a transfer there is a parameter for metadata attribute pair. Why is this used for ?
One of the FTE engagements I worked on required email notifications of transfer status. Our approach to this was to add an email step in the transfer and the way we passed in the source and destination addresses was with metadata pairs. The transfer XML is provided below for an example:
<?xml version="1.0" encoding="UTF-8"?><request version="4.00" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FileTransfer.xsd">
<!DOCTYPE request>
<managedTransfer>
<originator>
<hostName>host.example.com</hostName>
<userID>me</userID>
</originator>
<sourceAgent QMgr="QMGR01" agent="AGENT01"/>
<destinationAgent QMgr="QMGR02" agent="AGENT02"/>
<transferSet priority="5">
<metaDataSet>
<metaData key="email.from">fteadmin#example.com</metaData>
<metaData key="email.to">"dept#example.com</metaData>
</metaDataSet>
<item checksumMethod="MD5" mode="binary">
<source disposition="delete" recursive="false">
<file>/root/path/file</file>
</source>
<destination exist="overwrite" type="directory">
<file>/root/path/</file>
</destination>
</item>
</transferSet>
<job>
<name>Your Job Name Here</name>
</job>
</managedTransfer>
</request>
A better way of sending status emails is to watch the transfer notifications published at the Coordination QMgr. However this example does show one possible use for the metadata pairs.
Can somebody suggest me a template engine (preferably written in Java) that could generate any text that I like from given XML input?
StringTemplate, FreeMarker
How about XSLt? You may use JAXP to do the processing.
You can use XSLT, it is not restricted to generating only XML output. It is restricted to XML input. Use the xsl:output tag do define the type of output you will be generating.
E.g. to generate text output
<xsl:output method="text" encoding="UTF-8"/>
To generate XML output with indentation
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>