--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+
+tdbeacons_data_columns
+#
+_group.id
+_group.name
+_group.sort_order
+g1;Miscellaneous;2
+g2;Name;1
+#
+_data_column.primary_key;id
+_data_column.default_response_page_size;100
+#
+_data_column.name
+_data_column.code
+_data_column.group_id
+_data_column.data_type
+_data_column.min_col_width
+_data_column.max_col_width
+_data_column.preferred_col_width
+_data_column.is_shown_by_default
+_data_column.is_searchable
+Uniprot Id;id;String;g2;80;150;85;true;true
+UniProt Accession;uniprot_accession;String;g2;50;400;95;true;false
+Entry Name;entry name;String;g2;100;150;105;true;true
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import javax.ws.rs.core.MediaType;
private static FTSRestClientI instance = null;
+ protected TDBeaconsFTSRestClient()
+ {
+ }
+
@SuppressWarnings("unchecked")
@Override
public FTSRestResponse executeRequest(FTSRestRequest tdbRestRequest)
int responseSize = (tdbRestRequest.getResponseSize() == 0)
? getDefaultResponsePageSize()
: tdbRestRequest.getResponseSize();
+ //int offSet = pdbRestRequest.getOffSet();
String query = tdbRestRequest.getFieldToSearchBy()
+ tdbRestRequest.getSearchTerm();
}
WebResource webResource;
webResource = client.resource(DEFAULT_THREEDBEACONS_DOMAIN)
- .queryParam("P",query);
+ .queryParam("ac", query);
+// .queryParam("rows", String.valueOf(responseSize))
+// .queryParam("P",query);
URI uri = webResource.getURI();
System.out.println(uri);
}
+ public String setSearchTerm() {
+ return null;
+ }
+
public static FTSRestResponse parseTDBeaconsJsonResponse(
String tdbJsonResponseString, FTSRestRequest tdbRestRequest)
{
{
jsonObj = (Map<String, Object>) JSONUtils.parse(tdbJsonResponseString);
}
- Map<String, Object> tdbEntry = (Map<String, Object>) jsonObj.get("uniprot_entry");
+ //Map<String, Object> tdbResponse = (Map<String, Object>) jsonObj.get("structures");
//String seqLength = tdbEntry.get("sequence_length").toString();
- int seqLength = Integer.valueOf(tdbEntry.get("sequence_length").toString());
+ //int seqLength = Integer.valueOf(tdbEntry.get("sequence_length").toString());
- // tdbStructures is the list of found structures
-// Map<String, Object> tdbStructures = (Map<String, Object>) jsonObj.get("structures");
- Object[] structures = (Object[]) jsonObj.get("structures");
- String accessName = ((Map<String, Object>) jsonObj.get("uniprot_entry"))
- .get("ac").toString();
- // this is to be modified
- int numFound = structures.length;
-// if (numFound > 0)
-// {
-//
-// result = new ArrayList<>();
-// List<String> models;
-// //= ((Map<String, Object>) jsonObj.get("structures"))
-// //.get("model_identifier").toString();
-// for (Iterator<String> modelsIter = models.iterator(); modelsIter.hasNext();)
-// .hasNext();)
-// {
-// Map<String, Object> doc = (Map<String, Object>) docIter.next();
-// result.add(getFTSData(doc, tdbRestRequest));
-// }
+ int seqLength = (int) ((Map<String, Object>) jsonObj.get("uniprot_entry")).get("sequence_length");
+ result = new ArrayList<>();
+ List<Object> structures = (List<Object>) jsonObj.get("structures");
+ int numFound = 0;
+ for (Iterator<Object> strucIter = structures.iterator(); strucIter
+ .hasNext();)
+ {
+ Map<String, Object> structure = (Map<String, Object>) strucIter.next();
+ result.add(getFTSData(structure, tdbRestRequest));
+ numFound++;
+ }
searchResult.setNumberOfItemsFound(numFound);
- // searchResult.setAccessionName(accessName); ?usefulness?
-// searchResult.setSearchSummary(result);
-//
-// }
+ searchResult.setSearchSummary(result);
+ searchResult.setSequenceLength(seqLength);
+
} catch (ParseException e)
{
e.printStackTrace();
return searchResult;
}
+private static FTSData getFTSData(Map<String, Object> tdbJsonStructure,
+ FTSRestRequest tdbRequest)
+ {
+ // TODO Auto-generated method stub
+ String primaryKey = null;
+ Object[] summaryRowData;
+ Collection<FTSDataColumnI> displayFields = tdbRequest.getWantedFields();
+ int colCounter = 0;
+ summaryRowData = new Object[displayFields.size()];
+ for (FTSDataColumnI field : displayFields) {
+ String fieldData = (tdbJsonStructure.get(field.getCode()) == null) ? " "
+ : tdbJsonStructure.get(field.getCode()).toString();
+ if (field.isPrimaryKeyColumn())
+ {
+ primaryKey = fieldData;
+ summaryRowData[colCounter++] = primaryKey;
+ }
+ else if (fieldData == null || fieldData.isEmpty())
+ {
+ summaryRowData[colCounter++] = null;
+ }
+ else
+ {
+ try
+ {
+ summaryRowData[colCounter++] = (field.getDataType()
+ .getDataTypeClass() == Integer.class)
+ ? Integer.valueOf(fieldData)
+ : (field.getDataType()
+ .getDataTypeClass() == Double.class)
+ ? Double.valueOf(fieldData)
+ : fieldData;
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ System.out.println("offending value:" + 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());
+ }
+ };
+ }
+
// private static FTSData getFTSData(Map<String, Object> doc,
// FTSRestRequest tdbRestRequest)
// {
import static org.testng.AssertJUnit.assertTrue;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import org.testng.Assert;
import org.testng.annotations.Test;
import jalview.fts.api.FTSDataColumnI;
+import jalview.fts.core.FTSRestClient;
import jalview.fts.core.FTSRestRequest;
import jalview.fts.core.FTSRestResponse;
import jalview.fts.service.threedbeacons.TDBeaconsFTSRestClient;
JvOptionPane.setInteractiveMode(false);
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
}
+
+ private FTSRestClient ftsRestClient;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
+ ftsRestClient = new FTSRestClient()
+ {
+
+ @Override
+ public String getColumnDataConfigFileName()
+ {
+ return "/fts/tdbeacons_data_columns.txt";
+ }
+
+ @Override
+ public FTSRestResponse executeRequest(FTSRestRequest ftsRequest)
+ throws Exception
+ {
+ return null;
+ }
+ };
}
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
}
-
- @Test(groups = { "External", "Network" })
+ @Test
+ public void getAllDefaulDisplayedDataColumns()
+ {
+ Assert.assertNotNull(ftsRestClient
+ .getAllDefaultDisplayedFTSDataColumns());
+ System.out.println(ftsRestClient.getAllDefaultDisplayedFTSDataColumns());
+ Assert.assertTrue(!ftsRestClient.getAllDefaultDisplayedFTSDataColumns()
+ .isEmpty());
+ Assert.assertEquals(ftsRestClient
+ .getAllDefaultDisplayedFTSDataColumns().size(), 3);
+ }
+
+ @Test(groups = { "Functional" })
+ public void getPrimaryKeyColumIndexTest()
+ {
+ Collection<FTSDataColumnI> wantedFields = ftsRestClient
+ .getAllDefaultDisplayedFTSDataColumns();
+ int foundIndex = -1;
+ try
+ {
+ Assert.assertEquals(foundIndex, -1);
+ foundIndex = ftsRestClient.getPrimaryKeyColumIndex(wantedFields,
+ false);
+ Assert.assertEquals(foundIndex, 0);
+ foundIndex = ftsRestClient
+ .getPrimaryKeyColumIndex(wantedFields, true);
+ Assert.assertEquals(foundIndex, 1);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ Assert.fail("Exception thrown while testing...");
+ }
+ }
+
+ @Test(groups = { "External", "Network" })
public void executeRequestTest()
{
List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
try
{
wantedFields.add(TDBeaconsFTSRestClient.getInstance()
- .getDataColumnByNameOrCode("uniprot_entry"));
+ .getDataColumnByNameOrCode("model_category"));
+ wantedFields.add(TDBeaconsFTSRestClient.getInstance()
+ .getDataColumnByNameOrCode("provider"));
+ wantedFields.add(TDBeaconsFTSRestClient.getInstance()
+ .getDataColumnByNameOrCode("created"));
} catch (Exception e1)
{
e1.printStackTrace();
}
- System.out.println(wantedFields);
+ System.out.println("wantedFields >>" + wantedFields);
FTSRestRequest request = new FTSRestRequest();
//request.setAllowEmptySeq(false);
//request.setResponseSize(100);
request.setSearchTerm("01308.json");
- //request.setWantedFields(wantedFields);
+ request.setWantedFields(wantedFields);
+ System.out.println("request : " + request.getFieldToSearchBy());
System.out.println(request.toString());
FTSRestResponse response;
assertTrue(response.getSearchSummary() != null);
assertTrue(response.getSearchSummary().size() > 99);
}
-
}