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