Source

Texa / grails-app / services / ImportFirmService.groovy

import com.koyanainc.bc.Firm
import com.koyanainc.bc.Person

class ImportFirmService {

  boolean transactional = true

  def importXML(firm) {

    def firmBits = firm.children()

    def firmLeafs = []
    firmBits.each{
      if( it.children().size() == 0)
      {
        firmLeafs << it
      }
    }

    def leafMap = XMLUtil.xmlToGorm(firmLeafs)

    def f = new Firm(leafMap)
    f.id = leafMap.id
    f.save(flush:true)


    def peopleList = []
    if(firm.people.children().size() > 0)
    {
      firm.people.children().each{
        peopleList <<  it
      }
    }
    else
    {
      log.info "Firm has no people"
    }

    peopleList.each{
      def pm = XMLUtil.xmlToGorm(it.children())

      def p = new Person(pm)
      p.id = pm.id
      p.save(flush:true)
      f.addToPeople(p)
    }
  }

 }