Project

General

Profile

Download (8.32 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, UUID parentUuid) {
96
        super(uuid, id, nameTitleCache, taxonTitleCache);
97
        this.rankOrderIndex = rankOrderIndex;
98
        this.parentUUID = parentUuid;
99
    }
100

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

    
106
    public TaxonNodeDto(Class<? extends ITaxonTreeNode> type, ITaxonTreeNode taxonTreeNode) {
107
        super(type, taxonTreeNode.getUuid(), taxonTreeNode.getId(), null);
108

    
109
        Taxon taxon = null;
110
        TaxonNode taxonNode = null;
111
        Classification classification = null;
112

    
113
        //taxonNode, taxon, classification
114
        if (taxonTreeNode instanceof TaxonNode){
115
            taxonNode = (TaxonNode)taxonTreeNode;
116
            classification = taxonNode.getClassification();
117
            taxon = taxonNode.getTaxon();
118
        }else if (taxonTreeNode instanceof Classification){
119
            classification = (Classification) taxonTreeNode;
120
            taxonNode = classification.getRootNode();
121
            //taxon should always be null for rootnode therefore no assignment here
122
        }else{
123
            throw new IllegalStateException("Class not yet handled: " +  taxonTreeNode.getClass().getName());
124
        }
125

    
126
        //taxon or titleCache
127
        if (taxon != null){
128
            setTitleCache(taxon.getName() != null ? taxon.getName().getTitleCache() : taxon.getTitleCache());
129
            secUuid = taxon.getSec() != null ? taxon.getSec().getUuid() : null;
130
            taxonUuid = taxon.getUuid();
131
            taggedTitle = taxon.getName() != null? taxon.getName().getTaggedName() : taxon.getTaggedTitle();
132
            rankLabel = taxon.getNullSafeRank() != null ? taxon.getNullSafeRank().getLabel() : null;
133
            this.setAbbrevTitleCache(taxon.getTitleCache());
134
            rankOrderIndex =taxon.getNullSafeRank() != null ? taxon.getNullSafeRank().getOrderIndex() : null;
135
            taxonIsPublish = taxon.isPublish();
136
        }else{
137
            if (classification != null){
138
                setTitleCache(classification.getTitleCache());
139
            }
140
            rankOrderIndex = null;
141
        }
142
        taxonStatus = TaxonStatus.Accepted;
143

    
144
        //taxonNode
145
        taxonomicChildrenCount = taxonNode.getCountChildren();
146
        status = taxonNode.getStatus();
147

    
148
        for(Language lang : taxonNode.getStatusNote().keySet()) {
149
            statusNote.put(lang, taxonNode.getStatusNote(lang));
150
        }
151

    
152
        treeIndex = taxonNode.treeIndex();
153
        if(taxonNode.getParent() != null) {
154
            parentUUID = taxonNode.getParent().getUuid();
155
        } else {
156
            parentUUID = null;
157
        }
158

    
159
        sortIndex = taxonNode.getSortIndex();
160

    
161
        //classification
162
        if (classification != null){
163
            classificationUUID = classification.getUuid();
164
        }
165
    }
166

    
167
    public TaxonNodeDto(Synonym synonym, boolean isHomotypic) {
168
        super(null, synonym.getName().getTitleCache());
169

    
170
        taxonomicChildrenCount = 0;
171
        secUuid = synonym.getSec().getUuid();
172
        taxonUuid = synonym.getUuid();
173
//        setTitleCache(synonym.getName().getTitleCache());
174
        taggedTitle = synonym.getName().getTaggedName();
175

    
176
        rankLabel = synonym.getNullSafeRank() != null ? synonym.getNullSafeRank().getLabel() : null;
177
        rankOrderIndex =synonym.getNullSafeRank() != null ? synonym.getNullSafeRank().getOrderIndex() : null;
178
        taxonStatus = isHomotypic ? TaxonStatus.SynonymObjective : TaxonStatus.Synonym;
179
        classificationUUID = null;
180
    }
181

    
182
    public int getTaxonomicChildrenCount() {
183
        return taxonomicChildrenCount;
184
    }
185

    
186
    public UUID getSecUuid() {
187
        return secUuid;
188
    }
189

    
190
    public UUID getTaxonUuid() {
191
        return taxonUuid;
192
    }
193

    
194
    public List<TaggedText> getTaggedTitle() {
195
        return taggedTitle;
196
    }
197

    
198
    public TaxonNodeStatus getStatus() {
199
        return status;
200
    }
201

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

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

    
210
    public boolean isDoubtful() {
211
        return status == null ? false : status.equals(TaxonNodeStatus.DOUBTFUL);
212
    }
213

    
214
    public String getRankLabel() {
215
        return rankLabel;
216
    }
217

    
218
    public TaxonStatus getTaxonStatus() {
219
        return taxonStatus;
220
    }
221

    
222
    public UUID getClassificationUUID() {
223
        return classificationUUID;
224
    }
225

    
226
    public String getTreeIndex() {
227
        return treeIndex;
228
    }
229

    
230
    public UUID getParentUUID() {
231
        return parentUUID;
232
    }
233

    
234
    public Integer getSortIndex() {
235
        return sortIndex;
236
    }
237

    
238
    public Integer getRankOrderIndex() {
239
        return rankOrderIndex;
240
    }
241

    
242
    public String getTaxonTitleCache(){
243
        return getAbbrevTitleCache();
244
    }
245

    
246
    public String getNameTitleCache(){
247
        return getTitleCache();
248
    }
249

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

    
261
    public boolean isPublish(){
262
        return taxonIsPublish;
263
    }
264

    
265
    @Override
266
    public boolean equals(Object node2){
267
        if (node2 instanceof TaxonNodeDto){
268
            return this.getUuid().equals(((TaxonNodeDto)node2).getUuid());
269
        } else{
270
            return false;
271
        }
272
    }
273

    
274
    public Map<Language, String> getStatusNote() {
275
        return Collections.unmodifiableMap(statusNote);
276
    }
277
}
(18-18/29)