JAL-3990 gradle spotlessApply
[jalview.git] / src / jalview / gui / structurechooser / PDBStructureChooserQuerySource.java
index 3d1b982..8555a78 100644 (file)
@@ -1,5 +1,27 @@
+/*
+ * 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.
+ */
 package jalview.gui.structurechooser;
 
+import java.util.Locale;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -50,7 +72,6 @@ public class PDBStructureChooserQuerySource
 
   }
 
-
   /**
    * Builds a query string for a given sequences using its DBRef entries
    * 
@@ -78,7 +99,7 @@ public class PDBStructureChooserQuerySource
       {
         if (isValidSeqName(entry.getId()))
         {
-          String id = entry.getId().toLowerCase();
+          String id = entry.getId().toLowerCase(Locale.ROOT);
           queryBuilder.append("pdb_id:").append(id).append(" OR ");
           isPDBRefsFound = true;
           pdbids.add(id);
@@ -106,7 +127,7 @@ public class PDBStructureChooserQuerySource
           else if (dbRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
           {
 
-            String id = getDBRefId(dbRef).toLowerCase();
+            String id = getDBRefId(dbRef).toLowerCase(Locale.ROOT);
             if (!pdbids.contains(id))
             {
               queryBuilder.append("pdb_id:").append(id).append(" OR ");
@@ -126,7 +147,7 @@ public class PDBStructureChooserQuerySource
     {
       String seqName = seq.getName();
       seqName = sanitizeSeqName(seqName);
-      String[] names = seqName.toLowerCase().split("\\|");
+      String[] names = seqName.toLowerCase(Locale.ROOT).split("\\|");
       for (String name : names)
       {
         // System.out.println("Found name : " + name);
@@ -185,7 +206,7 @@ public class PDBStructureChooserQuerySource
     {
       return false;
     }
-    seqName = seqName.toLowerCase();
+    seqName = seqName.toLowerCase(Locale.ROOT);
     for (String ignoredEntry : ignoreList.split(","))
     {
       if (seqName.contains(ignoredEntry))
@@ -235,28 +256,38 @@ public class PDBStructureChooserQuerySource
     lastPdbRequest = pdbRequest;
     return resultList;
   }
+
   public List<FilterOption> getAvailableFilterOptions(String VIEWS_FILTER)
   {
     List<FilterOption> filters = new ArrayList<FilterOption>();
     filters.add(new FilterOption(
-            MessageManager.getString("label.best_quality"),
-            "overall_quality", VIEWS_FILTER, false));
+            "PDBe " + MessageManager.getString("label.best_quality"),
+            "overall_quality", VIEWS_FILTER, false, this));
     filters.add(new FilterOption(
-            MessageManager.getString("label.best_resolution"),
-            "resolution", VIEWS_FILTER, false));
+            "PDBe " + MessageManager.getString("label.best_resolution"),
+            "resolution", VIEWS_FILTER, false, this));
     filters.add(new FilterOption(
-            MessageManager.getString("label.most_protein_chain"),
-            "number_of_protein_chains", VIEWS_FILTER, false));
+            "PDBe " + MessageManager.getString("label.most_protein_chain"),
+            "number_of_protein_chains", VIEWS_FILTER, false, this));
     filters.add(new FilterOption(
-            MessageManager.getString("label.most_bound_molecules"),
-            "number_of_bound_molecules", VIEWS_FILTER, false));
+            "PDBe " + MessageManager
+                    .getString("label.most_bound_molecules"),
+            "number_of_bound_molecules", VIEWS_FILTER, false, this));
     filters.add(new FilterOption(
-            MessageManager.getString("label.most_polymer_residues"),
-            "number_of_polymer_residues", VIEWS_FILTER, true));
-  
+            "PDBe " + MessageManager
+                    .getString("label.most_polymer_residues"),
+            "number_of_polymer_residues", VIEWS_FILTER, true, this));
+
     return filters;
   }
 
+  @Override
+  public boolean needsRefetch(FilterOption selectedFilterOpt)
+  {
+    // PDBe queries never need a refetch first
+    return false;
+  }
+
   /**
    * FTSRestClient specific query builder to pick top ranked entry from a
    * fetchStructuresMetaData query
@@ -273,6 +304,7 @@ public class PDBStructureChooserQuerySource
    * @throws Exception
    */
   public FTSRestResponse selectFirstRankedQuery(SequenceI seq,
+          Collection<FTSData> collectedResults,
           Collection<FTSDataColumnI> wantedFields, String fieldToFilterBy,
           boolean b) throws Exception
   {
@@ -307,33 +339,29 @@ public class PDBStructureChooserQuerySource
     return resultList;
   }
 
-
   @Override
   public PDBEntry[] collectSelectedRows(JTable restable, int[] selectedRows,
           List<SequenceI> selectedSeqsToView)
   {
-    int refSeqColIndex = restable.getColumn("Ref Sequence")
-            .getModelIndex();
+    int refSeqColIndex = restable.getColumn("Ref Sequence").getModelIndex();
 
-    PDBEntry[] pdbEntriesToView=new PDBEntry[selectedRows.length];
+    PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
     int count = 0;
-    int idColumnIndex=-1;
-    boolean fromTDB=true;
+    int idColumnIndex = -1;
+    boolean fromTDB = true;
     idColumnIndex = restable.getColumn("PDB Id").getModelIndex();
-    
+
     for (int row : selectedRows)
     {
-      
-      String pdbIdStr = restable.getValueAt(row,idColumnIndex)
-              .toString();
+
+      String pdbIdStr = restable.getValueAt(row, idColumnIndex).toString();
       SequenceI selectedSeq = (SequenceI) restable.getValueAt(row,
               refSeqColIndex);
       selectedSeqsToView.add(selectedSeq);
       PDBEntry pdbEntry = selectedSeq.getPDBEntry(pdbIdStr);
       if (pdbEntry == null)
       {
-        pdbEntry = getFindEntry(pdbIdStr,
-                selectedSeq.getAllPDBEntries());
+        pdbEntry = getFindEntry(pdbIdStr, selectedSeq.getAllPDBEntries());
       }
 
       if (pdbEntry == null)
@@ -348,11 +376,16 @@ public class PDBStructureChooserQuerySource
     return pdbEntriesToView;
   }
 
-
   @Override
   protected FTSRestRequest getLastFTSRequest()
   {
     return lastPdbRequest;
   }
 
+  public FTSRestResponse executePDBFTSRestRequest(FTSRestRequest pdbRequest)
+          throws Exception
+  {
+    return pdbRestClient.executeRequest(pdbRequest);
+  }
+
 }
\ No newline at end of file