Project

General

Profile

Download (1.48 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2022 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
package eu.etaxonomy.cdm.remote.json.processor.value;
10

    
11
import java.util.Objects;
12

    
13
import eu.etaxonomy.cdm.api.service.l10n.TermRepresentation_L10n;
14
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSet;
15
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase;
16
import net.sf.json.JSONObject;
17
import net.sf.json.JsonConfig;
18
import net.sf.json.processors.JsonValueProcessor;
19

    
20
/**
21
 * @author a.mueller
22
 * @date 13.07.2022
23
 */
24
public class TypeDesignationSetValueProcessor implements JsonValueProcessor {
25

    
26
    @Override
27
    public Object processArrayValue(Object value, JsonConfig jsonConfig) {
28
        if (value == null) {
29
            return null;
30
        }
31
        TypeDesignationSet tds = (TypeDesignationSet)value;
32
        JSONObject json = new JSONObject();
33
        for(TypeDesignationStatusBase<?> key : tds.keySet()){
34
            TermRepresentation_L10n term_L10n = new TermRepresentation_L10n(key, false);
35
            String label = Objects.toString(term_L10n.getLabel(), "NULL");
36
            json.element(label, tds.get(key), jsonConfig);
37
        }
38
        return json;
39
    }
40

    
41
    @Override
42
    public Object processObjectValue(String arg0, Object value, JsonConfig jsonConfig) {
43
        return processArrayValue(value, jsonConfig);
44
    }
45
}
(9-9/11)