1 /* Copyright (c) 2011 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0
\r
5 * This library is free software; you can redistribute it and/or modify it under the terms of the
\r
6 * Apache License version 2 as published by the Apache Software Foundation
\r
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
\r
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
\r
10 * License for more details.
\r
12 * A copy of the license is in apache_license.txt. It is also available here:
\r
13 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
18 package compbio.ws.client;
\r
20 import static compbio.ws.client.Constraints.pseparator;
\r
22 import java.util.ArrayList;
\r
23 import java.util.Collections;
\r
24 import java.util.List;
\r
26 import compbio.data.msa.Metadata;
\r
27 import compbio.metadata.Limit;
\r
28 import compbio.metadata.LimitsManager;
\r
29 import compbio.metadata.Option;
\r
30 import compbio.metadata.Preset;
\r
31 import compbio.metadata.PresetManager;
\r
32 import compbio.metadata.RunnerConfig;
\r
33 import compbio.metadata.WrongParameterException;
\r
35 public class MetadataHelper {
\r
38 * Returns a list of options supported by web service
\r
44 * @return List of options supported by a web service
\r
46 static <T> List<Option<T>> getParametersList(Metadata<T> msaws) {
\r
47 assert msaws != null;
\r
48 RunnerConfig<T> config = msaws.getRunnerOptions();
\r
49 if (config == null) {
\r
50 return Collections.emptyList();
\r
52 return config.getArguments();
\r
56 * Returns an objects from which the list of presets supported by web
\r
57 * service <T> can be obtained
\r
63 * @return PresetManager, object which operates on presets
\r
65 static <T> PresetManager<T> getPresetList(Metadata<T> msaws) {
\r
66 assert msaws != null;
\r
67 PresetManager<T> presetman = msaws.getPresets();
\r
72 * Returns a list of limits supported by web service Each limit correspond
\r
73 * to a particular preset.
\r
79 * @return List of limits supported by a web service
\r
81 static <T> List<Limit<T>> getLimits(Metadata<T> msaws) {
\r
82 assert msaws != null;
\r
83 LimitsManager<T> lmanger = msaws.getLimits();
\r
85 return lmanger != null ? lmanger.getLimits() : null;
\r
89 * Returns {@code Preset} by its name
\r
95 * @return Return a Preset by its optionName
\r
97 static <T> Preset<T> getPreset(Metadata<T> msaws, String presetName) {
\r
98 assert presetName != null;
\r
99 PresetManager<T> presets = MetadataHelper.getPresetList(msaws);
\r
100 if (presets == null) {
\r
102 .println("No presets are supported by the service! Ignoring -r directive!");
\r
105 Preset<T> pre = presets.getPresetByName(presetName);
\r
107 System.out.println("Cannot find preset: " + presetName
\r
108 + " WARN: ignoring -r directive!");
\r
114 * Converts options supplied via parameters file into {@code Option} objects
\r
120 * @return List of Options of type T
\r
122 static <T> List<Option<T>> processParameters(List<String> params,
\r
123 RunnerConfig<T> options) {
\r
124 List<Option<T>> chosenOptions = new ArrayList<Option<T>>();
\r
125 for (String param : params) {
\r
126 String oname = null;
\r
127 if (isParameter(param)) {
\r
128 oname = getParamName(param);
\r
132 Option<T> o = options.getArgumentByOptionName(oname);
\r
134 System.out.println("WARN ignoring unsuppoted parameter: "
\r
138 if (isParameter(param)) {
\r
140 o.setValue(getParamValue(param));
\r
141 } catch (WrongParameterException e) {
\r
143 .println("Problem setting value for the parameter: "
\r
145 e.printStackTrace();
\r
148 chosenOptions.add(o);
\r
150 return chosenOptions;
\r
153 static String getParamName(String fullName) {
\r
154 assert isParameter(fullName);
\r
155 return fullName.substring(0, fullName.indexOf(pseparator));
\r
158 static String getParamValue(String fullName) {
\r
159 assert isParameter(fullName);
\r
160 return fullName.substring(fullName.indexOf(pseparator) + 1);
\r
163 static boolean isParameter(String param) {
\r
164 return param.contains(pseparator);
\r