Multiple TDWG areas in Berlin Model occurrence
authorAndreas Müller <a.mueller@bgbm.org>
Mon, 26 Jan 2009 19:26:15 +0000 (19:26 +0000)
committerAndreas Müller <a.mueller@bgbm.org>
Mon, 26 Jan 2009 19:26:15 +0000 (19:26 +0000)
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/BerlinModelOccurrenceIO.java

index ae72157809d8a2053ec2138462bd919adba7d366..38b4f07c40bf2cf928a976cc2e5da729a2051c50 100644 (file)
@@ -5,7 +5,9 @@ package eu.etaxonomy.cdm.io.berlinModel;
 \r
 import java.sql.ResultSet;\r
 import java.sql.SQLException;\r
+import java.util.ArrayList;\r
 import java.util.HashSet;\r
+import java.util.List;\r
 import java.util.Map;\r
 import java.util.Set;\r
 \r
@@ -134,51 +136,60 @@ public class BerlinModelOccurrenceIO  extends BerlinModelIOBase {
                        int countDescriptions = 0;\r
                        int countDistributions = 0;\r
                        //for each reference\r
-                       while (rs.next()){\r
-                               \r
-                               if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("Facts handled: " + (i-1));}\r
-                               \r
-                               int occurrenceId = rs.getInt("OccurrenceId");\r
-                               int newTaxonId = rs.getInt("RIdentifier");\r
-                               String tdwgCode = rs.getString("TDWGCode");\r
-                               Integer emStatusId = (Integer)rs.getObject("emOccurSumCatId");\r
-                               \r
-                               try {\r
-                               \r
-                                       PresenceAbsenceTermBase<?> status = null;\r
-                                       if (emStatusId != null){\r
-                                                       status = BerlinModelTransformer.occStatus2PresenceAbsence(emStatusId);\r
-                                       }\r
-                                       \r
-                                       NamedArea tdwgArea = null;\r
-                                       if (tdwgCode != null){\r
-                                               tdwgArea = TdwgArea.getAreaByTdwgAbbreviation(tdwgCode.trim());\r
-                                       }\r
-                                       \r
-                                       TaxonDescription taxonDescription = getTaxonDescription(newTaxonId, oldTaxonId, oldDescription, taxonMap, occurrenceId);\r
-                                       if (tdwgArea != null){\r
-                                               Distribution distribution = Distribution.NewInstance(tdwgArea, status);\r
-                                               if (taxonDescription != null) {\r
-                                                       taxonDescription.addElement(distribution);\r
-                                                       countDistributions++;\r
-                                                       if (taxonDescription != oldDescription){\r
-                                                               taxonStore.add(taxonDescription.getTaxon());\r
-                                                               oldDescription = taxonDescription;\r
-                                                               countDescriptions++;\r
-                                                       }\r
-                                               } else {\r
-                                                       logger.warn("Distribution " + tdwgArea.toString() + " ignored");\r
-                                               }\r
-                                       }\r
-                               } catch (UnknownCdmTypeException e) {\r
-                                       // TODO Auto-generated catch block\r
-                                       e.printStackTrace();\r
-                               }\r
+            while (rs.next()){\r
+                \r
+                if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("Facts handled: " + (i-1));}\r
+                \r
+                int occurrenceId = rs.getInt("OccurrenceId");\r
+                int newTaxonId = rs.getInt("RIdentifier");\r
+                String tdwgCodeString = rs.getString("TDWGCode");\r
+                Integer emStatusId = (Integer)rs.getObject("emOccurSumCatId");\r
+                \r
+                try {\r
+                    //status\r
+                     PresenceAbsenceTermBase<?> status = null;\r
+                     if (emStatusId != null){\r
+                                 status = BerlinModelTransformer.occStatus2PresenceAbsence(emStatusId);\r
+                     }\r
+                     \r
+                     //Create area list\r
+                     List<NamedArea> tdwgAreas = new ArrayList<NamedArea>();\r
+                     if (tdwgCodeString != null){\r
+                           String[] tdwgCodes = tdwgCodeString.split(";");\r
+                           for (String tdwgCode : tdwgCodes){\r
+                                 NamedArea tdwgArea = TdwgArea.getAreaByTdwgAbbreviation(tdwgCode.trim());\r
+                                 if (tdwgArea != null){\r
+                                       tdwgAreas.add(tdwgArea);\r
+                                 }\r
+                           }\r
+                     }\r
+                     \r
+                     //create description(elements)\r
+                     TaxonDescription taxonDescription = getTaxonDescription(newTaxonId, oldTaxonId, oldDescription, taxonMap, occurrenceId);\r
+                     for (NamedArea tdwgArea : tdwgAreas){\r
+                           Distribution distribution = Distribution.NewInstance(tdwgArea, status);\r
+                           if (taxonDescription != null) { \r
+                               taxonDescription.addElement(distribution); \r
+                               countDistributions++; \r
+                               if (taxonDescription != oldDescription){ \r
+                                       taxonStore.add(taxonDescription.getTaxon()); \r
+                                       oldDescription = taxonDescription; \r
+                                       countDescriptions++; \r
+                               } \r
+                              } else { \r
+                                      logger.warn("Distribution " + tdwgArea.toString() + " ignored"); \r
+                            }\r
+                     }\r
+                } catch (UnknownCdmTypeException e) {\r
+                     // TODO Auto-generated catch block\r
+                     e.printStackTrace();\r
+                }\r
+\r
+//              TODO\r
+//              sources\r
+//              references\r
+            }\r
 \r
-//                             TODO\r
-//                             sources\r
-//                             references\r
-                       }\r
                        logger.info("Distributions: " + countDistributions + ", Descriptions: " + countDescriptions );\r
                        logger.warn("Unmatched occurrences: "  + (i - countDescriptions));\r
                        logger.info("Taxa to save: " + taxonStore.size());\r