Search in sources :

Example 1 with CLIElement

use of com.genericworkflownodes.knime.cliwrapper.CLIElement 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 2 with CLIElement

use of com.genericworkflownodes.knime.cliwrapper.CLIElement 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)

Example 3 with CLIElement

use of com.genericworkflownodes.knime.cliwrapper.CLIElement in project GenericKnimeNodes by genericworkflownodes.

the class CLIElementHandler method startElement.

@Override
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
    if (TAG_CLIELEMENT.equals(name)) {
        // we start a new element
        m_currentElement = new CLIElement();
        String isList = attributes.getValue(ATTR_ISLIST);
        m_currentElement.setIsList((isList != null && "true".equals(isList)));
        String isRequired = attributes.getValue(ATTR_REQUIRED);
        m_currentElement.setRequired((isRequired != null && "true".equals(isRequired)));
        m_currentElement.setOptionIdentifier(attributes.getValue(ATTR_OPTION_IDENTIFIER));
    } else if (TAG_MAPPING.equals(name)) {
        CLIMapping mapping = new CLIMapping();
        String refName = attributes.getValue(ATTR_REFNAME);
        mapping.setReferenceName(refName);
        m_currentElement.getMapping().add(mapping);
    }
}
Also used : CLIElement(com.genericworkflownodes.knime.cliwrapper.CLIElement) CLIMapping(com.genericworkflownodes.knime.cliwrapper.CLIMapping)

Example 4 with CLIElement

use of com.genericworkflownodes.knime.cliwrapper.CLIElement in project GenericKnimeNodes by genericworkflownodes.

the class ParamHandler method transferValuesToConfig.

/**
 * Translate all parameters extracted from the ParamXML file into the given
 * INodeConfiguration.
 */
private void transferValuesToConfig() {
    // add parameters
    for (Entry<String, Parameter<?>> entry : m_extractedParameters.entrySet()) {
        m_config.addParameter(entry.getKey(), entry.getValue());
    }
    // set ports
    m_config.setInports(m_inputPorts);
    m_config.setOutports(m_outputPorts);
    // remove cli mappings of ignored parameters
    if (m_config.getCLI() != null && !m_ignoredParameters.isEmpty()) {
        Iterator<CLIElement> element_iterator = m_config.getCLI().getCLIElement().iterator();
        while (element_iterator.hasNext()) {
            CLIElement current_element = element_iterator.next();
            // check the mapping elements
            for (CLIMapping mapping : current_element.getMapping()) {
                if (m_ignoredParameters.contains(mapping.getReferenceName())) {
                    // remove this element and stop the loop
                    element_iterator.remove();
                    break;
                }
            }
        }
    }
}
Also used : CLIElement(com.genericworkflownodes.knime.cliwrapper.CLIElement) FileListParameter(com.genericworkflownodes.knime.parameter.FileListParameter) ListParameter(com.genericworkflownodes.knime.parameter.ListParameter) BoolParameter(com.genericworkflownodes.knime.parameter.BoolParameter) FileParameter(com.genericworkflownodes.knime.parameter.FileParameter) IntegerListParameter(com.genericworkflownodes.knime.parameter.IntegerListParameter) DoubleParameter(com.genericworkflownodes.knime.parameter.DoubleParameter) Parameter(com.genericworkflownodes.knime.parameter.Parameter) StringChoiceParameter(com.genericworkflownodes.knime.parameter.StringChoiceParameter) StringListParameter(com.genericworkflownodes.knime.parameter.StringListParameter) DoubleListParameter(com.genericworkflownodes.knime.parameter.DoubleListParameter) StringParameter(com.genericworkflownodes.knime.parameter.StringParameter) IntegerParameter(com.genericworkflownodes.knime.parameter.IntegerParameter) CLIMapping(com.genericworkflownodes.knime.cliwrapper.CLIMapping)

Example 5 with CLIElement

use of com.genericworkflownodes.knime.cliwrapper.CLIElement in project GenericKnimeNodes by genericworkflownodes.

the class CTDConfigurationWriter method writeCLI.

private void writeCLI() throws IOException {
    streamPut("<cli>");
    indent();
    for (CLIElement elem : currentConfig.getCLI().getCLIElement()) {
        streamPut(String.format("<clielement optionIdentifier=\"%s\" isList=\"%s\">", elem.getOptionIdentifier(), (elem.isList() ? "true" : "false")));
        indent();
        for (CLIMapping mapping : elem.getMapping()) {
            streamPut(String.format("<mapping referenceName=\"%s\" />", mapping.getReferenceName()));
        }
        outdent();
        streamPut("</clielement>");
    }
    outdent();
    streamPut("</cli>");
}
Also used : CLIElement(com.genericworkflownodes.knime.cliwrapper.CLIElement) CLIMapping(com.genericworkflownodes.knime.cliwrapper.CLIMapping)

Aggregations

CLIElement (com.genericworkflownodes.knime.cliwrapper.CLIElement)7 CLIMapping (com.genericworkflownodes.knime.cliwrapper.CLIMapping)3 INodeConfiguration (com.genericworkflownodes.knime.config.INodeConfiguration)2 CTDHandler (com.genericworkflownodes.knime.config.reader.handler.CTDHandler)2 TestDataSource (com.genericworkflownodes.knime.test.data.TestDataSource)2 SAXParser (javax.xml.parsers.SAXParser)2 SAXParserFactory (javax.xml.parsers.SAXParserFactory)2 Test (org.junit.Test)2 CommandLineElement (com.genericworkflownodes.knime.commandline.CommandLineElement)1 CommandLineFixedString (com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString)1 CTDConfigurationReader (com.genericworkflownodes.knime.config.reader.CTDConfigurationReader)1 BoolParameter (com.genericworkflownodes.knime.parameter.BoolParameter)1 DoubleListParameter (com.genericworkflownodes.knime.parameter.DoubleListParameter)1 DoubleParameter (com.genericworkflownodes.knime.parameter.DoubleParameter)1 FileListParameter (com.genericworkflownodes.knime.parameter.FileListParameter)1 FileParameter (com.genericworkflownodes.knime.parameter.FileParameter)1 IntegerListParameter (com.genericworkflownodes.knime.parameter.IntegerListParameter)1 IntegerParameter (com.genericworkflownodes.knime.parameter.IntegerParameter)1 ListParameter (com.genericworkflownodes.knime.parameter.ListParameter)1 Parameter (com.genericworkflownodes.knime.parameter.Parameter)1