fixing CDM part of #386 (Handle hybrids in data portals)
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / json / processor / bean / TaxonNodeDaoBeanProcessor.java
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 net.sf.json.JSONObject;
16 import net.sf.json.JsonConfig;
17 import net.sf.json.processors.JsonBeanProcessor;
18 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
19 import eu.etaxonomy.cdm.strategy.TaggedText;
20 import eu.etaxonomy.cdm.strategy.TaggedTextGenerator;
21
22 /**
23 * @author a.kohlbecker
24 * @date 29.07.2010
25 *
26 */
27 public class TaxonNodeDaoBeanProcessor implements JsonBeanProcessor {
28
29
30 /* (non-Javadoc)
31 * @see net.sf.json.processors.JsonBeanProcessor#processBean(java.lang.Object, net.sf.json.JsonConfig)
32 */
33 @Override
34 public JSONObject processBean(Object bean, JsonConfig jsonConfig) {
35
36 TaxonNode node = (TaxonNode)bean;
37 JSONObject json = new JSONObject();
38 json.element("class", "TaxonNodeDao");
39 json.element("uuid", node.getUuid(), jsonConfig);
40 json.element("titleCache", node.getTaxon().getName().getTitleCache(), jsonConfig);
41 // List<TaggedText> taggedTitle = TaggedTextGenerator.getTaggedName(node.getTaxon().getName());
42 List<TaggedText> taggedTitle = node.getTaxon().getName().getTaggedName();
43 json.element("taggedTitle", taggedTitle, jsonConfig);
44 json.element("taxonUuid", node.getTaxon().getUuid(), jsonConfig);
45 //Sec can be null (web services can return null for sec)
46 //comparation made for avoiding view exceptions
47 if (node.getTaxon().getSec() == null){
48 json.element("secUuid", "null");
49 }else{
50 json.element("secUuid", node.getTaxon().getSec().getUuid(), jsonConfig);
51 }
52 json.element("taxonomicChildrenCount", node.getCountChildren(), jsonConfig);
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 //json.element("treeUuid", node.getClassification().getUuid(), jsonConfig);
61
62 return json;
63 }
64
65 }