use of org.knime.core.node.workflow.capture.WorkflowSegment.PortID in project knime-core by knime.
the class WorkflowPortObjectSpec method saveInputs.
private static void saveInputs(final ModelContentWO model, final List<Input> inputs, final List<String> inputIDs) {
model.addInt("num_inputs", inputs.size());
for (int i = 0; i < inputs.size(); i++) {
Input input = inputs.get(i);
Config inputConf = model.addConfig("input_" + i);
if (input.getType().isPresent()) {
Config type = inputConf.addConfig("type");
savePortType(type, input.getType().get());
}
Optional<DataTableSpec> optionalSpec = input.getSpec();
if (optionalSpec.isPresent()) {
Config spec = inputConf.addConfig("spec");
saveSpec(spec, input.getSpec().get());
}
Set<PortID> connectedPorts = input.getConnectedPorts();
Config portsConf = inputConf.addConfig("connected_ports");
portsConf.addInt("num_ports", connectedPorts.size());
int j = 0;
for (PortID pid : connectedPorts) {
Config portConf = portsConf.addConfig("port_" + j);
savePortID(portConf, pid);
j++;
}
inputConf.addString("id", inputIDs.get(i));
}
}
use of org.knime.core.node.workflow.capture.WorkflowSegment.PortID in project knime-core by knime.
the class WorkflowPortObjectSpec method loadInputs.
private static Pair<List<Input>, List<String>> loadInputs(final ModelContentRO model) throws InvalidSettingsException {
int size = model.getInt("num_inputs");
List<Input> inputs = new ArrayList<>(size);
List<String> inputIDs = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
Config inputConf = model.getConfig("input_" + i);
Set<PortID> connectedPorts = new HashSet<>();
Config portsConf = inputConf.getConfig("connected_ports");
for (int j = 0; j < portsConf.getInt("num_ports"); j++) {
connectedPorts.add(loadPortID(portsConf.getConfig("port_" + j)));
}
Input input = new Input(inputConf.containsKey("type") ? loadPortType(inputConf.getConfig("type")) : null, inputConf.containsKey("spec") ? loadTableSpec(inputConf.getConfig("spec")) : null, connectedPorts);
inputs.add(input);
inputIDs.add(inputConf.getString("id"));
}
return Pair.create(inputs, inputIDs);
}
use of org.knime.core.node.workflow.capture.WorkflowSegment.PortID in project knime-core by knime.
the class WorkflowCaptureOperation method getOutputs.
/**
* Returns the outputs of the (to be) captured sub-workflow, i.e. the same ports {@link #capture()} with a
* subsequent {@link WorkflowSegment#getConnectedOutputs()} would return.
*
* @return the outputs of the (to be) captured workflow fragment
*/
public List<Output> getOutputs() {
List<Output> res = new ArrayList<>();
for (int i = 0; i < m_endNode.getNrInPorts(); i++) {
ConnectionContainer cc = m_wfm.getIncomingConnectionFor(m_endNode.getID(), i);
PortID connectPort = null;
PortType type = null;
DataTableSpec spec = null;
if (cc != null) {
connectPort = new PortID(NodeIDSuffix.create(m_wfm.getID(), cc.getSource()), cc.getSourcePort());
NodeOutPort outPort = m_wfm.getNodeContainer(cc.getSource()).getOutPort(cc.getSourcePort());
type = outPort.getPortType();
spec = castToDTSpecOrNull(outPort.getPortObjectSpec());
}
res.add(new Output(type, spec, connectPort));
}
return res;
}
use of org.knime.core.node.workflow.capture.WorkflowSegment.PortID in project knime-core by knime.
the class WorkflowCaptureOperation method getInputs.
/**
* Returns the input of the (to be) captured sub-workflow, i.e. the same ports {@link #capture()} with a
* subsequent {@link WorkflowSegment#getConnectedInputs()} would return.
*
* @return the inputs of the (to be) captured workflow fragment
*/
public List<Input> getInputs() {
List<Input> res = new ArrayList<>();
for (int i = 0; i < m_startNode.getNrOutPorts(); i++) {
Set<PortID> connections = m_wfm.getOutgoingConnectionsFor(m_startNode.getID(), i).stream().map(cc -> {
return new PortID(NodeIDSuffix.create(m_wfm.getID(), cc.getDest()), cc.getDestPort());
}).collect(Collectors.toSet());
NodeOutPort outPort = m_startNode.getOutPort(i);
res.add(new Input(outPort.getPortType(), castToDTSpecOrNull(outPort.getPortObjectSpec()), connections));
}
return res;
}
use of org.knime.core.node.workflow.capture.WorkflowSegment.PortID in project knime-core by knime.
the class WorkflowPortObjectSpec method loadOutputs.
private static Pair<List<Output>, List<String>> loadOutputs(final ModelContentRO model) throws InvalidSettingsException {
int size = model.getInt("num_outputs");
List<Output> outputs = new ArrayList<>(size);
List<String> outputIDs = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
Config outputConf = model.getConfig("output_" + i);
PortID connectedPort = null;
if (outputConf.containsKey("connected_port")) {
connectedPort = loadPortID(outputConf.getConfig("connected_port"));
}
Output output = new Output(outputConf.containsKey("type") ? loadPortType(outputConf.getConfig("type")) : null, outputConf.containsKey("spec") ? loadTableSpec(outputConf.getConfig("spec")) : null, connectedPort);
outputs.add(output);
outputIDs.add(outputConf.getString("id"));
}
return Pair.create(outputs, outputIDs);
}
Aggregations