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.cyprus;
|
11
|
|
12
|
import java.net.URI;
|
13
|
import java.net.URISyntaxException;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
|
19
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
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.common.mapping.IInputTransformer;
|
26
|
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
|
27
|
import eu.etaxonomy.cdm.io.cyprus.CyprusImportConfigurator;
|
28
|
import eu.etaxonomy.cdm.io.cyprus.CyprusTransformer;
|
29
|
import eu.etaxonomy.cdm.model.agent.Person;
|
30
|
import eu.etaxonomy.cdm.model.description.Feature;
|
31
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
32
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
33
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
34
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
35
|
|
36
|
/**
|
37
|
* @author a.mueller
|
38
|
* @created 16.12.2010
|
39
|
*/
|
40
|
public class CyprusActivator {
|
41
|
private static final Logger logger = Logger.getLogger(CyprusActivator.class);
|
42
|
|
43
|
//database validation status (create, update, validate ...)
|
44
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
45
|
// static final URI source = cyprus_distribution();
|
46
|
static final URI source = cyprus_local();
|
47
|
|
48
|
|
49
|
static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
50
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_postgres_CdmTest();
|
51
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
|
52
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_cyprus_dev();
|
53
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_cyprus_production();
|
54
|
|
55
|
|
56
|
//feature tree uuid
|
57
|
public static final UUID featureTreeUuid = UUID.fromString("14d1e912-5ec2-4d10-878b-828788b70a87");
|
58
|
|
59
|
//classification
|
60
|
static final UUID classificationUuid = UUID.fromString("0c2b5d25-7b15-4401-8b51-dd4be0ee5cab");
|
61
|
|
62
|
//check - import
|
63
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
64
|
|
65
|
//taxa
|
66
|
static final boolean doTaxa = true;
|
67
|
static final boolean doDeduplicate = false;
|
68
|
static final boolean doDistribution = false;
|
69
|
|
70
|
|
71
|
private void doImport(ICdmDataSource cdmDestination){
|
72
|
|
73
|
//make Source
|
74
|
CyprusImportConfigurator config= CyprusImportConfigurator.NewInstance(source, cdmDestination);
|
75
|
config.setClassificationUuid(classificationUuid);
|
76
|
config.setCheck(check);
|
77
|
config.setDoDistribution(doDistribution);
|
78
|
config.setDoTaxa(doTaxa);
|
79
|
config.setDbSchemaValidation(hbm2dll);
|
80
|
|
81
|
CdmDefaultImport myImport = new CdmDefaultImport();
|
82
|
|
83
|
|
84
|
//...
|
85
|
if (true){
|
86
|
System.out.println("Start import from ("+ source.toString() + ") ...");
|
87
|
config.setSourceReference(getSourceReference(config.getSourceReferenceTitle()));
|
88
|
myImport.invoke(config);
|
89
|
if (doTaxa){
|
90
|
FeatureTree tree = makeFeatureNodes(myImport.getCdmAppController().getTermService());
|
91
|
myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
|
92
|
}
|
93
|
|
94
|
System.out.println("End import from ("+ source.toString() + ")...");
|
95
|
}
|
96
|
|
97
|
|
98
|
|
99
|
//deduplicate
|
100
|
if (doDeduplicate){
|
101
|
ICdmApplicationConfiguration app = myImport.getCdmAppController();
|
102
|
int count = app.getAgentService().deduplicate(Person.class, null, null);
|
103
|
logger.warn("Deduplicated " + count + " persons.");
|
104
|
// count = app.getAgentService().deduplicate(Team.class, null, null);
|
105
|
// logger.warn("Deduplicated " + count + " teams.");
|
106
|
count = app.getReferenceService().deduplicate(Reference.class, null, null);
|
107
|
logger.warn("Deduplicated " + count + " references.");
|
108
|
}
|
109
|
|
110
|
}
|
111
|
|
112
|
private Reference<?> getSourceReference(String string) {
|
113
|
Reference<?> result = ReferenceFactory.newGeneric();
|
114
|
result.setTitleCache(string, true);
|
115
|
return result;
|
116
|
}
|
117
|
|
118
|
private FeatureTree makeFeatureNodes(ITermService service){
|
119
|
CyprusTransformer transformer = new CyprusTransformer();
|
120
|
|
121
|
FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
|
122
|
result.setTitleCache("Cyprus Feature Tree", true);
|
123
|
FeatureNode root = result.getRoot();
|
124
|
FeatureNode newNode;
|
125
|
|
126
|
newNode = FeatureNode.NewInstance(Feature.STATUS());
|
127
|
root.addChild(newNode);
|
128
|
|
129
|
newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
130
|
root.addChild(newNode);
|
131
|
|
132
|
newNode = FeatureNode.NewInstance(Feature.SYSTEMATICS());
|
133
|
root.addChild(newNode);
|
134
|
|
135
|
//user defined features
|
136
|
String [] featureList = new String[]{"Red Book", "Endemism"};
|
137
|
addFeataureNodesByStringList(featureList, root, transformer, service);
|
138
|
|
139
|
return result;
|
140
|
}
|
141
|
|
142
|
|
143
|
//Cyprus
|
144
|
public static URI cyprus_local() {
|
145
|
URI sourceUrl;
|
146
|
try {
|
147
|
sourceUrl = new URI("file:/C:/localCopy/Data/zypern/Zypern.xls");
|
148
|
return sourceUrl;
|
149
|
} catch (URISyntaxException e) {
|
150
|
e.printStackTrace();
|
151
|
return null;
|
152
|
}
|
153
|
}
|
154
|
//Cyprus distriution
|
155
|
public static URI cyprus_distribution() {
|
156
|
URI sourceUrl;
|
157
|
try {
|
158
|
sourceUrl = new URI("file:/C:/localCopy/Data/zypern/Zypern_distribution_RH_corr.xls");
|
159
|
return sourceUrl;
|
160
|
} catch (URISyntaxException e) {
|
161
|
e.printStackTrace();
|
162
|
return null;
|
163
|
}
|
164
|
}
|
165
|
|
166
|
public void addFeataureNodesByStringList(String[] featureStringList, FeatureNode root, IInputTransformer transformer, ITermService termService){
|
167
|
try {
|
168
|
for (String featureString : featureStringList){
|
169
|
UUID featureUuid;
|
170
|
featureUuid = transformer.getFeatureUuid(featureString);
|
171
|
Feature feature = (Feature)termService.find(featureUuid);
|
172
|
if (feature != null){
|
173
|
FeatureNode child = FeatureNode.NewInstance(feature);
|
174
|
root.addChild(child);
|
175
|
}
|
176
|
}
|
177
|
} catch (UndefinedTransformerMethodException e) {
|
178
|
logger.error("getFeatureUuid is not implemented in transformer. Features could not be added");
|
179
|
}
|
180
|
}
|
181
|
|
182
|
|
183
|
/**
|
184
|
* @param args
|
185
|
*/
|
186
|
public static void main(String[] args) {
|
187
|
CyprusActivator me = new CyprusActivator();
|
188
|
me.doImport(cdmDestination);
|
189
|
}
|
190
|
|
191
|
}
|