Re-design the ServiceStatus JSP page
[jabaws.git] / webservices / compbio / ws / server / WSUtil.java
index fb96de8..07d005d 100644 (file)
@@ -38,6 +38,8 @@ import compbio.metadata.Limit;
 import compbio.metadata.LimitExceededException;\r
 import compbio.metadata.Option;\r
 import compbio.metadata.ResultNotAvailableException;\r
+import compbio.ws.client.Services;\r
+import compbio.ws.client.ServicesUtil;\r
 \r
 public final class WSUtil {\r
 \r
@@ -106,8 +108,19 @@ public final class WSUtil {
                compbio.runner.Util.writeInput(sequences, confExec);\r
                AsyncExecutor engine = Configurator.getAsyncEngine(confExec);\r
                String jobId = engine.submitJob(confExec);\r
+               reportUsage(confExec, logger);\r
                return jobId;\r
        }\r
+       \r
+\r
+       static <T> void reportUsage(ConfiguredExecutable<T> confExec, Logger logger) {\r
+               if (GAUtils.IS_GA_ENABLED) {\r
+                       Services service = ServicesUtil.getServiceByRunner(confExec\r
+                                       .getExecutable().getClass());\r
+                       GAUtils.reportUsage(service);\r
+                       logger.info("Reporting GA usage for " + service);\r
+               }\r
+       }\r
 \r
        public static <T> String analize(List<FastaSequence> sequences,\r
                        ConfiguredExecutable<T> confExec, Logger log, String method,\r
@@ -116,11 +129,29 @@ public final class WSUtil {
                        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
+               reportUsage(confExec, log);\r
+               return jobId;\r
+       }\r
+       \r
+       // Same as analize but Alifold takes clustal input not fasta\r
+       // An if condition in the above method might be a better solution but \r
+       // you need a way of finding out the type of confExec at runtime\r
+       \r
+       public static <T> String fold(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
+               // This line is different from the above method\r
+               compbio.runner.Util.writeClustalInput(sequences, confExec, '-');\r
+               AsyncExecutor engine = Configurator.getAsyncEngine(confExec);\r
+               String jobId = engine.submitJob(confExec);\r
+               reportUsage(confExec, log);\r
                return jobId;\r
        }\r
 \r
@@ -147,10 +178,28 @@ public final class WSUtil {
                        }\r
                        if (fs.getLength() != len) {\r
                                throw new JobSubmissionException(\r
-                                               "All sequences must be of the same length. Please align "\r
-                                                               + "the sequences prior to submission! The first sequence length is : "\r
-                                                               + len + " but the sequence '" + fs.getId()\r
-                                                               + "' length is " + fs.getLength());\r
+                                               "All sequences must be of the same length. Please align the sequences " + \r
+                                               " prior to submission! The first sequence length is : " + len + \r
+                                               " but the sequence '" + fs.getId() + "' length is " + fs.getLength());\r
+                       }\r
+               }\r
+       }\r
+\r
+       public static void validateJpredInput(List<FastaSequence> sequences)\r
+                       throws JobSubmissionException {\r
+               validateFastaInput(sequences);\r
+               int len = 0;\r
+               for (FastaSequence fs : sequences) {\r
+                       if (len == 0) {\r
+                               len = fs.getLength();\r
+                               continue;\r
+                       }\r
+                       if (fs.getLength() != len) {\r
+                               System.out.println("FASTA rec: id = " + fs.getId() + ": seq = " + fs.getSequence());\r
+                               throw new JobSubmissionException(\r
+                                               "All sequences must be of the same length. Please align the sequences " + \r
+                                               " prior to submission! The first sequence length is : " + len + \r
+                                               " but the sequence '" + fs.getId() + "' length is " + fs.getLength());\r
                        }\r
                }\r
        }\r
@@ -159,12 +208,13 @@ public final class WSUtil {
                        throws ResultNotAvailableException {\r
                WSUtil.validateJobId(jobId);\r
                AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);\r
-               ConfiguredExecutable<T> aacon = (ConfiguredExecutable<T>) asyncEngine\r
-                               .getResults(jobId);\r
+               ConfiguredExecutable<T> aacon = (ConfiguredExecutable<T>) asyncEngine.getResults(jobId);\r
                ScoreManager mas = aacon.getResults();\r
+               \r
                log.trace(jobId + " getConservation : " + mas);\r
                return mas;\r
        }\r
+       \r
 \r
        /*\r
         * UNUSED\r