Search in sources :

Example 1 with CTDHandler

use of com.genericworkflownodes.knime.config.reader.handler.CTDHandler in project GenericKnimeNodes by genericworkflownodes.

the class CTDHandlerTest method testParamHandler.

@Test
public void testParamHandler() throws ParserConfigurationException, SAXException, IOException {
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema ctdSchema = schemaFactory.newSchema(SchemaProvider.class.getResource("CTD.xsd"));
    SAXParserFactory spfac = SAXParserFactory.newInstance();
    spfac.setValidating(false);
    spfac.setSchema(ctdSchema);
    // Now use the parser factory to create a SAXParser object
    SAXParser sp = spfac.newSAXParser();
    CTDHandler handler = new CTDHandler(sp.getXMLReader());
    sp.parse(TestDataSource.class.getResourceAsStream("FileFilter.ctd"), handler);
    INodeConfiguration config = handler.getNodeConfiguration();
    StringParameter mz = (StringParameter) config.getParameter("FileFilter.1.mz");
    assertEquals("m/z range to extract (applies to ALL ms levels!)", mz.getDescription());
    assertEquals(":", mz.getValue());
    assertEquals("mz", mz.getKey());
    IntegerListParameter levels = (IntegerListParameter) config.getParameter("FileFilter.1.peak_options.level");
    assertEquals("MS levels to extract", levels.getDescription());
    assertEquals(3, levels.getValue().size());
    assertEquals(1, levels.getValue().get(0).intValue());
    assertEquals(2, levels.getValue().get(1).intValue());
    assertEquals(3, levels.getValue().get(2).intValue());
    assertEquals(false, levels.isAdvanced());
    StringChoiceParameter int_precision = (StringChoiceParameter) config.getParameter("FileFilter.1.peak_options.int_precision");
    assertEquals("32", int_precision.getValue());
    assertEquals(3, int_precision.getAllowedValues().size());
    BoolParameter no_progress = (BoolParameter) config.getParameter("FileFilter.1.no_progress");
    assertEquals(false, no_progress.getValue());
    assertEquals(true, no_progress.isAdvanced());
    assertEquals(3, config.getInputPorts().size());
    assertEquals("FileFilter.1.in", config.getInputPorts().get(0).getName());
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) StringParameter(com.genericworkflownodes.knime.parameter.StringParameter) Schema(javax.xml.validation.Schema) CTDHandler(com.genericworkflownodes.knime.config.reader.handler.CTDHandler) TestDataSource(com.genericworkflownodes.knime.test.data.TestDataSource) INodeConfiguration(com.genericworkflownodes.knime.config.INodeConfiguration) SchemaProvider(com.genericworkflownodes.knime.schemas.SchemaProvider) SAXParser(javax.xml.parsers.SAXParser) StringChoiceParameter(com.genericworkflownodes.knime.parameter.StringChoiceParameter) IntegerListParameter(com.genericworkflownodes.knime.parameter.IntegerListParameter) BoolParameter(com.genericworkflownodes.knime.parameter.BoolParameter) SAXParserFactory(javax.xml.parsers.SAXParserFactory) Test(org.junit.Test)

Example 2 with CTDHandler

use of com.genericworkflownodes.knime.config.reader.handler.CTDHandler in project GenericKnimeNodes by genericworkflownodes.

the class CTDHandlerTest method testCTDHandler.

