+ /**
+ * Read data from an identifiers.org download file
+ *
+ * @param idFileName
+ * name of identifiers.org download file
+ * @return hashmap of identifiers.org data, keyed by MIRIAM id
+ */
+ @SuppressWarnings("unchecked")
+private HashMap<String, UrlLink> readIdentifiers(String idFileName)
+ {
+ // identifiers.org data
+ HashMap<String, UrlLink> idData = new HashMap<>();
+
+ String errorMessage = null;
+ try
+ {
+ // NOTE: THIS WILL FAIL IN SWINGJS BECAUSE IT INVOLVES A FILE READER
+
+ FileReader reader = new FileReader(idFileName);
+ String key = "";
+ Map<String, Object> obj = (Map<String, Object>) JSONUtils.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;
+ }
+
+ List<Object> jsonarray = (List<Object>) obj.get(key);
+
+ // loop over each entry in JSON array and build HashMap entry
+ for (int i = 0; i < jsonarray.size(); i++)
+ {
+ Map<String, Object> item = (Map<String, Object>) jsonarray.get(i);
+
+ String url = (String) item.get("url") + "/" + DELIM + DB_ACCESSION
+ + DELIM;
+ UrlLink link = new UrlLink((String) item.get("name"), url,
+ (String) item.get("prefix"));
+ idData.put((String) item.get("id"), link);
+ }
+ } catch (IOException | ParseException e)
+ {
+ // unnecessary e.printStackTrace();
+ // Note how in JavaScript we can grab the first bytes from any file reader.
+ // Typical report here is "NetworkError" because the file does not exist.
+ // "https://." is coming from System.getProperty("user.home"), but this could
+ // be set by the page developer to anything, of course.
+ errorMessage = e.toString();
+ idData.clear();
+ }
+ // BH 2018 -- added more valuable report
+ if (errorMessage != null)
+ {
+ System.err.println("IdentifiersUrlProvider: cannot read " + idFileName + ": " + errorMessage);
+ }
+ return idData;