Project

General

Profile

Download (19.5 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.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.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<TaxonBase>();
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 readCsvFile(String fileName){
99

    
100
		List<List<String>> result = new ArrayList<List<String>>();
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<String>();
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<TaxonBase>();
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(uuidFaunaEu);
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
	}
169

    
170
	public void setSpecificRank(List<TaxonBase> taxa, Rank rank){
171

    
172
		for (TaxonBase taxon: taxa){
173
			taxon.getName().setRank(rank);
174
		}
175
	}
176

    
177
	private void mergeDiffStatus(){
178
		List<List<String>> diffStatus = readCsvFile(sFileName + "_status.csv");
179

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

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

    
200

    
201
	}
202

    
203
	private void mergeSameStatus(){
204
		List<List<String>> sameStatus = readCsvFile(sFileName + "_names.csv");
205

    
206
		TaxonBase taxonFaunaEu;
207
		TaxonBase taxonErms;
208

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

    
219

    
220

    
221
	private void mergeErmsAccFaunaEuSyn(List<List<String>> ermsAccFaEuSyn){
222

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

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

    
234
		//merge the infos of
235
	}
236

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

    
246
			if (taxonErms == null){
247
				logger.debug("There is no accepted taxon for the synonym" + synErms.getTitleCache());
248
			}
249

    
250
			Set<Feature> features = new HashSet<Feature>();
251
			features.add(Feature.DISTRIBUTION());
252
			List<String> propertyPaths = new ArrayList<String>();
253
			propertyPaths.add("inDescription.Taxon.*");
254
			List<Distribution> distributions = appCtrInit.getDescriptionService().getDescriptionElementsForTaxon(taxonFaunaEu, features, Distribution.class, 10, 0, null);
255

    
256

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

    
268

    
269
			//Child-Parent Relationship aktualisieren -> dem Child des Fauna Europaea Taxons als parent das akzeptierte Taxon von synErms
270
			Set<TaxonNode> nodesErms = taxonErms.getTaxonNodes();
271
			Set<TaxonNode> nodesFaunaEu =taxonFaunaEu.getTaxonNodes();
272
			if (nodesFaunaEu.size()>1 || nodesFaunaEu.isEmpty()){
273

    
274
			}else{
275
				Iterator<TaxonNode> iteratorNodesErms = nodesErms.iterator();
276

    
277
				Iterator<TaxonNode> iteratorNodesFaunaEu = nodesFaunaEu.iterator();
278
				TaxonNode node = iteratorNodesFaunaEu.next();
279
				List<TaxonNode> children = node.getChildNodes();
280
				Iterator<TaxonNode> childrenIterator = children.iterator();
281
				TaxonNode childNode;
282
				if (iteratorNodesErms.hasNext()){
283
					TaxonNode ermsNode = iteratorNodesErms.next();
284
					while (childrenIterator.hasNext()){
285
						childNode = childrenIterator.next();
286
						ermsNode.addChildNode(childNode, childNode.getReference(), childNode.getMicroReference());
287
					}
288
				}
289

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

    
302

    
303

    
304

    
305
	}
306

    
307

    
308

    
309
	private void updateNameRelationships(List<List<String>> ermsAccFaEuSyn){
310
		//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
311
		//wenn es diese relationship noch nicht gibt und der typ der gleiche ist!!
312
		//wenn der relatedTo Name zu einem Erms Taxon und einem FaunaEu Synonym geh�rt
313

    
314
		Synonym synFaunaEu;
315
		Taxon taxonErms;
316
		for (List<String> row: ermsAccFaEuSyn){
317
			synFaunaEu = (Synonym)appCtrInit.getTaxonService().find(UUID.fromString(row.get(faunaEuUuid)));
318
			taxonErms = (Taxon)appCtrInit.getTaxonService().find(UUID.fromString(row.get(ermsUuid)));
319
			List<NameRelationship> relSynFaunaEu = appCtrInit.getNameService().listToNameRelationships(synFaunaEu.getName(), null, 100, 0, null, null);
320
			List<NameRelationship> relTaxonErms = appCtrInit.getNameService().listToNameRelationships(taxonErms.getName(), null, 100, 0, null, null);
321

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

    
339
		}
340
	}
341

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

    
373
			if (taxonErms != null){
374
				Pager<Synonym> synsTaxonFaunaEuPager = appCtrInit.getTaxonService().getSynonyms(taxonFaunaEu, null, null, null, null, null);
375
				List<Synonym> synsTaxonFaunaEu = synsTaxonFaunaEuPager.getRecords();
376

    
377
				Pager<Synonym> synsTaxonErmsPager = appCtrInit.getTaxonService().getSynonyms(taxonErms, null, null, null, null, null);
378
				List<Synonym> synsTaxonErms = synsTaxonErmsPager.getRecords();
379

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

    
397
					deleteRel.add(synFauEu);
398
				}
399
			}
400

    
401
		}
