X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=webservices%2Fcompbio%2Fws%2Fserver%2FWSUtil.java;h=7341989581a7ddcb0907b40d4460680fbe172716;hb=da8c820a7fb2edecb190589f3dc9c362e57a2f24;hp=9895289706bb08d2c54260d1864f8d615829b7be;hpb=2a269830633463e5016d5c92ed672d9e312c9776;p=jabaws.git diff --git a/webservices/compbio/ws/server/WSUtil.java b/webservices/compbio/ws/server/WSUtil.java index 9895289..7341989 100644 --- a/webservices/compbio/ws/server/WSUtil.java +++ b/webservices/compbio/ws/server/WSUtil.java @@ -1,6 +1,6 @@ -/* Copyright (c) 2009 Peter Troshin +/* Copyright (c) 2011 Peter Troshin * - * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0 + * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0 * * This library is free software; you can redistribute it and/or modify it under the terms of the * Apache License version 2 as published by the Apache Software Foundation @@ -19,11 +19,14 @@ package compbio.ws.server; import java.security.InvalidParameterException; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.apache.log4j.Logger; import compbio.data.sequence.FastaSequence; +import compbio.data.sequence.ScoreManager; import compbio.engine.AsyncExecutor; import compbio.engine.Configurator; import compbio.engine.ProgressGetter; @@ -34,14 +37,12 @@ import compbio.metadata.JobSubmissionException; import compbio.metadata.Limit; import compbio.metadata.LimitExceededException; import compbio.metadata.Option; -import compbio.util.Timer; +import compbio.metadata.ResultNotAvailableException; +import compbio.ws.client.Services; +import compbio.ws.client.ServicesUtil; public final class WSUtil { - private static final String CACHE_KEY = "LIMITS_CACHE"; - - private static Logger log = Logger.getLogger(WSUtil.class); - public static final void validateJobId(String jobId) throws InvalidParameterException { if (!compbio.engine.client.Util.isValidJobId(jobId)) { @@ -52,11 +53,25 @@ public final class WSUtil { } public static final void validateFastaInput(List sequences) - throws InvalidParameterException { + throws JobSubmissionException { if (sequences == null || sequences.isEmpty()) { - throw new InvalidParameterException( + throw new JobSubmissionException( "List of fasta sequences required but not provided! "); } + Set names = new HashSet(); + for (FastaSequence fs : sequences) { + boolean unique = names.add(fs.getId()); + if (!unique) { + throw new JobSubmissionException( + "Input sequences must have unique names! \n" + + "Sequence " + fs.getId() + " is a duplicate!"); + } + if (fs.getLength() == 0) { + throw new JobSubmissionException( + "Sequence must not be empty! Sequence: " + fs.getId() + + " was empty"); + } + } } public static JobStatus getJobStatus(String jobId) { @@ -83,19 +98,41 @@ public final class WSUtil { } public static String align(List sequences, - ConfiguredExecutable confExec, WSLogger logger, + ConfiguredExecutable confExec, Logger logger, String callingMethod, Limit limit) throws LimitExceededException, JobSubmissionException { - Timer timer = Timer.getMilliSecondsTimer(); + if (limit != null && limit.isExceeded(sequences)) { throw LimitExceededException.newLimitExceeded(limit, sequences); } compbio.runner.Util.writeInput(sequences, confExec); AsyncExecutor engine = Configurator.getAsyncEngine(confExec); String jobId = engine.submitJob(confExec); - if (logger != null) { - logger.log(timer, callingMethod, jobId); + reportUsage(confExec, logger); + return jobId; + } + + static void reportUsage(ConfiguredExecutable confExec, Logger logger) { + if (GAUtils.IS_GA_ENABLED) { + Services service = ServicesUtil.getServiceByRunner(confExec + .getExecutable().getClass()); + GAUtils.reportUsage(service); + logger.info("Reporting GA usage for " + service); + } + } + + public static String analize(List sequences, + ConfiguredExecutable confExec, Logger log, String method, + Limit limit) throws JobSubmissionException { + if (limit != null && limit.isExceeded(sequences)) { + throw LimitExceededException.newLimitExceeded(limit, sequences); } + log.debug("Method: " + method + " with task: " + confExec.getTaskId()); + + compbio.runner.Util.writeInput(sequences, confExec); + AsyncExecutor engine = Configurator.getAsyncEngine(confExec); + String jobId = engine.submitJob(confExec); + reportUsage(confExec, log); return jobId; } @@ -111,6 +148,36 @@ public final class WSUtil { return oList; } + public static void validateAAConInput(List sequences) + throws JobSubmissionException { + validateFastaInput(sequences); + int len = 0; + for (FastaSequence fs : sequences) { + if (len == 0) { + len = fs.getLength(); + continue; + } + if (fs.getLength() != len) { + throw new JobSubmissionException( + "All sequences must be of the same length. Please align " + + "the sequences prior to submission! The first sequence length is : " + + len + " but the sequence '" + fs.getId() + + "' length is " + fs.getLength()); + } + } + } + + public static ScoreManager getAnnotation(String jobId, Logger log) + throws ResultNotAvailableException { + WSUtil.validateJobId(jobId); + AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId); + ConfiguredExecutable aacon = (ConfiguredExecutable) asyncEngine + .getResults(jobId); + ScoreManager mas = aacon.getResults(); + log.trace(jobId + " getConservation : " + mas); + return mas; + } + /* * UNUSED *