X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Ffts%2Fservice%2Fthreedbeacons%2FTDBeaconsFTSRestClient.java;h=ccdc525b3187efbad87c2e85e41aebe2a12ec628;hb=efff0826d9368314db6215e90a856059b86dbea8;hp=73939c32ed4c167be900581aaa4579c36ff61ba8;hpb=bb3748fd2cc3ee8e8e0409599569e24e88974a17;p=jalview.git diff --git a/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java b/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java index 73939c3..ccdc525 100644 --- a/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java +++ b/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java @@ -34,7 +34,15 @@ 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/api/uniprot/summary/"; + /** + * 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; @@ -67,9 +75,10 @@ public class TDBeaconsFTSRestClient extends FTSRestClient 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()); @@ -90,7 +99,7 @@ public class TDBeaconsFTSRestClient extends FTSRestClient String responseString = null; // Check the response status and report exception if one occurs - int responseStatus = isMocked() ? (mockQuery.equals(query) ? 200 : 404) : clientResponse.getStatus(); + int responseStatus = isMocked() ? (mockQueries.containsKey(query) ? 200 : 404) : clientResponse.getStatus(); switch (responseStatus) { // if success @@ -101,7 +110,7 @@ public class TDBeaconsFTSRestClient extends FTSRestClient } else { - responseString = isMocked() ? mockResponse: clientResponse.getEntity(String.class); + responseString = isMocked() ? mockQueries.get(query): clientResponse.getEntity(String.class); } break; case 400: @@ -118,22 +127,23 @@ public class TDBeaconsFTSRestClient extends FTSRestClient } 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; + } } @@ -209,8 +219,6 @@ public class TDBeaconsFTSRestClient extends FTSRestClient private static FTSData getFTSData(Map tdbJsonStructure, FTSRestRequest tdbRequest) { - // TODO: consider reusing PDBFTSRestClient.getFTSData ? - String primaryKey = null; Object[] summaryRowData; @@ -265,52 +273,7 @@ public class TDBeaconsFTSRestClient extends FTSRestClient final String primaryKey1 = primaryKey; final Object[] summaryRowData1 = summaryRowData; - return new FTSData() - { - - @Override - public Object[] getSummaryData() - { - return summaryRowData1; - } - - @Override - public Object getPrimaryKey() - { - return primaryKey1; - } - - /** - * Returns a string representation of this object; - */ - @Override - public String toString() - { - StringBuilder summaryFieldValues = new StringBuilder(); - for (Object summaryField : summaryRowData1) - { - summaryFieldValues.append( - summaryField == null ? " " : summaryField.toString()) - .append("\t"); - } - return summaryFieldValues.toString(); - } - - /** - * Returns hash code value for this object - */ - @Override - public int hashCode() - { - return Objects.hash(primaryKey1, this.toString()); - } - - @Override - public boolean equals(Object that) - { - return this.toString().equals(that.toString()); - } - }; + return new TDB_FTSData(primaryKey, tdbJsonStructure, summaryRowData1); } // private static FTSData getFTSData(Map doc,