1
|
// $Id: TaxonBaseBeanProcessor.java 5473 2009-03-25 13:42:07Z a.kohlbecker $
|
2
|
/**
|
3
|
* Copyright (C) 2009 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;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.Arrays;
|
15
|
import java.util.Date;
|
16
|
import java.util.List;
|
17
|
|
18
|
import org.apache.log4j.Logger;
|
19
|
import org.hibernate.Hibernate;
|
20
|
|
21
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
22
|
import eu.etaxonomy.cdm.model.agent.Team;
|
23
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
24
|
import eu.etaxonomy.cdm.model.name.Rank;
|
25
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
26
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
27
|
import eu.etaxonomy.cdm.remote.dto.TagEnum;
|
28
|
import eu.etaxonomy.cdm.remote.dto.TaggedText;
|
29
|
|
30
|
import net.sf.json.JSONObject;
|
31
|
import net.sf.json.JsonConfig;
|
32
|
import net.sf.json.processors.JsonBeanProcessor;
|
33
|
|
34
|
/**
|
35
|
* @author a.kohlbecker
|
36
|
*
|
37
|
*/
|
38
|
public class TaxonNameBaseBeanProcessor extends AbstractCdmBeanProcessor<TaxonNameBase> {
|
39
|
|
40
|
public static final Logger logger = Logger.getLogger(TaxonNameBaseBeanProcessor.class);
|
41
|
|
42
|
/* (non-Javadoc)
|
43
|
* @see eu.etaxonomy.cdm.remote.json.processor.AbstractCdmBeanProcessor#getIgnorePropNames()
|
44
|
*/
|
45
|
@Override
|
46
|
public List<String> getIgnorePropNames() {
|
47
|
return Arrays.asList(new String[]{
|
48
|
});
|
49
|
}
|
50
|
|
51
|
/* (non-Javadoc)
|
52
|
* @see eu.etaxonomy.cdm.remote.json.processor.AbstractCdmBeanProcessor#processBeanSecondStage(java.lang.Object, net.sf.json.JSONObject, net.sf.json.JsonConfig)
|
53
|
*/
|
54
|
@Override
|
55
|
public JSONObject processBeanSecondStep(TaxonNameBase bean, JSONObject json, JsonConfig jsonConfig) {
|
56
|
if(logger.isDebugEnabled()){
|
57
|
logger.debug("processing second step" + bean);
|
58
|
}
|
59
|
json.element("taggedTitle", getTaggedName(bean), jsonConfig);
|
60
|
return json;
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* FIXME ugly method - this functionality mainly be performed by ChachStrategies ?
|
65
|
*
|
66
|
* @param taxonNameBase
|
67
|
* @return
|
68
|
*/
|
69
|
public static List<TaggedText> getTaggedName(TaxonNameBase taxonNameBase){
|
70
|
|
71
|
List<TaggedText> tags = new ArrayList<TaggedText>();
|
72
|
|
73
|
/**
|
74
|
* taxonNameBase.getHibernateLazyInitializer().getImplementation();
|
75
|
* class eu.etaxonomy.cdm.model.name.TaxonNameBase$$EnhancerByCGLIB$$3683183d
|
76
|
* @link( CGLIBLazyInitializer.getImplementation())
|
77
|
*/
|
78
|
// if(taxonNameBase instanceof HibernateProxy) {
|
79
|
// LazyInitializer lazyInitializer = ((HibernateProxy)taxonNameBase).getHibernateLazyInitializer();
|
80
|
// taxonNameBase = (TaxonNameBase)lazyInitializer.getImplementation();
|
81
|
// }
|
82
|
taxonNameBase = HibernateProxyHelper.deproxy(taxonNameBase, TaxonNameBase.class);
|
83
|
|
84
|
//FIXME rude hack:
|
85
|
if(!(taxonNameBase instanceof NonViralName)){
|
86
|
return tags;
|
87
|
}
|
88
|
|
89
|
// --- end of rude hack
|
90
|
//FIXME infrageneric epithets are not jet handled!
|
91
|
// - infraGenericEpithet "Cicerbita"
|
92
|
// - infraSpecificEpithet null
|
93
|
|
94
|
List<Object> taggedName = taxonNameBase.getCacheStrategy().getTaggedName(taxonNameBase);
|
95
|
|
96
|
for (Object token : taggedName){
|
97
|
TaggedText tag = new TaggedText();
|
98
|
if (String.class.isInstance(token)){
|
99
|
tag.setText((String)token);
|
100
|
tag.setType(TagEnum.name);
|
101
|
}
|
102
|
else if (Rank.class.isInstance(token)){
|
103
|
Rank r = (Rank)token;
|
104
|
tag.setText(r.getAbbreviation());
|
105
|
tag.setType(TagEnum.rank);
|
106
|
}
|
107
|
else if (Date.class.isInstance(token)){
|
108
|
Date d = (Date)token;
|
109
|
tag.setText(String.valueOf(d.getYear()));
|
110
|
tag.setType(TagEnum.year);
|
111
|
}
|
112
|
else if (Team.class.isInstance(token)){
|
113
|
Team t = (Team)token;
|
114
|
tag.setText(String.valueOf(t.getTitleCache()));
|
115
|
tag.setType(TagEnum.authors);
|
116
|
}
|
117
|
|
118
|
if (tag!=null){
|
119
|
tags.add(tag);
|
120
|
}
|
121
|
}
|
122
|
return tags;
|
123
|
}
|
124
|
|
125
|
|
126
|
|
127
|
}
|