1
|
// $Id: TaxonBeanProcessor.java 5561 2009-04-07 12:25:33Z 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.bean;
|
12
|
|
13
|
import java.util.Arrays;
|
14
|
import java.util.List;
|
15
|
|
16
|
import net.sf.json.JSONObject;
|
17
|
import net.sf.json.JsonConfig;
|
18
|
|
19
|
import org.apache.log4j.Logger;
|
20
|
import org.hibernate.Hibernate;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
|
23
|
import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
|
24
|
import eu.etaxonomy.cdm.model.common.TermBase;
|
25
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
26
|
import eu.etaxonomy.cdm.persistence.dto.ITermRepresentation_L10n;
|
27
|
import eu.etaxonomy.cdm.remote.l10n.TermRepresentation_L10n;
|
28
|
|
29
|
/**
|
30
|
* @author a.kohlbecker
|
31
|
*
|
32
|
*/
|
33
|
public class TermBaseBeanProcessor extends AbstractCdmBeanProcessor<TermBase> {
|
34
|
|
35
|
public static final Logger logger = Logger.getLogger(TermBaseBeanProcessor.class);
|
36
|
|
37
|
private static final List<String> IGNORE_LIST = Arrays.asList(new String[] {
|
38
|
"representations",
|
39
|
"inversRepresentations",
|
40
|
"terms"
|
41
|
});
|
42
|
|
43
|
private boolean replaceRepresentations = false;
|
44
|
|
45
|
public boolean isReplaceRepresentations() {
|
46
|
return replaceRepresentations;
|
47
|
}
|
48
|
|
49
|
public void setReplaceRepresentations(boolean replace) {
|
50
|
this.replaceRepresentations = replace;
|
51
|
}
|
52
|
|
53
|
/* (non-Javadoc)
|
54
|
* @see eu.etaxonomy.cdm.remote.json.processor.AbstractCdmBeanProcessor#getIgnorePropNames()
|
55
|
*/
|
56
|
@Override
|
57
|
public List<String> getIgnorePropNames() {
|
58
|
return IGNORE_LIST;
|
59
|
}
|
60
|
|
61
|
/* (non-Javadoc)
|
62
|
* @see eu.etaxonomy.cdm.remote.json.processor.AbstractCdmBeanProcessor#processBeanSecondStep(eu.etaxonomy.cdm.model.common.CdmBase, net.sf.json.JSONObject, net.sf.json.JsonConfig)
|
63
|
*/
|
64
|
@Override
|
65
|
public JSONObject processBeanSecondStep(TermBase term, JSONObject json, JsonConfig jsonConfig) {
|
66
|
|
67
|
// handle OrderedTermVocabulary
|
68
|
if(OrderedTermVocabulary.class.isAssignableFrom(term.getClass())){
|
69
|
OrderedTermVocabulary otv = (OrderedTermVocabulary)term;
|
70
|
if(Hibernate.isInitialized(otv.getTerms())){
|
71
|
json.element("terms", otv.getOrderedTerms(), jsonConfig);
|
72
|
}
|
73
|
} else if(TermVocabulary.class.isAssignableFrom(term.getClass())) {
|
74
|
TermVocabulary tv = (TermVocabulary)term;
|
75
|
if(Hibernate.isInitialized(tv.getTerms())){
|
76
|
json.element("terms", tv.getTerms(), jsonConfig);
|
77
|
}
|
78
|
}
|
79
|
|
80
|
ITermRepresentation_L10n representation_L10n = new TermRepresentation_L10n(term, false);
|
81
|
if (representation_L10n.getLabel() != null) {
|
82
|
json.element("representation_L10n",representation_L10n.getLabel());
|
83
|
}
|
84
|
if (representation_L10n.getAbbreviatedLabel() != null) {
|
85
|
json.element("representation_L10n_abbreviatedLabel", representation_L10n.getAbbreviatedLabel());
|
86
|
}
|
87
|
if(!replaceRepresentations){
|
88
|
json.element("representations", term.getRepresentations(), jsonConfig);
|
89
|
}
|
90
|
|
91
|
// add additional representation for RelationShipBase
|
92
|
if(RelationshipTermBase.class.isAssignableFrom(term.getClass())){
|
93
|
RelationshipTermBase<?> relTerm = (RelationshipTermBase<?>)term;
|
94
|
ITermRepresentation_L10n inverseRepresentation_L10n = new TermRepresentation_L10n(relTerm, true);
|
95
|
if (inverseRepresentation_L10n.getLabel() != null) {
|
96
|
json.element("inverseRepresentation_L10n", inverseRepresentation_L10n.getLabel());
|
97
|
}
|
98
|
if (inverseRepresentation_L10n.getAbbreviatedLabel() != null) {
|
99
|
json.element("inverseRepresentation_L10n_abbreviatedLabel", inverseRepresentation_L10n.getAbbreviatedLabel());
|
100
|
}
|
101
|
if(!replaceRepresentations){
|
102
|
json.element("inverseRepresentations", relTerm.getRepresentations(), jsonConfig);
|
103
|
}
|
104
|
}
|
105
|
return json;
|
106
|
}
|
107
|
|
108
|
}
|