1
|
package eu.etaxonomy.cdm.app.pesi.merging;
|
2
|
|
3
|
import java.io.BufferedReader;
|
4
|
import java.io.File;
|
5
|
import java.io.FileNotFoundException;
|
6
|
import java.io.FileReader;
|
7
|
import java.io.IOException;
|
8
|
import java.util.ArrayList;
|
9
|
import java.util.HashSet;
|
10
|
import java.util.Iterator;
|
11
|
import java.util.List;
|
12
|
import java.util.Set;
|
13
|
import java.util.StringTokenizer;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
19
|
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
|
20
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
21
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
22
|
import eu.etaxonomy.cdm.app.util.TestDatabase;
|
23
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
24
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
25
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
26
|
import eu.etaxonomy.cdm.io.api.application.CdmIoApplicationController;
|
27
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
28
|
import eu.etaxonomy.cdm.model.common.Credit;
|
29
|
import eu.etaxonomy.cdm.model.common.Extension;
|
30
|
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
31
|
import eu.etaxonomy.cdm.model.common.Marker;
|
32
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
33
|
import eu.etaxonomy.cdm.model.description.Feature;
|
34
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
35
|
import eu.etaxonomy.cdm.model.name.IZoologicalName;
|
36
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
37
|
import eu.etaxonomy.cdm.model.name.Rank;
|
38
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
39
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
40
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
41
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
42
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
43
|
|
44
|
public class FaunaEuErmsMergeActivator {
|
45
|
|
46
|
// static final ICdmDataSource faunaEuropaeaSource = CdmDestinations.cdm_test_patricia();
|
47
|
static final ICdmDataSource faunaEuropaeaSource = CdmDestinations.localH2();
|
48
|
|
49
|
static final int faunaEuUuid = 0;
|
50
|
static final int ermsUuid = 9;
|
51
|
static final int rankFaunaEu = 4;
|
52
|
static final int rankErms = 13;
|
53
|
|
54
|
CdmApplicationController appCtrInit;
|
55
|
|
56
|
private static final Logger logger = Logger.getLogger(FaunaEuErmsMergeActivator.class);
|
57
|
|
58
|
//csv files starting with...
|
59
|
static String sFileName = "c:\\test";
|
60
|
|
61
|
private void initDb(ICdmDataSource db) {
|
62
|
|
63
|
// Init source DB
|
64
|
appCtrInit = CdmIoApplicationController.NewInstance(db, DbSchemaValidation.VALIDATE, false);
|
65
|
|
66
|
|
67
|
}
|
68
|
|
69
|
public static void main(String[] args) {
|
70
|
|
71
|
FaunaEuErmsMergeActivator sc = new FaunaEuErmsMergeActivator();
|
72
|
|
73
|
sc.initDb(faunaEuropaeaSource);
|
74
|
|
75
|
sc.mergeAuthors();
|
76
|
|
77
|
//set the ranks of Agnatha and Gnathostomata to 50 instead of 45
|
78
|
List<TaxonBase> taxaToChangeRank = new ArrayList<>();
|
79
|
Pager<TaxonBase> agnatha = sc.appCtrInit.getTaxonService().findTaxaByName(TaxonBase.class, "Agnatha", null, null, null, "*", Rank.INFRAPHYLUM(), 10, 0);
|
80
|
List<TaxonBase> agnathaList = agnatha.getRecords();
|
81
|
taxaToChangeRank.addAll(agnathaList);
|
82
|
Pager<TaxonBase> gnathostomata = sc.appCtrInit.getTaxonService().findTaxaByName(TaxonBase.class, "Gnathostomata", null, null, null, "*", Rank.INFRAPHYLUM(), 10, 0);
|
83
|
List<TaxonBase> gnathostomataList = gnathostomata.getRecords();
|
84
|
taxaToChangeRank.addAll(gnathostomataList);
|
85
|
|
86
|
sc.setSpecificRank(taxaToChangeRank, Rank.SUPERCLASS());
|
87
|
|
88
|
//ermsTaxon is accepted, fauna eu taxon is synonym
|
89
|
//ermsTaxon is synonym, faunaEu is accepted
|
90
|
|
91
|
sc.mergeDiffStatus();
|
92
|
|
93
|
//erms is synonym, faunaEu as well
|
94
|
|
95
|
// erms is accepted, faunaEu as well
|
96
|
|
97
|
}
|
98
|
|
99
|
private static List<List<String>> readCsvFile(String fileName){
|
100
|
|
101
|
List<List<String>> result = new ArrayList<>();
|
102
|
File file = new File(fileName);
|
103
|
BufferedReader bufRdr;
|
104
|
try {
|
105
|
bufRdr = new BufferedReader(new FileReader(file));
|
106
|
String line = null;
|
107
|
//read each line of text file
|
108
|
while((line = bufRdr.readLine()) != null){
|
109
|
StringTokenizer st = new StringTokenizer(line,",");
|
110
|
List<String> rowList = new ArrayList<>();
|
111
|
while (st.hasMoreTokens()){
|
112
|
//get next token and store it in the array
|
113
|
rowList.add(st.nextToken());
|
114
|
}
|
115
|
result.add(rowList);
|
116
|
}
|
117
|
//close the file
|
118
|
bufRdr.close();
|
119
|
} catch (FileNotFoundException e) {
|
120
|
// TODO Auto-generated catch block
|
121
|
e.printStackTrace();
|
122
|
} catch (IOException e) {
|
123
|
// TODO Auto-generated catch block
|
124
|
e.printStackTrace();
|
125
|
}
|
126
|
return result;
|
127
|
}
|
128
|
|
129
|
|
130
|
private void mergeAuthors(){
|
131
|
List<List<String>> authors = readCsvFile(sFileName + "_authors.csv");
|
132
|
//authors: get firstAuthor if isFauEu = 1 otherwise get secondAuthor
|
133
|
|
134
|
Iterator<List<String>> authorIterator = authors.iterator();
|
135
|
List<String> row;
|
136
|
TaxonBase<?> taxonFaunaEu;
|
137
|
TaxonBase<?> taxonErms;
|
138
|
List<TaxonBase<?>> taxaToSave = new ArrayList<>();
|
139
|
while (authorIterator.hasNext()){
|
140
|
row = authorIterator.next();
|
141
|
UUID uuidFaunaEu = UUID.fromString(row.get(faunaEuUuid));
|
142
|
UUID uuidErms = UUID.fromString(row.get(ermsUuid));
|
143
|
taxonFaunaEu = appCtrInit.getTaxonService().find(uuidFaunaEu);
|
144
|
taxonErms = appCtrInit.getTaxonService().find(uuidErms);
|
145
|
|
146
|
if (Integer.parseInt(row.get(18)) == 1){
|
147
|
//isFaunaEu = 1 -> copy the author of Fauna Europaea to Erms
|
148
|
if (((IZoologicalName)taxonFaunaEu.getName()).getBasionymAuthorship()!= null){
|
149
|
((IZoologicalName)taxonErms.getName()).setBasionymAuthorship(((IZoologicalName)taxonFaunaEu.getName()).getBasionymAuthorship());
|
150
|
}
|
151
|
if (((IZoologicalName)taxonFaunaEu.getName()).getCombinationAuthorship()!= null){
|
152
|
((IZoologicalName)taxonErms.getName()).setCombinationAuthorship(((IZoologicalName)taxonFaunaEu.getName()).getCombinationAuthorship());
|
153
|
}
|
154
|
((IZoologicalName)taxonErms.getName()).generateAuthorship();
|
155
|
taxaToSave.add(taxonErms);
|
156
|
}else{
|
157
|
if (((IZoologicalName)taxonErms.getName()).getBasionymAuthorship()!= null){
|
158
|
((IZoologicalName)taxonFaunaEu.getName()).setBasionymAuthorship(((IZoologicalName)taxonErms.getName()).getBasionymAuthorship());
|
159
|
}
|
160
|
if (((IZoologicalName)taxonErms.getName()).getCombinationAuthorship()!= null){
|
161
|
((IZoologicalName)taxonFaunaEu.getName()).setCombinationAuthorship(((IZoologicalName)taxonErms.getName()).getCombinationAuthorship());
|
162
|
}
|
163
|
((IZoologicalName)taxonFaunaEu.getName()).generateAuthorship();
|
164
|
taxaToSave.add(taxonFaunaEu);
|
165
|
}
|
166
|
}
|
167
|
}
|
168
|
|
169
|
private void setSpecificRank(List<TaxonBase> taxa, Rank rank){
|
170
|
for (TaxonBase<?> taxon: taxa){
|
171
|
taxon.getName().setRank(rank);
|
172
|
}
|
173
|
}
|
174
|
|
175
|
private void mergeDiffStatus(){
|
176
|
List<List<String>> diffStatus = readCsvFile(sFileName + "_status.csv");
|
177
|
|
178
|
//find all taxa accepted in erms, but synonyms in FauEu and the same rank
|
179
|
List<List<String>> accErmsSynFaunaEu = new ArrayList<List<String>>();
|
180
|
for (List<String> rowList: diffStatus){
|
181
|
if ((rowList.get(5).equals("synonym")) && (rowList.get(rankFaunaEu).equals(rowList.get(rankErms)))){
|
182
|
//both conditions are true
|
183
|
accErmsSynFaunaEu.add(rowList);
|
184
|
}
|
185
|
}
|
186
|
mergeErmsAccFaunaEuSyn(accErmsSynFaunaEu);
|
187
|
|
188
|
//find all taxa accepted in faunaEu, but synonyms in Erms and the same rank
|
189
|
List<List<String>> synErmsAccFaunaEu = new ArrayList<List<String>>();
|
190
|
for (List<String> rowList: diffStatus){
|
191
|
if ((rowList.get(5).equals("accepted")) && (rowList.get(rankFaunaEu).equals(rowList.get(rankErms)))){
|
192
|
//both conditions are true
|
193
|
synErmsAccFaunaEu.add(rowList);
|
194
|
}
|
195
|
}
|
196
|
mergeErmsSynFaunaEuAcc(synErmsAccFaunaEu);
|
197
|
|
198
|
|
199
|
}
|
200
|
|
201
|
private void mergeSameStatus(){
|
202
|
List<List<String>> sameStatus = readCsvFile(sFileName + "_names.csv");
|
203
|
|
204
|
TaxonBase<?> taxonFaunaEu;
|
205
|
TaxonBase<?> taxonErms;
|
206
|
|
207
|
for (List<String> row: sameStatus){
|
208
|
taxonFaunaEu = appCtrInit.getTaxonService().find(UUID.fromString(row.get(faunaEuUuid)));
|
209
|
taxonErms = appCtrInit.getTaxonService().find(UUID.fromString(row.get(ermsUuid)));
|
210
|
moveAllInformationsFromFaunaEuToErms(taxonFaunaEu, taxonErms);
|
211
|
if (taxonErms instanceof Taxon){
|
212
|
moveFaunaEuSynonymsToErmsTaxon((Taxon)taxonFaunaEu, (Taxon)taxonErms);
|
213
|
}
|
214
|
}
|
215
|
}
|
216
|
|
217
|
private void mergeErmsAccFaunaEuSyn(List<List<String>> ermsAccFaEuSyn){
|
218
|
|
219
|
// update nameRelationships -> if the nameRelationship does not exist, then create a new one with ermsAcc as relatedTo TaxonName
|
220
|
updateNameRelationships(ermsAccFaEuSyn);
|
221
|
|
222
|
//delete all synonyms of FaunaEu Syn
|
223
|
for (List<String> rowList: ermsAccFaEuSyn){
|
224
|
UUID faunaUUID = UUID.fromString(rowList.get(faunaEuUuid));
|
225
|
//UUID ermsUUID = UUID.fromString(rowList.get(ermsUuid));
|
226
|
Synonym syn = (Synonym)appCtrInit.getTaxonService().find(faunaUUID);
|
227
|
appCtrInit.getTaxonService().deleteSynonym(syn, null);
|
228
|
}
|
229
|
|
230
|
//merge the infos of
|
231
|
}
|
232
|
|
233
|
private void mergeErmsSynFaunaEuAcc (List<List<String>> ermsAccFaEuSyn){
|
234
|
//occurence: verknüpfe statt dem Fauna Europaea Taxon das akzeptierte Taxon, des Synonyms mit der Occurence (CDM -> distribution)
|
235
|
//suche distribution (über das Taxon der TaxonDescription), dessen Taxon, das entsprechende Fauna Eu Taxon ist und verkn�pfe es mit dem akzeptieren Taxon des Erms Syn
|
236
|
for (List<String> row: ermsAccFaEuSyn){
|
237
|
Taxon taxonFaunaEu = (Taxon)appCtrInit.getTaxonService().find(UUID.fromString(row.get(faunaEuUuid)));
|
238
|
Synonym synErms = (Synonym)appCtrInit.getTaxonService().find(UUID.fromString(row.get(ermsUuid)));
|
239
|
synErms = HibernateProxyHelper.deproxy(synErms, Synonym.class);
|
240
|
Taxon taxonErms = synErms.getAcceptedTaxon();
|
241
|
|
242
|
if (taxonErms == null){
|
243
|
logger.debug("There is no accepted taxon for the synonym" + synErms.getTitleCache());
|
244
|
}
|
245
|
|
246
|
Set<Feature> features = new HashSet<>();
|
247
|
features.add(Feature.DISTRIBUTION());
|
248
|
List<String> propertyPaths = new ArrayList<>();
|
249
|
propertyPaths.add("inDescription.Taxon.*");
|
250
|
List<Distribution> distributions = appCtrInit.getDescriptionService().getDescriptionElementsForTaxon(taxonFaunaEu, features, Distribution.class, 10, 0, null);
|
251
|
|
252
|
|
253
|
for(Distribution distribution: distributions){
|
254
|
TaxonDescription description = (TaxonDescription)distribution.getInDescription();
|
255
|
TaxonDescription newDescription = TaxonDescription.NewInstance(taxonErms);
|
256
|
newDescription.addElement(distribution);
|
257
|
try{
|
258
|
appCtrInit.getDescriptionService().delete(description);
|
259
|
}catch (Exception e){
|
260
|
logger.debug("The description of" + description.getTaxon().getTitleCache() + description.getTitleCache() + "can't be deleted because it is referenced.");
|
261
|
}
|
262
|
}
|
263
|
|
264
|
|
265
|
//Child-Parent Relationship aktualisieren -> dem Child des Fauna Europaea Taxons als parent das akzeptierte Taxon von synErms
|
266
|
Set<TaxonNode> nodesErms = taxonErms.getTaxonNodes();
|
267
|
Set<TaxonNode> nodesFaunaEu =taxonFaunaEu.getTaxonNodes();
|
268
|
if (nodesFaunaEu.size()>1 || nodesFaunaEu.isEmpty()){
|
269
|
|
270
|
}else{
|
271
|
Iterator<TaxonNode> iteratorNodesErms = nodesErms.iterator();
|
272
|
|
273
|
Iterator<TaxonNode> iteratorNodesFaunaEu = nodesFaunaEu.iterator();
|
274
|
TaxonNode node = iteratorNodesFaunaEu.next();
|
275
|
List<TaxonNode> children = node.getChildNodes();
|
276
|
Iterator<TaxonNode> childrenIterator = children.iterator();
|
277
|
TaxonNode childNode;
|
278
|
if (iteratorNodesErms.hasNext()){
|
279
|
TaxonNode ermsNode = iteratorNodesErms.next();
|
280
|
while (childrenIterator.hasNext()){
|
281
|
childNode = childrenIterator.next();
|
282
|
ermsNode.addChildNode(childNode, childNode.getReference(), childNode.getMicroReference());
|
283
|
}
|
284
|
}
|
285
|
|
286
|
}
|
287
|
moveFaunaEuSynonymsToErmsTaxon(taxonFaunaEu, taxonErms);
|
288
|
moveAllInformationsFromFaunaEuToErms(taxonFaunaEu, taxonErms);
|
289
|
moveOriginalDbToErmsTaxon(taxonFaunaEu, taxonErms);
|
290
|
//neue sec Referenz an das ErmsTaxon oder an das Synonym und Taxon oder nur Synonym??
|
291
|
try{
|
292
|
deleteFaunaEuTaxon(taxonFaunaEu);
|
293
|
}catch(ReferencedObjectUndeletableException e){
|
294
|
logger.debug("The taxon " + taxonFaunaEu.getTitleCache() + " can't be deleted because it is referenced.");
|
295
|
}
|
296
|
}
|
297
|
|
298
|
}
|
299
|
|
300
|
|
301
|
|
302
|
private void updateNameRelationships(List<List<String>> ermsAccFaEuSyn){
|
303
|
//suche alle NameRelationships aus FaunaEu und Erms, wo (faunaEu)relatedFrom.name.titleCache = (erms)relatedFrom.name.titleCache und ersetze in der faunaEu Relationship den relatedTo.name durch den relatedTo.name der erms-relationship
|
304
|
//wenn es diese relationship noch nicht gibt und der typ der gleiche ist!!
|
305
|
//wenn der relatedTo Name zu einem Erms Taxon und einem FaunaEu Synonym gehört
|
306
|
|
307
|
Synonym synFaunaEu;
|
308
|
Taxon taxonErms;
|
309
|
for (List<String> row: ermsAccFaEuSyn){
|
310
|
synFaunaEu = (Synonym)appCtrInit.getTaxonService().find(UUID.fromString(row.get(faunaEuUuid)));
|
311
|
taxonErms = (Taxon)appCtrInit.getTaxonService().find(UUID.fromString(row.get(ermsUuid)));
|
312
|
List<NameRelationship> relSynFaunaEu = appCtrInit.getNameService().listToNameRelationships(synFaunaEu.getName(), null, 100, 0, null, null);
|
313
|
List<NameRelationship> relTaxonErms = appCtrInit.getNameService().listToNameRelationships(taxonErms.getName(), null, 100, 0, null, null);
|
314
|
|
315
|
List<NameRelationship> deleteRel = new ArrayList<NameRelationship>();
|
316
|
for (NameRelationship relFauEu: relSynFaunaEu){
|
317
|
boolean createNewRelationship = true;
|
318
|
for (NameRelationship relErms: relTaxonErms){
|
319
|
if ((relErms.getFromName().getTitleCache().equals(relFauEu.getFromName().getTitleCache())) && (relErms.getToName().getTitleCache().equals(relFauEu.getFromName().getTitleCache()))){
|
320
|
//delete the faunaEu relationship because there exist an analogous relationship in erms
|
321
|
deleteRel.add(relFauEu);
|
322
|
createNewRelationship = false;
|
323
|
break;
|
324
|
}
|
325
|
}
|
326
|
if (createNewRelationship){
|
327
|
//if relationship does not exist, create a new one with erms synonym
|
328
|
taxonErms.getName().addRelationshipFromName(relFauEu.getFromName(), relFauEu.getType(), relFauEu.getRuleConsidered(), null);
|
329
|
}
|
330
|
}
|
331
|
}
|
332
|
}
|
333
|
|
334
|
private void updateSynonymRelationships(List<List<String>> ermsSynFaEuAcc){
|
335
|
// -- Update queries for RelTaxon (synonym relationships - move relationships to ERMS accepted taxon if not already existent or delete if already existent)
|
336
|
// UPDATE RelTaxon_1 SET RelTaxon_1.TaxonFk2 = RT.TaxonFk2
|
337
|
// FROM Taxon AS ERMSSyn INNER JOIN
|
338
|
// Taxon AS FaEuAcc ON ERMSSyn.RankFk = FaEuAcc.RankFk AND ERMSSyn.FullName = FaEuAcc.FullName AND
|
339
|
// ERMSSyn.TaxonStatusFk <> ISNULL(FaEuAcc.TaxonStatusFk, 0) INNER JOIN
|
340
|
// RelTaxon AS RT ON ERMSSyn.TaxonId = RT.TaxonFk1 INNER JOIN
|
341
|
// RelTaxon AS RelTaxon_1 ON FaEuAcc.TaxonId = RelTaxon_1.TaxonFk2 INNER JOIN
|
342
|
// Taxon AS FaEuSyn ON RelTaxon_1.TaxonFk1 = FaEuSyn.TaxonId LEFT OUTER JOIN
|
343
|
// Taxon AS ERMSAllSyn ON RT.TaxonFk1 = ERMSAllSyn.TaxonId AND FaEuSyn.FullName <> ERMSAllSyn.FullName --(!!)
|
344
|
// WHERE (ERMSSyn.OriginalDB = N'ERMS') AND (RT.RelTaxonQualifierFk > 100) AND (ERMSSyn.TaxonStatusFk <> 1) AND (ERMSSyn.KingdomFk = 2) AND
|
345
|
// (FaEuAcc.OriginalDB = N'FaEu') AND (RelTaxon_1.RelTaxonQualifierFk > 100)
|
346
|
Taxon taxonFaunaEu;
|
347
|
Synonym synErms;
|
348
|
Taxon taxonErms;
|
349
|
Set<Taxon> acceptedTaxa = new HashSet<Taxon>();
|
350
|
for (List<String> row: ermsSynFaEuAcc){
|
351
|
taxonFaunaEu = (Taxon)appCtrInit.getTaxonService().find(UUID.fromString(row.get(faunaEuUuid)));
|
352
|
synErms = (Synonym)appCtrInit.getTaxonService().find(UUID.fromString(row.get(ermsUuid)));
|
353
|
acceptedTaxa.clear();
|
354
|
acceptedTaxa.add( synErms.getAcceptedTaxon());
|
355
|
if (!acceptedTaxa.isEmpty()){
|
356
|
taxonErms = acceptedTaxa.iterator().next();
|
357
|
if (acceptedTaxa.size() > 1){
|
358
|
logger.debug("There are more than one accepted taxon for synonym " + synErms.getTitleCache());
|
359
|
}
|
360
|
}else{
|
361
|
taxonErms = null;
|
362
|
logger.debug("There is no accepted taxon for synonym " + synErms.getTitleCache());
|
363
|
}
|
364
|
|
365
|
if (taxonErms != null){
|
366
|
Pager<Synonym> synsTaxonFaunaEuPager = appCtrInit.getTaxonService().getSynonyms(taxonFaunaEu, null, null, null, null, null);
|
367
|
List<Synonym> synsTaxonFaunaEu = synsTaxonFaunaEuPager.getRecords();
|
368
|
|
369
|
Pager<Synonym> synsTaxonErmsPager = appCtrInit.getTaxonService().getSynonyms(taxonErms, null, null, null, null, null);
|
370
|
List<Synonym> synsTaxonErms = synsTaxonErmsPager.getRecords();
|
371
|
|
372
|
List<Synonym> deleteRel = new ArrayList<>();
|
373
|
for (Synonym synFauEu: synsTaxonFaunaEu){
|
374
|
//TODO: wenn es noch keine SynonymRelationship gibt zu einem Synonym mit gleichem Namen,
|
375
|
//dann erzeuge die SynonymRelationship vom FaunaEuSyn (des FaunaEu Taxons, das
|
376
|
//identischen Namen hat) zum akzeptierten Taxon des Erms Syn
|
377
|
boolean createNewRelationship = true;
|
378
|
for (Synonym relErms: synsTaxonErms){
|
379
|
if (relErms.getTitleCache().equals(synFauEu.getTitleCache())){
|
380
|
//es gibt schon eine Relationship zu einem Synonym mit dem gleichen Namen wie das FaunaEu Synonym, also Relationship l�schen.
|
381
|
createNewRelationship = false;
|
382
|
break;
|
383
|
}
|
384
|
}
|
385
|
if (createNewRelationship){
|
386
|
taxonErms.addSynonym(synFauEu, synFauEu.getType());
|
387
|
}
|
388
|
deleteRel.add(synFauEu);
|
389
|
}
|
390
|
}
|
391
|
}
|
392
|
}
|
393
|
|
394
|
private void deleteFaunaEuTaxon(Taxon taxonFaunaEu) throws ReferencedObjectUndeletableException {
|
395
|
appCtrInit.getTaxonService().delete(taxonFaunaEu);
|
396
|
}
|
397
|
|
398
|
//wenn Name und Rang identisch sind und auch der Status gleich, dann alle Informationen vom Fauna Europaea Taxon/Synonym zum Erms Taxon/Synonym
|
399
|
|
400
|
private void moveAllInformationsFromFaunaEuToErms(TaxonBase<?> faunaEu, TaxonBase<?> erms){
|
401
|
Set<Annotation> annotations = faunaEu.getAnnotations();
|
402
|
Set<Extension> extensions = faunaEu.getExtensions();
|
403
|
Set<Marker> markers = faunaEu.getMarkers();
|
404
|
List<Credit> credits = faunaEu.getCredits();
|
405
|
if (faunaEu instanceof Taxon){
|
406
|
Set<TaxonDescription> descriptions = ((Taxon)faunaEu).getDescriptions();
|
407
|
Set<Taxon> misappliedNames = ((Taxon)faunaEu).getMisappliedNames(true);
|
408
|
|
409
|
if (erms instanceof Taxon){
|
410
|
Iterator<TaxonDescription> descriptionsIterator = descriptions.iterator();
|
411
|
TaxonDescription description;
|
412
|
while (descriptionsIterator.hasNext()){
|
413
|
description = descriptionsIterator.next();
|
414
|
((Taxon) erms).addDescription(description);
|
415
|
}
|
416
|
|
417
|
Iterator<Taxon> misappliedNamesIterator = misappliedNames.iterator();
|
418
|
Taxon misappliedName;
|
419
|
while (misappliedNamesIterator.hasNext()){
|
420
|
misappliedName = misappliedNamesIterator.next();
|
421
|
((Taxon) erms).addMisappliedName(misappliedName, null, null);
|
422
|
}
|
423
|
}
|
424
|
}
|
425
|
|
426
|
//move all these informations to the erms taxon
|
427
|
Iterator<Annotation> annotationsIterator = annotations.iterator();
|
428
|
Annotation annotation;
|
429
|
while (annotationsIterator.hasNext()){
|
430
|
annotation = annotationsIterator.next();
|
431
|
erms.addAnnotation(annotation);
|
432
|
}
|
433
|
|
434
|
Iterator<Extension> extensionIterator = extensions.iterator();
|
435
|
Extension extension;
|
436
|
while (extensionIterator.hasNext()){
|
437
|
extension = extensionIterator.next();
|
438
|
erms.addExtension(extension);
|
439
|
}
|
440
|
|
441
|
Iterator<Marker> markerIterator = markers.iterator();
|
442
|
Marker marker;
|
443
|
while (markerIterator.hasNext()){
|
444
|
marker = markerIterator.next();
|
445
|
erms.addMarker(marker);
|
446
|
}
|
447
|
|
448
|
for (Credit credit: credits){
|
449
|
erms.addCredit(credit);
|
450
|
}
|
451
|
}
|
452
|
|
453
|
//if name, rank, and status (accepted) are the same, then move the synonyms of faunaEu taxon to the erms taxon
|
454
|
|
455
|
private void moveFaunaEuSynonymsToErmsTaxon(Taxon faunaEu, Taxon erms){
|
456
|
Set<Synonym> syns =faunaEu.getSynonyms();
|
457
|
Iterator<Synonym> synRelIterator = syns.iterator();
|
458
|
while (synRelIterator.hasNext()){
|
459
|
Synonym syn = synRelIterator.next();
|
460
|
faunaEu.removeSynonym(syn);
|
461
|
erms.addSynonym(syn, syn.getType());
|
462
|
}
|
463
|
}
|
464
|
|
465
|
//after merging faunaEu taxon and erms taxon, the originalSource of the faunaEu taxon has to be moved to the erms taxon
|
466
|
private void moveOriginalDbToErmsTaxon(TaxonBase faunaEu, TaxonBase erms){
|
467
|
Set<IdentifiableSource> sourcesFaunaEu = faunaEu.getSources();
|
468
|
IdentifiableSource sourceFaunaEu = sourcesFaunaEu.iterator().next();
|
469
|
erms.addSource(sourceFaunaEu);
|
470
|
}
|
471
|
|
472
|
//merged taxon should have a new sec reference
|
473
|
private void addNewSecForMergedTaxon(Taxon taxon, Reference sec){
|
474
|
taxon.setSec(sec);
|
475
|
taxon.setUuid(UUID.randomUUID());
|
476
|
}
|
477
|
|
478
|
// ----------- methods for merging Erms synonyms and Fauna Europaea Taxon
|
479
|
|
480
|
}
|