Project

General

Profile

« Previous | Next » 

Revision 2a28e5d2

Added by Andreas Kohlbecker over 3 years ago

TypedEntityReference: factory method with option to supress the label & using this in TypeDesignationSetFormatter

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/ref/TypedEntityReference.java
26 26

  
27 27
    private Class<T> type;
28 28

  
29
    /**
30
     * @deprecated use factory method instead (TODO: to be made protected once no longer used publicly)
31
     */
32
    @Deprecated
29 33
    public TypedEntityReference(Class<T> type, UUID uuid, String label) {
30 34
        super(uuid, label);
31 35
        this.type = type;
32 36
    }
33 37

  
38
    /**
39
     * @deprecated use factory method instead (TODO; to be made protected once no longer used publicly)
40
     */
41
    @Deprecated
34 42
    public TypedEntityReference(Class<T> type, UUID uuid) {
35 43
        super(uuid, null);
36 44
        this.type = type;
37 45
    }
38 46

  
39
    public static  <T extends CdmBase> TypedEntityReference<T> fromEntity(T entity) {
47
    public static  <T extends CdmBase> TypedEntityReference<T> fromEntity(T entity, boolean withLabel) {
40 48
        if(entity == null) {
41 49
            return null;
42 50
        }
43 51
        entity = HibernateProxyHelper.deproxy(entity);
44
        if(IdentifiableEntity.class.isAssignableFrom(entity.getClass())) {
52
        if(withLabel && IdentifiableEntity.class.isAssignableFrom(entity.getClass())) {
45 53
            return new TypedEntityReference<T>((Class<T>)entity.getClass(), entity.getUuid(), ((IdentifiableEntity)entity).getTitleCache());
46 54
        } else {
47 55
            return new TypedEntityReference<T>((Class<T>)entity.getClass(), entity.getUuid());
48 56
        }
49 57
    }
50 58

  
59
    public static  <T extends CdmBase> TypedEntityReference<T> fromEntity(T entity) {
60
        return TypedEntityReference.fromEntity(entity, true);
61
    }
62

  
51 63
    public Class<T> getType() {
52 64
        return type;
53 65
    }
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetFormatter.java
87 87
        TaggedTextBuilder finalBuilder = new TaggedTextBuilder();
88 88

  
89 89
        if(withNameIfAvailable && manager.getTypifiedNameCache() != null){
90
            finalBuilder.add(TagEnum.name, manager.getTypifiedNameCache(), TypedEntityReference.fromEntity(manager.getTypifiedName()));
90
            finalBuilder.add(TagEnum.name, manager.getTypifiedNameCache(), TypedEntityReference.fromEntity(manager.getTypifiedName(), false));
91 91
            finalBuilder.addPostSeparator(POST_NAME_SEPARTOR);
92 92
        }
93 93

  
......
189 189
            workingsetBuilder.add(TagEnum.separator, TYPE_DESIGNATION_SEPARATOR);
190 190
        }
191 191

  
192
        workingsetBuilder.add(TagEnum.typeDesignation, stringify(typeDes), TypedEntityReference.fromEntity(typeDes));
192
        workingsetBuilder.add(TagEnum.typeDesignation, stringify(typeDes), TypedEntityReference.fromEntity(typeDes, false));
193 193
//        workingsetBuilder.add(TagEnum.typeDesignation, typeDesignationEntityReference.getLabel(), typeDesignationEntityReference);
194 194

  
195 195
        if (withCitation){
......
226 226
        if (ref != null){
227 227
            DefaultReferenceCacheStrategy strategy = ((DefaultReferenceCacheStrategy)ref.getCacheStrategy());
228 228
            String shortCitation = strategy.createShortCitation(ref, source.getCitationMicroReference(), false);
229
            workingsetBuilder.add(TagEnum.reference, shortCitation, TypedEntityReference.fromEntity(ref));
229
            workingsetBuilder.add(TagEnum.reference, shortCitation, TypedEntityReference.fromEntity(ref, false));
230 230
        }
231 231
    }
232 232

  

Also available in: Unified diff