Search in sources :

Example 1 with IridaWorkflowLoadException

use of ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowLoadException in project irida by phac-nml.

the class IridaWorkflowLoaderService method loadWorkflowDescription.

/**
 * Loads up the workflow description from the given file.
 *
 * @param descriptionFile
 *            The file to load up a workflow description.
 * @return An IridaWorkflowDescription object.
 * @throws IOException
 *             If there was an issue reading the passed file.
 * @throws IridaWorkflowLoadException
 *             If there was an issue loading up the workflow description.
 */
public IridaWorkflowDescription loadWorkflowDescription(Path descriptionFile) throws IOException, IridaWorkflowLoadException {
    checkNotNull(descriptionFile, "descriptionFile is null");
    if (!Files.exists(descriptionFile)) {
        throw new FileNotFoundException(descriptionFile.toAbsolutePath().toString());
    }
    Source source = new StreamSource(Files.newInputStream(descriptionFile));
    IridaWorkflowDescription workflowDescription = (IridaWorkflowDescription) workflowDescriptionUnmarshaller.unmarshal(source);
    if (workflowDescription.getId() == null) {
        throw new IridaWorkflowLoadException("No id for workflow description from file " + descriptionFile);
    } else if (workflowDescription.getAnalysisType() == null) {
        throw new IridaWorkflowLoadException("Invalid analysisType for workflow description from file " + descriptionFile);
    } else {
        if (workflowDescription.acceptsParameters()) {
            for (IridaWorkflowParameter workflowParameter : workflowDescription.getParameters()) {
                if (workflowParameter.getDefaultValue() == null && !workflowParameter.isRequired()) {
                    throw new IridaWorkflowLoadException("Parameters with no default value must set the \"required\" attribute to \"true\"." + descriptionFile);
                }
                if (workflowParameter.hasDynamicSource() && !workflowParameter.isRequired()) {
                    throw new IridaWorkflowLoadException("Parameters loaded from Dynamic Sources must set the \"required\" attribute to \"true\"." + descriptionFile);
                }
                if (workflowParameter.isRequired() && workflowParameter.getDefaultValue() != null) {
                    throw new IridaWorkflowLoadException("Required parameters should not have a default value." + descriptionFile);
                }
                try {
                    workflowParameter.getDynamicSource();
                } catch (IridaWorkflowParameterException e) {
                    throw new IridaWorkflowLoadException("Parameters may have no more than one Dynamic Source." + descriptionFile);
                }
            }
        }
        return workflowDescription;
    }
}
Also used : IridaWorkflowParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter) StreamSource(javax.xml.transform.stream.StreamSource) FileNotFoundException(java.io.FileNotFoundException) IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) IridaWorkflowLoadException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowLoadException) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) IridaWorkflowParameterException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowParameterException)

Aggregations

IridaWorkflowLoadException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowLoadException)1 IridaWorkflowParameterException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowParameterException)1 IridaWorkflowDescription (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription)1 IridaWorkflowParameter (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter)1 FileNotFoundException (java.io.FileNotFoundException)1 Source (javax.xml.transform.Source)1 StreamSource (javax.xml.transform.stream.StreamSource)1