Project

General

Profile

Download (19.8 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.database.DbSchemaValidation;
23
import eu.etaxonomy.cdm.database.ICdmDataSource;
24
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
25
import eu.etaxonomy.cdm.io.api.application.CdmIoApplicationController;
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 = CdmIoApplicationController.NewInstance(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
//we also need to merge names completely identical!
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, null);
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, null);
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
// which information should be used can be found in last row -> needs to be done manually
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 TODO: move sources and additional informations to erms taxon
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
			// remove synonym from taxon then delete
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: connect instead of Fauna Europaea taxon the accepted taxon of the synonym with the occurrence (CDM -> distribution)
235
		//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
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
			//the fauna eu taxon should now only contain synonyms not existing in erms
288
			moveFaunaEuSynonymsToErmsTaxon(taxonFaunaEu, taxonErms);
289
			moveAllInformationsFromFaunaEuToErms(taxonFaunaEu, taxonErms);
290
			moveOriginalDbToErmsTaxon(taxonFaunaEu, taxonErms);
291
			//neue sec Referenz an das ErmsTaxon oder an das Synonym und Taxon oder nur Synonym??
292
			try{
293
				deleteFaunaEuTaxon(taxonFaunaEu);
294
			}catch(ReferencedObjectUndeletableException e){
295
				logger.debug("The taxon " + taxonFaunaEu.getTitleCache() + " can't be deleted because it is referenced.");
296
			}
297
		}
298

    
299
	}
300

    
301
	private void updateNameRelationships(List<List<String>> ermsAccFaEuSyn){
302
		//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
303
		//if this relationship does not yet exist and the type is the same!!
304
		//if the relatedTo name belongs to an Erms taxon and to an FaunaEu synonym
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)