+ /**
+ * Primary access point to parsed JSON data, including the call to retrieve
+ * and parsing.
+ *
+ * @param url
+ * request url; if null, getUrl(ids) will be used
+ * @param ids
+ * optional; may be null
+ * @param msDelay
+ * -1 for default delay
+ * @param mode
+ * map, array, or array iterator
+ * @param mapKey
+ * an optional key for an outer map
+ * @return a Map, List, Iterator, or null
+ * @throws IOException
+ * @throws ParseException
+ *
+ * @author Bob Hanson 2019
+ */
+ @SuppressWarnings("unchecked")
+ protected Object getJSON(URL url, List<String> ids, int msDelay, int mode,
+ String mapKey) throws IOException, ParseException
+ {
+ if (url == null)
+ {
+ url = getUrl(ids);
+ }
+
+ Object json = (url == null ? null : getJSON(url, ids, msDelay));
+
+ if (json != null && mapKey != null)
+ {
+ json = ((Map<String, Object>) json).get(mapKey);
+ }
+ if (json == null)
+ {
+ return null;
+ }
+ switch (mode)
+ {
+ case MODE_ARRAY:
+ case MODE_MAP:
+ break;
+ case MODE_ITERATOR:
+ json = ((List<Object>) json).iterator();
+ break;
+ }
+ return json;
+ }
+
+ /**
+ * Fetches and checks Ensembl's REST version number
+ *
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ private void checkEnsemblRestVersion()
+ {
+ EnsemblData info = domainData.get(getDomain());
+
+ try
+ {
+ Map<String, Object> val = (Map<String, Object>) getJSON(
+ new URL(getDomain() + "/info/rest" + CONTENT_TYPE_JSON), null,
+ -1, MODE_MAP, null);
+ if (val == null)
+ {
+ return;
+ }
+ String version = val.get("release").toString();
+ String majorVersion = version.substring(0, version.indexOf("."));
+ String expected = info.expectedRestVersion;
+ String expectedMajorVersion = expected.substring(0,
+ expected.indexOf("."));
+ info.restMajorVersionMismatch = false;
+ try
+ {
+ /*
+ * if actual REST major version is ahead of what we expect,
+ * record this in case we want to warn the user
+ */
+ if (Float.valueOf(majorVersion) > Float
+ .valueOf(expectedMajorVersion))
+ {
+ info.restMajorVersionMismatch = true;
+ }
+ } catch (NumberFormatException e)
+ {
+ System.err.println("Error in REST version: " + e.toString());
+ }
+
+ /*
+ * check if REST version is later than what Jalview has tested against,
+ * if so warn; we don't worry if it is earlier (this indicates Jalview has
+ * been tested in advance against the next pending REST version)
+ */
+ boolean laterVersion = StringUtils.compareVersions(version,
+ expected) == 1;
+ if (laterVersion)
+ {
+ System.err.println(String.format(
+ "EnsemblRestClient expected %s REST version %s but found %s, see %s",
+ getDbSource(), expected, version, REST_CHANGE_LOG));
+ }
+ info.restVersion = version;
+ } catch (Throwable t)
+ {
+ System.err.println(
+ "Error checking Ensembl REST version: " + t.getMessage());
+ }
+ }
+
+ public boolean isRestMajorVersionMismatch()
+ {
+ return domainData.get(getDomain()).restMajorVersionMismatch;
+ }
+
+ /**
+ * Fetches and checks Ensembl's data version number
+ *
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ private void checkEnsemblDataVersion()
+ {
+ Map<String, Object> val;
+ try
+ {
+ val = (Map<String, Object>) getJSON(
+ new URL(getDomain() + "/info/data" + CONTENT_TYPE_JSON), null,
+ -1, MODE_MAP, null);
+ if (val == null)
+ {
+ return;
+ }
+ List<Object> versions = (List<Object>) val.get("releases");
+ domainData.get(getDomain()).dataVersion = versions.get(0).toString();
+ } catch (Throwable e)
+ {// could be IOException | ParseException e) {
+ System.err.println(
+ "Error checking Ensembl data version: " + e.getMessage());
+ }
+ }
+
+ public String getEnsemblDataVersion()
+ {
+ return domainData.get(getDomain()).dataVersion;
+ }
+
+ @Override
+ public String getDbVersion()
+ {
+ return getEnsemblDataVersion();
+ }
+