Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 16:11:35 GMT
  2. Package jalview.ws.params

File AutoCalcSetting.java

 

Coverage histogram

../../../img/srcFileCovDistChart0.png
60% of files have more coverage

Code metrics

14
39
11
1
190
111
20
0.51
3.55
11
1.82

Classes

Class Line # Actions
AutoCalcSetting 29 39 20
0.00%
 

Contributing tests

No tests hitting this source file were found.

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.params;
22   
23    import jalview.util.MessageManager;
24    import jalview.ws.api.ServiceWithParameters;
25   
26    import java.util.ArrayList;
27    import java.util.List;
28   
 
29    public class AutoCalcSetting
30    {
31   
32    protected boolean autoUpdate;
33   
34    protected WsParamSetI preset;
35   
36    protected List<ArgumentI> jobArgset;
37   
38    protected ServiceWithParameters service;
39   
 
40  0 toggle public AutoCalcSetting(ServiceWithParameters service2,
41    WsParamSetI preset2, List<ArgumentI> jobArgset2,
42    boolean autoUpdate2)
43    {
44  0 service = service2;
45  0 autoUpdate = autoUpdate2;
46  0 preset = preset2;
47  0 jobArgset = jobArgset2;
48    }
49   
 
50  0 toggle public boolean isAutoUpdate()
51    {
52  0 return autoUpdate;
53    }
54   
 
55  0 toggle public void setAutoUpdate(boolean autoUpdate)
56    {
57  0 this.autoUpdate = autoUpdate;
58    }
59   
 
60  0 toggle public WsParamSetI getPreset()
61    {
62  0 return preset;
63    }
64   
 
65  0 toggle public void setPreset(WsParamSetI preset)
66    {
67    // TODO: test if service URL is in presets
68  0 this.preset = preset;
69    }
70   
 
71  0 toggle public List<ArgumentI> getArgumentSet()
72    {
73  0 return jobArgset;
74    }
75   
76    /**
77    * TODO: refactor to ServiceWithParameters ?
78    *
79    * @return characteristic URI for this service. The URI should reflect the
80    * type and version of this service, enabling the service client code
81    * to recover the correct client for this calculation.
82    */
 
83  0 toggle public String getServiceURI()
84    {
85  0 return service.getNameURI();
86    }
87   
88    /**
89    * TODO: refactor to ServiceWithParameters ?
90    *
91    * return any concrete service endpoints associated with this calculation.
92    * built in services should return a zero length array
93    *
94    * @return
95    */
 
96  0 toggle public String[] getServiceURLs()
97    {
98  0 return new String[] { service.getUri() };
99    }
100   
101    /**
102    * default WsParamFile generator method - clients with custom formats should
103    * override and implement their own
104    *
105    * @return stringified representation of the parameters for this setting
106    */
 
107  0 toggle public String getWsParamFile()
108    {
109  0 List<ArgumentI> opts = null;
110  0 if (jobArgset != null)
111    {
112  0 opts = jobArgset;
113    }
114    else
115    {
116  0 if (preset != null)
117    {
118  0 opts = preset.getArguments();
119    }
120    }
121  0 if (opts == null || opts.size() == 0)
122    {
123  0 return "";
124    }
125  0 StringBuffer pset = new StringBuffer();
126  0 for (ArgumentI ps : opts)
127    {
128  0 pset.append(ps.getName() + "\t" + ps.getValue());
129  0 pset.append("\n");
130    }
131  0 return pset.toString();
132    }
 
133  0 toggle public ServiceWithParameters getService()
134    {
135  0 return service;
136    }
137   
 
138  0 toggle public void setService(ServiceWithParameters service)
139    {
140  0 this.service = service;
141  0 if (preset != null)
142    {
143    // check if we need to migrate preset to a new service URL
144  0 for (String url : preset.getApplicableUrls())
145    {
146  0 if (url.equals(service.getUri()))
147    {
148    // preset already verified
149  0 return;
150    }
151    }
152  0 WsParamSetI pr = service.getParamStore().getPreset(preset.getName());
153   
154    // TODO: decide of this distinction between preset and args are needed.
155    //
156    // if (pr instanceof JabaPreset && preset instanceof JabaPreset)
157    // {
158    // // easy - Presets are identical (we assume)
159    // preset = pr;
160    // return;
161    // }
162   
163    // this verifies that all arguments in the existing preset are the same as
164    // the parameters for the preset provided by the service parameter store.
165    // ie the LastUsed settings or a predefined preset.
166   
167  0 List<ArgumentI> oldargs = new ArrayList<>(),
168    newargs = new ArrayList<>();
169  0 oldargs.addAll(preset.getArguments());
170    // need to compare parameters
171  0 for (ArgumentI newparg : pr.getArguments())
172    {
173  0 if (!oldargs.remove(newparg))
174    {
175  0 newargs.add(newparg);
176    }
177    }
178  0 if (oldargs.size() == 0 && newargs.size() == 0)
179    {
180    // exact match.
181  0 preset = pr;
182  0 return;
183    }
184    // Try even harder to migrate arguments.
185  0 throw new Error(MessageManager
186    .getString("error.parameter_migration_not_implemented_yet"));
187    }
188    }
189   
190    }