Project

General

Profile

« Previous | Next » 

Revision 8b256be0

Added by Andreas Müller over 3 years ago

ref #6591 adapt PESI import to new original spellings handling

View differences:

cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiExportBase.java
37 37
import eu.etaxonomy.cdm.model.name.INonViralName;
38 38
import eu.etaxonomy.cdm.model.name.NameRelationship;
39 39
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
40
import eu.etaxonomy.cdm.model.name.NomenclaturalSource;
40 41
import eu.etaxonomy.cdm.model.name.TaxonName;
41 42
import eu.etaxonomy.cdm.model.reference.Reference;
42 43
import eu.etaxonomy.cdm.model.taxon.Synonym;
......
150 151
		return list;
151 152
	}
152 153

  
154
	protected List<NomenclaturalSource> getNextOriginalSpellingPartition(
155
	        int pageSize, int partitionCount, List<String> propertyPaths) {
156

  
157
       List<NomenclaturalSource> result = new ArrayList<>();
158
       List<OrderHint> orderHints = null;
159
       List<NomenclaturalSource> list;
160
       list = getNameService().listOriginalSpellings(pageSize, partitionCount, orderHints, propertyPaths);
161

  
162
       if (list.isEmpty()){
163
           return null;
164
       }
165
       for (NomenclaturalSource rel : list){
166
           if (isPesiOriginalSpelling(rel)){
167
               result.add(rel);
168
           }
169
       }
170
       return result;
171
    }
172

  
153 173
	protected <CLASS extends RelationshipBase> List<CLASS> getNextNameRelationshipPartition(
154 174
	                Class<CLASS> clazz, int pageSize, int partitionCount, List<String> propertyPaths) {
155 175

  
......
243 263
		return (isPesiName(name1) && isPesiName(name2));
244 264
	}
245 265

  
266
	protected boolean isPesiOriginalSpelling(NomenclaturalSource nomSource){
267
        TaxonName name1 = nomSource.getNameUsedInSource();
268
        TaxonName name2 = nomSource.getSourcedName();
269
        return (isPesiName(name1) && isPesiName(name2));
270
    }
271

  
246 272
	private boolean isPesiName(TaxonName name) {
247 273
		return hasPesiTaxon(name) || isPurePesiName(name);
248 274
	}
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiRelTaxonExport.java
29 29
import eu.etaxonomy.cdm.model.name.HybridRelationship;
30 30
import eu.etaxonomy.cdm.model.name.NameRelationship;
31 31
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
32
import eu.etaxonomy.cdm.model.name.NomenclaturalSource;
32 33
import eu.etaxonomy.cdm.model.name.TaxonName;
33 34
import eu.etaxonomy.cdm.model.taxon.Synonym;
34 35
import eu.etaxonomy.cdm.model.taxon.Taxon;
......
58 59
	private PesiExportMapping mapping;
59 60
	private PesiExportMapping synonymMapping;
60 61
	private PesiExportMapping taxonNodeMapping;
62
	private PesiExportMapping originalSpellingMapping;
61 63

  
62 64
	public PesiRelTaxonExport() {
63 65
		super();
......
97 99
            taxonNodeMapping = getTaxonNodeMapping();
98 100
            taxonNodeMapping.initialize(state);
99 101

  
100

  
101 102
			//Export taxon relations
102 103
			success &= doPhase01(state, mapping);
103 104

  
......
247 248
        while ((hybridList = getNextNameRelationshipPartition(HybridRelationship.class, limit, partitionCount++, null)) != null   ) {
248 249
            txStatus = handleNameRelationList(state, txStatus, hybridList);
249 250
        }
251
        //original spellings
252
        List<NomenclaturalSource> originalSpellingList;
253
        partitionCount = 0;
254
        while ((originalSpellingList = getNextOriginalSpellingPartition(limit, partitionCount++, null)) != null   ) {
255
            txStatus = handleOriginalSpellingList(state, txStatus, originalSpellingList);
256
        }
257

  
250 258
        commitTransaction(txStatus);
251 259
		logger.info("End PHASE 2: Name Relationships ...");
252 260
		state.setCurrentFromObject(null);
......
285 293
        				mapping.invoke(rel);
286 294
        			}
