1
|
package eu.etaxonomy.cdm.app.pesi.merging;
|
2
|
|
3
|
import java.io.FileWriter;
|
4
|
import java.io.IOException;
|
5
|
import java.util.ArrayList;
|
6
|
import java.util.Iterator;
|
7
|
import java.util.List;
|
8
|
import java.util.Map;
|
9
|
import java.util.Set;
|
10
|
import java.util.UUID;
|
11
|
|
12
|
import org.apache.log4j.Logger;
|
13
|
|
14
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
15
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
16
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
17
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
18
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
19
|
import eu.etaxonomy.cdm.io.api.application.CdmIoApplicationController;
|
20
|
import eu.etaxonomy.cdm.io.pesi.merging.PesiMergeObject;
|
21
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
22
|
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
23
|
import eu.etaxonomy.cdm.model.name.IZoologicalName;
|
24
|
import eu.etaxonomy.cdm.model.name.Rank;
|
25
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
26
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
27
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
28
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
29
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
30
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
31
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
32
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
33
|
|
34
|
public class FaunaEuErmsFindIdenticalNamesActivator {
|
35
|
|
36
|
private static final Logger logger = Logger.getLogger(FaunaEuErmsFindIdenticalNamesActivator.class);
|
37
|
|
38
|
//static final ICdmDataSource faunaEuropaeaSource = CdmDestinations.localH2();
|
39
|
static final ICdmDataSource pesiSource = CdmDestinations.cdm_test_local_faunaEu_mysql();
|
40
|
|
41
|
static final String path = "C:\\Users\\k.luther\\test";
|
42
|
|
43
|
private static UUID faunaEuSecUuid = UUID.fromString("6786d863-75d4-4796-b916-c1c3dff4cb70");
|
44
|
private static UUID ermsSecUuid = UUID.fromString("7744bc26-f914-42c4-b54a-dd2a030a8bb7");
|
45
|
private static UUID ifSecUuid;
|
46
|
private static UUID emSecUuid;
|
47
|
|
48
|
private void invoke(ICdmDataSource source){
|
49
|
|
50
|
CdmApplicationController app = CdmIoApplicationController.NewInstance(source, DbSchemaValidation.VALIDATE, false);
|
51
|
|
52
|
List<String> propertyPaths = new ArrayList<>();
|
53
|
propertyPaths.add("sources.*");
|
54
|
propertyPaths.add("sources.idInSource");
|
55
|
propertyPaths.add("sources.idNamespace");
|
56
|
propertyPaths.add("taxonBases.*");
|
57
|
propertyPaths.add("taxonBases.relationsFromThisTaxon");
|
58
|
propertyPaths.add("taxonBases.taxonNodes.*");
|
59
|
propertyPaths.add("taxonBases.taxonNodes.parent.*");
|
60
|
propertyPaths.add("taxonBases.taxonNodes.childNodes.*");
|
61
|
propertyPaths.add("taxonBases.taxonNodes.childNodes.classification.rootNode.childNodes.*");
|
62
|
propertyPaths.add("taxonBases.taxonNodes.parent.taxon.name.*");
|
63
|
propertyPaths.add("taxonBases.acceptedTaxon.taxonNodes.*");
|
64
|
propertyPaths.add("taxonBases.acceptedTaxon.taxonNodes.childNodes.*");
|
65
|
propertyPaths.add("taxonBases.acceptedTaxon.taxonNodes.childNodes.classification.rootNode.childNodes.*");
|
66
|
System.out.println("Start getIdenticalNames...");
|
67
|
|
68
|
Reference faunaEuSec = app.getReferenceService().load(faunaEuSecUuid);
|
69
|
Reference ermsSec = app.getReferenceService().load(ermsSecUuid);
|
70
|
Map<String, List<TaxonName>> namesOfIdenticalTaxa = app.getTaxonService().findIdenticalTaxonNameIds(ermsSec, faunaEuSec, propertyPaths);
|
71
|
|
72
|
System.out.println("Start creating merging objects");
|
73
|
List<PesiMergeObject> mergingObjects= createMergeObjects(namesOfIdenticalTaxa, app);
|
74
|
boolean resultOK = true;
|
75
|
System.out.println("Start creating csv files");
|
76
|
resultOK &= writeSameNamesDifferentAuthorToCsv(mergingObjects, path + "_authors.csv");
|
77
|
resultOK &= writeSameNamesDifferentStatusToCsv(mergingObjects, path + "_status.csv");
|
78
|
resultOK &= writeSameNamesToCsvFile(mergingObjects, path + "_names.csv");
|
79
|
resultOK &= writeSameNamesDifferentPhylumToCsv(mergingObjects, path + "_phylum.csv");
|
80
|
resultOK &= writeSameNamesDifferentParentToCsv(mergingObjects, path + "parent.csv");
|
81
|
|
82
|
System.out.println("End merging Fauna Europaea and Erms: " + resultOK);
|
83
|
}
|
84
|
|
85
|
private boolean writeSameNamesToCsvFile(
|
86
|
List<PesiMergeObject> mergingObjects, String string) {
|
87
|
|
88
|
try{
|
89
|
FileWriter writer = new FileWriter(string);
|
90
|
|
91
|
//create Header
|
92
|
String firstLine = "same names";
|
93
|
createHeader(writer, firstLine);
|
94
|
for (PesiMergeObject merging : mergingObjects){
|
95
|
writeCsvLine(writer, merging) ;
|
96
|
}
|
97
|
writer.flush();
|
98
|
writer.close();
|
99
|
return true;
|
100
|
}catch(IOException e){
|
101
|
logger.error(e.getMessage());
|
102
|
return false;
|
103
|
}
|
104
|
}
|
105
|
|
106
|
private boolean writeSameNamesDifferentPhylumToCsv(
|
107
|
List<PesiMergeObject> mergingObjects, String sfileName){
|
108
|
|
109
|
try{
|
110
|
FileWriter writer = new FileWriter(sfileName);
|
111
|
|
112
|
//create Header
|
113
|
String firstLine = "same names but different phylum";
|
114
|
createHeader(writer, firstLine);
|
115
|
|
116
|
//write data
|
117
|
for (PesiMergeObject merging : mergingObjects){
|
118
|
//TODO
|
119
|
if ((merging.getPhylumInErms()== null )^ (merging.getPhylumInFaunaEu()== null)){
|
120
|
writeCsvLine(writer, merging) ;
|
121
|
}else if(!((merging.getPhylumInErms()==null) && (merging.getPhylumInFaunaEu()==null))){
|
122
|
if(!merging.getPhylumInErms().equals(merging.getPhylumInFaunaEu())){
|
123
|
writeCsvLine(writer, merging) ;
|
124
|
}
|
125
|
}
|
126
|
}
|
127
|
writer.flush();
|
128
|
writer.close();
|
129
|
return true;
|
130
|
}catch(IOException e){
|
131
|
logger.error(e.getMessage());
|
132
|
return false;
|
133
|
}
|
134
|
}
|
135
|
|
136
|
private boolean writeSameNamesDifferentParentToCsv(
|
137
|
List<PesiMergeObject> mergingObjects, String sfileName){
|
138
|
|
139
|
try{
|
140
|
FileWriter writer = new FileWriter(sfileName);
|
141
|
|
142
|
//create Header
|
143
|
String firstLine = "same names but different parent";
|
144
|
createHeader(writer, firstLine);
|
145
|
|
146
|
//write data
|
147
|
for (PesiMergeObject merging : mergingObjects){
|
148
|
//TODO
|
149
|
if ((merging.getParentStringInErms()== null )^ (merging.getParentStringInFaunaEu()== null)){
|
150
|
writeCsvLine(writer, merging) ;
|
151
|
}else if(!((merging.getParentStringInErms()==null) && (merging.getParentStringInFaunaEu()==null))){
|
152
|
if(!merging.getParentStringInErms().equals(merging.getParentStringInFaunaEu())){
|
153
|
writeCsvLine(writer, merging) ;
|
154
|
}
|
155
|
}
|
156
|
}
|
157
|
writer.flush();
|
158
|
writer.close();
|
159
|
return true;
|
160
|
}catch(IOException e){
|
161
|
return false;
|
162
|
}
|
163
|
}
|
164
|
|
165
|
private boolean writeSameNamesdifferentRankToCsv(
|
166
|
List<PesiMergeObject> mergingObjects, String sfileName){
|
167
|
|
168
|
try{
|
169
|
FileWriter writer = new FileWriter(sfileName);
|
170
|
String firstLine = "same names but different rank";
|
171
|
//create Header
|
172
|
createHeader(writer, firstLine);
|
173
|
|
174
|
//write data
|
175
|
for (PesiMergeObject merging : mergingObjects){
|
176
|
|
177
|
if (!merging.getRankInErms().equals(merging.getRankInFaunaEu())){
|
178
|
writeCsvLine(writer, merging);
|
179
|
}
|
180
|
}
|
181
|
writer.flush();
|
182
|
writer.close();
|
183
|
return true;
|
184
|
}catch(IOException e){
|
185
|
return false;
|
186
|
}
|
187
|
}
|
188
|
|
189
|
private void createHeader(FileWriter writer, String firstLine) throws IOException{
|
190
|
writer.append(firstLine);
|
191
|
writer.append('\n');
|
192
|
writer.append("uuid in Fauna Europaea");
|
193
|
writer.append(';');
|
194
|
writer.append("id in Fauna Europaea");
|
195
|
writer.append(';');
|
196
|
writer.append("name");
|
197
|
writer.append(';');
|
198
|
writer.append("author");
|
199
|
writer.append(';');
|
200
|
writer.append("rank");
|
201
|
writer.append(';');
|
202
|
writer.append("state");
|
203
|
writer.append(';');
|
204
|
writer.append("phylum");
|
205
|
writer.append(';');
|
206
|
writer.append("parent");
|
207
|
writer.append(';');
|
208
|
writer.append("parent rank");
|
209
|
writer.append(';');
|
210
|
|
211
|
writer.append("uuid in Erms");
|
212
|
writer.append(';');
|
213
|
writer.append("id in Erms");
|
214
|
writer.append(';');
|
215
|
writer.append("name");
|
216
|
writer.append(';');
|
217
|
writer.append("author");
|
218
|
writer.append(';');
|
219
|
writer.append("rank");
|
220
|
writer.append(';');
|
221
|
writer.append("state");
|
222
|
writer.append(';');
|
223
|
writer.append("phylum");
|
224
|
writer.append(';');
|
225
|
writer.append("parent");
|
226
|
writer.append(';');
|
227
|
writer.append("parent rank");
|
228
|
writer.append('\n');
|
229
|
}
|
230
|
|
231
|
private boolean writeSameNamesDifferentStatusToCsv(
|
232
|
List<PesiMergeObject> mergingObjects, String sfileName){
|
233
|
|
234
|
try{
|
235
|
FileWriter writer = new FileWriter(sfileName);
|
236
|
|
237
|
//create Header
|
238
|
String firstLine = "same names but different status";
|
239
|
createHeader(writer, firstLine);
|
240
|
|
241
|
//write data
|
242
|
for (PesiMergeObject merging : mergingObjects){
|
243
|
if (merging.isStatInErms()^merging.isStatInFaunaEu()){
|
244
|
writeCsvLine(writer, merging);
|
245
|
}
|
246
|
}
|
247
|
|
248
|
writer.flush();
|
249
|
writer.close();
|
250
|
return true;
|
251
|
}catch(IOException e){
|
252
|
return false;
|
253
|
}
|
254
|
}
|
255
|
|
256
|
private boolean writeSameNamesDifferentAuthorToCsv(
|
257
|
List<PesiMergeObject> mergingObjects, String sfileName){
|
258
|
|
259
|
try{
|
260
|
FileWriter writer = new FileWriter(sfileName);
|
261
|
|
262
|
//create Header
|
263
|
String firstLine = "same names but different authors";
|
264
|
createHeader(writer, firstLine);
|
265
|
|
266
|
//write data
|
267
|
for (PesiMergeObject merging : mergingObjects){
|
268
|
|
269
|
if (merging.getAuthorInErms() != null && merging.getAuthorInFaunaEu() != null && !merging.getAuthorInErms().equals(merging.getAuthorInFaunaEu())){
|
270
|
writeCsvLine(writer, merging);
|
271
|
}else if ((merging.getAuthorInErms() == null && merging.getAuthorInFaunaEu() != null) || (merging.getAuthorInErms() != null && merging.getAuthorInFaunaEu() == null)) {
|
272
|
writeCsvLine(writer, merging);
|
273
|
}
|
274
|
}
|
275
|
|
276
|
writer.flush();
|
277
|
writer.close();
|
278
|
return true;
|
279
|
}catch(IOException e){
|
280
|
return false;
|
281
|
}
|
282
|
}
|
283
|
|
284
|
private void writeCsvLine(FileWriter writer, PesiMergeObject merging) throws IOException{
|
285
|
|
286
|
writer.append(merging.getUuidFaunaEu());
|
287
|
writer.append(';');
|
288
|
writer.append(merging.getIdInFaunaEu());
|
289
|
writer.append(';');
|
290
|
writer.append(merging.getNameCacheInFaunaEu());
|
291
|
writer.append(';');
|
292
|
writer.append(merging.getAuthorInFaunaEu());
|
293
|
writer.append(';');
|
294
|
writer.append(merging.getRankInFaunaEu());
|
295
|
writer.append(';');
|
296
|
if (merging.isStatInFaunaEu()){
|
297
|
writer.append("accepted");
|
298
|
}else{
|
299
|
writer.append("synonym");
|
300
|
}
|
301
|
writer.append(';');
|
302
|
writer.append(merging.getPhylumInFaunaEu() != null? merging.getPhylumInFaunaEu().getTaxonTitleCache(): "");
|
303
|
writer.append(';');
|
304
|
writer.append(merging.getParentStringInFaunaEu());
|
305
|
writer.append(';');
|
306
|
writer.append(merging.getParentRankStringInFaunaEu());
|
307
|
writer.append(';');
|
308
|
|
309
|
writer.append(merging.getUuidErms());
|
310
|
writer.append(';');
|
311
|
writer.append(merging.getIdInErms());
|
312
|
writer.append(';');
|
313
|
writer.append(merging.getNameCacheInErms());
|
314
|
writer.append(';');
|
315
|
writer.append(merging.getAuthorInErms());
|
316
|
writer.append(';');
|
317
|
writer.append(merging.getRankInErms());
|
318
|
writer.append(';');
|
319
|
if (merging.isStatInErms()){
|
320
|
writer.append("accepted");
|
321
|
}else{
|
322
|
writer.append("synonym");
|
323
|
}
|
324
|
|
325
|
writer.append(';');
|
326
|
writer.append(merging.getPhylumInErms() != null? merging.getPhylumInErms().getTaxonTitleCache():"");
|
327
|
writer.append(';');
|
328
|
writer.append(merging.getParentStringInErms());
|
329
|
writer.append(';');
|
330
|
writer.append(merging.getParentRankStringInErms());
|
331
|
writer.append('\n');
|
332
|
}
|
333
|
|
334
|
private List<PesiMergeObject> createMergeObjects(Map<String,List<TaxonName>> names,
|
335
|
CdmApplicationController appCtr){
|
336
|
|
337
|
UUID uuidClassification1 = UUID.fromString("44d8605e-a7ce-41e1-bee9-99edfec01e7c");
|
338
|
UUID uuidClassification2 = UUID.fromString("6fa988a9-10b7-48b0-a370-2586fbc066eb");
|
339
|
Classification classification1 = appCtr.getClassificationService().load(uuidClassification1);
|
340
|
Classification classification2 = appCtr.getClassificationService().load(uuidClassification2);
|
341
|
|
342
|
List<PesiMergeObject> merge = new ArrayList<>();
|
343
|
|
344
|
for (String nameCache: names.keySet()){
|
345
|
createSingleMergeObject(appCtr, merge, nameCache, names.get(nameCache),classification1, classification2);
|
346
|
}
|
347
|
|
348
|
return merge;
|
349
|
}
|
350
|
|
351
|
|
352
|
private void createSingleMergeObject(CdmApplicationController appCtr, List<PesiMergeObject> merge, String nameCache,
|
353
|
List<TaxonName> identicalNames,
|
354
|
Classification classification1, Classification classification2) {
|
355
|
|
356
|
PesiMergeObject mergeObject = new PesiMergeObject();
|
357
|
|
358
|
if(identicalNames.size()!= 2) {
|
359
|
logger.warn(nameCache + " has more than 2 names with identical name cache from different sources. This is not yet handled.");
|
360
|
return;
|
361
|
}
|
362
|
//getPhylum
|
363
|
TaxonNodeDto phylum1 = null;
|
364
|
TaxonName faunaEuName = null;
|
365
|
TaxonName ermsName = null;
|
366
|
|
367
|
Set<TaxonBase> taxonBases = identicalNames.get(0).getTaxonBases();
|
368
|
if (taxonBases.size()==1) {
|
369
|
Iterator<TaxonBase> it = taxonBases.iterator();
|
370
|
TaxonBase<?> tempName = it.next();
|
371
|
if (tempName.getSec().getUuid().equals(faunaEuSecUuid)) {
|
372
|
faunaEuName = identicalNames.get(0);
|
373
|
ermsName = identicalNames.get(1);
|
374
|
}else {
|
375
|
faunaEuName = identicalNames.get(1);
|
376
|
ermsName = identicalNames.get(0);
|
377
|
}
|
378
|
}else {
|
379
|
//TODO: find the two correct names
|
380
|
logger.warn("Name has not exact 1 but " + taxonBases.size() + " taxon base attached. This is not yet handled");
|
381
|
return;
|
382
|
}
|
383
|
if (faunaEuName.getRank().equals(Rank.PHYLUM())) {
|
384
|
Taxon taxon = null;
|
385
|
taxon = getAcceptedTaxon(faunaEuName);
|
386
|
if (taxon != null) {
|
387
|
phylum1 = new TaxonNodeDto(taxon.getTaxonNode(classification1));
|
388
|
}
|
389
|
|
390
|
}
|
391
|
if (phylum1 == null && !faunaEuName.getRank().isHigher(Rank.PHYLUM())){
|
392
|
phylum1 = appCtr.getTaxonNodeService().taxonNodeDtoParentRank(classification1, Rank.PHYLUM(), faunaEuName);
|
393
|
}
|
394
|
|
395
|
TaxonNodeDto phylum2 = null;
|
396
|
if (ermsName.getRank().equals(Rank.PHYLUM())) {
|
397
|
Taxon taxon = null;
|
398
|
taxon = getAcceptedTaxon(ermsName);
|
399
|
if (taxon != null) {
|
400
|
phylum2 = new TaxonNodeDto(taxon.getTaxonNode(classification2));
|
401
|
}
|
402
|
|
403
|
}
|
404
|
if (phylum2 == null && !ermsName.getRank().isHigher(Rank.PHYLUM())){
|
405
|
phylum2 = appCtr.getTaxonNodeService().taxonNodeDtoParentRank(classification2, Rank.PHYLUM(), ermsName);
|
406
|
}
|
407
|
mergeObject.setPhylumInErms(phylum1);
|
408
|
mergeObject.setPhylumInFaunaEu(phylum2);
|
409
|
|
410
|
//getUuids
|
411
|
mergeObject.setUuidErms(ermsName.getUuid().toString());
|
412
|
mergeObject.setUuidFaunaEu(faunaEuName.getUuid().toString());
|
413
|
|
414
|
Iterator<IdentifiableSource> sources = ermsName.getSources().iterator();
|
415
|
if (sources.hasNext()){
|
416
|
IdentifiableSource source = sources.next();
|
417
|
String idInSource1 = source.getIdInSource();
|
418
|
mergeObject.setIdInErms(idInSource1);
|
419
|
}
|
420
|
sources = faunaEuName.getSources().iterator();
|
421
|
if (sources.hasNext()){
|
422
|
IdentifiableSource source = sources.next();
|
423
|
String idInSource1 = source.getIdInSource();
|
424
|
mergeObject.setIdInFaunaEu(idInSource1);
|
425
|
}
|
426
|
|
427
|
mergeObject.setNameCacheInErms(ermsName.getNameCache());
|
428
|
mergeObject.setNameCacheInFaunaEu(faunaEuName.getNameCache());
|
429
|
|
430
|
mergeObject.setAuthorInErms(ermsName.getAuthorshipCache());
|
431
|
mergeObject.setAuthorInFaunaEu(faunaEuName.getAuthorshipCache());
|
432
|
Set<Taxon> taxa = ermsName.getTaxa();
|
433
|
if (!taxa.isEmpty()){
|
434
|
mergeObject.setStatInErms(true);
|
435
|
Iterator<Taxon> taxaIterator = taxa.iterator();
|
436
|
Taxon taxon = null;
|
437
|
while (taxaIterator.hasNext()){
|
438
|
taxon = taxaIterator.next();
|
439
|
if (!taxon.isMisapplication()){
|
440
|
break;
|
441
|
}
|
442
|
}
|
443
|
Set<TaxonNode> nodes = taxon.getTaxonNodes();
|
444
|
Iterator<TaxonNode> taxonNodeIterator = nodes.iterator();
|
445
|
TaxonNode node, parentNode = null;
|
446
|
while (taxonNodeIterator.hasNext()){
|
447
|
node = taxonNodeIterator.next();
|
448
|
if (!node.isTopmostNode()){
|
449
|
parentNode = node.getParent();
|
450
|
}
|
451
|
}
|
452
|
//TODO: ändern mit erweitertem Initializer..
|
453
|
if (parentNode != null){
|
454
|
TaxonName parentName = CdmBase.deproxy(parentNode.getTaxon().getName());
|
455
|
String parentNameCache = parentName.getNameCache();
|
456
|
mergeObject.setParentStringInErms(parentNameCache);
|
457
|
mergeObject.setParentRankStringInErms(parentName.getRank().getLabel());
|
458
|
}
|
459
|
}else{
|
460
|
mergeObject.setStatInErms(false);
|
461
|
TaxonNode parentNode = getAcceptedNode(ermsName);
|
462
|
//TODO: ändern mit erweitertem Initializer..
|
463
|
if (parentNode != null){
|
464
|
TaxonName parentName = HibernateProxyHelper.deproxy(parentNode.getTaxon().getName());
|
465
|
String parentNameCache = parentName.getNameCache();
|
466
|
mergeObject.setParentStringInErms(parentNameCache);
|
467
|
mergeObject.setParentRankStringInErms(parentName.getRank().getLabel());
|
468
|
}
|
469
|
}
|
470
|
taxa = faunaEuName.getTaxa();
|
471
|
if (!taxa.isEmpty()){
|
472
|
mergeObject.setStatInFaunaEu(true);
|
473
|
Iterator<Taxon> taxaIterator = taxa.iterator();
|
474
|
Taxon taxon = null;
|
475
|
while (taxaIterator.hasNext()){
|
476
|
taxon = taxaIterator.next();
|
477
|
if (!taxon.isMisapplication()){
|
478
|
break;
|
479
|
}
|
480
|
}
|
481
|
Set<TaxonNode> nodes = taxon.getTaxonNodes();
|
482
|
Iterator<TaxonNode> taxonNodeIterator = nodes.iterator();
|
483
|
TaxonNode node, parentNode = null;
|
484
|
while (taxonNodeIterator.hasNext()){
|
485
|
node = taxonNodeIterator.next();
|
486
|
if (!node.isTopmostNode()){
|
487
|
parentNode = node.getParent();
|
488
|
}
|
489
|
}
|
490
|
//TODO: ändern mit erweitertem Initializer..
|
491
|
if (parentNode != null){
|
492
|
if (parentNode.getTaxon().getName().isZoological()){
|
493
|
|
494
|
IZoologicalName parentName = CdmBase.deproxy(parentNode.getTaxon().getName());
|
495
|
String parentNameCache = parentName.getNameCache();
|
496
|
mergeObject.setParentStringInFaunaEu(parentNameCache);
|
497
|
mergeObject.setParentRankStringInFaunaEu(parentName.getRank().getLabel());
|
498
|
|
499
|
}else{
|
500
|
logger.debug("no zoologicalName: " + parentNode.getTaxon().getName().getTitleCache() +" . "+parentNode.getTaxon().getName().getUuid());
|
501
|
}
|
502
|
}
|
503
|
}else{
|
504
|
mergeObject.setStatInFaunaEu(false);
|
505
|
TaxonNode parentNode = getAcceptedNode(faunaEuName);
|
506
|
//TODO: ändern mit erweitertem Initializer..
|
507
|
if (parentNode != null){
|
508
|
TaxonName parentName = HibernateProxyHelper.deproxy(parentNode.getTaxon().getName());
|
509
|
String parentNameCache = parentName.getNameCache();
|
510
|
mergeObject.setParentStringInFaunaEu(parentNameCache);
|
511
|
mergeObject.setParentRankStringInFaunaEu(parentName.getRank().getLabel());
|
512
|
|
513
|
}
|
514
|
}
|
515
|
|
516
|
mergeObject.setRankInErms(ermsName.getRank().getLabel());
|
517
|
mergeObject.setRankInFaunaEu(faunaEuName.getRank().getLabel());
|
518
|
|
519
|
//set parent informations
|
520
|
|
521
|
/*
|
522
|
Set<HybridRelationship> parentRelations = zooName.getParentRelationships();
|
523
|
Iterator parentIterator = parentRelations.iterator();
|
524
|
HybridRelationship parentRel;
|
525
|
ZoologicalName parentName;
|
526
|
while (parentIterator.hasNext()){
|
527
|
parentRel = (HybridRelationship)parentIterator.next();
|
528
|
parentName = (ZoologicalName)parentRel.getParentName();
|
529
|
mergeObject.setParentRankStringInErms(parentName.getRank().getLabel());
|
530
|
mergeObject.setParentStringInErms(parentName.getNameCache());
|
531
|
}
|
532
|
|
533
|
parentRelations = zooName2.getParentRelationships();
|
534
|
parentIterator = parentRelations.iterator();
|
535
|
|
536
|
while (parentIterator.hasNext()){
|
537
|
parentRel = (HybridRelationship)parentIterator.next();
|
538
|
parentName = (ZoologicalName)parentRel.getParentName();
|
539
|
mergeObject.setParentRankStringInFaunaEu(parentName.getRank().getLabel());
|
540
|
mergeObject.setParentStringInFaunaEu(parentName.getNameCache());
|
541
|
}*/
|
542
|
merge.add(mergeObject);
|
543
|
}
|
544
|
|
545
|
private TaxonNode getAcceptedNode(TaxonName ermsName) {
|
546
|
Set<TaxonBase> taxonBases = ermsName.getTaxonBases();
|
547
|
Taxon taxon = null;
|
548
|
if (taxonBases != null && !taxonBases.isEmpty()) {
|
549
|
TaxonBase<?> taxonBase = taxonBases.iterator().next();
|
550
|
if (taxonBase instanceof Synonym) {
|
551
|
taxon = ((Synonym)taxonBase).getAcceptedTaxon();
|
552
|
}
|
553
|
}
|
554
|
|
555
|
Set<TaxonNode> nodes = taxon.getTaxonNodes();
|
556
|
|
557
|
TaxonNode parentNode = null;
|
558
|
if (nodes != null && !nodes.isEmpty()) {
|
559
|
parentNode = nodes.iterator().next();
|
560
|
}
|
561
|
return parentNode;
|
562
|
}
|
563
|
|
564
|
private Taxon getAcceptedTaxon(TaxonName ermsName) {
|
565
|
Taxon taxon = null;
|
566
|
if (ermsName.getTaxa() != null && !ermsName.getTaxa().isEmpty()){
|
567
|
taxon = ermsName.getTaxa().iterator().next();
|
568
|
|
569
|
}else if (ermsName.getTaxonBases() != null && !ermsName.getTaxonBases().isEmpty()){
|
570
|
TaxonBase<?> taxonBase = ermsName.getTaxonBases().iterator().next();
|
571
|
if (taxonBase instanceof Synonym) {
|
572
|
Synonym syn = (Synonym)taxonBase;
|
573
|
taxon = syn.getAcceptedTaxon();
|
574
|
}
|
575
|
}
|
576
|
return taxon;
|
577
|
}
|
578
|
|
579
|
public static void main(String[] args) {
|
580
|
FaunaEuErmsFindIdenticalNamesActivator activator = new FaunaEuErmsFindIdenticalNamesActivator();
|
581
|
activator.invoke(pesiSource);
|
582
|
System.exit(0);
|
583
|
}
|
584
|
}
|