bringing the titleCache of TeamOrPersonBase back to the REST services
[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 json.element("taggedTitle", taggedTitle, jsonConfig);
43 json.element("taxonUuid", node.getTaxon().getUuid(), jsonConfig);
44 //Sec can be null (web services can return null for sec)
45 //comparation made for avoiding view exceptions
46 if (node.getTaxon().getSec() == null){
47 json.element("secUuid", "null");
48 }else{
49 json.element("secUuid", node.getTaxon().getSec().getUuid(), jsonConfig);
50 }
51 json.element("taxonomicChildrenCount", node.getCountChildren(), jsonConfig);
52 json.element("unplaced", node.getTaxon().isUnplaced());
53 json.element("excluded", node.getTaxon().isExcluded());
54 String ranklabel = null;
55 if(node.getTaxon().getName().getRank() != null){
56 ranklabel = node.getTaxon().getName().getRank().getLabel();
57 }
58 json.element("rankLabel", ranklabel, jsonConfig);
59 //json.element("treeUuid", node.getClassification().getUuid(), jsonConfig);
60
61 return json;
62 }
63
64 }