@Test
public void testCTDHandler() throws ParserConfigurationException, SAXException, IOException {
    SAXParserFactory spfac = SAXParserFactory.newInstance();
    // Now use the parser factory to create a SAXParser object
    SAXParser sp = spfac.newSAXParser();
    CTDHandler handler = new CTDHandler(sp.getXMLReader());
    sp.parse(TestDataSource.class.getResourceAsStream("test5.ctd"), handler);
    INodeConfiguration config = handler.getNodeConfiguration();
    assertEquals(2, config.getCLI().getCLIElement().size());
    CLIElement firstCLIElement = config.getCLI().getCLIElement().get(0);
    assertEquals("-i", firstCLIElement.getOptionIdentifier());
    assertEquals(false, firstCLIElement.isList());
    assertEquals(false, firstCLIElement.isRequired());
    assertEquals(1, firstCLIElement.getMapping().size());
    assertEquals("blastall.i", firstCLIElement.getMapping().get(0).getReferenceName());
    CLIElement secondCLIElement = config.getCLI().getCLIElement().get(1);
    assertEquals("-d", secondCLIElement.getOptionIdentifier());
    assertEquals(false, secondCLIElement.isList());
    assertEquals(false, secondCLIElement.isRequired());
    assertEquals(1, secondCLIElement.getMapping().size());
    assertEquals("blastall.d", secondCLIElement.getMapping().get(0).getReferenceName());
}
Also used : CTDHandler(com.genericworkflownodes.knime.config.reader.handler.CTDHandler) TestDataSource(com.genericworkflownodes.knime.test.data.TestDataSource) CLIElement(com.genericworkflownodes.knime.cliwrapper.CLIElement) INodeConfiguration(com.genericworkflownodes.knime.config.INodeConfiguration) SAXParser(javax.xml.parsers.SAXParser) SAXParserFactory(javax.xml.parsers.SAXParserFactory) Test(org.junit.Test)

Example 3 with CTDHandler

use of com.genericworkflownodes.knime.config.reader.handler.CTDHandler in project GenericKnimeNodes by genericworkflownodes.

the class CTDConfigurationReader method read.

@Override
public INodeConfiguration read(InputStream in) throws InvalidCTDFileException {
    try {
        // create schema and parser for validation and parsing
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema ctdSchema = schemaFactory.newSchema(SchemaProvider.class.getResource("CTD.xsd"));
        SAXParserFactory spfac = SAXParserFactory.newInstance();
        spfac.setValidating(false);
        spfac.setSchema(ctdSchema);
        SAXParser sp = spfac.newSAXParser();
        CTDHandler handler = new CTDHandler(sp.getXMLReader());
        sp.parse(in, handler);
        m_config = handler.getNodeConfiguration();
    } catch (Exception e) {
        throw new InvalidCTDFileException("Failed to parse CTD file.", e);
    }
    // validate mappings of CLI config
    for (CLIElement cliElement : m_config.getCLI().getCLIElement()) {
        validateCLIElement(cliElement);
    }
    // validate mappings in OutputConverter
    for (Relocator relocator : m_config.getRelocators()) {
        validateRelocator(relocator);
    }
    // validate ports
    for (Port port : m_config.getInputPorts()) {
        validatePort(port);
    }
    for (Port port : m_config.getOutputPorts()) {
        validatePort(port);
    }
    // return parsed and validated config
    return m_config;
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) Schema(javax.xml.validation.Schema) CTDHandler(com.genericworkflownodes.knime.config.reader.handler.CTDHandler) CLIElement(com.genericworkflownodes.knime.cliwrapper.CLIElement) Port(com.genericworkflownodes.knime.port.Port) SchemaProvider(com.genericworkflownodes.knime.schemas.SchemaProvider) SAXParser(javax.xml.parsers.SAXParser) Relocator(com.genericworkflownodes.knime.relocator.Relocator) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

CTDHandler (com.genericworkflownodes.knime.config.reader.handler.CTDHandler)3 SAXParser (javax.xml.parsers.SAXParser)3 SAXParserFactory (javax.xml.parsers.SAXParserFactory)3 CLIElement (com.genericworkflownodes.knime.cliwrapper.CLIElement)2 INodeConfiguration (com.genericworkflownodes.knime.config.INodeConfiguration)2 SchemaProvider (com.genericworkflownodes.knime.schemas.SchemaProvider)2 TestDataSource (com.genericworkflownodes.knime.test.data.TestDataSource)2 Schema (javax.xml.validation.Schema)2 SchemaFactory (javax.xml.validation.SchemaFactory)2 Test (org.junit.Test)2 BoolParameter (com.genericworkflownodes.knime.parameter.BoolParameter)1 IntegerListParameter (com.genericworkflownodes.knime.parameter.IntegerListParameter)1 StringChoiceParameter (com.genericworkflownodes.knime.parameter.StringChoiceParameter)1 StringParameter (com.genericworkflownodes.knime.parameter.StringParameter)1 Port (com.genericworkflownodes.knime.port.Port)1 Relocator (com.genericworkflownodes.knime.relocator.Relocator)1