Project

General

Profile

Download (19.6 KB) Statistics
| Branch: | Revision:
1
package eu.etaxonomy.cdm.app.pesi.merging;
2

    
3
import java.io.BufferedReader;
4
import java.io.File;
5
import java.io.FileReader;
6
import java.io.IOException;
7
import java.util.ArrayList;
8
import java.util.HashSet;
9
import java.util.Iterator;
10
import java.util.List;
11
import java.util.Set;
12
import java.util.StringTokenizer;
13
import java.util.UUID;
14

    
15
import org.apache.log4j.Logger;
16

    
17
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
18
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
19
import eu.etaxonomy.cdm.api.service.pager.Pager;
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.hibernate.HibernateProxyHelper;
24
import eu.etaxonomy.cdm.io.api.application.CdmIoApplicationController;
25
import eu.etaxonomy.cdm.model.common.Annotation;
26
import eu.etaxonomy.cdm.model.common.Credit;
27
import eu.etaxonomy.cdm.model.common.Extension;
28
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
29
import eu.etaxonomy.cdm.model.common.Marker;
30
import eu.etaxonomy.cdm.model.description.Distribution;
31
import eu.etaxonomy.cdm.model.description.Feature;
32
import eu.etaxonomy.cdm.model.description.TaxonDescription;
33
import eu.etaxonomy.cdm.model.name.IZoologicalName;
34
import eu.etaxonomy.cdm.model.name.NameRelationship;
35
import eu.etaxonomy.cdm.model.name.Rank;
36
import eu.etaxonomy.cdm.model.reference.Reference;
37
import eu.etaxonomy.cdm.model.taxon.Synonym;
38
import eu.etaxonomy.cdm.model.taxon.Taxon;
39
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
40
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
41

    
42
public class FaunaEuErmsMergeActivator {
43

    
44
//	static final ICdmDataSource faunaEuropaeaSource = CdmDestinations.cdm_test_patricia();
45
	static final ICdmDataSource faunaEuropaeaSource = CdmDestinations.localH2();
46

    
47
	static final int faunaEuUuid = 0;
48
	static final int ermsUuid = 9;
49
	static final int rankFaunaEu = 4;
50
	static final int rankErms = 13;
51

    
52
	CdmApplicationController appCtrInit;
53

    
54
	private static final Logger logger = Logger.getLogger(FaunaEuErmsMergeActivator.class);
55

    
56
	//csv files starting with...
57
	static String sFileName = "c:\\test";
58

    
59
	private void initDb(ICdmDataSource db) {
60
		// Init source DB
61
		appCtrInit = CdmIoApplicationController.NewInstance(db, DbSchemaValidation.VALIDATE, false);
62
	}
63

    
64
	public static void main(String[] args) {
65

    
66
		FaunaEuErmsMergeActivator sc = new FaunaEuErmsMergeActivator();
67

    
68
		sc.initDb(faunaEuropaeaSource);
69
//we also need to merge names completely identical!
70
		sc.mergeAuthors();
71

    
72
		//set the ranks of Agnatha and Gnathostomata to 50 instead of 45
73
		List<TaxonBase> taxaToChangeRank = new ArrayList<>();
74
		Pager<TaxonBase> agnatha = sc.appCtrInit.getTaxonService().findTaxaByName(TaxonBase.class, "Agnatha", null, null, null, "*", Rank.INFRAPHYLUM(), 10, 0, null);
75
		List<TaxonBase> agnathaList = agnatha.getRecords();
76
		taxaToChangeRank.addAll(agnathaList);
77
		Pager<TaxonBase> gnathostomata = sc.appCtrInit.getTaxonService().findTaxaByName(TaxonBase.class, "Gnathostomata", null, null, null, "*", Rank.INFRAPHYLUM(), 10, 0, null);
78
		List<TaxonBase> gnathostomataList = gnathostomata.getRecords();
79
		taxaToChangeRank.addAll(gnathostomataList);
80

    
81
		sc.setSpecificRank(taxaToChangeRank, Rank.SUPERCLASS());
82

    
83
		//ermsTaxon is accepted, fauna eu taxon is synonym
84
		//ermsTaxon is synonym, faunaEu is accepted
85

    
86
		sc.mergeDiffStatus();
87

    
88
		//erms is synonym, faunaEu as well
89

    
90
		// erms is accepted, faunaEu as well
91

    
92
	}
93

    
94
	private static List<List<String>> readCsvFile(String fileName){
95

    
96
		List<List<String>> result = new ArrayList<>();
97
		File file = new File(fileName);
98
		BufferedReader bufRdr;
99
		try {
100
			bufRdr = new BufferedReader(new FileReader(file));
101
			String line = null;
102
			//read each line of text file
103
			while((line = bufRdr.readLine()) != null){
104
				StringTokenizer st = new StringTokenizer(line,",");
105
				List<String> rowList = new ArrayList<>();
106
				while (st.hasMoreTokens()){
107
					//get next token and store it in the array
108
					rowList.add(st.nextToken());
109
				}
110
			result.add(rowList);
111
			}
112
			//close the file
113
			bufRdr.close();
114
		} catch (IOException e) {
115
			e.printStackTrace();
116
		}
117
		return result;
118
	}
119

    
120

    
121
	private void mergeAuthors(){
122
		List<List<String>> authors = readCsvFile(sFileName + "_authors.csv");
123
		//authors: get firstAuthor if isFauEu = 1 otherwise get secondAuthor
124

    
125
		Iterator<List<String>> authorIterator = authors.iterator();
126
		List<String> row;
127
		TaxonBase<?> taxonFaunaEu;
128
		TaxonBase<?> taxonErms;
129
		List<TaxonBase<?>> taxaToSave = new ArrayList<>();
130
		while (authorIterator.hasNext()){
131
			row = authorIterator.next();
132
			UUID uuidFaunaEu = UUID.fromString(row.get(faunaEuUuid));
133
			UUID uuidErms = UUID.fromString(row.get(ermsUuid));
134
			taxonFaunaEu = appCtrInit.getTaxonService().find(uuidFaunaEu);
135
			taxonErms = appCtrInit.getTaxonService().find(uuidErms);
136
// which information should be used can be found in last row -> needs to be done manually
137
			if (Integer.parseInt(row.get(18)) == 1){
138
				//isFaunaEu = 1 -> copy the author of Fauna Europaea to Erms
139
				if (((IZoologicalName)taxonFaunaEu.getName()).getBasionymAuthorship()!= null){
140
					((IZoologicalName)taxonErms.getName()).setBasionymAuthorship(((IZoologicalName)taxonFaunaEu.getName()).getBasionymAuthorship());
141
				}
142
				if (((IZoologicalName)taxonFaunaEu.getName()).getCombinationAuthorship()!= null){
143
					((IZoologicalName)taxonErms.getName()).setCombinationAuthorship(((IZoologicalName)taxonFaunaEu.getName()).getCombinationAuthorship());
144
				}
145
				((IZoologicalName)taxonErms.getName()).generateAuthorship();
146
				taxaToSave.add(taxonErms);
147
			}else{
148
				if (((IZoologicalName)taxonErms.getName()).getBasionymAuthorship()!= null){
149
					((IZoologicalName)taxonFaunaEu.getName()).setBasionymAuthorship(((IZoologicalName)taxonErms.getName()).getBasionymAuthorship());
150
				}
151
				if (((IZoologicalName)taxonErms.getName()).getCombinationAuthorship()!= null){
152
					((IZoologicalName)taxonFaunaEu.getName()).setCombinationAuthorship(((IZoologicalName)taxonErms.getName()).getCombinationAuthorship());
153
				}
154
				((IZoologicalName)taxonFaunaEu.getName()).generateAuthorship();
155
				taxaToSave.add(taxonFaunaEu);
156
			}
157
		}
158
	}
159

    
160
	private void setSpecificRank(List<TaxonBase> taxa, Rank rank){
161
		for (TaxonBase<?> taxon: taxa){
162
			taxon.getName().setRank(rank);
163
		}
164
	}
165

    
166
	private void mergeDiffStatus(){
167
		List<List<String>> diffStatus = readCsvFile(sFileName + "_status.csv");
168

    
169
		//find all taxa accepted in erms, but synonyms in FauEu  and the same rank
170
		List<List<String>> accErmsSynFaunaEu = new ArrayList<List<String>>();
171
		for (List<String> rowList: diffStatus){
172
			if ((rowList.get(5).equals("synonym")) && (rowList.get(rankFaunaEu).equals(rowList.get(rankErms)))){
173
				//both conditions are true
174
				accErmsSynFaunaEu.add(rowList);
175
			}
176
		}
177
		mergeErmsAccFaunaEuSyn(accErmsSynFaunaEu);
178

    
179
		//find all taxa accepted in faunaEu, but synonyms in Erms and the same rank
180
		List<List<String>> synErmsAccFaunaEu = new ArrayList<List<String>>();
181
		for (List<String> rowList: diffStatus){
182
			if ((rowList.get(5).equals("accepted")) && (rowList.get(rankFaunaEu).equals(rowList.get(rankErms)))){
183
				//both conditions are true
184
				synErmsAccFaunaEu.add(rowList);
185
			}
186
		}
187
		mergeErmsSynFaunaEuAcc(synErmsAccFaunaEu);
188

    
189

    
190
	}
191

    
192
	private void mergeSameStatus(){
193
		List<List<String>> sameStatus = readCsvFile(sFileName + "_names.csv");
194

    
195
		TaxonBase<?> taxonFaunaEu;
196
		TaxonBase<?> taxonErms;
197

    
198
		for (List<String> row: sameStatus){
199
			taxonFaunaEu = appCtrInit.getTaxonService().find(UUID.fromString(row.get(faunaEuUuid)));
200
			taxonErms = appCtrInit.getTaxonService().find(UUID.fromString(row.get(ermsUuid)));
201
			moveAllInformationsFromFaunaEuToErms(taxonFaunaEu, taxonErms);
202
			if (taxonErms instanceof Taxon){
203
				moveFaunaEuSynonymsToErmsTaxon((Taxon)taxonFaunaEu, (Taxon)taxonErms);
204
			}
205
		}
206
	}
207

    
208
	private void mergeErmsAccFaunaEuSyn(List<List<String>> ermsAccFaEuSyn){
209

    
210
		// update nameRelationships -> if the nameRelationship does not exist, then create a new one with ermsAcc as relatedTo TaxonName
211
		updateNameRelationships(ermsAccFaEuSyn);
212

    
213
		//delete all synonyms of FaunaEu Syn TODO: move sources and additional informations to erms taxon
214
		for (List<String> rowList: ermsAccFaEuSyn){
215
			UUID faunaUUID = UUID.fromString(rowList.get(faunaEuUuid));
216
			//UUID ermsUUID = UUID.fromString(rowList.get(ermsUuid));
217
			Synonym syn = (Synonym)appCtrInit.getTaxonService().find(faunaUUID);
218
			// remove synonym from taxon then delete
219
			appCtrInit.getTaxonService().deleteSynonym(syn, null);
220
		}
221

    
222
		//merge the infos of
223
	}
224

    
225
	private  void mergeErmsSynFaunaEuAcc (List<List<String>> ermsAccFaEuSyn){
226
		//occurence: connect instead of Fauna Europaea taxon the accepted taxon of the synonym with the occurrence (CDM -> distribution)
227
		//search distribution (via taxon of the taxon description), of which the taxon is the according Fauna Eu taxon and connect it with the accepted taxon of the ERMS syn
228
		for (List<String> row: ermsAccFaEuSyn){
229
		    Taxon taxonFaunaEu = (Taxon)appCtrInit.getTaxonService().find(UUID.fromString(row.get(faunaEuUuid)));
230
			Synonym synErms = (Synonym)appCtrInit.getTaxonService().find(UUID.fromString(row.get(ermsUuid)));
231
			synErms = HibernateProxyHelper.deproxy(synErms, Synonym.class);
232
			Taxon taxonErms = synErms.getAcceptedTaxon();
233

    
234
			if (taxonErms == null){
235
				logger.debug("There is no accepted taxon for the synonym" + synErms.getTitleCache());
236
			}
237

    
238
			Set<Feature> features = new HashSet<>();
239
			features.add(Feature.DISTRIBUTION());
240
			List<String> propertyPaths = new ArrayList<>();
241
			propertyPaths.add("inDescription.Taxon.*");
242
			List<Distribution> distributions = appCtrInit.getDescriptionService().getDescriptionElementsForTaxon(taxonFaunaEu, features, Distribution.class, 10, 0, null);
243

    
244

    
245
			for(Distribution distribution: distributions){
246
				TaxonDescription description = (TaxonDescription)distribution.getInDescription();
247
				TaxonDescription newDescription = TaxonDescription.NewInstance(taxonErms);
248
				newDescription.addElement(distribution);
249
				try{
250
					appCtrInit.getDescriptionService().delete(description);
251
				}catch (Exception e){
252
					logger.debug("The description of" + description.getTaxon().getTitleCache() + description.getTitleCache() + "can't be deleted because it is referenced.");
253
				}
254
			}
255

    
256
			//Child-Parent Relationship aktualisieren -> dem Child des Fauna Europaea Taxons als parent das akzeptierte Taxon von synErms
257
			Set<TaxonNode> nodesErms = taxonErms.getTaxonNodes();
258
			Set<TaxonNode> nodesFaunaEu =taxonFaunaEu.getTaxonNodes();
259
			if (nodesFaunaEu.size()>1 || nodesFaunaEu.isEmpty()){
260

    
261
			}else{
262
				Iterator<TaxonNode> iteratorNodesErms = nodesErms.iterator();
263

    
264
				Iterator<TaxonNode> iteratorNodesFaunaEu = nodesFaunaEu.iterator();
265
				TaxonNode node = iteratorNodesFaunaEu.next();
266
				List<TaxonNode> children = node.getChildNodes();
267
				Iterator<TaxonNode> childrenIterator = children.iterator();
268
				TaxonNode childNode;
269
				if (iteratorNodesErms.hasNext()){
270
					TaxonNode ermsNode = iteratorNodesErms.next();
271
					while (childrenIterator.hasNext()){
272
						childNode = childrenIterator.next();
273
						ermsNode.addChildNode(childNode, childNode.getReference(), childNode.getMicroReference());
274
					}
275
				}
276

    
277
			}
278
			//the fauna eu taxon should now only contain synonyms not existing in erms
279
			moveFaunaEuSynonymsToErmsTaxon(taxonFaunaEu, taxonErms);
280
			moveAllInformationsFromFaunaEuToErms(taxonFaunaEu, taxonErms);
281
			moveOriginalDbToErmsTaxon(taxonFaunaEu, taxonErms);
282
			//neue sec Referenz an das ErmsTaxon oder an das Synonym und Taxon oder nur Synonym??
283
			try{
284
				deleteFaunaEuTaxon(taxonFaunaEu);
285
			}catch(ReferencedObjectUndeletableException e){
286
				logger.debug("The taxon " + taxonFaunaEu.getTitleCache() + " can't be deleted because it is referenced.");
287
			}
288
		}
289

    
290
	}
291

    
292
	private void updateNameRelationships(List<List<String>> ermsAccFaEuSyn){
293
		//search all NameRelationships of FaunaEu and Erms, where (faunaEu)relatedFrom.name.titleCache = (erms)relatedFrom.name.titleCache and replace in faunaEu relationship the relatedTo.name by the relatedTo.name of the erms-relationship
294
		//if this relationship does not yet exist and the type is the same!!
295
		//if the relatedTo name belongs to an Erms taxon and to an FaunaEu synonym
296

    
297
		Synonym synFaunaEu;
298
		Taxon taxonErms;
299
		for (List<String> row: ermsAccFaEuSyn){
300
			synFaunaEu = (Synonym)appCtrInit.getTaxonService().find(UUID.fromString(row.get(faunaEuUuid)));
301
			taxonErms = (Taxon)appCtrInit.getTaxonService().find(UUID.fromString(row.get(ermsUuid)));
302
			List<NameRelationship> relSynFaunaEu = appCtrInit.getNameService().listToNameRelationships(synFaunaEu.getName(), null, 100, 0, null, null);
303
			List<NameRelationship> relTaxonErms = appCtrInit.getNameService().listToNameRelationships(taxonErms.getName(), null, 100, 0, null, null);
304

    
305
			List<NameRelationship> deleteRel = new ArrayList<>();
306
			for (NameRelationship relFauEu: relSynFaunaEu){
307
				boolean createNewRelationship = true;
308
				for (NameRelationship relErms: relTaxonErms){
309
					if ((relErms.getFromName().getTitleCache().equals(relFauEu.getFromName().getTitleCache())) && (relErms.getToName().getTitleCache().equals(relFauEu.getFromName().getTitleCache()))){
310
						//delete the faunaEu relationship because there exist an analogous relationship in erms
311
						deleteRel.add(relFauEu);
312
						createNewRelationship = false;
313
						break;
314
					}
315
				}
316
				if (createNewRelationship){
317
					//if relationship does not exist, create a new one with erms synonym
318
					taxonErms.getName().addRelationshipFromName(relFauEu.getFromName(), relFauEu.getType(), relFauEu.getRuleConsidered(), null);
319
				}
320
			}
321
		}
322
	}
323

    
324
	private void updateSynonymRelationships(List<List<String>> ermsSynFaEuAcc){
325
//		-- Update queries for RelTaxon (synonym relationships - move relationships to ERMS accepted taxon if not already existent or delete if already existent)
326
//		UPDATE RelTaxon_1 SET RelTaxon_1.TaxonFk2 = RT.TaxonFk2
327
//		FROM         Taxon AS ERMSSyn INNER JOIN
328
//		                      Taxon AS FaEuAcc ON ERMSSyn.RankFk = FaEuAcc.RankFk AND ERMSSyn.FullName = FaEuAcc.FullName AND
329
//		                      ERMSSyn.TaxonStatusFk <> ISNULL(FaEuAcc.TaxonStatusFk, 0) INNER JOIN
330
//		                      RelTaxon AS RT ON ERMSSyn.TaxonId = RT.TaxonFk1 INNER JOIN
331
//		                      RelTaxon AS RelTaxon_1 ON FaEuAcc.TaxonId = RelTaxon_1.TaxonFk2 INNER JOIN
332
//		                      Taxon AS FaEuSyn ON RelTaxon_1.TaxonFk1 = FaEuSyn.TaxonId LEFT OUTER JOIN
333
//		                      Taxon AS ERMSAllSyn ON RT.TaxonFk1 = ERMSAllSyn.TaxonId AND FaEuSyn.FullName <> ERMSAllSyn.FullName --(!!)
334
//		WHERE     (ERMSSyn.OriginalDB = N'ERMS') AND (RT.RelTaxonQualifierFk > 100) AND (ERMSSyn.TaxonStatusFk <> 1) AND (ERMSSyn.KingdomFk = 2) AND
335
//		                      (FaEuAcc.OriginalDB = N'FaEu') AND (RelTaxon_1.RelTaxonQualifierFk > 100)
336
		Taxon taxonFaunaEu;
337
		Synonym synErms;
338
		Taxon taxonErms;
339
		Set<Taxon> acceptedTaxa = new HashSet<>();
340
		for (List<String> row: ermsSynFaEuAcc){
341
			taxonFaunaEu = (Taxon)appCtrInit.getTaxonService().find(UUID.fromString(row.get(faunaEuUuid)));
342
			synErms = (Synonym)appCtrInit.getTaxonService().find(UUID.fromString(row.get(ermsUuid)));
343
			acceptedTaxa.clear();
344
			acceptedTaxa.add( synErms.getAcceptedTaxon());
345
			if (!acceptedTaxa.isEmpty()){
346
				taxonErms = acceptedTaxa.iterator().next();
347
				if (acceptedTaxa.size() > 1){
348
					logger.debug("There are more than one accepted taxon for synonym " + synErms.getTitleCache());
349
				}
350
			}else{
351
				taxonErms = null;
352
				logger.debug("There is no accepted taxon for synonym "  + synErms.getTitleCache());
353
			}
354

    
355
			if (taxonErms != null){
356
				Pager<Synonym> synsTaxonFaunaEuPager = appCtrInit.getTaxonService().getSynonyms(taxonFaunaEu, null, null, null, null, null);
357
				List<Synonym> synsTaxonFaunaEu = synsTaxonFaunaEuPager.getRecords();
358

    
359
				Pager<Synonym> synsTaxonErmsPager = appCtrInit.getTaxonService().getSynonyms(taxonErms, null, null, null, null, null);
360
				List<Synonym> synsTaxonErms = synsTaxonErmsPager.getRecords();
361

    
362
				List<Synonym> deleteRel = new ArrayList<>();
363
				for (Synonym synFauEu: synsTaxonFaunaEu){
364
					//TODO: wenn es noch keine SynonymRelationship gibt zu einem Synonym mit gleichem Namen,
365
				    //dann erzeuge die SynonymRelationship vom FaunaEuSyn (des FaunaEu Taxons, das
366
				    //identischen Namen hat) zum akzeptierten Taxon des Erms Syn
367
					boolean createNewRelationship = true;
368
					for (Synonym relErms: synsTaxonErms){
369
						if (relErms.getTitleCache().equals(synFauEu.getTitleCache())){
370
							//es gibt schon eine Relationship zu einem Synonym mit dem gleichen Namen wie das FaunaEu Synonym, also Relationship l�schen.
371
							createNewRelationship = false;
372
							break;
373
						}
374
					}
375
					if (createNewRelationship){
376
						taxonErms.addSynonym(synFauEu, synFauEu.getType());
377
					}
378
					deleteRel.add(synFauEu);
379
				}
380
			}
381
		}
382
	}
383

    
384
	private void deleteFaunaEuTaxon(Taxon taxonFaunaEu) throws ReferencedObjectUndeletableException {
385
		appCtrInit.getTaxonService().delete(taxonFaunaEu);
386
	}
387

    
388
	//wenn Name und Rang identisch sind und auch der Status gleich, dann alle Informationen vom Fauna Europaea Taxon/Synonym zum Erms Taxon/Synonym
389

    
390
	private void moveAllInformationsFromFaunaEuToErms(TaxonBase<?> faunaEu, TaxonBase<?> erms){
391
		Set<Annotation> annotations = faunaEu.getAnnotations();
392
		Set<Extension> extensions = faunaEu.getExtensions();
393
		Set<Marker> markers = faunaEu.getMarkers();
394
		List<Credit> credits = faunaEu.getCredits();
395
		if (faunaEu instanceof Taxon){
396
			Set<TaxonDescription> descriptions = ((Taxon)faunaEu).getDescriptions();
397
			Set<Taxon> misappliedNames = ((Taxon)faunaEu).getMisappliedNames(true);
398

    
399
			if (erms instanceof Taxon){
400
				Iterator<TaxonDescription> descriptionsIterator = descriptions.iterator();
401
				TaxonDescription description;
402
				while (descriptionsIterator.hasNext()){
403
					description = descriptionsIterator.next();
404
					((Taxon) erms).addDescription(description);
405
				}
406

    
407
				Iterator<Taxon> misappliedNamesIterator = misappliedNames.iterator();
408
				Taxon misappliedName;
409
				while (misappliedNamesIterator.hasNext()){
410
					misappliedName = misappliedNamesIterator.next();
411
					((Taxon) erms).addMisappliedName(misappliedName, null, null);
412
				}
413
			}
414
		}
415

    
416
		//move all these informations to the erms taxon
417
		Iterator<Annotation> annotationsIterator = annotations.iterator();
418
		Annotation annotation;
419
		while (annotationsIterator.hasNext()){
420
			annotation = annotationsIterator.next();
421
			erms.addAnnotation(annotation);
422
		}
423

    
424
		Iterator<Extension> extensionIterator = extensions.iterator();
425
		Extension extension;
426
		while (extensionIterator.hasNext()){
427
			extension = extensionIterator.next();
428
			erms.addExtension(extension);
429
		}
430

    
431
		Iterator<Marker> markerIterator = markers.iterator();
432
		Marker marker;
433
		while (markerIterator.hasNext()){
434
			marker = markerIterator.next();
435
			erms.addMarker(marker);
436
		}
437

    
438
		for (Credit credit: credits){
439
			erms.addCredit(credit);
440
		}
441
	}
442

    
443
	//if name, rank, and status (accepted) are the same, then move the synonyms of faunaEu taxon to the erms taxon
444

    
445
	private void moveFaunaEuSynonymsToErmsTaxon(Taxon faunaEu, Taxon erms){
446
		Set<Synonym> syns =faunaEu.getSynonyms();
447
		Iterator<Synonym> synRelIterator = syns.iterator();
448
		while (synRelIterator.hasNext()){
449
			Synonym syn = synRelIterator.next();
450
			faunaEu.removeSynonym(syn);
451
			erms.addSynonym(syn, syn.getType());
452
		}
453
	}
454

    
455
	//after merging faunaEu taxon and erms taxon, the originalSource of the faunaEu taxon has to be moved to the erms taxon
456
	private void moveOriginalDbToErmsTaxon(TaxonBase<?> faunaEuTaxon, TaxonBase<?> ermsTaxon){
457
		Set<IdentifiableSource> sourcesFaunaEu = faunaEuTaxon.getSources();
458
		IdentifiableSource sourceFaunaEu = sourcesFaunaEu.iterator().next();
459
		ermsTaxon.addSource(sourceFaunaEu);
460
	}
461

    
462
	//merged taxon should have a new sec reference
463
	private void addNewSecForMergedTaxon(Taxon taxon, Reference sec){
464
		taxon.setSec(sec);
465
		taxon.setUuid(UUID.randomUUID());
466
	}
467

    
468
	// ----------- methods for merging Erms synonyms and Fauna Europaea Taxon
469

    
470
}
(2-2/2)