Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 20:42:03 GMT
  2. Package jalview.ws.jws1

File SeqSearchWSClient.java

 

Coverage histogram

../../../img/srcFileCovDistChart1.png
56% of files have more coverage

Code metrics

38
85
12
1
339
235
36
0.42
7.08
12
3

Classes

Class Line # Actions
SeqSearchWSClient 53 85 36
0.029629633%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.ws.jws1;
22   
23    import jalview.bin.Console;
24    import jalview.datamodel.AlignmentI;
25    import jalview.datamodel.AlignmentView;
26    import jalview.gui.AlignFrame;
27    import jalview.gui.Desktop;
28    import jalview.gui.JvOptionPane;
29    import jalview.gui.WebserviceInfo;
30    import jalview.util.MessageManager;
31   
32    import java.awt.Component;
33    import java.awt.event.ActionEvent;
34    import java.awt.event.ActionListener;
35    import java.util.Enumeration;
36    import java.util.Hashtable;
37    import java.util.StringTokenizer;
38    import java.util.Vector;
39   
40    import javax.swing.JMenu;
41    import javax.swing.JMenuItem;
42   
43    import ext.vamsas.SeqSearchServiceLocator;
44    import ext.vamsas.SeqSearchServiceSoapBindingStub;
45    import ext.vamsas.ServiceHandle;
46   
47    /**
48    * DOCUMENT ME!
49    *
50    * @author $author$
51    * @version $Revision$
52    */
 
