X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fws%2Fjws2%2FJabaParamStore.java;h=34b8a72da3568002ae63c873e513feda56d33423;hb=134576f5b34894218bdc4c5ce5e27fa18ad973bd;hp=0f7d6facf31e0582ba2ad9d14f9ff1da29d09f4b;hpb=85037c7f026acf289a22eaf0bd0d368351b5905e;p=jalview.git
diff --git a/src/jalview/ws/jws2/JabaParamStore.java b/src/jalview/ws/jws2/JabaParamStore.java
index 0f7d6fa..34b8a72 100644
--- a/src/jalview/ws/jws2/JabaParamStore.java
+++ b/src/jalview/ws/jws2/JabaParamStore.java
@@ -1,12 +1,41 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.ws.jws2;
-import java.io.BufferedReader;
+import jalview.util.MessageManager;
+import jalview.ws.jws2.dm.JabaOption;
+import jalview.ws.jws2.dm.JabaParameter;
+import jalview.ws.jws2.dm.JabaWsParamSet;
+import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.params.ArgumentI;
+import jalview.ws.params.ParamDatastoreI;
+import jalview.ws.params.ParamManager;
+import jalview.ws.params.WsParamSetI;
+
import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
+import java.util.StringTokenizer;
import compbio.metadata.Argument;
import compbio.metadata.Option;
@@ -15,14 +44,6 @@ import compbio.metadata.Preset;
import compbio.metadata.PresetManager;
import compbio.metadata.RunnerConfig;
-import jalview.ws.jws2.Jws2Discoverer.Jws2Instance;
-import jalview.ws.jws2.dm.JabaOption;
-import jalview.ws.jws2.dm.JabaParameter;
-import jalview.ws.jws2.dm.JabaWsParamSet;
-import jalview.ws.params.ArgumentI;
-import jalview.ws.params.ParamDatastoreI;
-import jalview.ws.params.WsParamSetI;
-
public class JabaParamStore implements ParamDatastoreI
{
@@ -36,56 +57,44 @@ public class JabaParamStore implements ParamDatastoreI
public JabaParamStore(Jws2Instance service)
{
- this.service = service;
- serviceOptions = service.getRunnerConfig();
- // TODO: discover all the user's locally sored presets for this service and populate the hash table
- // TODO: for JAL-632
+ this(service, null);
}
- /**
- * store the given parameters in the user parameter set database.
- *
- * @param storeSetName
- * - lastParmSet
- * @param descr
- * - setDescr.getText()
- * @param jobParams
- * - getJobParams()
- */
- private void _storeUserPreset(String storeSetName, String descr,
- List jobParams)
- {
- // this is a simple hash store.
- editedParams.put(storeSetName, new JabaWsParamSet(storeSetName, descr,
- JabaParamStore.getJwsArgsfromJaba(jobParams)));
- // writeParam("Saving " + storeSetName + ": ", jobParams);
- }
+ ParamManager manager;
- private void writeParam(String nm, List params)
+ public JabaParamStore(Jws2Instance service, ParamManager manager)
{
- for (Argument p : params)
+ this.service = service;
+ serviceOptions = service.getRunnerConfig();
+ this.manager = manager;
+ // discover all the user's locally stored presets for this service and
+ // populate the hash table
+ if (manager != null)
{
- System.out.println(nm + ":" + System.identityHashCode(p) + " Name: "
- + p.getName() + " Value: " + p.getDefaultValue());
+ manager.registerParser(service.getUri(), this);
+ WsParamSetI[] prams = manager.getParameterSet(null, service.getUri(),
+ true, false);
+ if (prams != null)
+ {
+ for (WsParamSetI paramset : prams)
+ {
+ if (paramset instanceof JabaWsParamSet)
+ {
+ editedParams.put(paramset.getName(), (JabaWsParamSet) paramset);
+ }
+ else
+ {
+ System.err
+ .println("Warning: Ignoring parameter set instance of type "
+ + paramset.getClass()
+ + " : Bound but not applicable for service at "
+ + service.getUri());
+ }
+ }
+ }
}
}
- private JabaWsParamSet _getUserPreset(String setName)
- {
- JabaWsParamSet pset = editedParams.get(setName);
- return pset;
- }
-
- /**
- * remove the given user preset from the preset stash
- *
- * @param setName
- */
- private void _deleteUserPreset(String setName)
- {
- editedParams.remove(setName);
- }
-
@Override
public List getPresets()
{
@@ -133,24 +142,56 @@ public class JabaParamStore implements ParamDatastoreI
public static List getJwsArgsfromJaba(List jabargs)
{
+ return getJwsArgsfromJaba(jabargs, true);
+ }
+
+ public static List getJwsArgsfromJaba(List jabargs,
+ boolean sortByOpt)
+ {
List rgs = new ArrayList();
+ List rgnames = new ArrayList();
for (Object rg : jabargs)
{
- ArgumentI narg = (rg instanceof Parameter) ? new JabaParameter(
- (Parameter) rg) : (rg instanceof Option) ? new JabaOption(
- (Option) rg) : null;
+ ArgumentI narg = null;
+ String nargstring = null;
+ if (rg instanceof Parameter)
+ {
+ narg = new JabaParameter((Parameter) rg);
+ nargstring = narg.getName(); // just sort by name for this
+ }
+ else if (rg instanceof Option)
+ {
+ narg = new JabaOption((Option) rg);
+ nargstring = (String) ((Option) rg).getOptionNames().get(0);
+ }
if (narg == null)
{
- throw new Error(
- "Implementation Error: Cannot handle Jaba parameter object "
- + rg.getClass());
+ throw new Error(MessageManager.formatMessage(
+ "error.implementation_error_cannot_handle_jaba_param",
+ new String[] { rg.getClass().toString() }));
}
else
{
rgs.add(narg);
+ rgnames.add(nargstring);
}
}
- return rgs;
+ if (!sortByOpt)
+ {
+ return rgs;
+ }
+ ArgumentI[] rgssort = rgs.toArray(new ArgumentI[rgs.size()]);
+ String[] rgssorton = rgnames.toArray(new String[rgs.size()]);
+ jalview.util.QuickSort.sort(rgssorton, rgssort);
+ ArgumentI tmp1;
+ int i = 0;
+ while (rgssort.length - i > i)
+ {
+ tmp1 = rgssort[rgssort.length - i - 1];
+ rgssort[rgssort.length - i - 1] = rgssort[i];
+ rgssort[i++] = tmp1;
+ }
+ return Arrays.asList(rgssort);
}
public static List getJabafromJwsArgs(List jwsargs)
@@ -162,9 +203,9 @@ public class JabaParamStore implements ParamDatastoreI
.getOption() : null;
if (narg == null)
{
- throw new Error(
- "Implementation Error: Cannot handle Jaba parameter object "
- + rg.getClass());
+ throw new Error(MessageManager.formatMessage(
+ "error.implementation_error_cannot_handle_jaba_param",
+ new String[] { rg.getClass().toString() }));
}
else
{
@@ -192,55 +233,145 @@ public class JabaParamStore implements ParamDatastoreI
{
if (editedParams.containsKey(name))
{
+ WsParamSetI parameterSet = editedParams.get(name);
editedParams.remove(name);
+ if (manager != null)
+ {
+ manager.deleteParameterSet(parameterSet);
+ }
return;
}
if (servicePresets.containsKey(name))
{
throw new Error(
- "Implementation error: Attempt to delete a service preset!");
+ MessageManager
+ .getString("error.implementation_error_attempt_to_delete_service_preset"));
}
}
-
@Override
public void storePreset(String presetName, String text,
List jobParams)
{
JabaWsParamSet jps = new JabaWsParamSet(presetName, text, jobParams);
+ jps.setApplicableUrls(new String[] { service.getUri() });
editedParams.put(jps.getName(), jps);
+ if (manager != null)
+ {
+ manager.storeParameterSet(jps);
+ }
}
@Override
- public boolean readParamSet(WsParamSetI wsp,
- Reader reader) throws IOException
+ public void updatePreset(String oldName, String presetName, String text,
+ List jobParams)
{
- if (!(wsp instanceof JabaWsParamSet))
+ JabaWsParamSet jps = (JabaWsParamSet) ((oldName != null) ? getPreset(oldName)
+ : getPreset(presetName));
+ if (jps == null)
+ {
+ throw new Error(
+ MessageManager
+ .formatMessage(
+ "error.implementation_error_cannot_locate_oldname_presetname",
+ new String[] { oldName, presetName }));
+ }
+ jps.setName(presetName);
+ jps.setDescription(text);
+ jps.setArguments(jobParams);
+ jps.setApplicableUrls(new String[] { service.getUri() });
+ if (oldName != null && !oldName.equals(jps.getName()))
{
- throw new Error("Implementation error: JabaWsParamSets can only be handled by JabaParamStore");
+ editedParams.remove(oldName);
}
- List lines=new ArrayList();
- String line;
- BufferedReader br = new BufferedReader(reader);
- while ((line=br.readLine())!=null)
+ editedParams.put(jps.getName(), jps);
+
+ if (manager != null)
{
- lines.add(line);
+ manager.storeParameterSet(jps);
}
- ((JabaWsParamSet) wsp).setjabaArguments(ParameterUtils.processParameters(lines, serviceOptions, " "));
- return true;
+ }
+
+ /**
+ * create a new, empty parameter set for this service
+ *
+ * @return
+ */
+ WsParamSetI newWsParamSet()
+ {
+ return new JabaWsParamSet();
+ };
+
+ private boolean involves(String[] urls)
+ {
+ boolean found = false;
+ for (String url : urls)
+ {
+ if (service.getServiceTypeURI().equals(url)
+ || service.getUri().equalsIgnoreCase(url))
+ {
+ found = true;
+ break;
+ }
+ }
+ return found;
}
@Override
- public boolean writeParamSet(WsParamSetI wsp,
- Writer writer) throws IOException
- {
- if (!(wsp instanceof JabaWsParamSet))
- {
- throw new Error("Implementation error: JabaWsParamSets can only be handled by JabaParamStore");
- }
- writer.write(ParameterUtils.writeParameterSet(((JabaWsParamSet)wsp).getjabaArguments(), " ")
- .toString());
- return true;
+ public WsParamSetI parseServiceParameterFile(String name, String descr,
+ String[] urls, String parameterfile) throws IOException
+ {
+ if (!involves(urls))
+ {
+ throw new IOException(
+ MessageManager
+ .getString("error.implementation_error_cannot_find_service_url_in_given_set"));
+
+ }
+ JabaWsParamSet wsp = new JabaWsParamSet();
+ wsp.setName(name);
+ wsp.setDescription(descr);
+ wsp.setApplicableUrls(urls.clone());
+
+ List lines = new ArrayList();
+ StringTokenizer st = new StringTokenizer(parameterfile, "\n");
+ while (st.hasMoreTokens())
+ {
+ lines.add(st.nextToken());
+ }
+ wsp.setjabaArguments(ParameterUtils.processParameters(lines,
+ serviceOptions, " "));
+ return wsp;
+ }
+
+ @Override
+ public String generateServiceParameterFile(WsParamSetI pset)
+ throws IOException
+ {
+ if (!involves(pset.getApplicableUrls()))
+ {
+ throw new IOException(
+ MessageManager
+ .formatMessage(
+ "error.implementation_error_cannot_find_service_url_in_given_set_param_store",
+ new String[] { service.getUri() }));
+ }
+ if (!(pset instanceof JabaWsParamSet))
+ {
+ throw new Error(
+ MessageManager
+ .getString("error.implementation_error_jabaws_param_set_only_handled_by"));
+ }
+
+ StringBuffer rslt = new StringBuffer();
+ for (String ln : ParameterUtils.writeParameterSet(
+ ((JabaWsParamSet) pset).getjabaArguments(), " "))
+ {
+ rslt.append(ln);
+ rslt.append("\n");
+ }
+ ;
+ return rslt.toString();
}
}