Project

General

Profile

Download (7.63 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2016 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 java.util.ArrayList;
12
import java.util.Collections;
13
import java.util.HashMap;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.UUID;
17
import java.util.stream.Collectors;
18

    
19
import eu.etaxonomy.cdm.model.common.Language;
20
import eu.etaxonomy.cdm.model.taxon.Classification;
21
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
22
import eu.etaxonomy.cdm.model.taxon.Synonym;
23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
25
import eu.etaxonomy.cdm.model.taxon.TaxonNodeStatus;
26
import eu.etaxonomy.cdm.strategy.cache.HTMLTagRules;
27
import eu.etaxonomy.cdm.strategy.cache.TaggedCacheHelper;
28
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
29

    
30
/**
31
 * @author a.kohlbecker
32
 * @since Jun 13, 2016
33
 */
34
public class TaxonNodeDto extends UuidAndTitleCache<ITaxonTreeNode> {
35

    
36
    private static final long serialVersionUID = -7169646913528213604L;
37

    
38
    /**
39
     * count of the direct taxonomic children
40
     */
41
    private int taxonomicChildrenCount = 0;
42

    
43
    /**
44
     * The UUID of the associated secundum reference
45
     */
46
    private UUID secUuid = null;
47

    
48
    /**
49
     * The uuid of the associated Taxon entity
50
     */
51
    private UUID taxonUuid = null;
52

    
53
    /**
54
     * the taggedTitle of the associated TaxonName entity
55
     */
56
    private List<TaggedText> taggedTitle = new ArrayList<>();
57

    
58
    /**
59
     * The status of the TaxonNode entity
60
     */
61
    private TaxonNodeStatus status;
62

    
63
    private Map<Language, String> statusNote = new HashMap<>();
64

    
65

    
66
    /**
67
     * The Rank.label value of the rank to which the associated TaxonName entity is assigned to.
68
     */
69
    private String rankLabel = null;
70
    private Integer rankOrderIndex = null;
71

    
72
    private TaxonStatus taxonStatus;
73

    
74
    private UUID classificationUUID = null;
75
    private UUID parentUUID = null;
76

    
77
    private String treeIndex = null;
78
    private Integer sortIndex = null;
79

    
80

    
81
    public TaxonNodeDto(ITaxonTreeNode taxonNode) {
82
        this(TaxonNode.class, taxonNode);
83
    }
84

    
85
    public TaxonNodeDto(UUID uuid, Integer id, String titleCache) {
86
        super(uuid, id, titleCache);
87
    }
88

    
89
    public TaxonNodeDto(Class type, ITaxonTreeNode taxonTreeNode) {
90
        super(type, taxonTreeNode.getUuid(), taxonTreeNode.getId(), null);
91
        Taxon taxon = null;
92
        TaxonNode taxonNode = null;
93
        Classification classification = null;
94
        if (taxonTreeNode instanceof TaxonNode){
95
            taxonNode = (TaxonNode)taxonTreeNode;
96
            taxon = taxonNode.getTaxon();
97
        }else if (taxonTreeNode instanceof Classification){
98
            classification = (Classification) taxonTreeNode;
99
        }
100

    
101

    
102
        if (taxon != null){
103
            setTitleCache(taxon.getName() != null ? taxon.getName().getTitleCache() : taxon.getTitleCache());
104
            secUuid = taxon.getSec() != null ? taxon.getSec().getUuid() : null;
105
            taxonUuid = taxon.getUuid();
106
            taggedTitle = taxon.getName() != null? taxon.getName().getTaggedName() : taxon.getTaggedTitle();
107
            rankLabel = taxon.getNullSafeRank() != null ? taxon.getNullSafeRank().getLabel() : null;
108
            this.setAbbrevTitleCache(taxon.getTitleCache());
109
            rankOrderIndex =taxon.getNullSafeRank() != null ? taxon.getNullSafeRank().getOrderIndex() : null;
110
        }else{
111
            if (taxonNode != null && taxonNode.getClassification() != null){
112
                setTitleCache(taxonNode.getClassification().getTitleCache());
113
            } else if (classification != null){
114
                setTitleCache(classification.getTitleCache());
115
            }
116
            rankOrderIndex = null;
117
        }
118
        if (taxonNode != null || classification != null){
119
            if (classification != null){
120
                taxonNode = classification.getRootNode();
121
            }
122
            taxonomicChildrenCount = taxonNode.getCountChildren();
123
            status = taxonNode.getStatus();
124

    
125
            for(Language lang : taxonNode.getStatusNote().keySet()) {
126
                statusNote.put(lang, taxonNode.getStatusNote(lang));
127
            }
128

    
129
            treeIndex = taxonNode.treeIndex();
130
            if(taxonNode.getParent() != null) {
131
                parentUUID = taxonNode.getParent().getUuid();
132
            } else {
133
                parentUUID = null;
134
            }
135

    
136
            sortIndex = taxonNode.getSortIndex();
137
            if(taxonNode.getClassification() != null) {
138
                classificationUUID = taxonNode.getClassification().getUuid();
139
            } else if (classification != null){
140
                classificationUUID = classification.getUuid();
141
            }
142

    
143
        }
144
        taxonStatus = TaxonStatus.Accepted;
145
    }
146

    
147
    public TaxonNodeDto(Synonym synonym, boolean isHomotypic) {
148
        super(null, synonym.getName().getTitleCache());
149

    
150
        taxonomicChildrenCount = 0;
151
        secUuid = synonym.getSec().getUuid();
152
        taxonUuid = synonym.getUuid();
153
//        setTitleCache(synonym.getName().getTitleCache());
154
        taggedTitle = synonym.getName().getTaggedName();
155

    
156
        rankLabel = synonym.getNullSafeRank() != null ? synonym.getNullSafeRank().getLabel() : null;
157
        rankOrderIndex =synonym.getNullSafeRank() != null ? synonym.getNullSafeRank().getOrderIndex() : null;
158
        taxonStatus = isHomotypic ? TaxonStatus.SynonymObjective : TaxonStatus.Synonym;
159
        classificationUUID = null;
160

    
161

    
162
    }
163

    
164

    
165
    public int getTaxonomicChildrenCount() {
166
        return taxonomicChildrenCount;
167
    }
168

    
169
    public UUID getSecUuid() {
170
        return secUuid;
171
    }
172

    
173
    public UUID getTaxonUuid() {
174
        return taxonUuid;
175
    }
176

    
177
    public List<TaggedText> getTaggedTitle() {
178
        return taggedTitle;
179
    }
180

    
181
    public TaxonNodeStatus getStatus() {
182
        return status;
183
    }
184

    
185
    public boolean isUnplaced() {
186
        return status == null ? false : status.equals(TaxonNodeStatus.UNPLACED);
187
    }
188

    
189
    public boolean isExcluded() {
190
        return status == null ? false : status.equals(TaxonNodeStatus.EXCLUDED);
191
    }
192

    
193
    public boolean isDoubtful() {
194
        return status == null ? false : status.equals(TaxonNodeStatus.DOUBTFUL);
195
    }
196

    
197
    public String getRankLabel() {
198
        return rankLabel;
199
    }
200

    
201
    public TaxonStatus getTaxonStatus() {
202
        return taxonStatus;
203
    }
204

    
205
    public UUID getClassificationUUID() {
206
        return classificationUUID;
207
    }
208

    
209
    public String getTreeIndex() {
210
        return treeIndex;
211
    }
212

    
213
    public UUID getParentUUID() {
214
        return parentUUID;
215
    }
216

    
217
    public Integer getSortIndex() {
218
        return sortIndex;
219
    }
220

    
221
    public Integer getRankOrderIndex() {
222
        return rankOrderIndex;
223
    }
224

    
225
    public String getTaxonTitleCache(){
226
        return getAbbrevTitleCache();
227
    }
228

    
229
    public String getNameTitleCache(){
230
        return getTitleCache();
231
    }
232

    
233
    /**
234
     * Preliminary implementation. May not be exactly match
235
     * the real name cache.
236
     */
237
    public String getNameCache(){
238
        List<TaggedText> nameCacheTags = taggedTitle.stream()
239
                .filter(t->t.getType().isNameCachePart())
240
                .collect(Collectors.toList());
241
        return TaggedCacheHelper.createString(nameCacheTags, new HTMLTagRules());
242
    }
243

    
244
    @Override
245
    public boolean equals(Object node2){
246
        if (node2 instanceof TaxonNodeDto){
247
            return this.getUuid().equals(((TaxonNodeDto)node2).getUuid());
248
        } else{
249
            return false;
250
        }
251
    }
252

    
253
    public Map<Language, String> getStatusNote() {
254
        return Collections.unmodifiableMap(statusNote);
255
    }
256

    
257
}
(14-14/24)