better use of generics in service layer and persistence list methods
[cdmlib-apps.git] / app-import / src / main / java / eu / etaxonomy / cdm / app / vibrant / DwcaScratchpadImportActivator.java
index acf015ffd5164cbf4d8722d75a721afb66d87981..b21616f7167f4302de4c99a23b5304995eb7eee2 100644 (file)
@@ -9,6 +9,7 @@
 \r
 package eu.etaxonomy.cdm.app.vibrant;\r
 \r
+import java.io.File;\r
 import java.net.URI;\r
 import java.util.UUID;\r
 \r
@@ -37,18 +38,23 @@ public class DwcaScratchpadImportActivator {
        private static final Logger logger = Logger.getLogger(DwcaScratchpadImportActivator.class);\r
        \r
        //database validation status (create, update, validate ...)\r
-       static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;\r
+       static DbSchemaValidation hbm2dll = DbSchemaValidation.UPDATE;//UPDATE;//CREATE;//UPDATE;\r
 \r
        //      static final URI source =  dwca_emonocots_dioscoreaceae();\r
-       static final URI source =  dwca_emonocots_zingiberaceae();\r
-//     static final URI source =  dwca_emonocots_cypripedioideae();\r
+//     static final URI source =  dwca_emonocots_zingiberaceae();\r
+       //static final URI source =  dwca_emonocots_cypripedioideae();\r
+       static final URI source =  null;//dwca_antkey();//dwca_emonocots_dioscoreaceae();\r
+       \r
        \r
 //     static final ICdmDataSource cdmDestination = CdmDestinations.localH2();\r
        static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();\r
 //     static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();\r
        \r
        //default nom code is ICZN as it allows adding publication year \r
-       static final NomenclaturalCode defaultNomCode = NomenclaturalCode.ICBN;\r
+       static final NomenclaturalCode defaultNomCode = NomenclaturalCode.ICNAFP;\r
+       \r
+       //classification Name\r
+       static String classificationName = "Default classification";\r
 \r
        //title\r
        static final String title = "Scratchpad test import";\r
@@ -106,7 +112,10 @@ public class DwcaScratchpadImportActivator {
                config.setGuessNomenclaturalReferences(guessNomRef);\r
                config.setHandleAllRefsAsCitation(handleAllRefsAsCitation);\r
                config.setUseSourceReferenceAsSec(useSourceReferenceAsSec);\r
-               config.setSourceReferenceTitle(title);\r
+               config.setSourceReferenceTitle(classificationName);//title);\r
+               config.setClassificationName(classificationName);\r
+               \r
+               config.setUseSourceReferenceAsSec(true);//Lorna: what shall we use as sec reference for Scratchpads data?\r
                \r
                CdmDefaultImport myImport = new CdmDefaultImport();\r
 \r
@@ -136,7 +145,15 @@ public class DwcaScratchpadImportActivator {
        \r
        //emonocots_dioscoreaceae\r
        public static URI dwca_emonocots_dioscoreaceae() {\r
-               URI sourceUrl = URI.create("file:////PESIIMPORT3/vibrant/dwca/dwca_emonocots_dioscoreaceae.zip");\r
+               //URI sourceUrl = URI.create("file:////PESIIMPORT3/vibrant/dwca/dwca_emonocots_dioscoreaceae.zip");//dwca_dioscoreaceae_e_monocot.zip\r
+               URI sourceUrl = URI.create("file:///C:/Users/l.morris/Downloads/dwca_scratchpads/dwca_dioscoreaceae_e_monocot_org.zip");\r
+               return sourceUrl;\r
+       }\r
+       \r
+       //dwca_antkey_org.zip\r
+       public static URI dwca_antkey() {\r
+               //URI sourceUrl = URI.create("file:////PESIIMPORT3/vibrant/dwca/dwca_emonocots_dioscoreaceae.zip");//dwca_dioscoreaceae_e_monocot.zip\r
+               URI sourceUrl = URI.create("file:///C:/Users/l.morris/Downloads/amaryllidaceae.zip");//antkey.zip");//alismataceae.zip");//hypoxidaceae.zip");//dwca_antkey.zip");\r
                return sourceUrl;\r
        }\r
        \r
@@ -147,7 +164,8 @@ public class DwcaScratchpadImportActivator {
        }\r
        //emonocots_cypripedioideae\r
        public static URI dwca_emonocots_cypripedioideae() {\r
-               URI sourceUrl = URI.create("file:////PESIIMPORT3/vibrant/dwca/dwca_emonocots_cypripedioideae.zip");\r
+               //URI sourceUrl = URI.create("file:////PESIIMPORT3/vibrant/dwca/dwca_emonocots_cypripedioideae.zip");\r
+               URI sourceUrl = URI.create("file:///C:/Users/l.morris/Downloads/dwca_scratchpads/dwca_cypripedioideae_e-monocot_org.zip");\r
                return sourceUrl;\r
        }\r
        \r
@@ -157,7 +175,54 @@ public class DwcaScratchpadImportActivator {
         */\r
        public static void main(String[] args) {\r
                DwcaScratchpadImportActivator me = new DwcaScratchpadImportActivator();\r
-               me.doImport(source, cdmDestination, classificationUuid, title, hbm2dll);\r
+\r
+               //lorna: TODO get the classification name from the dwca zip file name\r
+               classificationName = "Scratchpad classification";//"Amaryllidaceae";\r
+\r
+               // Directory path here\r
+               String path = "C:/Users/l.morris/Downloads/dwca_scratchpads/nine";\r
+               URI sourceUrl;\r
+               //URI sourceUrl = URI.create("file:////PESIIMPORT3/vibrant/dwca/dwca_emonocots_zingiberaceae.zip");\r
+\r
+               String zipFile;\r
+               File folder = new File(path);\r
+               File[] listOfFiles = folder.listFiles(); \r
+\r
+               for (int i = 0; i < listOfFiles.length; i++) \r
+               {\r
+\r
+                       if (listOfFiles[i].isFile()) \r
+                       {\r
+                               zipFile = listOfFiles[i].getName();\r
+\r
+                               if (zipFile.endsWith(".zip"))\r
+                               {\r
+                                       //classificationName = zipFile.split(".zip")[0];\r
+                                       classificationName = zipFile.split("dwca_")[1];\r
+                                       classificationName = classificationName.split("_")[0];\r
+                                       System.out.println(classificationName);\r
+                                       //start the Scratchpad name with uppercase.\r
+                                       char[] stringArray = classificationName.toCharArray();\r
+                                       stringArray[0] = Character.toUpperCase(stringArray[0]);\r
+                                       classificationName = new String(stringArray) + " (Scratchpads)";\r
+                                       System.out.println(classificationName);\r
+                                       //System.exit(999);\r
+\r
+                                       sourceUrl = URI.create("file:///" + path + "/" + zipFile);\r
+                                       System.out.println(sourceUrl);\r
+                                       me.doImport(sourceUrl, cdmDestination, classificationUuid, title, hbm2dll);\r
+                                       //System.exit(999);\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               //System.exit(999);\r
+               //list all files in the directory\r
+               //get the URI of each\r
+               //URI sourceUrl = URI.create("file:///C:/Users/l.morris/Downloads/amaryllidaceae.zip");\r
+               \r
+               //Lorna iterate through the dwca directly getting each dwca.zip and generate a URI for each source\r
+               //me.doImport(source, cdmDestination, classificationUuid, title, hbm2dll);\r
        }\r
        \r
 }\r