Search in sources :

Example 6 with InactiveBranchPortObjectSpec

use of org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec in project knime-core by knime.

the class FileNodePersistor method savePort.

private static void savePort(final Node node, final File portDir, final NodeSettingsWO settings, final Set<Integer> savedTableIDs, final ExecutionMonitor exec, final int portIdx, final boolean saveData) throws IOException, CanceledExecutionException {
    PortObjectSpec spec = node.getOutputSpec(portIdx);
    PortObject object = node.getOutputObject(portIdx);
    String summary = node.getOutputObjectSummary(portIdx);
    settings.addString("port_spec_class", spec != null ? spec.getClass().getName() : null);
    boolean isSaveObject = saveData && object != null;
    settings.addString("port_object_class", isSaveObject ? object.getClass().getName() : null);
    if (saveData && object != null) {
        settings.addString("port_object_summary", summary);
    }
    boolean isBDT = object instanceof BufferedDataTable || node.getOutputType(portIdx).equals(BufferedDataTable.TYPE);
    boolean isInactive = spec instanceof InactiveBranchPortObjectSpec;
    if (isBDT && !isInactive) {
        assert object == null || object instanceof BufferedDataTable : "Expected BufferedDataTable, got " + object.getClass().getSimpleName();
        // executed and instructed to save data
        if (saveData && object != null) {
            saveBufferedDataTable((BufferedDataTable) object, savedTableIDs, portDir, exec);
        }
    } else {
        if (isSaveObject) {
            exec.setMessage("Saving object");
            assert spec != null : "Spec is null but port object is non-null (port " + portIdx + " of node " + node.getName() + ")";
            savePortObject(spec, object, portDir, settings, exec);
        }
    }
}
Also used : InactiveBranchPortObjectSpec(org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec) InactiveBranchPortObjectSpec(org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FlowVariablePortObjectSpec(org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec) PortObject(org.knime.core.node.port.PortObject) FileStorePortObject(org.knime.core.data.filestore.FileStorePortObject) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject)

Example 7 with InactiveBranchPortObjectSpec

use of org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec in project knime-core by knime.

the class FileNodePersistor method loadPort.

void loadPort(final Node node, final ReferencedFile portDir, final NodeSettingsRO settings, final ExecutionMonitor exec, final int portIdx, final Map<Integer, BufferedDataTable> loadTblRep, final HashMap<Integer, ContainerTable> tblRep, final FileStoreHandlerRepository fileStoreHandlerRepository) throws IOException, InvalidSettingsException, CanceledExecutionException {
    final String specClass = settings.getString("port_spec_class");
    final String objectClass = loadPortObjectClassName(settings);
    PortType designatedType = node.getOutputType(portIdx);
    PortObjectSpec spec = null;
    PortObject object = null;
    // this cannot be simplified as BDT must be loaded as BDT even if
    // the port type is not BDT (but general PortObject)
    boolean isBDT = (BufferedDataTable.TYPE.getPortObjectClass().getName().equals(objectClass) && BufferedDataTable.TYPE.getPortObjectSpecClass().getName().equals(specClass)) || designatedType.equals(BufferedDataTable.TYPE);
    // an InactiveBranchPortObjectSpec can be put into any port!
    boolean isInactive = InactiveBranchPortObjectSpec.class.getName().equals(specClass);
    if (isBDT && !isInactive) {
        if (specClass != null && !specClass.equals(BufferedDataTable.TYPE.getPortObjectSpecClass().getName())) {
            throw new IOException("Actual spec class \"" + specClass + "\", expected \"" + BufferedDataTable.TYPE.getPortObjectSpecClass().getName() + "\"");
        }
        if (objectClass != null && !objectClass.equals(BufferedDataTable.TYPE.getPortObjectClass().getName())) {
            throw new IOException("Actual object class \"" + objectClass + "\", expected \"" + BufferedDataTable.TYPE.getPortObjectClass().getName() + "\"");
        }
        if (objectClass != null) {
            object = loadBufferedDataTable(portDir, exec, loadTblRep, tblRep, fileStoreHandlerRepository);
            ((BufferedDataTable) object).setOwnerRecursively(node);
            spec = ((BufferedDataTable) object).getDataTableSpec();
        } else if (specClass != null) {
            spec = BufferedDataTable.loadSpec(portDir);
        }
    } else {
        object = loadPortObject(portDir, settings, exec, fileStoreHandlerRepository).orElse(null);
        spec = object != null ? object.getSpec() : null;
    }
    if (spec != null) {
        if (!designatedType.getPortObjectSpecClass().isInstance(spec) && !isInactive) {
            throw new IOException("Actual port spec type (\"" + spec.getClass().getSimpleName() + "\") does not match designated one (\"" + designatedType.getPortObjectSpecClass().getSimpleName() + "\")");
        }
    }
    String summary = null;
    if (object != null) {
        if (!designatedType.getPortObjectClass().isInstance(object) && !isInactive) {
            throw new IOException("Actual port object type (\"" + object.getClass().getSimpleName() + "\") does not match designated one (\"" + designatedType.getPortObjectClass().getSimpleName() + "\")");
        }
        summary = settings.getString("port_object_summary", null);
        if (summary == null) {
            summary = object.getSummary();
        }
    }
    setPortObjectSpec(portIdx, spec);
    setPortObject(portIdx, object);
    setPortObjectSummary(portIdx, summary);
}
Also used : InactiveBranchPortObjectSpec(org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec) InactiveBranchPortObjectSpec(org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FlowVariablePortObjectSpec(org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec) IOException(java.io.IOException) PortObject(org.knime.core.node.port.PortObject) FileStorePortObject(org.knime.core.data.filestore.FileStorePortObject) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) PortType(org.knime.core.node.port.PortType)

Aggregations

PortObjectSpec (org.knime.core.node.port.PortObjectSpec)7 InactiveBranchPortObjectSpec (org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec)7 DataTableSpec (org.knime.core.data.DataTableSpec)4 FlowVariablePortObjectSpec (org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec)4 FileStorePortObject (org.knime.core.data.filestore.FileStorePortObject)3 PortObject (org.knime.core.node.port.PortObject)3 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)3 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)3 IOException (java.io.IOException)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 PortType (org.knime.core.node.port.PortType)2 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)2 DataTableSpecCreator (org.knime.core.data.DataTableSpecCreator)1 DataContainerException (org.knime.core.data.container.DataContainerException)1 ValueControlledDialogPane (org.knime.core.node.dialog.ValueControlledDialogPane)1 ValueControlledNode (org.knime.core.node.dialog.ValueControlledNode)1 FlowLoopContext (org.knime.core.node.workflow.FlowLoopContext)1 FlowObjectStack (org.knime.core.node.workflow.FlowObjectStack)1 VirtualSubNodeInputNodeModel (org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel)1