Project

General

Profile

« Previous | Next » 

Revision 3221710a

Added by Andreas Müller over 4 years ago

cleanup

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/out/BerlinModelTaxonExport.java
36 36
/**
37 37
 * @author a.mueller
38 38
 * @since 20.03.2008
39
 * @version 1.0
40 39
 */
41 40
@Component
42 41
public class BerlinModelTaxonExport extends BerlinModelExportBase<TaxonBase> {
43
	private static final Logger logger = Logger.getLogger(BerlinModelTaxonExport.class);
42

  
43
    private static final long serialVersionUID = 145503113573711492L;
44
    private static final Logger logger = Logger.getLogger(BerlinModelTaxonExport.class);
44 45

  
45 46
	private static int modCount = 1000;
46 47
	private static final String dbTableName = "PTaxon";
......
51 52
		super();
52 53
	}
53 54

  
54
	/* (non-Javadoc)
55
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
56
	 */
57 55
	@Override
58 56
	protected boolean doCheck(BerlinModelExportState state){
59 57
		boolean result = true;
......
141 139
		}
142 140
	}
143 141

  
144

  
145

  
146

  
147 142
	protected boolean doDelete(BerlinModelExportState state){
148 143
		BerlinModelExportConfigurator bmeConfig = state.getConfig();
149 144

  
......
165 160
		return true;
166 161
	}
167 162

  
168

  
169
	/* (non-Javadoc)
170
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
171
	 */
172 163
	@Override
173 164
    protected boolean isIgnore(BerlinModelExportState state){
174 165
		return ! state.getConfig().isDoTaxa();
......
189 180
		}
190 181
	}
191 182

  
192
	/* (non-Javadoc)
193
	 * @see eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportBase#getStandardMethodParameter()
194
	 */
195 183
	@Override
