Project

General

Profile

Download (20.1 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.NameRelationship;
34
import eu.etaxonomy.cdm.model.name.Rank;
35
import eu.etaxonomy.cdm.model.reference.Reference;
36
import eu.etaxonomy.cdm.model.taxon.Classification;
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
	Classification faunaEuClassification;
52
	Classification ermsClassification;
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
		// Init source DB
63
		appCtrInit = CdmIoApplicationController.NewInstance(db, DbSchemaValidation.VALIDATE, false);
64
	}
65

    
66
	public static void main(String[] args) {
67

    
68
		FaunaEuErmsMergeActivator sc = new FaunaEuErmsMergeActivator();
69

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

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

    
83
		sc.setSpecificRank(taxaToChangeRank, Rank.SUPERCLASS());
84

    
85
		//ermsTaxon is accepted, fauna eu taxon is synonym
86
		//ermsTaxon is synonym, faunaEu is accepted
87

    
88
		sc.mergeDiffStatus();
89

    
90
		//erms is synonym, faunaEu as well
91

    
92
		// erms is accepted, faunaEu as well
93

    
94
	}
95

    
96
	private static List<List<String>> readCsvFile(String fileName){
97

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

    
122

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

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

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

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

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

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

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

    
195
		TaxonBase<?> taxonFaunaEu;
196
		TaxonBase<?> taxonErms;
197
		List<String> propertyPaths = new ArrayList<>();
198
		propertyPaths.add("taxonBases.nodes.*");
199
		for (List<String> row: sameStatus){
200
			taxonFaunaEu = appCtrInit.getTaxonService().load(UUID.fromString(row.get(faunaEuUuid)), propertyPaths);
201
			taxonErms = appCtrInit.getTaxonService().load(UUID.fromString(row.get(ermsUuid)), propertyPaths);
202
			moveAllInformationsFromFaunaEuToErms(taxonFaunaEu, taxonErms);
203
			if (taxonErms instanceof Taxon){
204
				moveFaunaEuSynonymsToErmsTaxon((Taxon)taxonFaunaEu, (Taxon)taxonErms);
205
			}
206
		}
207
	}
208

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

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

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

    
223
		//merge the infos of
224
	}
225

    
226
	private  void mergeErmsSynFaunaEuAcc (List<List<String>> ermsAccFaEuSyn){
227
		//occurence: connect instead of Fauna Europaea taxon the accepted taxon of the synonym with the occurrence (CDM -> distribution)
228
		//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
229
		for (List<String> row: ermsAccFaEuSyn){
230
		    Taxon taxonFaunaEu = (Taxon)appCtrInit.getTaxonService().find(UUID.fromString(row.get(faunaEuUuid)));
231
			Synonym synErms = (Synonym)appCtrInit.getTaxonService().find(UUID.fromString(row.get(ermsUuid)));
232
			synErms = HibernateProxyHelper.deproxy(synErms, Synonym.class);
233
			Taxon taxonErms = synErms.getAcceptedTaxon();
234

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

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

    
245

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

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

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

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

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

    
291
	}
292

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
439
		for (Credit credit: credits){
440
			erms.addCredit(credit);
441
		}
442
		//move children to erms taxon
443
		if (faunaEu instanceof Taxon && ((Taxon)faunaEu).getTaxonNode(faunaEuClassification).hasChildNodes()) {
444
			Taxon acceptedErmsTaxon;
445
			if (erms instanceof Synonym) {
446
				acceptedErmsTaxon = ((Synonym)erms).getAcceptedTaxon();
447
			}else {
448
				acceptedErmsTaxon = (Taxon)erms;
449
			}
450
			TaxonNode node = acceptedErmsTaxon.getTaxonNode(ermsClassification);
451
			for (TaxonNode child:((Taxon)faunaEu).getTaxonNode(faunaEuClassification).getChildNodes()) {
452
				//add pesi reference as reference??
453
				node.addChildNode(child, null, null);
454
			}
455
		}
456
	}
457

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

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

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

    
477
	//merged taxon should have a new sec reference
478
	private void addNewSecForMergedTaxon(Taxon taxon, Reference sec){
479
		taxon.setSec(sec);
480
		//this does not work!!
481
		//taxon.setUuid(UUID.randomUUID());
482
	}
483

    
484
	// ----------- methods for merging Erms synonyms and Fauna Europaea Taxon
485

    
486
}
(1-1/2)