Search in sources :

Example 1 with URIContent

use of org.knime.core.data.uri.URIContent in project GenericKnimeNodes by genericworkflownodes.

the class ListZipLoopStartNodeModel method execute.

@Override
protected PortObject[] execute(PortObject[] inObjects, ExecutionContext exec) throws InvalidSettingsException {
    // check the loop conditions
    if (m_iteration == 0) {
        assert getLoopEndNode() == null : "1st iteration but end node set";
        // check the content of the different Ports
        if (!m_reuse.getBooleanValue()) {
            int numberOfURIs = ((IURIPortObject) inObjects[0]).getURIContents().size();
            for (int i = 1; i < m_numAssignedIncomingPorts; ++i) {
                if (((IURIPortObject) inObjects[i]).getURIContents().size() != numberOfURIs) {
                    throw new InvalidSettingsException("Invalid settings. The number of URIs at the incoming ports differ.");
                }
            }
        }
    } else {
        assert getLoopEndNode() != null : "No end node set";
    }
    IURIPortObject[] uriOutputObjects = new URIPortObject[PORT_COUNT];
    m_rowCount = ((IURIPortObject) inObjects[0]).getURIContents().size();
    // 1st port is handled separately
    URIContent uri = ((IURIPortObject) inObjects[0]).getURIContents().get(m_iteration);
    List<URIContent> uriContents = new ArrayList<URIContent>();
    uriContents.add(uri);
    uriOutputObjects[0] = new URIPortObject(uriContents);
    for (int i = 1; i < PORT_COUNT; i++) {
        IURIPortObject in = (IURIPortObject) inObjects[i];
        if (i < m_numAssignedIncomingPorts) {
            if (m_reuse.getBooleanValue()) {
                uriOutputObjects[i] = new URIPortObject(in.getURIContents());
            } else {
                List<URIContent> localUriContents = new ArrayList<URIContent>();
                URIContent localUri = in.getURIContents().get(m_iteration);
                localUriContents.add(localUri);
                uriOutputObjects[i] = new URIPortObject(localUriContents);
            }
        } else {
            uriOutputObjects[i] = new URIPortObject(new ArrayList<URIContent>());
        }
    }
    // TODO: check if this is necessary
    pushFlowVariableInt("currentIteration", m_iteration);
    pushFlowVariableInt("maxIterations", m_rowCount);
    // proceed in the number of iterations
    m_iteration++;
    return uriOutputObjects;
}
Also used : IURIPortObject(org.knime.core.data.uri.IURIPortObject) URIPortObject(org.knime.core.data.uri.URIPortObject) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) IURIPortObject(org.knime.core.data.uri.IURIPortObject) ArrayList(java.util.ArrayList) URIContent(org.knime.core.data.uri.URIContent)

Example 2 with URIContent

use of org.knime.core.data.uri.URIContent in project GenericKnimeNodes by genericworkflownodes.

the class AbstractFileStoreURIPortObject method postConstruct.

@Override
protected void postConstruct() throws IOException {
    // call super if they have something todo
    super.postConstruct();
    List<URIContent> relocatedURIContents = new ArrayList<URIContent>();
    // 
    for (int i = 0; i < m_uriContents.size() && i < m_relPaths.size(); ++i) {
        File fileInNewFileStore = new File(getFileStoreRootDirectory(), m_relPaths.get(i));
        if (!fileInNewFileStore.exists()) {
            throw new IOException(String.format("Could not locate file %s in FileStoreURIPortObject.", m_relPaths.get(i)));
        }
        // create new URIContent using the rel path and the old extension
        // infos
        relocatedURIContents.add(new URIContent(fileInNewFileStore.toURI(), m_uriContents.get(i).getExtension()));
    }
    m_uriContents = relocatedURIContents;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) URIContent(org.knime.core.data.uri.URIContent)

Example 3 with URIContent

use of org.knime.core.data.uri.URIContent in project GenericKnimeNodes by genericworkflownodes.

the class PortObjectHandlerCell method postConstruct.

@Override
protected void postConstruct() throws IOException {
    // fix rel-path
    File relocatedFile = new File(getFileStore().getFile(), m_relativePath);
    if (!relocatedFile.exists()) {
        throw new IOException(String.format("Could not locate file %s in PortObjectHandlerCell.", m_relativePath));
    }
    // re-create uricontent
    m_uriContent = new URIContent(relocatedFile.toURI(), m_uriContent.getExtension());
}
Also used : IOException(java.io.IOException) File(java.io.File) URIContent(org.knime.core.data.uri.URIContent)

