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