Project

General

Profile

Revision 4e6e568a

ID4e6e568ab5c32fb97ec0b0b2a134ae7bb1031ce0
Parent 576743e2
Child 78614c1a

Added by Andreas Müller about 2 years ago

ref #6682 fix misapplication deduplication issues

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/TaxonRelationshipsDTO.java
196 196
            if (relation.isMisapplication()){
197 197
                List<TaggedText> tags = relation.getTaggedText();
198 198

  
199
                boolean isDuplicate = false;;
199
                boolean isDuplicate = false;
200 200
                for (List<TaggedText> existing: result){
201 201
                    isDuplicate = mergeIfDuplicate(existing, tags);
202 202
                    if (isDuplicate){
......
230 230
        boolean isDuplicate = true;
231 231
        while (isDuplicate && i < first.size() && j< second.size()){
232 232
            if (tagEqualsMisapplied(first.get(i), second.get(i))){
233
                //do nothing
233
                i++;j++;
234 234
            }else if (!sensuHandled){
235 235
                while (i < first.size() && tagIsSensu(first.get(i))){
236 236
                    i++;
......
244 244
                sensuHandled = true;
245 245
            }else{
246 246
                isDuplicate = false;
247
                i++;j++; //not really necessary
247 248
            }
248
            i++;j++;
249

  
249 250
        }
250
        isDuplicate = isDuplicate && (i == first.size() || j == second.size());
251
        isDuplicate = isDuplicate && i == first.size() && j == second.size();
251 252
        if (isDuplicate && sensuEndInFirst > -1 && sensuStartInSecond > -1){
252 253
            first.addAll(sensuEndInFirst, second.subList(sensuStartInSecond, senusEndInSecond));
253 254
            first.add(sensuEndInFirst, TaggedText.NewSeparatorInstance(SENSU_SEPARATOR));
......
289 290
     */
290 291
    private boolean tagEqualsMisapplied(TaggedText x, TaggedText y) {
291 292
        if (CdmUtils.nullSafeEqual(x.getText(),y.getText())
292
                && x.getType().equals(y.getType())){
293
            //TODO entity
293
                && x.getType().equals(y.getType())
294
                && CdmUtils.nullSafeEqual(x.getEntityReference(),y.getEntityReference())){
294 295
            return true;
295 296
        }else{
296 297
            return false;
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/dto/TaxonRelationshipsDTOTest.java
112 112

  
113 113
    @Test
114 114
    public void test() {
115
        //2
115 116
        Reference sec2 = ReferenceFactory.newGeneric();
116 117
        sec2.setAuthorship(Person.NewInstance("Mue.", "Mueller", "I.", "Inger"));
117 118
        sec2.setDatePublished(TimePeriodParser.parseStringVerbatim("1987"));
118 119
        Taxon from2 = Taxon.NewInstance(fromName, sec2);
119 120
        TaxonRelationship rel2 = toTaxon.addMisappliedName(from2, sec2, "333");
121
        //3
120 122
        //same as rel1 except for sec
121 123
        TaxonRelationship rel3 = toTaxon.addMisappliedName(from2, taxonRel.getCitation(), taxonRel.getCitationMicroReference());
122 124

  
125
        Taxon taxon2 = Taxon.NewInstance(fromName, sec2);
126
        Taxon taxon2Dupl = Taxon.NewInstance(fromName, toSec);
127

  
128
        //4
129
        TaxonRelationship rel4 = toTaxon.addMisappliedName(taxon2, null, null);
130
        TaxonRelationship rel5 = toTaxon.addMisappliedName(taxon2Dupl, null, null);
131

  
132

  
123 133
        TaxonRelationshipsDTO dto = new TaxonRelationshipsDTO();
124 134

  
125 135
        dto.addRelation(taxonRel, Direction.relatedFrom, languages);
126 136
        dto.addRelation(rel2, Direction.relatedFrom, languages);
127 137
        TaxonRelation relToDuplicate = dto.addRelation(rel3, Direction.relatedFrom, languages);
138
        dto.addRelation(rel4, Direction.relatedFrom, languages);
139
        TaxonRelation duplicateWithoutRelSec2 = dto.addRelation(rel5, Direction.relatedFrom, languages);
140

  
128 141
        dto.createMisapplicationString();
142

  
129 143
        List<List<TaggedText>> misapplications = dto.getMisapplications();
130
        Assert.assertEquals(2, misapplications.size());  //1 deduplicated
144
        Assert.assertEquals("2 of 5 misapplications must be deduplicated", 3, misapplications.size());  //2/5 were deduplicated
145

  
131 146
        List<TaggedText> deduplicated = misapplications.get(0);
132 147
        Assert.assertEquals(13, deduplicated.size());
133 148
        Assert.assertSame(relToDuplicate.getTaggedText().get(6), deduplicated.get(8));
149

  
134 150
        Assert.assertEquals(11, misapplications.get(1).size());
135 151

  
152
        deduplicated = misapplications.get(2);
153
        Assert.assertEquals(9, deduplicated.size());
154
        Assert.assertSame(duplicateWithoutRelSec2.getTaggedText().get(6), deduplicated.get(8));
155

  
156

  
136 157
    }
137 158

  
138 159
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)