Commits

Anonymous committed 9fefaf3

Added Client import.

  • Participants
  • Parent commits 188090b

Comments (0)

Files changed (6)

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

     Boolean deleted = false
     Boolean hasAccessToNewProjects = false
     
-    //static belongsTo = [person:Client]
+    //static belongsTo = [client:Client]
 
     String uuid = ""
 

File grails-app/services/ImportClientService.groovy

+import com.koyanainc.bc.Client
+import com.koyanainc.bc.Person
+
+
+class ImportClientService {
+    boolean transactional = true
+
+    def importXML(clients) {
+    
+    clients.client.each{client->
+
+      def clientMap = XMLUtil.xmlToGorm(client.children())
+      clientMap.remove('people')    //We have to remove the 'people' key and it's associated data - not digestible by GORM
+
+      def c  = new Client(clientMap)
+      c.id = clientMap.id
+      c.save(flush:true)
+
+      client.people.person.each{person->
+        def personMap = XMLUtil.xmlToGorm(person.children())
+
+        def p = new Person(personMap)
+        p.id = personMap.id
+
+        p.save(flush:true)
+        c.addToPeople(p)
+      }
+
+    }
+  }
+}

File grails-app/services/ImportXMLService.groovy

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

File grails-app/utils/XMLUtil.groovy

+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ *
+ * @author rob
+ */
+class XMLUtil {
+  static String xmlToCamel(String xmlString)
+  {
+    def b = xmlString.split("-")
+
+    String r = b[0]
+    b.eachWithIndex{v,i->
+      StringBuffer sb = new StringBuffer(v)
+      if(i!=0){
+        Character c = v[0].toUpperCase()
+        sb.setCharAt(0,c)
+
+        r += sb
+      }
+    }
+    r
+  }
+
+  static Map xmlToGorm(xml)
+  {
+    Map m = [:]
+    xml.each{
+
+      m[XMLUtil.xmlToCamel(it.name())] = it.text()
+    }
+
+    convertIdToLong(m)
+  }
+
+  static Map convertIdToLong(Map m)
+  {
+    if( m.containsKey("id"))
+    {
+      m.id = m.id.toLong()
+    }
+
+    m
+  }
+	
+}
+

File src/groovy/XMLUtil.groovy

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-/**
- *
- * @author rob
- */
-class XMLUtil {
-  static String xmlToCamel(String xmlString)
-  {
-    def b = xmlString.split("-")
-
-    String r = b[0]
-    b.eachWithIndex{v,i->
-      StringBuffer sb = new StringBuffer(v)
-      if(i!=0){
-        Character c = v[0].toUpperCase()
-        sb.setCharAt(0,c)
-
-        r += sb
-      }
-    }
-    r
-  }
-
-  static Map xmlToMap(xml)
-  {
-    Map m = [:]
-    xml.each{
-
-      m[XMLUtil.xmlToCamel(it.name())] = it.text()
-    }
-
-    m
-  }
-	
-}
-

File test/unit/ImportClientServiceTests.groovy

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