287 295
        		}
288
        		fromList = null;
289
        		toList = null;
290

  
291 296
        	} catch (Exception e) {
292 297
        		logger.error(e.getMessage() + ". Relationship: " +  rel.getUuid());
293 298
        		e.printStackTrace();
......
298 303
        return txStatus;
299 304
    }
300 305

  
306
    private TransactionStatus handleOriginalSpellingList(PesiExportState state, TransactionStatus txStatus,
307
            List<NomenclaturalSource> list) {
308
        for (NomenclaturalSource nomSource : list){
309
            try {
310
                TaxonName name1 = nomSource.getNameUsedInSource();
311
                TaxonName name2 = nomSource.getSourcedName();
312
                List<IdentifiableEntity> fromList = new ArrayList<>();
313
                List<IdentifiableEntity> toList = new ArrayList<>();
314
                makeList(name1, fromList);
315
                makeList(name2, toList);
316

  
317
                for (IdentifiableEntity<?> fromEntity : fromList){
318
                    for (IdentifiableEntity<?> toEntity : toList){
319
                        //TODO set entities to state
320
                        state.setCurrentFromObject(fromEntity);
321
                        state.setCurrentToObject(toEntity);
322
                        originalSpellingMapping.invoke(nomSource);
323
                    }
324
                }
325
            } catch (Exception e) {
326
                logger.error(e.getMessage() + ". NomenclaturalSource: " +  nomSource.getUuid());
327
                e.printStackTrace();
328
            }
329
        }
330
        commitTransaction(txStatus);
331
        txStatus = startTransaction();
332
        return txStatus;
333
    }
334

  
335

  
301 336
	private void makeList(TaxonName name, List<IdentifiableEntity> list) {
302 337
		if (! hasPesiTaxon(name)){
303 338
			list.add(name);
304 339
		}else{
305
			for (TaxonBase<?> taxon:  getPesiTaxa(name)){
340
			for (TaxonBase<?> taxon: getPesiTaxa(name)){
306 341
				list.add(taxon);
307 342
			}
308 343
		}
......
373 408
        return state.getDbId(parentTaxon);
374 409
    }
375 410

  
411
    /**
412
     * Returns the id of the previously defined fromObject.
413
     * @see MethodMapper
414
     */
415
    @SuppressWarnings("unused")
416
    private static Integer getFromObject(PesiExportState state) {
417
        return state.getDbId(state.getCurrentFromObject());
418
    }
419
    /**
420
     * Returns the id of the previously defined fromObject.
421
     * @see MethodMapper
422
     */
423
    @SuppressWarnings("unused")
424
    private static Integer getToObject(PesiExportState state) {
425
        return state.getDbId(state.getCurrentToObject());
426
    }
427

  
376 428
	/**
377 429
	 * Returns the <code>TaxonFk2</code> attribute. It corresponds to a CDM <code>SynonymRelationship</code>.
378 430
	 * @param relationship The {@link RelationshipBase Relationship}.
......
448 500
		if (relationship.isInstanceOf(TaxonRelationship.class)) {
449 501
			TaxonRelationship tr = (TaxonRelationship)relationship;
450 502
			taxonBase = (isFrom) ? tr.getFromTaxon():  tr.getToTaxon();
451
		} else if (relationship.isInstanceOf(NameRelationship.class) ||  relationship.isInstanceOf(HybridRelationship.class)) {
503
		} else if (relationship.isInstanceOf(NameRelationship.class)
504
		        || relationship.isInstanceOf(HybridRelationship.class)) {
452 505
			if (isFrom){
453 506
				return state.getDbId(state.getCurrentFromObject());
454 507
			}else{
......
468 521
		return null;
469 522
	}
470 523

  
524
   private static Integer getObjectFk(NomenclaturalSource nomSource, PesiExportState state, boolean isFrom) {
525
        if (isFrom){
526
            return state.getDbId(state.getCurrentFromObject());
527
        }else{
528
            return state.getDbId(state.getCurrentToObject());
529
        }
530
    }
531

  
471 532
    @SuppressWarnings("unused")  //for synonym mapping
472 533
    private static String getSynonymTypeCache(Synonym synonym, PesiExportState state) {
473 534
        String result = null;
......
498 559
		return mapping;
499 560
	}
500 561

  
501
	   /**
562
	/**
502 563
     * Returns the CDM to PESI specific export mappings.
503 564
     * @return The {@link PesiExportMapping PesiExportMapping}.
504 565
     */
......
519 580

  
520 581
        mapping.addMapper(MethodMapper.NewInstance("TaxonFk2", this.getClass(), "getParent", TaxonNode.class, PesiExportState.class));
521 582
        mapping.addMapper(DbObjectMapper.NewInstance("taxon", "TaxonFk1"));
522
        mapping.addMapper(DbFixedIntegerMapper.NewInstance(101, "RelTaxonQualifierFk"));
583
        mapping.addMapper(DbFixedIntegerMapper.NewInstance(PesiTransformer.IS_TAXONOMICALLY_INCLUDED_IN, "RelTaxonQualifierFk"));
523 584
        mapping.addMapper(DbFixedStringMapper.NewInstance("is taxonomically included in", "RelQualifierCache"));
524 585
//        mapping.addMapper(DbAnnotationMapper.NewExludedInstance(getLastActionAnnotationTypes(), "Notes"));
525 586

  
526 587
        return mapping;
527 588
    }
