Some updates to Berlin MOdel import validation
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / berlinModel / in / validation / BerlinModelCommonNamesImportValidator.java
index 5a497663742e3e4e20dffb7ad17cdab51776b412..b7b21841cbc7f37cac64415b8be7f240aadb286e 100644 (file)
@@ -36,6 +36,7 @@ public class BerlinModelCommonNamesImportValidator implements IOValidator<Berlin
                boolean result = true;\r
                result &= checkUnreferredNameUsedInSource(state.getConfig());\r
                result &= checkUnreferredLanguageRefFk(state.getConfig());\r
+               result &= checkTaxonIsAccepted(state.getConfig());\r
                \r
                return result;\r
        }\r
@@ -132,5 +133,52 @@ public class BerlinModelCommonNamesImportValidator implements IOValidator<Berlin
 \r
        }\r
        \r
+       private static boolean checkTaxonIsAccepted(BerlinModelImportConfigurator config){\r
+               try {\r
+                       boolean result = true;\r
+                       Source source = config.getSource();\r
+                       String strQuery = "SELECT cn.CommonNameId, cn.CommonName, pt.StatusFk, n.FullNameCache, s.Status, pt.PTRefFk, r.RefCache " + \r
+                                               " FROM emCommonName cn " +\r
+                                                       " INNER JOIN PTaxon pt ON cn.PTNameFk = pt.PTNameFk AND cn.PTRefFk = pt.PTRefFk " + \r
+                                       " INNER JOIN Name n ON pt.PTNameFk = n.NameId " +\r
+                                       " INNER JOIN Status s ON pt.StatusFk = s.StatusId " +\r
+                                       " LEFT OUTER JOIN Reference r ON pt.PTRefFk = r.RefId " + \r
+                                               " WHERE (pt.StatusFk NOT IN ( 1, 5))  ";\r
+\r
+                       if (StringUtils.isNotBlank(config.getOccurrenceFilter())){\r
+                               strQuery += String.format(" AND (%s) ", config.getCommonNameFilter()) ; \r
+                       }\r
+\r
+                       \r
+                       ResultSet resulSet = source.getResultSet(strQuery);\r
+                       boolean firstRow = true;\r
+                       while (resulSet.next()){\r
+                               if (firstRow){\r
+                                       System.out.println("========================================================");\r
+                                       System.out.println("There are Common Names for a taxon that is not accepted!");\r
+                                       System.out.println("========================================================");\r
+                               }\r
+                               int commonNameId = resulSet.getInt("CommonNameId");\r
+                               String commonName = resulSet.getString("CommonName");\r
+                               String status = resulSet.getString("Status");\r
+                               String fullNameCache = resulSet.getString("FullNameCache");\r
+                               String ptRefFk = resulSet.getString("PTRefFk");\r
+                               String ptRef = resulSet.getString("RefCache");\r
+                               \r
+                               System.out.println("CommonNameId: " + commonNameId + "\n CommonName: " + commonName + \r
+                                               "\n  Status: " + status + \r
+                                               "\n  FullNameCache: " + fullNameCache +  "\n  ptRefFk: " + ptRefFk +\r
+                                               "\n  sec: " + ptRef );\r
+                               \r
+                               result = firstRow = false;\r
+                       }\r
+                       \r
+                       return result;\r
+               } catch (SQLException e) {\r
+                       e.printStackTrace();\r
+                       return false;\r
+               }\r
+       }\r
+       \r
 \r
 }\r