JAL-3829 abstract essential TDB metadata from the user configurable data array displa...
authorJim Procter <j.procter@dundee.ac.uk>
Fri, 24 Sep 2021 13:17:03 +0000 (14:17 +0100)
committerJim Procter <j.procter@dundee.ac.uk>
Fri, 24 Sep 2021 13:17:03 +0000 (14:17 +0100)
src/jalview/fts/service/threedbeacons/TDB_FTSData.java [new file with mode: 0644]
src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java
src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java

diff --git a/src/jalview/fts/service/threedbeacons/TDB_FTSData.java b/src/jalview/fts/service/threedbeacons/TDB_FTSData.java
new file mode 100644 (file)
index 0000000..3418949
--- /dev/null
@@ -0,0 +1,115 @@
+package jalview.fts.service.threedbeacons;
+
+import java.util.Map;
+import java.util.Objects;
+
+import jalview.fts.api.FTSData;
+
+/**
+ * TDB result bean - holds filtered fields for GUI and essential metadata fields
+ * for back end
+ * 
+ * @author jprocter
+ *
+ */
+public class TDB_FTSData implements FTSData
+{
+  String primaryKey;
+
+  Object[] summaryRowData;
+
+  /*
+   * fields in the JSON object 
+   */
+  public static String Uniprot_Id= "id";
+  public static String Uniprot_Start= "uniprot_start";
+  public static String Uniprot_End= "uniprot_end";
+  public static String Provider= "provider";
+  public static String Model_id= "model_identifier";
+  public static String Model_Category= "model_category";
+  public static String Model_Type= "model_type";
+  public static String Model_Title="model_title";
+  public static String Resolution= "resolution";
+  public static String Confidence= "confidence_avg_local_score";
+  public static String Confidence_Score_Type= "confidence_type";
+  public static String Confidence_Score_Version= "confidence_version";
+  public static String Coverage= "coverage";
+  public static String Sequence_Identity= "sequence_identity";
+  public static String Created_Date= "created";
+  public static String UniProt_Accession= "uniprot_accession";
+  public static String Url= "model_url";
+  public static String Page_URL= "model_page_url";
+  public static String Ensemble_Sample_Url= "ensembl_sample_url";
+
+  /**
+   * original response from server
+   */
+  Map<String, Object> tdb_entry;
+
+  public TDB_FTSData(String primaryKey,
+          Map<String, Object> tdbJsonStructure, Object[] summaryData)
+  {
+    this.primaryKey = primaryKey;
+    tdb_entry = tdbJsonStructure;
+    this.summaryRowData = summaryData;
+  }
+
+  public Object getField(String key)
+  {
+    return tdb_entry.get(key);
+  }
+
+  @Override
+  public Object[] getSummaryData()
+  {
+    return summaryRowData;
+  }
+
+  @Override
+  public Object getPrimaryKey()
+  {
+    return primaryKey;
+  }
+
+  /**
+   * Returns a string representation of this object;
+   */
+  @Override
+  public String toString()
+  {
+    StringBuilder summaryFieldValues = new StringBuilder();
+    for (Object summaryField : summaryRowData)
+    {
+      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(primaryKey, this.toString());
+  }
+
+  @Override
+  public boolean equals(Object that)
+  {
+    return this.toString().equals(that.toString());
+  }
+
+  public String getProvider()
+  {
+    return (String) getField(Provider);
+  }
+
+  public String getModelViewUrl()
+  {
+    return (String) getField(Page_URL);
+  }
+
+}
index c05306a..ccdc525 100644 (file)
@@ -219,8 +219,6 @@ public class TDBeaconsFTSRestClient extends FTSRestClient
   private static FTSData getFTSData(Map<String, Object> tdbJsonStructure,
           FTSRestRequest tdbRequest)
   {
-    // TODO: consider reusing PDBFTSRestClient.getFTSData ?
-
     String primaryKey = null;
     Object[] summaryRowData;
 
@@ -275,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<String, Object> doc,
index 7a311f8..5a7f7d5 100644 (file)
@@ -23,6 +23,7 @@ import jalview.fts.core.FTSDataColumnPreferences;
 import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
 import jalview.fts.core.FTSRestRequest;
 import jalview.fts.core.FTSRestResponse;
+import jalview.fts.service.threedbeacons.TDB_FTSData;
 import jalview.fts.service.threedbeacons.TDBeaconsFTSRestClient;
 import jalview.jbgui.FilterOption;
 
@@ -251,9 +252,11 @@ public class ThreeDBStructureChooserQuerySource
     {
       int prov_idx = lastTdbRequest.getFieldIndex("Provider");
       boolean hasPDBe=false;
-      for (FTSData row : tdbEntries)
+      for (FTSData _row : tdbEntries)
       {
-        String provider = (String) row.getSummaryData()[prov_idx];
+        // tdb returns custom object
+        TDB_FTSData row = (TDB_FTSData) _row;
+        String provider = (String) row.getProvider();
         FilterOption providerOpt = new FilterOption(
                 "3DB Provider - " + provider,
                 FILTER_SOURCE_PREFIX + provider, VIEWS_FILTER, false, this);