JAL-1705 regular expression updates, tests, other refactoring
[jalview.git] / src / jalview / gui / SequenceFetcher.java
index a973757..fc6fb0d 100755 (executable)
@@ -22,7 +22,6 @@ package jalview.gui;
 
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefEntry;
-import jalview.datamodel.DBRefSource;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.io.FormatAdapter;
@@ -54,8 +53,6 @@ import javax.swing.JTextArea;
 import javax.swing.SwingConstants;
 import javax.swing.tree.DefaultMutableTreeNode;
 
-import com.stevesoft.pat.Regex;
-
 public class SequenceFetcher extends JPanel implements Runnable
 {
   JLabel dbeg = new JLabel();
@@ -518,6 +515,7 @@ public class SequenceFetcher extends JPanel implements Runnable
       resetDialog();
       return;
     }
+    // TODO: Refactor to GUI independent code and write tests.
     // indicate if successive sources should be merged into one alignment.
     boolean addToLast = false;
     ArrayList<String> aresultq = new ArrayList<String>(), presultTitle = new ArrayList<String>();
@@ -552,7 +550,7 @@ public class SequenceFetcher extends JPanel implements Runnable
                             Integer.valueOf(nqueries).toString(),
                             proxy.getDbName() }), Thread.currentThread()
                         .hashCode());
-        isAliSource = proxy.isA(DBRefSource.ALIGNMENTDB);
+        isAliSource = proxy.isAlignmentSource();
         if (proxy.getAccessionSeparator() == null)
         {
           while (en.hasNext())
@@ -639,34 +637,19 @@ public class SequenceFetcher extends JPanel implements Runnable
                 DBRefEntry dbr = new DBRefEntry(), found[] = null;
                 dbr.setSource(proxy.getDbSource());
                 dbr.setVersion(null);
-                if (proxy.getAccessionValidator() != null)
-                {
-                  Regex vgr = proxy.getAccessionValidator();
-                  vgr.search(q);
-                  if (vgr.numSubs() > 0)
-                  {
-                    dbr.setAccessionId(vgr.stringMatched(1));
-                  }
-                  else
-                  {
-                    dbr.setAccessionId(vgr.stringMatched());
-                  }
-                }
-                else
-                {
-                  dbr.setAccessionId(q);
-                }
+                String accId = proxy.getAccessionIdFromQuery(q);
+                dbr.setAccessionId(accId);
                 boolean rfound = false;
                 for (int r = 0; r < rs.length; r++)
                 {
-                  if (rs[r] != null
-                          && (found = DBRefUtils.searchRefs(
-                                  rs[r].getDBRef(), dbr)) != null
-                          && found.length > 0)
+                  if (rs[r] != null)
                   {
-                    rfound = true;
-                    rs[r] = null;
-                    continue;
+                    found = DBRefUtils.searchRefs(rs[r].getDBRefs(), accId);
+                    if (found != null && found.length > 0)
+                    {
+                      rfound = true;
+                      rs[r] = null;
+                    }
                   }
                 }
                 if (!rfound)
@@ -790,7 +773,7 @@ public class SequenceFetcher extends JPanel implements Runnable
 
   AlignmentI parseResult(String result, String title)
   {
-    String format = new IdentifyFile().Identify(result, "Paste");
+    String format = new IdentifyFile().identify(result, "Paste");
     AlignmentI sequences = null;
     if (FormatAdapter.isValidFormat(format))
     {