use of org.knime.core.node.workflow.NodeContainer 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.NodeContainer in project knime-core by knime.
the class PortObjectInNodeModel method pushFlowVariables.
/**
* Push flow variables onto stack.
*/
private void pushFlowVariables() {
if (m_portObjectIDSettings.getReferenceType() == ReferenceType.NODE) {
// if a node is referenced we can just take and clone the flow variables of that node
// (by that, e.g., passwords of credential flow variables don't get lost)
NodeContainer nc = getReferencedNode();
nc.getOutPort(m_portObjectIDSettings.getPortIdx()).getFlowObjectStack().getAllAvailableFlowVariables().values().stream().filter(f -> f.getScope() == Scope.Flow).forEach(v -> Node.invokePushFlowVariable(this, v.withNewName(v.getName())));
} else {
for (FlowVariable fv : m_portObjectIDSettings.getFlowVariables()) {
Node.invokePushFlowVariable(this, fv);
}
}
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class NodeLogger method getLogObject.
/**
* @param message the logging message
* @return a KNIMELogMessage that not only contains the log message but also the information about the workflow
* and node that belong to the log message if applicable
*/
private Object getLogObject(final Object message) {
if (!LOG_NODE_ID && !LOG_IN_WF_DIR && !LOG_WF_DIR && !LOG_JOB_ID) {
return message;
}
final NodeContext context = NodeContext.getContext();
NodeID nodeID = null;
String nodeName = null;
File workflowDir = null;
UUID jobID = null;
if (context != null) {
if (LOG_NODE_ID) {
// retrieve and store the node id only if the user has requested to log it
final NodeContainer nodeContainer = context.getNodeContainer();
if (nodeContainer != null) {
nodeID = nodeContainer.getID();
nodeName = nodeContainer.getName();
}
}
if (LOG_IN_WF_DIR || LOG_WF_DIR || LOG_JOB_ID) {
final WorkflowManager workflowManager = context.getWorkflowManager();
if (workflowManager != null) {
final WorkflowContext workflowContext = workflowManager.getContext();
if (workflowContext != null) {
workflowDir = workflowContext.getCurrentLocation();
jobID = workflowContext.getJobId().orElse(null);
}
}
}
}
return new KNIMELogMessage(nodeID, nodeName, workflowDir, jobID, message);
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class WizardPageUtil method collectWizardPageNodes.
private static void collectWizardPageNodes(final WorkflowManager wfm, final boolean recurseIntoComponents, final boolean includeHiddenNodes, final List<NativeNodeContainer> res) {
for (NodeContainer nc : wfm.getNodeContainers()) {
if (nc instanceof NativeNodeContainer) {
NativeNodeContainer nnc = (NativeNodeContainer) nc;
var nodeModel = nnc.getNodeModel();
if (!includeHiddenNodes && nodeModel instanceof ViewHideable && ((ViewHideable) nodeModel).isHideInWizard()) {
continue;
}
if (isWizardPageNode(nnc)) {
res.add(nnc);
}
} else if (recurseIntoComponents && nc instanceof SubNodeContainer) {
collectWizardPageNodes(((SubNodeContainer) nc).getWorkflowManager(), recurseIntoComponents, includeHiddenNodes, res);
}
}
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class AbstractRpcClient method createRpcServer.
/**
* @return the node model's server if working local or an empty optional if working remotely.
*/
@SuppressWarnings("unchecked")
private static <N extends NodeModel> Optional<RpcServer> createRpcServer() {
NodeContainer nc = NodeContext.getContext().getNodeContainer();
if (nc instanceof NativeNodeContainer) {
N nodeModel = (N) ((NativeNodeContainer) nc).getNodeModel();
NodeFactory<NodeModel> factory = ((NativeNodeContainer) nc).getNode().getFactory();
return Optional.of(getRpcServerFromNodeFactory(nodeModel, factory));
}
return Optional.empty();
}
Aggregations