53    public class SeqSearchWSClient extends WS1Client
54    {
55    /**
56    * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
57    */
58    ext.vamsas.SeqSearchI server;
59   
60    AlignFrame alignFrame;
61   
62    /**
63    * Creates a new MsaWSClient object that uses a service given by an externally
64    * retrieved ServiceHandle
65    *
66    * @param sh
67    * service handle of type AbstractName(MsaWS)
68    * @param altitle
69    * DOCUMENT ME!
70    * @param msa
71    * DOCUMENT ME!
72    * @param submitGaps
73    * DOCUMENT ME!
74    * @param preserveOrder
75    * DOCUMENT ME!
76    */
77   
 
78  0 toggle public SeqSearchWSClient(ext.vamsas.ServiceHandle sh, String altitle,
79    jalview.datamodel.AlignmentView msa, String db,
80    AlignmentI seqdataset, AlignFrame _alignFrame)
81    {
82  0 super();
83  0 alignFrame = _alignFrame;
84    // can generalise the two errors below for metadata mapping from interface
85    // name to service client name
86  0 if (!sh.getAbstractName().equals(this.getServiceActionKey()))
87    {
88  0 JvOptionPane.showMessageDialog(Desktop.desktop,
89    MessageManager.formatMessage(
90    "label.service_called_is_not_seq_search_service",
91    new String[]
92    { sh.getName() }),
93    MessageManager.getString("label.internal_jalview_error"),
94    JvOptionPane.WARNING_MESSAGE);
95   
96  0 return;
97    }
98   
99  0 if ((wsInfo = setWebService(sh)) == null)
100    {
101  0 JvOptionPane.showMessageDialog(Desktop.desktop,
102    MessageManager.formatMessage(
103    "label.seq_search_service_is_unknown", new String[]
104    { sh.getName() }),
105    MessageManager.getString("label.internal_jalview_error"),
106    JvOptionPane.WARNING_MESSAGE);
107   
108  0 return;
109    }
110  0 startSeqSearchClient(altitle, msa, db, seqdataset);
111   
112    }
113   
114    /**
115    * non-process web service interaction - use this for calling HEADLESS
116    * synchronous service methods
117    *
118    * @param sh
119    */
 
120  0 toggle public SeqSearchWSClient(ServiceHandle sh)
121    {
122  0 setWebService(sh, true);
123    }
124   
 
125  6 toggle public SeqSearchWSClient()
126    {
127   
128  6 super();
129    // add a class reference to the list
130    }
131   
 
132  0 toggle private void startSeqSearchClient(String altitle, AlignmentView msa,
133    String db, AlignmentI seqdataset)
134    {
135  0 if (!locateWebService())
136    {
137  0 return;
138    }
139  0 String visdb = (db == null || db == "") ? "default" : db; // need a visible
140    // name for a
141    // sequence db
142  0 boolean profileSearch = msa.getSequences().length > 2 ? true : false;
143    // single sequence or profile from alignment view
144  0 wsInfo.setProgressText("Searching " + visdb
145  0 + (!profileSearch
146    ? " with sequence "
147    + msa.getSequences()[0].getRefSeq().getName()
148    : " with profile")
149    + " from " + altitle + "\nJob details\n");
150   
151  0 String jobtitle = WebServiceName
152  0 + ((WebServiceName.indexOf("earch") > -1) ? " " : " search ")
153    + " of " + visdb
154  0 + (!profileSearch
155    ? " with sequence "
156    + msa.getSequences()[0].getRefSeq().getName()
157    : " with profile")
158    + " from " + altitle;
159  0 SeqSearchWSThread ssthread = new SeqSearchWSThread(server, WsURL,
160    wsInfo, alignFrame, WebServiceName, jobtitle, msa, db,
161    seqdataset);
162  0 wsInfo.setthisService(ssthread);
163  0 ssthread.start();
164    }
165   
166    /**
167    * Initializes the server field with a valid service implementation.
168    *
169    * @return true if service was located.
170    */
 
171  0 toggle private boolean locateWebService()
172    {
173    // this can be abstracted using reflection
174    // TODO: MuscleWS transmuted to generic MsaWS client
175  0 SeqSearchServiceLocator loc = new SeqSearchServiceLocator(); // Default
176   
177  0 try
178    {
179  0 this.server = loc.getSeqSearchService(new java.net.URL(WsURL));
180  0 ((SeqSearchServiceSoapBindingStub) this.server).setTimeout(60000); // One
181    // minute
182    // timeout
183    } catch (Exception ex)
184    {
185  0 wsInfo.setProgressText("Serious! " + WebServiceName
186    + " Service location failed\nfor URL :" + WsURL + "\n"
187    + ex.getMessage());
188  0 wsInfo.setStatus(WebserviceInfo.ERROR);
189  0 ex.printStackTrace();
190   
191  0 return false;
192    }
193   
194  0 loc.getEngine().setOption("axis", "1");
195   
196  0 return true;
197    }
198   
 
199  0 toggle protected String getServiceActionKey()
200    {
201  0 return "SeqSearch";
202    }
203   
 
204  0 toggle protected String getServiceActionDescription()
205    {
206  0 return "Sequence Database Search";
207    }
208   
209    // simple caching of db parameters for each service endpoint
210    private static Hashtable dbParamsForEndpoint;
 
211  6 toggle static
212    {
213  6 dbParamsForEndpoint = new Hashtable();
214    }
215   
 
216  0 toggle public String[] getSupportedDatabases() throws Exception
217    {
218   
219    // check that we haven't already been to this service endpoint
220  0 if (dbParamsForEndpoint.containsKey(WsURL))
221    {
222  0 return (String[]) dbParamsForEndpoint.get(WsURL);
223    }
224  0 if (!locateWebService())
225    {
226  0 throw new Exception(MessageManager.formatMessage(
227    "exception.cannot_contact_service_endpoint_at", new String[]
228    { WsURL }));
229    }
230  0 String database = server.getDatabase();
231  0 if (database == null)
232    {
233  0 dbParamsForEndpoint.put(WsURL, new String[] {});
234  0 return null;
235    }
236  0 StringTokenizer en = new StringTokenizer(database.trim(), ",| ");
237  0 String[] dbs = new String[en.countTokens()];
238  0 for (int i = 0; i < dbs.length; i++)
239    {
240  0 dbs[i++] = en.nextToken().trim();
241    }
242  0 dbParamsForEndpoint.put(WsURL, dbs);
243  0 return dbs;
244    }
245   
 
246  0 toggle @Override
247    public void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle sh,
248    final AlignFrame af)
249    {
250    // look for existing database service submenus on wsmenu
251  0 Hashtable dbsrchs = new Hashtable();
252  0 Vector newdbsrch = new Vector();
253  0 Component entries[] = wsmenu.getComponents();
254  0 for (int i = 0; entries != null && i < entries.length; i++)
255    {
256  0 if (entries[i] instanceof JMenu)
257    {
258  0 dbsrchs.put(entries[i].getName(), entries[i]);
259    }
260    }
261  0 JMenu defmenu = (JMenu) dbsrchs.get("Default Database");
262  0 if (defmenu == null)
263    {
264  0 dbsrchs.put("Default Database",
265    defmenu = new JMenu("Default Database"));
266  0 newdbsrch.addElement(defmenu);
267    }
268   
269  0 String dbs[] = null;
270  0 try
271    {
272  0 dbs = new jalview.ws.jws1.SeqSearchWSClient(sh)
273    .getSupportedDatabases();
274    } catch (Exception e)
275    {
276  0 Console.warn(
277    "Database list request failed, so disabling SeqSearch Service client "
278    + sh.getName() + " at " + sh.getEndpointURL(),
279    e);
280  0 return;
281    }
282  0 JMenuItem method;
283    // do default entry
284  0 defmenu.add(method = new JMenuItem(sh.getName()));
285  0 method.setToolTipText(sh.getEndpointURL());
286  0 method.addActionListener(new ActionListener()
287    {
 
288  0 toggle @Override
289    public void actionPerformed(ActionEvent e)
290    {
291    // use same input gatherer as for secondary structure prediction
292    // we could actually parameterise the gatherer method here...
293  0 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
294  0 new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa, null,
295    af.getViewport().getAlignment().getDataset(), af);
296    }
297    });
298    // add entry for each database the service supports
299  0 for (int db = 0; dbs != null && db < dbs.length; db++)
300    {
301  0 JMenu dbmenu = (JMenu) dbsrchs.get(dbs[db]);
302  0 if (dbmenu == null)
303    {
304  0 dbsrchs.put(dbs[db], dbmenu = new JMenu(dbs[db]));
305  0 newdbsrch.addElement(dbmenu);
306    }
307    // add the client handler code for this service
308  0 dbmenu.add(method = new JMenuItem(sh.getName()));
309  0 method.setToolTipText(sh.getEndpointURL());
310  0 final String searchdb = dbs[db];
311  0 method.addActionListener(new ActionListener()
312    {
 
313  0 toggle @Override
314    public void actionPerformed(ActionEvent e)
315    {
316  0 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
317  0 new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa,
318    searchdb, af.getViewport().getAlignment().getDataset(),
319    af);
320    }
321    });
322    }
323    // add the databases onto the seqsearch menu
324  0 Enumeration e = newdbsrch.elements();
325  0 while (e.hasMoreElements())
326    {
327  0 Object el = e.nextElement();
328  0 if (el instanceof JMenu)
329    {
330  0 wsmenu.add((JMenu) el);
331    }
332    else
333    {
334  0 wsmenu.add((JMenuItem) el);
335    }
336    }
337   
338    }
339    }