Example 4 with URIContent

use of org.knime.core.data.uri.URIContent in project GenericKnimeNodes by genericworkflownodes.

the class SplitTableToPortNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataTable input = (BufferedDataTable) inData[0];
    List<URIContent> contents = new ArrayList<>();
    String mimetype = null;
    int index = input.getDataTableSpec().findColumnIndex(m_fileCol.getColumnName());
    for (DataRow row : input) {
        PortObjectHandlerCell cell = (PortObjectHandlerCell) row.getCell(index);
        URIContent uc = cell.getURIContent();
        String mt = MIMETypeHelper.getMIMEtypeByExtension(uc.getExtension());
        if (mimetype == null) {
            mimetype = mt;
        } else if (!mt.equals(mimetype)) {
            throw new InvalidSettingsException("File ports do not support mixed mimetypes.");
        }
        contents.add(uc);
    }
    URIPortObject output = new URIPortObject(contents);
    return new PortObject[] { output };
}
Also used : URIPortObject(org.knime.core.data.uri.URIPortObject) IURIPortObject(org.knime.core.data.uri.IURIPortObject) FileStoreURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStoreURIPortObject) PortObjectHandlerCell(com.genericworkflownodes.knime.base.data.port.PortObjectHandlerCell) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BufferedDataTable(org.knime.core.node.BufferedDataTable) ArrayList(java.util.ArrayList) DataRow(org.knime.core.data.DataRow) URIPortObject(org.knime.core.data.uri.URIPortObject) IURIPortObject(org.knime.core.data.uri.IURIPortObject) PortObject(org.knime.core.node.port.PortObject) FileStoreURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStoreURIPortObject) URIContent(org.knime.core.data.uri.URIContent)

Example 5 with URIContent

use of org.knime.core.data.uri.URIContent in project GenericKnimeNodes by genericworkflownodes.

the class OutputFolderNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    IURIPortObject obj = (IURIPortObject) inObjects[0];
    List<URIContent> uris = obj.getURIContents();
    if (uris.size() == 0) {
        throw new Exception("There were no URIs in the supplied URIPortObject");
    }
    double idx = 1.0;
    for (URIContent uri : uris) {
        File in = new File(uri.getURI());
        if (!in.canRead()) {
            throw new Exception("Cannot read file to export: " + in.getAbsolutePath());
        }
        File target = new File(m_foldername.getStringValue(), in.getName());
        if (target.exists() && !target.canWrite()) {
            throw new Exception("Cannot write to file: " + target.getAbsolutePath());
        } else if (!target.getParentFile().canWrite()) {
            throw new Exception("Cannot write to containing directoy: " + target.getParentFile().getAbsolutePath());
        }
        FileUtils.copyFile(in, target);
        exec.setProgress(idx / uris.size());
        exec.checkCanceled();
    }
    return null;
}
Also used : IURIPortObject(org.knime.core.data.uri.IURIPortObject) File(java.io.File) URIContent(org.knime.core.data.uri.URIContent) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException)

Aggregations

URIContent (org.knime.core.data.uri.URIContent)21 File (java.io.File)13 ArrayList (java.util.ArrayList)13 IURIPortObject (org.knime.core.data.uri.IURIPortObject)13 IOException (java.io.IOException)11 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)10 URIPortObject (org.knime.core.data.uri.URIPortObject)6 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)6 PortObject (org.knime.core.node.port.PortObject)6 URI (java.net.URI)5 BufferedDataTable (org.knime.core.node.BufferedDataTable)4 FileStoreURIPortObject (com.genericworkflownodes.knime.base.data.port.FileStoreURIPortObject)3 IPrefixURIPortObject (com.genericworkflownodes.knime.base.data.port.IPrefixURIPortObject)2 PortObjectHandlerCell (com.genericworkflownodes.knime.base.data.port.PortObjectHandlerCell)2 NoBinaryAvailableException (com.genericworkflownodes.knime.custom.config.NoBinaryAvailableException)2 UnknownCommandGeneratorException (com.genericworkflownodes.knime.execution.UnknownCommandGeneratorException)2 UnknownToolExecutorException (com.genericworkflownodes.knime.execution.UnknownToolExecutorException)2 FileParameter (com.genericworkflownodes.knime.parameter.FileParameter)2 IFileParameter (com.genericworkflownodes.knime.parameter.IFileParameter)2 InvalidParameterValueException (com.genericworkflownodes.knime.parameter.InvalidParameterValueException)2