Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.ws.jws2.jabaws2

File Jws2Instance.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
12% of files have more coverage

Code metrics

28
48
12
1
252
164
30
0.62
4
12
2.5

Classes

Class Line # Actions
Jws2Instance 41 48 30 15
0.8295454483%
 

Contributing tests

This file is covered by 133 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
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  132 toggle public Jws2Instance(String hosturl, String serviceType, String action,
70    String description, JABAService service)
71    {
72  132 super();
73  132 this.hosturl = hosturl;
74  132 this.serviceType = serviceType;
75  132 this.service = service;
76  132 this.action = action;
77  132 this.description = description;
78  132 int p = description.indexOf("MORE INFORMATION:");
79  132 if (p > -1)
80    {
81  132 docUrl = description.substring(description.indexOf("http", p)).trim();
82  132 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  132 toggle public PresetManager getPresets()
101    {
102  132 if (presets == null)
103    {
104  132 try
105    {
106  132 if (service instanceof MsaWS<?>)
107    {
108  78 presets = ((MsaWS) service).getPresets();
109   
110    }
111  132 if (service instanceof SequenceAnnotation<?>)
112    {
113  54 presets = ((SequenceAnnotation) service).getPresets();
114    }
115    } catch (Exception ex)
116    {
117  0 System.err.println("Exception when retrieving presets for service "
118    + serviceType + " at " + hosturl);
119    }
120    }
121  132 return presets;
122    }
123   
 
124  7688 toggle public String getHost()
125    {
126  7688 return hosturl;
127    /*
128    * try { URL serviceurl = new URL(hosturl); if (serviceurl.getPort()!=80) {
129    * return serviceurl.getHost()+":"+serviceurl.getPort(); } return
130    * serviceurl.getHost(); } catch (Exception e) {
131    * System.err.println("Failed to parse service URL '" + hosturl +
132    * "' as a valid URL!"); } return null;
133    */
134    }
135   
136    /**
137    * @return short description of what the service will do
138    */
 
139  15884 toggle public String getActionText()
140    {
141  15884 return action + " with " + serviceType;
142    }
143   
144    /**
145    * non-thread safe - blocks whilst accessing service to get complete set of
146    * available options and parameters
147    *
148    * @return
149    */
 
150  264 toggle public RunnerConfig getRunnerConfig()
151    {
152  264 if (service instanceof MsaWS<?>)
153    {
154  156 return ((MsaWS) service).getRunnerOptions();
155    }
156  108 if (service instanceof SequenceAnnotation<?>)
157    {
158  108 return ((SequenceAnnotation) service).getRunnerOptions();
159    }
160  0 throw new Error(MessageManager.formatMessage(
161    "error.implementation_error_runner_config_not_available",
162    new String[]
163    { serviceType, service.getClass().toString() }));
164    }
165   
 
166  90 toggle @Override
167    protected void finalize() throws Throwable
168    {
169  90 if (service != null)
170    {
171  90 try
172    {
173  90 ((Closeable) service).close();
174    } catch (Throwable t)
175    {
176    // ignore
177    }
178    }
179  90 super.finalize();
180    }
181   
 
182  5266 toggle public ParamDatastoreI getParamStore()
183    {
184  5266 if (paramStore == null)
185    {
186  132 try
187    {
188  132 paramStore = new JabaParamStore(this,
189  132 (Desktop.instance != null ? Desktop.getUserParameterStore()
190    : null));
191    } catch (Exception ex)
192    {
193  0 System.err.println("Unexpected exception creating JabaParamStore.");
194  0 ex.printStackTrace();
195    }
196   
197    }
198  5266 return paramStore;
199    }
200   
 
201  264 toggle public String getUri()
202    {
203    // this is only valid for Jaba 1.0 - this formula might have to change!
204  264 return hosturl
205  264 + (hosturl.lastIndexOf("/") == (hosturl.length() - 1) ? ""
206    : "/")
207    + serviceType;
208    }
209   
210    private boolean hasParams = false, lookedForParams = false;
211   
 
212  5732 toggle public boolean hasParameters()
213    {
214  5732 if (!lookedForParams)
215    {
216  132 lookedForParams = true;
217  132 try
218    {
219  132 hasParams = (getRunnerConfig().getArguments().size() > 0);
220    } catch (Exception e)
221    {
222   
223    }
224    }
225  5732 return hasParams;
226    }
227   
 
228  6540 toggle public void attachWSMenuEntry(JMenu atpoint, AlignFrame alignFrame)
229    {
230  6540 if (service instanceof MsaWS<?>)
231    {
232  3736 new MsaWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
233    }
234  2804 else if (service instanceof SequenceAnnotation<?>)
235    {
236  2804 new SequenceAnnotationWSClient().attachWSMenuEntry(atpoint, this,
237    alignFrame);
238    }
239    }
240   
 
241  0 toggle public String getServiceTypeURI()
242    {
243  0 return "java:" + serviceType;
244    }
245   
246    jalview.ws.uimodel.AlignAnalysisUIText aaui;
247   
 
248  6540 toggle public jalview.ws.uimodel.AlignAnalysisUIText getAlignAnalysisUI()
249    {
250  6540 return aaui;
251    }
252    }