genericworkflownodes / GenericKnimeNodes

Base package for GenericKnimeNodes
https://github.com/genericworkflownodes/GenericKnimeNodes
Other
15 stars 16 forks source link

Input and Output Nodes should work with workflow relative URIs #104

Closed AlexanderFillbrunn closed 5 years ago

AlexanderFillbrunn commented 9 years ago

KNIME input and output nodes allow files to be specified like this:

knime://knime.workflow/myfile.txt

This saves the file in the workflow directory. This is especially useful for sharing workflows with data files. To use this feature, java.nio.file.Files and the KNIME org.knime.core.util.FileUtil class have to be used to get an output stream:

 protected PortObject[] execute(final PortObject[] inData,
            final ExecutionContext exec) throws Exception {
        URL url = FileUtil.toURL(myfilepath_string);
        Path localPath = FileUtil.resolveToPath(url);
        try (OutputStream os = openStream(localPath, url)) { ... }
        // ...
    }
    private static OutputStream openStream(final Path localPath, final URL url) throws IOException {
        if (localPath != null) {
            return Files.newOutputStream(localPath, StandardOpenOption.CREATE);
        } else {
            OutputStream os = FileUtil.openOutputConnection(url, "PUT").getOutputStream();
            return os;
        }
    }
jpfeuffer commented 8 years ago

See https://github.com/genericworkflownodes/GenericKnimeNodes/pull/141

@AlexanderFillbrunn: Do we NEED to use an OutputStream? In which case should we use one? As you know, we will return URIPortObjects that will be passed to our nodes. Maybe you can have a look at my PR and see if it suffices.

AlexanderFillbrunn commented 8 years ago

Hi, I think you don't need an OutputStream as long as you resolve and handle the URI properly. As far as I know KNIME input and output nodes also support URIs that point to FTP or HTTP resources. I guess this would not work with SeqAn and OpenMS. You should probably check what kind of URI you are dealing with. I will have a look at the FileUtils next week and report back to you.

jpfeuffer commented 8 years ago

Ah I see, yes it seems like you can use remote resources with e.g. the FileReader. With GKN we need local files only. The only thing we could think about, is a quicker way to download remote files for GKN. Currently you need Remote Connection-> List Files -> Download from list -> String to URI -> URI to Port.

jpfeuffer commented 7 years ago

After I updated #141 this works for both In and Output nodes. We discussed an improvement, though. Currently the user has to explicitly write e.g. knime://knime.workflow/... to make use of the feature. Therefore browsing a selection is not possible (the FileChoosers automatically give you the absolute name). It would be nice, if we automatically detect if a file was chosen that contains a knime relative prefix. Also improve Exception handling and abstract things like the OutputFolderView and the conversion of the paths.

rrahn commented 6 years ago

Sorry to ask, but is #141 already in 3.6? It does not seem to work for Input File Nodes.

jpfeuffer commented 6 years ago

Yes, it is not in 3.6 yet. But can you check the nightly update site?

AlexanderFillbrunn commented 5 years ago

141 was superseded by #209, which is merged. Can this issue be closed, then?

jpfeuffer commented 5 years ago

Yes at least I can confirm that it works on nightly.

jpfeuffer commented 5 years ago

@rrahn Please reopen if this does not work for you.

rrahn commented 5 years ago

@jpfeuffer @AlexanderFillbrunn thanks. I'll let you know if I stumble over it.