Project

General

Profile

Download (1.5 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.taxeditor.view.webimport.termimport.parser;
10

    
11
import java.util.ArrayList;
12
import java.util.Collection;
13
import java.util.List;
14

    
15
import org.json.JSONArray;
16
import org.json.JSONException;
17
import org.json.JSONObject;
18

    
19
import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.OntologyTermWrapper;
20

    
21
/**
22
 * @author pplitzner
23
 * @since May 9, 2018
24
 *
25
 */
26
public class SuggestParser {
27
    public static Collection<OntologyTermWrapper> parse(String response){
28
        List<OntologyTermWrapper> wrapperList = new ArrayList<>();
29
        try {
30
            JSONObject jsonResponse = new JSONObject(response);
31
            JSONArray responseArray = jsonResponse.getJSONArray("results");
32
            for(int i=0;i<responseArray.length();i++){
33
                JSONObject terminology = responseArray.getJSONObject(i);
34
                String label = terminology.getString("label");
35
                String uri = terminology.getString("uri");
36
                String sourceTerminology = terminology.getString("sourceTerminology");
37
                wrapperList.add(new OntologyTermWrapper(uri, label, sourceTerminology));
38
            }
39
        } catch (JSONException jsonException) {
40
            jsonException.printStackTrace();
41
        }
42
        return wrapperList;
43
    }
44

    
45
}
(3-3/4)