X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Ffts%2Fservice%2Fthreedbeacons%2FTDBeaconsFTSRestClient.java;h=ac02a5fa1705775e9bd87b2800e70e6cf34ce46f;hb=d654b1f014790b7ae25e6eec631847170a930987;hp=9c6f45a2df3c6af21969770861d72a57c1f75eb1;hpb=a848ed8eb380e5f9d915b0d7a062feec4f9d3dad;p=jalview.git
diff --git a/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java b/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java
index 9c6f45a..ac02a5f 100644
--- a/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java
+++ b/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java
@@ -1,3 +1,23 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.fts.service.threedbeacons;
import java.net.URI;
@@ -21,25 +41,37 @@ import jalview.datamodel.SequenceI;
import jalview.fts.api.FTSData;
import jalview.fts.api.FTSDataColumnI;
import jalview.fts.api.FTSRestClientI;
+import jalview.fts.api.StructureFTSRestClientI;
import jalview.fts.core.FTSRestClient;
import jalview.fts.core.FTSRestRequest;
import jalview.fts.core.FTSRestResponse;
+import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
import jalview.fts.service.pdb.PDBFTSRestClient;
import jalview.util.JSONUtils;
import jalview.util.MessageManager;
import jalview.util.Platform;
public class TDBeaconsFTSRestClient extends FTSRestClient
+ implements StructureFTSRestClientI
{
- private static final String DEFAULT_THREEDBEACONS_DOMAIN =
- "https://wwwdev.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons-hub-api/uniprot/";
-
- private static FTSRestClientI instance = null;
-
+ /**
+ * production server URI
+ */
+ private static String TDB_PROD_API = "https://www.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons/api/uniprot/summary/";
+
+ /**
+ * dev server URI
+ */
+ private static String TDB_DEV_API = "https://wwwdev.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons/api/uniprot/summary/";
+
+ private static String DEFAULT_THREEDBEACONS_DOMAIN = TDB_PROD_API;
+
+ public static FTSRestClientI instance = null;
+
protected TDBeaconsFTSRestClient()
- {
+ {
}
-
+
@SuppressWarnings("unchecked")
@Override
public FTSRestResponse executeRequest(FTSRestRequest tdbRestRequest)
@@ -47,8 +79,7 @@ public class TDBeaconsFTSRestClient extends FTSRestClient
{
try
{
- String query = tdbRestRequest.getFieldToSearchBy()
- + tdbRestRequest.getSearchTerm();
+ String query = tdbRestRequest.getSearchTerm();
Client client;
Class clientResponseClass;
if (Platform.isJS())
@@ -60,29 +91,41 @@ public class TDBeaconsFTSRestClient extends FTSRestClient
else
/**
* Java only
+ *
* @j2sIgnore
*/
{
client = Client.create(new DefaultClientConfig());
clientResponseClass = ClientResponse.class;
}
+
WebResource webResource;
- webResource = client.resource(DEFAULT_THREEDBEACONS_DOMAIN)
- .path(query);
+ webResource = client.resource(DEFAULT_THREEDBEACONS_DOMAIN + query);
+
URI uri = webResource.getURI();
System.out.println(uri.toString());
-
+
// Execute the REST request
- ClientResponse clientResponse = webResource
- .accept(MediaType.APPLICATION_JSON).get(clientResponseClass);
-
+ ClientResponse clientResponse;
+ if (isMocked())
+ {
+ clientResponse = null;
+ }
+ else
+ {
+ clientResponse = webResource.accept(MediaType.APPLICATION_JSON)
+ .get(clientResponseClass);
+ }
+
// Get the JSON string from the response object or directly from the
// client (JavaScript)
Map jsonObj = null;
String responseString = null;
-
+
// Check the response status and report exception if one occurs
- int responseStatus = clientResponse.getStatus();
+ int responseStatus = isMocked()
+ ? (mockQueries.containsKey(query) ? 200 : 404)
+ : clientResponse.getStatus();
switch (responseStatus)
{
// if success
@@ -93,89 +136,106 @@ public class TDBeaconsFTSRestClient extends FTSRestClient
}
else
{
- responseString = clientResponse.getEntity(String.class);
+ responseString = isMocked() ? mockQueries.get(query)
+ : clientResponse.getEntity(String.class);
}
break;
case 400:
throw new Exception(parseJsonExceptionString(responseString));
+ case 404:
+ return emptyTDBeaconsJsonResponse();
default:
throw new Exception(
getMessageByHTTPStatusCode(responseStatus, "3DBeacons"));
}
// Process the response and return the result to the caller.
- return parseTDBeaconsJsonResponse(responseString, jsonObj, tdbRestRequest);
+ return parseTDBeaconsJsonResponse(responseString, jsonObj,
+ tdbRestRequest);
} catch (Exception e)
{
String exceptionMsg = e.getMessage();
- if (exceptionMsg.contains("SocketException"))
- {
- // No internet connection
- throw new Exception(MessageManager.getString(
- "exception.unable_to_detect_internet_connection"));
- }
- else if (exceptionMsg.contains("UnknownHostException"))
+ if (exceptionMsg != null)
{
- // The server is unreachable
- throw new Exception(MessageManager.formatMessage(
- "exception.fts_server_unreachable", "3DB Hub"));
- }
- else
- {
- throw e;
+ if (exceptionMsg.contains("SocketException"))
+ {
+ // No internet connection
+ throw new Exception(MessageManager.getString(
+ "exception.unable_to_detect_internet_connection"));
+ }
+ else if (exceptionMsg.contains("UnknownHostException"))
+ {
+ // The server is unreachable
+ throw new Exception(MessageManager.formatMessage(
+ "exception.fts_server_unreachable", "3DB Hub"));
+ }
}
+ throw e;
+
}
-
+
}
-
- public String setSearchTerm(String term) {
+
+ /**
+ * returns response for when the 3D-Beacons service doesn't have a record for
+ * the given query - in 2.11.2 this triggers a failover to the PDBe FTS
+ *
+ * @return null
+ */
+ private FTSRestResponse emptyTDBeaconsJsonResponse()
+ {
+ return null;
+ }
+
+ public String setSearchTerm(String term)
+ {
return term;
}
-
+
public static FTSRestResponse parseTDBeaconsJsonResponse(
String tdbJsonResponseString, FTSRestRequest tdbRestRequest)
{
return parseTDBeaconsJsonResponse(tdbJsonResponseString,
(Map) null, tdbRestRequest);
}
-
+
@SuppressWarnings("unchecked")
- public static FTSRestResponse parseTDBeaconsJsonResponse(String tdbJsonResponseString,
- Map jsonObj, FTSRestRequest tdbRestRequest)
+ public static FTSRestResponse parseTDBeaconsJsonResponse(
+ String tdbJsonResponseString, Map jsonObj,
+ FTSRestRequest tdbRestRequest)
{
FTSRestResponse searchResult = new FTSRestResponse();
List result = null;
-
+
try
{
if (jsonObj == null)
{
- jsonObj = (Map) JSONUtils.parse(tdbJsonResponseString);
+ jsonObj = (Map) JSONUtils
+ .parse(tdbJsonResponseString);
}
-
- Object uniprot_entry = jsonObj.get("uniprot_entry");
- Long seqLength = (Long) ((Map) jsonObj.get("uniprot_entry")).get("sequence_length");
- //System.out.println(uniprot_entry);
- //System.out.println(jsonObj);
- //System.out.println("seqLenght :" + seqLength);
-
- //Map tdbResponse = (Map) jsonObj.get("structures");
+
+ Object uniprot_entry = jsonObj.get("uniprot_entry");
+ // TODO: decide if anything from uniprot_entry needs to be reported via
+ // the FTSRestResponse object
+ // Arnaud added seqLength = (Long) ((Map)
+ // jsonObj.get("uniprot_entry")).get("sequence_length");
+
List