Initial set of classes for the IAPT import
[cdmlib-apps.git] / app-import / src / main / java / eu / etaxonomy / cdm / app / iapt / IAPTActivator.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.cdm.app.iapt;
11
12 import java.io.File;
13 import java.net.URI;
14 import java.util.UUID;
15
16 import org.apache.log4j.Logger;
17
18 import eu.etaxonomy.cdm.app.common.CdmDestinations;
19 import eu.etaxonomy.cdm.database.DbSchemaValidation;
20 import eu.etaxonomy.cdm.database.ICdmDataSource;
21 import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
22 import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
23 import eu.etaxonomy.cdm.io.iapt.IAPTImportConfigurator;
24 import eu.etaxonomy.cdm.model.reference.Reference;
25 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
26
27
28 /**
29 * @author a.kohlbecker
30 * @date Jul 26, 2016
31 *
32 */
33 public class IAPTActivator {
34 private static final Logger logger = Logger.getLogger(IAPTActivator.class);
35
36 //database validation status (create, update, validate ...)
37 static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
38
39 static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
40 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
41 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_cuba_production();
42
43 static boolean invers = true;
44
45 static boolean include = !invers;
46
47 //classification
48 static final UUID classificationUuid = UUID.fromString("8c51efb4-3d67-4bea-8f87-4bc1cba1310d");
49 private static final String classificationName = "IAPT";
50 static final String sourceReferenceTitle = "IAPT Import";
51
52 //check - import
53 static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
54
55 static final boolean doTaxa = false;
56
57
58 private void doImport(ICdmDataSource cdmDestination){
59
60 URI source = iapt(); //just any
61
62 Reference secRef = ReferenceFactory.newDatabase();
63 secRef.setTitle("IAPT");
64
65 //make Source
66 IAPTImportConfigurator config= IAPTImportConfigurator.NewInstance(source, cdmDestination);
67 config.setClassificationUuid(classificationUuid);
68 config.setClassificationName(classificationName);
69 config.setCheck(check);
70 config.setDbSchemaValidation(hbm2dll);
71 config.setSourceReferenceTitle(sourceReferenceTitle);
72 config.setSecReference(secRef);
73
74 CdmDefaultImport<IAPTImportConfigurator> myImport = new CdmDefaultImport<>();
75
76 doSingleSource(iapt(), config, myImport);
77
78 System.exit(0);
79
80 }
81
82 /**
83 * @param source
84 * @param config
85 * @param myImport
86 */
87 private void doSingleSource(URI source, IAPTImportConfigurator config, CdmDefaultImport<IAPTImportConfigurator> myImport) {
88 config.setSource(source);
89 String fileName = source.toString();
90 fileName = fileName.substring(fileName.lastIndexOf("/") + 1 );
91
92 String message = "Start import from ("+ fileName + ") ...";
93 System.out.println(message);
94 logger.warn(message);
95 config.setSourceReference(getSourceReference(fileName));
96 myImport.invoke(config);
97
98 System.out.println("End import from ("+ source.toString() + ")...");
99 }
100
101 private final Reference inRef = ReferenceFactory.newGeneric();
102 private Reference getSourceReference(String string) {
103 Reference result = ReferenceFactory.newGeneric();
104 result.setTitleCache(string, true);
105 result.setInReference(inRef);
106 inRef.setTitleCache(sourceReferenceTitle, true);
107 return result;
108 }
109
110
111
112 public static URI iapt() {
113 File f = new File("~/data/Projekte/Algea Name Registry/registry/sources/IAPT/Registration_DB_from_BGBM17-cleaned.xls");
114 return f.toURI();
115 }
116
117 /**
118 * @param args
119 */
120 public static void main(String[] args) {
121 IAPTActivator me = new IAPTActivator();
122 me.doImport(cdmDestination);
123 }
124
125 }