Project

General

Profile

« Previous | Next » 

Revision 9a6fb38b

Added by Andreas Müller almost 9 years ago

Improve E+M-Activator and E+M occurrence import

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/app/berlinModelImport/EuroMedActivator.java
81 81
	private static final Logger logger = Logger.getLogger(EuroMedActivator.class);
82 82

  
83 83
	//database validation status (create, update, validate ...)
84
	static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
84
	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
85 85
	static final Source berlinModelSource = BerlinModelSources.euroMed_BGBM42();
86 86
//	static final Source berlinModelSource = BerlinModelSources.euroMed_PESI3();
87 87

  
88
	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_euroMed();
89

  
88
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_euroMed();
90 89
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_pesi_euromed();
90

  
91 91
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_euromed3();
92
	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
93

  
92 94
//	static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
93 95

  
94 96
	static final boolean includePesiExport = false;
......
168 170

  
169 171
	//taxa
170 172
	static final boolean doTaxa = true;
171
	static final boolean doRelTaxa = true;  //FIXME revert
172 173
	static final boolean doFacts = true;
173
	static final boolean doOccurences = true;
174
	static final boolean doCommonNames = true;
174
	static final boolean doCommonNames = false;
175
	static final boolean doOccurences = false;
176
	static final boolean doRelTaxa = false;
177
	static final boolean doRunTransmissionEngine = (hbm2dll == DbSchemaValidation.VALIDATE);
175 178

  
176 179
	//etc.
177 180
	static final boolean doMarker = true;
......
254 257

  
255 258
		changeCommonNameLabel(config, bmImport);
256 259

  
260
		createUsersAndRoles(config, bmImport);
261

  
257 262
        runTransmissionEngine(config, bmImport);
258 263

  
259 264
        importShapefile(config, bmImport);
260 265

  
261
        createUsersAndRoles(config, bmImport);
262

  
263
	    markAreasAsHidden(config, bmImport);
266
        markAreasAsHidden(config, bmImport);
264 267

  
265 268
		System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")...");
266 269
	}
267 270

  
271
	//Rename Ranks (still needed?)
