use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class NodeContainer method unsetDirty.
/**
* Called from persistor when node has been saved.
*/
void unsetDirty() {
final ReferencedFile ncDirectory = getNodeContainerDirectory();
assert ncDirectory != null : "NC directory must not be null at this point";
ncDirectory.setDirty(false);
}
use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class FileWorkflowPersistor method loadNodeFile.
ReferencedFile loadNodeFile(final NodeSettingsRO settings, final ReferencedFile workflowDirRef) throws InvalidSettingsException {
String fileString = settings.getString("node_settings_file");
if (fileString == null) {
throw new InvalidSettingsException("Unable to read settings " + "file for node " + settings.getKey());
}
File workflowDir = workflowDirRef.getFile();
// fileString is something like "File Reader(#1)/settings.xml", thus
// it contains two levels of the hierarchy. We leave it here to the
// java.io.File implementation to resolve these levels
File fullFile = new File(workflowDir, fileString);
if (!fullFile.isFile() || !fullFile.canRead()) {
throw new InvalidSettingsException("Unable to read settings " + "file " + fullFile.getAbsolutePath());
}
Stack<String> children = new Stack<String>();
File workflowDirAbsolute = workflowDir.getAbsoluteFile();
while (!fullFile.getAbsoluteFile().equals(workflowDirAbsolute)) {
children.push(fullFile.getName());
fullFile = fullFile.getParentFile();
}
// create a ReferencedFile hierarchy for the settings file
ReferencedFile result = workflowDirRef;
while (!children.empty()) {
result = new ReferencedFile(result, children.pop());
}
return result;
}
use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class WorkflowManager method load.
/**
* Implementation of {@link #load(FileWorkflowPersistor, ExecutionMonitor, boolean)}.
*
* @noreference This method is not intended to be referenced by clients.
*/
public void load(final TemplateNodeContainerPersistor persistor, final MetaNodeLinkUpdateResult result, final ExecutionMonitor exec, final boolean keepNodeMessages) throws IOException, InvalidSettingsException, CanceledExecutionException, UnsupportedWorkflowVersionException {
final ReferencedFile refDirectory = persistor.getMetaPersistor().getNodeContainerDirectory();
exec.setMessage("Loading workflow structure from \"" + refDirectory + "\"");
exec.checkCanceled();
LoadVersion version = persistor.getLoadVersion();
LOGGER.debug("Loading workflow from \"" + refDirectory + "\" (version \"" + version + "\" with loader class \"" + persistor.getClass().getSimpleName() + "\")");
// data files are loaded using a repository of reference tables;
Map<Integer, BufferedDataTable> tblRep = new HashMap<Integer, BufferedDataTable>();
persistor.preLoadNodeContainer(null, null, result);
NodeContainerTemplate loadedInstance = null;
boolean isIsolatedProject = persistor.isProject();
InsertWorkflowPersistor insertPersistor = new InsertWorkflowPersistor(persistor);
ReentrantLock lock = isIsolatedProject ? new ReentrantLock() : m_workflowLock.getReentrantLock();
lock.lock();
try {
m_loadVersion = persistor.getLoadVersion();
NodeID[] newIDs = loadContent(insertPersistor, tblRep, null, exec, result, keepNodeMessages).getNodeIDs();
if (newIDs.length != 1) {
throw new InvalidSettingsException("Loading workflow failed, " + "couldn't identify child sub flow (typically " + "a project)");
}
loadedInstance = (NodeContainerTemplate) getNodeContainer(newIDs[0]);
} finally {
lock.unlock();
}
exec.setProgress(1.0);
result.setLoadedInstance(loadedInstance);
result.setGUIMustReportDataLoadErrors(persistor.mustWarnOnDataLoadError());
}
use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class WorkflowManager method saveAsTemplate.
/**
* {@inheritDoc}
*/
@Override
public MetaNodeTemplateInformation saveAsTemplate(final File directory, final ExecutionMonitor exec) throws IOException, CanceledExecutionException, LockFailedException {
WorkflowManager tempParent = lazyInitTemplateWorkflowRoot();
WorkflowManager copy = null;
ReferencedFile workflowDirRef = new ReferencedFile(directory);
workflowDirRef.lock();
try {
WorkflowCopyContent.Builder cntBuilder = WorkflowCopyContent.builder();
cntBuilder.setNodeIDs(getID());
WorkflowCopyContent cnt = cntBuilder.build();
try (WorkflowLock lock = lock()) {
cnt = tempParent.copyFromAndPasteHere(getParent(), cnt);
}
NodeID cID = cnt.getNodeIDs()[0];
copy = (WorkflowManager) tempParent.getNodeContainer(cID);
MetaNodeTemplateInformation template = MetaNodeTemplateInformation.createNewTemplate(WorkflowManager.class);
try (WorkflowLock copyLock = copy.lock()) {
copy.setTemplateInformation(template);
copy.setName(null);
NodeSettings templateSettings = MetaNodeTemplateInformation.createNodeSettingsForTemplate(copy);
copy.save(directory, new WorkflowSaveHelper(true, false), exec);
templateSettings.saveToXML(new FileOutputStream(new File(workflowDirRef.getFile(), WorkflowPersistor.TEMPLATE_FILE)));
}
return template;
} finally {
if (copy != null) {
tempParent.removeNode(copy.getID());
}
workflowDirRef.unlock();
}
}
use of org.knime.core.internal.ReferencedFile in project knime-core by knime.
the class WorkflowManager method save.
/**
* @param directory The directory to save in
* @param exec The execution monitor
* @param saveHelper ...
* @throws IOException If an IO error occured
* @throws CanceledExecutionException If the execution was canceled
* @throws LockFailedException If locking failed
* @since 2.10
*/
public void save(final File directory, final WorkflowSaveHelper saveHelper, final ExecutionMonitor exec) throws IOException, CanceledExecutionException, LockFailedException {
if (this == ROOT) {
throw new IOException("Can't save root workflow");
}
if (m_isWorkflowDirectoryReadonly) {
throw new IOException("Workflow is read-only, can't save");
}
try (WorkflowLock lock = lock()) {
ReferencedFile directoryReference = new ReferencedFile(directory);
// if it's the location associated with the workflow we will use the same instance (due to VM lock)
if (directoryReference.equals(getNodeContainerDirectory())) {
directoryReference = getNodeContainerDirectory();
} else if (saveHelper.isAutoSave() && directoryReference.equals(getAutoSaveDirectory())) {
directoryReference = getAutoSaveDirectory();
}
directoryReference.writeLock();
try {
final boolean isWorkingDirectory = directoryReference.equals(getNodeContainerDirectory());
final LoadVersion saveVersion = FileWorkflowPersistor.VERSION_LATEST;
if (m_loadVersion != null && !m_loadVersion.equals(saveVersion)) {
LOGGER.info("Workflow was created with another version of KNIME (workflow version " + m_loadVersion + "), converting to current version. This may take some time.");
setDirtyAll();
}
if (isWorkingDirectory) {
m_loadVersion = saveVersion;
}
if (m_authorInformation == null) {
m_authorInformation = new AuthorInformation();
} else {
m_authorInformation = new AuthorInformation(m_authorInformation);
}
final File workflowDir = directoryReference.getFile();
workflowDir.mkdirs();
boolean isTemplate = getTemplateInformation().getRole().equals(Role.Template);
if (isTemplate) {
FileWorkflowPersistor.saveAsTemplate(this, directoryReference, exec, saveHelper);
} else {
FileWorkflowPersistor.save(this, directoryReference, exec, saveHelper);
WorkflowSaveHook.runHooks(this, saveHelper.isSaveData(), workflowDir);
}
} finally {
directoryReference.writeUnlock();
}
}
}
Aggregations