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.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.io.api.application.CdmIoApplicationController;
27
import eu.etaxonomy.cdm.model.common.Annotation;
28
import eu.etaxonomy.cdm.model.common.Credit;
29
import eu.etaxonomy.cdm.model.common.Extension;
30
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
31
import eu.etaxonomy.cdm.model.common.Marker;
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.IZoologicalName;
36
import eu.etaxonomy.cdm.model.name.NameRelationship;
37
import eu.etaxonomy.cdm.model.name.Rank;
38
import eu.etaxonomy.cdm.model.reference.Reference;
39
import eu.etaxonomy.cdm.model.taxon.Synonym;
40
import eu.etaxonomy.cdm.model.taxon.Taxon;
41
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
42
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
43

    
44
public class FaunaEuErmsMergeActivator {
45

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

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

    
54
	CdmApplicationController appCtrInit;
55

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

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

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

    
66

    
67
	}
68

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

    
71
		FaunaEuErmsMergeActivator sc = new FaunaEuErmsMergeActivator();
72

    
73
		sc.initDb(faunaEuropaeaSource);
74
//we also need to merge names completely identical!
75
		sc.mergeAuthors();
76

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

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

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

    
91
		sc.mergeDiffStatus();
92

    
93
		//erms is synonym, faunaEu as well
94

    
95
		// erms is accepted, faunaEu as well
96

    
97
	}
98

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

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

    
129

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

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

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

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

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

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

    
198

    
199
	}
200

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

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

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

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

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

    
222
		//delete all synonyms of FaunaEu Syn TODO: move sources and additional informations to erms taxon
223
		for (List<String> rowList: ermsAccFaEuSyn){
224
			UUID faunaUUID = UUID.fromString(rowList.get(faunaEuUuid));
225
			//UUID ermsUUID = UUID.fromString(rowList.get(ermsUuid));
226
			Synonym syn = (Synonym)appCtrInit.getTaxonService().find(faunaUUID);
227
			// remove synonym from taxon then delete
228
			appCtrInit.getTaxonService().deleteSynonym(syn, null);
229
		}
230

    
231
		//merge the infos of
232
	}
233

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

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

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

    
253

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

    
265

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

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

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

    
287
			}
288
			//the fauna eu taxon should now only contain synonyms not existing in erms
289
			moveFaunaEuSynonymsToErmsTaxon(taxonFaunaEu, taxonErms);
290
			moveAllInformationsFromFaunaEuToErms(taxonFaunaEu, taxonErms);
291
			moveOriginalDbToErmsTaxon(taxonFaunaEu, taxonErms);
292
			//neue sec Referenz an das ErmsTaxon oder an das Synonym und Taxon oder nur Synonym??
293
			try{
294
				deleteFaunaEuTaxon(taxonFaunaEu);
295
			}catch(ReferencedObjectUndeletableException e){
296
				logger.debug("The taxon " + taxonFaunaEu.getTitleCache() + " can't be deleted because it is referenced.");
297
			}
298
		}
299

    
300
	}
301

    
302

    
303

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

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

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

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

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

    
371
				Pager<Synonym> synsTaxonErmsPager = appCtrInit.getTaxonService().getSynonyms(taxonErms, null, null, null, null, null);
372
				List<Synonym> synsTaxonErms = synsTaxonErmsPager.getRecords();
373

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

    
396
	private void deleteFaunaEuTaxon(Taxon taxonFaunaEu) throws ReferencedObjectUndeletableException {
397
		appCtrInit.getTaxonService().delete(taxonFaunaEu);
398
	}
399

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

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

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

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

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

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

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

    
450
		for (Credit credit: credits){
451
			erms.addCredit(credit);
452
		}
453
	}
454

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

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

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

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

    
480
	// ----------- methods for merging Erms synonyms and Fauna Europaea Taxon
481

    
482
}
(2-2/2)