Search in sources :

Example 1 with FileStorePrefixURIPortObject

use of com.genericworkflownodes.knime.base.data.port.FileStorePrefixURIPortObject in project GenericKnimeNodes by genericworkflownodes.

the class DynamicGenericNodeModel method transferOutgoingPorts2Config.

/**
 * Creates a list of lists of output files (as {@link URI}s) pointing to the
 * files that will be generated by the executed tool.
 *
 * @param jobdir
 *            The working directory of the executable.
 * @param inData
 *            The input data as {@link PortObject} array
 * @return A list of lists of output files
 * @throws Exception
 *             If the input has an invalid configuration.
 */
private List<PortObject> transferOutgoingPorts2Config(final File jobdir, PortObject[] inData, ExecutionContext exec) throws Exception {
    final int nOut = m_nodeConfig.getOutputPorts().size();
    List<PortObject> outPorts = new ArrayList<PortObject>(nOut);
    for (int i = 0; i < nOut; i++) {
        Port port = m_nodeConfig.getOutputPorts().get(i);
        String name = port.getName();
        String ext = "";
        boolean isPrefix = port.isPrefix();
        if (!isPrefix) {
            ext = getOutputType(i);
        }
        Parameter<?> p = m_nodeConfig.getParameter(name);
        // basenames and number of output files guessed from input
        List<String> basenames = getOutputBaseNames();
        if (p instanceof FileListParameter && port.isMultiFile()) {
            // we currently do not support lists of prefixes
            if (isPrefix) {
                throw new InvalidSettingsException("GKN currently does not support lists of prefixes as output.");
            }
            FileListParameter flp = (FileListParameter) p;
            List<String> fileNames = new ArrayList<String>();
            if (basenames.size() == 0) {
                throw new Exception("Cannot determine number of output files if no input file is given.");
            }
            // if MimeType is "Inactive" just create Empty FileStore(Prefix)URIPortObjects
            PortObject fsupo;
            if (!ext.equals("Inactive")) {
                fsupo = new FileStoreURIPortObject(exec.createFileStore(m_nodeConfig.getName() + "_" + i));
                for (int f = 0; f < basenames.size(); ++f) {
                    // create basename: <base_name>_<port_nr>_<outfile_nr>
                    String file_basename = String.format("%s_%d", basenames.get(f), f);
                    File file = ((FileStoreURIPortObject) fsupo).registerFile(file_basename + "." + ext);
                    fileNames.add(file.getAbsolutePath());
                }
            } else {
                fsupo = InactiveBranchPortObject.INSTANCE;
            }
            // add filled portobject
            outPorts.add(fsupo);
            // overwrite existing settings with new values generated by the
            // stash
            flp.setValue(fileNames);
        } else if (p instanceof FileParameter && !port.isMultiFile()) {
            // if MimeType is "Inactive" just create Empty FileStore(Prefix)URIPortObjects
            PortObject po;
            if (!ext.equals("Inactive")) {
                // if we have no basename to use (e.g., Node without input-file)
                // we use the nodename
                String basename;
                if (basenames.isEmpty()) {
                    basename = m_nodeConfig.getName();
                } else {
                    basename = basenames.get(0);
                }
                // create basename: <base_name>_<outfile_nr>
                String fileName = basename;
                if (!isPrefix) {
                    fileName += '.' + ext;
                }
                if (isPrefix) {
                    po = new FileStorePrefixURIPortObject(exec.createFileStore(m_nodeConfig.getName() + "_" + i), fileName);
                    ((FileParameter) p).setValue(((FileStorePrefixURIPortObject) po).getPrefix());
                    LOGGER.debug("> setting param " + name + "->" + ((FileStorePrefixURIPortObject) po).getPrefix());
                } else {
                    po = new FileStoreURIPortObject(exec.createFileStore(m_nodeConfig.getName() + "_" + i));
                    // we do not append the file extension if we have a prefix
                    File file = ((FileStoreURIPortObject) po).registerFile(fileName);
                    ((FileParameter) p).setValue(file.getAbsolutePath());
                    LOGGER.debug("> setting param " + name + "->" + file);
                }
            } else {
                po = InactiveBranchPortObject.INSTANCE;
            }
            // remember output file
            outPorts.add(po);
        } else {
            throw new Exception("Invalid connection between ports and parameters.");
        }
    }
    return outPorts;
}
Also used : FileListParameter(com.genericworkflownodes.knime.parameter.FileListParameter) FileStoreURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStoreURIPortObject) Port(com.genericworkflownodes.knime.port.Port) ArrayList(java.util.ArrayList) FileStorePrefixURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStorePrefixURIPortObject) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) InvalidParameterValueException(com.genericworkflownodes.knime.parameter.InvalidParameterValueException) ExecutionFailedException(com.genericworkflownodes.knime.generic_node.ExecutionFailedException) 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) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) FileParameter(com.genericworkflownodes.knime.parameter.FileParameter) IFileParameter(com.genericworkflownodes.knime.parameter.IFileParameter) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) IURIPortObject(org.knime.core.data.uri.IURIPortObject) IPrefixURIPortObject(com.genericworkflownodes.knime.base.data.port.IPrefixURIPortObject) FileStorePrefixURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStorePrefixURIPortObject) PortObject(org.knime.core.node.port.PortObject) FileStoreURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStoreURIPortObject) File(java.io.File)