196 184
	public Class<? extends CdmBase> getStandardMethodParameter() {
197 185
		return standardMethodParameter;
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/out/mapper/TeamOrPersonMapper.java
5 5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/ 
8
*/
9 9

  
10 10
package eu.etaxonomy.cdm.io.berlinModel.out.mapper;
11 11

  
......
36 36
	PreparedStatement stmtInsertTeam;
37 37
	PreparedStatement stmtInsertSequence;
38 38
	PreparedStatement stmtMaxId;
39
	
39

  
40 40
	public static TeamOrPersonMapper NewInstance(String cdmAttributeString, String dbAttributeString){
41 41
		TeamOrPersonMapper result = new TeamOrPersonMapper(cdmAttributeString, dbAttributeString, null);
42 42
		return result;
43 43
	}
44
	
45
	
44

  
45

  
46 46
	protected TeamOrPersonMapper(String cdmAttributeString, String dbAttributeString, Object defaultValue) {
47 47
		super(cdmAttributeString, dbAttributeString, defaultValue, false);
48
		
48

  
49 49
	}
50
	
50

  
51 51
	Integer lastTeamId;
52
	
53
	protected boolean doInvoke(CdmBase cdmBase) throws SQLException {
54
		CdmBase agent = (CdmBase)ImportHelper.getValue(cdmBase, this.getSourceAttribute(), false, obligatory);  
52

  
53
	@Override
54
    protected boolean doInvoke(CdmBase cdmBase) throws SQLException {
55
		CdmBase agent = (CdmBase)ImportHelper.getValue(cdmBase, this.getSourceAttribute(), false, obligatory);
55 56
		if (agent == null || agent.isInstanceOf(Team.class)){
56 57
			//if Team, do normal
57 58
			if (agent == null){
......
67 68
			throw new IllegalStateException("Invoke argument for TeamOrPersonMapper must be either a Team or a Person but was " + agent.getClass().getName());
68 69
		}
69 70
	}
70
	
71 71

  
72
	private int makePersonToTeam(Person agent) {		
72

  
73
	private int makePersonToTeam(Person agent) {
73 74
		int teamFk = 0;
74 75
		try {
75 76
			ResultSet result = stmtMaxId.executeQuery();
76
			
77

  
77 78
			while (result.next()){
78 79
				teamFk = result.getInt(1) +1;
79 80
				System.out.println(teamFk);
......
81 82
				stmtInsertTeam.setString(2, agent.getTitleCache());
82 83
				stmtInsertTeam.setString(3, agent.getNomenclaturalTitle());
83 84
				stmtInsertTeam.executeUpdate();
84
				
85

  
85 86
				stmtInsertSequence.setInt(1, teamFk);
86 87
				stmtInsertSequence.setInt(2, agent.getId());
87 88
				stmtInsertSequence.executeUpdate();
88 89
			}
89
			
90

  
90 91
		} catch (SQLException e) {
91 92
			e.printStackTrace();
92 93
			throw new IllegalStateException("SQL Exception occurred in makePersonToTeam()");
93 94
		}
94
		
95

  
95 96
		return teamFk;
96 97
	}
97 98

  
......
105 106
	@Override
106 107
	public void initialize(PreparedStatement stmt, IndexCounter index, DbExportStateBase<?, IExportTransformer> state, String tableName) {
107 108
		super.initialize(stmt, index, state, tableName);
108
		
109

  
109 110
		Source db = this.getState().getConfig().getDestination();
110 111
		try {
111 112
			String insertAuthorTeam = "INSERT INTO authorTeam (AuthorTeamId, FullAuthorTeamCache,AuthorTeamCache, PreliminaryFlag ) " +
112 113
							" Values (?, ?,?,0)";
113 114
			stmtInsertTeam = db.getConnection().prepareStatement(insertAuthorTeam);
114
			
115

  
115 116
			String insertSequence = "INSERT INTO authorTeamSequence (authorTeamFk, authorFk, Sequence) " +
116 117
			" Values (?,?,1)";
117 118
			stmtInsertSequence = db.getConnection().prepareStatement(insertSequence);
118
			
119

  
119 120
			String getMaxId = "SELECT max(AuthorTeamId) as max FROM AuthorTeam";
120 121
			stmtMaxId = db.getConnection().prepareStatement(getMaxId);
121
			
122

  
122 123
		} catch (SQLException e1) {
123 124
			e1.printStackTrace();
124 125
			throw new IllegalStateException("An SQLException occurred when trying to prepare insert team statements");
......
126 127
	}
127 128

  
128 129

  
129
	
130

  
130 131

  
131 132
}
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiExportConfigurator.java
62 62
				PesiRelTaxonExport.class, // RelTaxonId's could be deleted from state hashmap
63 63
				PesiDescriptionExport.class,
64 64
				PesiFinalUpdateExport.class
65

  
65 66
//				PesiNoteExport.class,
66 67
//				PesiNoteSourceExport.class, // NoteId's could be deleted from state hashmap
67 68
//				PesiAdditionalTaxonSourceExport.class,
......
69 70
//				PesiOccurrenceSourceExport.class,
70 71
//				PesiImageExport.class,
71 72
		};
72

  
73 73
	}
74 74

  
75 75
	private PesiExportConfigurator(Source pesiSource, ICdmDataSource cdmSource, PesiTransformer transformer) {
76
	   super(transformer);
77
	   setSource(cdmSource);
78
	   setDestination(pesiSource);
76
	    super(transformer);
77
	    setSource(cdmSource);
78
	    setDestination(pesiSource);
79 79
	}
80 80

  
81 81
	@Override
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiRelTaxonExport.java
95 95
			//Export taxon relations
96 96
			success &= doPhase01(state, mapping);
97 97

  
98

  
99 98
			// Export name relations
100 99
			success &= doPhase02(state, mapping);
101 100

  
102 101
			if (! success){
103 102
				state.getResult().addError("An unknown error occurred in PesiRelTaxonExport");
104 103
			}
105

  
106
		} catch (SQLException e) {
104
		} catch (Exception e) {
107 105
			e.printStackTrace();
108 106
			logger.error(e.getMessage());
109 107
			state.getResult().addException(e);
......
111 109
		}
112 110
	}
113 111

  
114

  
115 112
	private boolean doPhase01(PesiExportState state, PesiExportMapping mapping2) {
116 113
		logger.info("PHASE 1: Taxon Relationships ...");
117 114
		boolean success = true;
......
148 145
		return success;
149 146
	}
150 147

  
151
	private boolean doPhase02(PesiExportState state, PesiExportMapping mapping2) throws SQLException {
148
	private boolean doPhase02(PesiExportState state, PesiExportMapping mapping2) {
152 149
		logger.info("PHASE 2: Name Relationships ...");
153 150
		boolean success = true;
154 151

  
......
195 192
					}
196 193
					fromList = null;
197 194
					toList = null;
198
					name1 = null;
199
					name2 = null;
200
					rel = null;
201 195

  
202 196
				} catch (Exception e) {
203 197
					logger.error(e.getMessage() + ". Relationship: " +  rel.getUuid());
......
208 202
			txStatus = startTransaction();
209 203
		}
210 204
		commitTransaction(txStatus);
211
		list = null;
212 205
		logger.info("End PHASE 2: Name Relationships ...");
213 206
		state.setCurrentFromObject(null);
214 207
		state.setCurrentToObject(null);
......
381 374
			success &= saveSynonymAndSynNameRelationships(state, childNodeTaxon);
382 375
		}
383 376
		return success;
384

  
385 377
	}
