URI uri = webResource.getURI();
- // System.out.println(uri);
+ System.out.println(uri);
// Execute the REST request
ClientResponse clientResponse = webResource
Map<String, Object> jsonObj = null;
String responseString = null;
- // System.out.println("query >>>>>>> " + pdbRestRequest.toString());
+ System.out.println("query >>>>>>> " + pdbRestRequest.toString());
// Check the response status and report exception if one occurs
int responseStatus = clientResponse.getStatus();
package jalview.fts.service.threedbeacons;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
import jalview.fts.api.FTSDataColumnI;
import jalview.fts.api.FTSRestClientI;
import jalview.fts.core.FTSRestRequest;
public class TDBeaconsFTSPanel extends GFTSPanel
{
private static String defaultFTSFrameTitle = MessageManager
- .getString("label.threedb_sequence_fetcher");
+ .getString("label.pdb_sequence_fetcher");
private static Map<String, Integer> tempUserPrefs = new HashMap<>();
private static final String THREEDB_AUTOSEARCH = "FTS.THREEDB.AUTOSEARCH";
+ private static HttpURLConnection connection;
+
public TDBeaconsFTSPanel(SequenceFetcher fetcher)
{
super(fetcher);
this.progressIndicator = (fetcher == null) ? null
: fetcher.getProgressIndicator();
}
+
+ public int TDBeaconsFTSPanel2(String result)
+ {
+ int seqlength = executeParse(result);
+ return seqlength;
+ }
+
+ public static int executeParse(String query) {
+ BufferedReader reader;
+ String line;
+ StringBuffer responseContent = new StringBuffer();
+ try {
+ URL url = new URL("https://wwwdev.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons-hub-api/uniprot/summary/" + query + ".json");
+ connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setConnectTimeout(5000); // <=>5seconds
+ connection.setReadTimeout(5000);
+ // Status check up, 200 = connection succesful
+ int status = connection.getResponseCode();
+ // System.out.println(status);
+
+ if (status > 299) {
+ reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
+ while ((line = reader.readLine()) != null) {
+ responseContent.append(line);
+ }
+ reader.close();
+ } else {
+ reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ while ((line = reader.readLine()) != null) {
+ responseContent.append(line);
+ }
+ reader.close();
+ }
+ //System.out.println(responseContent.toString());
+ int seq = parse(responseContent.toString());
+ return seq;
+
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ connection.disconnect();
+ }
+ return (Integer) null;
+
+ }
+
+ public static int parse(String jsonString) {
+ JSONObject entry = new JSONObject(jsonString);
+ System.out.println(entry);
+ int length = entry.getJSONObject("uniprot_entry").getInt("sequence_length");
+ String ac = entry.getJSONObject("uniprot_entry").getString("ac");
+
+ JSONArray structures = entry.getJSONArray("structures");
+ for (int i=0 ; i < structures.length() ; i++) {
+ String id = structures.getJSONObject(i).getString("model_identifier");
+ System.out.println("identifier num " + i + " : " + id);
+ }
+ System.out.println("length : " + length + "; access name : " + ac);
+ return length;
+
+}
@Override
public void searchAction(boolean isFreshSearch)
System.out.println("No help implemented yet.");
}
-
+
+ public static String decodeSearchTerm(String enteredText) {
+ // no multiple query support yet
+ return enteredText;
+ }
}
try
{
// Removed wantedFields, sortParam & facetPivot from PDBFTSRClient
-
+ String wantedFields = getDataColumnsFieldsAsCommaDelimitedString(
+ tdbRestRequest.getWantedFields());
int responseSize = (tdbRestRequest.getResponseSize() == 0)
? getDefaultResponsePageSize()
: tdbRestRequest.getResponseSize();
clientResponseClass = ClientResponse.class;
}
WebResource webResource;
- webResource = client.resource(DEFAULT_THREEDBEACONS_DOMAIN);
+ webResource = client.resource(DEFAULT_THREEDBEACONS_DOMAIN)
+ .queryParam("P",query);
URI uri = webResource.getURI();
System.out.println(uri);
String expectedString = "1xyz OR text:2xyz OR text:3xyz";
String outcome = PDBFTSPanel.decodeSearchTerm("1xyz:A;2xyz;3xyz",
"text");
- // System.out.println("1 >>>>>>>>>>> " + outcome);
+ System.out.println("1 >>>>>>>>>>> " + outcome);
assertEquals(expectedString, outcome);
expectedString = "1xyz";
--- /dev/null
+package jalview.fts.threedbeacons;
+
+import static org.testng.AssertJUnit.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import jalview.fts.api.FTSDataColumnI;
+import jalview.fts.core.FTSRestRequest;
+import jalview.fts.core.FTSRestResponse;
+import jalview.fts.service.threedbeacons.TDBeaconsFTSRestClient;
+import jalview.gui.JvOptionPane;
+
+public class TDBeaconsFTSRestClientTest
+{
+ @BeforeClass(alwaysRun = true)
+ public void setUpJvOptionPane()
+ {
+ JvOptionPane.setInteractiveMode(false);
+ JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ }
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception
+ {
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void tearDown() throws Exception
+ {
+ }
+
+ @Test(groups = { "External", "Network" })
+
+ public void executeRequestTest()
+ {
+ List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
+ try
+ {
+ wantedFields.add(TDBeaconsFTSRestClient.getInstance()
+ .getDataColumnByNameOrCode("uniprot_entry"));
+ } catch (Exception e1)
+ {
+ e1.printStackTrace();
+ }
+ System.out.println(wantedFields);
+
+ FTSRestRequest request = new FTSRestRequest();
+ //request.setAllowEmptySeq(false);
+ //request.setResponseSize(100);
+ request.setSearchTerm("01308.json");
+ //request.setWantedFields(wantedFields);
+ System.out.println(request.toString());
+
+ FTSRestResponse response;
+ try
+ {
+ response = TDBeaconsFTSRestClient.getInstance().executeRequest(request);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ Assert.fail("Couldn't execute webservice call!");
+ return;
+ }
+ //assertTrue(response.getNumberOfItemsFound() > 99);
+ assertTrue(response.getSearchSummary() != null);
+ assertTrue(response.getSearchSummary().size() > 99);
+ }
+
+}
--- /dev/null
+package jalview.fts.threedbeacons;
+
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
+
+import jalview.fts.service.pdb.PDBFTSPanel;
+import jalview.fts.service.threedbeacons.TDBeaconsFTSPanel;
+import jalview.gui.JvOptionPane;
+
+import javax.swing.JComboBox;
+import javax.swing.JInternalFrame;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import junit.extensions.PA;
+
+
+public class TDBeaconsPanelTest
+{
+ @BeforeClass(alwaysRun = true)
+ public void setUpJvOptionPane()
+ {
+ JvOptionPane.setInteractiveMode(false);
+ JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ }
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception
+ {
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void tearDown() throws Exception
+ {
+ }
+
+ @Test(groups = { "Functional" })
+ public void populateCmbSearchTargetOptionsTest()
+ {
+ TDBeaconsFTSPanel searchPanel = new TDBeaconsFTSPanel(null);
+ assertTrue(searchPanel.getCmbSearchTarget().getItemCount() > 0);
+ searchPanel.populateCmbSearchTargetOptions();
+ }
+
+ @Test
+ public void getFTSframeTitleTest() {
+ TDBeaconsFTSPanel searchPanel = new TDBeaconsFTSPanel(null);
+ System.out.println(searchPanel.getFTSFrameTitle());
+ }
+
+ @Test
+ public void testgetUNIPROTid() {
+ String outcome = TDBeaconsFTSPanel.decodeSearchTerm("P01308");
+ System.out.println(outcome);
+ }
+
+ @Test
+ public void queryTest() {
+ int outcome = TDBeaconsFTSPanel.executeParse("P01308");
+ //System.out.println("query outcome :" + outcome);
+ int expected_length = 110;
+ assertEquals(outcome, expected_length);
+ }
+}