Robert MacGregor avatar Robert MacGregor committed a909584

Added TimeEntry and it's import service. Added 'integer' handling to utils for TimeEntries with null-valued TodoItems.

Comments (0)

Files changed (10)

grails-app/controllers/ImportController.groovy

 
     def index = {
 
-                           
-       importXMLService.importFromFile("/Users/rmacgreg/Dropbox/Projects/basecamp/db/xml/koyanainc-20090716141017.xml")
+			//def importFile = "/Users/rob/Dropbox/Projects/basecamp/db/xml/rapportinc-20090721001012.xml"
+      def importFile = "/Users/rob/Dropbox/Projects/basecamp/db/xml/koyanainc-20090716141017.xml"
 
+       //importXMLService.importFromFile("/Users/rmacgreg/Dropbox/Projects/basecamp/db/xml/koyanainc-20090716141017.xml")
+       //importXMLService.importFromFile("/Users/rmacgreg/Dropbox/Projects/basecamp/db/xml/rapportinc-20090721001012.xml")
 
-      //importXMLService.importFromFile("/Users/rob/Dropbox/Projects/basecamp/db/xml/koyanainc-20090716141017.xml")
-      //importXMLService.importFromFile("/Users/rob/Dropbox/Projects/basecamp/db/xml/rapportinc-20090721001012.xml")
+
+      //importXMLService.importFromFile()
+			log.warn "Importing from:$importFile"
+      importXMLService.importFromFile(importFile)
 
     }
 }

grails-app/domain/com/koyanainc/bc/Milestone.groovy

   
   static constraints = {
     title(blank:false)
-    completedOn(nullable:true)
+
+		//completeadOn(nullable:true)
+		deadline(nullable:true)
+		completedOn(nullable:true)
+		
+    completer(nullable:true)
     creator(nullable:false)
+    responsibleParty(nullable:true)
 
     //deadline(nullable:false)
     project(nullable:false)
-    completer(nullable:true)
-    //responsibleParty(nullable:true)
+
 
   }
     

grails-app/domain/com/koyanainc/bc/ResponsibleParty.groovy

 **/
     static mapping = {
         id generator: 'assigned'
-        tablePerHierarchy false
+        //tablePerHierarchy false
     }
 
 }

grails-app/domain/com/koyanainc/bc/TimeEntry.groovy

+package com.koyanainc.bc
+
+class TimeEntry {
+   
+   Date date
+   String description
+   Float hours
+   
+   Person person
+   Project project
+   TodoItem todoItem
+   
+   static constraints = {
+			person(nullable:true)
+			project(nullable:true)
+      todoItem(nullable:true)
+   }
+   
+   static mapping = {
+       id generator: 'assigned'
+   }
+}

grails-app/services/ImportClientService.groovy

       def c  = new Client(clientMap)
       if(!c.validate()) println "Cannot create Client using map $clientMap"
       c.id = clientMap.id
-      c.save(flush:true)
+      c.save()
       //println "client errors ${c.errors}"
 
       client.people.person.each{person->
 
         def p = new Person(personMap)
         p.id = personMap.id
-        p.save(flush:true)
+        p.save()
         c.addToPeople(p)
       }
 

grails-app/services/ImportFirmService.groovy

 
     def f = new Firm(leafMap)
     f.id = leafMap.id
-    f.save(flush:true)
+    f.save()
 
 
     def peopleList = []
 
       def p = new Person(pm)
       p.id = pm.id
-      p.save(flush:true)
+      p.save()
       f.addToPeople(p)
     }
   }

grails-app/services/ImportProjectService.groovy

       }
 
       def crp = ResponsibleParty.findById(project.company.id.text())
-      projectMap.company = crp
+      projectMap.responsibleParty = crp
 
       def p  = new Project(projectMap)
       p.id = projectMap.id
-      p.save(flush:true)
+      p.save()
 
       project.milestones.milestone.each{milestone->
 
         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)
+				if( !m.validate() ) { m.errors.allErrors.each{e-> println "Failed creating Milestone with map ${milestoneMap}. Error:$e"} }
         m.id = milestoneMap.id
-        m.save()
+        m.save() 
 
       }
 
 
       //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()
-      }
-      **/
 
     }
   }

grails-app/services/ImportTimeEntryService.groovy

+import com.koyanainc.bc.*
+
+class ImportTimeEntryService {
+
+  boolean transactional = true
+
+  def importXML(projects) {
+
+     projects.project.each{project->
+
+       project.'time-entries'.'time-entry'.each{timeEntryXml->
+          
+          def timeEntryMap = XMLUtil.xmlToGorm(timeEntryXml.children())
+      
+          //Person
+          def pe = Person.findById(timeEntryMap['personId'])
+          if( null == pe )
+          {
+            log.warn "\n\tFailed to locate person with id ${timeEntryMap['personId']}"
+          }
+          timeEntryMap['person'] = pe
+
+
+          //Project
+          def pr = Project.findById(timeEntryMap['projectId'])
+          if( null == pr )
+          {
+            log.warn "\n\tFailed to locate project with id ${timeEntryMap['projectId']}"
+          }
+          timeEntryMap['project'] = pr
+          
+          
+          //TodoItem
+          def tdi = 'Undefined TimeEntry'
+          if( null == timeEntryMap['todoItemId'] )
+          {
+            tdi = null
+          }
+          else
+          {
+            tdi = TodoItem.findById(timeEntryMap['todoItemId'])
+            if( null == tdi )
+            {
+              log.warn "\n\tFailed to locate TodoItem with id ${timeEntryMap['todoItemId']}"
+            }
+          }
+          timeEntryMap['todoItem'] = tdi
+          
+          def te = new TimeEntry(timeEntryMap)
+          te.id = timeEntryMap.id
+          if( !te.save() )
+          {
+            log.warn "\n\tFailed to create TimeEntry using map: ${timeEntryMap}.\nGot errors: ${te.errors}"
+          }
+       }
+    }
+   }
+ }

grails-app/services/ImportXMLService.groovy

     def importFirmService
     def importClientService
     def importProjectService
+    
     def importTodoListsService
+    def importTimeEntryService
 
     def importFromFile(String pathAndFilename) {
 
        def accountXML = XML.parse(new FileInputStream(pathAndFilename), "UTF-8")
 
+       def ts = new Date(); println "Start at $ts"
+       
        log.info "Importing Firm";      importFirmService.importXML(accountXML.firm)
        log.info "Importing Clients";   importClientService.importXML(accountXML.clients)
        log.info "Importing Projects";  importProjectService.importXML(accountXML.projects)
+
        log.info "Importing TodoLists"; importTodoListsService.importXML(accountXML.projects)
+       log.info "Importing TimeEntry"; importTimeEntryService.importXML(accountXML.projects)
 
+       def te = new Date(); println "End at $te"
     }
 }

grails-app/utils/XMLUtil.groovy

       {
         m[xmlToCamel(it.name())] = convertDateToDateObject(it.text())
       }
+			else if( it.attributes().type == 'integer')
+			{
+				if( java.lang.String == it.text().getClass() && 0 == it.text().length())
+				{
+					m[xmlToCamel(it.name())] = null
+				}
+				else
+				{
+					m[xmlToCamel(it.name())] = it.text().toInteger()
+				}
+				
+			}
       else
       {
          m[xmlToCamel(it.name())] = it.text()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.