386 378

  
387 379
	private boolean saveSynonymAndSynNameRelationships(PesiExportState state, Taxon childNodeTaxon) {
......
396 388
			// Store synonym data in Taxon table
397 389
			invokeSynonyms(state, synonymTaxonName);
398 390

  
399

  
400 391
			try {
401 392
				if (neededValuesNotNull(synonym, state)) {
402 393
					doCount(count++, modCount, pluralString);
403 394
					success &= mapping.invoke(synonym);
404

  
405 395
				}
406
			} catch (SQLException e) {
396
			} catch (Exception e) {
407 397
				logger.error("Synonym (" + synonym.getUuid() + ") could not be stored : " + e.getMessage());
408 398
			}
409 399

  
410

  
411 400
			// SynonymNameRelationship
412 401
			success &= saveNameRelationships(state, synonym);
413 402
		}
......
446 435
						success &= checkAndInvokeNameRelation(state, nameRelation, relatedTaxon, isFrom);
447 436
					}
448 437
				}
449
			} catch (SQLException e) {
438
			} catch (Exception e) {
450 439
				logger.error("NameRelationship " + nameRelation.getUuid() + " for " + nameRelation.getFromName().getTitleCache() + " and " + nameRelation.getToName().getTitleCache() + " could not be created: " + e.getMessage());
451 440
				success = false;
452 441
			}
......
454 443
		return success;
455 444
	}
456 445

  
457
	private boolean checkAndInvokeNameRelation(PesiExportState state, NameRelationship nameRelation, IdentifiableEntity<?> relatedObject, boolean isFrom) throws SQLException {
446
	private boolean checkAndInvokeNameRelation(PesiExportState state, NameRelationship nameRelation, IdentifiableEntity<?> relatedObject, boolean isFrom) {
458 447
		boolean success = true;
459 448
		if (isFrom){
460 449
			state.setCurrentToObject(relatedObject);
......
480 469
					doCount(count++, modCount, pluralString);
481 470
					success &= mapping.invoke(taxonRelationship);
482 471
				}
483
			} catch (SQLException e) {
472
			} catch (Exception e) {
484 473
				logger.error("TaxonRelationship could not be created for this TaxonRelation (" + taxonRelationship.getUuid() + "): " + e.getMessage());
485 474
			}
486 475
		}
......
494 483
	 */
495 484
	private void invokeSynonyms(PesiExportState state, TaxonName synonymTaxonName) {
496 485
		// Store KingdomFk and Rank information in Taxon table
497
		Integer kingdomFk = PesiTransformer.nomenClaturalCode2Kingdom(synonymTaxonName.getNomenclaturalCode());
486
		Integer kingdomFk = PesiTransformer.nomenClaturalCode2Kingdom(synonymTaxonName.getNameType());
498 487
		Integer synonymFk = state.getDbId(synonymTaxonName);
499 488

  
500
		saveSynonymData(state, synonymTaxonName, synonymTaxonName.getNomenclaturalCode(), kingdomFk, synonymFk);
489
		saveSynonymData(state, synonymTaxonName, synonymTaxonName.getNameType(), kingdomFk, synonymFk);
501 490
	}
