Search in sources :

Example 1 with TableBackendUnknownException

use of org.knime.core.node.workflow.WorkflowTableBackendSettings.TableBackendUnknownException in project knime-core by knime.

the class FileWorkflowPersistor method preLoadNodeContainer.

/**
 * {@inheritDoc}
 */
@Override
public void preLoadNodeContainer(final WorkflowPersistor parentPersistor, final NodeSettingsRO parentSettings, final LoadResult loadResult) throws InvalidSettingsException, IOException {
    m_parentPersistor = parentPersistor;
    final ReferencedFile knimeFile = getWorkflowKNIMEFile();
    if (knimeFile == null || !knimeFile.getFile().isFile()) {
        setDirtyAfterLoad();
        String error = "Can't read workflow file \"" + knimeFile + "\"";
        throw new IOException(error);
    }
    // workflow.knime (or template.knime)
    File nodeFile = knimeFile.getFile();
    ReferencedFile parentRef = knimeFile.getParent();
    if (parentRef == null) {
        setDirtyAfterLoad();
        throw new IOException("Parent directory of file \"" + knimeFile + "\" is not represented by " + ReferencedFile.class.getSimpleName() + " object");
    }
    m_mustWarnOnDataLoadError = loadIfMustWarnOnDataLoadError(parentRef.getFile());
    NodeSettingsRO subWFSettings;
    try {
        InputStream in = new FileInputStream(nodeFile);
        if (m_parentPersistor != null) {
            // real metanode, not a project
            // the workflow.knime (or template.knime) file is not encrypted
            // with this metanode's cipher but possibly with a parent
            // cipher
            in = m_parentPersistor.decipherInput(in);
        }
        in = new BufferedInputStream(in);
        subWFSettings = NodeSettings.loadFromXML(in);
    } catch (IOException ioe) {
        setDirtyAfterLoad();
        throw ioe;
    }
    m_workflowSett = subWFSettings;
    try {
        if (m_nameOverwrite != null) {
            m_name = m_nameOverwrite;
        } else {
            m_name = loadWorkflowName(m_workflowSett);
        }
    } catch (InvalidSettingsException e) {
        String error = "Unable to load workflow name: " + e.getMessage();
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        loadResult.addError(error);
        m_name = null;
    }
    try {
        m_workflowCipher = loadWorkflowCipher(getLoadVersion(), m_workflowSett);
    } catch (InvalidSettingsException e) {
        String error = "Unable to load workflow cipher: " + e.getMessage();
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        loadResult.addError(error);
        m_workflowCipher = WorkflowCipher.NULL_CIPHER;
    }
    try {
        if (m_templateInformation != null) {
            // template information was set after construction (this node is a link created from a template)
            assert m_templateInformation.getRole() == Role.Link;
        } else {
            m_templateInformation = MetaNodeTemplateInformation.load(m_workflowSett, getLoadVersion());
            CheckUtils.checkSettingNotNull(m_templateInformation, "No template information");
        }
    } catch (InvalidSettingsException e) {
        String error = "Unable to load workflow template information: " + e.getMessage();
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        loadResult.addError(error);
        m_templateInformation = MetaNodeTemplateInformation.NONE;
    }
    try {
        m_authorInformation = loadAuthorInformation(m_workflowSett, loadResult);
    } catch (InvalidSettingsException e) {
        String error = "Unable to load workflow author information: " + e.getMessage();
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        loadResult.addError(error);
        m_authorInformation = AuthorInformation.UNKNOWN;
    }
    try {
        m_workflowVariables = loadWorkflowVariables(m_workflowSett);
    } catch (InvalidSettingsException e) {
        String error = "Unable to load workflow variables: " + e.getMessage();
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        loadResult.addError(error);
        m_workflowVariables = Collections.emptyList();
    }
    try {
        m_credentials = loadCredentials(m_workflowSett);
        // request to initialize credentials - if available
        if (m_credentials != null && !m_credentials.isEmpty()) {
            m_credentials = getLoadHelper().loadCredentialsPrefilled(m_credentials);
        }
    } catch (InvalidSettingsException e) {
        String error = "Unable to load credentials: " + e.getMessage();
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        loadResult.addError(error);
        m_credentials = Collections.emptyList();
    }
    try {
        m_tableBackendSettings = loadTableBackendSettings(m_workflowSett);
    } catch (InvalidSettingsException e) {
        String error = "Unable to table backend: " + e.getMessage();
        getLogger().debug(error, e);
        setNeedsResetAfterLoad();
        setDirtyAfterLoad();
        loadResult.addError(error, true);
        if (e instanceof TableBackendUnknownException) {
            // NOSONAR
            loadResult.addMissingTableFormat(((TableBackendUnknownException) e).getFormatInfo());
        }
        m_tableBackendSettings = isProject() ? new WorkflowTableBackendSettings() : null;
    }
    try {
        m_workflowAnnotations = loadWorkflowAnnotations(m_workflowSett);
    } catch (InvalidSettingsException e) {
        String error = "Unable to load workflow annotations: " + e.getMessage();
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        loadResult.addError(error);
        m_workflowAnnotations = Collections.emptyList();
    }
    try {
        m_wizardState = loadWizardState(m_workflowSett);
    } catch (InvalidSettingsException e) {
        String error = "Unable to load wizard state: " + e.getMessage();
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        loadResult.addError(error);
        m_wizardState = null;
    }
    NodeSettingsRO metaFlowParentSettings = new NodeSettings("fake_parent_settings");
    try {
        metaFlowParentSettings = readParentSettings();
    } catch (IOException e1) {
        String error = "Errors reading settings file: " + e1.getMessage();
        getLogger().warn(error, e1);
        setDirtyAfterLoad();
        loadResult.addError(error);
    }
    boolean isResetRequired = m_metaPersistor.load(subWFSettings, metaFlowParentSettings, loadResult);
    if (isResetRequired) {
        setNeedsResetAfterLoad();
    }
    if (m_metaPersistor.isDirtyAfterLoad()) {
        setDirtyAfterLoad();
    }
    /* read in and outports */
    NodeSettingsRO inPortsEnum = EMPTY_SETTINGS;
    try {
        NodeSettingsRO inPorts = loadInPortsSetting(m_workflowSett);
        if (inPorts != null) {
            inPortsEnum = loadInPortsSettingsEnum(inPorts);
        }
    } catch (InvalidSettingsException e) {
        String error = "Can't load workflow ports, config not found";
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        loadResult.addError(error);
        setNeedsResetAfterLoad();
    }
    int inPortCount = inPortsEnum.keySet().size();
    m_inPortTemplates = new WorkflowPortTemplate[inPortCount];
    for (String key : inPortsEnum.keySet()) {
        WorkflowPortTemplate p;
        try {
            NodeSettingsRO sub = inPortsEnum.getNodeSettings(key);
            p = loadInPortTemplate(sub);
        } catch (InvalidSettingsException e) {
            String error = "Can't load workflow inport (internal ID \"" + key + "\", skipping it: " + e.getMessage();
            getLogger().debug(error, e);
            setDirtyAfterLoad();
            loadResult.addError(error);
            setNeedsResetAfterLoad();
            continue;
        }
        int index = p.getPortIndex();
        if (index < 0 || index >= inPortCount) {
            setDirtyAfterLoad();
            loadResult.addError("Invalid inport index " + index);
            setNeedsResetAfterLoad();
            continue;
        }
        if (m_inPortTemplates[index] != null) {
            setDirtyAfterLoad();
            loadResult.addError("Duplicate inport definition for index: " + index);
        }
        m_inPortTemplates[index] = p;
    }
    for (int i = 0; i < m_inPortTemplates.length; i++) {
        if (m_inPortTemplates[i] == null) {
            setDirtyAfterLoad();
            loadResult.addError("Assigning fallback port type for " + "missing input port " + i);
            m_inPortTemplates[i] = new WorkflowPortTemplate(i, FALLBACK_PORTTYPE);
        }
    }
    NodeSettingsRO outPortsEnum = EMPTY_SETTINGS;
    try {
        NodeSettingsRO outPorts = loadOutPortsSetting(m_workflowSett);
        if (outPorts != null) {
            outPortsEnum = loadOutPortsSettingsEnum(outPorts);
        }
    } catch (InvalidSettingsException e) {
        String error = "Can't load workflow out ports, config not found: " + e.getMessage();
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        loadResult.addError(error);
    }
    int outPortCount = outPortsEnum.keySet().size();
    m_outPortTemplates = new WorkflowPortTemplate[outPortCount];
    for (String key : outPortsEnum.keySet()) {
        WorkflowPortTemplate p;
        try {
            NodeSettingsRO sub = outPortsEnum.getNodeSettings(key);
            p = loadOutPortTemplate(sub);
        } catch (InvalidSettingsException e) {
            String error = "Can't load workflow outport (internal ID \"" + key + "\", skipping it: " + e.getMessage();
            getLogger().debug(error, e);
            setDirtyAfterLoad();
            loadResult.addError(error);
            setNeedsResetAfterLoad();
            continue;
        }
        int index = p.getPortIndex();
        if (index < 0 || index >= outPortCount) {
            setDirtyAfterLoad();
            loadResult.addError("Invalid inport index " + index);
            setNeedsResetAfterLoad();
            continue;
        }
        if (m_outPortTemplates[index] != null) {
            setDirtyAfterLoad();
            loadResult.addError("Duplicate outport definition for index: " + index);
        }
        m_outPortTemplates[index] = p;
    }
    for (int i = 0; i < m_outPortTemplates.length; i++) {
        if (m_outPortTemplates[i] == null) {
            setDirtyAfterLoad();
            loadResult.addError("Assigning fallback port type for " + "missing output port " + i);
            m_outPortTemplates[i] = new WorkflowPortTemplate(i, FALLBACK_PORTTYPE);
        }
    }
    boolean hasPorts = inPortCount > 0 || outPortCount > 0;
    if (hasPorts && m_isProject) {
        throw new InvalidSettingsException(String.format("Workflow \"%s\"" + " is not a project as it has ports (%d in, %d out)", nodeFile.getAbsoluteFile(), inPortCount, outPortCount));
    }
    NodeSettingsRO inPorts = EMPTY_SETTINGS;
    NodeUIInformation inPortsBarUIInfo = null;
    String uiInfoClassName = null;
    try {
        inPorts = loadInPortsSetting(m_workflowSett);
        if (inPorts != null) {
            uiInfoClassName = loadInPortsBarUIInfoClassName(inPorts);
        }
    } catch (InvalidSettingsException e) {
        String error = "Unable to load class name for inport bar's " + "UI information: " + e.getMessage();
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        loadResult.addError(error);
    }
    if (uiInfoClassName != null) {
        try {
            if (!getLoadVersion().isOlderThan(LoadVersion.V200)) {
                inPortsBarUIInfo = loadNodeUIInformation(inPorts);
            }
        } catch (InvalidSettingsException e) {
            String error = "Unable to load inport bar's UI information: " + e.getMessage();
            getLogger().debug(error, e);
            setDirtyAfterLoad();
            loadResult.addError(error);
            inPortsBarUIInfo = null;
        }
    }
    NodeSettingsRO outPorts = null;
    m_inPortsBarUIInfo = inPortsBarUIInfo;
    NodeUIInformation outPortsBarUIInfo = null;
    uiInfoClassName = null;
    try {
        // TODO probably not necessary anymore to store the ui information class name (it's node ui information anyway)
        outPorts = loadOutPortsSetting(m_workflowSett);
        if (outPorts != null) {
            uiInfoClassName = loadOutPortsBarUIInfoClassName(outPorts);
        }
    } catch (InvalidSettingsException e) {
        String error = "Unable to load class name for outport bar's UI information" + ", no UI information available: " + e.getMessage();
        setDirtyAfterLoad();
        getLogger().debug(error, e);
        loadResult.addError(error);
    }
    if (uiInfoClassName != null) {
        try {
            if (!getLoadVersion().isOlderThan(LoadVersion.V200)) {
                outPortsBarUIInfo = loadNodeUIInformation(outPorts);
            }
        } catch (InvalidSettingsException e) {
            String error = "Unable to load outport bar's UI information: " + e.getMessage();
            getLogger().debug(error, e);
            setDirtyAfterLoad();
            loadResult.addError(error);
            outPortsBarUIInfo = null;
        }
    }
    m_outPortsBarUIInfo = outPortsBarUIInfo;
    try {
        m_editorUIInfo = loadEditorUIInformation(m_workflowSett);
    } catch (InvalidSettingsException e) {
        String error = "Unable to load editor UI information: " + e.getMessage();
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        loadResult.addError(error);
        m_editorUIInfo = null;
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ReferencedFile(org.knime.core.internal.ReferencedFile) FileInputStream(java.io.FileInputStream) NodeSettings(org.knime.core.node.NodeSettings) BufferedInputStream(java.io.BufferedInputStream) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) TableBackendUnknownException(org.knime.core.node.workflow.WorkflowTableBackendSettings.TableBackendUnknownException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ReferencedFile (org.knime.core.internal.ReferencedFile)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NodeSettings (org.knime.core.node.NodeSettings)1 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)1 TableBackendUnknownException (org.knime.core.node.workflow.WorkflowTableBackendSettings.TableBackendUnknownException)1