Clover icon

Coverage Report

  1. Project Clover database Mon Sep 2 2024 17:57:51 BST
  2. Package jalview.ws.jws2.jabaws2

File Jws2Instance.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
21% of files have more coverage

Code metrics

28
47
12
1
254
165
30
0.64
3.92
12
2.5

Classes

Class Line # Actions
Jws2Instance 41 47 30
0.7701149677%
 

Contributing tests

This file is covered by 268 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.jws2.jabaws2;
22   
23    import jalview.gui.AlignFrame;
24    import jalview.gui.Desktop;
25    import jalview.util.MessageManager;
26    import jalview.ws.jws2.JabaParamStore;
27    import jalview.ws.jws2.MsaWSClient;
28    import jalview.ws.jws2.SequenceAnnotationWSClient;
29    import jalview.ws.params.ParamDatastoreI;
30   
31    import java.io.Closeable;
32   
33    import javax.swing.JMenu;
34   
35    import compbio.data.msa.JABAService;
36    import compbio.data.msa.MsaWS;
37    import compbio.data.msa.SequenceAnnotation;
38    import compbio.metadata.PresetManager;
39    import compbio.metadata.RunnerConfig;
40   
 
41    public class Jws2Instance implements AutoCloseable
42    {
43    public String hosturl;
44   
45    public String serviceType;
46   
47    public String action;
48   
49    public JABAService service;
50   
51    public String description;
52   
53    public String docUrl;
54   
55    /**
56    *
57    * @param hosturl
58    * Service endpoint
59    * @param serviceType
60    * Category for this service's analysis
61    * @param action
62    * text describing their action that service performs (eg 'aligning',
63    * 'analysing')
64    * @param description
65    * Description from JABAWS registry
66    * @param service
67    * JABAWS registry ID for service
68    */
 
69  721 toggle public Jws2Instance(String hosturl, String serviceType, String action,
70    String description, JABAService service)
71    {
72  721 super();
73  721 this.hosturl = hosturl;
74  721 this.serviceType = serviceType;
75  721 this.service = service;
76  721 this.action = action;
77  721 this.description = description;
78  721 int p = description.indexOf("MORE INFORMATION:");
79  721 if (p > -1)
80    {
81  721 docUrl = description.substring(description.indexOf("http", p)).trim();
82  721 if (docUrl.indexOf('\n') > -1)
83    {
84  0 docUrl = docUrl.substring(0, docUrl.indexOf("\n")).trim();
85    }
86   
87    }
88    }
89   
90    PresetManager presets = null;
91   
92    public JabaParamStore paramStore = null;
93   
94    /**
95    * non thread safe - gets the presets for this service (blocks whilst it calls
96    * the service to get the preset set)
97    *
98    * @return service presets or null if exceptions were raised.
99    */
 
100  721 toggle public PresetManager getPresets()
101    {
102  721 if (presets == null)
103    {
104  721 try
105    {
106  721 if (service instanceof MsaWS<?>)
107    {
108  470 presets = ((MsaWS) service).getPresets();
109   
110    }
111  721 if (service instanceof SequenceAnnotation<?>)
112    {
113  251 presets = ((SequenceAnnotation) service).getPresets();
114    }
115    } catch (Exception ex)
116    {
117  0 jalview.bin.Console
118    .errPrintln("Exception when retrieving presets for service "
119    + serviceType + " at " + hosturl);
120    }
121    }
122  721 return presets;
123    }
124   
 
125  16869 toggle public String getHost()
126    {
127  16869 return hosturl;
128    /*
129    * try { URL serviceurl = new URL(hosturl); if (serviceurl.getPort()!=80) {
130    * return serviceurl.getHost()+":"+serviceurl.getPort(); } return
131    * serviceurl.getHost(); } catch (Exception e) {
132    * jalview.bin.Console.errPrintln("Failed to parse service URL '" + hosturl +
133    * "' as a valid URL!"); } return null;
134    */
135    }
136   
137    /**
138    * @return short description of what the service will do
139    */
 
140  34741 toggle public String getActionText()
141    {
142  34741 return action + " with " + serviceType;
143    }
144   
145    /**
146    * non-thread safe - blocks whilst accessing service to get complete set of
147    * available options and parameters
148    *
149    * @return
150    */
 
151  1442 toggle public RunnerConfig getRunnerConfig()
152    {
153  1442 if (service instanceof MsaWS<?>)
154    {
155  940 return ((MsaWS) service).getRunnerOptions();
156    }
157  502 if (service instanceof SequenceAnnotation<?>)
158    {
159  502 return ((SequenceAnnotation) service).getRunnerOptions();
160    }
161  0 throw new Error(MessageManager.formatMessage(
162    "error.implementation_error_runner_config_not_available",
163    new String[]
164    { serviceType, service.getClass().toString() }));
165    }
166   
 
167  0 toggle @Override
168    public void close()
169    {
170  0 if (service != null)
171    {
172  0 try
173    {
174  0 ((Closeable) service).close();
175    } catch (Throwable t)
176    {
177    // ignore
178    }
179    }
180    // super.finalize();
181    }
182   
 
183  12083 toggle public ParamDatastoreI getParamStore()
184    {
185  12083 if (paramStore == null)
186    {
187  721 try
188    {
189  721 paramStore = new JabaParamStore(this,
190  721 (Desktop.instance != null ? Desktop.getUserParameterStore()
191    : null));
192    } catch (Exception ex)
193    {
194  0 jalview.bin.Console.errPrintln(
195    "Unexpected exception creating JabaParamStore.");
196  0 ex.printStackTrace();
197    }
198   
199    }
200  12083 return paramStore;
201    }
202   
 
203  1442 toggle public String getUri()
204    {
205    // this is only valid for Jaba 1.0 - this formula might have to change!
206  1442 return hosturl
207  1442 + (hosturl.lastIndexOf("/") == (hosturl.length() - 1) ? ""
208    : "/")
209    + serviceType;
210    }
211   
212    private boolean hasParams = false, lookedForParams = false;
213   
 
214  12938 toggle public boolean hasParameters()
215    {
216  12938 if (!lookedForParams)
217    {
218  721 lookedForParams = true;
219  721 try
220    {
221  721 hasParams = (getRunnerConfig().getArguments().size() > 0);
222    } catch (Exception e)
223    {
224   
225    }
226    }
227  12938 return hasParams;
228    }
229   
 
230  14189 toggle public void attachWSMenuEntry(JMenu atpoint, AlignFrame alignFrame)
231    {
232  14189 if (service instanceof MsaWS<?>)
233    {
234  8325 new MsaWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
235    }
236  5864 else if (service instanceof SequenceAnnotation<?>)
237    {
238  5864 new SequenceAnnotationWSClient().attachWSMenuEntry(atpoint, this,
239    alignFrame);
240    }
241    }
242   
 
243  0 toggle public String getServiceTypeURI()
244    {
245  0 return "java:" + serviceType;
246    }
247   
248    jalview.ws.uimodel.AlignAnalysisUIText aaui;
249   
 
250  14189 toggle public jalview.ws.uimodel.AlignAnalysisUIText getAlignAnalysisUI()
251    {
252  14189 return aaui;
253    }
254    }