Search in sources :

Example 6 with InvalidSettingsException

use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.

the class LoadWorkflowRunnable method run.

/**
 * {@inheritDoc}
 */
@Override
public void run(final IProgressMonitor pm) {
    // indicates whether to create an empty workflow
    // this is done if the file is empty
    boolean createEmptyWorkflow = false;
    // name of workflow will be null (uses directory name then)
    String name = null;
    m_throwable = null;
    try {
        // create progress monitor
        ProgressHandler progressHandler = new ProgressHandler(pm, 101, "Loading workflow...");
        final CheckCancelNodeProgressMonitor progressMonitor = new CheckCancelNodeProgressMonitor(pm);
        progressMonitor.addProgressListener(progressHandler);
        File workflowDirectory = m_workflowFile.getParentFile();
        Display d = Display.getDefault();
        GUIWorkflowLoadHelper loadHelper = new GUIWorkflowLoadHelper(d, workflowDirectory.getName(), m_mountpointURI, workflowDirectory, m_mountpointRoot);
        final WorkflowLoadResult result = WorkflowManager.loadProject(workflowDirectory, new ExecutionMonitor(progressMonitor), loadHelper);
        final WorkflowManager wm = result.getWorkflowManager();
        m_editor.setWorkflowManager(wm);
        pm.subTask("Finished.");
        pm.done();
        if (wm.isDirty()) {
            m_editor.markDirty();
        }
        final IStatus status = createStatus(result, !result.getGUIMustReportDataLoadErrors());
        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: " + result.getFilteredError("", LoadResultEntryType.Warning), false);
                break;
            default:
                message = "Errors during load";
                logPreseveLineBreaks("Errors during load: " + result.getFilteredError("", LoadResultEntryType.Warning), true);
        }
        if (!status.isOK()) {
            showLoadErrorDialog(result, status, message);
        }
        final List<NodeID> linkedMNs = wm.getLinkedMetaNodes(true);
        if (!linkedMNs.isEmpty()) {
            final WorkflowEditor editor = m_editor;
            m_editor.addAfterOpenRunnable(new Runnable() {

                @Override
                public void run() {
                    postLoadCheckForMetaNodeUpdates(editor, wm, linkedMNs);
                }
            });
        }
    } catch (FileNotFoundException fnfe) {
        m_throwable = fnfe;
        LOGGER.fatal("File not found", fnfe);
    } catch (IOException ioe) {
        m_throwable = ioe;
        if (m_workflowFile.length() == 0) {
            LOGGER.info("New workflow created.");
            // this is the only place to set this flag to true: we have an
            // empty workflow file, i.e. a new project was created
            // bugfix 1555: if an exception is thrown DO NOT create empty
            // workflow
            createEmptyWorkflow = true;
        } else {
            LOGGER.error("Could not load workflow from: " + m_workflowFile.getName(), ioe);
        }
    } catch (InvalidSettingsException ise) {
        LOGGER.error("Could not load workflow from: " + m_workflowFile.getName(), ise);
        m_throwable = ise;
    } catch (UnsupportedWorkflowVersionException uve) {
        m_loadingCanceledMessage = INCOMPATIBLE_VERSION_MSG;
        LOGGER.info(m_loadingCanceledMessage, uve);
        m_editor.setWorkflowManager(null);
    } catch (CanceledExecutionException cee) {
        m_loadingCanceledMessage = "Canceled loading workflow: " + m_workflowFile.getParentFile().getName();
        LOGGER.info(m_loadingCanceledMessage, cee);
        m_editor.setWorkflowManager(null);
    } catch (LockFailedException lfe) {
        StringBuilder error = new StringBuilder();
        error.append("Unable to load workflow \"");
        error.append(m_workflowFile.getParentFile().getName());
        if (m_workflowFile.getParentFile().exists()) {
            error.append("\"\nIt is in use by another user/instance.");
        } else {
            error.append("\"\nLocation does not exist.");
        }
        m_loadingCanceledMessage = error.toString();
        LOGGER.info(m_loadingCanceledMessage, lfe);
        m_editor.setWorkflowManager(null);
    } catch (Throwable e) {
        m_throwable = e;
        LOGGER.error("Workflow could not be loaded. " + e.getMessage(), e);
        m_editor.setWorkflowManager(null);
    } finally {
        // (empty workflow file)
        if (createEmptyWorkflow) {
            WorkflowCreationHelper creationHelper = new WorkflowCreationHelper();
            WorkflowContext.Factory fac = new WorkflowContext.Factory(m_workflowFile.getParentFile());
            fac.setMountpointRoot(m_mountpointRoot);
            fac.setMountpointURI(m_mountpointURI);
            creationHelper.setWorkflowContext(fac.createContext());
            m_editor.setWorkflowManager(WorkflowManager.ROOT.createAndAddProject(name, creationHelper));
            // save empty project immediately
            // bugfix 1341 -> see WorkflowEditor line 1294
            // (resource delta visitor movedTo)
            Display.getDefault().syncExec(new Runnable() {

                @Override
                public void run() {
                    m_editor.doSave(new NullProgressMonitor());
                }
            });
            m_editor.setIsDirty(false);
        }
        // IMPORTANT: Remove the reference to the file and the
        // editor!!! Otherwise the memory cannot be freed later
        m_editor = null;
        m_workflowFile = null;
        m_mountpointRoot = null;
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) UnsupportedWorkflowVersionException(org.knime.core.node.workflow.UnsupportedWorkflowVersionException) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) FileNotFoundException(java.io.FileNotFoundException) WorkflowCreationHelper(org.knime.core.node.workflow.WorkflowCreationHelper) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) NodeID(org.knime.core.node.workflow.NodeID) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) LockFailedException(org.knime.core.util.LockFailedException) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) IOException(java.io.IOException) WorkflowLoadResult(org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) File(java.io.File) Display(org.eclipse.swt.widgets.Display)

