Search in sources :

Example 36 with FlowVariable

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

the class FeatureSelectionLoopEndNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    final FlowVariable scoreVariable = getAvailableInputFlowVariables().get(m_settings.getScoreVariableName());
    final double score = scoreVariable.getDoubleValue();
    if (m_resultTable == null) {
        m_resultTable = exec.createDataContainer(m_featureSelector.getSpecForResultTable());
        m_featureSelector.setResultTableContainer(m_resultTable);
    }
    m_featureSelector.addScore(score);
    m_iteration++;
    if (m_featureSelector.continueLoop()) {
        continueLoop();
        return null;
    }
    m_resultTable.close();
    return new PortObject[] { m_resultTable.getTable(), m_featureSelector.getFeatureSelectionModel() };
}
Also used : FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) PortObject(org.knime.core.node.port.PortObject) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 37 with FlowVariable

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

the class VirtualSubNodeOutputNodeModel method getVisibleFlowVariables.

/**
 * @return
 */
private Collection<FlowVariable> getVisibleFlowVariables() {
    Map<String, FlowVariable> filter = new LinkedHashMap<>(Node.invokeGetAvailableFlowVariables(this, Type.values()));
    FilterResult result = m_configuration.getFilterConfiguration().applyTo(filter);
    filter.keySet().retainAll(Arrays.asList(result.getIncludes()));
    return filter.values().stream().filter(e -> !e.isGlobalConstant()).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) FlowVariable(org.knime.core.node.workflow.FlowVariable) PortObjectInput(org.knime.core.node.streamable.PortObjectInput) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) LinkedHashMap(java.util.LinkedHashMap) ExecutionContext(org.knime.core.node.ExecutionContext) ExecutionEnvironment(org.knime.core.node.workflow.ExecutionEnvironment) Node(org.knime.core.node.Node) CredentialsProvider(org.knime.core.node.workflow.CredentialsProvider) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Map(java.util.Map) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) WorkflowLoadHelper(org.knime.core.node.workflow.WorkflowLoadHelper) PortType(org.knime.core.node.port.PortType) PortInput(org.knime.core.node.streamable.PortInput) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) PartitionInfo(org.knime.core.node.streamable.PartitionInfo) RowInput(org.knime.core.node.streamable.RowInput) NodeStateEvent(org.knime.core.node.workflow.NodeStateEvent) Collection(java.util.Collection) ExtendedScopeNodeModel(org.knime.core.node.ExtendedScopeNodeModel) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) IOException(java.io.IOException) InactiveBranchConsumer(org.knime.core.node.port.inactive.InactiveBranchConsumer) CredentialsNode(org.knime.core.node.workflow.CredentialsStore.CredentialsNode) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) Collectors(java.util.stream.Collectors) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) File(java.io.File) DataRow(org.knime.core.data.DataRow) PortOutput(org.knime.core.node.streamable.PortOutput) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) BufferedDataTable(org.knime.core.node.BufferedDataTable) Type(org.knime.core.node.workflow.FlowVariable.Type) InputPortRole(org.knime.core.node.streamable.InputPortRole) CheckUtils(org.knime.core.node.util.CheckUtils) Collections(java.util.Collections) PortObject(org.knime.core.node.port.PortObject) PortObjectHolder(org.knime.core.node.port.PortObjectHolder) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) FlowVariable(org.knime.core.node.workflow.FlowVariable) LinkedHashMap(java.util.LinkedHashMap)

Example 38 with FlowVariable

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

the class JavaScriptingPanel method onSelectionInVariableList.

private void onSelectionInVariableList(final Object selected) {
    if (selected instanceof FlowVariable) {
        FlowVariable v = (FlowVariable) selected;
        String typeChar;
        switch(v.getType()) {
            case DOUBLE:
                typeChar = "D";
                break;
            case INTEGER:
                typeChar = "I";
                break;
            case STRING:
                typeChar = "S";
                break;
            default:
                return;
        }
        String enter = "$${" + typeChar + v.getName() + "}$$";
        m_expEdit.replaceSelection(enter);
        m_flowVarsList.clearSelection();
        m_expEdit.requestFocus();
    }
}
Also used : FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 39 with FlowVariable

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

