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