Project

General

Profile

Revision 050137a3

ID050137a3bc2d5e3bfc31d30b079478e7f1caa98f
Parent 93d11c3e
Child 727a2e1a

Added by Andreas Kohlbecker over 3 years ago

ref #7348 TypeDesignationSetManager provides TaggedText representation

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/TagEnum.java
85 85
     * a secundum micro reference (for TaxonBase)
86 86
     */
87 87
    secMicroReference,
88
    /**
89
     * Any type of label
90
     */
91
    label,
92
    specimenOrObservation,
93
    typeDesignation,
88 94
	;
89 95

  
90 96

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/TaggedCacheHelper.java
27 27
     * @see #createString(List, HTMLTagRules)
28 28
     */
29 29
    public static String createString(List<TaggedText> tags) {
30
        StringBuffer result = new StringBuffer();
30
        StringBuilder result = new StringBuilder();
31 31

  
32 32
        boolean isSeparator;
33 33
        boolean wasSeparator = true;  //true for start tag
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/TaggedTextBuilder.java
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.strategy.cache;
10

  
11
import java.util.ArrayList;
12
import java.util.List;
13

  
14
import eu.etaxonomy.cdm.model.common.CdmBase;
15
import eu.etaxonomy.cdm.ref.TypedEntityReference;
16

  
17
/**
18
 * @author a.kohlbecker
19
 * @since Jul 12, 2018
20
 *
21
 */
22
public class TaggedTextBuilder {
23

  
24
    ArrayList<TaggedText> taggedText = new ArrayList<>();
25

  
26
    public void add(TagEnum type, String text){
27
        taggedText.add(new TaggedText(type, text));
28
    }
29

  
30
    public void add(TagEnum type, String text, TypedEntityReference<?> entityReference){
31
        taggedText.add(new TaggedText(type, text, entityReference));
32
    }
33

  
34
    public void add(TagEnum type, String text, CdmBase entity){
35
        taggedText.add(new TaggedText(type, text, new TypedEntityReference<>(entity.getClass(), entity.getUuid())));
36
    }
37

  
38
    public void  clear() {
39
        taggedText.clear();
40
    }
41

  
42
    @Override
43
    public String toString(){
44
        return TaggedCacheHelper.createString(taggedText);
45
    }
46

  
47
    /**
48
     * @param workingsetBuilder
49
     */
50
    public void addAll(TaggedTextBuilder ttb) {
51
        taggedText.addAll(ttb.taggedText);
52

  
53
    }
54

  
55
    /**
56
     * @return
57
     */
58
    public List<TaggedText> getTaggedText() {
59
        return taggedText;
60
    }
61

  
62
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/RegistrationServiceImpl.java
16 16
import java.util.Set;
17 17

  
18 18
import org.springframework.beans.factory.annotation.Autowired;
19
import org.springframework.beans.factory.annotation.Qualifier;
19 20
import org.springframework.stereotype.Service;
20 21
import org.springframework.transaction.annotation.Transactional;
21 22

  
......
52 53
    }
53 54

  
54 55
    @Autowired
56
    @Qualifier("cdmUserHelper")
55 57
    private UserHelper userHelper;
56 58

  
57 59
    /**
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/RegistrationDTO.java
101 101
        default:
102 102
            try {
103 103
                typeDesignationManager = new TypeDesignationSetManager(reg.getTypeDesignations());
104
                summary = typeDesignationManager.buildString().print();
104
                summary = typeDesignationManager.print();
105 105
            } catch (RegistrationValidationException e) {
106 106
                validationProblems.add("Validation errors: " + e.getMessage());
107 107
            }
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetManager.java
38 38
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
39 39
import eu.etaxonomy.cdm.ref.EntityReference;
40 40
import eu.etaxonomy.cdm.ref.TypedEntityReference;
41
import eu.etaxonomy.cdm.strategy.cache.TagEnum;
42
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
43
import eu.etaxonomy.cdm.strategy.cache.TaggedTextBuilder;
41 44
/**
42 45
 * Manages a collection of {@link TypeDesignationBase TypeDesignations} for the same typified name.
43 46
 *
......
94 97

  
95 98
    private boolean printCitation = false;
96 99

  
100
    private List<TaggedText> taggedText;
101

  
97 102
    /**
98 103
     * @param containgEntity
99 104
     * @param taxonName
......
280 285
    }
281 286
*/
282 287

  
283
    public TypeDesignationSetManager buildString(){
288
    public void buildString(){
284 289

  
285 290
        if(finalString == null){
286 291

  
292
            TaggedTextBuilder finalBuilder = new TaggedTextBuilder();
287 293
            finalString = "";
294

  
288 295
            if(getTypifiedNameCache() != null){
289 296
                finalString += getTypifiedNameCache() + " ";
297
                finalBuilder.add(TagEnum.name, getTypifiedNameCache(), new TypedEntityReference<>(TaxonName.class, getTypifiedNameRef().getUuid()));
290 298
            }
291 299

  
292 300
            int typeCount = 0;
293 301
            if(orderedByTypesByBaseEntity != null){
294 302
                for(TypedEntityReference baseEntityRef : orderedByTypesByBaseEntity.keySet()) {
295
                    StringBuilder sb = new StringBuilder();
303

  
304
                    TaggedTextBuilder workingsetBuilder = new TaggedTextBuilder();
296 305
                    if(typeCount++ > 0){
297
                        sb.append(TYPE_SEPARATOR);
306
                        workingsetBuilder.add(TagEnum.separator, TYPE_SEPARATOR);
298 307
                    }
299 308
                    boolean isNameTypeDesignation = false;
300 309
                    if(SpecimenOrObservationBase.class.isAssignableFrom(baseEntityRef.getType())){
301
                        sb.append("Type: ");
310
                        workingsetBuilder.add(TagEnum.label, "Type:");  // .append(" ");
302 311
                    } else {
303
                        sb.append("NameType: ");
312
                        workingsetBuilder.add(TagEnum.label, "NameType:");  // .append(" ");
304 313
                        isNameTypeDesignation = true;
305 314
                    }
306 315
                    if(!baseEntityRef.getLabel().isEmpty()){
307
                        sb.append(baseEntityRef.getLabel()).append(" ");
316
                        workingsetBuilder.add(TagEnum.specimenOrObservation, baseEntityRef.getLabel(), baseEntityRef); // .append(" ");
308 317
                    }
309 318
                    TypeDesignationWorkingSet typeDesignationWorkingSet = orderedByTypesByBaseEntity.get(baseEntityRef);
310 319
                    if(!isNameTypeDesignation ){
311
                        sb.append("(");
320
                        workingsetBuilder.add(TagEnum.separator, " (");
312 321
                    }
313 322
                    int typeStatusCount = 0;
314 323
                    for(TypeDesignationStatusBase<?> typeStatus : typeDesignationWorkingSet.keySet()) {
315 324
                        if(typeStatusCount++  > 0){
316
                            sb.append(TYPE_STATUS_SEPARATOR);
325
                            workingsetBuilder.add(TagEnum.separator, TYPE_STATUS_SEPARATOR);
317 326
                        }
318 327
                        boolean isPlural = typeDesignationWorkingSet.get(typeStatus).size() > 1;
319 328
                        if(!typeStatus.equals(NULL_STATUS)) {
320
                            sb.append(typeStatus.getLabel());
321
                            if(isPlural){
322
                                sb.append("s: ");
323
                            } else {
324
                                sb.append(", ");
325
                            }
329
                            workingsetBuilder.add(TagEnum.label, typeStatus.getLabel() + (isPlural ? "s:" : ","));
326 330
                        }
327 331
                        int typeDesignationCount = 0;
328 332
                        for(EntityReference typeDesignationEntityReference : typeDesignationWorkingSet.get(typeStatus)) {
329 333
                            if(typeDesignationCount++  > 0){
330
                                sb.append(TYPE_DESIGNATION_SEPARATOR);
334
                                workingsetBuilder.add(TagEnum.separator, TYPE_DESIGNATION_SEPARATOR);
331 335
                            }
332
                            sb.append(typeDesignationEntityReference.getLabel());
336
                            workingsetBuilder.add(TagEnum.typeDesignation, typeDesignationEntityReference.getLabel(), new TypedEntityReference<TypeDesignationBase>(TypeDesignationBase.class, typeDesignationEntityReference.getUuid()));
333 337
                        }
334 338
                    }
335 339
                    if(!isNameTypeDesignation ){
336
                        sb.append(")");
340
                        workingsetBuilder.add(TagEnum.separator, ")");
337 341
                    }
338
                    typeDesignationWorkingSet.setRepresentation(sb.toString());
342
                    typeDesignationWorkingSet.setRepresentation(workingsetBuilder.toString());
339 343
                    finalString += typeDesignationWorkingSet.getRepresentation();
344
                    finalBuilder.addAll(workingsetBuilder);
340 345
                }
341 346
            }
347
            finalString = finalString.trim();
348
            taggedText = finalBuilder.getTaggedText();
342 349
        }
343
        return this;
344 350
    }
345 351

  
346 352
    /**
......
566 572
    }
567 573

  
568 574
    public String print() {
569
        return finalString.trim();
575
        buildString();
576
        return finalString;
577
    }
578

  
579
    public List<TaggedText> toTaggedText() {
580
        buildString();
581
        return taggedText;
570 582
    }
571 583

  
572 584
    /**

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)