Project

General

Profile

« Previous | Next » 

Revision 45c2e0b4

Added by Andreas Müller over 3 years ago

ref #1447 latest changes to PesiCommandLineMerge and PesiMergeObject

View differences:

cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/merging/PesiCommandLineMerge.java
111 111
        }
112 112
        if (commit){
113 113
            app.commitTransaction(tx);
114
            if (taxonInformation.taxonToUse == 1 && taxonInformation.nameToUse == 1){
114
            if (isAutomatedAnswer(taxonInformation)){
115 115
                removeTaxon(taxonInformation.taxon2);
116 116
            }else if (booleanAnswer("Information moved. Delete old taxon")){
117 117
                removeTaxon(taxonInformation.taxonToUse == 2 ? taxonInformation.taxon1 : taxonInformation.taxon2);
......
122 122
        return commit;
123 123
    }
124 124

  
125
    private boolean isAutomatedAnswer(TaxonInformation taxonInformation) {
126
        return taxonInformation.taxonToUse == 2 && taxonInformation.nameToUse == 2 && false;
127
    }
128

  
125 129
    private class TaxonInformation{
126 130
        TaxonBase<?> taxon1;
127 131
        TaxonBase<?> taxon2;
......
206 210
    private boolean compareTaxa(TaxonInformation taxonInformation) {
207 211
        TaxonBase<?> removeTaxon = taxonInformation.taxon2;
208 212
        TaxonBase<?> stayTaxon = taxonInformation.taxon1;
213
        if(removeTaxon.getId() == stayTaxon.getId()){
214
            logger.warn("Same taxon: "+  removeTaxon.getTitleCache());
215
            return false;
216
        }
209 217
        String nc1 = removeTaxon.getName().getNameCache();
210 218
        String nc2 = stayTaxon.getName().getNameCache();
211 219

  
......
213 221
        String ft2 = stayTaxon.getName().getFullTitleCache();
214 222
        System.out.println("Remove " + getStatusStr(removeTaxon) + ft1);
215 223
        System.out.println("Stay   " + getStatusStr(stayTaxon) + ft2);
216
        boolean isStandard = taxonInformation.taxonToUse == 1 && taxonInformation.nameToUse == 1;
224
        boolean isStandard = isAutomatedAnswer(taxonInformation);
217 225
        if (!nc1.equals(nc2)){
218 226
            return booleanAnswer("Name Cache differs!!! Do you really want to merge???");
219 227
        }else if (!ft1.equals(ft2)){
......
307 315
            mergeHybridRelationships(removeName, stayName);
308 316
            mergeNameDescriptions(removeName, stayName);
309 317

  
310
            if(taxonInformation.taxonToUse == 1 && taxonInformation.nameToUse == 1){
318
            if(isAutomatedAnswer(taxonInformation)){
311 319
                return true;
312 320
            }else{
313 321
                return booleanAnswer("Commit moved information");
......
393 401
            }
394 402
        }
395 403
        TaxonNode removeNode = removeTaxon.getTaxonNodes().iterator().next();
404
        if(removeNode.getChildNodes().isEmpty()){
405
            return true;
406
        }
407

  
408
        stayTaxon = reallyAccTaxon(stayTaxon);
396 409
        TaxonNode stayNode = stayTaxon.getTaxonNodes().iterator().next();
397 410
        Set<UUID> removeNodeChildrenUuids = removeNode.getChildNodes()
398 411
                .stream().map(tn->tn.getUuid()).collect(Collectors.toSet());
......
405 418
        return true;
406 419
    }
407 420

  
421
    private Taxon reallyAccTaxon(Taxon stayTaxon) {
422
        if (isTaxonSynonym(stayTaxon)){
423
            for (TaxonRelationship rel: stayTaxon.getRelationsFromThisTaxon()){
424
                boolean isPseudo = TaxonRelationshipType.pseudoTaxonUuids().contains(rel.getType().getUuid());
425
                if (isPseudo){
426
                    return rel.getToTaxon();
427
                }
428
            }
429
        }
430
        return stayTaxon;
431
    }
408 432
    private boolean mergeSynonyms(Taxon removeTaxon, Taxon stayTaxon, boolean isTaxonSynonym) {
409 433
        if (isTaxonSynonym){
410 434
            if (!removeTaxon.getSynonyms().isEmpty()){
......
467 491
        }
468 492
    }
469 493

  
470
    private IdentifiableEntity<?> selectStay(IdentifiableEntity<?> removeEntity, IdentifiableEntity<?> stayEntity, String type) {
494
    private <T extends IdentifiableEntity<?>> T selectStay(T removeEntity, T stayEntity, String type) {
471 495
        if(removeEntity.isInstanceOf(Taxon.class) && stayEntity.isInstanceOf(Synonym.class)){
472 496
            String answer = "";
473 497
            while(!(answer.matches("[sSaAcC]"))){
......
476 500
            if (answer.equalsIgnoreCase("c")){
477 501
                return null;
478 502
            }else if (answer.equalsIgnoreCase("a")){
479
               return accTaxon(CdmBase.deproxy(stayEntity, Synonym.class));
503
               return (T)accTaxon(CdmBase.deproxy(stayEntity, Synonym.class));
480 504
            }else{
481 505
                return stayEntity;
482 506
            }
......
525 549
            IdentifiableEntity<?> stayEntity) throws CloneNotSupportedException {
526 550
        String className = removeEntity.getClass().getSimpleName();
527 551
        for (IdentifiableSource source: removeEntity.getSources()){
528
            System.out.println("Move "+className+" source: " + source.getType().getMessage() + ": " + source.getCitation().getTitleCache() + "; " + source.getIdInSource() + "/" + source.getIdNamespace());
552
            System.out.println("Move "+className+" source: " + source.getType().getLabel() + ": " + source.getCitation().getTitleCache() + "; " + source.getIdInSource() + "/" + source.getIdNamespace());
529 553
            stayEntity.addSource((IdentifiableSource)source.clone());
530 554
        }
531 555
    }
cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/merging/PesiMergeObject.java
1 1
package eu.etaxonomy.cdm.app.pesi.merging;
2 2

  
3
import java.util.List;
4

  
5
import eu.etaxonomy.cdm.common.CdmUtils;
3 6
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
4 7

  
5 8
public class PesiMergeObject {
......
12 15

  
13 16
	private String idTaxon;
14 17

  
15
	private String uuidTaxonNode;
16

  
17 18
	private String idInSource;
18 19

  
19 20
	private String nameCache;
......
30 31

  
31 32
	private TaxonNodeDto kingdom;
32 33

  
33
	private TaxonNodeDto family;
34
	private TaxonNodeDto tclass;
35

  
36
	private TaxonNodeDto order;
37

  
38
    private TaxonNodeDto family;
39

  
40
	private List<TaxonNodeDto> higherClassification;
34 41

  
35 42
	private String parentString;
36 43

  
......
127 134
        this.phylum = phylum;
128 135
    }
129 136

  
137
    //class and getClass are part of java core therefore use other name
138
    public TaxonNodeDto getTClass() {
139
        return tclass;
140
    }
141
    public String getClassCache() {
142
        return tclass == null? null : tclass.getNameCache();
143
    }
144
    public void setTClass(TaxonNodeDto tclass) {
145
        this.tclass = tclass;
146
    }
147

  
148
    //order
149
    public TaxonNodeDto getOrder() {
150
        return order;
151
    }
152
    public String getOrderCache() {
153
        return order == null? null : order.getNameCache();
154
    }
155
    public void setOrder(TaxonNodeDto order) {
156
        this.order = order;
157
    }
158

  
159
    //family
130 160
    public TaxonNodeDto getFamily() {
131 161
        return family;
132 162
    }
......
137 167
        this.family = family;
138 168
    }
139 169

  
170
    //classification
171
    public List<TaxonNodeDto> getHigherClassification() {
172
        return higherClassification;
173
    }
174
    public String getClassificationCache() {
175
        return higherClassification == null? null : classificationCache();
176
    }
177
    public void setHigherClassification(List<TaxonNodeDto> higherClassification) {
178
        this.higherClassification = higherClassification;
179
    }
180

  
181
    private String classificationCache() {
182
        String result = "";
183
        for (TaxonNodeDto dto : this.higherClassification){
184
            result = CdmUtils.concat("-", result, dto.getNameCache());
185
        }
186
        return result;
187
    }
188

  
189
    //taxon uuid
140 190
    public String getUuidTaxon() {
141 191
        return uuidTaxon;
142 192
    }
143

  
144 193
    public void setUuidTaxon(String uuidTaxon) {
145 194
        this.uuidTaxon = uuidTaxon;
146 195
    }
147 196

  
197
    //taxon id
148 198
    public String getIdTaxon() {
149 199
        return idTaxon;
150 200
    }
151

  
152 201
    public void setIdTaxon(String idTaxon) {
153 202
        this.idTaxon = idTaxon;
154 203
    }
155 204

  
205
    //source uuid
156 206
    public String getUuidSource() {
157 207
        return uuidSource;
158 208
    }
159

  
160 209
    public void setUuidSource(String uuidSource) {
161 210
        this.uuidSource = uuidSource;
162 211
    }
163 212

  
213
    //nom.ref.
164 214
    public String getNomenclaturalReference() {
165 215
        return nomenclaturalReference;
166 216
    }

Also available in: Unified diff