Example 7 with InvalidSettingsException

use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.

the class NodeContainerProperties method setPropertyValue.

/**
 * {@inheritDoc}
 */
@Override
public void setPropertyValue(final Object id, final Object value) {
    if ((id instanceof String) && (value instanceof String)) {
        String strVal = (String) value;
        String strID = (String) id;
        if (strID.startsWith(m_prefix)) {
            String[] hierarchy = strID.split(CONFIG_SEPARATOR);
            String key = hierarchy[hierarchy.length - 1];
            // apply it to the node's settings:
            NodeContainer node = getNode();
            if (node == null) {
                return;
            }
            WorkflowManager wfm = node.getParent();
            NodeSettings nodeSettings = new NodeSettings("Transfer");
            NodeSettings settings;
            try {
                wfm.saveNodeSettings(node.getID(), nodeSettings);
                // overwrite our config in the settings
                settings = nodeSettings.getNodeSettings("model");
                if (hierarchy.length > 1) {
                    for (int i = 0; i < hierarchy.length - 1; i++) {
                        settings = settings.getNodeSettings(hierarchy[i]);
                        if (settings == null) {
                            return;
                        }
                    }
                }
            } catch (InvalidSettingsException e) {
                // somehow node is not able to save its settings anymore
                return;
            }
            AbstractConfigEntry entry = settings.getEntry(key);
            if (entry == null || entry instanceof Config) {
                // settings are not complete or correct anymore
                return;
            }
            switch(entry.getType()) {
                case xboolean:
                    settings.addBoolean(key, Boolean.parseBoolean(strVal));
                    break;
                case xbyte:
                    settings.addByte(key, Byte.parseByte(strVal));
                    break;
                case xchar:
                    String decoded = TokenizerSettings.unescapeString(strVal);
                    settings.addChar(key, decoded.charAt(0));
                    break;
                case xdouble:
                    settings.addDouble(key, Double.parseDouble(strVal));
                    break;
                case xfloat:
                    settings.addFloat(key, Float.parseFloat(strVal));
                    break;
                case xint:
                    settings.addInt(key, Integer.parseInt(strVal));
                    break;
                case xlong:
                    settings.addLong(key, Long.parseLong(strVal));
                    break;
                case xshort:
                    settings.addShort(key, Short.parseShort(strVal));
                    break;
                case xstring:
                    String dec = TokenizerSettings.unescapeString(strVal);
                    settings.addString(key, dec);
                    break;
                default:
                    // ignore the new value
                    return;
            }
            try {
                wfm.loadNodeSettings(node.getID(), nodeSettings);
            } catch (Exception ex) {
                LOGGER.error("Invalid Value (" + strVal + "): " + ex.getMessage(), ex);
                return;
            }
            return;
        }
    }
}
Also used : AbstractConfigEntry(org.knime.core.node.config.base.AbstractConfigEntry) NodeSettings(org.knime.core.node.NodeSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Config(org.knime.core.node.config.Config) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeContainer(org.knime.core.node.workflow.NodeContainer) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 8 with InvalidSettingsException

use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.

the class ChangeMetaNodeLinkCommand method setLink.

private boolean setLink(final URI link) {
    NodeContainer metaNode = getHostWFM().getNodeContainer(m_metaNodeID);
    if (!(metaNode instanceof WorkflowManager)) {
        LOGGER.error("Command failed: Specified node is not a metanode");
        return false;
    }
    MetaNodeTemplateInformation templateInfo = ((WorkflowManager) metaNode).getTemplateInformation();
    MetaNodeTemplateInformation newInfo;
    try {
        newInfo = templateInfo.createLinkWithUpdatedSource(m_newLink);
    } catch (InvalidSettingsException e1) {
        // will not happen.
        LOGGER.error("Command failed: Specified node is not a metanode with a link." + e1.getMessage(), e1);
        return false;
    }
    getHostWFM().setTemplateInformation(m_metaNodeID, newInfo);
    return true;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeContainer(org.knime.core.node.workflow.NodeContainer) MetaNodeTemplateInformation(org.knime.core.node.workflow.MetaNodeTemplateInformation)

Example 9 with InvalidSettingsException

use of org.knime.core.node.InvalidSettingsException 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);
        }
    }
}
Also used : UnsupportedWorkflowVersionException(org.knime.core.node.workflow.UnsupportedWorkflowVersionException) LoadMetaNodeTemplateRunnable(org.knime.workbench.editor2.LoadMetaNodeTemplateRunnable) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IWorkbench(org.eclipse.ui.IWorkbench) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IProgressService(org.eclipse.ui.progress.IProgressService) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) MetaNodeLinkUpdateResult(org.knime.core.node.workflow.WorkflowPersistor.MetaNodeLinkUpdateResult)

