/* Copyright (c) 2009 Peter Troshin * * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.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 * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache * License for more details. * * A copy of the license is in apache_license.txt. It is also available here: * @see: http://www.apache.org/licenses/LICENSE-2.0.txt * * Any republication or derived work distributed in source code form * must include this copyright and license notice. */ package compbio.ws.server; import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.List; import compbio.data.sequence.FastaSequence; import compbio.engine.AsyncExecutor; import compbio.engine.Configurator; import compbio.engine.ProgressGetter; import compbio.engine.client.ConfiguredExecutable; import compbio.metadata.ChunkHolder; import compbio.metadata.JobStatus; import compbio.metadata.JobSubmissionException; import compbio.metadata.Limit; import compbio.metadata.LimitExceededException; import compbio.metadata.Option; import compbio.util.Timer; public final class WSUtil { public static final void validateJobId(String jobId) throws InvalidParameterException { if (!compbio.engine.client.Util.isValidJobId(jobId)) { throw new InvalidParameterException( "JobId is not provided or cannot be recognised! Given value: " + jobId); } } public static final void validateFastaInput(List sequences) throws InvalidParameterException { if (sequences == null || sequences.isEmpty()) { throw new InvalidParameterException( "List of fasta sequences required but not provided! "); } } public static JobStatus getJobStatus(String jobId) { AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId); return asyncEngine.getJobStatus(jobId); } public static ChunkHolder pullFile(String file, long position) { return ProgressGetter.pull(file, position); } public static byte getProgress(String jobId) { throw new UnsupportedOperationException(); } public static AsyncExecutor getEngine(ConfiguredExecutable confClustal) { assert confClustal != null; return Configurator.getAsyncEngine(confClustal); } public static boolean cancelJob(String jobId) { AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId); return asyncEngine.cancelJob(jobId); } public static String align(List sequences, ConfiguredExecutable confExec, WSLogger 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); } return jobId; } /* * TODO Rewrite using purely CommandBuilder. This is breaking encapsulation */ public static final List getCommands(List> options, String keyValueSeparator) { List oList = new ArrayList(); for (Option o : options) { oList.add(o.toCommand(keyValueSeparator)); } return oList; } }