Source

Texa / grails-app / services / ImportClientService.groovy

import com.koyanainc.bc.ResponsibleParty



class ImportClientService {
    boolean transactional = true

    def importXML(clients) {
    
    clients.client.each{client->

      def clientMap = XMLUtil.xmlToGorm(client.children())
      clientMap.remove('people')    //We have to remove the 'people' key and it's associated data - not digestible by GORM

      clientMap.type = 'Client'
      def c  = new ResponsibleParty(clientMap)
      if(!c.validate())
			{
				println "Cannot create Client using map $clientMap"
				c.errors.allErrors.each{e-> println "Client creation errors: $e"}
			}
      c.id = clientMap.id
      c.save()
      //println "client errors ${c.errors}"

      client.people.person.each{person->
        def personMap = XMLUtil.xmlToGorm(person.children())
        
        personMap.type = "Person"
        def p = new ResponsibleParty(personMap)
        p.id = personMap.id
        p.save()
        c.addToPeople(p)
      }

    }
  }
}