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 abstract 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() };
103 * @return stringified representation of the parameters for this setting
105 public abstract String getWsParamFile();
107 public ServiceWithParameters getService()
112 public void setService(ServiceWithParameters service)
114 this.service = service;
117 // check if we need to migrate preset to a new service URL
118 for (String url : preset.getApplicableUrls())
120 if (url.equals(service.getUri()))
122 // preset already verified
126 WsParamSetI pr = service.getParamStore().getPreset(preset.getName());
128 // TODO: decide of this distinction between preset and args are needed.
130 // if (pr instanceof JabaPreset && preset instanceof JabaPreset)
132 // // easy - Presets are identical (we assume)
137 // this verifies that all arguments in the existing preset are the same as
138 // the parameters for the preset provided by the service parameter store.
139 // ie the LastUsed settings or a predefined preset.
141 List<ArgumentI> oldargs = new ArrayList<>(),
142 newargs = new ArrayList<>();
143 oldargs.addAll(preset.getArguments());
144 // need to compare parameters
145 for (ArgumentI newparg : pr.getArguments())
147 if (!oldargs.remove(newparg))
149 newargs.add(newparg);
152 if (oldargs.size() == 0 && newargs.size() == 0)
158 // Try even harder to migrate arguments.
159 throw new Error(MessageManager
160 .getString("error.parameter_migration_not_implemented_yet"));