From: Jim Procter Date: Fri, 24 Sep 2021 13:17:03 +0000 (+0100) Subject: JAL-3829 abstract essential TDB metadata from the user configurable data array displa... X-Git-Tag: Release_2_11_2_0~30^2^2~5 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=efff0826d9368314db6215e90a856059b86dbea8;p=jalview.git JAL-3829 abstract essential TDB metadata from the user configurable data array displayed in the JTable --- diff --git a/src/jalview/fts/service/threedbeacons/TDB_FTSData.java b/src/jalview/fts/service/threedbeacons/TDB_FTSData.java new file mode 100644 index 0000000..3418949 --- /dev/null +++ b/src/jalview/fts/service/threedbeacons/TDB_FTSData.java @@ -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 tdb_entry; + + public TDB_FTSData(String primaryKey, + Map 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); + } + +} diff --git a/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java b/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java index c05306a..ccdc525 100644 --- a/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java +++ b/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java @@ -219,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; @@ -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 doc, diff --git a/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java b/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java index 7a311f8..5a7f7d5 100644 --- a/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java +++ b/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java @@ -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);