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