268 272
    private void renameRanks(BerlinModelImportConfigurator config,
269 273
            CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
270
        //Rename Ranks (still needed?)
271
		if (config.isDoTaxonNames() && (config.getCheck().isImport() )  ){
274

  
275
        if (true || config.isDoTaxonNames() && (config.getCheck().isImport() )  ){
272 276
			ICdmApplicationConfiguration app = bmImport.getCdmAppController();
273 277
			TransactionStatus tx = app.startTransaction();
274 278
			try {
......
292 296
		}
293 297
    }
294 298

  
299
    //create feature tree
295 300
    private void createFeatureTree(BerlinModelImportConfigurator config,
296
            CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
297
        //create feature tree
298
		if (config.isDoFacts() && (config.getCheck().isImport()  )  ){
301
            CdmDefaultImport<BerlinModelImportConfigurator> bmImport)
302
    {
303
	    if (true || config.isDoFacts() && (config.getCheck().isImport()  )  ){
299 304
			ICdmApplicationConfiguration app = bmImport.getCdmAppController();
300 305
			TransactionStatus tx = app.startTransaction();
301 306

  
......
313 318
		}
314 319
    }
315 320

  
321
    //Change common name label
316 322
    private void changeCommonNameLabel(BerlinModelImportConfigurator config,
317 323
            CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
318
        //Change common name label
319
	    if (config.isDoFacts() && (config.getCheck().isImport()  )  ){
324
	    if (true || config.isDoFacts() && (config.getCheck().isImport()  )  ){
320 325
	        ICdmApplicationConfiguration app = bmImport.getCdmAppController();
321 326
	        TransactionStatus tx = app.startTransaction();
322 327

  
......
332 337
    //1. run transmission engine #3979
333 338
    private void runTransmissionEngine(BerlinModelImportConfigurator config,
334 339
            CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
335
        //Transmission engine #3979 .1
336
        if (true || config.isDoOccurrence() && (config.getCheck().isImport()  )  ){
340

  
341
        if (doRunTransmissionEngine && (config.getCheck().isImport()  )  ){
337 342
            ICdmApplicationConfiguration app = bmImport.getCdmAppController();
338 343

  
339 344
            final List<String> term_init_strategy = Arrays.asList(new String []{
......
365 370
    private void markAreasAsHidden(BerlinModelImportConfigurator config,
366 371
            CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
367 372

  
368
        if (config.isDoOccurrence() && (config.getCheck().isImport())){
373
        if (true || config.isDoOccurrence() && (config.getCheck().isImport())){
369 374
	        ICdmApplicationConfiguration app = bmImport.getCdmAppController();
370 375
	        TransactionStatus tx = app.startTransaction();
371 376

  
......
397 402
    private void importShapefile(BerlinModelImportConfigurator config,
398 403
            CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
399 404

  
400
        if (config.isDoOccurrence() && (config.getCheck().isImport())){
405
        if (true || config.isDoOccurrence() && (config.getCheck().isImport())){
401 406

  
402 407
	       UUID areaVocabularyUuid = BerlinModelTransformer.uuidVocEuroMedAreas;
403 408
           List<String> idSearchFields = Arrays.asList(new String[]{"EMAREA","PARENT"});
......
429 434
    }
430 435

  
431 436
    //4. Create users and assign roles  #3979
432
    private void createUsersAndRoles(
433
            BerlinModelImportConfigurator config,
437
    private void createUsersAndRoles(BerlinModelImportConfigurator config,
434 438
            CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
435 439

  
436
        if (config.isDoRelTaxa() && (config.getCheck().isImport())){
440
        if (true || config.isDoRelTaxa() && (config.getCheck().isImport())){
437 441
	        ICdmApplicationConfiguration app = bmImport.getCdmAppController();
438 442
	        TransactionStatus tx = app.startTransaction();
439 443

  
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelOccurrenceImport.java
164 164
			NamedArea newArea = makeSingleEuroMedArea(rs, eurMarkerType, euroMedAreaMarkerType,
165 165
					isoCodeExtType, tdwgCodeExtType, mclCodeExtType,
166 166
					areaLevelTop, areaLevelEm1 , areaLevelEm2, sourceReference, euroMedArea, lastLevel2Area);
167
			euroMedAreas.addTerm(newArea);
168
			if (newArea.getPartOf().equals(euroMedArea)){
169
				lastLevel2Area = newArea;
167
			if (newArea != null){
168
    			euroMedAreas.addTerm(newArea);
169
    			if (newArea.getPartOf().equals(euroMedArea)){
170
    				lastLevel2Area = newArea;
171
    			}
170 172
			}
171
			getVocabularyService().saveOrUpdate(euroMedAreas);
172 173
		}
174
		getVocabularyService().saveOrUpdate(euroMedAreas);
173 175

  
174 176
		commitTransaction(txStatus);
175 177
		logger.warn("Created E+M areas");
......
219 221
		String mclCode = nullSafeTrim(rs.getString("MCLCode"));
220 222
		String geoSearch = nullSafeTrim(rs.getString("NameForGeoSearch"));
221 223

  
224

  
225

  
222 226
		if (isBlank(emCode)){
223 227
			emCode = unit;
224 228
		}
......
232 236
			if (uuid != null){
233 237
				area.setUuid(uuid);
234 238
			}else{
235
				logger.warn("Uuuid for emCode could not be defined: " + emCode);
239
			    if (areaId == 211 || areaId == 213){  //Additional Azores and Canary Is. area are merged into primary area, see also area.addSource part below
240
			        return null;
241
			    }
242
				logger.warn("Uuid for emCode could not be defined: " + emCode);
236 243
			}
237 244
		}
238 245

  
......
263 270

  
264 271
		//source
265 272
		area.addSource(OriginalSourceType.Import, String.valueOf(areaId), EM_AREA_NAMESPACE, sourceReference, null);
273
		//add duplicate area ids for canary
274
		if (areaId == 624){ //Canary Is.
275
		    area.addSource(OriginalSourceType.Import, String.valueOf(213), EM_AREA_NAMESPACE, sourceReference, null);
276
		}
277
		if (areaId == 210){//Azores
278
            area.addSource(OriginalSourceType.Import, String.valueOf(211), EM_AREA_NAMESPACE, sourceReference, null);
279
        }
266 280

  
267 281
		//parent
268 282
		if (euroMedArea != null){
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelTaxonRelationImport.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
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
*/
......
64 64
	private static final Logger logger = Logger.getLogger(BerlinModelTaxonRelationImport.class);
65 65

  
66 66
	public static final String TREE_NAMESPACE = "PTRefFk";
67
	
67

  
68 68
	private static int modCount = 30000;
69 69
	private static final String pluralString = "taxon relations";
70 70
	private static final String dbTableName = "RelPTaxon";
71 71

  
72
	
72

  
73 73
	public BerlinModelTaxonRelationImport(){
74 74
		super(dbTableName, pluralString);
75 75
	}
......
83 83
	 */
84 84
	private void makeClassifications(BerlinModelImportState state) throws SQLException{
85 85
		logger.info("start make classification ...");
86
		
86

  
87 87
		Set<String> idSet = getTreeReferenceIdSet(state);
88 88

  
89 89
		//reference map
90 90
		String nameSpace = BerlinModelReferenceImport.REFERENCE_NAMESPACE;
91 91
		Class<?> cdmClass = Reference.class;
92 92
		Map<String, Reference> refMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
93
		
93

  
94 94
		String treeName = "Classification - No Name";
95
		
95

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

  
103 103
				try {
104 104
					if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("RelPTaxa handled: " + (i-1));}
105
					
105

  
106 106
					Integer ptRefFkInt = nullSafeInt(rs,"PTRefFk");
107 107
					String ptRefFk= String.valueOf(ptRefFkInt);
108 108
					Reference<?> ref = refMap.get(ptRefFk);
109
					
109

  
110 110
					String refCache = rs.getString("RefCache");
111 111
					if (StringUtils.isNotBlank(refCache)){
112 112
						treeName = refCache;
......
121 121
					}
122 122
					IdentifiableSource identifiableSource = IdentifiableSource.NewDataImportInstance(ptRefFk, TREE_NAMESPACE);
123 123
					tree.addSource(identifiableSource);
124
					
124

  
125 125
					getClassificationService().save(tree);
126 126
					state.putClassificationUuidInt(ptRefFkInt, tree);
127 127
				} catch (Exception e) {
......
140 140

  
141 141
	/**
142 142
	 * @return
143
	 * @throws SQLException 
143
	 * @throws SQLException
144 144
	 */
145 145
	private Set<String> getTreeReferenceIdSet(BerlinModelImportState state) throws SQLException {
146 146
		Source source = state.getConfig().getSource();
......
158 158
	 */
159 159
	private String getClassificationQuery(BerlinModelImportState state) {
160 160
		boolean includeAllClassifications = state.getConfig().isIncludeAllNonMisappliedRelatedClassifications();
161
		String strQuerySelect = "SELECT PTaxon.PTRefFk, r.RefCache ";  
162
		String strQueryFrom = " FROM RelPTaxon " + 
161
		String strQuerySelect = "SELECT PTaxon.PTRefFk, r.RefCache ";
162
		String strQueryFrom = " FROM RelPTaxon " +
163 163
							" INNER JOIN PTaxon AS PTaxon ON RelPTaxon.PTNameFk2 = PTaxon.PTNameFk AND RelPTaxon.PTRefFk2 = PTaxon.PTRefFk " +
164
							" INNER JOIN Reference r ON PTaxon.PTRefFk = r.RefId "; 
165
		String strQueryWhere = " WHERE (RelPTaxon.RelQualifierFk = 1) "; 
164
							" INNER JOIN Reference r ON PTaxon.PTRefFk = r.RefId ";
165
		String strQueryWhere = " WHERE (RelPTaxon.RelQualifierFk = 1) ";
166 166
		if (includeAllClassifications){
167 167
			strQueryWhere = " WHERE (RelPTaxon.RelQualifierFk <> 3) ";
168 168
		}else{
......
174 174
				}
175 175
			}
176 176
		}
177
		
177

  
178 178
		String strQueryGroupBy = " GROUP BY PTaxon.PTRefFk, r.RefCache ";
179 179
		String strQuery = strQuerySelect + " " + strQueryFrom + " " + strQueryWhere + " " + strQueryGroupBy;
180
		
181
		
180

  
181

  
182 182
		if (includeAllClassifications){
183 183
			//add otherdirection
184
			strQuerySelect = "SELECT PTaxon.PTRefFk, r.RefCache ";  
185
			strQueryFrom = " FROM RelPTaxon rel " + 
184
			strQuerySelect = "SELECT PTaxon.PTRefFk, r.RefCache ";
185
			strQueryFrom = " FROM RelPTaxon rel " +
186 186
								" INNER JOIN PTaxon AS PTaxon ON rel.PTNameFk1 = PTaxon.PTNameFk AND rel.PTRefFk1 = PTaxon.PTRefFk " +
187
								" INNER JOIN Reference r ON PTaxon.PTRefFk = r.RefId "; 
187
								" INNER JOIN Reference r ON PTaxon.PTRefFk = r.RefId ";
188 188
			strQueryWhere =" WHERE (rel.RelQualifierFk <> 3) ";
189 189
			String strAllQuery =  strQuerySelect + " " + strQueryFrom + " " + strQueryWhere + " " + strQueryGroupBy;
190 190
			strQuery = strQuery + " UNION " + strAllQuery;
191 191
		}
192
		
193
		
194
		
192

  
193

  
194

  
195 195
		boolean includeFlatClassifications = state.getConfig().isIncludeFlatClassifications();
196
		//concepts with 
196
		//concepts with
197 197
		if (includeFlatClassifications){
198
			String strFlatQuery = 
198
			String strFlatQuery =
199 199
					" SELECT pt.PTRefFk AS secRefFk, r.RefCache AS secRef " +
200
					" FROM PTaxon AS pt LEFT OUTER JOIN " + 
200
					" FROM PTaxon AS pt LEFT OUTER JOIN " +
201 201
					          " Reference r ON pt.PTRefFk = r.RefId LEFT OUTER JOIN " +
202 202
					          " RelPTaxon rel1 ON pt.PTNameFk = rel1.PTNameFk2 AND pt.PTRefFk = rel1.PTRefFk2 LEFT OUTER JOIN " +
203
					          " RelPTaxon AS rel2 ON pt.PTNameFk = rel2.PTNameFk1 AND pt.PTRefFk = rel2.PTRefFk1 " + 
204
					" WHERE (rel2.RelQualifierFk IS NULL) AND (rel1.RelQualifierFk IS NULL) " + 
203
					          " RelPTaxon AS rel2 ON pt.PTNameFk = rel2.PTNameFk1 AND pt.PTRefFk = rel2.PTRefFk1 " +
204
					" WHERE (rel2.RelQualifierFk IS NULL) AND (rel1.RelQualifierFk IS NULL) " +
205 205
					" GROUP BY pt.PTRefFk, r.RefCache "
206 206
					;
207
			
207

  
208 208
			strQuery = strQuery + " UNION " + strFlatQuery;
209 209
		}
210 210

  
211
		
212
		
211

  
212

  
213 213
		if (state.getConfig().getClassificationQuery() != null){
214 214
			strQuery = state.getConfig().getClassificationQuery();
215 215
		}
216 216
		return strQuery;
217 217
	}
218
	
218

  
219 219
	@Override
220 220
	protected String getRecordQuery(BerlinModelImportConfigurator config) {
221
		String strQuery = 
222
			" SELECT RelPTaxon.*, FromTaxon.RIdentifier as taxon1Id, ToTaxon.RIdentifier as taxon2Id, ToTaxon.PTRefFk as treeRefFk, FromTaxon.PTRefFk as fromRefFk, q.is_concept_relation " + 
221
		String strQuery =
222
			" SELECT RelPTaxon.*, FromTaxon.RIdentifier as taxon1Id, ToTaxon.RIdentifier as taxon2Id, ToTaxon.PTRefFk as treeRefFk, FromTaxon.PTRefFk as fromRefFk, q.is_concept_relation " +
223 223
			" FROM PTaxon as FromTaxon " +
224 224
              	" INNER JOIN RelPTaxon ON FromTaxon.PTNameFk = RelPTaxon.PTNameFk1 AND FromTaxon.PTRefFk = RelPTaxon.PTRefFk1 " +
225 225
              	" INNER JOIN PTaxon AS ToTaxon ON RelPTaxon.PTNameFk2 = ToTaxon.PTNameFk AND RelPTaxon.PTRefFk2 = ToTaxon.PTRefFk " +
226
              	" INNER JOIN RelPTQualifier q ON q.RelPTQualifierId = RelPTaxon.RelQualifierFk " + 
226
              	" INNER JOIN RelPTQualifier q ON q.RelPTQualifierId = RelPTaxon.RelQualifierFk " +
227 227
            " WHERE RelPTaxon.RelPTaxonId IN ("+ID_LIST_TOKEN+") ORDER BY RelPTaxon.RelPTaxonId ";
228 228
		return strQuery;
229 229
	}
......
233 233
		boolean success = true ;
234 234
		BerlinModelImportConfigurator config = state.getConfig();
235 235
		Set<TaxonBase> taxaToSave = new HashSet<TaxonBase>();
236
		Map<String, TaxonBase> taxonMap = (Map<String, TaxonBase>) partitioner.getObjectMap(BerlinModelTaxonImport.NAMESPACE);
236
		Map<String, TaxonBase> taxonMap = partitioner.getObjectMap(BerlinModelTaxonImport.NAMESPACE);
237 237
		Map<Integer, Classification> classificationMap = new HashMap<Integer, Classification>();
238
		Map<String, Reference> refMap = (Map<String, Reference>)partitioner.getObjectMap(BerlinModelReferenceImport.REFERENCE_NAMESPACE);
238
		Map<String, Reference> refMap = partitioner.getObjectMap(BerlinModelReferenceImport.REFERENCE_NAMESPACE);
239 239

  
240 240
		ResultSet rs = partitioner.getResultSet();
241
			
241

  
242 242
		try{
243 243
			int i = 0;
244 244
			//for each reference
245 245
			while (rs.next()){
246
				
246

  
247 247
				if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("RelPTaxa handled: " + (i-1));}
248
					
248

  
249 249
				int relPTaxonId = rs.getInt("RelPTaxonId");
250 250
				Integer taxon1Id = nullSafeInt(rs, "taxon1Id");
251 251
				Integer taxon2Id = nullSafeInt(rs, "taxon2Id");
......
253 253
					Integer relRefFk = nullSafeInt(rs,"relRefFk");
254 254
					int treeRefFk = rs.getInt("treeRefFk");
255 255
					int fromRefFk = rs.getInt("fromRefFk");
256
					
256

  
257 257
					int relQualifierFk = rs.getInt("relQualifierFk");
258 258
					String notes = rs.getString("notes");
259 259
					boolean isConceptRelationship = rs.getBoolean("is_concept_relation");
260
					
260

  
261 261
					TaxonBase<?> taxon1 = taxonMap.get(String.valueOf(taxon1Id));
262 262
					TaxonBase<?> taxon2 = taxonMap.get(String.valueOf(taxon2Id));
263
					
263

  
264 264
					String refFk = String.valueOf(relRefFk);
265 265
					Reference<?> citation = refMap.get(refFk);
266
					
266

  
267 267
					String microcitation = null; //does not exist in RelPTaxon
268 268

  
269 269
					if (taxon2 != null && taxon1 != null){
......
300 300
							Synonym synonym = (Synonym)taxon1;
301 301
							SynonymRelationship synRel = getSynRel(relQualifierFk, toTaxon, synonym, citation, microcitation);
302 302
							taxonRelationship = synRel;
303
							
304
							if (relQualifierFk == TAX_REL_IS_SYNONYM_OF || 
303

  
304
							if (relQualifierFk == TAX_REL_IS_SYNONYM_OF ||
305 305
									relQualifierFk == TAX_REL_IS_HOMOTYPIC_SYNONYM_OF ||
306 306
									relQualifierFk == TAX_REL_IS_HETEROTYPIC_SYNONYM_OF){
307 307
								addProParteAndPartial(synRel, synonym, config);
......
309 309
									relQualifierFk == TAX_REL_IS_PROPARTE_HOMOTYPIC_SYNONYM_OF ||
310 310
									relQualifierFk == TAX_REL_IS_PROPARTE_HETEROTYPIC_SYNONYM_OF ){
311 311
									synRel.setProParte(true);
312
							}else if(relQualifierFk == TAX_REL_IS_PARTIAL_SYN_OF || 
312
							}else if(relQualifierFk == TAX_REL_IS_PARTIAL_SYN_OF ||
313 313
									relQualifierFk == TAX_REL_IS_PARTIAL_HOMOTYPIC_SYNONYM_OF ||
314 314
									relQualifierFk == TAX_REL_IS_PARTIAL_HETEROTYPIC_SYNONYM_OF ){
315 315
									synRel.setPartial(true);
......
321 321
							ResultWrapper<Boolean> isInverse = ResultWrapper.NewInstance(false);
322 322
							ResultWrapper<Boolean> isDoubtful = ResultWrapper.NewInstance(false);
323 323
							try {
324
								TaxonRelationshipType relType = BerlinModelTransformer.taxonRelId2TaxonRelType(relQualifierFk, isInverse, isDoubtful);	
324
								TaxonRelationshipType relType = BerlinModelTransformer.taxonRelId2TaxonRelType(relQualifierFk, isInverse, isDoubtful);
325 325

  
326 326
								if (! (taxon1 instanceof Taxon)){
327 327
									success = false;
......
338 338
									handleAllRelatedTaxa(state, fromTaxon, classificationMap, fromRefFk);
339 339
									if (isDoubtful.getValue() == true){
340 340
										((TaxonRelationship)taxonRelationship).setDoubtful(true);
341
									}	
341
									}
342 342
								}
343 343
							} catch (UnknownCdmTypeException e) {
344 344
								logger.warn("TaxonRelationShipType " + relQualifierFk + " (conceptRelationship) not yet implemented");
......
348 348
							logger.warn("TaxonRelationShipType " + relQualifierFk + " not yet implemented: RelPTaxonId = " + relPTaxonId );
349 349
							success = false;
350 350
						}
351
						
351

  
352 352
						doNotes(taxonRelationship, notes);
353 353
						taxaToSave.add(taxon2);
354
						
354

  
355 355
						//TODO
356 356
						//etc.
357 357
					}else{
......
362 362
						}else{
363 363
							logger.warn("Both taxa ("+taxon1Id+","+taxon2Id +") for RelPTaxon " + relPTaxonId + " do not exist in store. RelType: " + relQualifierFk);
364 364
						}
365
						
365

  
366 366
						success = false;
367 367
					}
368 368
				} catch (Exception e) {
369 369
					logger.error("Exception occurred when trying to handle taxon relationship " + relPTaxonId + " (" + taxon1Id + ","+ taxon2Id + "): " + e.getMessage());
370
//					e.printStackTrace();
370
					e.printStackTrace();
371 371
				}
372 372
			}
373 373
		}catch(SQLException e){
......
378 378
		getTaxonService().saveOrUpdate(taxaToSave);
379 379
		classificationMap = null;
380 380
		taxaToSave = null;
381
			
381

  
382 382
		return success;
383 383
	}
384
	
384

  
385 385

  
386 386
	private void handleAllRelatedTaxa(BerlinModelImportState state, Taxon taxon, Map<Integer, Classification> classificationMap, Integer secRefFk) {
387 387
		if (taxon.getTaxonNodes().size() > 0){
......
393 393
	}
394 394

  
395 395
	@Override
396
	protected void doInvoke(BerlinModelImportState state){				
396
	protected void doInvoke(BerlinModelImportState state){
397 397
		try {
398 398
			makeClassifications(state);
399 399
			super.doInvoke(state);
......
402 402
		} catch (SQLException e) {
403 403
			throw new RuntimeException(e);
404 404
		}
405
		
405

  
406 406
	}
407
	
408
	
407

  
408

  
409 409
	private void makeFlatClassificationTaxa(BerlinModelImportState state) {
410 410
		//Note: this part still does not use partitions
411 411
		logger.info("Flat classifications start");
......
421 421
						" ORDER BY pt.PTRefFk "	;
422 422
		ResultSet rs = state.getConfig().getSource().getResultSet(sql);
423 423
		Map<Object, Map<String, ? extends CdmBase>> maps = getRelatedObjectsForFlatPartition(rs);
424
		
424

  
425 425
		Map<String, TaxonBase> taxonMap = (Map<String, TaxonBase>) maps.get(BerlinModelTaxonImport.NAMESPACE);
426 426
		Map<Integer, Classification> classificationMap = new HashMap<Integer, Classification>();
427
				
427

  
428 428
		rs = state.getConfig().getSource().getResultSet(sql);
429 429
		try {
430 430
			while (rs.next()){
......
448 448
		}
449 449
		commitTransaction(txStatus);
450 450
		logger.info("Flat classifications end");
451
		
451

  
452 452
	}
453 453

  
454 454
	@Override
......
459 459
			return super.getIdQuery(state);
460 460
		}
461 461
	}
462
	
462

  
463 463
	@Override
464 464
	public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition( ResultSet rs, BerlinModelImportState state) {
465 465
		String nameSpace;
466 466
		Class<?> cdmClass;
467 467
		Set<String> idSet;
468 468
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
469
		
469

  
470 470
		try{
471 471
			Set<String> taxonIdSet = new HashSet<String>();
472 472
			Set<String> referenceIdSet = new HashSet<String>();
......
477 477
//				handleForeignKey(rs, classificationIdSet, "treeRefFk");
478 478
				handleForeignKey(rs, referenceIdSet, "RelRefFk");
479 479
	}
480
	
480

  
481 481
			//taxon map
482 482
			nameSpace = BerlinModelTaxonImport.NAMESPACE;
483 483
			cdmClass = TaxonBase.class;
......
493 493
//			result.put(cdmClass, treeMap);
494 494
//			Set<UUID> treeUuidSet = state
495 495
//			getClassificationService().find(uuidSet);
496
//			
496
//
497 497
			//reference map
498 498
			nameSpace = BerlinModelReferenceImport.REFERENCE_NAMESPACE;
499 499
			cdmClass = Reference.class;
......
506 506
		}
507 507
		return result;
508 508
	}
509
	
509

  
510 510

  
511 511
	private Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForFlatPartition( ResultSet rs) {
512 512
		String nameSpace;
513 513
		Class cdmClass;
514 514
		Set<String> idSet;
515 515
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
516
		
516

  
517 517
		try{
518 518
			Set<String> taxonIdSet = new HashSet<String>();
519 519
			Set<String> referenceIdSet = new HashSet<String>();
......
522 522
				handleForeignKey(rs, taxonIdSet, "RIdentifier");
523 523
//				handleForeignKey(rs, classificationIdSet, "treeRefFk");
524 524
	}
525
	
525

  
526 526
			//taxon map
527 527
			nameSpace = BerlinModelTaxonImport.NAMESPACE;
528 528
			cdmClass = TaxonBase.class;
......
538 538
//			result.put(cdmClass, treeMap);
539 539
//			Set<UUID> treeUuidSet = state
540 540
//			getClassificationService().find(uuidSet);
541
//			
541
//
542 542

  
543 543
		} catch (SQLException e) {
544 544
			throw new RuntimeException(e);
......
568 568
		return result;
569 569

  
570 570
	}
571
	
571

  
572 572
	private  boolean isSynonymRelationship(int relQualifierFk){
573
		if (relQualifierFk == TAX_REL_IS_SYNONYM_OF || 
574
			relQualifierFk == TAX_REL_IS_HOMOTYPIC_SYNONYM_OF || 
573
		if (relQualifierFk == TAX_REL_IS_SYNONYM_OF ||
574
			relQualifierFk == TAX_REL_IS_HOMOTYPIC_SYNONYM_OF ||
575 575
			relQualifierFk == TAX_REL_IS_HETEROTYPIC_SYNONYM_OF ||
576
			relQualifierFk == TAX_REL_IS_PROPARTE_SYN_OF || 
576
			relQualifierFk == TAX_REL_IS_PROPARTE_SYN_OF ||
577 577
			relQualifierFk == TAX_REL_IS_PARTIAL_SYN_OF ||
578 578
			relQualifierFk == TAX_REL_IS_PROPARTE_HOMOTYPIC_SYNONYM_OF ||
579 579
			relQualifierFk == TAX_REL_IS_PROPARTE_HETEROTYPIC_SYNONYM_OF ||
......
585 585
			return false;
586 586
		}
587 587
	}
588
	
588

  
589 589
	private  boolean isTaxonRelationship(int relQualifierFk){
590
		if (relQualifierFk == TAX_REL_IS_INCLUDED_IN || 
590
		if (relQualifierFk == TAX_REL_IS_INCLUDED_IN ||
591 591
				relQualifierFk == TAX_REL_IS_MISAPPLIED_NAME_OF){
592 592
			return true;
593 593
		}else{
594 594
			return false;
595 595
		}
596 596
	}
597
	
597

  
598 598
	private void addProParteAndPartial(SynonymRelationship synRel, Synonym synonym, BerlinModelImportConfigurator bmiConfig){
599 599
		if (bmiConfig.isPartialSynonym(synonym)){
600 600
			synRel.setPartial(true);
......
603 603
			synRel.setProParte(true);
604 604
		}
605 605
	}
606
	
606

  
607 607
	private TaxonNode makeTaxonomicallyIncluded(BerlinModelImportState state, Map<Integer, Classification> classificationMap, int treeRefFk, Taxon child, Taxon parent, Reference citation, String microCitation){
608 608
		Classification tree = getClassificationTree(state, classificationMap, treeRefFk);
609 609
		return tree.addParentChild(parent, child, citation, microCitation);
......
612 612
	private Classification getClassificationTree(BerlinModelImportState state, Map<Integer, Classification> classificationMap, int treeRefFk) {
613 613
		if (state.getConfig().isUseSingleClassification()){
614 614
			if (state.getConfig().getSourceSecId() != null){
615
				treeRefFk = (Integer)state.getConfig().getSourceSecId();	
615
				treeRefFk = (Integer)state.getConfig().getSourceSecId();
616 616
			}else{
617 617
				treeRefFk = 1;
618 618
			}
619
			
619

  
620 620
		}
621 621
		Classification tree = classificationMap.get(treeRefFk);
622 622
		if (tree == null){
......
629 629
		}
630 630
		return tree;
631 631
	}
632
	
632

  
633 633
	@Override
634 634
	protected boolean doCheck(BerlinModelImportState state){
635 635
		IOValidator<BerlinModelImportState> validator = new BerlinModelTaxonRelationImportValidator();
636 636
		return validator.validate(state);
637 637
	}
638
	
638

  
639 639
	@Override
640 640
	protected boolean isIgnore(BerlinModelImportState state){
641 641
		return ! state.getConfig().isDoRelTaxa();
642 642
	}
643 643

  
644
	
644

  
645 645
}

Also available in: Unified diff