Search in sources :

Example 1 with WorkflowPortTemplate

use of org.knime.core.node.workflow.WorkflowPersistor.WorkflowPortTemplate in project knime-core by knime.

the class FileSubNodeContainerPersistor method preLoadNodeContainer.

/**
 * {@inheritDoc}
 */
@Override
public void preLoadNodeContainer(final WorkflowPersistor parentPersistor, final NodeSettingsRO parentSettings, final LoadResult result) throws InvalidSettingsException, IOException {
    super.preLoadNodeContainer(parentPersistor, parentSettings, result);
    // assigned by super
    NodeSettingsRO nodeSettings = getNodeSettings();
    m_workflowPersistor = createWorkflowPersistor(getMetaPersistor().getNodeSettingsFile(), getWorkflowDataRepository());
    if (m_nameOverwrite != null) {
        m_workflowPersistor.setNameOverwrite(m_nameOverwrite);
        m_nameOverwrite = null;
    }
    try {
        int i = nodeSettings.getInt("virtual-in-ID");
        CheckUtils.checkSetting(i >= 0, "Node ID < 0: %d", i);
        m_virtualInNodeIDSuffix = i;
    } catch (InvalidSettingsException e) {
        String error = "Can't load virtual input node ID: " + e.getMessage();
        result.addError(error);
        getLogger().error(error, e);
        setDirtyAfterLoad();
    }
    try {
        int i = nodeSettings.getInt("virtual-in-ID");
        CheckUtils.checkSetting(i >= 0, "Node ID < 0: %d", i);
        m_virtualInNodeIDSuffix = i;
    } catch (InvalidSettingsException e) {
        String error = "Can't load virtual input node ID: " + e.getMessage();
        result.addError(error);
        getLogger().error(error, e);
        setDirtyAfterLoad();
    }
    Set<String> inportSetKeys = Collections.emptySet();
    NodeSettingsRO inportsSettings = null;
    try {
        inportsSettings = nodeSettings.getNodeSettings("inports");
        // input of subnode is represented by output of virtual in node.
        inportSetKeys = inportsSettings.keySet();
        // an extra for hidden flow var port
        m_inPortTemplates = new WorkflowPortTemplate[inportSetKeys.size() + 1];
        m_inPortTemplates[0] = new WorkflowPortTemplate(0, FlowVariablePortObject.TYPE_OPTIONAL);
        for (int i = 1; i < m_inPortTemplates.length; i++) {
            // fallback values, correctly set below
            m_inPortTemplates[i] = new WorkflowPortTemplate(i, BufferedDataTable.TYPE);
        }
    } catch (InvalidSettingsException e) {
        String error = "Can't load virtual input port information: " + e.getMessage();
        result.addError(error);
        getLogger().error(error, e);
        setDirtyAfterLoad();
        m_inPortTemplates = new WorkflowPortTemplate[0];
    }
    for (String key : inportSetKeys) {
        try {
            @SuppressWarnings("null") NodeSettingsRO inportSetting = inportsSettings.getNodeSettings(key);
            WorkflowPortTemplate portTemplate = loadPort(inportSetting, inportSetKeys.size());
            m_inPortTemplates[portTemplate.getPortIndex()] = portTemplate;
        } catch (InvalidSettingsException e) {
            String error = "Could not load input port information: " + e.getMessage();
            result.addError(error);
            getLogger().error(error, e);
            setDirtyAfterLoad();
            continue;
        }
    }
    try {
        m_componentMetadata = ComponentMetadata.load(nodeSettings, getLoadVersion());
    } catch (InvalidSettingsException e) {
        String error = "Unable to load component metadata: " + e.getMessage();
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        result.addError(error);
        m_componentMetadata = ComponentMetadata.NONE;
    }
    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(nodeSettings, 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();
        result.addError(error);
        m_templateInformation = MetaNodeTemplateInformation.NONE;
    }
    try {
        int i = nodeSettings.getInt("virtual-out-ID");
        CheckUtils.checkSetting(i >= 0, "Node ID < 0: %d", i);
        m_virtualOutNodeIDSuffix = i;
    } catch (InvalidSettingsException e) {
        String error = "Can't load virtual output node ID: " + e.getMessage();
        result.addError(error);
        getLogger().error(error, e);
        setDirtyAfterLoad();
    }
    Set<String> outportSetKeys = Collections.emptySet();
    NodeSettingsRO outportsSettings = null;
    try {
        outportsSettings = nodeSettings.getNodeSettings("outports");
        // output of subnode is represented by input of virtual out node.
        outportSetKeys = outportsSettings.keySet();
        m_outPortTemplates = new WorkflowPortTemplate[outportSetKeys.size() + 1];
        m_outPortTemplates[0] = new WorkflowPortTemplate(0, FlowVariablePortObject.TYPE_OPTIONAL);
        for (int i = 1; i < m_outPortTemplates.length; i++) {
            // fallback values, correctly set below
            m_outPortTemplates[i] = new WorkflowPortTemplate(i, BufferedDataTable.TYPE);
        }
    } catch (InvalidSettingsException e) {
        String error = "Can't load virtual output port information: " + e.getMessage();
        result.addError(error);
        getLogger().error(error, e);
        setDirtyAfterLoad();
        m_outPortTemplates = new WorkflowPortTemplate[0];
    }
    for (String key : outportSetKeys) {
        try {
            @SuppressWarnings("null") NodeSettingsRO outportSetting = outportsSettings.getNodeSettings(key);
            WorkflowPortTemplate portTemplate = loadPort(outportSetting, outportSetKeys.size());
            m_outPortTemplates[portTemplate.getPortIndex()] = portTemplate;
        } catch (InvalidSettingsException e) {
            String error = "Could not load output port information: " + e.getMessage();
            result.addError(error);
            getLogger().error(error, e);
            setDirtyAfterLoad();
            continue;
        }
    }
    // added in 3.1, updated with 4.2
    m_subnodeLayoutStringProvider = new SubnodeContainerLayoutStringProvider(nodeSettings.getString("layoutJSON", ""));
    // added in 3.7, load with default values
    m_customCSS = nodeSettings.getString("customCSS", "");
    m_hideInWizard = nodeSettings.getBoolean("hideInWizard", false);
    m_workflowPersistor.preLoadNodeContainer(parentPersistor, parentSettings, result);
    // added in 4.3
    m_subnodeConfigurationStringProvider = new SubnodeContainerConfigurationStringProvider(nodeSettings.getString("configurationLayoutJSON", ""));
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) WorkflowPortTemplate(org.knime.core.node.workflow.WorkflowPersistor.WorkflowPortTemplate)

Example 2 with WorkflowPortTemplate

use of org.knime.core.node.workflow.WorkflowPersistor.WorkflowPortTemplate in project knime-core by knime.

the class FileSubNodeContainerPersistor method loadPort.

private WorkflowPortTemplate loadPort(final NodeSettingsRO portSetting, final int max) throws InvalidSettingsException {
    int index = portSetting.getInt("index");
    CheckUtils.checkSetting(index >= 0 && index < max, "Index must be in [0:%d]: %d", max - 1, index);
    NodeSettingsRO portTypeSettings = portSetting.getNodeSettings("type");
    PortType portType = PortType.load(portTypeSettings);
    // one off due to flow var port
    return new WorkflowPortTemplate(index + 1, portType);
}
Also used : NodeSettingsRO(org.knime.core.node.NodeSettingsRO) WorkflowPortTemplate(org.knime.core.node.workflow.WorkflowPersistor.WorkflowPortTemplate) PortType(org.knime.core.node.port.PortType)

Aggregations

NodeSettingsRO (org.knime.core.node.NodeSettingsRO)2 WorkflowPortTemplate (org.knime.core.node.workflow.WorkflowPersistor.WorkflowPortTemplate)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 PortType (org.knime.core.node.port.PortType)1