Example 10 with InvalidSettingsException

use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.

the class DateFieldExtractorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inSpec = inSpecs[0];
    // contains timestamp?
    if (!inSpec.containsCompatibleType(DateAndTimeValue.class)) {
        throw new InvalidSettingsException("No timestamp found in input table!");
    }
    // currently selected column still there?
    String selectedColName = m_selectedColumn.getStringValue();
    if (selectedColName != null && !selectedColName.isEmpty()) {
        if (!inSpec.containsName(selectedColName)) {
            throw new InvalidSettingsException("Column " + selectedColName + " not found in input spec!");
        }
    } else {
        // no value set: auto-configure -> choose first timeseries
        for (DataColumnSpec colSpec : inSpec) {
            if (colSpec.getType().isCompatible(DateAndTimeValue.class)) {
                String colName = colSpec.getName();
                m_selectedColumn.setStringValue(colName);
                setWarningMessage("Auto-configure: selected " + colName);
                break;
            }
        }
    }
    // create outputspec
    ColumnRearranger colRearranger = createColumnRearranger(inSpec).getColumnRearranger();
    return new DataTableSpec[] { colRearranger.createSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Aggregations

InvalidSettingsException (org.knime.core.node.InvalidSettingsException)818 DataTableSpec (org.knime.core.data.DataTableSpec)278 DataColumnSpec (org.knime.core.data.DataColumnSpec)211 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)153 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)121 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)113 IOException (java.io.IOException)109 DataCell (org.knime.core.data.DataCell)99 ArrayList (java.util.ArrayList)96 DataType (org.knime.core.data.DataType)89 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)82 File (java.io.File)72 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)69 DataRow (org.knime.core.data.DataRow)66 DoubleValue (org.knime.core.data.DoubleValue)58 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)48 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)47 FileInputStream (java.io.FileInputStream)43 LinkedHashMap (java.util.LinkedHashMap)42 NotConfigurableException (org.knime.core.node.NotConfigurableException)41