Project

General

Profile

Download (8.94 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
    public TaxonNodeDto(UUID uuid, Integer id, String treeIndex, String nameTitleCache, String taxonTitleCache, Integer rankOrderIndex, UUID parentUuid, Integer sortIndex, UUID classificationUuid, Boolean taxonIsPublished, TaxonNodeStatus status){
95
    	this(uuid, id, treeIndex, nameTitleCache, taxonTitleCache, rankOrderIndex, parentUuid, sortIndex, classificationUuid);
96
    	this.status = status;
97
    	this.taxonIsPublish = taxonIsPublished;
98
    }
99

    
100
    public TaxonNodeDto(UUID uuid, Integer id, String treeIndex, String nameTitleCache, String taxonTitleCache, Integer rankOrderIndex, UUID parentUuid, Integer sortIndex, UUID classificationUuid) {
101
        super(uuid, id, nameTitleCache, taxonTitleCache);
102
        this.rankOrderIndex = rankOrderIndex;
103
        this.parentUUID = parentUuid;
104
        this.treeIndex = treeIndex;
105
        this.sortIndex = sortIndex;
106
        this.classificationUUID = classificationUuid;
107
    }
108

    
109
    public TaxonNodeDto(UUID uuid, Integer id, String titleCache, Integer rankOrderIndex) {
110
        super(uuid, id, titleCache);
111
        this.rankOrderIndex = rankOrderIndex;
112
    }
113

    
114
    public TaxonNodeDto(Class<? extends ITaxonTreeNode> type, ITaxonTreeNode taxonTreeNode) {
115
        super(type, taxonTreeNode.getUuid(), taxonTreeNode.getId(), null);
116

    
117
        Taxon taxon = null;
118
        TaxonNode taxonNode = null;
119
        Classification classification = null;
120

    
121
        //taxonNode, taxon, classification
122
        if (taxonTreeNode instanceof TaxonNode){
123
            taxonNode = (TaxonNode)taxonTreeNode;
124
            classification = taxonNode.getClassification();
125
            taxon = taxonNode.getTaxon();
126
        }else if (taxonTreeNode instanceof Classification){
127
            classification = (Classification) taxonTreeNode;
128
            taxonNode = classification.getRootNode();
129
            //taxon should always be null for rootnode therefore no assignment here
130
        }else{
131
            throw new IllegalStateException("Class not yet handled: " +  taxonTreeNode.getClass().getName());
132
        }
133

    
134
        //taxon or titleCache
135
        if (taxon != null){
136
            setTitleCache(taxon.getName() != null ? taxon.getName().getTitleCache() : taxon.getTitleCache());
137
            secUuid = taxon.getSec() != null ? taxon.getSec().getUuid() : null;
138
            taxonUuid = taxon.getUuid();
139
            taggedTitle = taxon.getName() != null? taxon.getName().getTaggedName() : taxon.getTaggedTitle();
140
            rankLabel = taxon.getNullSafeRank() != null ? taxon.getNullSafeRank().getLabel() : null;
141
            this.setAbbrevTitleCache(taxon.getTitleCache());
142
            rankOrderIndex =taxon.getNullSafeRank() != null ? taxon.getNullSafeRank().getOrderIndex() : null;
143
            taxonIsPublish = taxon.isPublish();
144
        }else{
145
            if (classification != null){
146
                setTitleCache(classification.getTitleCache());
147
            }
148
            rankOrderIndex = null;
149
        }
150
        taxonStatus = TaxonStatus.Accepted;
151

    
152
        //taxonNode
153
        taxonomicChildrenCount = taxonNode.getCountChildren();
154
        status = taxonNode.getStatus();
155

    
156
        for(Language lang : taxonNode.getStatusNote().keySet()) {
157
            statusNote.put(lang, taxonNode.getStatusNote(lang));
158
        }
159

    
160
        treeIndex = taxonNode.treeIndex();
161
        if(taxonNode.getParent() != null) {
162
            parentUUID = taxonNode.getParent().getUuid();
163
        } else {
164
            parentUUID = null;
165
        }
166

    
167
        sortIndex = taxonNode.getSortIndex();
168

    
169
        //classification
170
        if (classification != null){
171
            classificationUUID = classification.getUuid();
172
        }
173
    }
174

    
175
    public TaxonNodeDto(Synonym synonym, boolean isHomotypic) {
176
        super(null, synonym.getName().getTitleCache());
177

    
178
        taxonomicChildrenCount = 0;
179
        secUuid = synonym.getSec().getUuid();
180
        taxonUuid = synonym.getUuid();
181
//        setTitleCache(synonym.getName().getTitleCache());
182
        taggedTitle = synonym.getName().getTaggedName();
183

    
184
        rankLabel = synonym.getNullSafeRank() != null ? synonym.getNullSafeRank().getLabel() : null;
185
        rankOrderIndex =synonym.getNullSafeRank() != null ? synonym.getNullSafeRank().getOrderIndex() : null;
186
        taxonStatus = isHomotypic ? TaxonStatus.SynonymObjective : TaxonStatus.Synonym;
187
        classificationUUID = null;
188
    }
189

    
190
    public int getTaxonomicChildrenCount() {
191
        return taxonomicChildrenCount;
192
    }
193

    
194
    public UUID getSecUuid() {
195
        return secUuid;
196
    }
197

    
198
    public UUID getTaxonUuid() {
199
        return taxonUuid;
200
    }
201

    
202
    public List<TaggedText> getTaggedTitle() {
203
        return taggedTitle;
204
    }
205

    
206
    public TaxonNodeStatus getStatus() {
207
        return status;
208
    }
209

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

    
214
    public boolean isExcluded() {
215
        return status == null ? false : status.equals(TaxonNodeStatus.EXCLUDED);
216
    }
217

    
218
    public boolean isDoubtful() {
219
        return status == null ? false : status.equals(TaxonNodeStatus.DOUBTFUL);
220
    }
221

    
222
    public String getRankLabel() {
223
        return rankLabel;
224
    }
225

    
226
    public TaxonStatus getTaxonStatus() {
227
        return taxonStatus;
228
    }
229

    
230
    public UUID getClassificationUUID() {
231
        return classificationUUID;
232
    }
233

    
234
    public String getTreeIndex() {
235
        return treeIndex;
236
    }
237

    
238
    public UUID getParentUUID() {
239
        return parentUUID;
240
    }
241

    
242
    public Integer getSortIndex() {
243
        return sortIndex;
244
    }
245

    
246
    public Integer getRankOrderIndex() {
247
        return rankOrderIndex;
248
    }
249

    
250
    public String getTaxonTitleCache(){
251
        return getAbbrevTitleCache();
252
    }
253

    
254
    public String getNameTitleCache(){
255
        return getTitleCache();
256
    }
257

    
258
    /**
259
     * Preliminary implementation. May not be exactly match
260
     * the real name cache.
261
     */
262
    public String getNameCache(){
263
        List<TaggedText> nameCacheTags = taggedTitle.stream()
264
                .filter(t->t.getType().isNameCachePart())
265
                .collect(Collectors.toList());
266
        return TaggedCacheHelper.createString(nameCacheTags, new HTMLTagRules());
267
    }
268

    
269
    public boolean isPublish(){
270
        return taxonIsPublish;
271
    }
272

    
273
    @Override
274
    public boolean equals(Object node2){
275
        if (node2 instanceof TaxonNodeDto){
276
            return this.getUuid().equals(((TaxonNodeDto)node2).getUuid());
277
        } else{
278
            return false;
279
        }
280
    }
281

    
282
    public Map<Language, String> getStatusNote() {
283
        return Collections.unmodifiableMap(statusNote);
284
    }
285
}
(20-20/30)