Project

General

Profile

Download (1.72 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.requests.RequestTerm;
20
import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.OntologyTermWrapper;
21

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

    
48
}
(4-4/6)