502 491

  
503 492
	/**
......
647 636
			TaxonRelationship rel = CdmBase.deproxy(relationship, TaxonRelationship.class);
648 637
			taxon = rel.getToTaxon();
649 638
			name = taxon.getName();
650
			code = name.getNomenclaturalCode();
639
			code = name.getNameType();
651 640
			rel = null;
652 641

  
653 642
//		}else if (relationship.isInstanceOf(SynonymRelationship.class)){
......
660 649
		}else if (relationship.isInstanceOf(NameRelationship.class)){
661 650
			NameRelationship rel = CdmBase.deproxy(relationship,  NameRelationship.class);
662 651
			name = rel.getFromName();
663
			code =name.getNomenclaturalCode();
652
			code =name.getNameType();
664 653
			rel = null;
665 654

  
666 655
		}else if (relationship.isInstanceOf(HybridRelationship.class)){
667 656
			HybridRelationship rel =  CdmBase.deproxy(relationship,  HybridRelationship.class);
668 657
			name = rel.getParentName();
669
			code = name.getNomenclaturalCode();
658
			code = name.getNameType();
670 659
			rel = null;
671 660
		}
672 661
		taxon = null;
......
737 726
	private static Integer getRankFk(TaxonName taxonName, NomenclaturalCode nomenclaturalCode) {
738 727
		Integer result = null;
739 728
		if (nomenclaturalCode != null) {
740
			if (taxonName != null && taxonName.getRank() == null) {
729
			if (taxonName.getRank() == null) {
741 730
				logger.warn("Rank is null: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
742 731
			}
743 732
			result = PesiTransformer.rank2RankId(taxonName.getRank(), PesiTransformer.nomenClaturalCode2Kingdom(nomenclaturalCode));
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiTaxonExport.java
19 19
import java.util.HashSet;
20 20
import java.util.Iterator;
21 21
import java.util.List;
22
import java.util.Map;
22 23
import java.util.Set;
23 24
import java.util.UUID;
24 25
import java.util.regex.Matcher;
......
81 82
 * The export class for {@link eu.etaxonomy.cdm.model.name.TaxonNameBase TaxonNames}.<p>
82 83
 * Inserts into DataWarehouse database table <code>Taxon</code>.
83 84
 * It is divided into four phases:<p><ul>
84
 * <li>Phase 1:	Export of all {@link eu.etaxonomy.cdm.model.name.TaxonNameBase TaxonNames} except some data exported in the following phases.
85
 * <li>Phase 2:	Export of additional data: ParenTaxonFk and TreeIndex.
85
 * <li>Phase 1:	Export of all {@link eu.etaxonomy.cdm.model.name.TaxonName TaxonNames} except some data exported in the following phases.
86
 * <li>Phase 2:	Export of additional data: ParentTaxonFk and TreeIndex.
86 87
 * <li>Phase 3:	Export of additional data: Rank data, KingdomFk, TypeNameFk, expertFk and speciesExpertFk.
87 88
 * <li>Phase 4:	Export of Inferred Synonyms.</ul>
88 89
 *
......
100 101
	private static final String dbTableName = "Taxon";
101 102
	private static final String dbTableNameSynRel = "RelTaxon";
102 103
	private static final String dbTableAdditionalSourceRel = "AdditionalTaxonSource";
104

  
103 105
	private static final String pluralString = "Taxa";
104 106
	private static final String parentPluralString = "Taxa";
107

  
105 108
	private PreparedStatement parentTaxonFk_TreeIndex_KingdomFkStmt;
106 109
	private PreparedStatement parentTaxonFkStmt;
107 110
	private PreparedStatement rankTypeExpertsUpdateStmt;
......
200 203
			success &= doPhase04(state);
201 204

  
202 205

  
203
			//"PHASE 4: Creating Inferred Synonyms...
206
			//"PHASE 5: Creating Inferred Synonyms...
204 207
			success &= doPhase05(state, mapping, synonymRelMapping);
205 208

  
206 209
			logger.info("*** Finished Making " + pluralString + " ..." + getSuccessString(success));
......
283 286
				TaxonName taxonName = taxon.getName();
284 287

  
285 288
				TaxonName nvn = CdmBase.deproxy(taxonName);
286
				System.err.println(nvn.getTitleCache());
289
//				System.err.println(nvn.getTitleCache());
287 290
				if (! nvn.isProtectedTitleCache()){
288 291
					nvn.setTitleCache(null, false);
289 292
				}
......
319 322
				taxonName = null;
320 323
			}
321 324

  
322

  
323 325
			// Commit transaction
324 326
			commitTransaction(txStatus);
325 327
			logger.debug("Committed transaction.");
......
461 463
			logger.info("Started new transaction. Fetching some " + pluralString + " (max: " + limit + ") ...");
462 464

  
463 465
		}
464
		if (list == null ) {
465
			logger.info("No " + pluralString + " left to fetch.");
466
		}
466
		logger.info("No " + pluralString + " left to fetch.");
467

  
467 468
		// Commit transaction
468 469
		commitTransaction(txStatus);
469 470

  
......
730 731

  
731 732
		int limit = state.getConfig().getLimitSave();
732 733
		// Create inferred synonyms for accepted taxa
733
		logger.info("PHASE 4: Creating Inferred Synonyms...");
734
		logger.info("PHASE 5: Creating Inferred Synonyms...");
734 735

  
735
		// Determine the count of elements in datawarehouse database table Taxon
736
		// Determine the count of elements in data warehouse database table Taxon
736 737
		currentTaxonId = determineTaxonCount(state);
737 738
		currentTaxonId++;
738 739

  
......
747 748
		logger.info("Started new transaction. Fetching some " + parentPluralString + " first (max: " + limit + ") ...");
748 749
		List<TaxonBase> taxonList = null;
749 750

  
750

  
751

  
752 751
		while ((taxonList  = getTaxonService().listTaxaByName(Taxon.class, "*", "*", "*", "*", "*", Rank.SPECIES(), pageSize, pageNumber)).size() > 0) {
753
			HashMap<Integer, TaxonName> inferredSynonymsDataToBeSaved = new HashMap<Integer, TaxonName>();
752

  
753
		    Map<Integer, TaxonName> inferredSynonymsDataToBeSaved = new HashMap<>();
754 754

  
755 755
			logger.info("Fetched " + taxonList.size() + " " + parentPluralString + ". Exporting...");
756 756
			inferredSynonymsDataToBeSaved.putAll(createInferredSynonymsForTaxonList(state, mapping,
......
777 777
		}
778 778
		taxonList = null;
779 779
		while ((taxonList  = getTaxonService().listTaxaByName(Taxon.class, "*", "*", "*", "*", "*", Rank.SUBSPECIES(), pageSize, pageNumber)).size() > 0) {
780
			HashMap<Integer, TaxonName> inferredSynonymsDataToBeSaved = new HashMap<>();
780
			Map<Integer, TaxonName> inferredSynonymsDataToBeSaved = new HashMap<>();
781 781

  
782 782
			logger.info("Fetched " + taxonList.size() + " " + parentPluralString + ". Exporting...");
783 783
			inferredSynonymsDataToBeSaved.putAll(createInferredSynonymsForTaxonList(state, mapping,
784 784
					synRelMapping, taxonList));
785
			;
785

  
786 786
			doCount(count += taxonList.size(), modCount, inferredSynonymPluralString);
787 787
			// Commit transaction
788 788
			commitTransaction(txStatus);
......
808 808
		}
809 809

  
810 810
		taxonList = null;
811
//		logger.warn("Taking snapshot at the end of phase 4 of taxonExport");
811
//		logger.warn("Taking snapshot at the end of phase 5 of taxonExport");
812 812
//		ProfilerController.memorySnapshot();
813 813

  
814 814
		// Commit transaction
815 815
		commitTransaction(txStatus);
816 816
		System.gc();
817
		logger.debug("Taking snapshot at the end of phase 4 after gc() of taxonExport");
817
		logger.debug("Taking snapshot at the end of phase 5 after gc() of taxonExport");
818 818
		//ProfilerController.memorySnapshot();
819 819
		logger.debug("Committed transaction.");
820 820
		return success;
......
829 829
	 * @param inferredSynonymsDataToBeSaved
830 830
	 * @return
831 831
	 */
