use of org.knime.core.node.workflow.WorkflowPersistor.MetaNodeLinkUpdateResult in project knime-core by knime.
the class LoadMetaNodeTemplateRunnable method run.
/**
* {@inheritDoc}
*/
@SuppressWarnings("null")
@Override
public void run(final IProgressMonitor pm) {
try {
// create progress monitor
ProgressHandler progressHandler = new ProgressHandler(pm, 101, "Loading metanode template...");
final CheckCancelNodeProgressMonitor progressMonitor = new CheckCancelNodeProgressMonitor(pm);
progressMonitor.addProgressListener(progressHandler);
URI sourceURI = m_templateKNIMEFolder.toURI();
File parentFile = ResolverUtil.resolveURItoLocalOrTempFile(sourceURI, pm);
if (pm.isCanceled()) {
throw new InterruptedException();
}
Display d = Display.getDefault();
GUIWorkflowLoadHelper loadHelper = new GUIWorkflowLoadHelper(d, parentFile.getName(), sourceURI, parentFile, null, true);
TemplateNodeContainerPersistor loadPersistor = loadHelper.createTemplateLoadPersistor(parentFile, sourceURI);
MetaNodeLinkUpdateResult loadResult = new MetaNodeLinkUpdateResult("Template from \"" + sourceURI + "\"");
m_parentWFM.load(loadPersistor, loadResult, new ExecutionMonitor(progressMonitor), false);
m_result = loadResult;
if (pm.isCanceled()) {
throw new InterruptedException();
}
pm.subTask("Finished.");
pm.done();
final IStatus status = createStatus(m_result, !m_result.getGUIMustReportDataLoadErrors());
final String message;
switch(status.getSeverity()) {
case IStatus.OK:
message = "No problems during load.";
break;
case IStatus.WARNING:
message = "Warnings during load";
logPreseveLineBreaks("Warnings during load: " + m_result.getFilteredError("", LoadResultEntryType.Warning), false);
break;
default:
message = "Errors during load";
logPreseveLineBreaks("Errors during load: " + m_result.getFilteredError("", LoadResultEntryType.Warning), true);
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
// will not open if status is OK.
ErrorDialog.openError(Display.getDefault().getActiveShell(), "Workflow Load", message, status);
}
});
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
// IMPORTANT: Remove the reference to the file and the
// editor!!! Otherwise the memory cannot be freed later
m_parentWFM = null;
m_templateKNIMEFolder = null;
}
}
use of org.knime.core.node.workflow.WorkflowPersistor.MetaNodeLinkUpdateResult in project knime-core by knime.
the class CreateMetaNodeTemplateCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
// Add node to workflow and get the container
LoadMetaNodeTemplateRunnable loadRunnable = null;
try {
IWorkbench wb = PlatformUI.getWorkbench();
IProgressService ps = wb.getProgressService();
// this one sets the workflow manager in the editor
loadRunnable = new LoadMetaNodeTemplateRunnable(getHostWFM(), m_templateKNIMEFolder);
ps.run(false, true, loadRunnable);
MetaNodeLinkUpdateResult result = loadRunnable.getLoadResult();
m_container = (NodeContainer) result.getLoadedInstance();
if (m_container == null) {
throw new RuntimeException("No template returned by load routine, see log for details");
}
// create extra info and set it
NodeUIInformation info = NodeUIInformation.builder().setNodeLocation(m_location.x, m_location.y, -1, -1).setHasAbsoluteCoordinates(false).setSnapToGrid(m_snapToGrid).setIsDropLocation(true).build();
m_container.setUIInformation(info);
} catch (Throwable t) {
Throwable cause = t;
while ((cause.getCause() != null) && (cause.getCause() != cause)) {
cause = cause.getCause();
}
String error = "The selected node could not be created";
if (cause instanceof FileNotFoundException) {
error += " because a file could not be found: " + cause.getMessage();
MessageDialog.openError(Display.getDefault().getActiveShell(), "Node cannot be created.", error);
} else if (cause instanceof IOException) {
error += " because of an I/O error: " + cause.getMessage();
MessageDialog.openError(Display.getDefault().getActiveShell(), "Node cannot be created.", error);
} else if (cause instanceof InvalidSettingsException) {
error += " because the metanode contains invalid settings: " + cause.getMessage();
MessageDialog.openError(Display.getDefault().getActiveShell(), "Node cannot be created.", error);
} else if (cause instanceof UnsupportedWorkflowVersionException) {
error += " because the metanode version is incompatible: " + cause.getMessage();
MessageDialog.openError(Display.getDefault().getActiveShell(), "Node cannot be created.", error);
} else if ((cause instanceof CanceledExecutionException) || (cause instanceof InterruptedException)) {
LOGGER.info("Metanode loading was canceled by the user", cause);
} else {
LOGGER.error(String.format("Metanode loading failed with %s: %s", cause.getClass().getSimpleName(), cause.getMessage()), cause);
error += ": " + cause.getMessage();
MessageDialog.openError(Display.getDefault().getActiveShell(), "Node cannot be created.", error);
}
}
}
use of org.knime.core.node.workflow.WorkflowPersistor.MetaNodeLinkUpdateResult in project knime-core by knime.
the class WorkflowManager method loadMetaNodeTemplate.
/**
* Reads the template info from the metanode argument and then resolves that URI and returns a workflow manager that
* lives as child of {@link #templateWorkflowRoot}. Used to avoid duplicate loading from a remote location. The
* returned instance is then copied to the final destination.
*/
private NodeContainerTemplate loadMetaNodeTemplate(final NodeContainerTemplate meta, final WorkflowLoadHelper loadHelper, final LoadResult loadResult) throws IOException, UnsupportedWorkflowVersionException, CanceledExecutionException {
MetaNodeTemplateInformation linkInfo = meta.getTemplateInformation();
URI sourceURI = linkInfo.getSourceURI();
WorkflowManager tempParent = lazyInitTemplateWorkflowRoot();
MetaNodeLinkUpdateResult loadResultChild;
NodeContext.pushContext((NodeContainer) meta);
try {
if (m_workflowContext != null && m_workflowContext.getMountpointURI().isPresent() && sourceURI.getHost().startsWith("knime.") && (ResolverUtil.resolveURItoLocalFile(m_workflowContext.getMountpointURI().get()) == null)) {
// a workflow relative template URI but the workflow itself is not local
// => the template is also not local and must be resolved using the workflow's original location
URI origWfUri = m_workflowContext.getMountpointURI().get();
String combinedPath = origWfUri.getPath() + sourceURI.getPath();
sourceURI = new URI(origWfUri.getScheme(), origWfUri.getUserInfo(), origWfUri.getHost(), origWfUri.getPort(), combinedPath, origWfUri.getQuery(), origWfUri.getFragment()).normalize();
}
File localDir = ResolverUtil.resolveURItoLocalOrTempFile(sourceURI);
if (localDir.isFile()) {
// looks like a zipped metanode downloaded from a 4.4+ server
File unzipped = FileUtil.createTempDir("metanode-template");
FileUtil.unzip(localDir, unzipped);
localDir = unzipped.listFiles()[0];
}
TemplateNodeContainerPersistor loadPersistor = loadHelper.createTemplateLoadPersistor(localDir, sourceURI);
loadResultChild = new MetaNodeLinkUpdateResult("Template from " + sourceURI.toString());
tempParent.load(loadPersistor, loadResultChild, new ExecutionMonitor(), false);
} catch (InvalidSettingsException | URISyntaxException e) {
throw new IOException("Unable to read template metanode: " + e.getMessage(), e);
} finally {
NodeContext.removeLastContext();
}
NodeContainerTemplate linkResult = loadResultChild.getLoadedInstance();
MetaNodeTemplateInformation templInfo = linkResult.getTemplateInformation();
Role sourceRole = templInfo.getRole();
switch(sourceRole) {
case Link:
// (this is due to the template information link uri set above)
break;
default:
throw new IOException("The source of the linked instance does " + "not represent a template but is of role " + sourceRole);
}
loadResult.addChildError(loadResultChild);
return linkResult;
}
Aggregations