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 eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
|
17
|
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
|
18
|
import org.apache.log4j.Appender;
|
19
|
import org.apache.log4j.Logger;
|
20
|
|
21
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
22
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
23
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
24
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
25
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
26
|
import eu.etaxonomy.cdm.io.iapt.IAPTImportConfigurator;
|
27
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
28
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
29
|
import org.apache.log4j.RollingFileAppender;
|
30
|
|
31
|
|
32
|
/**
|
33
|
* @author a.kohlbecker
|
34
|
* @date Jul 26, 2016
|
35
|
*
|
36
|
*/
|
37
|
public class IAPTActivator {
|
38
|
private static final Logger logger = Logger.getLogger(IAPTActivator.class);
|
39
|
|
40
|
//database validation status (create, update, validate ...)
|
41
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
42
|
|
43
|
static ICdmDataSource cdmDestination = null;
|
44
|
static {
|
45
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
46
|
String cdmServer = "127.0.0.1";
|
47
|
String cdmDB = "cdm_algea_registry";
|
48
|
String cdmUserName = "edit";
|
49
|
cdmDestination = CdmDestinations.makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
|
50
|
// cdmDestination = CdmDestinations.localH2();
|
51
|
}
|
52
|
|
53
|
static boolean invers = true;
|
54
|
|
55
|
static boolean include = !invers;
|
56
|
|
57
|
//classification
|
58
|
static final UUID classificationUuid = UUID.fromString("8c51efb4-3d67-4bea-8f87-4bc1cba1310d");
|
59
|
private static final String classificationName = "IAPT";
|
60
|
static final String sourceReferenceTitle = "IAPT Import";
|
61
|
|
62
|
//check - import
|
63
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
64
|
|
65
|
static final boolean doTaxa = false;
|
66
|
|
67
|
|
68
|
private void doImport(ICdmDataSource cdmDestination){
|
69
|
|
70
|
URI source = iapt(); //just any
|
71
|
|
72
|
Reference secRef = ReferenceFactory.newDatabase();
|
73
|
secRef.setTitle("IAPT");
|
74
|
|
75
|
//make Source
|
76
|
IAPTImportConfigurator config= IAPTImportConfigurator.NewInstance(source, cdmDestination);
|
77
|
config.setClassificationUuid(classificationUuid);
|
78
|
config.setClassificationName(classificationName);
|
79
|
config.setCheck(check);
|
80
|
config.setDbSchemaValidation(hbm2dll);
|
81
|
config.setSourceReferenceTitle(sourceReferenceTitle);
|
82
|
config.setSecReference(secRef);
|
83
|
config.setProgressMonitor(DefaultProgressMonitor.NewInstance());
|
84
|
|
85
|
CdmDefaultImport<IAPTImportConfigurator> myImport = new CdmDefaultImport<>();
|
86
|
|
87
|
doSingleSource(iapt(), config, myImport);
|
88
|
|
89
|
System.exit(0);
|
90
|
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* @param source
|
95
|
* @param config
|
96
|
* @param myImport
|
97
|
*/
|
98
|
private void doSingleSource(URI source, IAPTImportConfigurator config, CdmDefaultImport<IAPTImportConfigurator> myImport) {
|
99
|
config.setSource(source);
|
100
|
String fileName = source.toString();
|
101
|
fileName = fileName.substring(fileName.lastIndexOf("/") + 1 );
|
102
|
|
103
|
String message = "Start import from ("+ fileName + ") ...";
|
104
|
System.out.println(message);
|
105
|
logger.warn(message);
|
106
|
config.setSourceReference(getSourceReference(fileName));
|
107
|
myImport.invoke(config);
|
108
|
|
109
|
System.out.println("End import from ("+ source.toString() + ")...");
|
110
|
}
|
111
|
|
112
|
private final Reference inRef = ReferenceFactory.newGeneric();
|
113
|
private Reference getSourceReference(String string) {
|
114
|
Reference result = ReferenceFactory.newGeneric();
|
115
|
result.setTitleCache(string, true);
|
116
|
result.setInReference(inRef);
|
117
|
inRef.setTitleCache(sourceReferenceTitle, true);
|
118
|
return result;
|
119
|
}
|
120
|
|
121
|
|
122
|
|
123
|
public static URI iapt() {
|
124
|
File f = new File(System.getProperty("user.home") + "/data/Projekte/Algea Name Registry/registry/sources/IAPT/Registration_DB_from_BGBM17-cleaned-02.xls");
|
125
|
return f.toURI();
|
126
|
}
|
127
|
|
128
|
/**
|
129
|
* @param args
|
130
|
*/
|
131
|
public static void main(String[] args) {
|
132
|
|
133
|
IAPTActivator me = new IAPTActivator();
|
134
|
me.doImport(cdmDestination);
|
135
|
}
|
136
|
|
137
|
}
|