402
	}
403

    
404

    
405
	private void deleteFaunaEuTaxon(Taxon taxonFaunaEu) throws ReferencedObjectUndeletableException{
406
		appCtrInit.getTaxonService().delete(taxonFaunaEu);
407

    
408
	}
409

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

    
412
	private void moveAllInformationsFromFaunaEuToErms(TaxonBase faunaEu, TaxonBase erms){
413
		Set<Annotation> annotations = faunaEu.getAnnotations();
414
		Set<Extension> extensions = faunaEu.getExtensions();
415
		Set<Marker> markers = faunaEu.getMarkers();
416
		List<Credit> credits = faunaEu.getCredits();
417
		if (faunaEu instanceof Taxon){
418
			Set<TaxonDescription> descriptions = ((Taxon)faunaEu).getDescriptions();
419
			Set<Taxon> misappliedNames = ((Taxon)faunaEu).getMisappliedNames();
420

    
421
			if (erms instanceof Taxon){
422
				Iterator<TaxonDescription> descriptionsIterator = descriptions.iterator();
423
				TaxonDescription description;
424
				while (descriptionsIterator.hasNext()){
425
					description = descriptionsIterator.next();
426
					((Taxon) erms).addDescription(description);
427
				}
428

    
429
				Iterator<Taxon> misappliedNamesIterator = misappliedNames.iterator();
430
				Taxon misappliedName;
431
				while (misappliedNamesIterator.hasNext()){
432
					misappliedName = misappliedNamesIterator.next();
433
					((Taxon) erms).addMisappliedName(misappliedName, null, null);
434
				}
435
			}
436
		}
437

    
438
		//move all these informations to the erms taxon
439
		Iterator<Annotation> annotationsIterator = annotations.iterator();
440
		Annotation annotation;
441
		while (annotationsIterator.hasNext()){
442
			annotation = annotationsIterator.next();
443
			erms.addAnnotation(annotation);
444
		}
445

    
446
		Iterator<Extension> extensionIterator = extensions.iterator();
447
		Extension extension;
448
		while (extensionIterator.hasNext()){
449
			extension = extensionIterator.next();
450
			erms.addExtension(extension);
451
		}
452

    
453
		Iterator<Marker> markerIterator = markers.iterator();
454
		Marker marker;
455
		while (markerIterator.hasNext()){
456
			marker = markerIterator.next();
457
			erms.addMarker(marker);
458
		}
459

    
460
		for (Credit credit: credits){
461
			erms.addCredit(credit);
462
		}
463

    
464

    
465
	}
466

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

    
469
	private void moveFaunaEuSynonymsToErmsTaxon(Taxon faunaEu, Taxon erms){
470
		Set<Synonym> syns =faunaEu.getSynonyms();
471
		Iterator<Synonym> synRelIterator = syns.iterator();
472
		while (synRelIterator.hasNext()){
473
			Synonym syn = synRelIterator.next();
474
			faunaEu.removeSynonym(syn);
475
			erms.addSynonym(syn, syn.getType());
476
		}
477
	}
478

    
479
	//after merging faunaEu taxon and erms taxon, the originalSource of the faunaEu taxon has to be moved to the erms taxon
480
	private void moveOriginalDbToErmsTaxon(TaxonBase faunaEu, TaxonBase erms){
481
		Set<IdentifiableSource> sourcesFaunaEu = faunaEu.getSources();
482
		IdentifiableSource sourceFaunaEu = sourcesFaunaEu.iterator().next();
483
		erms.addSource(sourceFaunaEu);
484
	}
485

    
486
	//merged taxon should have a new sec reference
487
	private void addNewSecForMergedTaxon(Taxon taxon, Reference sec){
488
		taxon.setSec(sec);
489
		taxon.setUuid(UUID.randomUUID());
490
	}
491

    
492
	// ----------- methods for merging Erms synonyms and Fauna Europaea Taxon
493

    
494

    
495

    
496

    
497
}
(2-2/2)