Search in sources :

Example 1 with LoadNodeModelSettingsFailPolicy

use of org.knime.core.node.NodePersistor.LoadNodeModelSettingsFailPolicy in project knime-core by knime.

the class FileNativeNodeContainerPersistor method loadNCAndWashModelSettings.

/**
 * {@inheritDoc}
 */
@Override
NodeSettingsRO loadNCAndWashModelSettings(final NodeSettingsRO settingsForNode, final NodeSettingsRO modelSettings, final Map<Integer, BufferedDataTable> tblRep, final ExecutionMonitor exec, final LoadResult result) throws InvalidSettingsException, CanceledExecutionException, IOException {
    final FileNodePersistor nodePersistor = createNodePersistor(settingsForNode);
    nodePersistor.preLoad(m_node, result);
    NodeSettingsRO washedModelSettings = modelSettings;
    try {
        if (modelSettings != null) {
            // null if the node never had settings - no reason to load them
            m_node.validateModelSettings(modelSettings);
            m_node.loadModelSettingsFrom(modelSettings);
            // previous versions of KNIME (2.7 and before) kept the model settings only in the node;
            // NodeModel#saveSettingsTo was always called before the dialog was opened (some dialog implementations
            // rely on the exact structure of the NodeSettings ... which may change between versions).
            // We wash the settings through the node so that the model settings are updated (they possibly
            // no longer map to the variable settings loaded further down below - if so, the inconsistency
            // is warned later during configuration)
            NodeSettings washedSettings = new NodeSettings("model");
            m_node.saveModelSettingsTo(washedSettings);
            washedModelSettings = washedSettings;
        }
    } catch (Exception e) {
        final String error;
        if (e instanceof InvalidSettingsException) {
            error = "Loading model settings failed: " + e.getMessage();
        } else {
            error = "Caught \"" + e.getClass().getSimpleName() + "\", " + "Loading model settings failed: " + e.getMessage();
        }
        final LoadNodeModelSettingsFailPolicy pol = getModelSettingsFailPolicy(getMetaPersistor().getState(), nodePersistor.isInactive());
        switch(pol) {
            case IGNORE:
                if (!(e instanceof InvalidSettingsException)) {
                    getLogger().coding(error, e);
                }
                break;
            case FAIL:
                result.addError(error);
                m_node.createErrorMessageAndNotify(error, e);
                setNeedsResetAfterLoad();
                break;
            case WARN:
                m_node.createWarningMessageAndNotify(error, e);
                result.addWarning(error);
                setDirtyAfterLoad();
                break;
        }
    }
    try {
        HashMap<Integer, ContainerTable> globalTableRepository = getGlobalTableRepository();
        WorkflowFileStoreHandlerRepository fileStoreHandlerRepository = getFileStoreHandlerRepository();
        nodePersistor.load(m_node, getParentPersistor(), exec, tblRep, globalTableRepository, fileStoreHandlerRepository, result);
    } catch (final Exception e) {
        String error = "Error loading node content: " + e.getMessage();
        getLogger().warn(error, e);
        needsResetAfterLoad();
        result.addError(error);
    }
    if (nodePersistor.isDirtyAfterLoad()) {
        setDirtyAfterLoad();
    }
    if (nodePersistor.needsResetAfterLoad()) {
        setNeedsResetAfterLoad();
    }
    return washedModelSettings;
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) WorkflowFileStoreHandlerRepository(org.knime.core.data.filestore.internal.WorkflowFileStoreHandlerRepository) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) LoadNodeModelSettingsFailPolicy(org.knime.core.node.NodePersistor.LoadNodeModelSettingsFailPolicy) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) FileNodePersistor(org.knime.core.node.FileNodePersistor) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) NodeFactoryUnknownException(org.knime.core.node.workflow.WorkflowPersistor.NodeFactoryUnknownException) IOException(java.io.IOException) ContainerTable(org.knime.core.data.container.ContainerTable)

Aggregations

IOException (java.io.IOException)1 ContainerTable (org.knime.core.data.container.ContainerTable)1 WorkflowFileStoreHandlerRepository (org.knime.core.data.filestore.internal.WorkflowFileStoreHandlerRepository)1 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)1 FileNodePersistor (org.knime.core.node.FileNodePersistor)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 LoadNodeModelSettingsFailPolicy (org.knime.core.node.NodePersistor.LoadNodeModelSettingsFailPolicy)1 NodeSettings (org.knime.core.node.NodeSettings)1 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)1 NodeFactoryUnknownException (org.knime.core.node.workflow.WorkflowPersistor.NodeFactoryUnknownException)1