Search in sources :

Example 46 with FlowVariable

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

the class ParameterizedDBQueryPanel method loadSettingsFrom.

void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs, final Collection<FlowVariable> flowVariables) {
    try {
        m_appendInputColsModel.loadSettingsFrom(settings);
        m_includeEmptyResultsModel.loadSettingsFrom(settings);
        m_retainAllColumnsModel.loadSettingsFrom(settings);
        m_failIfExceptionModel.loadSettingsFrom(settings);
        m_editor.setText(settings.getString(ParameterizedDBQueryNodeModel.CFG_SQL_STATEMENT, ParameterizedDBQueryNodeModel.getDefaultSQLStatement()));
    } catch (InvalidSettingsException ex) {
        m_appendInputColsModel.setBooleanValue(ParameterizedDBQueryNodeModel.DEF_APPEND_INPUT_COL);
        m_includeEmptyResultsModel.setBooleanValue(ParameterizedDBQueryNodeModel.DEF_INCLUDE_EMPTY_RESULTS);
        m_retainAllColumnsModel.setBooleanValue(ParameterizedDBQueryNodeModel.DEF_RETAIN_ALL_COLUMNS);
        m_failIfExceptionModel.setBooleanValue(ParameterizedDBQueryNodeModel.DEF_FAIL_IF_EXCEPTION);
    }
    updateKnimeColumns((DataTableSpec) specs[0]);
    updateDBColumns(((DatabasePortObjectSpec) specs[1]).getDataTableSpec());
    updateFlowVariables(flowVariables.toArray(new FlowVariable[flowVariables.size()]));
    if (specs[1] != null && specs[1] instanceof DatabasePortObjectSpec) {
        final DatabasePortObjectSpec dbSpec = (DatabasePortObjectSpec) specs[1];
        final DatabaseUtility dbUtility = DatabaseUtility.getUtility(dbSpec.getDatabaseIdentifier());
        m_statementManipulator = dbUtility.getStatementManipulator();
    }
}
Also used : DatabaseUtility(org.knime.core.node.port.database.DatabaseUtility) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 47 with FlowVariable

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

the class DBReaderDialogPane method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    if (m_showConnectionPanel) {
        m_connectionPane.loadSettingsFrom(settings, specs, getCredentialsProvider());
    }
    DatabaseQueryConnectionSettings s = new DatabaseQueryConnectionSettings();
    try {
        s.loadValidatedConnection(settings, getCredentialsProvider());
    } catch (InvalidSettingsException ex) {
    // use settings as they are
    }
    // statement
    String statement = s.getQuery();
    m_statmnt.setText(statement == null ? "SELECT * FROM " + DatabaseQueryConnectionSettings.TABLE_PLACEHOLDER : statement);
    // select the table placeholder statement for easier replacements
    selectPlaceHolder(m_statmnt, DatabaseQueryConnectionSettings.TABLE_PLACEHOLDER);
    // update list of flow/workflow variables
    m_listModelVars.removeAllElements();
    for (Map.Entry<String, FlowVariable> e : getAvailableFlowVariables().entrySet()) {
        m_listModelVars.addElement(e.getValue());
    }
    // read execute without configure checkbox
    if (runWithoutConfigure()) {
        m_configureBox.setSelected(!s.getValidateQuery());
    }
    m_upstreamConnectionSettings = null;
    for (PortObjectSpec pos : specs) {
        if (pos instanceof DatabaseConnectionPortObjectSpec) {
            try {
                m_upstreamConnectionSettings = ((DatabaseConnectionPortObjectSpec) pos).getConnectionSettings(getCredentialsProvider());
            } catch (InvalidSettingsException ex) {
                LOGGER.warn("Could not load database connection from upstream node: " + ex.getMessage(), ex);
            }
        }
    }
    if (m_upstreamConnectionSettings != null || !m_showConnectionPanel) {
        m_connectionPane.setVisible(false);
    } else {
        m_connectionPane.setVisible(true);
    }
}
Also used : DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec) Map(java.util.Map) FlowVariable(org.knime.core.node.workflow.FlowVariable) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec)

Example 48 with FlowVariable

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

the class FeatureSelectionLoopEndNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final String scoreVariableName = m_settings.getScoreVariableName();
    final Map<String, FlowVariable> fvs = getAvailableInputFlowVariables();
    boolean compatibleFVExists = false;
    for (final FlowVariable fv : fvs.values()) {
        if (fv.getType() == FlowVariable.Type.DOUBLE) {
            compatibleFVExists = true;
        }
    }
    if (!compatibleFVExists) {
        throw new InvalidSettingsException("There is no compatible flow variable (Double) at the inport.");
    }
    if (!fvs.containsKey(scoreVariableName)) {
        throw new InvalidSettingsException("The defined score variable \"" + scoreVariableName + "\" is not contained in the input flow variables.");
    }
    final FlowVariable scoreVariable = getAvailableInputFlowVariables().get(scoreVariableName);
    if (scoreVariable.getType() != FlowVariable.Type.DOUBLE) {
        throw new InvalidSettingsException("The score variable must be of type Double.");
    }
    // first configure
    if (m_iteration == 0) {
        // m_selectionStrategy = ((FeatureSelectionLoopStartNodeModel)getLoopStartNode()).getSelectionStrategy();
        // m_selectionStrategy.setIsMinimize(m_settings.isMinimize());
        // m_selectionStrategy.setScoreName(scoreVariableName);
        FeatureSelectionLoopStartNodeModel startNode = (FeatureSelectionLoopStartNodeModel) getLoopStartNode();
        m_featureSelector = startNode.getFeatureSelector();
        if (m_featureSelector == null) {
            return null;
        }
        m_featureSelector.setIsMinimize(m_settings.isMinimize());
        m_featureSelector.setScoreName(scoreVariableName);
    }
    // the second outSpec is null because before the search is finished, we don't know which feature levels there are
    return new PortObjectSpec[] { m_featureSelector.getSpecForResultTable(), null };
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 49 with FlowVariable

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

the class LoopEndConditionNodeDialog method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    m_settings.loadSettingsForDialog(settings);
    m_variablesModel.removeAllElements();
    for (FlowVariable v : getAvailableFlowVariables().values()) {
        m_variablesModel.addElement(v);
        if (v.getName().equals(m_settings.variableName())) {
            m_variables.setSelectedItem(v);
        }
    }
    m_operator.setSelectedItem(m_settings.operator());
    m_value.setText(m_settings.value());
    m_addLastRows.setSelected(m_settings.addLastRows() || m_settings.addLastRowsOnly());
    m_addLastRowsOnly.setSelected(m_settings.addLastRowsOnly());
    m_addLastRows.setEnabled(!m_settings.addLastRowsOnly());
    m_addIterationColumn.setSelected(m_settings.addIterationColumn());
}
Also used : FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 50 with FlowVariable

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

the class VariableLoopEndNodeModel method createNewRow.

/**
 * Creates and returns new instance of <code>DataRow</code> with the
 * iteration count as row key and the specified and available flow vars as
 * columns.
 * @return <code>DataRow</code> with the iteration count as row key and
 * the specified and available flow vars as columns.
 * @throws InvalidSettingsException If flow variable is of any not
 * compatible type.
 */
private DataRow createNewRow() throws InvalidSettingsException {
    // get available flow vars and selected vars
    Map<String, FlowVariable> availableFlowVars = getAvailableFlowVariables();
    // for now take all variable names
    String[] flowVarNames = m_selection.applyTo(availableFlowVars).getIncludes();
    // create a cell for each selected and available flow var
    DataCell[] cells = new DataCell[flowVarNames.length];
    if (flowVarNames.length > 0) {
        for (int i = 0; i < flowVarNames.length; i++) {
            String varName = flowVarNames[i];
            FlowVariable var = availableFlowVars.get(varName);
            // if flow var is available use flow var value
            if (var != null) {
                cells[i] = getCompatibleDataCell(var);
            // if flow var is not available insert missing cell
            } else {
                cells[i] = DataType.getMissingCell();
            }
        }
    }
    return new DefaultRow(RowKey.createRowKey(m_count), cells);
}
Also used : DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) 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