Commits

Robert MacGregor committed 2df18f8

Added import for Project.

Comments (0)

Files changed (5)

grails-app/controllers/ImportController.groovy

 
     def index = {
 
-
-
-        importXMLService.importFromFile("/Users/rob/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/Project.groovy

     String status = "active"
     Date lastChangedOn = new Date()
 
-    Client company
+    //Client company
 
     String announcement = ""
     Boolean showAnnouncement = false
 
 
     static constraints = {
-        name(blank:false)
-        lastChangedOn(nullable:true)
-        company(nullable:false)
+        //name(blank:false)
+        //lastChangedOn(nullable:true)
+        //company(nullable:false)
     }
 
     String toString()

grails-app/services/ImportProjectService.groovy

+import com.koyanainc.bc.Project
+
+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{
+        //log.warn "\nRemoving key $it"
+        projectMap.remove(it)
+      }
+      projectMap.each{k,v->
+      log.warn "\n\tProject entry has k $k = $v"
+      }
+
+
+      def p  = new Project(projectMap)
+      p.id = projectMap.id
+      p.save(flush:true)
+      //log.warn "\n\t Errors ${p.errors}"
+
+    }
+  }
+}

grails-app/services/ImportXMLService.groovy

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

test/unit/ImportProjectServiceTests.groovy

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