Search in sources :

Example 1 with FlowVariableRepository

use of org.knime.base.node.jsnippet.util.FlowVariableRepository in project knime-core by knime.

the class JavaEditVarNodeModel method performExecute.

/**
 */
private void performExecute(final ExecutionContext exec) {
    FlowVariableRepository flowVarRepo = new FlowVariableRepository(getAvailableInputFlowVariables());
    m_snippet.execute(flowVarRepo, exec);
    for (FlowVariable var : flowVarRepo.getModified()) {
        Type type = var.getType();
        if (type.equals(Type.INTEGER)) {
            pushFlowVariableInt(var.getName(), var.getIntValue());
        } else if (type.equals(Type.DOUBLE)) {
            pushFlowVariableDouble(var.getName(), var.getDoubleValue());
        } else {
            // case: type.equals(Type.STRING)
            pushFlowVariableString(var.getName(), var.getStringValue());
        }
    }
}
Also used : Type(org.knime.core.node.workflow.FlowVariable.Type) PortType(org.knime.core.node.port.PortType) FlowVariableRepository(org.knime.base.node.jsnippet.util.FlowVariableRepository) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 2 with FlowVariableRepository

use of org.knime.base.node.jsnippet.util.FlowVariableRepository in project knime-core by knime.

the class JavaEditVarNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    m_snippet.setSettings(m_settings);
    FlowVariableRepository flowVarRepository = new FlowVariableRepository(getAvailableInputFlowVariables());
    ValidationReport report = m_snippet.validateSettings(new DataTableSpec(), flowVarRepository);
    if (report.hasWarnings()) {
        setWarningMessage(StringUtils.join(report.getWarnings(), "\n"));
    }
    if (report.hasErrors()) {
        throw new InvalidSettingsException(StringUtils.join(report.getErrors(), "\n"));
    }
    m_snippet.configure(new DataTableSpec(), flowVarRepository);
    for (FlowVariable flowVar : flowVarRepository.getModified()) {
        if (flowVar.getType().equals(Type.INTEGER)) {
            pushFlowVariableInt(flowVar.getName(), flowVar.getIntValue());
        } else if (flowVar.getType().equals(Type.DOUBLE)) {
            pushFlowVariableDouble(flowVar.getName(), flowVar.getDoubleValue());
        } else {
            pushFlowVariableString(flowVar.getName(), flowVar.getStringValue());
        }
    }
    // execute if execute on config flag is set
    if (!m_settings.isRunOnExecute()) {
        performExecute(null);
    }
    return new PortObjectSpec[] { FlowVariablePortObjectSpec.INSTANCE };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) FlowVariableRepository(org.knime.base.node.jsnippet.util.FlowVariableRepository) ValidationReport(org.knime.base.node.jsnippet.util.ValidationReport) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FlowVariablePortObjectSpec(org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 3 with FlowVariableRepository

use of org.knime.base.node.jsnippet.util.FlowVariableRepository in project knime-core by knime.

the class JavaSnippetNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    m_snippet.setSettings(m_settings);
    FlowVariableRepository flowVarRepository = new FlowVariableRepository(getAvailableInputFlowVariables());
    // The following method also compile-checks the code and checks for missing converter factories
    ValidationReport report = m_snippet.validateSettings(inSpecs[0], flowVarRepository);
    if (report.hasWarnings()) {
        setWarningMessage(StringUtils.join(report.getWarnings(), "\n"));
    }
    if (report.hasErrors()) {
        throw new InvalidSettingsException(StringUtils.join(report.getErrors(), "\n"));
    }
    DataTableSpec outSpec = m_snippet.configure(inSpecs[0], flowVarRepository);
    for (FlowVariable flowVar : flowVarRepository.getModified()) {
        if (flowVar.getType().equals(Type.INTEGER)) {
            pushFlowVariableInt(flowVar.getName(), flowVar.getIntValue());
        } else if (flowVar.getType().equals(Type.DOUBLE)) {
            pushFlowVariableDouble(flowVar.getName(), flowVar.getDoubleValue());
        } else {
            pushFlowVariableString(flowVar.getName(), flowVar.getStringValue());
        }
    }
    return new DataTableSpec[] { outSpec };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) FlowVariableRepository(org.knime.base.node.jsnippet.util.FlowVariableRepository) ValidationReport(org.knime.base.node.jsnippet.util.ValidationReport) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 4 with FlowVariableRepository

use of org.knime.base.node.jsnippet.util.FlowVariableRepository in project knime-core by knime.

the class JavaSnippetNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    m_snippet.setSettings(m_settings);
    FlowVariableRepository flowVarRepo = new FlowVariableRepository(getAvailableInputFlowVariables());
    BufferedDataTable output = m_snippet.execute(inData[0], flowVarRepo, exec);
    for (FlowVariable var : flowVarRepo.getModified()) {
        Type type = var.getType();
        if (type.equals(Type.INTEGER)) {
            pushFlowVariableInt(var.getName(), var.getIntValue());
        } else if (type.equals(Type.DOUBLE)) {
            pushFlowVariableDouble(var.getName(), var.getDoubleValue());
        } else {
            // case: type.equals(Type.STRING)
            pushFlowVariableString(var.getName(), var.getStringValue());
        }
    }
    return new BufferedDataTable[] { output };
}
Also used : Type(org.knime.core.node.workflow.FlowVariable.Type) FlowVariableRepository(org.knime.base.node.jsnippet.util.FlowVariableRepository) BufferedDataTable(org.knime.core.node.BufferedDataTable) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 5 with FlowVariableRepository

use of org.knime.base.node.jsnippet.util.FlowVariableRepository in project knime-core by knime.

the class JavaSnippetNodeModel method createColumnRearranger.

/**
 * {@inheritDoc}
 */
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec, final long rowCount) throws InvalidSettingsException {
    m_snippet.setSettings(m_settings);
    final FlowVariableRepository flowVarRepo = new FlowVariableRepository(getAvailableInputFlowVariables());
    return m_snippet.createRearranger(spec, flowVarRepo, (int) rowCount, null);
}
Also used : FlowVariableRepository(org.knime.base.node.jsnippet.util.FlowVariableRepository)

Aggregations

FlowVariableRepository (org.knime.base.node.jsnippet.util.FlowVariableRepository)5 FlowVariable (org.knime.core.node.workflow.FlowVariable)4 ValidationReport (org.knime.base.node.jsnippet.util.ValidationReport)2 DataTableSpec (org.knime.core.data.DataTableSpec)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 Type (org.knime.core.node.workflow.FlowVariable.Type)2 BufferedDataTable (org.knime.core.node.BufferedDataTable)1 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)1 PortType (org.knime.core.node.port.PortType)1 FlowVariablePortObjectSpec (org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec)1