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.net.URISyntaxException;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
|
18
|
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
|
19
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
20
|
import org.apache.log4j.Logger;
|
21
|
|
22
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
23
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
24
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
25
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
26
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
27
|
import eu.etaxonomy.cdm.io.iapt.IAPTImportConfigurator;
|
28
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
29
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
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
|
public static final String DATA_FILE_FULL = "Registration_DB_from_BGBM17.xls";
|
41
|
public static final String DATA_FILE_0_100 = "iapt-100.xls";
|
42
|
public static final String DATA_ENCODING_PROBLEMS = "encoding-problems.xls";
|
43
|
public static final String DATA_IAPT_TYPES_100 = "iapt-types-100.xls";
|
44
|
public static final String DATA_TYPE_LEG_100 = "iapt-type-leg-100.xls";
|
45
|
public static final String DATA_NAME_TYPES = "iapt-name-types.xls";
|
46
|
public static final String DATA_SINGLE = "single.xls";
|
47
|
public static final String DATA_FILE = DATA_FILE_FULL;
|
48
|
|
49
|
public static final Boolean algaeOnly = false;
|
50
|
|
51
|
// ====================================================================================
|
52
|
|
53
|
//database validation status (create, update, validate ...)
|
54
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
55
|
|
56
|
static ICdmDataSource cdmDestination = null;
|
57
|
static {
|
58
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
59
|
String cdmServer = "127.0.0.1";
|
60
|
String cdmDB = "cdm_algea_registry";
|
61
|
String cdmUserName = "edit";
|
62
|
cdmDestination = CdmDestinations.makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
|
63
|
// cdmDestination = CdmDestinations.localH2();
|
64
|
}
|
65
|
|
66
|
static boolean invers = true;
|
67
|
|
68
|
static boolean include = !invers;
|
69
|
|
70
|
//classification
|
71
|
static final UUID classificationUuid = UUID.fromString("8c51efb4-3d67-4bea-8f87-4bc1cba1310d");
|
72
|
private static final String classificationName = "IAPT";
|
73
|
static final String sourceReferenceTitle = "IAPT Import";
|
74
|
|
75
|
//check - import
|
76
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
77
|
|
78
|
|
79
|
private void doImport(ICdmDataSource cdmDestination){
|
80
|
|
81
|
URI source = fileURI();
|
82
|
|
83
|
Reference secRef = ReferenceFactory.newDatabase();
|
84
|
secRef.setTitle("IAPT");
|
85
|
|
86
|
Reference sourceRef = ReferenceFactory.newDatabase();
|
87
|
sourceRef.setTitle("IAPT Registration of Plant Names Database");
|
88
|
sourceRef.setDatePublished(TimePeriod.NewInstance(1998, 2016));
|
89
|
sourceRef.setOrganization("International Association for Plant Taxonomy");
|
90
|
try {
|
91
|
sourceRef.setUri(new URI("http://archive.bgbm.org/scripts/ASP/registration/regSearch.asp"));
|
92
|
} catch (URISyntaxException e) {
|
93
|
e.printStackTrace();
|
94
|
}
|
95
|
|
96
|
|
97
|
//make Source
|
98
|
IAPTImportConfigurator config= IAPTImportConfigurator.NewInstance(source, cdmDestination);
|
99
|
config.setClassificationUuid(classificationUuid);
|
100
|
config.setClassificationName(classificationName);
|
101
|
config.setCheck(check);
|
102
|
config.setDbSchemaValidation(hbm2dll);
|
103
|
config.setSourceReference(sourceRef);
|
104
|
config.setSecReference(secRef);
|
105
|
config.setProgressMonitor(DefaultProgressMonitor.NewInstance());
|
106
|
config.setDoAlgeaeOnly(algaeOnly);
|
107
|
// config.setBatchSize(100); // causes Error during managed flush [Don't change the reference to a collection with delete-orphan enabled : eu.etaxonomy.cdm.model.taxon.TaxonNode.annotations]
|
108
|
|
109
|
CdmDefaultImport<IAPTImportConfigurator> myImport = new CdmDefaultImport<>();
|
110
|
|
111
|
doSingleSource(fileURI(), config, myImport);
|
112
|
|
113
|
System.exit(0);
|
114
|
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* @param source
|
119
|
* @param config
|
120
|
* @param myImport
|
121
|
*/
|
122
|
private void doSingleSource(URI source, IAPTImportConfigurator config, CdmDefaultImport<IAPTImportConfigurator> myImport) {
|
123
|
config.setSource(source);
|
124
|
String fileName = source.toString();
|
125
|
fileName = fileName.substring(fileName.lastIndexOf("/") + 1 );
|
126
|
|
127
|
String message = "Start import from ("+ fileName + ") ...";
|
128
|
System.out.println(message);
|
129
|
logger.warn(message);
|
130
|
config.setSourceReference(getSourceReference(fileName));
|
131
|
myImport.invoke(config);
|
132
|
|
133
|
System.out.println("End import from ("+ source.toString() + ")...");
|
134
|
}
|
135
|
|
136
|
private final Reference inRef = ReferenceFactory.newGeneric();
|
137
|
private Reference getSourceReference(String string) {
|
138
|
Reference result = ReferenceFactory.newGeneric();
|
139
|
result.setTitleCache(string, true);
|
140
|
result.setInReference(inRef);
|
141
|
inRef.setTitleCache(sourceReferenceTitle, true);
|
142
|
return result;
|
143
|
}
|
144
|
|
145
|
|
146
|
|
147
|
public static URI fileURI() {
|
148
|
File f = new File(System.getProperty("user.home") + "/data/Projekte/Algea Name Registry/registry/sources/IAPT/" + DATA_FILE);
|
149
|
return f.toURI();
|
150
|
}
|
151
|
|
152
|
/**
|
153
|
* @param args
|
154
|
*/
|
155
|
public static void main(String[] args) {
|
156
|
IAPTActivator me = new IAPTActivator();
|
157
|
me.doImport(cdmDestination);
|
158
|
}
|
159
|
|
160
|
}
|