1. Robert MacGregor
  2. Texa

Source

Texa / grails-app / services / ImportProjectService.groovy

import com.koyanainc.bc.*

class ImportProjectService {

  boolean transactional = true

  def importXML(projects) {

    projects.project.each{project->

      def projectMap = XMLUtil.xmlToGorm(project.children())

      //These keys are indigestible by GORM as-is
      "todoLists,attachmentCategories,company,timeEntries,posts,postCategories,milestones,participants".split(',').each{
        projectMap.remove(it)
      }

      def p  = new Project(projectMap)
      p.id = projectMap.id
      p.save(flush:true)

      project.milestones.milestone.each{milestone->

        def milestoneMap = XMLUtil.xmlToGorm(milestone.children())

        milestoneMap.remove('comments')

        def co = "Undefined Completer"
        if(milestoneMap.containsKey('completerId'))
        {
          co = ResponsibleParty.findById(milestoneMap.completerId)
          milestoneMap['completer'] = co
        }

        def rp = ResponsibleParty.findById(milestoneMap.responsiblePartyId)
        def cr = ResponsibleParty.findById(milestoneMap.creatorId)
        log.info "\n\n\t Rp is $rp, completer is $co, creator is $cr"
        milestoneMap['responsibleParty'] = rp
        milestoneMap['creator'] = cr
        milestoneMap['project'] = p

        log.warn "\n\n\t Milestone is ${milestoneMap}"

        def m = new Milestone(milestoneMap)
        m.id = milestoneMap.id
        m.save()

        log.warn "Milestone creation errors ${m.errors}"
      }

    }
  }
}