Project

General

Profile

Download (1.53 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.JSONNull;
17
import net.sf.json.JSONObject;
18
import net.sf.json.JsonConfig;
19
import net.sf.json.processors.JsonValueProcessor;
20

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

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

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