Search in sources :

Example 56 with FlowVariable

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

the class SandboxedNodeCreator method getFlowVariablesOnPort.

/**
 * Checks which flow variables are available on a port by looking on the output port connected to this input port.
 *
 * @param portIdx input port of the {@link NodeContainer} {@link #m_nc}
 * @return the flow variables available at this port
 */
private List<FlowVariable> getFlowVariablesOnPort(final int portIdx) {
    WorkflowManager wfm = m_nc.getParent();
    Optional<Stream<FlowVariable>> nodeInputFlowVariables = wfm.getNodeInputFlowVariables(m_nc.getID(), portIdx);
    if (nodeInputFlowVariables.isPresent()) {
        List<FlowVariable> result = nodeInputFlowVariables.get().filter(fv -> !fv.isGlobalConstant()).collect(Collectors.toList());
        // getNodeInputFlowVariables returns top down, make sure iterations on list return oldest entry first
        // (will be pushed onto node stack using an iterator)
        Collections.reverse(result);
        return result;
    }
    return Collections.emptyList();
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ReferencedFile(org.knime.core.internal.ReferencedFile) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) NativeNodeContainerExecutionResult(org.knime.core.node.workflow.execresult.NativeNodeContainerExecutionResult) NodeContainer(org.knime.core.node.workflow.NodeContainer) Map(java.util.Map) PortObjectInNodeModel(org.knime.core.node.exec.dataexchange.in.PortObjectInNodeModel) PortObjectInNodeFactory(org.knime.core.node.exec.dataexchange.in.PortObjectInNodeFactory) PortType(org.knime.core.node.port.PortType) LockFailedException(org.knime.core.util.LockFailedException) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) Collection(java.util.Collection) ConnectionID(org.knime.core.node.workflow.ConnectionID) WorkflowCreationHelper(org.knime.core.node.workflow.WorkflowCreationHelper) Collectors(java.util.stream.Collectors) ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) List(java.util.List) BufferedDataTable(org.knime.core.node.BufferedDataTable) Stream(java.util.stream.Stream) Optional(java.util.Optional) CredentialsStore(org.knime.core.node.workflow.CredentialsStore) CheckUtils(org.knime.core.node.util.CheckUtils) PortObject(org.knime.core.node.port.PortObject) NodeContainerExecutionResult(org.knime.core.node.workflow.execresult.NodeContainerExecutionResult) IntStream(java.util.stream.IntStream) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) NodeExecutionJobManagerPool(org.knime.core.node.util.NodeExecutionJobManagerPool) FlowVariable(org.knime.core.node.workflow.FlowVariable) NodeSettings(org.knime.core.node.NodeSettings) BDTInNodeFactory(org.knime.core.node.exec.dataexchange.in.BDTInNodeFactory) ArrayList(java.util.ArrayList) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) ExecutionContext(org.knime.core.node.ExecutionContext) NodeExecutionJobManager(org.knime.core.node.workflow.NodeExecutionJobManager) NodeLogger(org.knime.core.node.NodeLogger) WorkflowExecutionResult(org.knime.core.node.workflow.execresult.WorkflowExecutionResult) NodeFactory(org.knime.core.node.NodeFactory) NodeInPort(org.knime.core.node.workflow.NodeInPort) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) NodeContext(org.knime.core.node.workflow.NodeContext) WorkflowCopyContent(org.knime.core.node.workflow.WorkflowCopyContent) File(java.io.File) PortObjectRepository(org.knime.core.node.exec.dataexchange.PortObjectRepository) NodeExecutionResult(org.knime.core.node.workflow.execresult.NodeExecutionResult) NodeID(org.knime.core.node.workflow.NodeID) FileUtil(org.knime.core.util.FileUtil) IFileStoreHandler(org.knime.core.data.filestore.internal.IFileStoreHandler) SubnodeContainerExecutionResult(org.knime.core.node.workflow.execresult.SubnodeContainerExecutionResult) Collections(java.util.Collections) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) Stream(java.util.stream.Stream) IntStream(java.util.stream.IntStream) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 57 with FlowVariable

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

the class PortObjectIDSettings method loadSettings.

/**
 * Loads the settings from a NodeSettings object.
 * @param settings to load from.
 * @throws InvalidSettingsException If no settings present or invalid.
 */
