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();
}
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);
}
}
}
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();
}
}
}
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;
}
}
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;
}
Aggregations