Groovy web console

subscribe to the feed Subscribe
to this
site
test (via #groovywebconsole)
tweet this snippet Tweet
this
script

test

Published 10 months ago by test with tags test
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.util.XmlParser

@Grab( 'com.xlson.groovycsv:groovycsv:1.0' )
import com.xlson.groovycsv.CsvParser
class Test {
	static main(args) {
  def csvFilePath = "./src/resources/9999.csv";
  def csvBody = '''UID,country,firstname,baseStore,contactID,customerID,sessionLanguage,title,objType,addressUsage,lastname
prince.khanna13@gmail.ci,DE,Raj,electronics,1001,1001,en,mr,KNA1,DE,Shreyas
''';
  Test test = new Test();
  test.processData(csvBody);
	}
	
	
	def processData(String csvBody){
  def customerIDoc ='''<?xml version="1.0" encoding="UTF-8"?>
<CRMXIF_PARTNER_SAVE_M01>
   <IDOC BEGIN="1">
      <EDI_DC40 SEGMENT="1">
         <TABNAM>EDI_DC40</TABNAM>
         <MANDT>000</MANDT>
         <DOCNUM>1459247631108</DOCNUM>
         <STATUS>03</STATUS>
         <DIRECT>1</DIRECT>
         <OUTMOD>2</OUTMOD>
         <IDOCTYP>CRMXIF_PARTNER_SAVE_M01</IDOCTYP>
         <MESTYP>CRMXIF_PARTNER_SAVE_M</MESTYP>
         <SNDPOR>DHUB_PORT</SNDPOR>
         <SNDPRT>LS</SNDPRT>
         <SNDPRN>XIF_SYSTEM</SNDPRN>
         <RCVPOR>QD3CLNT601</RCVPOR>
         <RCVPRT>LS</RCVPRT>
         <RCVPRN>QD3CLNT601</RCVPRN>
         <CREDAT>20160329</CREDAT>
         <CRETIM>160902</CRETIM>
      </EDI_DC40>
      <E101CRMXIF_PARTNER_COMPLEX SEGMENT="1">
         <E101CRMXIF_PARTNER_HEADER SEGMENT="1">
            <OBJECT>BusinessPartner</OBJECT>
            <OBJECT_TASK>C</OBJECT_TASK>
            <E101CRMXIF_PARTNER_KEYS SEGMENT="1">
               <PARTNER_NO>0000490001</PARTNER_NO>
               <PARTNER_GUID>B0DCD3561B8C48A5A0FEEAE8A9D919D5</PARTNER_GUID>
            </E101CRMXIF_PARTNER_KEYS>
         </E101CRMXIF_PARTNER_HEADER>
         <E101BUS_EI_CENTRAL_DATA SEGMENT="1">
            <E101BUS_EI_BUPA_CENTRAL SEGMENT="1">
               <E101US_EI_BUPA_CENTRAL_DATA SEGMENT="1">
                  <E101US_EI_BUPA_CENTRAL_MAIN SEGMENT="1">
                     <CATEGORY>1</CATEGORY>
                     <GROUPING>0010</GROUPING>
                  </E101US_EI_BUPA_CENTRAL_MAIN>
                  <E101BUS_EI_STRUC_CENTRAL SEGMENT="1">
                     <PARTNERLANGUAGE />
                     <PARTNERLANGUAGEISO>EN</PARTNERLANGUAGEISO>
                     <TITLE_KEY>mr</TITLE_KEY>
                  </E101BUS_EI_STRUC_CENTRAL>
                  <E101EI_STRUC_CENTRAL_PERSON SEGMENT="1">
                     <FIRSTNAME>a</FIRSTNAME>
                     <LASTNAME>a</LASTNAME>
                     <CORRESPONDLANGUAGE />
                     <CORRESPONDLANGUAGEISO>EN</CORRESPONDLANGUAGEISO>
                  </E101EI_STRUC_CENTRAL_PERSON>
               </E101US_EI_BUPA_CENTRAL_DATA>
            </E101BUS_EI_BUPA_CENTRAL>
            <E101BUS_EI_ROLES SEGMENT="1">
               <E101BUS_EI_BUPA_ROLES SEGMENT="1">
                  <DATA_KEY>CRM006</DATA_KEY>
               </E101BUS_EI_BUPA_ROLES>
               <E101BUS_EI_BUPA_ROLES SEGMENT="1">
                  <DATA_KEY>CRM000</DATA_KEY>
               </E101BUS_EI_BUPA_ROLES>
            </E101BUS_EI_ROLES>
            <E101BUS_EI_ADDRESS SEGMENT="1">
               <CURRENT_STATE>X</CURRENT_STATE>
               <E101BUS_EI_BUPA_ADDRESS SEGMENT="1">
                  <TASK>I</TASK>
                  <E101BUS_EI_BUPA_ADDRESS_KEY SEGMENT="1" />
                  <E101US_EI_BUPA_ADDRESS_DATA SEGMENT="1">
                     <E101_EI_BUPA_POSTAL_ADDRESS SEGMENT="1">
                        <E101BUS_EI_STRUC_ADDRESS SEGMENT="1">
                           <STANDARDADDRESS>X</STANDARDADDRESS>
                           <COUNTRYISO>DE</COUNTRYISO>
                           <MOVE_DATE>00000000</MOVE_DATE>
                           <VALIDTODATE>99991231</VALIDTODATE>
                           <CHCKSTATUS>D</CHCKSTATUS>
                        </E101BUS_EI_STRUC_ADDRESS>
                     </E101_EI_BUPA_POSTAL_ADDRESS>
                     <E102BUS_EI_COMMUNICATION SEGMENT="1">
                        <TIME_DEPENDENT>X</TIME_DEPENDENT>
                        <E102BUS_EI_TEL_DATA SEGMENT="1">
                           <CURRENT_STATE>X</CURRENT_STATE>
                           <E102BUS_EI_BUPA_TELEPHONE SEGMENT="1">
                              <CURRENTLY_VALID>X</CURRENTLY_VALID>
                              <E102S_EI_BUPA_TELEPHONE_CON SEGMENT="1">
                                 <TASK>I</TASK>
                                 <E102BUS_EI_STRUC_TEL_DATA SEGMENT="1">
                                    <COUNTRYISO>DE</COUNTRYISO>
                                 </E102BUS_EI_STRUC_TEL_DATA>
                              </E102S_EI_BUPA_TELEPHONE_CON>
                           </E102BUS_EI_BUPA_TELEPHONE>
                        </E102BUS_EI_TEL_DATA>
                        <E102BUS_EI_SMTP_DATA SEGMENT="1">
                           <CURRENT_STATE>X</CURRENT_STATE>
                           <E102BUS_EI_BUPA_SMTP SEGMENT="1">
                              <CURRENTLY_VALID>X</CURRENTLY_VALID>
                              <E102BUS_EI_BUPA_SMTP_CON SEGMENT="1">
                                 <TASK>I</TASK>
                                 <E102BUS_EI_STRUC_SMTP_DATA SEGMENT="1">
                                    <E_MAIL>a1@a.com</E_MAIL>
                                    <EMAIL_SRCH>a1@a.com</EMAIL_SRCH>
                                    <VALID_TO>99991231</VALID_TO>
                                 </E102BUS_EI_STRUC_SMTP_DATA>
                              </E102BUS_EI_BUPA_SMTP_CON>
                           </E102BUS_EI_BUPA_SMTP>
                        </E102BUS_EI_SMTP_DATA>
                     </E102BUS_EI_COMMUNICATION>
                  </E101US_EI_BUPA_ADDRESS_DATA>
               </E101BUS_EI_BUPA_ADDRESS>
            </E101BUS_EI_ADDRESS>
         </E101BUS_EI_CENTRAL_DATA>
      </E101CRMXIF_PARTNER_COMPLEX>
   </IDOC>
</CRMXIF_PARTNER_SAVE_M01>''';
	
    def rootNode = new XmlParser().parseText(customerIDoc);
    def csvData = new CsvParser().parseCsv(csvBody);
    def firstname;
    def lastname;
    def country;
    def uid;
    def counter=0;
    csvData.toList().each {
      line -> /*firstname = line.firstname; lastname = line.lastname;
      uid = line.UID;
      country = line.country;
      ++counter;*/
      println "Value:-> "+line.firstname;
     };
   
    println "FirstName:"+firstname+" lastName:"+lastname+" UID:"+uid+" country:"+country+" counter:"+counter;
    rootNode.IDOC.E101CRMXIF_PARTNER_COMPLEX.E101BUS_EI_CENTRAL_DATA.E101BUS_EI_BUPA_CENTRAL.E101US_EI_BUPA_CENTRAL_DATA.E101EI_STRUC_CENTRAL_PERSON.FIRSTNAME[0].value=firstname;
    rootNode.IDOC.E101CRMXIF_PARTNER_COMPLEX.E101BUS_EI_CENTRAL_DATA.E101BUS_EI_BUPA_CENTRAL.E101US_EI_BUPA_CENTRAL_DATA.E101EI_STRUC_CENTRAL_PERSON.LASTNAME[0].value=lastname;
    rootNode.IDOC.E101CRMXIF_PARTNER_COMPLEX.E101BUS_EI_CENTRAL_DATA.E101BUS_EI_ADDRESS.E101BUS_EI_BUPA_ADDRESS.E101US_EI_BUPA_ADDRESS_DATA.E101_EI_BUPA_POSTAL_ADDRESS.E101BUS_EI_STRUC_ADDRESS.COUNTRYISO[0].value=country;
    
    //println("Root node name :"+rootNode.name());
    println("MODIFIED XML : \n"+ customerIDoc);
    //new XmlNodePrinter(new PrintWriter(new FileWriter(xmlFile))).print(rootNode);
    println("The File is updated");
   
  
	}
}