832
	private HashMap<Integer, TaxonName> createInferredSynonymsForTaxonList(PesiExportState state,
832
	private Map<Integer, TaxonName> createInferredSynonymsForTaxonList(PesiExportState state,
833 833
			PesiExportMapping mapping, PesiExportMapping synRelMapping,	 List<TaxonBase> taxonList) {
834 834

  
835 835
		Taxon acceptedTaxon;
......
837 837
		List<Synonym> inferredSynonyms = null;
838 838
		boolean localSuccess = true;
839 839

  
840
		HashMap<Integer, TaxonName> inferredSynonymsDataToBeSaved = new HashMap<Integer, TaxonName>();
840
		Map<Integer, TaxonName> inferredSynonymsDataToBeSaved = new HashMap<>();
841 841

  
842 842
		for (TaxonBase<?> taxonBase : taxonList) {
843 843

  
......
866 866
						// The stored classification from another TaxonNode is used. It's a simple, but not a failsafe fallback solution.
867 867
						if (taxonNodes.size() == 0) {
868 868
							//logger.error("Classification could not be determined directly from this Taxon: " + acceptedTaxon.getUuid() + " is misapplication? "+acceptedTaxon.isMisapplication()+ "). The classification of the last taxon is used");
869

  
870 869
						}
871 870
					}
872 871

  
......
934 933
				logger.error("This TaxonBase is not a Taxon even though it should be: " + taxonBase.getUuid() + " (" + taxonBase.getTitleCache() + ")");
935 934
			}
936 935
		}
937
		taxonList = null;
938 936
		return inferredSynonymsDataToBeSaved;
939 937
	}
940 938

  
......
943 941
	 * Handles names that do not appear in taxa
944 942
	 * @param state
945 943
	 * @param mapping
946
	 * @return
947 944
	 */
948 945
	private boolean doNames(PesiExportState state, PesiExportMapping additionalSourceMapping)  throws SQLException {
949 946

  
......
963 960
			// Get the limit for objects to save within a single transaction.
964 961
			int limit = state.getConfig().getLimitSave();
965 962

  
966

  
967 963
			logger.info("PHASE 1b: Export Pure Names ...");
968 964
			// Start transaction
969 965
			TransactionStatus txStatus = startTransaction(true);
......
992 988
				txStatus = startTransaction(true);
993 989
				logger.info("Started new transaction for PureNames. Fetching some " + pluralString + " (max: " + limit + ") ...");
994 990
			}
995
			if (list == null) {
996
				logger.info("No " + pluralString + " left to fetch.");
997
			}
998
			list = null;
991
			logger.info("No " + pluralString + " left to fetch.");
992

  
999 993
			// Commit transaction
1000 994
			commitTransaction(txStatus);
