Project

General

Profile

« Previous | Next » 

Revision 1ffd1c27

Added by Andreas Müller over 3 years ago

ref #9322 remove invalid designation relationship from cdmlib

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/format/taxon/TaxonRelationshipFormatter.java
67 67
        }
68 68

  
69 69
        TaxonRelationshipType type = taxonRelationship.getType();
70
        boolean isMisapplied = type == null ? false : type.isMisappliedNameOrInvalidDesignation() && reverse;
70
        boolean isMisapplied = type == null ? false : type.isMisappliedName() && reverse;
71 71
        boolean isSynonym = type == null? false : type.isAnySynonym();
72 72

  
73 73
        Taxon relatedTaxon = reverse? taxonRelationship.getFromTaxon()
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/Taxon.java
859 859
        return count;
860 860
    }
861 861

  
862
    /**
863
     * Returns the boolean value indicating whether <i>this</i> taxon is a invalid designation
864
     * for at least one other taxon.
865
     */
866
    // TODO cache as for #hasTaxonomicChildren
867
    @Transient
868
    public boolean isInvalidDesignation(){
869
        return computeInvalidDesignationRelations() > 0;
870
    }
871

  
872
    /**
873
     * Counts the number of invalid designation relationships where this taxon represents the
874
     * invalid designation for another taxon.
875
     * @return
876
     */
877
    private int computeInvalidDesignationRelations(){
878
        int count = 0;
879
        for (TaxonRelationship rel: this.getRelationsFromThisTaxon()){
880
            if (rel.getType().isInvalidDesignation()){
881
                count++;
882
            }
883
        }
884
        return count;
885
    }
886

  
887 862
    /**
888 863
     * Returns the boolean value indicating whether <i>this</i> taxon is a related
889 864
     * concept for at least one other taxon.
......
1596 1571
        return result;
1597 1572
    }
1598 1573

  
1599
    /**
1600
     * @see     #getSynonymsGroups()
1601
     */
1602
    @Transient
1603
    public List<Taxon> getInvalidDesignations(){
1604
        List<Taxon> result = new ArrayList<>();
1605
        for (TaxonRelationship rel : this.getRelationsToThisTaxon()){
1606
            if (rel.getType().isInvalidDesignation()){
1607
                result.add(rel.getFromTaxon());
1608
            }
1609
        }
1610
        sortBySimpleTitleCacheComparator(result);
1611
        return result;
1612
    }
1613 1574

  
1614 1575
    /**
1615 1576
     * @see     #getSynonymsGroups()
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonRelationshipType.java
69 69
	public static final UUID uuidPartialMisappliedNameFor = UUID.fromString("859fb615-b0e8-440b-866e-8a19f493cd36");
70 70
	public static final UUID uuidProParteSynonymFor = UUID.fromString("8a896603-0fa3-44c6-9cd7-df2d8792e577");
71 71
	public static final UUID uuidPartialSynonymFor = UUID.fromString("9d7a5e56-973c-474c-b6c3-a1cb00833a3c");
72
	private static final UUID uuidInvalidDesignationFor = UUID.fromString("605b1d01-f2b1-4544-b2e0-6f08def3d6ed");
73 72

  
74 73
	private static final UUID uuidContradiction = UUID.fromString("a8f03491-2ad6-4fae-a04c-2a4c117a2e9b");
75 74
	private static final UUID uuidCongruentTo = UUID.fromString("60974c98-64ab-4574-bb5c-c110f6db634d");
......
171 170
     *
172 171
     * @see #isAnyMisappliedName()()
173 172
     */
