Project

General

Profile

Revision d30b5c09

IDd30b5c09ae0d1cc471ef51532903c2c69c3c34f6
Parent cd37d4f5
Child 090f1450

Added by Andreas Müller about 2 years ago

ref #7508 further fix term representation web service

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/ITermRepresentation_L10n.java
30 30
     */
31 31
    public abstract String getAbbreviatedLabel();
32 32

  
33
    public String getLanguageIso();
34

  
35
    public String getLanguageUuid();
36

  
33 37
    /**
34 38
     * Derives the localized representations from the given term and sets
35 39
     * the according fields of the  TermRepresentation_L10n instance
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/bean/RepresentationBeanProcessor.java
1
/**
2
 * Copyright (C) 2009 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9

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

  
12
import java.util.Arrays;
13
import java.util.List;
14

  
15
import org.apache.commons.lang.StringUtils;
16
import org.apache.log4j.Logger;
17

  
18
import eu.etaxonomy.cdm.model.common.Language;
19
import eu.etaxonomy.cdm.model.common.Representation;
20
import net.sf.json.JSONObject;
21
import net.sf.json.JsonConfig;
22

  
23
/**
24
 * @author a.kohlbecker
25
 *
26
 */
27
public class RepresentationBeanProcessor extends AbstractCdmBeanProcessor<Representation> {
28

  
29
    public static final Logger logger = Logger.getLogger(RepresentationBeanProcessor.class);
30

  
31
    private static final List<String> IGNORE_LIST = Arrays.asList(new String[] {
32
//            "representations",
33
            });
34

  
35

  
36

  
37
    @Override
38
    public List<String> getIgnorePropNames() {
39
        return IGNORE_LIST;
40
    }
41

  
42
    @Override
43
    public JSONObject processBeanSecondStep(Representation representation, JSONObject json,	JsonConfig jsonConfig) {
44

  
45
        if (representation.getText() != null){
46
            json.element("description", representation.getText());
47
        }
48
        Language language = representation.getLanguage();
49
        if (language != null) {
50
            String iso = StringUtils.isEmpty(language.getIso639_2())? language.getIso639_1() : language.getIso639_2();
51
            if (iso != null){
52
                json.element("languageIso", iso);
53
            }
54
            json.element("languageUuid", language.getUuid());
55
        }
56

  
57
        return json;
58
    }
59

  
60
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/bean/TermBaseBeanProcessor.java
70 70
        }
71 71

  
72 72
        ITermRepresentation_L10n representation_L10n = new TermRepresentation_L10n(term, false);
73
        if (representation_L10n.getLabel() != null) {
74
            json.element("representation_L10n",representation_L10n.getLabel());
75
        }
76
        if (representation_L10n.getAbbreviatedLabel() != null) {
77
            json.element("representation_L10n_abbreviatedLabel", representation_L10n.getAbbreviatedLabel());
78
        }
73
        handleL10nRepresentation(json, representation_L10n);
79 74
        if(!replaceRepresentations){
80 75
            json.element("representations", term.getRepresentations(), jsonConfig);
81 76
        }
......
84 79
        if(RelationshipTermBase.class.isAssignableFrom(term.getClass())){
85 80
            RelationshipTermBase<?> relTerm = (RelationshipTermBase<?>)term;
86 81
            ITermRepresentation_L10n inverseRepresentation_L10n = new TermRepresentation_L10n(relTerm, true);
87
            if (inverseRepresentation_L10n.getLabel() != null) {
88
                json.element("inverseRepresentation_L10n", inverseRepresentation_L10n.getLabel());
89
            }
90
            if (inverseRepresentation_L10n.getAbbreviatedLabel() != null) {
91
                json.element("inverseRepresentation_L10n_abbreviatedLabel",  inverseRepresentation_L10n.getAbbreviatedLabel());
92
            }
82
            handleL10nRepresentation(json, inverseRepresentation_L10n);
93 83
            if(!replaceRepresentations){
94
                json.element("inverseRepresentations", relTerm.getRepresentations(), jsonConfig);
84
                json.element("inverseRepresentations", relTerm.getInverseRepresentations(), jsonConfig);
95 85
            }
96 86
        }
97 87
        return json;
98 88
    }
99 89

  
90
    /**
91
     * @param json
92
     * @param representation_L10n
93
     */
94
    private void handleL10nRepresentation(JSONObject json, ITermRepresentation_L10n representation_L10n) {
95
        if (representation_L10n.getLabel() != null) {
96
            json.element("representation_L10n",representation_L10n.getLabel());
97
        }
98
        if (representation_L10n.getAbbreviatedLabel() != null) {
99
            json.element("representation_L10n_abbreviatedLabel", representation_L10n.getAbbreviatedLabel());
100
        }
101
        if (representation_L10n.getAbbreviatedLabel() != null) {
102
            json.element("representation_L10n_language_iso", representation_L10n.getLanguageIso());
103
        }
104
        if (representation_L10n.getAbbreviatedLabel() != null) {
105
            json.element("representation_L10n_language_uuid", representation_L10n.getLanguageUuid());
106
        }
107
    }
108

  
100 109
}
cdmlib-remote/src/main/resources/eu/etaxonomy/cdm/remote/json/jsonConfigurations.xml
122 122
            </property>
123 123
           </bean>
124 124
         </entry>
125
         <entry key="eu.etaxonomy.cdm.model.common.Representation">
126
          <bean class="eu.etaxonomy.cdm.remote.json.processor.bean.RepresentationBeanProcessor"/>
127
         </entry>
125 128
         <entry key="eu.etaxonomy.cdm.model.media.Media">
126 129
            <bean class="eu.etaxonomy.cdm.remote.json.processor.bean.MediaBeanProcessor">
127 130
              <property name="replaceTitle" value="true" />

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)