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());
}
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());
}
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;
}
Aggregations