Project

General

Profile

Download (2.37 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
 * Copyright (C) 2007 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10

    
11
package eu.etaxonomy.cdm.remote.json.processor.bean;
12

    
13
import java.util.List;
14

    
15
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
16
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
17
import net.sf.json.JSONObject;
18
import net.sf.json.JsonConfig;
19
import net.sf.json.processors.JsonBeanProcessor;
20

    
21
/**
22
 * @author a.kohlbecker
23
 * @date 29.07.2010
24
 *
25
 */
26
public class TaxonNodeDtoBeanProcessor implements JsonBeanProcessor {
27

    
28

    
29
    /* (non-Javadoc)
30
     * @see net.sf.json.processors.JsonBeanProcessor#processBean(java.lang.Object, net.sf.json.JsonConfig)
31
     */
32
    @Override
33
    public JSONObject processBean(Object bean, JsonConfig jsonConfig) {
34

    
35
        TaxonNode node = (TaxonNode)bean;
36
        JSONObject json = new JSONObject();
37
        json.element("class", "TaxonNodeDto");
38
        json.element("uuid", node.getUuid(), jsonConfig);
39
        json.element("taxonomicChildrenCount", node.getCountChildren(), jsonConfig);
40
        //json.element("classificationUuid", node.getClassification().getUuid(), jsonConfig);
41
        if(node.getTaxon() != null){
42
            json.element("titleCache", node.getTaxon().getName().getTitleCache(), jsonConfig);
43
            List<TaggedText> taggedTitle = node.getTaxon().getName().getTaggedName();
44
            json.element("taggedTitle", taggedTitle, jsonConfig);
45
            json.element("taxonUuid", node.getTaxon().getUuid(), jsonConfig);
46
            //Sec can be null (web services can return null for sec)
47
            //comparation made for avoiding view exceptions
48
            if (node.getTaxon().getSec() == null){
49
                json.element("secUuid", "null");
50
            }else{
51
                json.element("secUuid", node.getTaxon().getSec().getUuid(), jsonConfig);
52
            }
53
            json.element("unplaced", node.getTaxon().isUnplaced());
54
            json.element("excluded", node.getTaxon().isExcluded());
55
            String ranklabel = null;
56
            if(node.getTaxon().getName().getRank() != null){
57
                ranklabel = node.getTaxon().getName().getRank().getLabel();
58
            }
59
            json.element("rankLabel", ranklabel, jsonConfig);
60
        }
61
        return json;
62
    }
63

    
64
}
(20-20/25)