Project

General

Profile

Revision b127d201

IDb127d201a97c8abd059cecc258f6617d54c6d50f
Parent 8963d4f9
Child 51249b12

Added by Andreas Müller 11 months ago

ref #7666 allow formatting without name part

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/format/taxon/TaxonRelationshipFormatter.java
58 58
    private static final String UNDEFINED_SYMBOL = "??";  //TODO
59 59

  
60 60
    public List<TaggedText> getTaggedText(TaxonRelationship taxonRelationship, boolean reverse, List<Language> languages) {
61
        return getTaggedText(taxonRelationship, reverse, languages, false);
62
    }
63

  
64

  
65

  
66
    public List<TaggedText> getTaggedText(TaxonRelationship taxonRelationship, boolean reverse, List<Language> languages, boolean withoutName) {
61 67

  
62 68
        if (taxonRelationship == null){
63 69
            return null;
......
88 94
        builder.add(TagEnum.symbol, symbol);
89 95

  
90 96
        //name
91
        if (isMisapplied){
92
            //starting quote
93
            String startQuote = " " + doubtfulTaxonStr + QUOTE_START;
94
            builder.addSeparator(startQuote);
95

  
96
            //name cache
97
            List<TaggedText> nameCacheTags = getNameCacheTags(name);
98
            builder.addAll(nameCacheTags);
99

  
100
            //end quote
101
            String endQuote = QUOTE_END;
102
            builder.add(TagEnum.postSeparator, endQuote);
97
        if (!withoutName){
98
            if (isMisapplied){
99
                //starting quote
100
                String startQuote = " " + doubtfulTaxonStr + QUOTE_START;
101
                builder.addSeparator(startQuote);
102

  
103
                //name cache
104
                List<TaggedText> nameCacheTags = getNameCacheTags(name);
105
                builder.addAll(nameCacheTags);
106

  
107
                //end quote
108
                String endQuote = QUOTE_END;
109
                builder.add(TagEnum.postSeparator, endQuote);
110
            }else{
111
                builder.addSeparator(" " + doubtfulTaxonStr);
112
                //name full title cache
113
                List<TaggedText> nameCacheTags = getNameTitleCacheTags(name);
114
                builder.addAll(nameCacheTags);
115
            }
103 116
        }else{
104
            builder.addSeparator(" " + doubtfulTaxonStr);
105
            //name full title cache
106
            List<TaggedText> nameCacheTags = getNameTitleCacheTags(name);
107
            builder.addAll(nameCacheTags);
117
            if (isNotBlank(doubtfulTaxonStr)){
118
                builder.addSeparator(" " + doubtfulTaxonStr);
119
            }
108 120
        }
109 121

  
110

  
111 122
        //sec/sensu (+ Separatoren?)
112 123
        if (isNotBlank(relatedTaxon.getAppendedPhrase())){
113 124
            builder.addWhitespace();
114 125
            builder.add(TagEnum.appendedPhrase, relatedTaxon.getAppendedPhrase());
115 126
        }
116
        List<TaggedText> secTags = getSensuTags(relatedTaxon.getSec(), relatedTaxon.getSecMicroReference(),
127
        List<TaggedText> secTags = getReferenceTags(relatedTaxon.getSec(), relatedTaxon.getSecMicroReference(),
117 128
               /* isMisapplied,*/ false);
118 129
        if (!secTags.isEmpty()) {
119 130
            builder.addSeparator(isMisapplied? SENSU_SEPARATOR : SEC_SEPARATOR);
......
136 147
            }
137 148
        }
138 149

  
139
        List<TaggedText> relSecTags = getSensuTags(taxonRelationship.getCitation(),
150
        List<TaggedText> relSecTags = getReferenceTags(taxonRelationship.getCitation(),
140 151
                taxonRelationship.getCitationMicroReference(),true);
141 152
        if (!relSecTags.isEmpty()){
142 153
            builder.addSeparator(isSynonym ? SYN_SEC : isMisapplied ? ERR_SEC : REL_SEC);
......
146 157
        return builder.getTaggedText();
147 158
    }
148 159

  
149
    private List<TaggedText> getSensuTags(Reference ref, String detail, /*boolean isSensu,*/ boolean isRelation) {
160
    private List<TaggedText> getReferenceTags(Reference ref, String detail, /*boolean isSensu,*/ boolean isRelation) {
150 161
        List<TaggedText> result = new ArrayList<>();
151 162
        String secRef;
152 163

  
cdmlib-model/src/test/java/eu/etaxonomy/cdm/format/TaxonRelationshipFormatterTest.java
274 274

  
275 275
    }
276 276

  
277
    @Test
278
    public void testGetTaggedTextMisappliedNameWithoutName() {
279

  
280
        reverse = true;
281
        String inverseSymbol = TaxonRelationshipType.MISAPPLIED_NAME_FOR().getInverseSymbol();
282
        String symbol = TaxonRelationshipType.MISAPPLIED_NAME_FOR().getSymbol();
283

  
284
        List<TaggedText> tags = formatter.getTaggedText(taxonRel, reverse, languages, true);
285
        String str = TaggedCacheHelper.createString(tags);
286
        Assert.assertEquals(inverseSymbol + " sensu Macfarlane 1918, err. sec. Cheek 1919: 123", str);
287

  
288
        //reverse
289
        tags = formatter.getTaggedText(taxonRel, !reverse, languages, true);
290
        str = TaggedCacheHelper.createString(tags);
291
        Assert.assertEquals(symbol + " sec. ToSecAuthor 1928, rel. sec. Cheek 1919: 123", str);
292

  
293
        //auctores
294
        fromTaxon.setAppendedPhrase("auctores");
295
        tags = formatter.getTaggedText(taxonRel, reverse, languages, true);
296
        str = TaggedCacheHelper.createString(tags);
297
        Assert.assertEquals(inverseSymbol + " auctores sensu Macfarlane 1918, err. sec. Cheek 1919: 123", str);
298

  
299
        fromTaxon.setSec(null);
300
        fromTaxon.setAppendedPhrase("");
301
        tags = formatter.getTaggedText(taxonRel, reverse, languages, true);
302
        str = TaggedCacheHelper.createString(tags);
303
        Assert.assertEquals(inverseSymbol + " auct., err. sec. Cheek 1919: 123", str);
304

  
305
        fromTaxon.setDoubtful(true);
306
        tags = formatter.getTaggedText(taxonRel, reverse, languages, true);
307
        str = TaggedCacheHelper.createString(tags);
308
        System.out.println(str);
309
        Assert.assertEquals(inverseSymbol + " ?\u202F auct., err. sec. Cheek 1919: 123", str);
310

  
311
    }
312

  
277 313
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)