Search in sources :

Example 11 with URIContent

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

the class FileStoreReferenceURIPortObject method load.

/**
 * Reconstruct the {@link FileStoreReferenceURIPortObject} from the given
 * {@link ModelContentRO}.
 *
 * @param model
 *            The {@link ModelContentRO} from where the object should be
 *            reconstructed.
 * @param spec
 *            The expected {@link PortObjectSpec}.
 * @param exec
 *            The current {@link ExecutionContext}.
 * @throws InvalidSettingsException
 *             Thrown if the content is invalid.
 */
void load(final ModelContentRO model, PortObjectSpec spec, ExecutionMonitor exec) throws InvalidSettingsException {
    List<URIContent> uriContents = new ArrayList<URIContent>();
    List<String> relPaths = new ArrayList<String>();
    List<Integer> fsIndices = new ArrayList<Integer>();
    for (String key : model.keySet()) {
        if (key.startsWith(MODEL_PREFIX)) {
            ModelContentRO child = model.getModelContent(key);
            uriContents.add(URIContent.load(child));
            relPaths.add(child.getString(SETTINGS_KEY_REL_PATH));
            fsIndices.add(child.getInt(SETTINGS_KEY_FS_INDEX));
        }
    }
    m_uriContents = uriContents;
    m_relPaths = relPaths;
    m_fsIndices = fsIndices;
    m_uriPortObjectSpec = (URIPortObjectSpec) spec;
}
Also used : ModelContentRO(org.knime.core.node.ModelContentRO) ArrayList(java.util.ArrayList) URIContent(org.knime.core.data.uri.URIContent)

Example 12 with URIContent

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

the class FileStoreReferenceURIPortObject 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) {
        if (m_fsIndices.get(i) != -1) {
            File fileInNewFileStore = new File(getFileStore(m_fsIndices.get(i)).getFile(), 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()));
        } else {
            relocatedURIContents.add(m_uriContents.get(i));
        }
    }
    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 13 with URIContent

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

the class FileStoreReferenceURIPortObject method create.

/**
 * @param uriPortObjects
 */
public static FileStoreReferenceURIPortObject create(List<IURIPortObject> uriPortObjects) {
    List<URIContent> uriContents = new ArrayList<URIContent>();
    List<String> relPaths = new ArrayList<String>();
    List<Integer> fsIndices = new ArrayList<Integer>();
    List<FileStore> fileStores = new ArrayList<FileStore>();
    for (IURIPortObject po : uriPortObjects) {
        int count = 0;
        for (URIContent uriContent : po.getURIContents()) {
            uriContents.add(uriContent);
            if (po instanceof AbstractFileStoreURIPortObject) {
                AbstractFileStoreURIPortObject afspo = (AbstractFileStoreURIPortObject) po;
                relPaths.add(afspo.getRelativePaths().get(count));
                fileStores.add(afspo.getInternalFileStore());
                fsIndices.add(fileStores.size() - 1);
            } else if (po instanceof FileStoreReferenceURIPortObject) {
                FileStoreReferenceURIPortObject frpo = (FileStoreReferenceURIPortObject) po;
                relPaths.add(frpo.getRelativePath(count));
                // get the old fileStore for the current URIContent
                fileStores.add(frpo.getFileStore(frpo.getFileStoreIndex(count)));
                fsIndices.add(fileStores.size() - 1);
            } else {
                // we add a dummy relative path for (non-FileStore-based) URIPortObjects etc.
                relPaths.add("");
                fsIndices.add(-1);
            }
            ++count;
        }
    }
    return new FileStoreReferenceURIPortObject(uriContents, relPaths, fsIndices, fileStores);
}
Also used : ArrayList(java.util.ArrayList) FileStore(org.knime.core.data.filestore.FileStore) IURIPortObject(org.knime.core.data.uri.IURIPortObject) URIContent(org.knime.core.data.uri.URIContent)

Example 14 with URIContent

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

the class DemanglerNodeModel method execute.

@Override
protected BufferedDataTable[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    BufferedDataContainer container = exec.createDataContainer(demangler.getTableSpec());
    IURIPortObject obj = (IURIPortObject) inObjects[0];
    List<URIContent> uris = obj.getURIContents();
    if (uris.size() == 0) {
        throw new Exception("No URI was supplied in IURIPortObject at input port 0");
    } else if (uris.size() != 1) {
        throw new Exception(String.format("We can only demangle a single file but got %d.", uris.size()));
    }
    URI relURI = uris.get(0).getURI();
    Iterator<DataRow> iter = demangler.demangle(relURI);
    while (iter.hasNext()) {
        container.addRowToTable(iter.next());
    }
    container.close();
    BufferedDataTable out = container.getTable();
    return new BufferedDataTable[] { out };
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) IURIPortObject(org.knime.core.data.uri.IURIPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) URI(java.net.URI) DataRow(org.knime.core.data.DataRow) URIContent(org.knime.core.data.uri.URIContent) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException)

Example 15 with URIContent

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

the class OutputFilesNodeModel method execute.

@Override
protected PortObject[] execute(PortObject[] inObjects, 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 IURIPortObject");
    }
    int idx = 1;
    for (URIContent uri : uris) {
        File in = new File(uri.getURI());
        if (!in.canRead()) {
            throw new Exception("Cannot read file to export: " + in.getAbsolutePath());
        }
        String outfilename = insertIndex(m_filename.getStringValue(), obj.getSpec().getFileExtensions().get(0), idx++);
        File out = new File(outfilename);
        if (out.exists() && !out.canWrite()) {
            throw new Exception("Cannot write to file: " + out.getAbsolutePath());
        } else if (!out.getParentFile().canWrite()) {
            throw new Exception("Cannot write to containing directoy: " + out.getParentFile().getAbsolutePath());
        }
        FileUtils.copyFile(in, out);
    }
    return null;
}
Also used : IURIPortObject(org.knime.core.data.uri.IURIPortObject) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) 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