1001 995
			logger.debug("Committed transaction.");
......
1147 1141
					logger.debug("Taxon is not a PESI taxon: " + childTaxon.getUuid());
1148 1142
				}
1149 1143
			}
1150

  
1151 1144
		} else {
1152 1145
			logger.error("Taxon is NULL for TaxonNode: " + childNode.getUuid());
1153 1146
		}
......
1169 1162
			TaxonBase<?> parentTaxon = null;
1170 1163
			if (parentNode != null) {
1171 1164
				parentTaxon = parentNode.getTaxon();
1172

  
1173 1165
			}
1174 1166

  
1175 1167
			invokeParentTaxonFkAndTreeIndex(state.getDbId(parentTaxon), currentTaxonFk,	treeIndex);
1176 1168
		}
1177

  
1178 1169
	}
1179 1170

  
1180 1171
	/**
......
1412 1403
	 */
1413 1404
	@SuppressWarnings("unused")  //used by mapper
1414 1405
	private static Integer getRankFk(TaxonName taxonName) {
1415
		return getRankFk(taxonName, taxonName.getNomenclaturalCode());
1406
		return getRankFk(taxonName, taxonName.getNameType());
1416 1407
	}
1417 1408

  
1418 1409

  
......
1452 1443
	 */
1453 1444
	@SuppressWarnings("unused")  //used by mapper
1454 1445
	private static String getRankCache(TaxonName taxonName, PesiExportState state) {
1455
		return getRankCache(taxonName, taxonName.getNomenclaturalCode(), state);
1446
		return getRankCache(taxonName, taxonName.getNameType(), state);
1456 1447
	}
1457 1448

  
1458

  
1459 1449
	/**
1460 1450
	 * Returns the <code>RankCache</code> attribute.
1461 1451
	 * @param taxonName The {@link TaxonNameBase TaxonName}.
......
1471 1461
			logger.warn("No nomenclatural code defined for name " + taxonName.getUuid());
1472 1462
			return null;
1473 1463
		}
1474

  
1475 1464
	}
1476 1465

  
1477

  
1478 1466
	/**
1479 1467
	 * Returns the <code>DisplayName</code> attribute.
1480 1468
	 * @param taxon The {@link TaxonBase Taxon}.
......
1497 1485
	 * @return The <code>AuthorString</code> attribute.
1498 1486
	 * @see MethodMapper
1499 1487
	 */
1500
	@SuppressWarnings("unused") //used by mapper
1488
	//used by mapper
1501 1489
	protected static String getAuthorString(TaxonBase<?> taxon) {
1502 1490
		try {
1503 1491
			String result = null;
......
1544 1532
			e.printStackTrace();
1545 1533
			return null;
1546 1534
		}
1547

  
1548 1535
	}
1549 1536

  
1550

  
1551 1537
	/**
1552 1538
	 * Returns the <code>DisplayName</code> attribute.
1553 1539
	 * @param taxonName The {@link TaxonNameBase TaxonName}.
1554 1540
	 * @return The <code>DisplayName</code> attribute.
1555 1541
	 * @see MethodMapper
1556 1542
	 */
1557
	@SuppressWarnings("unused")  //used by Mapper
1543
	 //used by Mapper
1558 1544
	private static String getDisplayName(TaxonName taxonName) {
1559 1545
		// TODO: extension?
1560 1546
		if (taxonName == null) {
......
1759 1745
					logger.error("This TaxonName has more than one Nomenclatural Status: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
1760 1746
				}
1761 1747
			}
1762

  
1763 1748
		} catch (Exception e) {
1764 1749
			e.printStackTrace();
1765 1750
		}
......
1784 1769
			} else {
1785 1770
				result = PesiTransformer.taxonBase2statusFk(taxon);
1786 1771
			}
1787

  
1788 1772
		} catch (Exception e) {
1789 1773
			e.printStackTrace();
1790 1774
		}
......
1841 1825
		String result = null;
