Source

Texa / grails-app / services / ImportProjectService.groovy

Full commit
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 crp = ResponsibleParty.findById(project.company.id.text())
      projectMap.company = crp

      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)

        milestoneMap['responsibleParty'] = rp
        milestoneMap['creator'] = cr

        //Insert company info
        def cId = milestone.company.id
        
        //Add belongsTo relationship to Project
        milestoneMap['project'] = p

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

      }

      //Insert project participants into project
      project.participants.person.each{personId->
        def rp = ResponsibleParty.findById(personId.text())
        p.addToParticipants(rp)
      }

      //Insert project posts and comments into db
      XMLUtil.postXmlToGorm(project)
      /**
      project.posts.post.each{postXml->

        def postMap = XMLUtil.xmlToGorm(postXml.children())
        postMap.remove('comments')
log.error "\n\tpostMap = ${postMap}"
        def rp = ResponsibleParty.findById(postMap.authorId)

        postMap['author'] = rp
        def po = new Post(postMap)

        po.id = postMap.id
        po.save()

        log.error("\n\tpost erorrs:${po.errors}")

        postXml.comments.comment.each{commentXml->

          def commentMap = XMLUtil.xmlToGorm(commentXml.children())
log.error "\n\tComment map = >${commentMap}<"

          def commentAuth = ResponsibleParty.findById(commentMap.authorId)
if(null == commentAuth) log.error "\n\n** Null author for ${commentMap}"

          commentMap['author'] = commentAuth

          def co = new Comment(commentMap)
          co.id = commentMap.id
          co.save()
          log.error("\n\tcomment erorrs:${co.errors}")


          po.addToComments(co)
        }

        po.save()
      }
      **/

    }
  }
}