Project

General

Profile

Download (4.83 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2021 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.persistence.dto;
10

    
11
import eu.etaxonomy.cdm.model.common.Language;
12
import eu.etaxonomy.cdm.model.term.Representation;
13

    
14
/**
15
 * @author k.luther
16
 * @since Apr 20, 2021
17
 */
18
public class CharacterDtoLabelBuilder  {
19

    
20
    public static final CharacterDtoLabelBuilder NewDefaultInstance(){
21
        return new CharacterDtoLabelBuilder();
22
    }
23

    
24
    private CharacterDtoLabelBuilder(){}
25

    
26
    public static String buildAbbrevLabel(CharacterDto character, Language lang){
27
        TermNodeDto propertyNode = character.getProperty();
28
        TermNodeDto structureNode = character.getStructure();
29
        TermNodeDto ratioToNode = character.getRatioTo();
30
        Representation structureRepresentation = structureNode.getTerm().getRepresentation(lang);
31
        if(structureRepresentation==null){
32
            structureRepresentation = structureNode.getTerm().getRepresentation(Language.DEFAULT());
33
        }
34
        Representation propertyRepresentation = propertyNode.getTerm().getRepresentation(lang);
35
        if(propertyRepresentation==null){
36
            propertyRepresentation = propertyNode.getTerm().getRepresentation(Language.DEFAULT());
37
        }
38

    
39
        String abbrevLabel = null;
40
        if(structureRepresentation!=null && propertyRepresentation!=null){
41
            if(structureRepresentation.getAbbreviatedLabel()!=null && propertyRepresentation.getAbbreviatedLabel()!=null){
42
                abbrevLabel = structureRepresentation.getAbbreviatedLabel()+" "+propertyRepresentation.getAbbreviatedLabel();
43
            }
44
        }
45

    
46
        if (character.getRatioTo() != null){
47
            Representation ratioToRepresentation = ratioToNode.getTerm().getRepresentation(lang);
48
            if(ratioToRepresentation==null){
49
                ratioToRepresentation = ratioToNode.getTerm().getRepresentation(Language.DEFAULT());
50
            }
51
            if(structureRepresentation!=null && propertyRepresentation!=null){
52

    
53
                if(structureRepresentation.getAbbreviatedLabel()!=null && propertyRepresentation.getAbbreviatedLabel()!=null && ratioToRepresentation.getAbbreviatedLabel() != null){
54
                    abbrevLabel = propertyRepresentation.getAbbreviatedLabel() + " ratio " +structureRepresentation.getAbbreviatedLabel()+ " to " + ratioToRepresentation.getAbbreviatedLabel();
55
                }
56
            }
57

    
58
        }
59

    
60
        return abbrevLabel;
61
    }
62
    public static String buildLabel(CharacterDto character, Language lang){
63
        TermNodeDto propertyNode = character.getProperty();
64
        TermNodeDto structureNode = character.getStructure();
65
        TermNodeDto ratioToNode = character.getRatioTo();
66
        Representation structureRepresentation = structureNode.getTerm().getRepresentation(lang);
67
        if(structureRepresentation==null){
68
            structureRepresentation = structureNode.getTerm().getRepresentation(Language.DEFAULT());
69
        }
70
        Representation propertyRepresentation = propertyNode.getTerm().getRepresentation(lang);
71
        if(propertyRepresentation==null){
72
            propertyRepresentation = propertyNode.getTerm().getRepresentation(Language.DEFAULT());
73
        }
74
        String label = null;
75

    
76
        if(structureRepresentation!=null && propertyRepresentation!=null){
77
            if(structureRepresentation.getLabel()!=null && propertyRepresentation.getLabel()!=null){
78
                label = structureRepresentation.getLabel()+" "+propertyRepresentation.getLabel();
79
            }
80

    
81
        }
82
        if(label!=null){
83
            //default label
84
            label = structureNode.getTerm().getRepresentation_L10n()+" "+propertyNode.getTerm().getRepresentation_L10n();
85
        }
86
        if (character.getRatioTo() != null){
87
            Representation ratioToRepresentation = ratioToNode.getTerm().getRepresentation(lang);
88
            if(ratioToRepresentation==null){
89
                ratioToRepresentation = ratioToNode.getTerm().getRepresentation(Language.DEFAULT());
90
            }
91
            if(structureRepresentation!=null && propertyRepresentation!=null){
92
                if(structureRepresentation.getLabel() != null && propertyRepresentation.getLabel() != null && ratioToRepresentation.getLabel() != null){
93
                    label = propertyRepresentation.getLabel() + " ratio " +structureRepresentation.getLabel()+" to " +ratioToRepresentation.getLabel() ;
94
                }
95

    
96
            }
97
            if(label==null){
98
                //default label
99
                label = propertyNode.getTerm().getRepresentation_L10n()+ " ratio " +structureNode.getTerm().getRepresentation_L10n()+ " to " + ratioToNode.getTerm().getRepresentation_L10n() ;
100
            }
101
        }
102

    
103
        return label;
104
    }
105

    
106
}
(3-3/27)