Search in sources :

Example 6 with IFileParameter

use of com.genericworkflownodes.knime.parameter.IFileParameter in project GenericKnimeNodes by genericworkflownodes.

the class GenericKnimeNodeModel method transferIncomingPorts2Config.

/**
 * Transfers the incoming ports into the config, that it can be written out
 * into a config file or can be transferred to the command line.
 *
 * @param inData
 *            The incoming port objects.
 * @throws Exception
 */
private void transferIncomingPorts2Config(PortObject[] inData) throws Exception {
    // Transfer settings from the input ports into the configuration object
    for (int i = 0; i < inData.length; i++) {
        // find the internal port for this PortObject
        Port port = m_nodeConfig.getInputPorts().get(i);
        IURIPortObject po = (IURIPortObject) inData[i];
        String name = port.getName();
        // find the associated parameter in the configuration
        Parameter<?> p = m_nodeConfig.getParameter(name);
        boolean isMultiFile = port.isMultiFile();
        boolean isPrefix = port.isPrefix();
        // skip optional and unconnected inport ports
        if (inData[i] == null) {
            p.setValue(null);
            continue;
        }
        // connected: check contents
        List<URIContent> uris = po.getURIContents();
        // check validity of subtypes with actual inputs
        if (uris.size() > 1 && (!isMultiFile && !isPrefix)) {
            throw new Exception("IURIPortObject with multiple URIs supplied at single URI port #" + i);
        }
        // port
        if (!(p instanceof IFileParameter)) {
            throw new Exception("Invalid reference from port to non-file parameter. URI port #" + i);
        }
        if (isPrefix) {
            // we pass only the prefix to the tool
            IPrefixURIPortObject puri = (IPrefixURIPortObject) inData[i];
            ((FileParameter) p).setValue(puri.getPrefix());
        } else if (isMultiFile) {
            // we need to collect all filenames and then set them as a batch
            // in the config
            List<String> filenames = new ArrayList<String>();
            for (URIContent uric : uris) {
                URI uri = uric.getURI();
                filenames.add(new File(uri).getAbsolutePath());
            }
            ((FileListParameter) p).setValue(filenames);
        } else {
            // just one filename
            URI uri = uris.get(0).getURI();
            String filename = new File(uri).getAbsolutePath();
            ((FileParameter) p).setValue(filename);
        }
    }
}
Also used : IPrefixURIPortObject(com.genericworkflownodes.knime.base.data.port.IPrefixURIPortObject) Port(com.genericworkflownodes.knime.port.Port) URI(java.net.URI) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) InvalidParameterValueException(com.genericworkflownodes.knime.parameter.InvalidParameterValueException) UnknownToolExecutorException(com.genericworkflownodes.knime.execution.UnknownToolExecutorException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NoBinaryAvailableException(com.genericworkflownodes.knime.custom.config.NoBinaryAvailableException) UnknownCommandGeneratorException(com.genericworkflownodes.knime.execution.UnknownCommandGeneratorException) IFileParameter(com.genericworkflownodes.knime.parameter.IFileParameter) IURIPortObject(org.knime.core.data.uri.IURIPortObject) ArrayList(java.util.ArrayList) List(java.util.List) FileParameter(com.genericworkflownodes.knime.parameter.FileParameter) IFileParameter(com.genericworkflownodes.knime.parameter.IFileParameter) File(java.io.File) URIContent(org.knime.core.data.uri.URIContent)

Example 7 with IFileParameter

use of com.genericworkflownodes.knime.parameter.IFileParameter in project GenericKnimeNodes by genericworkflownodes.

the class CLICommandGenerator method handleListParameter.

private void handleListParameter(final List<List<? extends CommandLineElement>> extractedParameterValues, final ListParameter listParameter) {
    final int nValues = listParameter.getStrings().size();
    final String key = ((Parameter<?>) listParameter).getKey();
    final List<CommandLineElement> tmpList = new LinkedList<CommandLineElement>();
    // there's only one element in the list
    if (nValues > 1) {
        int sequence = 0;
        for (final String value : listParameter.getStrings()) {
            final CommandLineElement commandLineElement;
            if (listParameter instanceof IFileParameter) {
                commandLineElement = new CommandLineFile(new FileParameter(key, value));
            } else {
                commandLineElement = new CommandLineParameter(new StringParameter(key, value));
            }
            commandLineElement.setSequenceNumber(sequence++);
            tmpList.add(commandLineElement);
        }
    } else {
        // only one value in the list, no need to use sequence numbers
        final String value = listParameter.getStrings().get(0);
        if (listParameter instanceof IFileParameter) {
            tmpList.add(new CommandLineFile(new FileParameter(key, value)));
        } else {
            tmpList.add(new CommandLineParameter(new StringParameter(key, value)));
        }
    }
    extractedParameterValues.add(tmpList);
}
Also used : IFileParameter(com.genericworkflownodes.knime.parameter.IFileParameter) StringParameter(com.genericworkflownodes.knime.parameter.StringParameter) CommandLineParameter(com.genericworkflownodes.knime.commandline.impl.CommandLineParameter) CommandLineFile(com.genericworkflownodes.knime.commandline.impl.CommandLineFile) ListParameter(com.genericworkflownodes.knime.parameter.ListParameter) BoolParameter(com.genericworkflownodes.knime.parameter.BoolParameter) FileParameter(com.genericworkflownodes.knime.parameter.FileParameter) CommandLineParameter(com.genericworkflownodes.knime.commandline.impl.CommandLineParameter) StringParameter(com.genericworkflownodes.knime.parameter.StringParameter) Parameter(com.genericworkflownodes.knime.parameter.Parameter) IFileParameter(com.genericworkflownodes.knime.parameter.IFileParameter) CommandLineFixedString(com.genericworkflownodes.knime.commandline.impl.CommandLineFixedString) CommandLineElement(com.genericworkflownodes.knime.commandline.CommandLineElement) FileParameter(com.genericworkflownodes.knime.parameter.FileParameter) IFileParameter(com.genericworkflownodes.knime.parameter.IFileParameter) LinkedList(java.util.LinkedList)

Aggregations

IFileParameter (com.genericworkflownodes.knime.parameter.IFileParameter)7 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)5 FileParameter (com.genericworkflownodes.knime.parameter.FileParameter)3 InvalidParameterValueException (com.genericworkflownodes.knime.parameter.InvalidParameterValueException)3 Port (com.genericworkflownodes.knime.port.Port)3 IPrefixURIPortObject (com.genericworkflownodes.knime.base.data.port.IPrefixURIPortObject)2 NoBinaryAvailableException (com.genericworkflownodes.knime.custom.config.NoBinaryAvailableException)2 UnknownCommandGeneratorException (com.genericworkflownodes.knime.execution.UnknownCommandGeneratorException)2 UnknownToolExecutorException (com.genericworkflownodes.knime.execution.UnknownToolExecutorException)2 File (java.io.File)2 IOException (java.io.IOException)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 IURIPortObject (org.knime.core.data.uri.IURIPortObject)2 URIContent (org.knime.core.data.uri.URIContent)2 URIPortObjectSpec (org.knime.core.data.uri.URIPortObjectSpec)2 CommandLineElement (com.genericworkflownodes.knime.commandline.CommandLineElement)1 CommandLineFile (com.genericworkflownodes.knime.commandline.impl.CommandLineFile)1