initial implementation of Rest client framework (JAL-715)
[jalview.git] / src / jalview / ws / rest / params / SeqIdVector.java
diff --git a/src/jalview/ws/rest/params/SeqIdVector.java b/src/jalview/ws/rest/params/SeqIdVector.java
new file mode 100644 (file)
index 0000000..9bdaed1
--- /dev/null
@@ -0,0 +1,46 @@
+package jalview.ws.rest.params;
+
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
+import jalview.ws.rest.InputType;
+import jalview.ws.rest.NoValidInputDataException;
+import jalview.ws.rest.RestJob;
+import jalview.ws.rest.InputType.molType;
+
+import java.io.UnsupportedEncodingException;
+
+import org.apache.http.entity.mime.content.ContentBody;
+import org.apache.http.entity.mime.content.StringBody;
+
+/**
+ * input a list of sequence IDs separated by some separator 
+ * @author JimP
+ *
+ */
+class SeqIdVector extends InputType {
+  public SeqIdVector()
+  {
+    super(new Class[] { AlignmentI.class} );
+  }
+
+  /**
+   * separator for list of sequence IDs - default is ','
+   */
+  String sep=",";
+  molType type;
+  @Override
+  public ContentBody formatForInput(RestJob rj) throws UnsupportedEncodingException, NoValidInputDataException
+  {
+    StringBuffer idvector = new StringBuffer();
+    boolean list=false;
+    for (SequenceI seq:rj.getSequencesForInput(token, type))
+    {
+      if (list)
+      {
+        idvector.append(sep);
+      }
+      idvector.append(seq.getName());
+    }
+    return new StringBody(idvector.toString());
+  }
+}
\ No newline at end of file