X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fslivkaws%2FSlivkaWSInstance.java;h=658d99e52162a45eaff7016630286fe3dce00d94;hb=c8dfa0a1b91d46b9c11dc6ce7b2b4bfcbc71c13e;hp=75e5722ac253cb9f50ed1870d4ea1c52d6a1ea80;hpb=bc7c2cf5500c5a4124a69ef8e7b1374d8997558f;p=jalview.git diff --git a/src/jalview/ws/slivkaws/SlivkaWSInstance.java b/src/jalview/ws/slivkaws/SlivkaWSInstance.java index 75e5722..658d99e 100644 --- a/src/jalview/ws/slivkaws/SlivkaWSInstance.java +++ b/src/jalview/ws/slivkaws/SlivkaWSInstance.java @@ -13,6 +13,7 @@ import jalview.ws.params.ArgumentI; 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; @@ -20,22 +21,18 @@ import java.io.IOError; 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 @@ -46,19 +43,19 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters protected SlivkaDatastore store = null; - protected static final EnumMap stateMap = new EnumMap<>(JobState.class); + protected static final EnumMap 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 failedStates = new HashSet<>(Arrays.asList( WsJob.JobState.INVALID, WsJob.JobState.BROKEN, WsJob.JobState.FAILED, @@ -67,7 +64,7 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters 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; } @@ -75,16 +72,17 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters protected final JobId submit(List sequences, WsParamSetI preset, List 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; @@ -100,9 +98,7 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters 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) @@ -111,22 +107,22 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters { // 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 @@ -134,7 +130,8 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters { 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); @@ -143,8 +140,9 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters @Override public final boolean updateJobProgress(WsJob job) throws IOException - { - List files = client.getJobResults(job.getJobId()); + { + var slivkaJob = client.getJob(job.getJobId()); + Collection files = slivkaJob.getResults(); RemoteFile logFile=null; for (RemoteFile f : files) { @@ -196,17 +194,10 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters @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;