Project

General

Profile

Download (8.36 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(UUID uuid, Integer id, String nameTitleCache, String taxonTitleCache) {
91
        super(uuid, id, nameTitleCache, taxonTitleCache);
92

    
93
    }
94

    
95
    public TaxonNodeDto(UUID uuid, Integer id, String nameTitleCache, String taxonTitleCache, Integer rankOrderIndex) {
96
        super(uuid, id, nameTitleCache, taxonTitleCache);
97
        this.rankOrderIndex = rankOrderIndex;
98
    }
99

    
100
    public TaxonNodeDto(UUID uuid, Integer id, String titleCache, Integer rankOrderIndex) {
101
        super(uuid, id, titleCache);
102
        this.rankOrderIndex = rankOrderIndex;
103
    }
104

    
105
    public TaxonNodeDto(Class<? extends ITaxonTreeNode> type, ITaxonTreeNode taxonTreeNode) {
106
        super(type, taxonTreeNode.getUuid(), taxonTreeNode.getId(), null);
107
        Taxon taxon = null;
108
        TaxonNode taxonNode = null;
109
        Classification classification = null;
110
        if (taxonTreeNode instanceof TaxonNode){
111
            taxonNode = (TaxonNode)taxonTreeNode;
112
            taxon = taxonNode.getTaxon();
113
        }else if (taxonTreeNode instanceof Classification){
114
            classification = (Classification) taxonTreeNode;
115
        }
116

    
117
        if (taxon != null){
118
            setTitleCache(taxon.getName() != null ? taxon.getName().getTitleCache() : taxon.getTitleCache());
119
            secUuid = taxon.getSec() != null ? taxon.getSec().getUuid() : null;
120
            taxonUuid = taxon.getUuid();
121
            taggedTitle = taxon.getName() != null? taxon.getName().getTaggedName() : taxon.getTaggedTitle();
122
            rankLabel = taxon.getNullSafeRank() != null ? taxon.getNullSafeRank().getLabel() : null;
123
            this.setAbbrevTitleCache(taxon.getTitleCache());
124
            rankOrderIndex =taxon.getNullSafeRank() != null ? taxon.getNullSafeRank().getOrderIndex() : null;
125
            taxonIsPublish = taxon.isPublish();
126
        }else{
127
            if (taxonNode != null && taxonNode.getClassification() != null){
128
                setTitleCache(taxonNode.getClassification().getTitleCache());
129
            } else if (classification != null){
130
                setTitleCache(classification.getTitleCache());
131
            }
132
            rankOrderIndex = null;
133
        }
134
        if (taxonNode != null || classification != null){
135
            if (classification != null){
136
                taxonNode = classification.getRootNode();
137
            }
138
            taxonomicChildrenCount = taxonNode.getCountChildren();
139
            status = taxonNode.getStatus();
140

    
141
            for(Language lang : taxonNode.getStatusNote().keySet()) {
142
                statusNote.put(lang, taxonNode.getStatusNote(lang));
143
            }
144

    
145
            treeIndex = taxonNode.treeIndex();
146
            if(taxonNode.getParent() != null) {
147
                parentUUID = taxonNode.getParent().getUuid();
148
            } else {
149
                parentUUID = null;
150
            }
151

    
152
            sortIndex = taxonNode.getSortIndex();
153
            if(taxonNode.getClassification() != null) {
154
                classificationUUID = taxonNode.getClassification().getUuid();
155
            } else if (classification != null){
156
                classificationUUID = classification.getUuid();
157
            }
158

    
159
        }
160
        taxonStatus = TaxonStatus.Accepted;
161
    }
162

    
163
    public TaxonNodeDto(Synonym synonym, boolean isHomotypic) {
164
        super(null, synonym.getName().getTitleCache());
165

    
166
        taxonomicChildrenCount = 0;
167
        secUuid = synonym.getSec().getUuid();
168
        taxonUuid = synonym.getUuid();
169
//        setTitleCache(synonym.getName().getTitleCache());
170
        taggedTitle = synonym.getName().getTaggedName();
171

    
172
        rankLabel = synonym.getNullSafeRank() != null ? synonym.getNullSafeRank().getLabel() : null;
173
        rankOrderIndex =synonym.getNullSafeRank() != null ? synonym.getNullSafeRank().getOrderIndex() : null;
174
        taxonStatus = isHomotypic ? TaxonStatus.SynonymObjective : TaxonStatus.Synonym;
175
        classificationUUID = null;
176
    }
177

    
178
    public int getTaxonomicChildrenCount() {
179
        return taxonomicChildrenCount;
180
    }
181

    
182
    public UUID getSecUuid() {
183
        return secUuid;
184
    }
185

    
186
    public UUID getTaxonUuid() {
187
        return taxonUuid;
188
    }
189

    
190
    public List<TaggedText> getTaggedTitle() {
191
        return taggedTitle;
192
    }
193

    
194
    public TaxonNodeStatus getStatus() {
195
        return status;
196
    }
197

    
198
    public boolean isUnplaced() {
199
        return status == null ? false : status.equals(TaxonNodeStatus.UNPLACED);
200
    }
201

    
202
    public boolean isExcluded() {
203
        return status == null ? false : status.equals(TaxonNodeStatus.EXCLUDED);
204
    }
205

    
206
    public boolean isDoubtful() {
207
        return status == null ? false : status.equals(TaxonNodeStatus.DOUBTFUL);
208
    }
209

    
210
    public String getRankLabel() {
211
        return rankLabel;
212
    }
213

    
214
    public TaxonStatus getTaxonStatus() {
215
        return taxonStatus;
216
    }
217

    
218
    public UUID getClassificationUUID() {
219
        return classificationUUID;
220
    }
221

    
222
    public String getTreeIndex() {
223
        return treeIndex;
224
    }
225

    
226
    public UUID getParentUUID() {
227
        return parentUUID;
228
    }
229

    
230
    public Integer getSortIndex() {
231
        return sortIndex;
232
    }
233

    
234
    public Integer getRankOrderIndex() {
235
        return rankOrderIndex;
236
    }
237

    
238
    public String getTaxonTitleCache(){
239
        return getAbbrevTitleCache();
240
    }
241

    
242
    public String getNameTitleCache(){
243
        return getTitleCache();
244
    }
245

    
246
    /**
247
     * Preliminary implementation. May not be exactly match
248
     * the real name cache.
249
     */
250
    public String getNameCache(){
251
        List<TaggedText> nameCacheTags = taggedTitle.stream()
252
                .filter(t->t.getType().isNameCachePart())
253
                .collect(Collectors.toList());
254
        return TaggedCacheHelper.createString(nameCacheTags, new HTMLTagRules());
255
    }
256

    
257
    public boolean isPublish(){
258
        return taxonIsPublish;
259
    }
260

    
261
    @Override
262
    public boolean equals(Object node2){
263
        if (node2 instanceof TaxonNodeDto){
264
            return this.getUuid().equals(((TaxonNodeDto)node2).getUuid());
265
        } else{
266
            return false;
267
        }
268
    }
269

    
270
    public Map<Language, String> getStatusNote() {
271
        return Collections.unmodifiableMap(statusNote);
272
    }
273
}
(18-18/29)