Commits

Anonymous committed 251a884

Added todo list and todoItem.

  • Participants
  • Parent commits 1b6e8bd

Comments (0)

Files changed (8)

File grails-app/controllers/ImportController.groovy

 
     def index = {
 
-      importXMLService.importFromFile("/Users/rmacgreg/Dropbox/Projects/basecamp/db/xml/koyanainc-20090716141017.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")
 
     }

File grails-app/domain/com/koyanainc/bc/Comment.groovy

     Person author
     String body = "No comment!"
 
-    Date createdAt = new Date()
+    Date createdAt
     String emailedFrom = ""
 
     CommentableType objectOfComment

File grails-app/domain/com/koyanainc/bc/Post.groovy

     Person author
     String body = ""
 
-    Category category
+    //Category category
     Integer commentsCount = 0
     String extendedBody = ""
 
     Milestone milestone
-    Date postedOn = new Date()
+    Date postedOn
     Project project
 
     String title

File grails-app/domain/com/koyanainc/bc/TodoItem.groovy

     String content
     Integer listPosition = 0
 
-    Date createdOn = new Date()
+    Date createdOn
+    Date completedOn
+
     //Integer creator
     Person creator
+    Person completer
+    ResponsibleParty responsibleParty
 
     Boolean completed = false
     Integer commentsCount = 0
 
-    Person responsibleParty
-
-    Date completedOn
-    //Integer completerId
-    Person completer
-
     static belongsTo = [todoList:TodoList]
 
     static constraints = {

File grails-app/domain/com/koyanainc/bc/TodoList.groovy

     Integer uncompletedCount = 0
 
     String description = ""
-    Milestone milestone
+    //Milestone milestone
 
     String name
     Integer position = 0
-    static belongsTo = [project:Project]
+    static belongsTo = [project:Project, milestone:Milestone]
 
     Boolean tracked = false
 

File grails-app/services/ImportTodoListsService.groovy

+import com.koyanainc.bc.*
+
+class ImportTodoListsService {
+
+  boolean transactional = true
+
+  def importXML(projects) {
+
+    projects.project.each{project->
+
+      project.'todo-lists'.'todo-list'.each{todoListXml->
+
+        def todoListMap = XMLUtil.xmlToGorm(todoListXml.children())
+
+        todoListMap.remove('todoItems')
+
+        def p = Project.findById(todoListXml.'project-id'.text())
+        if( null == p )
+        {
+          log.warn "\n\tFailed to locate project with id ${todoListXml.'project-id'.text()}"
+        }
+        todoListMap['project'] = p
+
+        def tl = new TodoList(todoListMap)
+        if( null == tl )
+        {
+          log.warn "\n\tFailed to create todoList using map: ${todoListMap}.\nGot errors: ${tl.errors}"
+        }
+        tl.id = todoListMap.id
+        tl.save()
+
+        //Add our todoList to it's parent project'
+        p.addToTodoLists(tl)
+
+        //Add todoList items to our todoList
+        todoListXml.'todo-items'.'todo-item'.each{todoItemXml->
+
+          def todoItemMap = XMLUtil.xmlToGorm(todoItemXml.children())
+
+          todoItemMap.remove('comments')
+
+          def co = "Undefined Completer"
+          if(todoItemMap.containsKey('completerId'))
+          {
+            co = ResponsibleParty.findById(todoItemMap.completerId)
+            todoItemMap['completer'] = co
+          }
+//log.warn "\n\ntodoItemMap is ${todoItemMap}"
+
+          def rp = "Undefined responsible party"
+          if( todoItemMap.containsKey('responsiblePartyId'))
+          {
+            rp = ResponsibleParty.findById(todoItemMap.responsiblePartyId)
+            todoItemMap['responsibleParty'] = rp
+          }
+
+          def cr = ResponsibleParty.findById(todoItemMap.creatorId)
+          todoItemMap['creator'] = cr
+
+          todoItemMap['todoList'] = tl
+
+          def ti = new TodoItem(todoItemMap)
+          if( null == ti )
+          {
+           log.warn "\n\tFailed to create todoItem using map: ${todoItemMap}.\nGot errors: ${ti.errors}"
+          }
+          ti.id = todoItemMap.id
+          ti.save()
+
+        }
+
+      }
+    }
+  }
+}

File grails-app/services/ImportXMLService.groovy

     def importFirmService
     def importClientService
     def importProjectService
+    def importTodoListsService
 
     def importFromFile(String pathAndFilename) {
 
         def accountXML = XML.parse(new FileInputStream(pathAndFilename), "UTF-8")
 
+    
         importFirmService.importXML(accountXML.firm)
         importClientService.importXML(accountXML.clients)
         importProjectService.importXML(accountXML.projects)
+    
+        importTodoListsService.importXML(accountXML.projects)
 
     }
 }

File test/unit/ImportTodoListsServiceTests.groovy

+import grails.test.*
+
+class ImportTodoListsServiceTests extends GrailsUnitTestCase {
+    protected void setUp() {
+        super.setUp()
+    }
+
+    protected void tearDown() {
+        super.tearDown()
+    }
+
+    void testSomething() {
+
+    }
+}