use of org.knime.core.node.NodeFactory in project knime-core by knime.
the class FileNativeNodeContainerPersistor method guessPortTypesFromConnectedNodes.
/**
* {@inheritDoc}
*/
@Override
public void guessPortTypesFromConnectedNodes(final NodeAndBundleInformationPersistor nodeInfo, final NodeSettingsRO additionalFactorySettings, final ArrayList<PersistorWithPortIndex> upstreamNodes, final ArrayList<List<PersistorWithPortIndex>> downstreamNodes) {
if (m_node == null) {
/* Input ports from the connection table. */
// first is flow var port
PortType[] inPortTypes = new PortType[Math.max(upstreamNodes.size() - 1, 0)];
// default to BDT for unconnected ports
Arrays.fill(inPortTypes, BufferedDataTable.TYPE);
for (int i = 0; i < inPortTypes.length; i++) {
// first is flow var port
PersistorWithPortIndex p = upstreamNodes.get(i + 1);
if (p != null) {
PortType portTypeFromUpstreamNode = p.getPersistor().getUpstreamPortType(p.getPortIndex());
if (portTypeFromUpstreamNode != null) {
// null if upstream is missing, too
inPortTypes[i] = portTypeFromUpstreamNode;
}
}
}
/* Output ports from node settings (saved ports) -- if possible (executed) */
String nodeName = nodeInfo.getNodeNameNotNull();
PortType[] outPortTypes;
try {
LoadResult guessLoadResult = new LoadResult("Port type guessing for missing node \"" + nodeName + "\"");
NodeSettingsRO settingsForNode = loadSettingsForNode(guessLoadResult);
FileNodePersistor nodePersistor = createNodePersistor(settingsForNode);
outPortTypes = nodePersistor.guessOutputPortTypes(guessLoadResult, nodeName);
if (guessLoadResult.hasErrors()) {
getLogger().debug("Errors guessing port types for missing node \"" + nodeName + "\": " + guessLoadResult.getFilteredError("", LoadResultEntryType.Error));
}
} catch (Exception e) {
getLogger().debug("Unable to guess port types for missing node \"" + nodeName + "\"", e);
outPortTypes = null;
}
if (outPortTypes == null) {
// couldn't guess port types from looking at node settings (e.g. not executed)
// default to BDT for unconnected ports
outPortTypes = new PortType[Math.max(downstreamNodes.size() - 1, 0)];
}
for (int i = 0; i < outPortTypes.length; i++) {
PortType type = outPortTypes[i];
// output types may be partially filled by settings guessing above, list may be empty or too short
List<PersistorWithPortIndex> list = i < downstreamNodes.size() - 1 ? downstreamNodes.get(i + 1) : null;
if (list != null) {
assert !list.isEmpty();
for (PersistorWithPortIndex p : list) {
PortType current = p.getPersistor().getDownstreamPortType(p.getPortIndex());
if (current == null) {
// ignore, downstream node is also missing
} else if (type == null) {
type = current;
} else if (type.equals(current)) {
// keep type
} else {
// this shouldn't really happen - someone changed port types between versions
type = PortObject.TYPE;
}
}
outPortTypes[i] = type;
}
if (outPortTypes[i] == null) {
// might still be null if missing node is only connected to missing node, fallback: BDT
outPortTypes[i] = BufferedDataTable.TYPE;
}
}
MissingNodeFactory nodefactory = new MissingNodeFactory(nodeInfo, additionalFactorySettings, inPortTypes, outPortTypes);
if (getLoadVersion().ordinal() < FileWorkflowPersistor.VERSION_LATEST.ordinal()) {
nodefactory.setCopyInternDirForWorkflowVersionChange(true);
}
nodefactory.init();
m_node = new Node((NodeFactory) nodefactory);
}
}
use of org.knime.core.node.NodeFactory in project knime-core by knime.
the class AbstractColumnTableSorterTest method setUp.
/**
* @throws java.lang.Exception
*/
@SuppressWarnings("rawtypes")
@Before
public void setUp() throws Exception {
@SuppressWarnings("unchecked") NodeFactory<NodeModel> dummyFactory = (NodeFactory) new VirtualParallelizedChunkPortObjectInNodeFactory(new PortType[0]);
m_exec = new ExecutionContext(new DefaultNodeProgressMonitor(), new Node(dummyFactory), SingleNodeContainer.MemoryPolicy.CacheOnDisc, new HashMap<Integer, ContainerTable>());
DataColumnSpec[] colSpecs = new DataColumnSpec[] { new DataColumnSpecCreator(FEATURE1, DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator(FEATURE2, DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator(STRING_FEATURE, StringCell.TYPE).createSpec(), new DataColumnSpecCreator(CLASS, StringCell.TYPE).createSpec() };
DataTableSpec spec = new DataTableSpec(colSpecs);
final BufferedDataContainer container = m_exec.createDataContainer(spec);
int i = 0;
container.addRowToTable(creatRow(i++, 1, 8, "A", "AClass8"));
container.addRowToTable(creatRow(i++, 2, 2, "Z", "ZClass2"));
container.addRowToTable(creatRow(i++, 3, 5, "B", "BClass5"));
container.addRowToTable(creatRow(i++, 4, 0, "E", "EClass0"));
container.addRowToTable(creatRow(i++, 5, 1, "F", "FClass1"));
container.addRowToTable(creatRow(i++, 6, 7, "G", "GClass7"));
container.addRowToTable(creatRow(i++, 7, 9, "H", "HClass9"));
container.addRowToTable(creatRow(i++, 8, 8, null, "Class8"));
container.close();
testTable = container.getTable();
final BufferedDataContainer emptyContainer = m_exec.createDataContainer(spec);
emptyContainer.close();
emptyTestTable = emptyContainer.getTable();
MemoryAlertSystemTest.forceGC();
}
use of org.knime.core.node.NodeFactory in project knime-core by knime.
the class NodeSetFactoryExtension method from.
static Optional<NodeSetFactoryExtension> from(final IConfigurationElement configurationElement) {
String setFactoryClassName = configurationElement.getAttribute(SET_FACTORY_CLASS_ATTRIBUTE);
final String pluginName = getContributingPlugIn(configurationElement);
if (StringUtils.isBlank(setFactoryClassName)) {
LOGGER.errorWithFormat("%s class name in attribute \"%s\" must not be blank (contributing plug-in %s)", NodeSetFactory.class.getSimpleName(), SET_FACTORY_CLASS_ATTRIBUTE, pluginName);
}
NodeSetFactory setFactory;
try {
setFactory = (NodeSetFactory) configurationElement.createExecutableExtension(SET_FACTORY_CLASS_ATTRIBUTE);
} catch (Throwable e) {
String message = String.format("%s '%s' from plugin '%s' could not be created.", NodeSetFactory.class.getSimpleName(), setFactoryClassName, pluginName);
Bundle bundle = Platform.getBundle(pluginName);
if ((bundle == null) || (bundle.getState() != Bundle.ACTIVE)) {
// if the plugin is null, the plugin could not be activated maybe due to a not
// activateable plugin (plugin class cannot be found)
message += " The corresponding plugin bundle could not be activated!";
}
LOGGER.error(message, e);
return Optional.empty();
}
// unfortunately a NodeSetFactory may return different factory classes for different IDs and these classes
// need to be known (during workflow load)
// a map from the distinct NodeFactory classes used in the current NodeSetFactory to their counts, e.g.
// org.knime.dynamic.js.v30.DynamicJSNodeFactory -> 12
// org.knime.dynamic.js.v212.DynamicJSNodeFactory -> 7
// (counts only for logging)
Map<Class<? extends NodeFactory<? extends NodeModel>>, Long> classToCountMap = //
setFactory.getNodeFactoryIds().stream().map(//
id -> getNodeFactoryClass(configurationElement, setFactory, id)).filter(//
Optional::isPresent).map(//
Optional::get).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
return Optional.of(new NodeSetFactoryExtension(configurationElement, setFactory, classToCountMap));
}
use of org.knime.core.node.NodeFactory in project knime-core by knime.
the class WorkflowManager method addNodeAndApplyContext.
/**
* Uses given Factory to create a new node and then adds new node to the workflow manager.
*
* @param factory NodeFactory used to create the new node
* @param creationConfig the creation configuration provided by the framework (e.g. the URL of the file that was
* dragged on the canvas) or null
* @param nodeIDSuffix unique node ID suffix of the to-be-created node or -1 if a new NodeID should be generated
* @return the node id of the created node.
* @since 4.2
*/
public NodeID addNodeAndApplyContext(final NodeFactory<?> factory, final ModifiableNodeCreationConfiguration creationConfig, final int nodeIDSuffix) {
CheckUtils.checkArgument(nodeIDSuffix >= -1, "Suffix must be -1 or larger or equal to 0: %d", nodeIDSuffix);
try (WorkflowLock lock = lock()) {
final NodeID id;
if (nodeIDSuffix >= 0) {
id = getID().createChild(nodeIDSuffix);
CheckUtils.checkArgument(!m_workflow.containsNodeKey(id), "ID already in use: %s", id);
} else {
id = m_workflow.createUniqueID();
}
@SuppressWarnings("unchecked") NativeNodeContainer container = new NativeNodeContainer(this, new Node((NodeFactory<NodeModel>) factory, creationConfig), id);
addNodeContainer(container, true);
configureNodeAndSuccessors(id, true);
// save node settings if source URL/context was provided (bug 5772)
if (creationConfig != null && creationConfig.getURLConfig().isPresent()) {
container.saveNodeSettingsToDefault();
}
LOGGER.debug("Added new node " + id);
setDirty();
return id;
}
}
use of org.knime.core.node.NodeFactory in project knime-core by knime.
the class AbstractRepositoryView method hookDoubleClickAction.
private void hookDoubleClickAction() {
m_viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(final DoubleClickEvent event) {
Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
if (o instanceof NodeTemplate) {
NodeTemplate tmplt = (NodeTemplate) o;
NodeFactory<? extends NodeModel> nodeFact;
try {
nodeFact = tmplt.createFactoryInstance();
} catch (Exception e) {
LOGGER.error("Unable to instantiate the selected node " + tmplt.getFactory().getName(), e);
return;
}
boolean added = NodeProvider.INSTANCE.addNode(nodeFact);
if (added) {
NodeUsageRegistry.addNode(tmplt);
}
} else if (o instanceof MetaNodeTemplate) {
MetaNodeTemplate mnt = (MetaNodeTemplate) o;
NodeID metaNode = mnt.getManager().getID();
NodeProvider.INSTANCE.addMetaNode(WorkflowManager.META_NODE_ROOT, metaNode);
} else if (o instanceof Category) {
m_viewer.setExpandedState(o, !m_viewer.getExpandedState(o));
}
}
});
}
Aggregations