Show error message when loading ontologies fails
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 21 Jan 2019 14:52:15 +0000 (15:52 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 22 Jan 2019 13:35:52 +0000 (14:35 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/webimport/termimport/GfBioTerminologyImportPresenter.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/webimport/termimport/parser/TerminologyParser.java

index 493c1a1a2a28c2cd7c3ecf73f4fea8644eb7fe7a..a40080de9a68d9f78a1d63f218ab0a8ea99d7458 100644 (file)
@@ -38,12 +38,14 @@ import org.eclipse.swt.events.KeyAdapter;
 import org.eclipse.swt.events.KeyEvent;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
+import org.json.JSONException;
 
 import eu.etaxonomy.cdm.common.CdmUtils;
 import eu.etaxonomy.taxeditor.l10n.Messages;
 import eu.etaxonomy.taxeditor.model.ColorResources;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.preference.Resources;
+import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 import eu.etaxonomy.taxeditor.view.webimport.termimport.parser.TermParser;
 import eu.etaxonomy.taxeditor.view.webimport.termimport.parser.TerminologyParser;
 import eu.etaxonomy.taxeditor.view.webimport.termimport.requests.RequestSearch;
@@ -185,7 +187,12 @@ public class GfBioTerminologyImportPresenter {
             @Override
             protected IStatus run(IProgressMonitor monitor) {
                 String response = new RequestTerminologies().request();
-                availableOntologies = TerminologyParser.parse(response);
+                try {
+                    availableOntologies = TerminologyParser.parse(response);
+                } catch (JSONException e) {
+                    MessagingUtils.errorDialog("Loading ontologies failed", this, "Ontologies could not be found", TaxeditorStorePlugin.PLUGIN_ID, e, false);
+                    e.printStackTrace();
+                }
                 return Status.OK_STATUS;
             }
         };
index 77a8b7d3389e8de6027bc4ad03103710a40870d8..1de37c16a504edd9d48b5aff528cc12ea3bd69b4 100644 (file)
@@ -24,21 +24,17 @@ import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.TerminologyWrapp
  *
  */
 public class TerminologyParser {
-    public static Collection<TerminologyWrapper> parse(String response){
+    public static Collection<TerminologyWrapper> parse(String response) throws JSONException{
         List<TerminologyWrapper> wrapperList = new ArrayList<>();
-        try {
-            JSONObject jsonResponse = new JSONObject(response);
-            JSONArray responseArray = jsonResponse.getJSONArray("results");
-            for(int i=0;i<responseArray.length();i++){
-                JSONObject jsonObject = responseArray.getJSONObject(i);
-                String name = jsonObject.getString("name");
-                String acronym = jsonObject.getString("acronym");
-                String description = ParserUtil.parseDescription(jsonObject);
-                String uri = ParserUtil.parseUri(jsonObject);
-                wrapperList.add(new TerminologyWrapper(name, acronym, description, uri));
-            }
-        } catch (JSONException e) {
-            e.printStackTrace();
+        JSONObject jsonResponse = new JSONObject(response);
+        JSONArray responseArray = jsonResponse.getJSONArray("results");
+        for(int i=0;i<responseArray.length();i++){
+            JSONObject jsonObject = responseArray.getJSONObject(i);
+            String name = jsonObject.getString("name");
+            String acronym = jsonObject.getString("acronym");
+            String description = ParserUtil.parseDescription(jsonObject);
+            String uri = ParserUtil.parseUri(jsonObject);
+            wrapperList.add(new TerminologyWrapper(name, acronym, description, uri));
         }
         return wrapperList;
     }