Clover icon

Coverage Report

  1. Project Clover database Wed Dec 3 2025 17:03:17 GMT
  2. Package jalview.ws.jws2.jabaws2

File Jws2Instance.java

 

Coverage histogram

../../../../img/srcFileCovDistChart6.png
37% of files have more coverage

Code metrics

40
56
8
1
272
189
34
0.61
7
8
4.25

Classes

Class Line # Actions
Jws2Instance 40 56 34
0.576923157.7%
 

Contributing tests

This file is covered by 281 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.Desktop;
24    import jalview.util.MessageManager;
25    import jalview.ws.api.JalviewServiceEndpointProviderI;
26    import jalview.ws.api.ServiceWithParameters;
27    import jalview.ws.jws2.JabaParamStore;
28    import jalview.ws.params.ParamDatastoreI;
29    import jalview.ws.params.ParamManager;
30   
31    import java.io.Closeable;
32    import java.net.URL;
33   
34    import compbio.data.msa.JABAService;
35    import compbio.data.msa.MsaWS;
36    import compbio.data.msa.SequenceAnnotation;
37    import compbio.metadata.PresetManager;
38    import compbio.metadata.RunnerConfig;
39   
 
40    public class Jws2Instance extends ServiceWithParameters
41    implements JalviewServiceEndpointProviderI, AutoCloseable
42    {
43   
44    public JABAService service;
45   
46    /**
47    *
48    * @param hosturl
49    * Service endpoint
50    * @param serviceType
51    * Category for this service's analysis
52    * @param action
53    * text describing their action that service performs (eg 'aligning',
54    * 'analysing')
55    * @param description
56    * Description from JABAWS registry
57    * @param service
58    * JABAWS registry ID for service
59    */
 
60  550 toggle public Jws2Instance(String hosturl, String serviceType, String action,
61    String description, JABAService service)
62    {
63  550 super(action, action, serviceType, description, hosturl);
64  550 this.service = service;
65  550 if (service instanceof MsaWS<?>)
66    {
67  386 style = ServiceClient.MSAWSCLIENT;
68    }
69  164 else if (service instanceof SequenceAnnotation<?>)
70    {
71  164 style = ServiceClient.SEQUENCEANNOTATIONWSCLIENT;
72    }
73   
74  550 int p = description.indexOf("MORE INFORMATION:");
75  550 if (p > -1)
76    {
77  550 String docUrl = description.substring(description.indexOf("http", p))
78    .trim();
79  550 if (docUrl.indexOf('\n') > -1)
80    {
81  0 docUrl = docUrl.substring(0, docUrl.indexOf("\n")).trim();
82    }
83  550 if (docUrl.length() > 0)
84    {
85  550 try
86    {
87  550 URL url = new URL(docUrl);
88  550 if (url != null)
89    {
90  550 setDocumentationUrl(docUrl);
91    }
92    } catch (Exception x)
93    {
94   
95    }
96    }
97   
98    }
99    }
100   
101    PresetManager presets = null;
102   
103    public JabaParamStore paramStore = null;
104   
105    /**
106    * non thread safe - gets the presets for this service (blocks whilst it calls
107    * the service to get the preset set)
108    *
109    * @return service presets or null if exceptions were raised.
110    */
 
111  549 toggle public PresetManager getPresets()
112    {
113  549 if (presets == null)
114    {
115  549 try
116    {
117  549 if (service instanceof MsaWS<?>)
118    {
119  385 presets = ((MsaWS) service).getPresets();
120   
121    }
122  549 if (service instanceof SequenceAnnotation<?>)
123    {
124  164 presets = ((SequenceAnnotation) service).getPresets();
125    }
126    } catch (Exception ex)
127    {
128  0 jalview.bin.Console
129    .errPrintln("Exception when retrieving presets for service "
130    + getServiceType() + " at " + getHostURL());
131    }
132    }
133  549 return presets;
134    }
135   
136    /**
137    * non-thread safe - blocks whilst accessing service to get complete set of
138    * available options and parameters
139    *
140    * @return
141    */
 
142  1099 toggle public RunnerConfig getRunnerConfig()
143    {
144  1099 if (service instanceof MsaWS<?>)
145    {
146  771 return ((MsaWS) service).getRunnerOptions();
147    }
148  328 if (service instanceof SequenceAnnotation<?>)
149    {
150  328 return ((SequenceAnnotation) service).getRunnerOptions();
151    }
152  0 throw new Error(MessageManager.formatMessage(
153    "error.implementation_error_runner_config_not_available",
154    new String[]
155    { getServiceType(), service.getClass().toString() }));
156    }
157   
 
158  0 toggle @Override
159    public void close()
160    {
161  0 if (service != null)
162    {
163  0 try
164    {
165  0 ((Closeable) service).close();
166    } catch (Throwable t)
167    {
168    // ignore
169    }
170    }
171    // super.finalize();
172    }
173   
 
174  21891 toggle @Override
175    public ParamDatastoreI getParamStore()
176    {
177  21891 if (paramStore == null)
178    {
179  550 try
180    {
181  550 paramStore = new JabaParamStore(this,
182  550 (Desktop.getInstance() != null ? Desktop.getUserParameterStore()
183    : null));
184    } catch (Exception ex)
185    {
186  0 jalview.bin.Console.errPrintln(
187    "Unexpected exception creating JabaParamStore.");
188  0 ex.printStackTrace();
189    }
190   
191    }
192  21890 return paramStore;
193    }
194   
195    private boolean hasParams = false, lookedForParams = false;
196   
 
197  21677 toggle @Override
198    public boolean hasParameters()
199    {
200  21677 if (!lookedForParams)
201    {
202  549 lookedForParams = true;
203  549 try
204    {
205  549 hasParams = (getRunnerConfig().getArguments().size() > 0);
206    } catch (Exception e)
207    {
208   
209    }
210    }
211  21677 return hasParams;
212    }
213   
214    /**
215    * initialise a parameter store for this service
216    *
217    * @param userParameterStore
218    * - the user ParamManager (e.g. Desktop.getUserParameterStore() )
219    */
 
220  0 toggle @Override
221    public void initParamStore(ParamManager userParameterStore)
222    {
223  0 if (paramStore == null)
224    {
225  0 paramStore = new JabaParamStore(this, userParameterStore);
226    }
227    }
228   
229    /**
230    * an object that implements one or more interfaces in jalview.ws.api
231    *
232    * @return
233    */
 
234  0 toggle @Override
235    public Object getEndpoint()
236    {
237  0 if (service instanceof MsaWS<?>)
238    {
239  0 if (aaui != null)
240    {
241  0 throw new Error(
242    "JABAWS MsaWS based instant calculation not implemented.");
243   
244    }
245    else
246    {
247  0 return new JabawsMsaInstance(this);
248    }
249    }
250    else
251    {
252  0 if (service instanceof compbio.data.msa.SequenceAnnotation)
253    {
254  0 if (aaui != null)
255    {
256  0 try
257    {
258    // probably a factory would be nicer but..
259  0 return aaui.getClient().getConstructor(getClass())
260    .newInstance(this);
261    } catch (Throwable t)
262    {
263  0 throw new Error("Implementation Error in web service framework",
264    t);
265    }
266    }
267  0 return new AADisorderClient(this);
268    }
269  0 return null;
270    }
271    }
272    }