1842 1826

  
1843 1827
		try {
1844
		if (taxonName != null) {
1845
			Set<NameTypeDesignation> nameTypeDesignations = taxonName.getNameTypeDesignations();
1846
			if (nameTypeDesignations.size() == 1) {
1847
				NameTypeDesignation nameTypeDesignation = nameTypeDesignations.iterator().next();
1848
				if (nameTypeDesignation != null) {
1849
					TaxonName typeName = nameTypeDesignation.getTypeName();
1850
					if (typeName != null) {
1851
						result = typeName.getTitleCache();
1852
					}
1853
				}
1854
			} else if (nameTypeDesignations.size() > 1) {
1855
				logger.warn("This TaxonName has " + nameTypeDesignations.size() + " NameTypeDesignations: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
1856
			}
1857
		}
1858

  
1828
    		if (taxonName != null) {
1829
    			Set<NameTypeDesignation> nameTypeDesignations = taxonName.getNameTypeDesignations();
1830
    			if (nameTypeDesignations.size() == 1) {
1831
    				NameTypeDesignation nameTypeDesignation = nameTypeDesignations.iterator().next();
1832
    				if (nameTypeDesignation != null) {
1833
    					TaxonName typeName = nameTypeDesignation.getTypeName();
1834
    					if (typeName != null) {
1835
    						result = typeName.getTitleCache();
1836
    					}
1837
    				}
1838
    			} else if (nameTypeDesignations.size() > 1) {
1839
    				logger.warn("This TaxonName has " + nameTypeDesignations.size() + " NameTypeDesignations: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
1840
    			}
1841
    		}
1859 1842
		} catch (Exception e) {
1860 1843
			e.printStackTrace();
1861 1844
		}
......
2159 2142
	}
2160 2143

  
2161 2144

  
2162

  
2163

  
2164 2145
	/**
2165 2146
	 * Returns the <code>DerivedFromGuid</code> attribute.
2166 2147
	 * @param taxonName The {@link TaxonNameBase TaxonName}.
......
2525 2506
		return mapping;
2526 2507
	}
2527 2508

  
2509

  
2528 2510
	private void addNameMappers(PesiExportMapping mapping) {
2529 2511
		mapping.addMapper(DbStringMapper.NewInstance("GenusOrUninomial", "GenusOrUninomial"));
2530 2512
		mapping.addMapper(DbStringMapper.NewInstance("InfraGenericEpithet", "InfraGenericEpithet"));
......
2556 2538

  
2557 2539
	}
2558 2540

  
2541
    /**
2542
     * Returns the <code>TaxonFk1</code> attribute. It corresponds to a CDM <code>TaxonRelationship</code>.
2543
     * @param relationship The {@link RelationshipBase Relationship}.
2544
     * @param state The {@link PesiExportState PesiExportState}.
2545
     * @return The <code>TaxonFk1</code> attribute.
2546
     * @see MethodMapper
2547
     */
2548
    @SuppressWarnings("unused")
2549
    private static Integer getSynonym(Synonym synonym, PesiExportState state) {
2550
         return state.getDbId(synonym);
2551
    }
2552

  
2553
    @SuppressWarnings("unused")
2554
    private static String getSynonymTypeCache(Synonym synonym, PesiExportState state) {
2555
        String result = null;
2556
        NomenclaturalCode code = null;
2557
        code = CdmBase.deproxy(synonym, Synonym.class).getAcceptedTaxon().getName().getNameType();
2558

  
2559
        if (code != null) {
2560
            result = state.getConfig().getTransformer().getCacheBySynonymType(synonym, code);
2561
        } else {
2562
            logger.error("NomenclaturalCode is NULL while creating the following synonym: " + synonym.getUuid());
2563
        }
2564
        return result;
2565
    }
2566

  
2559 2567
	private PesiExportMapping getSynRelMapping() {
2560 2568
		PesiExportMapping mapping = new PesiExportMapping(dbTableNameSynRel);
2569
		logger.warn("SynRelMapping currently not implemented. Needs to be checked");
2561 2570

  
2562
		mapping.addMapper(MethodMapper.NewInstance("TaxonFk1", this.getClass(), "getTaxonFk1", RelationshipBase.class, PesiExportState.class));
2563
		mapping.addMapper(MethodMapper.NewInstance("TaxonFk2", this.getClass(), "getTaxonFk2", RelationshipBase.class, PesiExportState.class));
2564
		mapping.addMapper(MethodMapper.NewInstance("RelTaxonQualifierFk", this,  RelationshipBase.class));
2565
		mapping.addMapper(MethodMapper.NewInstance("RelQualifierCache", this, RelationshipBase.class, PesiExportState.class));
2566
		mapping.addMapper(MethodMapper.NewInstance("Notes", this,  RelationshipBase.class));
2571
		mapping.addMapper(MethodMapper.NewInstance("TaxonFk1", this.getClass(), "getSynonym", Synonym.class, PesiExportState.class));
2572
		mapping.addMapper(DbObjectMapper.NewInstance("acceptedTaxon", "TaxonFk2"));
2573
		mapping.addMapper(DbObjectMapper.NewInstance("type", "RelTaxonQualifierFk"));
2574
		mapping.addMapper(MethodMapper.NewInstance("RelQualifierCache", this.getClass(), "getSynonymTypeCache", Synonym.class, PesiExportState.class));
2575
		// TODO
2576
//		mapping.addMapper(MethodMapper.NewInstance("Notes", this,  RelationshipBase.class));
2567 2577

  
2568 2578
		return mapping;
2569 2579
	}
2570 2580

  
2571
	private PesiExportMapping getAdditionalSourceMapping(PesiExportState state)  throws UndefinedTransformerMethodException{
2581
	private PesiExportMapping getAdditionalSourceMapping(PesiExportState state) {
2572 2582
		PesiExportMapping mapping = new PesiExportMapping(dbTableAdditionalSourceRel);
2573 2583

  
2574 2584
		mapping.addMapper(IdMapper.NewInstance("TaxonFk"));
......
2578 2588
//		mapping.addMapper(DbObjectMapper.NewInstance("NomenclaturalReference", "SourceNameCache", IS_CACHE));
2579 2589
		mapping.addMapper(MethodMapper.NewInstance("SourceNameCache", this, TaxonName.class));
2580 2590

  
2581

  
2582 2591
		//we have only nomenclatural references here
2583 2592
		mapping.addMapper(DbConstantMapper.NewInstance("SourceUseFk", Types.INTEGER , PesiTransformer.NOMENCLATURAL_REFERENCE));
2584 2593
		mapping.addMapper(DbConstantMapper.NewInstance("SourceUseCache", Types.VARCHAR, state.getTransformer().getSourceUseCacheByKey( PesiTransformer.NOMENCLATURAL_REFERENCE)));
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiTransformer.java
759 759
	public static int STATUS_MANAGED = 7;
760 760
	public static int STATUS_DOUBTFUL = 8;
761 761

  
762
	private final Map<String, Integer> tdwgKeyMap = new HashMap<String, Integer>();
763
	private final Map<Integer, String> areaCacheMap = new HashMap<Integer, String>();
764
	private final Map<Integer, String> languageCacheMap  = new HashMap<Integer, String>();
765
	private final Map<Integer, String> featureCacheMap  = new HashMap<Integer, String>();
766
	private final Map<Integer, String> nameStatusCacheMap  = new HashMap<Integer, String>();
767
	private final Map<Integer, String> qualityStatusCacheMap  = new HashMap<Integer, String>();
768
	private final Map<Integer, String> taxonStatusCacheMap  = new HashMap<Integer, String>();
769
	private final Map<Integer, String> taxRelQualifierCacheMap  = new HashMap<Integer, String>();
770
	private final Map<Integer, String> taxRelZooQualifierCacheMap  = new HashMap<Integer, String>();
771
	private final Map<Integer, String> sourceUseCacheMap  = new HashMap<Integer, String>();
772
	private final Map<Integer, String> fossilStatusCacheMap  = new HashMap<Integer, String>();
773
	private final Map<Integer, String> typeDesigStatusCacheMap  = new HashMap<Integer, String>();
774
	private final Map<Integer, String> sourceCategoryCacheMap  = new HashMap<Integer, String>();
775
	private final Map<Integer, String> occurrenceStatusCacheMap  = new HashMap<Integer, String>();
776
	private final Map<Integer, Map<Integer, String>> rankCacheMap  = new  HashMap<Integer, Map<Integer, String>>();
777
	private final Map<Integer, Map<Integer, String>> rankAbbrevCacheMap  = new  HashMap<Integer, Map<Integer, String>>();
762
	private final Map<String, Integer> tdwgKeyMap = new HashMap<>();
763
	private final Map<Integer, String> areaCacheMap = new HashMap<>();
764
	private final Map<Integer, String> languageCacheMap  = new HashMap<>();
765
	private final Map<Integer, String> featureCacheMap  = new HashMap<>();
766
	private final Map<Integer, String> nameStatusCacheMap  = new HashMap<>();
767
	private final Map<Integer, String> qualityStatusCacheMap  = new HashMap<>();
768
	private final Map<Integer, String> taxonStatusCacheMap  = new HashMap<>();
769
	private final Map<Integer, String> taxRelQualifierCacheMap  = new HashMap<>();
770
	private final Map<Integer, String> taxRelZooQualifierCacheMap  = new HashMap<>();
771
	private final Map<Integer, String> sourceUseCacheMap  = new HashMap<>();
772
	private final Map<Integer, String> fossilStatusCacheMap  = new HashMap<>();
773
	private final Map<Integer, String> typeDesigStatusCacheMap  = new HashMap<>();
774
	private final Map<Integer, String> sourceCategoryCacheMap  = new HashMap<>();
775
	private final Map<Integer, String> occurrenceStatusCacheMap  = new HashMap<>();
776
	private final Map<Integer, Map<Integer, String>> rankCacheMap  = new  HashMap<>();
777
	private final Map<Integer, Map<Integer, String>> rankAbbrevCacheMap  = new  HashMap<>();
778 778

  
779 779

  
780 780
	private final Source destination;

Also available in: Unified diff