Example 2 with FileStorePrefixURIPortObject

use of com.genericworkflownodes.knime.base.data.port.FileStorePrefixURIPortObject in project GenericKnimeNodes by genericworkflownodes.

the class DynamicGenericNodeModel method execute.

@Override
protected PortObject[] execute(PortObject[] inObjects, ExecutionContext execContext) throws Exception {
    // create job directory
    File jobdir = Helper.getTempDir(m_nodeConfig.getName(), !GenericNodesPlugin.isDebug());
    // transfer the incoming files into the nodeConfiguration
    transferIncomingPorts2Config(inObjects);
    // prepare input data and parameter values
    List<PortObject> outPorts = transferOutgoingPorts2Config(jobdir, inObjects, execContext);
    // prepare the executor
    m_executor = prepareExecutor(jobdir);
    // launch executable
    executeTool(m_executor, execContext);
    if (!GenericNodesPlugin.isDebug()) {
        FileUtils.deleteDirectory(jobdir);
    }
    PortObject[] outports = new PortObject[outPorts.size()];
    for (int i = 0; i < outPorts.size(); ++i) {
        outports[i] = outPorts.get(i);
        // if we have an prefix port we need to trigger reindexing
        if (outports[i] instanceof FileStorePrefixURIPortObject) {
            ((FileStorePrefixURIPortObject) outports[i]).collectFiles();
        }
    }
    return outports;
}
Also used : FileStorePrefixURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStorePrefixURIPortObject) File(java.io.File) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) IURIPortObject(org.knime.core.data.uri.IURIPortObject) IPrefixURIPortObject(com.genericworkflownodes.knime.base.data.port.IPrefixURIPortObject) FileStorePrefixURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStorePrefixURIPortObject) PortObject(org.knime.core.node.port.PortObject) FileStoreURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStoreURIPortObject)

Example 3 with FileStorePrefixURIPortObject

use of com.genericworkflownodes.knime.base.data.port.FileStorePrefixURIPortObject in project GenericKnimeNodes by genericworkflownodes.

the class GenericKnimeNodeModel method execute.

@Override
protected PortObject[] execute(PortObject[] inObjects, ExecutionContext execContext) throws Exception {
    // create job directory
    File jobdir = Helper.getTempDir(m_nodeConfig.getName(), !GenericNodesPlugin.isDebug());
    // transfer the incoming files into the nodeConfiguration
    transferIncomingPorts2Config(inObjects);
    // prepare input data and parameter values
    List<PortObject> outPorts = transferOutgoingPorts2Config(jobdir, inObjects, execContext);
    // prepare the executor
    m_executor = prepareExecutor(jobdir);
    // launch executable
    executeTool(m_executor, execContext);
    if (!GenericNodesPlugin.isDebug()) {
        FileUtils.deleteDirectory(jobdir);
    }
    PortObject[] outports = new PortObject[outPorts.size()];
    for (int i = 0; i < outPorts.size(); ++i) {
        outports[i] = outPorts.get(i);
        // if we have an prefix port we need to trigger reindexing
        if (outports[i] instanceof FileStorePrefixURIPortObject) {
            ((FileStorePrefixURIPortObject) outports[i]).collectFiles();
        }
    }
    return outports;
}
Also used : FileStorePrefixURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStorePrefixURIPortObject) File(java.io.File) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) IURIPortObject(org.knime.core.data.uri.IURIPortObject) IPrefixURIPortObject(com.genericworkflownodes.knime.base.data.port.IPrefixURIPortObject) FileStorePrefixURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStorePrefixURIPortObject) PortObject(org.knime.core.node.port.PortObject) FileStoreURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStoreURIPortObject)

Example 4 with FileStorePrefixURIPortObject

use of com.genericworkflownodes.knime.base.data.port.FileStorePrefixURIPortObject in project GenericKnimeNodes by genericworkflownodes.

the class GenericKnimeNodeModel method transferOutgoingPorts2Config.

/**
 * Creates a list of lists of output files (as {@link URI}s) pointing to the
 * files that will be generated by the executed tool.
 *
 * @param jobdir
 *            The working directory of the executable.
 * @param inData
 *            The input data as {@link PortObject} array
 * @return A list of lists of output files
 * @throws Exception
 *             If the input has an invalid configuration.
 */
