(no commit message)
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / faunaEuropaea / FaunaEuropaeaTransformer.java
index 5ec1945abddbb3f23cc5fb93abadd8ed36dabe05..a4b059434de429422209471240518994f39d6bf2 100644 (file)
@@ -18,6 +18,7 @@ import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;\r
 \r
 import eu.etaxonomy.cdm.common.ResultWrapper;\r
+import eu.etaxonomy.cdm.model.description.AbsenceTerm;\r
 import eu.etaxonomy.cdm.model.description.Feature;\r
 import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;\r
 import eu.etaxonomy.cdm.model.description.PresenceTerm;\r
@@ -38,10 +39,20 @@ import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
 public final class FaunaEuropaeaTransformer {\r
        private static final Logger logger = Logger.getLogger(FaunaEuropaeaTransformer.class);\r
        \r
-       //TaxonStatus\r
+       // Query\r
+       public static final int Q_NO_RESTRICTION = -1;\r
+       \r
+       // TaxonStatus\r
        public static final int T_STATUS_ACCEPTED = 1;\r
        public static final int T_STATUS_NOT_ACCEPTED = 0;\r
        \r
+       // Author\r
+       public static final int A_AUCT = 1;\r
+       public static final String A_AUCTNAME = "auct.";\r
+       \r
+       // Parenthesis\r
+       public static final int P_PARENTHESIS = 1;\r
+       \r
        // Rank\r
        public static final int R_KINGDOM = 1;\r
        public static final int R_SUBKINGDOM = 2;\r
@@ -68,7 +79,19 @@ public final class FaunaEuropaeaTransformer {
        \r
        private static Map<String, String> tdwgAreas = null;\r
 \r
-       public static PresenceAbsenceTermBase<?> occStatus2PresenceAbsence (int occStatusId)  throws UnknownCdmTypeException{\r
+       public static PresenceAbsenceTermBase<?> occStatus2PresenceAbsence(int occStatusId)  throws UnknownCdmTypeException{\r
+               switch (occStatusId){\r
+                       case 0: return AbsenceTerm.ABSENT();\r
+                       case 2: return PresenceTerm.INTRODUCED();\r
+                       case 1: return PresenceTerm.NATIVE();\r
+                       default: {\r
+                               throw new UnknownCdmTypeException("Unknown presence status (id=" + Integer.valueOf(occStatusId).toString() + ")");\r
+                       }\r
+               }\r
+       }\r
+\r
+       \r
+       public static PresenceAbsenceTermBase<?> occStatus2PresenceAbsence_ (int occStatusId)  throws UnknownCdmTypeException{\r
                switch (occStatusId){\r
                        case 0: return null;\r
                        case 110: return PresenceTerm.CULTIVATED_REPORTED_IN_ERROR();\r
@@ -158,17 +181,18 @@ public final class FaunaEuropaeaTransformer {
        }\r
        \r
        \r
-       public static NamedArea areaId2TdwgArea (ResultSet rs) throws UnknownCdmTypeException {\r
+       public static NamedArea areaId2TdwgArea (FaunaEuropaeaDistribution fauEuDistribution) \r
+       throws UnknownCdmTypeException {\r
                \r
                NamedArea tdwgArea = null;\r
                \r
                try {\r
-                       int areaId = rs.getInt("ara_id");\r
-                       String areaName = rs.getString("ara_name");\r
-                       String areaCode = rs.getString("ara_code");\r
-                       int extraLimital = rs.getInt("ara_extralimital");\r
+                       int areaId = fauEuDistribution.getAreaId();\r
+                       String areaName = fauEuDistribution.getAreaName();\r
+                       String areaCode = fauEuDistribution.getAreaCode();\r
+                       int extraLimital = fauEuDistribution.getExtraLimital();\r
                        \r
-                       //TODO: Verify mappings with comments. Are those the best matches?\r
+                       //TODO: Verify mappings with comments. Those don't map to TDWG areas.\r
                        \r
                        if (areaCode.equals("AD")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("SPA-AN");\r
                        else if (areaCode.equals("AFR")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("24"); // Afro-tropical region - Northeast Tropical Africa\r
@@ -186,7 +210,7 @@ public final class FaunaEuropaeaTransformer {
                        else if (areaCode.equals("DK-DEN")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("DEN-OO");\r
                        else if (areaCode.equals("DK-FOR")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("FOR-OO");\r
                        else if (areaCode.equals("EE")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("BLT-ES");\r
-                       else if (areaCode.equals("EPA")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("Palaearctic");\r
+                       else if (areaCode.equals("EPA")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("3");   // Palaearctic - Asia-Temperate\r
                        else if (areaCode.equals("ES-BAL")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("BLT-ES");\r
                        else if (areaCode.equals("ES-CNY")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("CNY-OO");\r
                        else if (areaCode.equals("ES-SPA")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("SPA-SP");\r
@@ -217,13 +241,13 @@ public final class FaunaEuropaeaTransformer {
                        else if (areaCode.equals("MD")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("UKR-MO");\r
                        else if (areaCode.equals("MK")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("YUG-MA");\r
                        else if (areaCode.equals("MT")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("SIC-MA");\r
-                       else if (areaCode.equals("NAF")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("20"); // North Africa - Northern Africa\r
+                       else if (areaCode.equals("NAF")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("20");   // North Africa - Northern Africa\r
                        else if (areaCode.equals("NEA")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("7");    // Nearctic region - Northern America\r
-                       else if (areaCode.equals("NEO")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("8"); // Neotropical region - Southern America\r
+                       else if (areaCode.equals("NEO")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("8");    // Neotropical region - Southern America\r
                        else if (areaCode.equals("NL")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("NET-OO");\r
                        else if (areaCode.equals("NO-NOR")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("NOR-OO");\r
                        else if (areaCode.equals("NO-SVA")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("SVA-OO");\r
-                       else if (areaCode.equals("NRE")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("34"); // Near East - Western Asia\r
+                       else if (areaCode.equals("NRE")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("34");   // Near East - Western Asia\r
                        else if (areaCode.equals("ORR")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("35");   // Oriental region - Arabian Peninsula\r
                        else if (areaCode.equals("PL")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("POL-OO");\r
                        else if (areaCode.equals("PT-AZO")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("AZO-OO");\r
@@ -241,7 +265,7 @@ public final class FaunaEuropaeaTransformer {
                        else if (areaCode.equals("RU-RUW")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("RUW-OO");\r
                        else if (areaCode.equals("SE")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("SWE-OO");\r
                        else if (areaCode.equals("SI")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("YUG-SL");\r
-                       else if (areaCode.equals("SK")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("CZE-SL");\r
+                       else if (areaCode.equals("SK")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("CZE-SK");\r
                        else if (areaCode.equals("SM")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("ITA-SM");\r
                        else if (areaCode.equals("TR-TUE")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("TUE-OO");\r
                        else if (areaCode.equals("UA")) tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("UKR-UK");\r
@@ -250,12 +274,11 @@ public final class FaunaEuropaeaTransformer {
                        else                                    \r
                                throw new UnknownCdmTypeException("Unknown Area " + areaCode);\r
 \r
-                               \r
                        if (logger.isDebugEnabled()) {\r
                                logger.debug(areaId + ", " + areaName + ", " + areaCode + ", " + extraLimital);\r
                        }\r
                        \r
-               } catch (SQLException e) {\r
+               } catch (Exception e) {\r
                        e.printStackTrace();\r
                        logger.warn("Exception occurred. Area could not be mapped.");\r
                        return null;\r