Change the way to deal with Limits to simplify wrapper writing and enable couping...
[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         private static final LimitsManager<GlobPlot> limitMan = compbio.runner.Util\r
51                         .getLimits(new GlobPlot().getType());\r
52 \r
53         ConfiguredExecutable<GlobPlot> init(List<FastaSequence> sequences)\r
54                         throws JobSubmissionException {\r
55                 GlobPlot globPlot = new GlobPlot();\r
56                 globPlot.setInput("fasta.in").setOutput("globPlot.out");\r
57                 return Configurator.configureExecutable(globPlot, sequences);\r
58         }\r
59 \r
60         @Override\r
61         public ScoreManager getAnnotation(String jobId)\r
62                         throws ResultNotAvailableException {\r
63                 WSUtil.validateJobId(jobId);\r
64                 AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);\r
65                 ConfiguredExecutable<GlobPlot> globPlot = (ConfiguredExecutable<GlobPlot>) asyncEngine\r
66                                 .getResults(jobId);\r
67                 ScoreManager mas = globPlot.getResults();\r
68                 log.trace(jobId + " getConservation : " + mas);\r
69                 return mas;\r
70         }\r
71 \r
72         @Override\r
73         public Limit<GlobPlot> getLimit(String presetName) {\r
74                 return limitMan.getLimitByName(presetName);\r
75         }\r
76 \r
77         @Override\r
78         public LimitsManager<GlobPlot> getLimits() {\r
79                 return limitMan;\r
80         }\r
81 \r
82         @Override\r
83         public ChunkHolder pullExecStatistics(String jobId, long position) {\r
84                 // Execution stat is not supported\r
85                 return new ChunkHolder("", -1);\r
86         }\r
87 \r
88         @Override\r
89         public boolean cancelJob(String jobId) {\r
90                 WSUtil.validateJobId(jobId);\r
91                 return WSUtil.cancelJob(jobId);\r
92         }\r
93 \r
94         @Override\r
95         public JobStatus getJobStatus(String jobId) {\r
96                 WSUtil.validateJobId(jobId);\r
97                 return WSUtil.getJobStatus(jobId);\r
98         }\r
99 \r
100         @Override\r
101         public PresetManager<GlobPlot> getPresets() {\r
102                 return globPlotPresets;\r
103         }\r
104 \r
105         @Override\r
106         public RunnerConfig<GlobPlot> getRunnerOptions() {\r
107                 return globPlotOptions;\r
108         }\r
109 \r
110         String analize(List<FastaSequence> sequences,\r
111                         ConfiguredExecutable<GlobPlot> confExec, Logger log, String method,\r
112                         Limit<GlobPlot> limit) throws JobSubmissionException {\r
113                 if (limit != null && limit.isExceeded(sequences)) {\r
114                         throw LimitExceededException.newLimitExceeded(limit, sequences);\r
115                 }\r
116 \r
117                 compbio.runner.Util.writeInput(sequences, confExec);\r
118                 AsyncExecutor engine = Configurator.getAsyncEngine(confExec);\r
119                 String jobId = engine.submitJob(confExec);\r
120                 return jobId;\r
121         }\r
122 \r
123         @Override\r
124         public String analize(List<FastaSequence> sequences)\r
125                         throws UnsupportedRuntimeException, LimitExceededException,\r
126                         JobSubmissionException {\r
127                 WSUtil.validateFastaInput(sequences);\r
128                 ConfiguredExecutable<GlobPlot> confGlobPlot = init(sequences);\r
129 \r
130                 return analize(sequences, confGlobPlot, null, "analize", getLimit(""));\r
131         }\r
132 \r
133         /*\r
134          * No options are supported, thus the result of this call will be as simple\r
135          * call to analize without parameters\r
136          */\r
137         @Override\r
138         public String customAnalize(List<FastaSequence> sequences,\r
139                         List<Option<GlobPlot>> options) throws UnsupportedRuntimeException,\r
140                         LimitExceededException, JobSubmissionException,\r
141                         WrongParameterException {\r
142                 return analize(sequences);\r
143         }\r
144 \r
145         /*\r
146          * No presets are supported, thus the result of this call will be as simple\r
147          * call to analize without parameters\r
148          */\r
149         @Override\r
150         public String presetAnalize(List<FastaSequence> sequences,\r
151                         Preset<GlobPlot> preset) throws UnsupportedRuntimeException,\r
152                         LimitExceededException, JobSubmissionException,\r
153                         WrongParameterException {\r
154 \r
155                 return analize(sequences);\r
156         }\r
157 \r
158 }\r