Refactoring of all SequenceAnnotation web services
[jabaws.git] / webservices / compbio / ws / server / WSUtil.java
index 6f33f24..1890d65 100644 (file)
@@ -19,11 +19,14 @@ package compbio.ws.server;
 \r
 import java.security.InvalidParameterException;\r
 import java.util.ArrayList;\r
+import java.util.HashSet;\r
 import java.util.List;\r
+import java.util.Set;\r
 \r
 import org.apache.log4j.Logger;\r
 \r
 import compbio.data.sequence.FastaSequence;\r
+import compbio.data.sequence.ScoreManager;\r
 import compbio.engine.AsyncExecutor;\r
 import compbio.engine.Configurator;\r
 import compbio.engine.ProgressGetter;\r
@@ -34,14 +37,10 @@ import compbio.metadata.JobSubmissionException;
 import compbio.metadata.Limit;\r
 import compbio.metadata.LimitExceededException;\r
 import compbio.metadata.Option;\r
-import compbio.util.Timer;\r
+import compbio.metadata.ResultNotAvailableException;\r
 \r
 public final class WSUtil {\r
 \r
-       private static final String CACHE_KEY = "LIMITS_CACHE";\r
-\r
-       private static Logger log = Logger.getLogger(WSUtil.class);\r
-\r
        public static final void validateJobId(String jobId)\r
                        throws InvalidParameterException {\r
                if (!compbio.engine.client.Util.isValidJobId(jobId)) {\r
@@ -57,7 +56,14 @@ public final class WSUtil {
                        throw new JobSubmissionException(\r
                                        "List of fasta sequences required but not provided! ");\r
                }\r
+               Set<String> names = new HashSet<String>();\r
                for (FastaSequence fs : sequences) {\r
+                       boolean unique = names.add(fs.getId());\r
+                       if (!unique) {\r
+                               throw new JobSubmissionException(\r
+                                               "Input sequences must have unique names! \n"\r
+                                                               + "Sequence " + fs.getId() + " is a duplicate!");\r
+                       }\r
                        if (fs.getLength() == 0) {\r
                                throw new JobSubmissionException(\r
                                                "Sequence must not be empty! Sequence: " + fs.getId()\r
@@ -90,19 +96,31 @@ public final class WSUtil {
        }\r
 \r
        public static <T> String align(List<FastaSequence> sequences,\r
-                       ConfiguredExecutable<T> confExec, WSLogger logger,\r
+                       ConfiguredExecutable<T> confExec, Logger logger,\r
                        String callingMethod, Limit<T> limit)\r
                        throws LimitExceededException, JobSubmissionException {\r
-               Timer timer = Timer.getMilliSecondsTimer();\r
+\r
                if (limit != null && limit.isExceeded(sequences)) {\r
                        throw LimitExceededException.newLimitExceeded(limit, sequences);\r
                }\r
                compbio.runner.Util.writeInput(sequences, confExec);\r
                AsyncExecutor engine = Configurator.getAsyncEngine(confExec);\r
                String jobId = engine.submitJob(confExec);\r
-               if (logger != null) {\r
-                       logger.log(timer, callingMethod, jobId);\r
+               return jobId;\r
+       }\r
+\r
+       public static <T> String analize(List<FastaSequence> sequences,\r
+                       ConfiguredExecutable<T> confExec, Logger log, String method,\r
+                       Limit<T> limit) throws JobSubmissionException {\r
+               if (limit != null && limit.isExceeded(sequences)) {\r
+                       throw LimitExceededException.newLimitExceeded(limit, sequences);\r
                }\r
+               log.debug("Method: " + method + " with task: " + confExec.getTaskId());\r
+\r
+               compbio.runner.Util.writeInput(sequences, confExec);\r
+               AsyncExecutor engine = Configurator.getAsyncEngine(confExec);\r
+               String jobId = engine.submitJob(confExec);\r
+\r
                return jobId;\r
        }\r
 \r
@@ -137,6 +155,17 @@ public final class WSUtil {
                }\r
        }\r
 \r
+       public static <T> ScoreManager getAnnotation(String jobId, Logger log)\r
+                       throws ResultNotAvailableException {\r
+               WSUtil.validateJobId(jobId);\r
+               AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);\r
+               ConfiguredExecutable<T> aacon = (ConfiguredExecutable<T>) asyncEngine\r
+                               .getResults(jobId);\r
+               ScoreManager mas = aacon.getResults();\r
+               log.trace(jobId + " getConservation : " + mas);\r
+               return mas;\r
+       }\r
+\r
        /*\r
         * UNUSED\r
         * \r