84dcfb951c6f18336e6e96999929e6efb5399bcc
[jalview.git] / src / jalview / ws / rest / params / AnnotationFile.java
1 package jalview.ws.rest.params;
2
3 import jalview.datamodel.AlignmentI;
4 import jalview.ws.rest.InputType;
5 import jalview.ws.rest.NoValidInputDataException;
6 import jalview.ws.rest.RestJob;
7 import jalview.ws.rest.InputType.molType;
8
9 import java.io.UnsupportedEncodingException;
10
11 import org.apache.http.entity.mime.content.ContentBody;
12 import org.apache.http.entity.mime.content.StringBody;
13
14 /**
15  * format a jalview annotation file for input to a rest service.
16  * @author JimP
17  *
18  */
19 public class AnnotationFile extends InputType {
20   public AnnotationFile()
21   {
22     super(new Class[] { AlignmentI.class} );
23   }
24   /**
25    * standard jalview annotation file
26    */
27   final String JVANNOT="JalviewAnnotation";
28   /**
29    * export annotation row as simple csv
30    */
31   final String CSVANNOT="CsvAnnotationRow";
32   /**
33    * format of annotation file
34    */
35   String format=JVANNOT;
36   // TODO verify annotation file format enumeration
37   @Override
38   public ContentBody formatForInput(RestJob rj) throws UnsupportedEncodingException, NoValidInputDataException
39   {
40     AlignmentI al = rj.getAlignmentForInput(token,molType.MIX);
41     if (format.equals(JVANNOT))
42       {return new StringBody(new jalview.io.AnnotationFile().printAnnotations(al.getAlignmentAnnotation(),
43             al.getGroups(),al.getProperties()));
44       } else {
45         if (!format.equals(CSVANNOT))
46         {
47           throw new UnsupportedEncodingException("Unrecognised format for exporting Annotation ("+format+")");
48         }
49         return new StringBody(new jalview.io.AnnotationFile().printCSVAnnotations(al.getAlignmentAnnotation()));
50       }
51   }
52 }