Create multiple records and split them using original data


#1

Business case.

  1. We have 1 record at the start

  2. We want to keep original records from start and split it to multiple records

  3. All new records will have original data plus new data.

    <?xml version="1.0" encoding="UTF-8"?>
     <var-def name="multiple_dividends">
     	<template>${multiple_dividends}</template>
     </var-def>
    
     <script><![CDATA[
     
     	List itemsForExport = new ArrayList();
     	List columns = new ArrayList();
    
           List values = hit_submission_data_item.getWrappedObject().getItemValueList();
           int originalListSize = values.size();
                       
           for(int i = 0; i < originalListSize; i++) {             
             com.freedomoss.crowdcontrol.webharvest.HitSubmissionDataItemValueDto dataItem = (com.freedomoss.crowdcontrol.webharvest.HitSubmissionDataItemValueDto) values.get(i);
               String name = dataItem.getName();
    
               columns.add(name);
           }
    
           columns.add("payment_date");
           columns.add("issuer");
           columns.add("record_date");
           columns.add("gross_amount");
           columns.add("stock_type");
           columns.add("currency");
           columns.add("ex_date");
           columns.add("dividend_type");
           columns.add("tax_rate");
           columns.add("frank_rate");
           columns.add("unfranked_amount");
           columns.add("franked_amount");
    
           columns.add("drp_price");
           columns.add("conduit_foreign_income");
           columns.add("election_date");
    
           columns.add("meeting_date");
           columns.add("conditional");
           columns.add("conditional_criteria");
           columns.add("announcement_date");
           columns.add("unfranked_tax_rate");
    
           //columns.add("interest");
           //columns.add("selic_rate");
           //columns.add("conversion_rate");
                              
       ]]>
     </script>
    
     <case>
     	<if condition='${!multiple_dividends.toString().isEmpty() &amp;&amp;multiple_dividends.toString().contains("{") }'>
     		<var-def name="multiple_divdends_json_val">
     			<json-to-xml>
     				<template>${multiple_dividends}</template>
     			</json-to-xml>
     		</var-def>
    
     		<var-def name="results">
     			<xpath expression="//multiple_dividends">
     				<template>&lt;content&gt;${multiple_divdends_json_val}&lt;/content&gt;</template>
     			</xpath>
     		</var-def>
    
     		<loop item="item">
     			<list>
     				<var name="results" />
     			</list>
     			<body>
     				<empty>
    
     					<var-def name="payment_date_value_ret">
     						<xpath expression="//payment_date_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="record_date_value_ret">
     						<xpath expression="//record_date_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="gross_amount_value_ret">
     						<xpath expression="//gross_amount_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="stock_type_value_ret">
     						<xpath expression="//stock_type_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="currency_value_ret">
     						<xpath expression="//currency_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="ex_date_value_ret">
     						<xpath expression="//ex_date_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="dividend_type_value_ret">
     						<xpath expression="//dividend_type_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="meeting_date_value_ret">
     						<xpath expression="//meeting_date_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="tax_rate_value_ret">
     						<xpath expression="//tax_rate_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="conditional_value_ret">
     						<xpath expression="//conditional_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="announcement_date_value_ret">
     						<xpath expression="//announcement_date_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="issuer_value_ret">
     						<xpath expression="//issuer_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="frank_rate_value_ret">
     						<xpath expression="//frank_rate_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="unfranked_amount_value_ret">
     						<xpath expression="//unfranked_amount_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="franked_amount_value_ret">
     						<xpath expression="//franked_amount_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="unfranked_tax_rate_value_ret">
     						<xpath expression="//unfranked_tax_rate_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="election_date_value_ret">
     						<xpath expression="//election_date_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="drp_price_value_ret">
     						<xpath expression="//drp_price_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="conduit_foreign_income_value_ret">
     						<xpath expression="//conduit_foreign_income_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
                         <var-def name="total_dividend_amount_ret">
     						<xpath expression="//total_dividend_amount_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
                         
                         <var-def name="total_dividend_amount_estimated_or_actual_ret">
     						<xpath expression="//total_dividend_amount_estimated_or_actual_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
               
     					<!--<var-def name="interest_value_ret">
     						<xpath expression="//interest_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="selic_rate_value_ret">
     						<xpath expression="//selic_rate_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def>
    
     					<var-def name="conversion_rate_value_ret">
     						<xpath expression="//conversion_rate_value/text()">
     							<var name="item" />
     						</xpath>
     					</var-def> -->           
    
    
     					<script><![CDATA[     
     			
     						Map rec = new HashMap();
     			    	
                             for(int i = 0; i < originalListSize; i++) {             
                             com.freedomoss.crowdcontrol.webharvest.HitSubmissionDataItemValueDto dataItem = (com.freedomoss.crowdcontrol.webharvest.HitSubmissionDataItemValueDto) values.get(i);
    
     				            String name = dataItem.getName();
     				            String value = dataItem.getValue();
     				            rec.put(name, value);
     				        }
    
     			    		rec.put("payment_date", payment_date_value_ret.toString().trim());
     			    		rec.put("record_date", record_date_value_ret.toString().trim());
                             rec.put("gross_amount", gross_amount_value_ret.toString().trim());
                             rec.put("stock_type", stock_type_value_ret.toString().trim().replace("|",""));
                             rec.put("currency", currency_value_ret.toString().trim());
     			    		rec.put("ex_date", ex_date_value_ret.toString().trim());
     			    		rec.put("dividend_type", dividend_type_value_ret.toString().trim());
                             rec.put("tax_rate", tax_rate_value_ret.toString().trim());
                             rec.put("meeting_date", meeting_date_value_ret.toString().trim());
                             if (conditional_value_ret.toString().trim().isEmpty()) { 
                                rec.put("conditional", "No");
                             }
                             else {
                                rec.put("conditional", "Yes");
                             } 
                             rec.put("conditional_criteria", conditional_value_ret.toString().trim());
                             rec.put("issuer", issuer_value_ret.toString().trim());
                             rec.put("frank_rate", frank_rate_value_ret.toString().trim());
                             rec.put("announcement_date", announcement_date_value_ret.toString().trim());
                             rec.put("unfranked_amount", unfranked_amount_value_ret.toString().trim());
                             rec.put("franked_amount", franked_amount_value_ret.toString().trim());
                             rec.put("unfranked_tax_rate", unfranked_tax_rate_value_ret.toString().trim());
                             
                             rec.put("drp_price", drp_price_value_ret.toString().trim());
                             rec.put("conduit_foreign_income", conduit_foreign_income_value_ret.toString().trim());
                             rec.put("election_date", election_date_value_ret.toString().trim());
                             rec.put("total_dividend_amount", total_dividend_amount_ret.toString().trim());
                             rec.put("total_dividend_amount_estimated_or_actual", total_dividend_amount_estimated_or_actual_ret.toString().trim());
    
                             //rec.put("interest", interest_value_ret.toString().trim());
                             //rec.put("selic_rate", selic_rate_value_ret.toString().trim());
                             //rec.put("conversion_rate", conversion_rate_value_ret.toString().trim());
                             
     						itemsForExport.add(rec);
     					
     			    	
           	  ]]></script>
    
     				</empty>
     			</body>
     		</loop>
     	</if>
     </case>
    
     <export include-original-data="false">
     	<multi-column list="${itemsForExport}" split-results="true">
     		<loop item="columnName">
     			<list>
     				<script return="columns" />
     			</list>
     			<body>
     				<put-to-column-getter name="${columnName}" property="${columnName}" />
     			</body>
     		</loop>
     	</multi-column>
     </export>
    

#2

for example we want to split any json list into separate records and process them indipendently.
So the current example shows that approach.