Merge branch 'release/5.1.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / webimport / termimport / parser / OntologyTermParser.java
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 OntologyTermParser {
27 public static Collection<OntologyTermWrapper> parse(String response, String terminology){
28 List<OntologyTermWrapper> wrapperList = new ArrayList<>();
29 try {
30 JSONObject jsonResponse = new JSONObject(response);
31 JSONArray responseArray = ParserUtil.parseResults(jsonResponse);
32 for(int i=0;i<responseArray.length();i++){
33 JSONObject jsonObject = responseArray.getJSONObject(i);
34 String label = ParserUtil.parseLabel(jsonObject);
35 String uriString = ParserUtil.parseUri(jsonObject);
36 wrapperList.add(new OntologyTermWrapper(uriString, label, terminology));
37 }
38 } catch (JSONException e) {
39 e.printStackTrace();
40 }
41 return wrapperList;
42 }
43
44 }