use of org.knime.core.node.workflow.NodeID.NodeIDSuffix in project knime-core by knime.
the class WorkflowCaptureOperation method groupAndPositionPortObjectReaders.
private static void groupAndPositionPortObjectReaders(final WorkflowManager tempParent, final Map<NodeID, List<NodeID>> portObjectReaderGroups, final Set<NodeIDSuffix> addedPortObjectReaderNodes, final int[] moveUIDist) {
for (List<NodeID> readerGroup : portObjectReaderGroups.values()) {
for (int i = 0; i < readerGroup.size(); i++) {
NodeUIInformation.moveNodeBy(tempParent.getNodeContainer(readerGroup.get(i)), new int[] { moveUIDist[0], moveUIDist[1] + i * READERS_VERTICAL_TRANSLATION });
}
if (readerGroup.size() > 1) {
int[] boundsFirstNode = tempParent.getNodeContainer(readerGroup.get(0)).getUIInformation().getBounds();
// group
CollapseIntoMetaNodeResult res = tempParent.collapseIntoMetaNode(readerGroup.toArray(new NodeID[readerGroup.size()]), new WorkflowAnnotation[0], READERS_METANODE_NAME);
// update ids
WorkflowManager readersMetanode = (WorkflowManager) tempParent.getNodeContainer(res.getCollapsedMetanodeID());
for (NodeID id : readerGroup) {
NodeIDSuffix suffix = NodeIDSuffix.create(tempParent.getID(), id);
addedPortObjectReaderNodes.remove(suffix);
addedPortObjectReaderNodes.add(NodeIDSuffix.create(tempParent.getID(), suffix.prependParent(readersMetanode.getID())));
}
// move component
readersMetanode.setUIInformation(NodeUIInformation.builder(readersMetanode.getUIInformation()).setNodeLocation(boundsFirstNode[0], boundsFirstNode[1], boundsFirstNode[2], boundsFirstNode[3]).build());
}
}
}
use of org.knime.core.node.workflow.NodeID.NodeIDSuffix in project knime-core by knime.
the class WizardPageUtil method findNestedViewNodes.
/**
* Collects different kind of infos for the 'wizard' nodes contained in a page (i.e. component). Nodes in nested
* pages are recursively collected, too.
*
* @param subNC the page to collect the info for
* @param infoMap the container for the collected {@link WizardPageNodeInfo}s, or <code>null</code> if it shouldn't
* be collected
* @param sncMap the map of nested pages, or <code>null</code> if shouldn't be collected
* @param initialHiliteHandlerSet collected hilite handlers or <code>null</code> if it shouldn't be collected
*/
private static void findNestedViewNodes(final SubNodeContainer subNC, final Map<NodeIDSuffix, NativeNodeContainer> resultMap, final Map<NodeIDSuffix, SubNodeContainer> sncMap, final Set<HiLiteHandler> initialHiliteHandlerSet) {
var subWFM = subNC.getWorkflowManager();
List<NativeNodeContainer> wizardNodes = getWizardPageNodes(subWFM);
WorkflowManager projectWFM = subNC.getProjectWFM();
for (NativeNodeContainer nc : wizardNodes) {
if (nc.isInactive()) {
// skip nodes in inactive branches
continue;
}
NodeID.NodeIDSuffix idSuffix = NodeID.NodeIDSuffix.create(projectWFM.getID(), nc.getID());
if (resultMap != null) {
resultMap.put(idSuffix, nc);
}
if (initialHiliteHandlerSet != null) {
for (var i = 0; i < nc.getNrInPorts() - 1; i++) {
var hiLiteHandler = nc.getNodeModel().getInHiLiteHandler(i);
if (hiLiteHandler != null) {
initialHiliteHandlerSet.add(hiLiteHandler);
}
}
}
}
Map<NodeID, SubNodeContainer> subnodeContainers = getSubPageNodes(subNC.getWorkflowManager());
for (Entry<NodeID, SubNodeContainer> entry : subnodeContainers.entrySet()) {
SubNodeContainer snc = entry.getValue();
NodeID.NodeIDSuffix idSuffix = NodeID.NodeIDSuffix.create(projectWFM.getID(), snc.getID());
if (sncMap != null) {
sncMap.put(idSuffix, snc);
}
findNestedViewNodes(snc, resultMap, sncMap, initialHiliteHandlerSet);
}
}
use of org.knime.core.node.workflow.NodeID.NodeIDSuffix in project knime-core by knime.
the class ReferenceReaderDataUtil method copyReferenceReaderData.
/**
* Copies the 'reference reader node'-data to the {@link PortObjectRepository}, returns the corresponding nodes id.
*
* Note: this operation potentially manipulates the passed workflow manager (changing the port object reference
* type, e.g. from 'file' to 'repository')
*
* @param wfm <T> The specific PortObject class of interest.
* @param exec a {@link ExecutionContext}
* @param portObjRepoNodeModel special node model that receives the port objects and makes them available through the
* {@link PortObjectRepository}
* @return a set of {@link NodeIDSuffix}.
* @throws IOException
* @throws CanceledExecutionException
* @throws InvalidSettingsException
*/
public static Set<NodeIDSuffix> copyReferenceReaderData(final WorkflowManager wfm, final ExecutionContext exec, final AbstractPortObjectRepositoryNodeModel portObjRepoNodeModel) throws InvalidSettingsException, CanceledExecutionException, IOException {
Set<NodeIDSuffix> res = new HashSet<>();
for (var nc : wfm.getNodeContainers()) {
if (nc instanceof NativeNodeContainer && ((NativeNodeContainer) nc).getNodeModel() instanceof PortObjectInNodeModel) {
exec.setProgress("Copying data for node " + nc.getID());
PortObjectInNodeModel portObjectReader = (PortObjectInNodeModel) ((NativeNodeContainer) nc).getNodeModel();
final PortObjectIDSettings poSettings = portObjectReader.getInputNodeSettingsCopy();
if (poSettings.getReferenceType() != ReferenceType.FILE) {
throw new IllegalStateException("Reference reader nodes expected to reference a file. But the reference type is " + poSettings.getReferenceType());
}
var uri = poSettings.getUri();
var wfFile = wfm.getNodeContainerDirectory().getFile();
var absoluteDataFile = new File(wfFile, uri.toString().replace("knime://knime.workflow", ""));
if (!absoluteDataFile.getCanonicalPath().startsWith(wfFile.getCanonicalPath())) {
throw new IllegalStateException("Trying to read in a data file outside of the workflow directory. Not allowed!");
}
var po = readPortObjectFromFile(absoluteDataFile, exec, poSettings.isTable());
var uuid = UUID.randomUUID();
portObjRepoNodeModel.addPortObject(uuid, po);
PortObjectRepository.add(uuid, po);
updatePortObjectReferenceReaderReference(wfm, nc.getID(), poSettings, uuid);
res.add(NodeIDSuffix.create(wfm.getID(), nc.getID()));
}
}
return res;
}
use of org.knime.core.node.workflow.NodeID.NodeIDSuffix in project knime-core by knime.
the class WorkflowPortObjectSpec method loadSpecMetadata.
/*
* Helper to load the spec metadata, including the workflow segment metadata
* (returned as workflow segment with pre-initialized metadata only).
* The direct spec's metadata is set directly.
*/
private static WorkflowPortObjectSpec loadSpecMetadata(final ModelContentRO metadata) throws InvalidSettingsException {
ModelContentRO refNodeIds = metadata.getModelContent("ref_node_ids");
Set<NodeIDSuffix> ids = new HashSet<>();
int numIds = refNodeIds.getInt("num_ids");
for (int i = 0; i < numIds; i++) {
ids.add(new NodeIDSuffix(refNodeIds.getIntArray("ref_node_id_" + i)));
}
ModelContentRO model = metadata.getModelContent("input_ports");
Pair<List<Input>, List<String>> inputs = loadInputs(model);
model = metadata.getModelContent("output_ports");
Pair<List<Output>, List<String>> outputs = loadOutputs(model);
String customWfName = null;
if (metadata.containsKey("custom_workflow_name")) {
customWfName = metadata.getString("custom_workflow_name");
}
WorkflowSegment wf = new WorkflowSegment(metadata.getString("name"), inputs.getFirst(), outputs.getFirst(), ids);
return new WorkflowPortObjectSpec(wf, customWfName, inputs.getSecond(), outputs.getSecond());
}
Aggregations