use of org.knime.core.data.uri.URIPortObject 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;
}
use of org.knime.core.data.uri.URIPortObject in project GenericKnimeNodes by genericworkflownodes.
the class FileSplitterNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
IURIPortObject input = (IURIPortObject) inData[0];
URIPortObject[] outputs = new URIPortObject[getOutgoing().length];
for (int i = 0; i < outputs.length - 1 && input.getURIContents().size() > i; i++) {
outputs[i] = new URIPortObject(Arrays.asList(input.getURIContents().get(i)));
}
if (input.getURIContents().size() > getOutgoing().length - 1) {
outputs[outputs.length - 1] = new URIPortObject(input.getURIContents().subList(outputs.length - 1, input.getURIContents().size()));
} else {
for (int i = input.getURIContents().size(); i < outputs.length; i++) {
outputs[i] = new URIPortObject(new ArrayList<URIContent>());
}
}
return outputs;
}
use of org.knime.core.data.uri.URIPortObject 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 };
}
use of org.knime.core.data.uri.URIPortObject in project GenericKnimeNodes by genericworkflownodes.
the class PortToFileStoreNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
IURIPortObject input = (IURIPortObject) inData[0];
DataContainer dc = exec.createDataContainer(createSpec());
/**
* Files that are not yet managed by KNIME (e.g. when they come from an InputFiles node) come as URIPortObject
* and must be copied into a FileStore to be handled properly.
* Other files already have a file store and can be put into a <code>PortObjectHandlerCell</code>.
*/
if (input instanceof AbstractFileStoreURIPortObject) {
PortObjectHandlerCell cell = new PortObjectHandlerCell((AbstractFileStoreURIPortObject) input);
dc.addRowToTable(new DefaultRow(new RowKey("files"), cell));
} else {
FileStore fs = exec.createFileStore("files");
fs.getFile().mkdirs();
for (URIContent uc : input.getURIContents()) {
String filename = Paths.get(uc.getURI()).getFileName().toString();
if (!filename.endsWith(uc.getExtension())) {
filename = filename.concat(".").concat(uc.getExtension());
}
// TODO: Report progress
Files.copy(Paths.get(uc.getURI()), Paths.get(fs.getFile().toURI()).resolve(filename));
AbstractFileStoreURIPortObject portObject = new FileStoreURIPortObject(fs);
portObject.registerFile(filename);
PortObjectHandlerCell cell = new PortObjectHandlerCell(portObject);
dc.addRowToTable(new DefaultRow(new RowKey(filename), cell));
}
}
dc.close();
return new PortObject[] { (BufferedDataTable) dc.getTable() };
}
use of org.knime.core.data.uri.URIPortObject in project GenericKnimeNodes by genericworkflownodes.
the class ListMimeFileImporterNodeModel method execute.
@Override
protected PortObject[] execute(PortObject[] inObjects, ExecutionContext exec) throws Exception {
String[] filenames = m_filenames.getStringArrayValue();
List<URIContent> uris = new ArrayList<URIContent>();
for (String filename : filenames) {
File in = new File(convertToURL(filename).toURI());
if (!in.canRead()) {
throw new Exception("Cannot read from input file: " + in.getAbsolutePath());
}
uris.add(new URIContent(in.toURI(), (m_file_extension.isActive() ? m_file_extension.getStringValue() : MIMETypeHelper.getMIMEtypeExtension(filename))));
}
return new PortObject[] { new URIPortObject(uris) };
}
Aggregations