X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Ffts%2Fservice%2Fthreedbeacons%2FTDBeaconsFTSRestClient.java;h=c275bda4ab0f2c6285db3cc07c9298aea5a44e8f;hb=8a2a0cda7067530f8481c2aec203e18d555f2dfd;hp=cb0bc2d853f51bca3f60cd4f13f7dd420e42a32d;hpb=d18997593094f475503cada1311e10d618e950a9;p=jalview.git
diff --git a/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java b/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java
index cb0bc2d..c275bda 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;
@@ -6,7 +26,6 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import javax.ws.rs.core.MediaType;
@@ -22,11 +41,10 @@ import jalview.fts.api.FTSData;
import jalview.fts.api.FTSDataColumnI;
import jalview.fts.api.FTSRestClientI;
import jalview.fts.api.StructureFTSRestClientI;
+import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
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;
@@ -37,18 +55,21 @@ public class TDBeaconsFTSRestClient extends FTSRestClient
/**
* production server URI
*/
- private static String TDB_PROD_API="https://www.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons/api/uniprot/summary/";
+ 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;
+ 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)
@@ -75,15 +96,17 @@ 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());
+ jalview.bin.Console.outPrintln(uri.toString());
// Execute the REST request
ClientResponse clientResponse;
- if (isMocked()) {
+ if (isMocked())
+ {
clientResponse = null;
}
else
@@ -98,7 +121,9 @@ 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
@@ -109,7 +134,8 @@ 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:
@@ -126,29 +152,30 @@ 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;
+
}
}
/**
* 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
+ * the given query - in 2.11.2 this triggers a failover to the PDBe FTS
*
* @return null
*/
@@ -214,11 +241,10 @@ public class TDBeaconsFTSRestClient extends FTSRestClient
return searchResult;
}
- private static FTSData getFTSData(Map tdbJsonStructure,
+ private static FTSData getFTSData(
+ Map tdbJsonStructureSummary,
FTSRestRequest tdbRequest)
{
- // TODO: consider reusing PDBFTSRestClient.getFTSData ?
-
String primaryKey = null;
Object[] summaryRowData;
@@ -228,21 +254,22 @@ public class TDBeaconsFTSRestClient extends FTSRestClient
SequenceI associatedSeq = tdbRequest.getAssociatedSequence();
int colCounter = 0;
summaryRowData = new Object[(associatedSeq != null)
- ? displayFields.size() + 1
- : displayFields.size()];
- if (associatedSeq != null)
- {
- associatedSequence = associatedSeq;
- summaryRowData[0] = associatedSequence;
- colCounter = 1;
- }
-
+ ? displayFields.size() + 1
+ : displayFields.size()];
+ if (associatedSeq != null)
+ {
+ associatedSequence = associatedSeq;
+ summaryRowData[0] = associatedSequence;
+ colCounter = 1;
+ }
+ Map tdbJsonStructure = (Map) tdbJsonStructureSummary
+ .get("summary");
for (FTSDataColumnI field : displayFields)
{
String fieldData = (tdbJsonStructure.get(field.getCode()) == null)
? " "
: tdbJsonStructure.get(field.getCode()).toString();
- // System.out.println("Field : " + field + " Data : " + fieldData);
+ // jalview.bin.Console.outPrintln("Field : " + field + " Data : " + fieldData);
if (field.isPrimaryKeyColumn())
{
primaryKey = fieldData;
@@ -266,59 +293,14 @@ public class TDBeaconsFTSRestClient extends FTSRestClient
} catch (Exception e)
{
// e.printStackTrace();
- System.out.println("offending value:" + fieldData + fieldData);
+ jalview.bin.Console.outPrintln("offending value:" + fieldData + fieldData);
}
}
}
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,
@@ -359,6 +341,7 @@ public class TDBeaconsFTSRestClient extends FTSRestClient
private Collection allDefaultDisplayedStructureDataColumns;
+ @Override
public Collection getAllDefaultDisplayedStructureDataColumns()
{
if (allDefaultDisplayedStructureDataColumns == null
@@ -384,8 +367,8 @@ public class TDBeaconsFTSRestClient extends FTSRestClient
columnNames = new String[] { "", "Display", "Group" };
break;
case PREFERENCES:
- columnNames = new String[] { "3DB Beacons Field", "Show in search summary",
- "Show in structure summary" };
+ columnNames = new String[] { "3DB Beacons Field",
+ "Show in search summary", "Show in structure summary" };
break;
default:
break;