Source

Texa / grails-app / services / ImportProjectService.groovy

Full commit
Robert MacGregor 0a8ea43 
Robert MacGregor 2df18f8 


Robert MacGregor 0a8ea43 
Robert MacGregor 2df18f8 
Robert MacGregor 0a8ea43 
Robert MacGregor 2df18f8 









Robert MacGregor 1b6e8bd 



Robert MacGregor 2df18f8 



Robert MacGregor 0a8ea43 














Robert MacGregor 1b6e8bd 
Robert MacGregor 0a8ea43 



Robert MacGregor 1b6e8bd 

Robert MacGregor 0a8ea43 




Robert MacGregor 1b6e8bd 





Robert MacGregor 0a8ea43 

rob 4d57638 





































Robert MacGregor 2df18f8 

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())
      if(null == crp ) log.warn "\n\n\t Company id:${project.company.id.text()} cannot be found in db"
      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
        milestoneMap['project'] = p

        //Insert company info
        def cId = milestone.company.id

        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
      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()
      }

    }
  }
}