public void loadSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    m_id = settings.getInt("portobject_ID");
    m_copyData = settings.getBoolean("copyData");
    m_flowVariables = new ArrayList<FlowVariable>();
    // added for cluster version 1.0.2
    if (settings.containsKey("flowVariables")) {
        NodeSettingsRO sub = settings.getNodeSettings("flowVariables");
        for (String key : sub.keySet()) {
            NodeSettingsRO child = sub.getNodeSettings(key);
            // code copied from (package scope) load method in FlowVariable
            String name = child.getString("name");
            String typeS = child.getString("class");
            if (typeS == null || name == null) {
                throw new InvalidSettingsException("name or type is null");
            }
            FlowVariable.Type varType;
            try {
                varType = FlowVariable.Type.valueOf(typeS);
            } catch (final IllegalArgumentException e) {
                throw new InvalidSettingsException("invalid type " + typeS);
            }
            FlowVariable v;
            switch(varType) {
                case DOUBLE:
                    v = new FlowVariable(name, child.getDouble("value"));
                    break;
                case INTEGER:
                    v = new FlowVariable(name, child.getInt("value"));
                    break;
                case STRING:
                    v = new FlowVariable(name, child.getString("value"));
                    break;
                case CREDENTIALS:
                    CheckUtils.checkState(m_credentialsProvider != null, "No credentials provider set");
                    ICredentials credentials = m_credentialsProvider.get(child.getString("value"));
                    v = CredentialsStore.newCredentialsFlowVariable(credentials.getName(), credentials.getLogin(), credentials.getPassword(), false, false);
                    break;
                default:
                    throw new InvalidSettingsException("Unknown type " + varType);
            }
            m_flowVariables.add(v);
        }
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ICredentials(org.knime.core.node.workflow.ICredentials) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 58 with FlowVariable

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

the class PortObjectIDSettings method saveSettings.

/**
 * Saves the current settings to a NodeSettings object.
 * @param settings To write to.
 */
public void saveSettings(final NodeSettingsWO settings) {
    if (m_id != null) {
        settings.addInt("portobject_ID", m_id);
    }
    settings.addBoolean("copyData", m_copyData);
    NodeSettingsWO sub = settings.addNodeSettings("flowVariables");
    int index = 0;
    for (FlowVariable fv : getFlowVariables()) {
        NodeSettingsWO child = sub.addNodeSettings("flowVar_" + (index++));
        // copied from (package scope) save method in FlowVariable
        child.addString("name", fv.getName());
        child.addString("class", fv.getType().name());
        switch(fv.getType()) {
            case INTEGER:
                child.addInt("value", fv.getIntValue());
                break;
            case DOUBLE:
                child.addDouble("value", fv.getDoubleValue());
                break;
            case STRING:
                child.addString("value", fv.getStringValue());
                break;
            case CREDENTIALS:
                child.addString("value", fv.getName());
                break;
            default:
                assert false : "Unknown variable type: " + fv.getType();
        }
    }
}
Also used : NodeSettingsWO(org.knime.core.node.NodeSettingsWO) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 59 with FlowVariable

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

the class AddOutFieldDialog method takeOverSettings.

/**
 * Save settings in field m_result.
 */
@SuppressWarnings("rawtypes")
private AbstractField takeOverSettings() {
    if (m_fieldType.getSelectedItem().equals(FieldType.Column)) {
        OutColumnField outCol = new OutColumnField();
        boolean isReplacing = m_replace.isSelected();
        outCol.setReplaceExisting(isReplacing);
        String colName = isReplacing ? ((DataColumnSpec) m_replacedKnimeName.getSelectedItem()).getName() : m_knimeName.getText();
        outCol.setKnimeName(colName);
        DataType elemType = (DataType) m_knimeType.getSelectedItem();
        boolean isCollection = m_isArray.isSelected();
        DataType dataType = isCollection ? ListCell.getCollectionType(elemType) : elemType;
        TypeProvider typeProvider = TypeProvider.getDefault();
        if (!typeProvider.getColumnTypes().contains(elemType)) {
            elemType = new StringCell("").getType();
            isCollection = false;
        }
        outCol.setKnimeType(dataType);
        return outCol;
    } else {
        // flow variable
        OutFlowVariableField outVar = m_defineDefaultValue ? new DefaultOutFlowVariableField() : new OutFlowVariableField();
        boolean isReplacing = m_replace.isSelected();
        outVar.setReplaceExisting(isReplacing);
        String colName = isReplacing ? ((FlowVariable) m_replacedKnimeName.getSelectedItem()).getName() : m_knimeName.getText();
        outVar.setKnimeName(colName);
        FlowVariable.Type type = (FlowVariable.Type) m_knimeType.getSelectedItem();
        outVar.setKnimeType(type);
        if (m_defineDefaultValue) {
            DefaultOutFlowVariableField dFVar = (DefaultOutFlowVariableField) outVar;
            switch(type) {
                case INTEGER:
                    dFVar.setDefaultValue(Integer.parseInt(m_defaultValue.getText()));
                    break;
                case DOUBLE:
                    dFVar.setDefaultValue(Double.parseDouble(m_defaultValue.getText()));
                    break;
                default:
                    dFVar.setDefaultValue(m_defaultValue.getText());
            }
        }
        return outVar;
    }
}
Also used : FieldType(org.knime.core.node.util.dialog.OutFieldsTableModel.FieldType) DataType(org.knime.core.data.DataType) OutColumnField(org.knime.core.node.util.dialog.field.OutColumnField) StringCell(org.knime.core.data.def.StringCell) DefaultOutFlowVariableField(org.knime.core.node.util.dialog.field.DefaultOutFlowVariableField) OutFlowVariableField(org.knime.core.node.util.dialog.field.OutFlowVariableField) DefaultOutFlowVariableField(org.knime.core.node.util.dialog.field.DefaultOutFlowVariableField) DataType(org.knime.core.data.DataType) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 60 with FlowVariable

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

the class OutFieldsTable method getOutVarFields.

/**
 * Get the field definitions representing output flow variables.
 *
 * @return fields representing output flow variables
 */
public OutFlowVariableList getOutVarFields() {
    OutFlowVariableList outVars = new OutFlowVariableList(m_defineDefaultValues);
    for (int r = 0; r < m_model.getRowCount(); r++) {
        if (!m_model.validateValues(r)) {
            // there are errors in this row
            continue;
        }
        Object fieldTypeValue = getFieldType(r);
        if (null == fieldTypeValue) {
            continue;
        }
        boolean isFlowVar = fieldTypeValue.equals(FieldType.FlowVariable);
        if (isFlowVar) {
            OutFlowVariableField outVar = m_defineDefaultValues ? new DefaultOutFlowVariableField() : new OutFlowVariableField();
            outVar.setReplaceExisting((Boolean) m_model.getValueAt(r, Column.REPLACE_EXISTING));
            Object colColValue = m_model.getValueAt(r, Column.COLUMN);
            if (colColValue instanceof FlowVariable) {
                FlowVariable flowVar = (FlowVariable) colColValue;
                outVar.setKnimeName(flowVar.getName());
            } else if (colColValue instanceof String) {
                outVar.setKnimeName(colColValue.toString());
            } else {
                continue;
            }
            Object dataTypeValue = m_model.getValueAt(r, Column.DATA_TYPE);
            if (dataTypeValue instanceof Type) {
                Type type = (Type) dataTypeValue;
                outVar.setKnimeType(type);
            } else {
                continue;
            }
            if (m_defineDefaultValues) {
                DefaultOutFlowVariableField dOVar = (DefaultOutFlowVariableField) outVar;
                Object defaultValue = m_model.getValueAt(r, Column.DEFAULT_VALUE);
                switch((Type) dataTypeValue) {
                    case INTEGER:
                        int defInt = defaultValue instanceof String ? Integer.parseInt((String) defaultValue) : (Integer) defaultValue;
                        dOVar.setDefaultValue(defInt);
                        break;
                    case DOUBLE:
                        double defDouble = defaultValue instanceof String ? Double.parseDouble((String) defaultValue) : (Double) defaultValue;
                        dOVar.setDefaultValue(defDouble);
                        break;
                    default:
                        dOVar.setDefaultValue((String) defaultValue);
                }
            }
            outVars.add(outVar);
        }
    }
    return outVars;
}
Also used : FieldType(org.knime.core.node.util.dialog.OutFieldsTableModel.FieldType) Type(org.knime.core.node.workflow.FlowVariable.Type) DataType(org.knime.core.data.DataType) DefaultOutFlowVariableField(org.knime.core.node.util.dialog.field.DefaultOutFlowVariableField) OutFlowVariableField(org.knime.core.node.util.dialog.field.OutFlowVariableField) DefaultOutFlowVariableField(org.knime.core.node.util.dialog.field.DefaultOutFlowVariableField) EventObject(java.util.EventObject) OutFlowVariableList(org.knime.core.node.util.dialog.field.FieldList.OutFlowVariableList) 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