2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.ws.params;
23 import jalview.util.MessageManager;
24 import jalview.ws.api.ServiceWithParameters;
26 import java.util.ArrayList;
27 import java.util.List;
29 public class AutoCalcSetting
32 protected boolean autoUpdate;
34 protected WsParamSetI preset;
36 protected List<ArgumentI> jobArgset;
38 protected ServiceWithParameters service;
40 public AutoCalcSetting(ServiceWithParameters service2,
41 WsParamSetI preset2, List<ArgumentI> jobArgset2,
45 autoUpdate = autoUpdate2;
47 jobArgset = jobArgset2;
50 public boolean isAutoUpdate()
55 public void setAutoUpdate(boolean autoUpdate)
57 this.autoUpdate = autoUpdate;
60 public WsParamSetI getPreset()
65 public void setPreset(WsParamSetI preset)
67 // TODO: test if service URL is in presets
71 public List<ArgumentI> getArgumentSet()
77 * TODO: refactor to ServiceWithParameters ?
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.
83 public String getServiceURI()
85 return service.getNameURI();
89 * TODO: refactor to ServiceWithParameters ?
91 * return any concrete service endpoints associated with this calculation.
92 * built in services should return a zero length array
96 public String[] getServiceURLs()
98 return new String[] { service.getUri() };
102 * default WsParamFile generator method - clients with custom formats should
103 * override and implement their own
105 * @return stringified representation of the parameters for this setting
107 public String getWsParamFile()
109 List<ArgumentI> opts = null;
110 if (jobArgset != null)
118 opts = preset.getArguments();
121 if (opts == null || opts.size() == 0)
125 StringBuffer pset = new StringBuffer();
126 for (ArgumentI ps : opts)
128 pset.append(ps.getName() + "\t" + ps.getValue());
131 return pset.toString();
133 public ServiceWithParameters getService()
138 public void setService(ServiceWithParameters service)
140 this.service = service;
143 // check if we need to migrate preset to a new service URL
144 for (String url : preset.getApplicableUrls())
146 if (url.equals(service.getUri()))
148 // preset already verified
152 WsParamSetI pr = service.getParamStore().getPreset(preset.getName());
154 // TODO: decide of this distinction between preset and args are needed.
156 // if (pr instanceof JabaPreset && preset instanceof JabaPreset)
158 // // easy - Presets are identical (we assume)
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.
167 List<ArgumentI> oldargs = new ArrayList<>(),
168 newargs = new ArrayList<>();
169 oldargs.addAll(preset.getArguments());
170 // need to compare parameters
171 for (ArgumentI newparg : pr.getArguments())
173 if (!oldargs.remove(newparg))
175 newargs.add(newparg);
178 if (oldargs.size() == 0 && newargs.size() == 0)
184 // Try even harder to migrate arguments.
185 throw new Error(MessageManager
186 .getString("error.parameter_migration_not_implemented_yet"));