the class JavaScriptingPanel method saveSettingsTo.

/**
 * Save current settings.
 * @param s To save to.
 * @throws InvalidSettingsException If compilation fails.
 */
public void saveSettingsTo(final JavaScriptingSettings s) throws InvalidSettingsException {
    String newColName = null;
    boolean isReplace = m_replaceRadio.isSelected();
    if (isReplace) {
        if (m_customizer.getOutputIsVariable()) {
            FlowVariable item = (FlowVariable) m_replaceVariableCombo.getSelectedItem();
            newColName = item.getName();
        } else {
            newColName = m_replaceColumnCombo.getSelectedColumn();
        }
    } else {
        newColName = m_newNameField.getText();
    }
    s.setReplace(isReplace);
    s.setColName(newColName);
    String type = m_returnTypeButtonGroup.getSelection().getActionCommand();
    s.setReturnType(type);
    s.setArrayReturn(m_isArrayReturnChecker.isSelected());
    String exp = m_expEdit.getText();
    s.setExpression(exp);
    s.setHeader(m_headerEdit.getText());
    s.setExpressionVersion(m_currentVersion);
    boolean isTestCompilation = m_compileOnCloseChecker.isSelected();
    s.setTestCompilationOnDialogClose(isTestCompilation);
    if (isTestCompilation && m_currentSpec != null) {
        try {
            Expression.compile(s, m_currentSpec);
        } catch (CompilationFailedException cfe) {
            throw new InvalidSettingsException(cfe.getMessage(), cfe);
        }
    }
    s.setInsertMissingAsNull(m_insertMissingAsNullChecker.isSelected());
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CompilationFailedException(org.knime.ext.sun.nodes.script.compile.CompilationFailedException) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 40 with FlowVariable

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

the class JavaSnippet method validateSettings.

/**
 * Validate settings which is typically called in the configure method of a node.
 *
 * What is checked:
 * <ul>
 * <li>Whether converter factories matching the ids from the settings exist</li>
 * <li>Whether the code compiles</li>
 * <li>Whether columns required by input mappings still exist.</li>
 * </ul>
 *
 * @param spec the spec of the data table at the inport
 * @param flowVariableRepository the flow variables at the inport
 * @return the validation results
 */
public ValidationReport validateSettings(final DataTableSpec spec, final FlowVariableRepository flowVariableRepository) {
    List<String> errors = new ArrayList<>();
    List<String> warnings = new ArrayList<>();
    // check input fields
    for (final InCol field : m_fields.getInColFields()) {
        final int index = spec.findColumnIndex(field.getKnimeName());
        if (index < 0) {
            errors.add("The column \"" + field.getKnimeName() + "\" is not found in the input table.");
        } else {
            final DataColumnSpec colSpec = spec.getColumnSpec(index);
            final DataType type = colSpec.getType();
            if (!type.equals(field.getDataType())) {
                // Input column type changed, try to find new converter
                final Optional<?> factory = ConverterUtil.getConverterFactory(type, field.getJavaType());
                if (factory.isPresent()) {
                    warnings.add("The type of the column \"" + field.getKnimeName() + "\" has changed but is compatible.");
                    field.setConverterFactory(type, (DataCellToJavaConverterFactory<?, ?>) factory.get());
                } else {
                    errors.add("The type of the column \"" + field.getKnimeName() + "\" has changed.");
                }
            }
        }
        if (!field.getConverterFactory().isPresent()) {
            errors.add(String.format("Missing converter for column '%s' to java field '%s' (converter id: '%s')", field.getKnimeName(), field.getJavaName(), field.getConverterFactoryId()));
        }
    }
    // check input variables
    for (InVar field : m_fields.getInVarFields()) {
        FlowVariable var = flowVariableRepository.getFlowVariable(field.getKnimeName());
        if (var != null) {
            if (!var.getType().equals(field.getFlowVarType())) {
                errors.add("The type of the flow variable \"" + field.getKnimeName() + "\" has changed.");
            }
        } else {
            errors.add("The flow variable \"" + field.getKnimeName() + "\" is not found in the input.");
        }
    }
    // check output fields
    for (OutCol field : m_fields.getOutColFields()) {
        if (field.getJavaType() == null) {
            errors.add("Java type could not be loaded. Providing plugin may be missing.");
        }
        int index = spec.findColumnIndex(field.getKnimeName());
        if (field.getReplaceExisting() && index < 0) {
            errors.add("The output column \"" + field.getKnimeName() + "\" is marked to be a replacement, " + "but an input with this name does not exist.");
        }
        if (!field.getReplaceExisting() && index > 0) {
            errors.add("The output column \"" + field.getKnimeName() + "\" is marked to be new, " + "but an input with this name does exist.");
        }
        if (!field.getConverterFactory().isPresent()) {
            errors.add(String.format("Missing converter for java field '%s' to column '%s' (converter id: '%s')", field.getJavaName(), field.getKnimeName(), field.getConverterFactoryId()));
        }
    }
    // check output variables
    for (OutVar field : m_fields.getOutVarFields()) {
        FlowVariable var = flowVariableRepository.getFlowVariable(field.getKnimeName());
        if (field.getReplaceExisting() && var == null) {
            errors.add("The output flow variable \"" + field.getKnimeName() + "\" is marked to be a replacement, " + "but an input with this name does not exist.");
        }
        if (!field.getReplaceExisting() && var != null) {
            errors.add("The output flow variable \"" + field.getKnimeName() + "\" is marked to be new, " + "but an input with this name does exist.");
        }
    }
    // Check additional bundles
    for (final String bundleName : m_settings.getBundles()) {
        final Bundle bundle = Platform.getBundle(bundleName);
        if (bundle == null) {
            errors.add("Bundle \"" + bundleName + "\" required by this snippet was not found.");
        } else {
        // TODO Version warning?
        }
    }
    try {
        // test if snippet compiles and if the file can be created
        createSnippetClass();
    } catch (Exception e) {
        errors.add(e.getMessage());
    } finally {
        close();
    }
    return new ValidationReport(errors.toArray(new String[errors.size()]), warnings.toArray(new String[warnings.size()]));
}
Also used : Bundle(org.osgi.framework.Bundle) OutCol(org.knime.base.node.jsnippet.util.field.OutCol) ArrayList(java.util.ArrayList) InCol(org.knime.base.node.jsnippet.util.field.InCol) OutVar(org.knime.base.node.jsnippet.util.field.OutVar) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) BadLocationException(javax.swing.text.BadLocationException) IOException(java.io.IOException) FlowVariableException(org.knime.base.node.jsnippet.expression.FlowVariableException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ColumnException(org.knime.base.node.jsnippet.expression.ColumnException) TypeException(org.knime.base.node.jsnippet.expression.TypeException) MalformedURLException(java.net.MalformedURLException) DataColumnSpec(org.knime.core.data.DataColumnSpec) ValidationReport(org.knime.base.node.jsnippet.util.ValidationReport) DataType(org.knime.core.data.DataType) InVar(org.knime.base.node.jsnippet.util.field.InVar) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Aggregations

FlowVariable (org.knime.core.node.workflow.FlowVariable)93 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)24 DataColumnSpec (org.knime.core.data.DataColumnSpec)14 DataType (org.knime.core.data.DataType)13 DataTableSpec (org.knime.core.data.DataTableSpec)11 ArrayList (java.util.ArrayList)10 PortType (org.knime.core.node.port.PortType)8 DefaultListModel (javax.swing.DefaultListModel)7 Type (org.knime.core.node.workflow.FlowVariable.Type)7 IOException (java.io.IOException)6 Map (java.util.Map)6 PortObject (org.knime.core.node.port.PortObject)6 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)5 OutVar (org.knime.base.node.jsnippet.util.field.OutVar)5 BufferedDataTable (org.knime.core.node.BufferedDataTable)5 URL (java.net.URL)4 ParseException (java.text.ParseException)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4