Project

General

Profile

« Previous | Next » 

Revision 23336874

Added by Andreas Müller about 6 years ago

cleanup BM import

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelCommonNamesImport.java
219 219
				Language language = getAndHandleLanguage(iso6392Map, iso639_2, iso639_1, languageString, originalLanguageString, state);
220 220

  
221 221
				//CommonTaxonName
222
				List<CommonTaxonName> commonTaxonNames = new ArrayList<CommonTaxonName>();
222
				List<CommonTaxonName> commonTaxonNames = new ArrayList<>();
223 223
				for (String regionFk : regionFkSplit){ //
224 224
					CommonTaxonName commonTaxonName;
225 225
					if (commonTaxonNames.size() == 0){
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelTaxonImport.java
217 217

  
218 218
					//detail
219 219
					String detail = rs.getString("Detail");
220
					if (StringUtils.isNotBlank(detail)){
220
					if (isNotBlank(detail)){
221 221
						ExtensionType detailExtensionType = getExtensionType(state, BerlinModelTransformer.DETAIL_EXT_UUID, "micro reference","micro reference","micro ref.");
222 222
						Extension.NewInstance(taxonBase, detail, detailExtensionType);
223 223
					}
224 224
					//idInSource
225 225
					String idInSource = rs.getString("IdInSource");
226
					if (StringUtils.isNotBlank(idInSource)){
226
					if (isNotBlank(idInSource)){
227 227
						ExtensionType detailExtensionType = getExtensionType(state, BerlinModelTransformer.ID_IN_SOURCE_EXT_UUID, "Berlin Model IdInSource","Berlin Model IdInSource","BM source id");
228 228
						Extension.NewInstance(taxonBase, idInSource, detailExtensionType);
229 229
					}
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelTaxonNameImport.java
205 205

  
206 206
					if (rank == null){
207 207
						//TODO rank should never be null or a more sophisticated algorithm has to be implemented for genus/supraGenericName
208
						logger.warn("Rank is null. Genus epethiton was imported. May be wrong");
208
						logger.warn("Rank is null. Genus epithet was imported. May be wrong");
209 209
						success = false;
210 210
					}
211 211

  
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelTaxonRelationImport.java
90 90
		//reference map
91 91
		String nameSpace = BerlinModelReferenceImport.REFERENCE_NAMESPACE;
92 92
		Class<?> cdmClass = Reference.class;
93
		Map<String, Reference> refMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
93
		@SuppressWarnings("unchecked")
94
        Map<String, Reference> refMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
94 95

  
95
		String treeName = "Classification - No Name";
96
		String classificationName = "Classification - No Name";
96 97

  
97 98
		ResultSet rs = state.getConfig().getSource().getResultSet(getClassificationQuery(state)) ;
98 99
		int i = 0;
99 100
		//for each reference
100 101
		try {
101 102
			//TODO handle case useSingleClassification = true && sourceSecId = null, which returns no record
102
			while (rs.next()){
103
			boolean isFirst = true;
104
		    while (rs.next()){
103 105

  
104 106
				try {
105 107
					if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("RelPTaxa handled: " + (i-1));}
......
109 111
					Reference ref = refMap.get(ptRefFk);
110 112

  
111 113
					String refCache = rs.getString("RefCache");
112
					if (StringUtils.isNotBlank(refCache)){
113
						treeName = refCache;
114
					if (isNotBlank(refCache)){
115
						classificationName = refCache;
114 116
					}
115 117
					if (ref != null && StringUtils.isNotBlank(ref.getTitleCache())){
116
						treeName = ref.getTitleCache();
118
						classificationName = ref.getTitleCache();
119
					}
120
					if (isFirst && isNotBlank(state.getConfig().getClassificationName())){
121
					    classificationName = state.getConfig().getClassificationName();
117 122
					}
118
					Classification tree = Classification.NewInstance(treeName);
123
					Classification tree = Classification.NewInstance(classificationName);
119 124
					tree.setReference(ref);
120 125
					if (i == 1 && state.getConfig().getClassificationUuid() != null){
121 126
						tree.setUuid(state.getConfig().getClassificationUuid());
......
125 130

  
126 131
					getClassificationService().save(tree);
127 132
					state.putClassificationUuidInt(ptRefFkInt, tree);
133
					isFirst = false;
128 134
				} catch (Exception e) {
129 135
					logger.error("Error in BerlinModleTaxonRelationImport.makeClassifications: " + e.getMessage());
130 136
					e.printStackTrace();
......
220 226
	@Override
221 227
	protected String getRecordQuery(BerlinModelImportConfigurator config) {
222 228
		String strQuery =
223
			" SELECT RelPTaxon.*, FromTaxon.RIdentifier as taxon1Id, ToTaxon.RIdentifier as taxon2Id, ToTaxon.PTRefFk as treeRefFk, FromTaxon.PTRefFk as fromRefFk, q.is_concept_relation " +
224
			" FROM PTaxon as FromTaxon " +
225
              	" INNER JOIN RelPTaxon ON FromTaxon.PTNameFk = RelPTaxon.PTNameFk1 AND FromTaxon.PTRefFk = RelPTaxon.PTRefFk1 " +
226
              	" INNER JOIN PTaxon AS ToTaxon ON RelPTaxon.PTNameFk2 = ToTaxon.PTNameFk AND RelPTaxon.PTRefFk2 = ToTaxon.PTRefFk " +
229
			" SELECT RelPTaxon.*, fromTaxon.RIdentifier as taxon1Id, toTaxon.RIdentifier as taxon2Id, toTaxon.PTRefFk as treeRefFk, fromTaxon.PTRefFk as fromRefFk, q.is_concept_relation " +
230
			" FROM PTaxon as fromTaxon " +
231
              	" INNER JOIN RelPTaxon ON fromTaxon.PTNameFk = relPTaxon.PTNameFk1 AND fromTaxon.PTRefFk = relPTaxon.PTRefFk1 " +
232
              	" INNER JOIN PTaxon AS toTaxon ON RelPTaxon.PTNameFk2 = ToTaxon.PTNameFk AND RelPTaxon.PTRefFk2 = ToTaxon.PTRefFk " +
227 233
              	" INNER JOIN RelPTQualifier q ON q.RelPTQualifierId = RelPTaxon.RelQualifierFk " +
228
            " WHERE RelPTaxon.RelPTaxonId IN ("+ID_LIST_TOKEN+") ORDER BY RelPTaxon.RelPTaxonId ";
234
            " WHERE RelPTaxon.RelPTaxonId IN ("+ID_LIST_TOKEN+") " +
235
            " ORDER BY RelPTaxon.RelPTaxonId ";
229 236
		return strQuery;
230 237
	}
231 238

  
232 239
	@Override
233 240
	public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState state) {
234 241
		boolean success = true ;
235
		BerlinModelImportConfigurator config = state.getConfig();
236 242
		Set<TaxonBase> taxaToSave = new HashSet<TaxonBase>();
237 243
		Map<String, TaxonBase> taxonMap = partitioner.getObjectMap(BerlinModelTaxonImport.NAMESPACE);
238 244
		Map<Integer, Classification> classificationMap = new HashMap<Integer, Classification>();
......
250 256
				int relPTaxonId = rs.getInt("RelPTaxonId");
251 257
				Integer taxon1Id = nullSafeInt(rs, "taxon1Id");
252 258
				Integer taxon2Id = nullSafeInt(rs, "taxon2Id");
253
				int relQualifierFk = 0;
259
				int relQualifierFk = -1;
254 260
				try {
255 261
					Integer relRefFk = nullSafeInt(rs,"relRefFk");
256 262
					int treeRefFk = rs.getInt("treeRefFk");
......
301 307
							handleAllRelatedTaxa(state, toTaxon, classificationMap, treeRefFk);
302 308
							Synonym synonym = (Synonym)taxon1;
303 309
							if (synonym.getAcceptedTaxon()!= null){
304
							    logger.warn("Synonym already has an accepted taxon. Create clone.");
310
							    logger.warn("RelID: " + relPTaxonId + ". Synonym ("+taxon1Id +") already has an accepted taxon. Create clone.");
305 311
							    synonym = (Synonym)synonym.clone();
306 312
							}
307 313
							makeSynRel(relQualifierFk, toTaxon, synonym, citation, microcitation);
308
							if (isNotBlank(notes)){
309
	                            logger.warn("Notes for synonym relationship or unknown taxon relationship not handled");
310
	                        }
311 314

  
312 315
							if (relQualifierFk == TAX_REL_IS_SYNONYM_OF ||
313 316
									relQualifierFk == TAX_REL_IS_HOMOTYPIC_SYNONYM_OF ||
......
323 326
							        synonym.setPartial(true);
324 327
							}else{
325 328
								success = false;
326
								logger.warn("Proparte/Partial not yet implemented for TaxonRelationShipType " + relQualifierFk);
329
								logger.warn("Synonym relationship type not yet implemented: " + relQualifierFk);
327 330
							}
328 331
						}else if (isConceptRelationship){
329 332
							ResultWrapper<Boolean> isInverse = ResultWrapper.NewInstance(false);
......
360 363
						if (taxonRelationship != null){
361 364
						    doNotes(taxonRelationship, notes);
362 365
						}else if (isNotBlank(notes)){
363
						    logger.warn("Notes for synonym relationship or unknown taxon relationship not handled");
366
						    logger.warn("Notes for synonym relationship or unknown taxon relationship not handled. RelID: " + relPTaxonId + ". Note: " + notes);
364 367
						}
365 368
						taxaToSave.add(taxon2);
366 369

  

Also available in: Unified diff