528 589

  
590
    PesiExportMapping getOriginalSpellingMapping() {
591
        PesiExportMapping mapping = new PesiExportMapping(dbTableName);
592

  
593
        mapping.addMapper(MethodMapper.NewInstance("TaxonFk1", this.getClass(), "getFromObject", PesiExportState.class));
594
        mapping.addMapper(MethodMapper.NewInstance("TaxonFk2", this.getClass(), "getToObject", PesiExportState.class));
595
        mapping.addMapper(DbFixedIntegerMapper.NewInstance(PesiTransformer.IS_ORIGINAL_SPELLING_FOR, "RelTaxonQualifierFk"));
596
        mapping.addMapper(DbFixedStringMapper.NewInstance("is original spelling for", "RelQualifierCache"));
597
//        mapping.addMapper(DbAnnotationMapper.NewExludedInstance(getLastActionAnnotationTypes(), "Notes"));
529 598

  
599
        return mapping;
600
    }
530 601

  
531 602
    @Override
532 603
    protected boolean doCheck(PesiExportState state) {
......
537 608
    protected boolean isIgnore(PesiExportState state) {
538 609
        return ! state.getConfig().isDoRelTaxa();
539 610
    }
540
}
611
}
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiTransformer.java
194 194
	private static int IS_ORTHOGRAPHIC_VARIANT_OF = 16;
195 195
	private static int IS_ALTERNATIVE_NAME_FOR = 17;
196 196
	private static int HAS_SAME_TYPE_AS = 18;
197
	private static int IS_ORIGINAL_SPELLING_FOR = 19;
197
	public static int IS_ORIGINAL_SPELLING_FOR = 19;
198 198
	private static int IS_BLOCKING_NAME_FOR = 20;
199 199
	private static int IS_LECTOTYPE_OF = 61;
200 200
	private static int TYPE_NOT_DESIGNATED = 62;
......
2184 2184
			return IS_TREATED_AS_LATER_HOMONYM_OF;
2185 2185
		} else if (type.equals(NameRelationshipType.ORTHOGRAPHIC_VARIANT())) {
2186 2186
			return IS_ORTHOGRAPHIC_VARIANT_OF;
2187
	    } else if (type.equals(NameRelationshipType.ORIGINAL_SPELLING())) {
2188
	        return IS_ORIGINAL_SPELLING_FOR;
2187
//	    } else if (type.equals(NameRelationshipType.ORIGINAL_SPELLING())) {
2188
//	        return IS_ORIGINAL_SPELLING_FOR;
2189 2189
        } else if (type.equals(NameRelationshipType.BLOCKING_NAME_FOR())) {
2190 2190
            return IS_BLOCKING_NAME_FOR;
2191 2191
		} else if (type.equals(NameRelationshipType.ALTERNATIVE_NAME())) {

Also available in: Unified diff