Search in sources :

Example 1 with ConnectionMonitor

use of org.knime.base.filehandling.remote.files.ConnectionMonitor in project GenericKnimeNodes by genericworkflownodes.

the class MimeDirectoryImporterNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    // Create connection monitor
    final ConnectionMonitor<? extends Connection> monitor = new ConnectionMonitor<>();
    // Create output URI container
    final List<URIContent> uris = new ArrayList<URIContent>();
    try {
        URI directoryUri;
        if (m_connectionInformation != null) {
            exec.setProgress("Connecting to " + m_connectionInformation.toURI());
            // Generate URI to the directory
            directoryUri = new URI(m_connectionInformation.toURI().toString() + NodeUtils.encodePath(m_configuration.getDirectory()));
        } else {
            // Create local URI
            directoryUri = new File(m_configuration.getDirectory()).toURI();
        }
        // Create remote file for directory selection
        final RemoteFile<? extends Connection> file = RemoteFileFactory.createRemoteFile(directoryUri, m_connectionInformation, monitor);
        // List the selected directory
        exec.setProgress("Retrieving list of files");
        listDirectory(file, uris, true, exec, new MutableInteger(0), new MutableInteger(0));
    } finally {
        // Close connections
        monitor.closeAll();
    }
    return new PortObject[] { new URIPortObject(uris) };
}
Also used : URIPortObject(org.knime.core.data.uri.URIPortObject) IURIPortObject(org.knime.core.data.uri.IURIPortObject) MutableInteger(org.knime.core.util.MutableInteger) ConnectionMonitor(org.knime.base.filehandling.remote.files.ConnectionMonitor) ArrayList(java.util.ArrayList) URI(java.net.URI) RemoteFile(org.knime.base.filehandling.remote.files.RemoteFile) File(java.io.File) URIPortObject(org.knime.core.data.uri.URIPortObject) ConnectionInformationPortObject(org.knime.base.filehandling.remote.connectioninformation.port.ConnectionInformationPortObject) IURIPortObject(org.knime.core.data.uri.IURIPortObject) PortObject(org.knime.core.node.port.PortObject) URIContent(org.knime.core.data.uri.URIContent)

Aggregations

File (java.io.File)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 ConnectionInformationPortObject (org.knime.base.filehandling.remote.connectioninformation.port.ConnectionInformationPortObject)1 ConnectionMonitor (org.knime.base.filehandling.remote.files.ConnectionMonitor)1 RemoteFile (org.knime.base.filehandling.remote.files.RemoteFile)1 IURIPortObject (org.knime.core.data.uri.IURIPortObject)1 URIContent (org.knime.core.data.uri.URIContent)1 URIPortObject (org.knime.core.data.uri.URIPortObject)1 PortObject (org.knime.core.node.port.PortObject)1 MutableInteger (org.knime.core.util.MutableInteger)1