Groovy web console

subscribe to the feed Subscribe
to this
site

Batach_map

Published 2 weeks ago by guwe with tags Products
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.util.Node;
import groovy.xml.XmlUtil;

 def batchNode = new Node(null, 'batchParts')
   def bcspSet = new Node(batchNode, 'batchChangeSet')
   def bcsp = new Node(bcspSet, 'batchChangeSetPart')
   new Node(bcsp, 'method', 'POST')
   def prodSet = new Node(bcsp, 'Products')
   def prod = new Node(prodSet, 'Product')

    
   def mapProdAttr = ['summary':'Sanitas123','externalId':'Sanitas123','internalDescription':'Test','code':'Sanitas123' ] 
   def catalogVersion = [catalogVersion : [CatalogVersion : [version:'Staged',catalog:[Catalog:[id:'swisslifeProductCatalog']]]]]
   def supercategories = [supercategories: [Category: [code: 'SwisslifeSelectProductPyramid', catalogVersion :[CatalogVersion: [version: 'Staged'] ] ] ]] 
   mapProdAttr.putAll(catalogVersion) 
   mapProdAttr.putAll(supercategories)

   def createDeep(parendNode, root) {
      root.each{  
        if ( it.value instanceof Map) {
            def parNode = new Node(parendNode, "$it.key" )
            createDeep(parNode , it.value) 
        }else {
        //   println("$it.key: $it.value") 
           new Node(parendNode, "$it.key" , "$it.value")
        }
      }
    }
    
    createDeep(prod, mapProdAttr )

    println(XmlUtil.serialize(batchNode)
)