use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class WorkflowEditor method setInput.
/**
* Sets the editor input, that is, the file that contains the serialized
* workflow manager.
*
* {@inheritDoc}
*/
@Override
protected void setInput(final IEditorInput input) {
LOGGER.debug("Setting input into editor...");
super.setInput(input);
m_origRemoteLocation = null;
if (input instanceof WorkflowManagerInput) {
// metanode and subnode
setWorkflowManagerInput((WorkflowManagerInput) input);
} else if (input instanceof IURIEditorInput) {
File wfFile;
AbstractExplorerFileStore wfFileFileStore = null;
File mountPointRoot = null;
URI uri = ((IURIEditorInput) input).getURI();
if (input instanceof RemoteWorkflowInput) {
m_origRemoteLocation = ((RemoteWorkflowInput) input).getRemoteOriginalLocation();
}
if ("file".equals(uri.getScheme())) {
wfFile = new File(uri);
try {
LocalExplorerFileStore fs = ExplorerFileSystem.INSTANCE.fromLocalFile(wfFile);
if ((fs == null) || (fs.getContentProvider() == null)) {
LOGGER.info("Could not determine mount point root for " + wfFile.getParent() + ", looks like it is a linked resource");
} else {
wfFileFileStore = fs;
mountPointRoot = fs.getContentProvider().getFileStore("/").toLocalFile();
}
} catch (CoreException ex) {
LOGGER.warn("Could not determine mount point root for " + wfFile.getParent() + ": " + ex.getMessage(), ex);
}
} else if (ExplorerFileSystem.SCHEME.equals(uri.getScheme())) {
AbstractExplorerFileStore filestore = ExplorerFileSystem.INSTANCE.getStore(uri);
if (filestore == null) {
LOGGER.error("Could not find filestore for URI " + uri);
openErrorDialogAndCloseEditor("Could not find filestore for URI " + uri);
return;
}
wfFileFileStore = filestore;
try {
wfFile = filestore.toLocalFile();
} catch (CoreException ex) {
LOGGER.error(ex.getMessage(), ex);
openErrorDialogAndCloseEditor(ex.getMessage());
return;
}
if (wfFile == null) {
LOGGER.error("URI " + uri + " is not a local workflow");
openErrorDialogAndCloseEditor("URI " + uri + " is not a local workflow");
return;
}
try {
mountPointRoot = filestore.getContentProvider().getFileStore("/").toLocalFile();
} catch (CoreException ex) {
LOGGER.warn("Could not determine mount point root for " + wfFile.getParent() + ": " + ex.getMessage(), ex);
}
} else {
LOGGER.error("Unsupported scheme for workflow URI: " + uri);
openErrorDialogAndCloseEditor("Unsupported scheme for workflow URI: " + uri);
return;
}
URI oldFileResource = m_fileResource;
WorkflowManagerUI oldManager = m_manager;
final File wfDir = wfFile.getParentFile();
m_fileResource = wfDir.toURI();
LOGGER.debug("Resource File's project: " + m_fileResource);
boolean isEnableAutoSave = true;
try {
if (oldManager != null) {
// doSaveAs called
assert oldFileResource != null;
WorkflowManagerUI managerForOldResource = (WorkflowManagerUI) ProjectWorkflowMap.getWorkflowUI(oldFileResource);
if (m_manager != managerForOldResource) {
throw new IllegalStateException(String.format("Cannot set new input for workflow editor " + "as there was already a workflow manager set (old resource: \"%s\", " + "new resource: \"%s\", old manager: \"%s\", manager to old resource: \"%s\"", oldFileResource, m_fileResource, oldManager, managerForOldResource));
}
ProjectWorkflowMap.replace(m_fileResource, oldManager, oldFileResource);
isEnableAutoSave = m_isAutoSaveAllowed;
} else {
m_manager = (WorkflowManagerUI) ProjectWorkflowMap.getWorkflowUI(m_fileResource);
}
if (m_manager != null) {
// in case the workflow manager was edited somewhere else
if (m_manager.isDirty()) {
markDirty();
}
} else {
File autoSaveDirectory = WorkflowSaveHelper.getAutoSaveDirectory(new ReferencedFile(wfDir));
if (autoSaveDirectory.exists()) {
if (!autoSaveDirectory.isDirectory() || !autoSaveDirectory.canRead()) {
LOGGER.warnWithFormat("Found existing auto-save location to workflow \"%s\" (\"%s\") but %s" + " - disabling auto-save", wfDir.getName(), autoSaveDirectory.getAbsolutePath(), (!autoSaveDirectory.isDirectory() ? "it is not a directory" : "cannot read it"));
isEnableAutoSave = false;
} else {
File parentDir = autoSaveDirectory.getParentFile();
String date = DateFormatUtils.format(autoSaveDirectory.lastModified(), "yyyy-MM-dd HH-mm");
String newName = wfDir.getName() + " (Auto-Save Copy - " + date + ")";
int unique = 1;
File restoredAutoSaveDirectory;
while ((restoredAutoSaveDirectory = new File(parentDir, newName)).exists()) {
newName = wfDir.getName() + " (Auto-Save Copy - " + date + " #" + (unique++) + ")";
}
// this is the file store object to autoSaveDirectory - if we can resolve it
// we use it below in user messages and to do the rename in order to trigger a refresh
// in the explorer tree - if we can't resolve it (dunno why) we use java.io.File operation
AbstractExplorerFileStore autoSaveDirFileStore = null;
AbstractExplorerFileStore restoredAutoSaveDirFileStore = null;
if (wfFileFileStore != null) {
try {
// first parent is workflow dir, parent of that is the workflow group
AbstractExplorerFileStore parFS = wfFileFileStore.getParent().getParent();
AbstractExplorerFileStore temp = parFS.getChild(autoSaveDirectory.getName());
if (autoSaveDirectory.equals(temp.toLocalFile())) {
autoSaveDirFileStore = temp;
}
restoredAutoSaveDirFileStore = parFS.getChild(newName);
} catch (CoreException e) {
LOGGER.warn("Unable to resolve parent file store for \"" + wfFileFileStore + "\"", e);
}
}
int action = openQuestionDialogWhenLoadingWorkflowWithAutoSaveCopy(wfDir.getName(), restoredAutoSaveDirectory.getName());
final boolean openCopy;
switch(action) {
case // Open Copy
0:
openCopy = true;
break;
case // Open Original
1:
openCopy = false;
break;
default:
// Cancel
String error = "Canceling due to auto-save copy conflict";
openErrorDialogAndCloseEditor(error);
throw new OperationCanceledException(error);
}
boolean couldRename = false;
if (autoSaveDirFileStore != null) {
// preferred way to rename, updates explorer tree
try {
autoSaveDirFileStore.move(restoredAutoSaveDirFileStore, EFS.NONE, null);
couldRename = true;
} catch (CoreException e) {
String message = "Could not rename auto-save copy\n" + "from\n " + autoSaveDirFileStore.getMountIDWithFullPath() + "\nto\n " + newName;
LOGGER.error(message, e);
}
} else {
LOGGER.warnWithFormat("Could not resolve explorer file store to \"%s\" - " + "renaming on file system directly", autoSaveDirectory.getAbsolutePath());
// just rename on file system and ignore explorer tree
couldRename = autoSaveDirectory.renameTo(restoredAutoSaveDirectory);
}
if (!couldRename) {
isEnableAutoSave = false;
String message = "Could not rename auto-save copy\n" + "from\n " + autoSaveDirectory.getAbsolutePath() + "\nto\n " + restoredAutoSaveDirectory.getAbsolutePath() + "";
if (openCopy) {
openErrorDialogAndCloseEditor(message);
throw new OperationCanceledException(message);
} else {
MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Auto-Save Rename Problem", message + "\nAuto-Save will be disabled.");
}
}
if (openCopy) {
m_fileResource = restoredAutoSaveDirectory.toURI();
wfFile = new File(restoredAutoSaveDirectory, wfFile.getName());
}
}
}
IWorkbench wb = PlatformUI.getWorkbench();
IProgressService ps = wb.getProgressService();
// this one sets the workflow manager in the editor
LoadWorkflowRunnable loadWorkflowRunnable = new LoadWorkflowRunnable(this, m_origRemoteLocation != null ? m_origRemoteLocation : uri, wfFile, mountPointRoot);
ps.busyCursorWhile(loadWorkflowRunnable);
// non-null if set by workflow runnable above
if (m_manager == null) {
if (loadWorkflowRunnable.hasLoadingBeenCanceled()) {
String cancelError = loadWorkflowRunnable.getLoadingCanceledMessage();
openErrorDialogAndCloseEditor(cancelError);
throw new OperationCanceledException(cancelError);
} else if (loadWorkflowRunnable.getThrowable() != null) {
throw new RuntimeException(loadWorkflowRunnable.getThrowable());
}
}
ProjectWorkflowMap.putWorkflowUI(m_fileResource, m_manager);
}
if (oldManager == null) {
// not null if via doSaveAs
// in any case register as client (also if the workflow was already loaded by another client
ProjectWorkflowMap.registerClientTo(m_fileResource, this);
}
} catch (InterruptedException ie) {
LOGGER.fatal("Workflow loading thread interrupted", ie);
} catch (InvocationTargetException e) {
LOGGER.fatal("Workflow could not be loaded.", e);
}
m_isAutoSaveAllowed = m_parentEditor == null && isEnableAutoSave;
setupAutoSaveSchedule();
m_manuallySetToolTip = null;
updatePartName();
if (getGraphicalViewer() != null) {
loadProperties();
updateTempRemoteWorkflowMessage();
}
// update Actions, as now there's everything available
updateActions();
} else {
throw new IllegalArgumentException("Unsupported editor input: " + input.getClass());
}
}
use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class BufferedDataTable method loadFromFile.
/**
* Factory method to restore a table that has been written using
* the save method.
* @param dirRef The directory to load from.
* @param settings The settings to load from.
* @param exec The exec mon for progress/cancel
* @param tblRep The table repository
* @param bufferRep The buffer repository (needed for blobs).
* @param fileStoreHandlerRepository ...
* @return The table as written by save.
* @throws IOException If reading fails.
* @throws CanceledExecutionException If canceled.
* @throws InvalidSettingsException If settings are invalid.
*/
static BufferedDataTable loadFromFile(final ReferencedFile dirRef, final NodeSettingsRO settings, final ExecutionMonitor exec, final Map<Integer, BufferedDataTable> tblRep, final HashMap<Integer, ContainerTable> bufferRep, final FileStoreHandlerRepository fileStoreHandlerRepository) throws IOException, CanceledExecutionException, InvalidSettingsException {
File dir = dirRef.getFile();
NodeSettingsRO s;
// in version 1.1.x and before, the information was stored in
// an external data.xml (directly in the node dir)
boolean isVersion11x;
File dataXML = new File(dir, TABLE_DESCRIPTION_FILE);
// loading an exported workflow without data
if (!dataXML.exists() && settings == null) {
throw new IOException("No such data file: " + dataXML.getAbsolutePath());
}
DataTableSpec spec;
if (dataXML.exists()) {
// version 1.2.0 and later
s = NodeSettings.loadFromXML(new BufferedInputStream(new FileInputStream(dataXML)));
spec = loadSpec(dirRef);
isVersion11x = false;
} else {
// version 1.1.x
s = settings.getNodeSettings(CFG_TABLE_META);
// needs to be read from zip file!
spec = null;
isVersion11x = true;
}
int id = s.getInt(CFG_TABLE_ID);
LAST_ID.set(Math.max(LAST_ID.get(), id + 1));
String fileName = s.getString(CFG_TABLE_FILE_NAME);
ReferencedFile fileRef;
if (fileName != null) {
fileRef = new ReferencedFile(dirRef, fileName);
File file = fileRef.getFile();
if (!file.exists()) {
throw new IOException("No such data file: " + fileRef);
}
if (!file.isFile() || !file.canRead()) {
throw new IOException("Cannot read file " + fileRef);
}
} else {
// for instance for a column filter node this is null.
fileRef = null;
}
String tableType = s.getString(CFG_TABLE_TYPE);
BufferedDataTable t;
if (tableType.equals(TABLE_TYPE_REFERENCE_IN_SAME_NODE)) {
t = tblRep.get(id);
if (t == null) {
throw new InvalidSettingsException("Table reference with ID " + id + " not found in load map");
}
return t;
} else if (tableType.equals(TABLE_TYPE_CONTAINER)) {
ContainerTable fromContainer;
if (isVersion11x) {
fromContainer = DataContainer.readFromZip(fileRef.getFile());
} else {
fromContainer = BufferedDataContainer.readFromZipDelayed(fileRef, spec, id, bufferRep, fileStoreHandlerRepository);
}
t = new BufferedDataTable(fromContainer, id);
} else {
String[] referenceDirs;
// (no concatenate table in those versions)
if (s.containsKey("table_reference")) {
String refDir = s.getString("table_reference");
referenceDirs = refDir == null ? new String[0] : new String[] { refDir };
} else {
referenceDirs = s.getStringArray(CFG_TABLE_REFERENCE);
}
for (String reference : referenceDirs) {
if (reference == null) {
throw new InvalidSettingsException("Reference dir is \"null\"");
}
ReferencedFile referenceDirRef = new ReferencedFile(dirRef, reference);
loadFromFile(referenceDirRef, s, exec, tblRep, bufferRep, fileStoreHandlerRepository);
}
if (tableType.equals(TABLE_TYPE_REARRANGE_COLUMN)) {
t = new BufferedDataTable(new RearrangeColumnsTable(fileRef, s, tblRep, spec, id, bufferRep, fileStoreHandlerRepository));
} else if (tableType.equals(TABLE_TYPE_JOINED)) {
JoinedTable jt = JoinedTable.load(s, spec, tblRep);
t = new BufferedDataTable(jt);
} else if (tableType.equals(TABLE_TYPE_VOID)) {
VoidTable jt = VoidTable.load(spec);
t = new BufferedDataTable(jt);
} else if (tableType.equals(TABLE_TYPE_CONCATENATE)) {
ConcatenateTable ct = ConcatenateTable.load(s, spec, tblRep);
t = new BufferedDataTable(ct);
} else if (tableType.equals(TABLE_TYPE_WRAPPED)) {
WrappedTable wt = WrappedTable.load(s, tblRep);
t = new BufferedDataTable(wt);
} else if (tableType.equals(TABLE_TYPE_NEW_SPEC)) {
TableSpecReplacerTable replTable;
if (isVersion11x) {
replTable = TableSpecReplacerTable.load11x(fileRef.getFile(), s, tblRep);
} else {
replTable = TableSpecReplacerTable.load(s, spec, tblRep);
}
t = new BufferedDataTable(replTable);
} else if (tableType.equals(TABLE_TYPE_EXTENSION)) {
ExtensionTable et = ExtensionTable.loadExtensionTable(fileRef, spec, s, tblRep, exec);
t = new BufferedDataTable(et);
} else {
throw new InvalidSettingsException("Unknown table identifier: " + tableType);
}
}
t.m_tableID = id;
tblRep.put(id, t);
return t;
}
use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class FileNodePersistor method loadInternalHeldTablesPre210.
/**
* Reads internally held table in version {@link LoadVersion#V2100Pre} and before. Was replaced by
* #loadInternalHeldObjects then on.
*/
void loadInternalHeldTablesPre210(final Node node, final ExecutionMonitor execMon, final NodeSettingsRO settings, final Map<Integer, BufferedDataTable> loadTblRep, final HashMap<Integer, ContainerTable> tblRep, final FileStoreHandlerRepository fileStoreHandlerRepository) throws IOException, InvalidSettingsException, CanceledExecutionException {
if (getLoadVersion().isOlderThan(FileWorkflowPersistor.LoadVersion.V200)) {
return;
}
if (!settings.containsKey("internalTables")) {
return;
}
NodeSettingsRO subSettings = settings.getNodeSettings("internalTables");
String subDirName = subSettings.getString("location");
ReferencedFile subDirFile = new ReferencedFile(getNodeDirectory(), subDirName);
NodeSettingsRO portSettings = subSettings.getNodeSettings("content");
Set<String> keySet = portSettings.keySet();
BufferedDataTable[] result = new BufferedDataTable[keySet.size()];
for (String s : keySet) {
ExecutionMonitor subProgress = execMon.createSubProgress(1.0 / result.length);
NodeSettingsRO singlePortSetting = portSettings.getNodeSettings(s);
int index = singlePortSetting.getInt("index");
if (index < 0 || index >= result.length) {
throw new InvalidSettingsException("Invalid index: " + index);
}
String location = singlePortSetting.getString("table_dir_location");
if (location == null) {
result[index] = null;
} else {
ReferencedFile portDirRef = new ReferencedFile(subDirFile, location);
readDirectory(portDirRef.getFile());
portDirRef.getFile();
BufferedDataTable t = loadBufferedDataTable(portDirRef, subProgress, loadTblRep, tblRep, fileStoreHandlerRepository);
t.setOwnerRecursively(node);
result[index] = t;
}
subProgress.setProgress(1.0);
}
setInternalHeldPortObjects(result);
}
use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class FileNodePersistor method loadFileStoreHandler.
IFileStoreHandler loadFileStoreHandler(final Node node, final ExecutionMonitor execMon, final NodeSettingsRO settings, final WorkflowFileStoreHandlerRepository fileStoreHandlerRepository) throws InvalidSettingsException {
if (getLoadVersion().isOlderThan(FileWorkflowPersistor.LoadVersion.V260)) {
return new EmptyFileStoreHandler(fileStoreHandlerRepository);
}
NodeSettingsRO fsSettings = settings.getNodeSettings("filestores");
String dirNameInFlow = fsSettings.getString("file_store_location");
if (dirNameInFlow == null) {
return new EmptyFileStoreHandler(fileStoreHandlerRepository);
} else {
String uuidS = fsSettings.getString("file_store_id");
UUID uuid = UUID.fromString(uuidS);
ReferencedFile subDirFile = new ReferencedFile(getNodeDirectory(), dirNameInFlow);
IFileStoreHandler fsh = WriteFileStoreHandler.restore(node.getName(), uuid, fileStoreHandlerRepository, subDirFile.getFile());
return fsh;
}
}
use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class FileNodePersistor method loadPorts.
/**
* @noreference
* @nooverride
*/
void loadPorts(final Node node, final ExecutionMonitor exec, final NodeSettingsRO settings, final Map<Integer, BufferedDataTable> loadTblRep, final HashMap<Integer, ContainerTable> tblRep, final FileStoreHandlerRepository fileStoreHandlerRepository) throws IOException, InvalidSettingsException, CanceledExecutionException {
final int nrOutPorts = node.getNrOutPorts();
if (getLoadVersion().isOlderThan(FileWorkflowPersistor.LoadVersion.V200)) {
// skip flow variables port (introduced in v2.2)
for (int i = 1; i < nrOutPorts; i++) {
int oldIndex = getOldPortIndex(i);
ExecutionMonitor execPort = exec.createSubProgress(1.0 / nrOutPorts);
exec.setMessage("Port " + oldIndex);
PortType type = node.getOutputType(i);
boolean isDataPort = BufferedDataTable.class.isAssignableFrom(type.getPortObjectClass());
if (m_isConfigured) {
PortObjectSpec spec = loadPortObjectSpec(node, settings, oldIndex);
setPortObjectSpec(i, spec);
}
if (m_isExecuted) {
PortObject object;
if (isDataPort) {
object = loadBufferedDataTable(node, settings, execPort, loadTblRep, oldIndex, tblRep, fileStoreHandlerRepository);
} else {
throw new IOException("Can't restore model ports of " + "old 1.x workflows. Execute node again.");
}
String summary = object != null ? object.getSummary() : null;
setPortObject(i, object);
setPortObjectSummary(i, summary);
}
execPort.setProgress(1.0);
}
} else {
if (nrOutPorts == 1) {
// only the mandatory flow variable port
return;
}
NodeSettingsRO portsSettings = loadPortsSettings(settings);
exec.setMessage("Reading outport data");
for (String key : portsSettings.keySet()) {
NodeSettingsRO singlePortSetting = portsSettings.getNodeSettings(key);
ExecutionMonitor subProgress = exec.createSubProgress(1 / (double) nrOutPorts);
int index = loadPortIndex(singlePortSetting);
if (index < 0 || index >= nrOutPorts) {
throw new InvalidSettingsException("Invalid outport index in settings: " + index);
}
String portDirN = singlePortSetting.getString("port_dir_location");
if (portDirN != null) {
ReferencedFile portDir = new ReferencedFile(getNodeDirectory(), portDirN);
subProgress.setMessage("Port " + index);
loadPort(node, portDir, singlePortSetting, subProgress, index, loadTblRep, tblRep, fileStoreHandlerRepository);
}
subProgress.setProgress(1.0);
}
}
}
Aggregations