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;
}
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;
}
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());
}
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 };
}
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;
}
Aggregations