2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.view
.webimport
.termimport
.parser
;
11 import java
.util
.ArrayList
;
12 import java
.util
.List
;
14 import org
.json
.JSONArray
;
15 import org
.json
.JSONException
;
16 import org
.json
.JSONObject
;
18 import eu
.etaxonomy
.taxeditor
.view
.webimport
.termimport
.requests
.RequestTerm
;
19 import eu
.etaxonomy
.taxeditor
.view
.webimport
.termimport
.wrapper
.OntologyTermWrapper
;
26 public class ParserUtil
{
28 public static JSONArray
parseResults(JSONObject jsonObject
) throws JSONException
{
29 return jsonObject
.getJSONArray("results");
32 public static String
parseUri(JSONObject jsonObject
) throws JSONException
{
33 return jsonObject
.getString("uri");
36 public static String
parseLabel(JSONObject jsonObject
) throws JSONException
{
37 return jsonObject
.getString("label");
40 public static String
parseDescription(JSONObject jsonObject
) throws JSONException
{
41 String descriptionKey
= "description";
42 if(jsonObject
.has(descriptionKey
)){
43 return jsonObject
.getString(descriptionKey
);
48 public static List
<String
> parseSynonyms(JSONObject jsonObject
) throws JSONException
{
49 List
<String
> synonyms
= new ArrayList
<>();
50 String synomymKey
= "synonyms";
51 if(jsonObject
.has(synomymKey
)){
52 JSONArray jsonArray
= jsonObject
.getJSONArray(synomymKey
);
53 for(int i
=0;i
<jsonArray
.length();i
++){
54 synonyms
.add(jsonArray
.getString(i
));
60 public static String
parseTerminology(JSONObject jsonObject
) throws JSONException
{
61 return jsonObject
.getString("sourceTerminology");
65 * Loads and sets detail information for the given wrapper
66 * @param wrapper the wrapper for which the detailed information will be loaded and set
68 public static void loadDetails(OntologyTermWrapper wrapper
) {
69 String request
= new RequestTerm(wrapper
.getUri(), wrapper
.getSourceTerminology()).request();
70 OntologyTermWrapper detailTerm
= TermParser
.parseSingleTerm(request
);
71 wrapper
.setDescription(detailTerm
.getDescription());
72 wrapper
.setSynonyms(detailTerm
.getSynonyms());