import java.io.IOError;
import java.io.IOException;
import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
}
@Override
- public List<AlignmentAnnotation> getAnnotationResult(JobId job,
+ public List<AlignmentAnnotation> getAnnotationResult(JobId jobId,
List<SequenceI> seqs, Map<String, FeatureColourI> featureColours,
Map<String, FeatureMatcherSetI> featureFilters) throws Throwable
{
RemoteFile featFile = null;
try
{
- List<RemoteFile> files = client.getJobResults(job.getJobId());
+ var slivkaJob = client.getJob(jobId.getJobId());
+ Collection<RemoteFile> files = slivkaJob.getResults();
for (RemoteFile f : files)
{
- if (f.getMimeType().equals("application/jalview-annotations"))
+ if (f.getMediaType().equals("application/jalview-annotations"))
{
annotFile = f;
}
- else if (f.getMimeType().equals("application/jalview-features"))
+ else if (f.getMediaType().equals("application/jalview-features"))
{
featFile = f;
}
}
Alignment aln = new Alignment(seqs.toArray(new SequenceI[0]));
if (annotFile == null
- || !new AnnotationFile().readAnnotationFile(aln, annotFile.getURL().toString(), DataSourceType.URL))
+ || !new AnnotationFile().readAnnotationFile(aln, annotFile.getContentUrl().toString(), DataSourceType.URL))
{
Cache.log.debug("No annotation from slivka job\n" + annotFile);
}
+ else {
+ Cache.log.debug("Annotation file loaded " + annotFile);
+ }
if (featFile == null
- || !new FeaturesFile(featFile.getURL().toString(), DataSourceType.URL).parse(aln, featureColours, true))
+ || !new FeaturesFile(featFile.getContentUrl().toString(), DataSourceType.URL).parse(aln, featureColours, true))
{
Cache.log.debug("No features from slivka job\n" + featFile);
}
+ else {
+ Cache.log.debug("Features feil loaded " + featFile);
+ }
return Arrays.asList(aln.getAlignmentAnnotation());
}
}
package jalview.ws.slivkaws;
+import jalview.bin.Cache;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.SequenceI;
import jalview.io.DataSourceType;
import java.io.IOError;
import java.io.IOException;
import java.rmi.ServerError;
+import java.util.Collection;
import java.util.List;
import compbio.data.msa.Category;
@Override
public AlignmentI getAlignmentFor(JobId jobId) throws InvalidArgumentException, ServerError, IOError
{
- List<RemoteFile> files;
+ Collection<RemoteFile> files;
try
{
- files = client.getJobResults(jobId.getJobId());
+ var slivkaJob = client.getJob(jobId.getJobId());
+ files = slivkaJob.getResults();
for (RemoteFile f : files)
{
- if (f.getMimeType().equals("application/clustal"))
+ if (f.getMediaType().equals("application/clustal"))
{
- return new FormatAdapter().readFile(f.getURL().toString(), DataSourceType.URL, FileFormat.Clustal);
+ return new FormatAdapter().readFile(f.getContentUrl().toString(), DataSourceType.URL, FileFormat.Clustal);
}
- else if (f.getMimeType().equals("application/fasta"))
+ else if (f.getMediaType().equals("application/fasta"))
{
- return new FormatAdapter().readFile(f.getURL().toString(), DataSourceType.URL, FileFormat.Fasta);
+ return new FormatAdapter().readFile(f.getContentUrl().toString(), DataSourceType.URL, FileFormat.Fasta);
}
}
} catch (IOException e)
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
-import uk.ac.dundee.compbio.slivkaclient.BooleanField;
-import uk.ac.dundee.compbio.slivkaclient.ChoiceField;
-import uk.ac.dundee.compbio.slivkaclient.DecimalField;
-import uk.ac.dundee.compbio.slivkaclient.FormField;
-import uk.ac.dundee.compbio.slivkaclient.IntegerField;
-import uk.ac.dundee.compbio.slivkaclient.SlivkaForm;
+import uk.ac.dundee.compbio.slivkaclient.Parameter;
import uk.ac.dundee.compbio.slivkaclient.SlivkaService;
-import uk.ac.dundee.compbio.slivkaclient.TextField;
-
-
public class SlivkaParamSet implements WsParamSetI
{
private SlivkaService service;
+
private List<ArgumentI> args = new ArrayList<>();
- SlivkaParamSet(SlivkaService service) throws IOException {
+ SlivkaParamSet(SlivkaService service) throws IOException
+ {
this.service = service;
- SlivkaForm form = service.getForm();
- for (FormField field : form.getFields())
+ for (Parameter param : service.getParameters())
{
- switch (field.getType()) {
- case BOOLEAN:
- BooleanField boolField = (BooleanField) field;
- args.add(new BooleanOption(
- field.getName(), field.getDescription(), field.getLabel(),
- field.isRequired(), boolField.getDefault(), null
- ));
- break;
- case TEXT:
- TextField textField = (TextField) field;
- args.add(new StringParameter(
- field.getName(), field.getDescription(), field.isRequired(),
- textField.getDefault(), textField.getDefault()
- ));
- break;
- case INTEGER:
- IntegerField intField = (IntegerField) field;
- args.add(new IntegerParameter(
- field.getName(), field.getDescription(), field.isRequired(),
- intField.getDefault(), intField.getMin(), intField.getMax()
- ));
- break;
- case DECIMAL:
- DecimalField doubleField = (DecimalField) field;
- args.add(new DoubleParameter(
- field.getName(), field.getDescription(), field.isRequired(),
- doubleField.getDefault(), doubleField.getMin(),
- doubleField.getMax()
- ));
- break;
- case CHOICE:
- ChoiceField choiceField = (ChoiceField) field;
- List<String> choices = new ArrayList<>(choiceField.getChoices());
- if (field.hasMultipleValues()) {
- int counter = 0;
- for (String choice : choices) {
+ Object defaultValue = param.getDefault() instanceof List ? ((List<?>) param.getDefault()).get(0)
+ : param.getDefault();
+ if (param instanceof Parameter.FlagParameter)
+ {
+ args.add(new BooleanOption(param.getId(), param.getDescription(),
+ param.getName(), param.isRequired(), (Boolean) defaultValue, null));
+ }
+ else if (param instanceof Parameter.TextParameter)
+ {
+ args.add(new StringParameter(param.getId(), param.getDescription(),
+ param.isRequired(), (String) defaultValue, (String) defaultValue));
+ }
+ else if (param instanceof Parameter.IntegerParameter)
+ {
+ Integer min = ((Parameter.IntegerParameter) param).getMin();
+ Integer max = ((Parameter.IntegerParameter) param).getMax();
+ Integer defVal = defaultValue != null ? ((Number) defaultValue).intValue() : null;
+ args.add(new IntegerParameter(param.getId(), param.getDescription(),
+ param.isRequired(), defVal, (min == null) ? Integer.MIN_VALUE : min,
+ (max == null) ? Integer.MAX_VALUE : max));
+ }
+ else if (param instanceof Parameter.DecimalParameter)
+ {
+ Double min = ((Parameter.DecimalParameter) param).getMin();
+ Double max = ((Parameter.DecimalParameter) param).getMax();
+ Double defVal = defaultValue != null ? ((Number) defaultValue).doubleValue() : null;
+ args.add(new DoubleParameter(param.getId(), param.getDescription(),
+ param.isRequired(), defVal, (min == null) ? -Double.MAX_VALUE : min,
+ (max == null) ? Double.MAX_VALUE : max));
+ }
+ else if (param instanceof Parameter.ChoiceParameter)
+ {
+ List<String> choices = ((Parameter.ChoiceParameter) param)
+ .getChoices();
+ if (param.isArray())
+ {
+ int i = 0;
+ List<?> selected = param.getDefault() != null
+ ? (List<?>) param.getDefault()
+ : Collections.EMPTY_LIST;
+ for (String choice : choices)
+ {
args.add(new BooleanOption(
- String.format("%s$%d", field.getName(), counter++),
- field.getDescription(), choice, field.isRequired(),
- choice.equals(choiceField.getDefault()), choice,
- null
- ));
+ String.format("%s$%d", param.getId(), i++),
+ param.getDescription(), choice, param.isRequired(),
+ selected.contains(choice), choice, null));
}
}
else
{
args.add(new StringParameter(
- field.getName(), field.getDescription(),
- field.isRequired(), choiceField.getDefault(), choiceField.getDefault(),
- choices, choices
- ));
+ param.getId(), param.getDescription(),
+ param.isRequired(), (String) param.getDefault(),
+ (String) defaultValue, choices, choices));
}
- break;
- case FILE:
- default:
- continue;
+ }
+ else if (param instanceof Parameter.FileParameter)
+ {
+ // skip: files are provided from sequences
+ }
+ else
+ {
+ String defaultVal = param.getDefault() != null
+ ? param.getDefault().toString()
+ : null;
+ args.add(new StringParameter(param.getId(), param.getDescription(),
+ param.isRequired(), defaultVal, defaultVal));
}
}
}
@Override
public String[] getApplicableUrls()
{
- return new String[] { service.getURL().toString() };
+ return new String[] { service.getUrl().toString() };
}
@Override
{
List<?> services = new SlivkaClient(url).getServices();
return services.isEmpty() ? STATUS_NO_SERVICES : STATUS_OK;
- } catch (IOException e)
+ } catch (IOException | org.json.JSONException e)
{
Cache.log.error("Slivka could not retrieve services list", e);
return STATUS_INVALID;
import jalview.ws.params.ParamDatastoreI;
import jalview.ws.params.ParamManager;
import jalview.ws.params.WsParamSetI;
+import javajs.http.ClientProtocolException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
+import java.util.Collection;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.List;
-import java.util.Optional;
import java.util.Set;
-import uk.ac.dundee.compbio.slivkaclient.FieldType;
-import uk.ac.dundee.compbio.slivkaclient.FileField;
-import uk.ac.dundee.compbio.slivkaclient.FormField;
-import uk.ac.dundee.compbio.slivkaclient.FormValidationException;
-import uk.ac.dundee.compbio.slivkaclient.JobState;
+import uk.ac.dundee.compbio.slivkaclient.Job;
+import uk.ac.dundee.compbio.slivkaclient.JobRequest;
+import uk.ac.dundee.compbio.slivkaclient.Parameter;
import uk.ac.dundee.compbio.slivkaclient.RemoteFile;
import uk.ac.dundee.compbio.slivkaclient.SlivkaClient;
-import uk.ac.dundee.compbio.slivkaclient.SlivkaForm;
import uk.ac.dundee.compbio.slivkaclient.SlivkaService;
-import uk.ac.dundee.compbio.slivkaclient.ValidationException;
public abstract class SlivkaWSInstance extends ServiceWithParameters
implements JalviewServiceEndpointProviderI, JalviewWebServiceI
protected SlivkaDatastore store = null;
- protected static final EnumMap<JobState, WsJob.JobState> stateMap = new EnumMap<>(JobState.class);
+ protected static final EnumMap<Job.Status, WsJob.JobState> stateMap = new EnumMap<>(Job.Status.class);
{
- stateMap.put(JobState.PENDING, WsJob.JobState.QUEUED);
- stateMap.put(JobState.REJECTED, WsJob.JobState.INVALID);
- stateMap.put(JobState.ACCEPTED, WsJob.JobState.QUEUED);
- stateMap.put(JobState.QUEUED, WsJob.JobState.QUEUED);
- stateMap.put(JobState.RUNNING, WsJob.JobState.RUNNING);
- stateMap.put(JobState.COMPLETED, WsJob.JobState.FINISHED);
- stateMap.put(JobState.INTERRUPTED, WsJob.JobState.CANCELLED);
- stateMap.put(JobState.DELETED, WsJob.JobState.CANCELLED);
- stateMap.put(JobState.FAILED, WsJob.JobState.FAILED);
- stateMap.put(JobState.ERROR, WsJob.JobState.SERVERERROR);
- stateMap.put(JobState.UNKNOWN, WsJob.JobState.UNKNOWN);
+ stateMap.put(Job.Status.PENDING, WsJob.JobState.QUEUED);
+ stateMap.put(Job.Status.REJECTED, WsJob.JobState.INVALID);
+ stateMap.put(Job.Status.ACCEPTED, WsJob.JobState.QUEUED);
+ stateMap.put(Job.Status.QUEUED, WsJob.JobState.QUEUED);
+ stateMap.put(Job.Status.RUNNING, WsJob.JobState.RUNNING);
+ stateMap.put(Job.Status.COMPLETED, WsJob.JobState.FINISHED);
+ stateMap.put(Job.Status.INTERRUPTED, WsJob.JobState.CANCELLED);
+ stateMap.put(Job.Status.DELETED, WsJob.JobState.CANCELLED);
+ stateMap.put(Job.Status.FAILED, WsJob.JobState.FAILED);
+ stateMap.put(Job.Status.ERROR, WsJob.JobState.SERVERERROR);
+ stateMap.put(Job.Status.UNKNOWN, WsJob.JobState.UNKNOWN);
}
protected final Set<WsJob.JobState> failedStates = new HashSet<>(Arrays.asList(
WsJob.JobState.INVALID, WsJob.JobState.BROKEN, WsJob.JobState.FAILED,
public SlivkaWSInstance(SlivkaClient client, SlivkaService service, String action)
{
- super(action, action, service.getLabel(), "Slivka", client.getUrl().toString());
+ super(action, action, service.getName(), "Slivka", client.getUrl().toString());
this.client = client;
this.service = service;
}
protected final JobId submit(List<SequenceI> sequences,
WsParamSetI preset, List<ArgumentI> args) throws Throwable
{
- SlivkaForm form = service.getForm();
- for (FormField field : form.getFields())
+ var parameters = service.getParameters();
+ var request = new JobRequest();
+ for (Parameter param : parameters)
{
- if (field.getType() == FieldType.FILE)
+ if (param instanceof Parameter.FileParameter)
{
FormatAdapter fa = new FormatAdapter();
fa.setNewlineString("\r\n");
- FileField fileField = (FileField) field;
+ Parameter.FileParameter fileParam = (Parameter.FileParameter) param;
FileFormat format;
- switch (fileField.getMediaType())
+ switch (fileParam.getMediaType())
{
case "application/pfam":
format = FileFormat.Pfam;
InputStream stream = new ByteArrayInputStream(
fa.formatSequences(format, sequences.toArray(new SequenceI[0]))
.getBytes());
- RemoteFile rf = client.uploadFile(stream, "input",
- fileField.getMediaType());
- form.insert(field.getName(), rf);
+ request.addFile(param.getId(), stream);
}
}
if (args != null)
{
// multiple choice field names are name$number to avoid duplications
// the number is stripped here
- String fieldName = arg.getName().split("\\$", 2)[0];
- FormField field = form.getField(fieldName);
- if (field.getType() == FieldType.BOOLEAN)
- {
- form.insert(fieldName,
- (arg.getValue() != null && !arg.getValue().isBlank())
- ? true
- : false);
+ String paramId = arg.getName().split("\\$", 2)[0];
+ Parameter param = service.getParameter(paramId);
+ if (param instanceof Parameter.FlagParameter) {
+ if (arg.getValue() != null && !arg.getValue().isBlank())
+ request.addData(paramId, true);
+ else
+ request.addData(paramId, false);
}
else
{
- form.insert(fieldName, arg.getValue());
+ request.addData(paramId, arg.getValue());
}
}
}
- return new JobId(service.getName(), service.getName(), form.submit());
+ var job = service.submitJob(request);
+ return new JobId(service.getName(), service.getName(), job.getId());
}
@Override
{
try
{
- job.setState(stateMap.get(client.getJobState(job.getJobId())));
+ var slivkaJob = client.getJob(job.getJobId());
+ job.setState(stateMap.get(slivkaJob.getStatus()));
} catch (IOException e)
{
throw new IOError(e);
@Override
public final boolean updateJobProgress(WsJob job) throws IOException
- {
- List<RemoteFile> files = client.getJobResults(job.getJobId());
+ {
+ var slivkaJob = client.getJob(job.getJobId());
+ Collection<RemoteFile> files = slivkaJob.getResults();
RemoteFile logFile=null;
for (RemoteFile f : files)
{
@Override
public final boolean handleSubmitError(Throwable _lex, WsJob j, WebserviceInfo wsInfo)
{
- if (_lex instanceof FormValidationException)
+ if (_lex instanceof ClientProtocolException)
{
- FormValidationException formError = (FormValidationException) _lex;
- String[] messages = new String[formError.getErrors().size()];
- int i = 0;
- for (ValidationException e : formError.getErrors())
- {
- messages[i++] = String.format("%s: %s,", e.getField().getName(), e.getMessage());
- }
j.setState(WsJob.JobState.INVALID);
- j.setStatus(String.join(", ", messages));
+ j.setStatus(_lex.getMessage());
return true;
}
return false;