Project

General

Profile

« Previous | Next » 

Revision 8275a22c

Added by Andreas Müller over 3 years ago

cleanup

View differences:

cdm-eflora/src/main/java/eu/etaxonomy/cdm/io/eflora/centralAfrica/ferns/CentralAfricaFernsTaxonRelationImport.java
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

  
10 9
package eu.etaxonomy.cdm.io.eflora.centralAfrica.ferns;
11 10

  
12 11
import java.sql.ResultSet;
......
60 59
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
61 60
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
62 61

  
63

  
64 62
/**
65 63
 * @author a.mueller
66 64
 */
67

  
68 65
@Component
69
public class CentralAfricaFernsTaxonRelationImport  extends CentralAfricaFernsImportBase<TaxonBase> implements IMappingImport<TaxonBase, CentralAfricaFernsImportState>{
70
	private static final Logger logger = Logger.getLogger(CentralAfricaFernsTaxonRelationImport.class);
66
public class CentralAfricaFernsTaxonRelationImport
67
        extends CentralAfricaFernsImportBase<TaxonBase>
68
        implements IMappingImport<TaxonBase, CentralAfricaFernsImportState>{
71 69

  
72
	private DbImportMapping<?,?> mapping;
70
    private static final long serialVersionUID = 5561099127416844593L;
71
    private static final Logger logger = Logger.getLogger(CentralAfricaFernsTaxonRelationImport.class);
73 72

  
73
	private DbImportMapping<?,?> mapping;
74 74

  
75 75
	private static final String pluralString = "taxon relations";
76 76
	private static final String dbTableName = "[African pteridophytes]";
77 77
	private static final Class<?> cdmTargetClass = TaxonBase.class;
78 78

  
79
	private final Map<String, UUID> nameCacheTaxonMap = new HashMap<String, UUID>();
80
	private final Map<String, UUID> titleCacheTaxonMap = new HashMap<String, UUID>();
81

  
82
	private CentralAfricaFernsImportState state;
83

  
79
	private final Map<String, UUID> nameCacheTaxonMap = new HashMap<>();
80
	private final Map<String, UUID> titleCacheTaxonMap = new HashMap<>();
84 81

  
85 82
	public CentralAfricaFernsTaxonRelationImport(){
86 83
		super(pluralString, dbTableName, cdmTargetClass);
87 84
	}
88 85

  
89

  
90 86
	@Override
91 87
	protected String getIdQuery() {
92 88
		String strQuery = " SELECT [Taxon number] FROM " + dbTableName;;
......
107 103
		return mapping;
108 104
	}
109 105

  
110
	/* (non-Javadoc)
111
	 * @see eu.etaxonomy.cdm.io.eflora.centralAfrica.ferns.CentralAfricaFernsImportBase#getRecordQuery(eu.etaxonomy.cdm.io.eflora.centralAfrica.ferns.CentralAfricaFernsImportConfigurator)
112
	 */
113 106
	@Override
114 107
	protected String getRecordQuery(CentralAfricaFernsImportConfigurator config) {
115 108
		String strSelect = " SELECT * ";
......
120 113
		return strRecordQuery;
121 114
	}
122 115

  
123

  
124
	/* (non-Javadoc)
125
	 * @see eu.etaxonomy.cdm.io.eflora.centralAfrica.ferns.CentralAfricaFernsImportBase#doInvoke(eu.etaxonomy.cdm.io.eflora.centralAfrica.ferns.CentralAfricaFernsImportState)
126
	 */
127 116
	@Override
128 117
	protected void doInvoke(CentralAfricaFernsImportState state) {
129
		this.state = state;
130 118
		fillTaxonMap();
131 119
		super.doInvoke(state);
132 120
		return;
133 121
	}
134 122

  
135

  
136 123
	/**
137 124
	 * Fills the nameCache and the titleCache maps. The maps are used to find existing taxa
138 125
	 * by titleCache or nameCache matching.
......
152 139
		}
153 140
	}
154 141

  
155

  
156 142
	@Override
157 143
	public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, CentralAfricaFernsImportState state) {
158 144
		String nameSpace;
......
175 161
			Map<String, TaxonBase> taxonMap = getCommonService().getSourcedObjectsByIdInSourceC((Class<TaxonBase>) cdmClass, taxonIdSet, nameSpace);
176 162
			result.put(nameSpace, taxonMap);
177 163

  
178

  
179 164
			//reference map
180 165
			this.sourceReference = getFernsSourceReference(state);
181 166
//			nameSpace = "Reference";
......
189 174
		return result;
190 175
	}
191 176

  
192

  
193
	/* (non-Javadoc)
194
	 * @see eu.etaxonomy.cdm.io.common.mapping.IMappingImport#createObject(java.sql.ResultSet, eu.etaxonomy.cdm.io.common.ImportStateBase)
195
	 */
196 177
	@Override
197 178
	public TaxonBase createObject(ResultSet rs, CentralAfricaFernsImportState state) throws SQLException {
198 179
		TaxonBase<?> result = null;
......
213 194
			e.printStackTrace();
214 195
			return result;
215 196
		}
216

  
217 197
	}
218 198

  
219

  
220 199
	/**
221 200
	 * Class to store all epithets of the database record. Maybe extended with business logic.
222 201
	 */
......
240 219
		private String subFormaName;
241 220
	}
