Project

General

Profile

Download (19.4 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.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.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.description.Distribution;
32
import eu.etaxonomy.cdm.model.description.Feature;
33
import eu.etaxonomy.cdm.model.description.TaxonDescription;
34
import eu.etaxonomy.cdm.model.name.IZoologicalName;
35
import eu.etaxonomy.cdm.model.name.NameRelationship;
36
import eu.etaxonomy.cdm.model.name.Rank;
37
import eu.etaxonomy.cdm.model.reference.Reference;
38
import eu.etaxonomy.cdm.model.taxon.Synonym;
39
import eu.etaxonomy.cdm.model.taxon.Taxon;
40
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
41
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
42

    
43
public class FaunaEuErmsMergeActivator {
44

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

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

    
53
	CdmApplicationController appCtrInit;
54

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

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

    
60
	private void initDb(ICdmDataSource db) {
61

    
62
		// Init source DB
63
		appCtrInit = TestDatabase.initDb(db, DbSchemaValidation.VALIDATE, false);
64

    
65

    
66
	}
67

    
68
	public static void main(String[] args) {
69

    
70
		FaunaEuErmsMergeActivator sc = new FaunaEuErmsMergeActivator();
71

    
72
		sc.initDb(faunaEuropaeaSource);
73

    
74
		sc.mergeAuthors();
75

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

    
85
		sc.setSpecificRank(taxaToChangeRank, Rank.SUPERCLASS());
86

    
87
		//ermsTaxon is accepted, fauna eu taxon is synonym
88
		//ermsTaxon is synonym, faunaEu is accepted
89

    
90
		sc.mergeDiffStatus();
91

    
92
		//erms is synonym, faunaEu as well
93

    
94
		// erms is accepted, faunaEu as well
95

    
96
	}
97

    
98
	private static List<List<String>> readCsvFile(String fileName){
99

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

    
128

    
129
	private void mergeAuthors(){
130
		List<List<String>> authors = readCsvFile(sFileName + "_authors.csv");
131
		//authors: get firstAuthor if isFauEu = 1 otherwise get secondAuthor
132

    
133
		Iterator<List<String>> authorIterator = authors.iterator();
134
		List<String> row;
135
		TaxonBase<?> taxonFaunaEu;
136
		TaxonBase<?> taxonErms;
137
		List<TaxonBase<?>> taxaToSave = new ArrayList<>();
138
		while (authorIterator.hasNext()){
139
			row = authorIterator.next();
140
			UUID uuidFaunaEu = UUID.fromString(row.get(faunaEuUuid));
141
			UUID uuidErms = UUID.fromString(row.get(ermsUuid));
142
			taxonFaunaEu = appCtrInit.getTaxonService().find(uuidFaunaEu);
143
			taxonErms = appCtrInit.getTaxonService().find(uuidErms);
144

    
145
			if (Integer.parseInt(row.get(18)) == 1){
146
				//isFaunaEu = 1 -> copy the author of Fauna Europaea to Erms
147
				if (((IZoologicalName)taxonFaunaEu.getName()).getBasionymAuthorship()!= null){
148
					((IZoologicalName)taxonErms.getName()).setBasionymAuthorship(((IZoologicalName)taxonFaunaEu.getName()).getBasionymAuthorship());
149
				}
150
				if (((IZoologicalName)taxonFaunaEu.getName()).getCombinationAuthorship()!= null){
151
					((IZoologicalName)taxonErms.getName()).setCombinationAuthorship(((IZoologicalName)taxonFaunaEu.getName()).getCombinationAuthorship());
152
				}
153
				((IZoologicalName)taxonErms.getName()).generateAuthorship();
154
				taxaToSave.add(taxonErms);
155
			}else{
156
				if (((IZoologicalName)taxonErms.getName()).getBasionymAuthorship()!= null){
157
					((IZoologicalName)taxonFaunaEu.getName()).setBasionymAuthorship(((IZoologicalName)taxonErms.getName()).getBasionymAuthorship());
158
				}
159
				if (((IZoologicalName)taxonErms.getName()).getCombinationAuthorship()!= null){
160
					((IZoologicalName)taxonFaunaEu.getName()).setCombinationAuthorship(((IZoologicalName)taxonErms.getName()).getCombinationAuthorship());
161
				}
162
				((IZoologicalName)taxonFaunaEu.getName()).generateAuthorship();
163
				taxaToSave.add(taxonFaunaEu);
164
			}
165
		}
166
	}
167

    
168
	private void setSpecificRank(List<TaxonBase> taxa, Rank rank){
169
		for (TaxonBase<?> taxon: taxa){
170
			taxon.getName().setRank(rank);
171
		}
172
	}
173

    
174
	private void mergeDiffStatus(){
175
		List<List<String>> diffStatus = readCsvFile(sFileName + "_status.csv");
176

    
177
		//find all taxa accepted in erms, but synonyms in FauEu  and the same rank
178
		List<List<String>> accErmsSynFaunaEu = new ArrayList<List<String>>();
179
		for (List<String> rowList: diffStatus){
180
			if ((rowList.get(5).equals("synonym")) && (rowList.get(rankFaunaEu).equals(rowList.get(rankErms)))){
181
				//both conditions are true
182
				accErmsSynFaunaEu.add(rowList);
183
			}
184
		}
185
		mergeErmsAccFaunaEuSyn(accErmsSynFaunaEu);
186

    
187
		//find all taxa accepted in faunaEu, but synonyms in Erms and the same rank
188
		List<List<String>> synErmsAccFaunaEu = new ArrayList<List<String>>();
189
		for (List<String> rowList: diffStatus){
190
			if ((rowList.get(5).equals("accepted")) && (rowList.get(rankFaunaEu).equals(rowList.get(rankErms)))){
191
				//both conditions are true
192
				synErmsAccFaunaEu.add(rowList);
193
			}
194
		}
195
		mergeErmsSynFaunaEuAcc(synErmsAccFaunaEu);
196

    
197

    
198
	}
199

    
200
	private void mergeSameStatus(){
201
		List<List<String>> sameStatus = readCsvFile(sFileName + "_names.csv");
202

    
203
		TaxonBase<?> taxonFaunaEu;
204
		TaxonBase<?> taxonErms;
205

    
206
		for (List<String> row: sameStatus){
207
			taxonFaunaEu = appCtrInit.getTaxonService().find(UUID.fromString(row.get(faunaEuUuid)));
208
			taxonErms = appCtrInit.getTaxonService().find(UUID.fromString(row.get(ermsUuid)));
209
			moveAllInformationsFromFaunaEuToErms(taxonFaunaEu, taxonErms);
210
			if (taxonErms instanceof Taxon){
211
				moveFaunaEuSynonymsToErmsTaxon((Taxon)taxonFaunaEu, (Taxon)taxonErms);
212
			}
213
		}
214
	}
215

    
216
	private void mergeErmsAccFaunaEuSyn(List<List<String>> ermsAccFaEuSyn){
217

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

    
221
		//delete all synonyms of FaunaEu Syn
222
		for (List<String> rowList: ermsAccFaEuSyn){
223
			UUID faunaUUID = UUID.fromString(rowList.get(faunaEuUuid));
224
			//UUID ermsUUID = UUID.fromString(rowList.get(ermsUuid));
225
			Synonym syn = (Synonym)appCtrInit.getTaxonService().find(faunaUUID);
226
			appCtrInit.getTaxonService().deleteSynonym(syn, null);
227
		}
228

    
229
		//merge the infos of
230
	}
231

    
232
	private  void mergeErmsSynFaunaEuAcc (List<List<String>> ermsAccFaEuSyn){
233
		//occurence: verknüpfe statt dem Fauna Europaea Taxon das akzeptierte Taxon, des Synonyms mit der Occurence (CDM -> distribution)
234
		//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
235
		for (List<String> row: ermsAccFaEuSyn){
236
		    Taxon taxonFaunaEu = (Taxon)appCtrInit.getTaxonService().find(UUID.fromString(row.get(faunaEuUuid)));
237
			Synonym synErms = (Synonym)appCtrInit.getTaxonService().find(UUID.fromString(row.get(ermsUuid)));
238
			synErms = HibernateProxyHelper.deproxy(synErms, Synonym.class);
239
			Taxon taxonErms = synErms.getAcceptedTaxon();
240

    
241
			if (taxonErms == null){
242
				logger.debug("There is no accepted taxon for the synonym" + synErms.getTitleCache());
243
			}
244

    
245
			Set<Feature> features = new HashSet<>();
246
			features.add(Feature.DISTRIBUTION());
247
			List<String> propertyPaths = new ArrayList<>();
248
			propertyPaths.add("inDescription.Taxon.*");
249
			List<Distribution> distributions = appCtrInit.getDescriptionService().getDescriptionElementsForTaxon(taxonFaunaEu, features, Distribution.class, 10, 0, null);
250

    
251

    
252
			for(Distribution distribution: distributions){
253
				TaxonDescription description = (TaxonDescription)distribution.getInDescription();
254
				TaxonDescription newDescription = TaxonDescription.NewInstance(taxonErms);
255
				newDescription.addElement(distribution);
256
				try{
257
					appCtrInit.getDescriptionService().delete(description);
258
				}catch (Exception e){
259
					logger.debug("The description of" + description.getTaxon().getTitleCache() + description.getTitleCache() + "can't be deleted because it is referenced.");
260
				}
261
			}
262

    
263

    
264
			//Child-Parent Relationship aktualisieren -> dem Child des Fauna Europaea Taxons als parent das akzeptierte Taxon von synErms
265
			Set<TaxonNode> nodesErms = taxonErms.getTaxonNodes();
266
			Set<TaxonNode> nodesFaunaEu =taxonFaunaEu.getTaxonNodes();
267
			if (nodesFaunaEu.size()>1 || nodesFaunaEu.isEmpty()){
268

    
269
			}else{
270
				Iterator<TaxonNode> iteratorNodesErms = nodesErms.iterator();
271

    
272
				Iterator<TaxonNode> iteratorNodesFaunaEu = nodesFaunaEu.iterator();
273
				TaxonNode node = iteratorNodesFaunaEu.next();
274
				List<TaxonNode> children = node.getChildNodes();
275
				Iterator<TaxonNode> childrenIterator = children.iterator();
276
				TaxonNode childNode;
277
				if (iteratorNodesErms.hasNext()){
278
					TaxonNode ermsNode = iteratorNodesErms.next();
279
					while (childrenIterator.hasNext()){
280
						childNode = childrenIterator.next();
281
						ermsNode.addChildNode(childNode, childNode.getReference(), childNode.getMicroReference());
282
					}
283
				}
284

    
285
			}
286
			moveFaunaEuSynonymsToErmsTaxon(taxonFaunaEu, taxonErms);
287
			moveAllInformationsFromFaunaEuToErms(taxonFaunaEu, taxonErms);
288
			moveOriginalDbToErmsTaxon(taxonFaunaEu, taxonErms);
289
			//neue sec Referenz an das ErmsTaxon oder an das Synonym und Taxon oder nur Synonym??
290
			try{
291
				deleteFaunaEuTaxon(taxonFaunaEu);
292
			}catch(ReferencedObjectUndeletableException e){
293
				logger.debug("The taxon " + taxonFaunaEu.getTitleCache() + " can't be deleted because it is referenced.");
294
			}
295
		}
296

    
297
	}
298

    
299

    
300

    
301
	private void updateNameRelationships(List<List<String>> ermsAccFaEuSyn){
302
		//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
303
		//wenn es diese relationship noch nicht gibt und der typ der gleiche ist!!
304
		//wenn der relatedTo Name zu einem Erms Taxon und einem FaunaEu Synonym gehört
305

    
306
		Synonym synFaunaEu;
307
		Taxon taxonErms;
308
		for (List<String> row: ermsAccFaEuSyn){
309
			synFaunaEu = (Synonym)appCtrInit.getTaxonService().find(UUID.fromString(row.get(faunaEuUuid)));
310
			taxonErms = (Taxon)appCtrInit.getTaxonService().find(UUID.fromString(row.get(ermsUuid)));
311
			List<NameRelationship> relSynFaunaEu = appCtrInit.getNameService().listToNameRelationships(synFaunaEu.getName(), null, 100, 0, null, null);
312
			List<NameRelationship> relTaxonErms = appCtrInit.getNameService().listToNameRelationships(taxonErms.getName(), null, 100, 0, null, null);
313

    
314
			List<NameRelationship> deleteRel = new ArrayList<NameRelationship>();
315
			for (NameRelationship relFauEu: relSynFaunaEu){
316
				boolean createNewRelationship = true;
317
				for (NameRelationship relErms: relTaxonErms){
318
					if ((relErms.getFromName().getTitleCache().equals(relFauEu.getFromName().getTitleCache())) && (relErms.getToName().getTitleCache().equals(relFauEu.getFromName().getTitleCache()))){
319
						//delete the faunaEu relationship because there exist an analogous relationship in erms
320
						deleteRel.add(relFauEu);
321
						createNewRelationship = false;
322
						break;
323
					}
324
				}
325
				if (createNewRelationship){
326
					//if relationship does not exist, create a new one with erms synonym
327
					taxonErms.getName().addRelationshipFromName(relFauEu.getFromName(), relFauEu.getType(), relFauEu.getRuleConsidered(), null);
328
				}
329
			}
330
		}
331
	}
332

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

    
364
			if (taxonErms != null){
365
				Pager<Synonym> synsTaxonFaunaEuPager = appCtrInit.getTaxonService().getSynonyms(taxonFaunaEu, null, null, null, null, null);
366
				List<Synonym> synsTaxonFaunaEu = synsTaxonFaunaEuPager.getRecords();
367

    
368
				Pager<Synonym> synsTaxonErmsPager = appCtrInit.getTaxonService().getSynonyms(taxonErms, null, null, null, null, null);
369
				List<Synonym> synsTaxonErms = synsTaxonErmsPager.getRecords();
370

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

    
393
	private void deleteFaunaEuTaxon(Taxon taxonFaunaEu) throws ReferencedObjectUndeletableException {
394
		appCtrInit.getTaxonService().delete(taxonFaunaEu);
395
	}
396

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

    
399
	private void moveAllInformationsFromFaunaEuToErms(TaxonBase<?> faunaEu, TaxonBase<?> erms){
400
		Set<Annotation> annotations = faunaEu.getAnnotations();
401
		Set<Extension> extensions = faunaEu.getExtensions();
402
		Set<Marker> markers = faunaEu.getMarkers();
403
		List<Credit> credits = faunaEu.getCredits();
404
		if (faunaEu instanceof Taxon){
405
			Set<TaxonDescription> descriptions = ((Taxon)faunaEu).getDescriptions();
406
			Set<Taxon> misappliedNames = ((Taxon)faunaEu).getMisappliedNames(true);
407

    
408
			if (erms instanceof Taxon){
409
				Iterator<TaxonDescription> descriptionsIterator = descriptions.iterator();
410
				TaxonDescription description;
411
				while (descriptionsIterator.hasNext()){
412
					description = descriptionsIterator.next();
413
					((Taxon) erms).addDescription(description);
414
				}
415

    
416
				Iterator<Taxon> misappliedNamesIterator = misappliedNames.iterator();
417
				Taxon misappliedName;
418
				while (misappliedNamesIterator.hasNext()){
419
					misappliedName = misappliedNamesIterator.next();
420
					((Taxon) erms).addMisappliedName(misappliedName, null, null);
421
				}
422
			}
423
		}
424

    
425
		//move all these informations to the erms taxon
426
		Iterator<Annotation> annotationsIterator = annotations.iterator();
427
		Annotation annotation;
428
		while (annotationsIterator.hasNext()){
429
			annotation = annotationsIterator.next();
430
			erms.addAnnotation(annotation);
431
		}
432

    
433
		Iterator<Extension> extensionIterator = extensions.iterator();
434
		Extension extension;
435
		while (extensionIterator.hasNext()){
436
			extension = extensionIterator.next();
437
			erms.addExtension(extension);
438
		}
439

    
440
		Iterator<Marker> markerIterator = markers.iterator();
441
		Marker marker;
442
		while (markerIterator.hasNext()){
443
			marker = markerIterator.next();
444
			erms.addMarker(marker);
445
		}
446

    
447
		for (Credit credit: credits){
448
			erms.addCredit(credit);
449
		}
450
	}
451

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

    
454
	private void moveFaunaEuSynonymsToErmsTaxon(Taxon faunaEu, Taxon erms){
455
		Set<Synonym> syns =faunaEu.getSynonyms();
456
		Iterator<Synonym> synRelIterator = syns.iterator();
457
		while (synRelIterator.hasNext()){
458
			Synonym syn = synRelIterator.next();
459
			faunaEu.removeSynonym(syn);
460
			erms.addSynonym(syn, syn.getType());
461
		}
462
	}
463

    
464
	//after merging faunaEu taxon and erms taxon, the originalSource of the faunaEu taxon has to be moved to the erms taxon
465
	private void moveOriginalDbToErmsTaxon(TaxonBase faunaEu, TaxonBase erms){
466
		Set<IdentifiableSource> sourcesFaunaEu = faunaEu.getSources();
467
		IdentifiableSource sourceFaunaEu = sourcesFaunaEu.iterator().next();
468
		erms.addSource(sourceFaunaEu);
469
	}
470

    
471
	//merged taxon should have a new sec reference
472
	private void addNewSecForMergedTaxon(Taxon taxon, Reference sec){
473
		taxon.setSec(sec);
474
		taxon.setUuid(UUID.randomUUID());
475
	}
476

    
477
	// ----------- methods for merging Erms synonyms and Fauna Europaea Taxon
478

    
479
}
(2-2/2)