Finally, the new web services are working
[jabaws.git] / webservices / compbio / ws / server / GlobPlotWS.java
1 package compbio.ws.server;\r
2 \r
3 import java.util.List;\r
4 \r
5 import javax.annotation.Resource;\r
6 import javax.jws.WebService;\r
7 import javax.xml.ws.WebServiceContext;\r
8 \r
9 import org.apache.log4j.Logger;\r
10 \r
11 import compbio.data.msa.SequenceAnnotation;\r
12 import compbio.data.sequence.FastaSequence;\r
13 import compbio.data.sequence.ScoreManager;\r
14 import compbio.engine.AsyncExecutor;\r
15 import compbio.engine.Configurator;\r
16 import compbio.engine.client.ConfiguredExecutable;\r
17 import compbio.metadata.ChunkHolder;\r
18 import compbio.metadata.JobStatus;\r
19 import compbio.metadata.JobSubmissionException;\r
20 import compbio.metadata.Limit;\r
21 import compbio.metadata.LimitExceededException;\r
22 import compbio.metadata.LimitsManager;\r
23 import compbio.metadata.Option;\r
24 import compbio.metadata.Preset;\r
25 import compbio.metadata.PresetManager;\r
26 import compbio.metadata.ResultNotAvailableException;\r
27 import compbio.metadata.RunnerConfig;\r
28 import compbio.metadata.UnsupportedRuntimeException;\r
29 import compbio.metadata.WrongParameterException;\r
30 import compbio.runner.Util;\r
31 import compbio.runner.disorder.GlobPlot;\r
32 \r
33 @WebService(endpointInterface = "compbio.data.msa.SequenceAnnotation", targetNamespace = "http://msa.data.compbio/01/12/2010/", serviceName = "GlobPlotWS")\r
34 public class GlobPlotWS implements SequenceAnnotation<GlobPlot> {\r
35 \r
36         // Ask for resource injection\r
37         @Resource\r
38         WebServiceContext wsContext;\r
39 \r
40         private static Logger statLog = Logger.getLogger("GlobPlotWS-stats");\r
41 \r
42         private static Logger log = Logger.getLogger(GlobPlotWS.class);\r
43 \r
44         private static final RunnerConfig<GlobPlot> globPlotOptions = Util\r
45                         .getSupportedOptions(GlobPlot.class);\r
46 \r
47         private static final PresetManager<GlobPlot> globPlotPresets = Util\r
48                         .getPresets(GlobPlot.class);\r
49 \r
50         ConfiguredExecutable<GlobPlot> init(List<FastaSequence> sequences)\r
51                         throws JobSubmissionException {\r
52                 GlobPlot globPlot = new GlobPlot();\r
53                 globPlot.setInput("fasta.in").setOutput("globPlot.out");\r
54                 return Configurator.configureExecutable(globPlot, sequences);\r
55         }\r
56 \r
57         @Override\r
58         public ScoreManager getAnnotation(String jobId)\r
59                         throws ResultNotAvailableException {\r
60                 WSUtil.validateJobId(jobId);\r
61                 AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);\r
62                 ConfiguredExecutable<GlobPlot> globPlot = (ConfiguredExecutable<GlobPlot>) asyncEngine\r
63                                 .getResults(jobId);\r
64                 ScoreManager mas = globPlot.getResults();\r
65                 log.trace(jobId + " getConservation : " + mas);\r
66                 return mas;\r
67         }\r
68 \r
69         @Override\r
70         public Limit<GlobPlot> getLimit(String presetName) {\r
71                 return new GlobPlot().getLimit(presetName);\r
72         }\r
73 \r
74         @Override\r
75         public LimitsManager<GlobPlot> getLimits() {\r
76                 return new GlobPlot().getLimits();\r
77         }\r
78 \r
79         @Override\r
80         public ChunkHolder pullExecStatistics(String jobId, long position) {\r
81                 // Execution stat is not supported\r
82                 return new ChunkHolder("", -1);\r
83         }\r
84 \r
85         @Override\r
86         public boolean cancelJob(String jobId) {\r
87                 WSUtil.validateJobId(jobId);\r
88                 return WSUtil.cancelJob(jobId);\r
89         }\r
90 \r
91         @Override\r
92         public JobStatus getJobStatus(String jobId) {\r
93                 WSUtil.validateJobId(jobId);\r
94                 return WSUtil.getJobStatus(jobId);\r
95         }\r
96 \r
97         @Override\r
98         public PresetManager<GlobPlot> getPresets() {\r
99                 return globPlotPresets;\r
100         }\r
101 \r
102         @Override\r
103         public RunnerConfig<GlobPlot> getRunnerOptions() {\r
104                 return globPlotOptions;\r
105         }\r
106 \r
107         String analize(List<FastaSequence> sequences,\r
108                         ConfiguredExecutable<GlobPlot> confExec, Logger log, String method,\r
109                         Limit<GlobPlot> limit) throws JobSubmissionException {\r
110                 if (limit != null && limit.isExceeded(sequences)) {\r
111                         throw LimitExceededException.newLimitExceeded(limit, sequences);\r
112                 }\r
113 \r
114                 compbio.runner.Util.writeInput(sequences, confExec);\r
115                 AsyncExecutor engine = Configurator.getAsyncEngine(confExec);\r
116                 String jobId = engine.submitJob(confExec);\r
117                 return jobId;\r
118         }\r
119 \r
120         @Override\r
121         public String analize(List<FastaSequence> sequences)\r
122                         throws UnsupportedRuntimeException, LimitExceededException,\r
123                         JobSubmissionException {\r
124                 WSUtil.validateFastaInput(sequences);\r
125                 ConfiguredExecutable<GlobPlot> confGlobPlot = init(sequences);\r
126 \r
127                 return analize(sequences, confGlobPlot, null, "analize", getLimit(""));\r
128         }\r
129 \r
130         /*\r
131          * No options are supported, thus the result of this call will be as simple\r
132          * call to analize without parameters\r
133          */\r
134         @Override\r
135         public String customAnalize(List<FastaSequence> sequences,\r
136                         List<Option<GlobPlot>> options) throws UnsupportedRuntimeException,\r
137                         LimitExceededException, JobSubmissionException,\r
138                         WrongParameterException {\r
139                 return analize(sequences);\r
140         }\r
141 \r
142         /*\r
143          * No presets are supported, thus the result of this call will be as simple\r
144          * call to analize without parameters\r
145          */\r
146         @Override\r
147         public String presetAnalize(List<FastaSequence> sequences,\r
148                         Preset<GlobPlot> preset) throws UnsupportedRuntimeException,\r
149                         LimitExceededException, JobSubmissionException,\r
150                         WrongParameterException {\r
151 \r
152                 return analize(sequences);\r
153         }\r
154 \r
155 }\r