174
	public boolean isMisappliedNameOrInvalidDesignation(){
173
	public boolean isMisappliedName(){
175 174
        if (this.isAnyMisappliedName()){
176 175
            return true;
177
        }else if (isInvalidDesignation()){
178
            return true;
179
        }
180
        return false;
181
    }
182

  
183
    /**
184
     * <code>true</code> if this relationship type is an
185
     * {@link #INVALID_DESIGNATION_FOR() invalid designation}
186
     *
187
     * @see #isAnyMisappliedName()()
188
     */
189
    public boolean isInvalidDesignation(){
190
        if (this.equals(INVALID_DESIGNATION_FOR())){
191
            return true;
192 176
        }
193 177
        return false;
194 178
    }
......
281 265
	 * @return
282 266
	 */
283 267
	public boolean isConceptRelationship(){
284
		if (this.isMisappliedNameOrInvalidDesignation()){
268
		if (this.isMisappliedName()){
285 269
			return false;
286 270
        }else if (this.equals(TAXONOMICALLY_INCLUDED_IN())){
287 271
			return false;
......
381 365
        return getTermByUuid(uuidPartialSynonymFor);
382 366
    }
383 367

  
384
	/**
385
	 * Returns the taxon relationship type "is invalid designation for". This
386
	 * indicates that the {@link eu.etaxonomy.cdm.model.name.TaxonName taxon name} of the {@link TaxonRelationship#getFromTaxon() source taxon}
387
	 * in such a {@link TaxonRelationship taxon relationship} has
388
	 * {@link eu.etaxonomy.cdm.model.name.NomenclaturalStatusType#isInvalid() not been validly published} but was intended to denominate
389
	 * a real taxon which is the same as the one meant by the target {@link Taxon taxon}.<BR>
390
	 * According to the nomenclature codes a not validly published taxon name is
391
	 * not a taxon name at all.<BR>
392
	 * This type is neither symmetric nor transitive.
393
	 */
394
	public static final TaxonRelationshipType INVALID_DESIGNATION_FOR(){
395
		return getTermByUuid(uuidInvalidDesignationFor);
396
	}
397 368
	/**
398 369
	 * Returns the (concept) taxon relationship type "is impossible"
399 370
	 * (contradiction). This is a concept relationship type which means that the
cdmlib-model/src/main/resources/terms/TaxonRelationshipType.csv
3 3
"1ed87175-59dd-437e-959e-0d71583d8417",,"is misapplied name for","is misapplied name for","⸺","has misapplied name","has misapplied name","—",FALSE,FALSE
4 4
"b59b4bd2-11ff-45d1-bae2-146efdeee206",,"is pro parte misapplied name for","is pro parte misapplied name for","⸺(p.p.)","has pro parte misapplied name","has pro parte misapplied name","—(p.p.)",FALSE,FALSE
5 5
"859fb615-b0e8-440b-866e-8a19f493cd36",,"is partial misapplied name for","is partial misapplied name for","⸺(part.)","has partial misapplied name","has partial misapplied name","—(part.)",FALSE,FALSE
6
"605b1d01-f2b1-4544-b2e0-6f08def3d6ed",,"is invalid designation for","is invalid designation for","–","has invalid designation","has invalid designation",,FALSE,FALSE
7 6
"8a896603-0fa3-44c6-9cd7-df2d8792e577",,"is pro parte synonym for","is pro parte synonym for","⊃p.p.","has pro parte synonym","has pro parte synonym","p.p.",FALSE,FALSE
8 7
"9d7a5e56-973c-474c-b6c3-a1cb00833a3c",,"is partial synonym for","is partial synonym for","⊃part.","has partial synonym","has partial synonym","part.",FALSE,FALSE
9 8
"a8f03491-2ad6-4fae-a04c-2a4c117a2e9b",,"Contradiction","Contradiction","∅","Contradiction","Contradiction","∅",TRUE,FALSE
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v515_518/SchemaUpdater_5185_5186.java
17 17
import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep;
18 18
import eu.etaxonomy.cdm.database.update.SchemaUpdaterBase;
19 19
import eu.etaxonomy.cdm.database.update.SimpleSchemaUpdaterStep;
20
import eu.etaxonomy.cdm.database.update.SingleTermRemover;
20 21
import eu.etaxonomy.cdm.model.metadata.CdmMetaData.CdmVersion;
21 22

  
22 23
/**
......
49 50

  
50 51
        adaptNomenclaturalStanding(stepList);
51 52

  
53
		//#9322 remove Invalid Designation taxon relationship
54
        String stepName = "remove invalid designation taxon relationship type";
55
        String uuidTerm = "605b1d01-f2b1-4544-b2e0-6f08def3d6ed";
56
        String checkUsedQueries = "SELECT count(*) FROM @@TaxonRelationship@@ tr "
57
                + " INNER JOIN @@DefinedTermBase@@ trType ON trType.id = tr.type_id "
58
                + " WHERE trType.uuid = '605b1d01-f2b1-4544-b2e0-6f08def3d6ed'";
59
        SingleTermRemover.NewInstance(stepList, stepName, uuidTerm, checkUsedQueries, -99);
60

  
52 61
        return stepList;
53 62
    }
54 63

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java
1030 1030
                configRelTaxon.setDeleteConceptRelationships(true);
1031 1031

  
1032 1032
                for (TaxonRelationship taxRel: taxon.getTaxonRelations()){
1033
                    if (config.isDeleteMisappliedNamesAndInvalidDesignations()
1034
                            && taxRel.getType().isMisappliedNameOrInvalidDesignation()
1033
                    if (config.isDeleteMisappliedNames()
1034
                            && taxRel.getType().isMisappliedName()
1035 1035
                            && taxon.equals(taxRel.getToTaxon())){
1036 1036
                        this.deleteTaxon(taxRel.getFromTaxon().getUuid(), config, classificationUuid);
1037 1037
                    } else if (config.isDeleteConceptRelationships() && taxRel.getType().isConceptRelationship()){
......
3028 3028

  
3029 3029
                }
3030 3030
                if (!config.isDeleteTaxonRelationships() && (ref instanceof TaxonRelationship)){
3031
                    if (!config.isDeleteMisappliedNamesAndInvalidDesignations() &&
3032
                            (((TaxonRelationship)ref).getType().isMisappliedNameOrInvalidDesignation())){
3031
                    if (!config.isDeleteMisappliedNames() &&
3032
                            (((TaxonRelationship)ref).getType().isMisappliedName())){
3033 3033
                        message = "The taxon can't be deleted as long as it has misapplied names or invalid designations.";
3034 3034
                    } else{
3035 3035
                        message = "The taxon can't be deleted as long as it belongs to taxon relationship.";
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/config/TaxonDeletionConfigurator.java
49 49

  
50 50
    private boolean deleteSynonymsIfPossible = true;
51 51

  
52
    private boolean deleteMisappliedNamesAndInvalidDesignations = true;
52
    private boolean deleteMisappliedNames = true;
53 53

  
54 54
    private boolean deleteConceptRelationships = false;
55 55

  
......
70 70
    private UUID classificationUuid = null;
71 71

  
72 72

  
73

  
74

  
75 73
	public boolean isDeleteInAllClassifications() {
76 74
        return deleteInAllClassifications;
77 75
    }
78

  
79

  
80 76
    public void setDeleteInAllClassifications(boolean deleteInAllClassifications) {
81 77
        this.deleteInAllClassifications = deleteInAllClassifications;
82 78
    }
83 79

  
84 80

  
85

  
86

  
87 81
    /**
88
     * If <code>true</code> related taxa with  {@link TaxonRelationshipType} misappliedName or invalidDesignation will be removed if possible
82
     * If <code>true</code> related taxa with  {@link TaxonRelationshipType} misappliedName
83
     * will be removed if possible.<BR>
89 84
     * It is possible to remove a related taxon if it is not used in any other context, e.g. any
90 85
     * other @link {@link TaxonRelationship} or in another @link {@link Classification}
91 86
     * @return
92 87
     */
93
    public boolean isDeleteMisappliedNamesAndInvalidDesignations() {
94
        return deleteMisappliedNamesAndInvalidDesignations;
88
    public boolean isDeleteMisappliedNames() {
89
        return deleteMisappliedNames;
95 90
    }
96

  
97

  
98
    public void setDeleteMisappliedNamesAndInvalidDesignations(
99
            boolean deleteMisappliedNamesAndInvalidDesignations) {
100
        this.deleteMisappliedNamesAndInvalidDesignations = deleteMisappliedNamesAndInvalidDesignations;
91
    public void setDeleteMisappliedNames(
92
            boolean deleteMisappliedNames) {
93
        this.deleteMisappliedNames = deleteMisappliedNames;
101 94
    }
102 95

  
103 96

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/TaxonRelationshipsDTO.java
63 63
            TaxonRelationshipType relType = relation.getType();
64 64

  
65 65
            if (relType != null){
66
                this.misapplication = relType.isMisappliedNameOrInvalidDesignation();
66
                this.misapplication = relType.isMisappliedName();
67 67
                this.synonym = relType.isAnySynonym();
68 68
                this.typeUuid = relType.getUuid();
69 69
//                TODO there must be a better DTO which also includes
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TaxonServiceImplTest.java
1175 1175
        Assert.assertNotNull("Child taxon should exist", child1);
1176 1176
        TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
1177 1177
        config.setDeleteTaxonNodes(false);
1178
        config.setDeleteMisappliedNamesAndInvalidDesignations(false);
1178
        config.setDeleteMisappliedNames(false);
1179 1179
        //try {
1180 1180
            //commitAndStartNewTransaction(tableNames);
1181 1181

  
......
1713 1713
        UUID misappliedNameUUID = service.save(misappliedName).getUuid();
1714 1714

  
1715 1715
        TaxonDeletionConfigurator config = new TaxonDeletionConfigurator() ;
1716
        config.setDeleteMisappliedNamesAndInvalidDesignations(true);
1716
        config.setDeleteMisappliedNames(true);
1717 1717

  
1718 1718
        DeleteResult result  = service.deleteTaxon(testTaxon.getUuid(), config, node.getClassification().getUuid());
1719 1719
        if(!result.isOk()){
......
1742 1742
        UUID misappliedNameUUID = service.save(misappliedName).getUuid();
1743 1743

  
1744 1744
        TaxonDeletionConfigurator config = new TaxonDeletionConfigurator() ;
1745
        config.setDeleteMisappliedNamesAndInvalidDesignations(false);
1745
        config.setDeleteMisappliedNames(false);
1746 1746

  
1747 1747
        DeleteResult result = service.deleteTaxon(testTaxon.getUuid(), config, node.getClassification().getUuid());
1748 1748
        if(!result.isOk()){

Also available in: Unified diff