Anonymous avatar Anonymous committed 251a884

Added todo list and todoItem.

Comments (0)

Files changed (8)

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

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

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

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

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 = {

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
 

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

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

test/unit/ImportTodoListsServiceTests.groovy

+import grails.test.*
+
+class ImportTodoListsServiceTests extends GrailsUnitTestCase {
+    protected void setUp() {
+        super.setUp()
+    }
+
+    protected void tearDown() {
+        super.tearDown()
+    }
+
+    void testSomething() {
+
+    }
+}
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.