242 221

  
243

  
244 222
	/**
245 223
	 * Handles records with status synonym. The synonym is attached to the accepted taxon.
246
	 *
247
	 * @param rs
248
	 * @param state
249
	 * @return
250
	 * @throws SQLException
251 224
	 */
252 225
	private Synonym handleSynonym(ResultSet rs, CentralAfricaFernsImportState state) throws SQLException {
253 226
		String accTaxonId = rs.getString("Current");
......
266 239
				Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class);
267 240
				taxon.addSynonym(synonym, SynonymType.SYNONYM_OF());
268 241
				if ("p.p.".equalsIgnoreCase(nomRemarksString)){
269
					synonym.setProParte(true);
242
					logger.error("Pro parte synonyms are currently not handled correctly anymore. Needs to be adapted also in TaxonImport");
270 243
				}
271 244
			}else{
272 245
				logger.warn("Accepted taxon (" + accTaxonId + ") for synonym (" + synonymId +") is not of type 'Current'");
......
282 255
	/**
283 256
	 * Handles all records with status 'current'. Creates parent-child relationships to the
284 257
	 * higher taxa. Uses a complex algorithm to reuse existing higher taxa.
285
	 * @param rs
286
	 * @param state
287
	 * @return
288
	 * @throws SQLException
289 258
	 */
290 259
	private Taxon handleTaxon(ResultSet rs, CentralAfricaFernsImportState state) throws SQLException {
291 260
		String taxonNumber = rs.getString("Taxon number");
......
348 317
	/**
349 318
	 * Handles the case when the database record has data for a taxon of a higher rank
350 319
	 * than the <code>child</code> taxon's rank.
351
	 * @param state
352
	 * @param rs
353
	 * @param child
354
	 * @param epithets
355
	 * @param higherTaxon
356
	 * @param citation
357
	 * @param microcitation
358
	 * @throws SQLException
359 320
	 */
360 321
	private void handleHigherTaxonMustExist(CentralAfricaFernsImportState state, ResultSet rs, Taxon child, Epithets epithets, Taxon constructedHigherTaxon, Reference citation, String microCitation) throws SQLException {
361 322
		Taxon parentTaxon = getParent(child);
......
397 358
	/**
398 359
	 * Merges author information of the constructed taxon into the existing taxon.
399 360
	 * Returns the existing taxon.
400
	 * @param state
401
	 * @param parentTaxon
402
	 * @param constructedHigherTaxon
403 361
	 */
404 362
	private Taxon mergeExistingAndConstructedTaxon(CentralAfricaFernsImportState state, Taxon existingTaxon, Taxon constructedTaxon) {
405 363
		INonViralName constructedName = constructedTaxon.getName();
......
457 415
		return constructedHigherTaxon;
458 416
	}
459 417

  
460

  
461 418
	/**
462 419
	 * Handles the case that the existing parent taxon and the constructed parent taxon
463 420
	 * have a diffent rank. Returns the constructedHigherTaxon if no common grand parent exists.
......
521 478

  
522 479
	/**
523 480
	 * Checks if a taxon is a grand parent of another taxon
524
	 * @param lowerTaxon
525
	 * @param higherTaxon
526
	 * @return
527 481
	 */
528 482
	private Taxon checkIsGrandParent(Taxon childTaxon, Taxon grandParentTaxon) {
529 483
		IBotanicalName lowerName = childTaxon.getName();
......
545 499
		}
546 500
	}
547 501

  
548

  
549 502
	/**
550 503
	 * Checks if the name caches match.
551
	 * @param name1
552
	 * @param name2
553
	 * @return
554 504
	 */
555 505
	private boolean nameCachesMatch(IBotanicalName name1, IBotanicalName name2) {
556 506
		return CdmUtils.nullSafeEqual(name1.getNameCache(), name2.getNameCache());
......
558 508

  
559 509
	/**
560 510
	 * Checks if the name caches of the related names match.
561
	 *@param taxon1
562
	 * @param taxon2
563
	 * @return
564 511
	 */
565 512
	private boolean nameCachesMatch(Taxon taxon1, Taxon taxon2) {
566 513
		IBotanicalName name1 = taxon1.getName();
......
571 518

  
572 519
	/**
573 520
	 * Checks if all authors match
574
	 * @param name1
575
	 * @param name2
576
	 * @return
577 521
	 */
578 522
	private boolean authorsMatch(INonViralName name1, INonViralName name2) {
579 523
		String combinationAuthor1 = name1.computeCombinationAuthorNomenclaturalTitle();
......
594 538

  
595 539
	/**
596 540
	 * Checks if all authors of the related names match.
597
	 * @param taxon1
598
	 * @param taxon2
599
	 * @return
600 541
	 */
601 542
	private boolean authorsMatch(Taxon taxon1, Taxon taxon2) {
602 543
		IBotanicalName name1 = taxon1.getName();
......
606 547

  
607 548
	/**
608 549
	 * Compares ranks of 2 names.
609
	 * @param parentName
610
	 * @param constructedName
611
	 * @return
612 550
	 */
613 551
	private int compareRanks(IBotanicalName name1, IBotanicalName name2) {
614 552
		return name1.getRank().compareTo(name2.getRank());
......
616 554

  
617 555
	/**
618 556
	 * Compares the ranks of the according names.
619
	 * @param taxon1
620
	 * @param taxon2
621
	 * @return
622 557
	 */
623 558
	private int compareRanks(Taxon taxon1, Taxon taxon2) {
624 559
		IBotanicalName name1 = taxon1.getName();
......
631 566
	/**
632 567
	 * Checks if 2 names match.
633 568
	 * Current strategy: true, if ranks are equal, nameCaches match and authors match
634
	 * @param name1
635
	 * @param name2
636
	 * @return
637 569
	 */
638 570
	private boolean namesMatch(IBotanicalName name1, IBotanicalName name2) {
639 571
		return compareRanks(name1, name2)==0 && nameCachesMatch(name1, name2) && authorsMatch(name1, name2);
......
642 574
	/**
643 575
	 * Checks if the according names match.
644 576
	 * @see #namesMatch(BotanicalName, BotanicalName)
645
	 * @param taxon1
646
	 * @param taxon2
647
	 * @return
648 577
	 */
649 578
	private boolean namesMatch(Taxon taxon1, Taxon taxon2) {
650 579
		IBotanicalName name1 = taxon1.getName();
......
678 607
		}
679 608
	}
680 609

  
681

  
682 610
	/**
683 611
	 * Persists and saves the newly created taxon to the CDM store and to the look-up
684 612
	 * maps.
......
710 638
	/**
711 639
	 * Adds the parent child relationship. Creates and saves the classification if needed.
712 640
	 * Adds parent and child to the classification.
713
	 * @param state
714
	 * @param treeRefFk
715
	 * @param child
716
	 * @param parent
717
	 * @param citation
718
	 * @param microCitation
719
	 * @return
720 641
	 */
721 642
	private boolean makeTaxonomicallyIncluded(CentralAfricaFernsImportState state, Integer treeRefFk, Taxon child, Taxon parent, Reference citation, String microCitation){
722 643
		String treeKey;
......
856 777
		return taxonName;
857 778
	}
858 779

  
859

  
860

  
861 780
	private IBotanicalName handleUninomial(Rank lowerTaxonRank, IBotanicalName taxonName,  Epithets epithets) {
862 781

  
863 782
		Rank newRank = null;
......
887 806
		return taxonName;
888 807
	}
889 808

  
890

  
891 809
	/**
892 810
	 * for internal use only, used by MethodMapper
893 811
	 */
......
911 829
		return taxonBase;
912 830
	}
913 831

  
914

  
915 832
	/**
916 833
	 * for internal use only, used by MethodMapper
917 834
	 */
......
946 863
		}
947 864
	}
948 865

  
949

  
950 866
	/**
951 867
	 * for internal use only, used by MethodMapper
952 868
	 * @param commonNames
......
970 886
		return taxonBase;
971 887
	}
972 888

  
973

  
974

  
975

  
976 889
	private void makeDistributionDetailed(Taxon taxon, String distributionDetailed) {
977 890
		if (StringUtils.isNotBlank(distributionDetailed)){
978 891
			TaxonDescription description = getTaxonDescription(taxon, false, true);
......
982 895
		}
983 896
	}
984 897

  
985

  
986 898
	private void makeProvince(Taxon taxon, String province) {
987 899
		if (StringUtils.isNotBlank(province)){
988 900
			TaxonDescription description = getTaxonDescription(taxon, false, true);
......
992 904
		}
993 905
	}
994 906

  
995

  
996
	/**
997
	 * @param state
998
	 * @param taxonNumber
999
	 * @param taxonBase
1000
	 * @param countriesString
1001
	 */
1002 907
	private void makeCountries(CentralAfricaFernsImportState state, String taxonNumber, Taxon taxon, TaxonName nameUsedInSource, String countriesString, String province, String distributionDetailed) {
1003 908
		countriesString = countriesString.replaceAll("\\*", "");
1004 909
		countriesString = countriesString.replace("  ", " ");
......
1026 931
		}
1027 932
	}
1028 933

  
1029

  
1030 934
	private void makeSingleCountry(CentralAfricaFernsImportState state, String taxonNumber, Taxon taxon, TaxonName nameUsedInSource, String country) throws UndefinedTransformerMethodException {
1031 935
		boolean areaDoubtful = false;
1032 936
		Distribution distribution = Distribution.NewInstance(null, PresenceAbsenceTerm.PRESENT());
......
1063 967
			country = country.replace("Islands", "Is.");
1064 968
		}
1065 969

  
1066

  
1067 970
		//areas
1068 971
		if (TdwgAreaProvider.isTdwgAreaLabel(country)){
1069 972
			//tdwg
......
1101 1004
		description.addElement(distribution);
1102 1005
	}
1103 1006

  
1104

  
1105

  
1106
	/**
1107
	 * @param state
1108
	 * @return
1109
	 */
1110 1007
	private Reference sourceReference = null;
1111 1008
	private Reference getFernsSourceReference(CentralAfricaFernsImportState state) {
1112 1009
//		if (sourceReference == null || true){
......
1116 1013
		return sourceReference;
1117 1014
	}
1118 1015

  
1119

  
1120 1016
	private String makeCountryBrackets(CentralAfricaFernsImportState state, String taxonNumber, Taxon taxon,
1121 1017
	        TaxonName nameUsedInSource, String country) {
1122 1018
		String[] split = (country + " ").split("\\(.*\\)");
......
1157 1053
		return country;
1158 1054
	}
1159 1055

  
1160

  
1161

  
1162

  
1163
	/* (non-Javadoc)
1164
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
1165
	 */
1166 1056
	@Override
1167 1057
	protected boolean doCheck(CentralAfricaFernsImportState state){
1168 1058
		IOValidator<CentralAfricaFernsImportState> validator = new CentralAfricaFernsTaxonImportValidator();
1169 1059
		return validator.validate(state);
1170 1060
	}
1171 1061

  
1172
	/* (non-Javadoc)
1173
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IoStateBase)
1174
	 */
1175 1062
	@Override
1176 1063
	protected boolean isIgnore(CentralAfricaFernsImportState state){
1177 1064
		return ! state.getConfig().isDoRelTaxa();
1178 1065
	}
1179 1066

  
1180

  
1181

  
1182 1067
//************************ OLD **********************************************************
1183 1068

  
1184 1069
	/**
......
1248 1133
		}
1249 1134
	}
1250 1135

  
1251

  
1252

  
1253 1136
	/**
1254 1137
	 * Tests if this the child taxon already is a child of the higher taxon.
1255
	 * @param child
1256
	 * @param higherTaxon
1257
	 * @return
1258 1138
	 */
1259 1139
	private boolean includedRelationshipExists_Old(Taxon child, Taxon higherTaxon) {
1260 1140
		int countNodes = higherTaxon.getTaxonNodes().size();
......
1268 1148
		}
1269 1149
	}
1270 1150

  
1271

  
1272

  
1273 1151
	private boolean childExists_old(Taxon child, TaxonNode higherNode) {
1274 1152
		for (TaxonNode childNode : higherNode.getChildNodes()){
1275 1153
			String existingChildTitle = childNode.getTaxon().getName().getTitleCache();
......
1280 1158
		}
1281 1159
		return false;
1282 1160
	}
1283

  
1284

  
1285
}
1161
}

Also available in: Unified diff