private List<PortObject> transferOutgoingPorts2Config(final File jobdir, PortObject[] inData, ExecutionContext exec) throws Exception {
    final int nOut = m_nodeConfig.getOutputPorts().size();
    List<PortObject> outPorts = new ArrayList<PortObject>(nOut);
    for (int i = 0; i < nOut; i++) {
        Port port = m_nodeConfig.getOutputPorts().get(i);
        // Before we know about its extension, a port is reset to active
        port.setActive(true);
        String name = port.getName();
        String ext = "";
        boolean isPrefix = port.isPrefix();
        if (!isPrefix) {
            ext = getOutputType(i);
        }
        if (ext.toLowerCase().equals("inactive")) {
            port.setActive(false);
            outPorts.add(InactiveBranchPortObject.INSTANCE);
            continue;
        }
        Parameter<?> p = m_nodeConfig.getParameter(name);
        // basenames and number of output files guessed from input
        List<String> basenames = getOutputBaseNames();
        if (p instanceof FileListParameter && port.isMultiFile()) {
            // we currently do not support lists of prefixes
            if (isPrefix) {
                throw new InvalidSettingsException("GKN currently does not support lists of prefixes as output.");
            }
            FileListParameter flp = (FileListParameter) p;
            List<String> fileNames = new ArrayList<String>();
            if (basenames.size() == 0) {
                throw new Exception("Cannot determine number of output files if no input file is given.");
            }
            PortObject fsupo = new FileStoreURIPortObject(exec.createFileStore(m_nodeConfig.getName() + "_" + i));
            for (int f = 0; f < basenames.size(); ++f) {
                // create basename: <base_name>_<port_nr>_<outfile_nr>
                String file_basename = String.format("%s_%d", basenames.get(f), f);
                File file = ((FileStoreURIPortObject) fsupo).registerFile(file_basename + "." + ext);
                fileNames.add(file.getAbsolutePath());
            }
            // add filled portobject
            outPorts.add(fsupo);
            // overwrite existing settings with new values generated by the
            // stash
            flp.setValue(fileNames);
        } else if (p instanceof FileParameter && !port.isMultiFile()) {
            PortObject po;
            // if we have no basename to use (e.g., Node without input-file)
            // we use the nodename
            String basename;
            if (basenames.isEmpty()) {
                basename = m_nodeConfig.getName();
            } else {
                basename = basenames.get(0);
            }
            // create basename: <base_name>_<outfile_nr>
            String fileName = basename;
            if (!isPrefix) {
                fileName += '.' + ext;
            }
            if (isPrefix) {
                po = new FileStorePrefixURIPortObject(exec.createFileStore(m_nodeConfig.getName() + "_" + i), fileName);
                ((FileParameter) p).setValue(((FileStorePrefixURIPortObject) po).getPrefix());
                LOGGER.debug("> setting param " + name + "->" + ((FileStorePrefixURIPortObject) po).getPrefix());
            } else {
                po = new FileStoreURIPortObject(exec.createFileStore(m_nodeConfig.getName() + "_" + i));
                // we do not append the file extension if we have a prefix
                File file = ((FileStoreURIPortObject) po).registerFile(fileName);
                ((FileParameter) p).setValue(file.getAbsolutePath());
                LOGGER.debug("> setting param " + name + "->" + file);
            }
            // remember output file
            outPorts.add(po);
        } else {
            throw new Exception("Invalid connection between ports and parameters.");
        }
    }
    return outPorts;
}
Also used : FileListParameter(com.genericworkflownodes.knime.parameter.FileListParameter) FileStoreURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStoreURIPortObject) Port(com.genericworkflownodes.knime.port.Port) ArrayList(java.util.ArrayList) FileStorePrefixURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStorePrefixURIPortObject) 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) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) FileParameter(com.genericworkflownodes.knime.parameter.FileParameter) IFileParameter(com.genericworkflownodes.knime.parameter.IFileParameter) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) IURIPortObject(org.knime.core.data.uri.IURIPortObject) IPrefixURIPortObject(com.genericworkflownodes.knime.base.data.port.IPrefixURIPortObject) FileStorePrefixURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStorePrefixURIPortObject) PortObject(org.knime.core.node.port.PortObject) FileStoreURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStoreURIPortObject) File(java.io.File)

Aggregations

FileStorePrefixURIPortObject (com.genericworkflownodes.knime.base.data.port.FileStorePrefixURIPortObject)4 FileStoreURIPortObject (com.genericworkflownodes.knime.base.data.port.FileStoreURIPortObject)4 IPrefixURIPortObject (com.genericworkflownodes.knime.base.data.port.IPrefixURIPortObject)4 File (java.io.File)4 IURIPortObject (org.knime.core.data.uri.IURIPortObject)4 PortObject (org.knime.core.node.port.PortObject)4 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)4 NoBinaryAvailableException (com.genericworkflownodes.knime.custom.config.NoBinaryAvailableException)2 UnknownCommandGeneratorException (com.genericworkflownodes.knime.execution.UnknownCommandGeneratorException)2 UnknownToolExecutorException (com.genericworkflownodes.knime.execution.UnknownToolExecutorException)2 FileListParameter (com.genericworkflownodes.knime.parameter.FileListParameter)2 FileParameter (com.genericworkflownodes.knime.parameter.FileParameter)2 IFileParameter (com.genericworkflownodes.knime.parameter.IFileParameter)2 InvalidParameterValueException (com.genericworkflownodes.knime.parameter.InvalidParameterValueException)2 Port (com.genericworkflownodes.knime.port.Port)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 ExecutionFailedException (com.genericworkflownodes.knime.generic_node.ExecutionFailedException)1