JAL-2316 Updated to use identifiers jalview service
[jalview.git] / src / jalview / urls / IdentifiersUrlProvider.java
index a966b07..c938666 100644 (file)
@@ -52,6 +52,10 @@ import org.json.simple.parser.ParseException;
 public class IdentifiersUrlProvider extends UrlProviderImpl
 {
 
+  private static final String LOCAL_KEY = "Local";
+
+  private static final String ID_ORG_KEY = "identifiers.org";
+
   // map of string ids to urls
   private HashMap<String, UrlLink> urls;
 
@@ -83,8 +87,24 @@ public class IdentifiersUrlProvider extends UrlProviderImpl
     try
     {
       FileReader reader = new FileReader(idFileName);
+      String key = "";
+      JSONObject obj = (JSONObject) parser.parse(reader);
+      if (obj.containsKey(ID_ORG_KEY))
+      {
+        key = ID_ORG_KEY;
+      }
+      else if (obj.containsKey(LOCAL_KEY))
+      {
+        key = LOCAL_KEY;
+      }
+      else
+      {
+        System.out
+                .println("Unexpected key returned from identifiers jalview service");
+        return idData;
+      }
 
-      JSONArray jsonarray = (JSONArray) parser.parse(reader);
+      JSONArray jsonarray = (JSONArray) obj.get(key);
 
       // loop over each entry in JSON array and build HashMap entry
       for (int i = 0; i < jsonarray.size(); i++)
@@ -100,12 +120,15 @@ public class IdentifiersUrlProvider extends UrlProviderImpl
     } catch (FileNotFoundException e)
     {
       e.printStackTrace();
+      idData.clear();
     } catch (IOException e)
     {
       e.printStackTrace();
+      idData.clear();
     } catch (ParseException e)
     {
       e.printStackTrace();
+      idData.clear();
     }
     return idData;
   }