Project

General

Profile

Download (7.78 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
    private boolean taxonIsPublish = true;
80

    
81

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

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

    
90
    public TaxonNodeDto(Class type, ITaxonTreeNode taxonTreeNode) {
91
        super(type, taxonTreeNode.getUuid(), taxonTreeNode.getId(), null);
92
        Taxon taxon = null;
93
        TaxonNode taxonNode = null;
94
        Classification classification = null;
95
        if (taxonTreeNode instanceof TaxonNode){
96
            taxonNode = (TaxonNode)taxonTreeNode;
97
            taxon = taxonNode.getTaxon();
98
        }else if (taxonTreeNode instanceof Classification){
99
            classification = (Classification) taxonTreeNode;
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
            taxonIsPublish = taxon.isPublish();
111
        }else{
112
            if (taxonNode != null && taxonNode.getClassification() != null){
113
                setTitleCache(taxonNode.getClassification().getTitleCache());
114
            } else if (classification != null){
115
                setTitleCache(classification.getTitleCache());
116
            }
117
            rankOrderIndex = null;
118
        }
119
        if (taxonNode != null || classification != null){
120
            if (classification != null){
121
                taxonNode = classification.getRootNode();
122
            }
123
            taxonomicChildrenCount = taxonNode.getCountChildren();
124
            status = taxonNode.getStatus();
125

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

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

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

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

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

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

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

    
163
    public int getTaxonomicChildrenCount() {
164
        return taxonomicChildrenCount;
165
    }
166

    
167
    public UUID getSecUuid() {
168
        return secUuid;
169
    }
170

    
171
    public UUID getTaxonUuid() {
172
        return taxonUuid;
173
    }
174

    
175
    public List<TaggedText> getTaggedTitle() {
176
        return taggedTitle;
177
    }
178

    
179
    public TaxonNodeStatus getStatus() {
180
        return status;
181
    }
182

    
183

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

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

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

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

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

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

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

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

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

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

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

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

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

    
243
    public boolean isPublish(){
244
        return taxonIsPublish;
245
    }
246

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

    
256
    public Map<Language, String> getStatusNote() {
257
        return Collections.unmodifiableMap(statusNote);
258
    }
259
}
(16-16/26)