Search in sources :

Example 6 with CollapseIntoMetaNodeResult

use of org.knime.core.node.workflow.action.CollapseIntoMetaNodeResult in project knime-core by knime.

the class BugAP5667_FileStoresInSubnode method tweakWorkflow.

private void tweakWorkflow(final WorkflowManager manager) {
    SubNodeContainer subnode = manager.getNodeContainer(m_subnode_5, SubNodeContainer.class, true);
    switch(m_testModification) {
        case WithStreaming:
            break;
        case Plain:
            subnode.setJobManager(ThreadNodeExecutionJobManagerFactory.INSTANCE.getInstance());
            break;
        case MetaNodeInSubnode:
        case SubnodeInSubnode:
            subnode.setJobManager(ThreadNodeExecutionJobManagerFactory.INSTANCE.getInstance());
            WorkflowManager innerWFM = subnode.getWorkflowManager();
            NodeID[] innerNodes = IntStream.of(2, 5).mapToObj(i -> innerWFM.getID().createChild(i)).toArray(NodeID[]::new);
            CollapseIntoMetaNodeResult collapse = innerWFM.collapseIntoMetaNode(innerNodes, new WorkflowAnnotation[0], "yet another level");
            if (m_testModification.equals(TestModifications.SubnodeInSubnode)) {
                NodeID metaNodeID = collapse.getCollapsedMetanodeID();
                innerWFM.convertMetaNodeToSubNode(metaNodeID);
            }
            break;
        default:
            throw new InternalError();
    }
}
Also used : IntStream(java.util.stream.IntStream) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) Parameter(org.junit.runners.Parameterized.Parameter) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Test(org.junit.Test) Collectors(java.util.stream.Collectors) File(java.io.File) IDLE(org.knime.core.node.workflow.InternalNodeContainerState.IDLE) Assert.assertNull(org.junit.Assert.assertNull) ThreadNodeExecutionJobManagerFactory(org.knime.core.node.exec.ThreadNodeExecutionJobManagerFactory) CONFIGURED(org.knime.core.node.workflow.InternalNodeContainerState.CONFIGURED) After(org.junit.After) EXECUTED(org.knime.core.node.workflow.InternalNodeContainerState.EXECUTED) FileUtil(org.knime.core.util.FileUtil) CollapseIntoMetaNodeResult(org.knime.core.node.workflow.action.CollapseIntoMetaNodeResult) Assert.assertEquals(org.junit.Assert.assertEquals) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) CollapseIntoMetaNodeResult(org.knime.core.node.workflow.action.CollapseIntoMetaNodeResult)

Example 7 with CollapseIntoMetaNodeResult

use of org.knime.core.node.workflow.action.CollapseIntoMetaNodeResult in project knime-core by knime.

the class TestCollapseAndWrapMetaNodeActions method testCollapseIntoMetaNodeThenWrapUnwrap.

/**
 * Collect nodes, collapse them, convert to meta node and wrap/unwrap.
 */
@Test
public void testCollapseIntoMetaNodeThenWrapUnwrap() throws Exception {
    WorkflowManager mgr = getManager();
    executeAllAndWait();
    checkState(mgr, EXECUTED);
    mgr.resetAndConfigureAll();
    // there is only one in the wfm
    WorkflowAnnotation annotation = mgr.getWorkflowAnnotations().stream().findFirst().get();
    final NodeID[] nodes = new NodeID[] { m_columnFilter_2, m_columnFilter_3, m_columnSplitter_4 };
    CollapseIntoMetaNodeResult collapseResult = mgr.collapseIntoMetaNode(nodes, new WorkflowAnnotation[] { annotation }, "Test-Meta/Wrap Node");
    WorkflowManager metaNode = mgr.getNodeContainer(collapseResult.getCollapsedMetanodeID(), WorkflowManager.class, true);
    NodeID metaSubID = metaNode.getID();
    assertFalse("Should have removed node: " + m_columnFilter_2, mgr.containsNodeContainer(m_columnFilter_2));
    assertTrue("No annotation expected", mgr.getWorkflowAnnotations().isEmpty());
    mgr.getNodeContainer(metaSubID, WorkflowManager.class, true);
    executeAllAndWait();
    checkState(mgr, EXECUTED);
    mgr.resetAndConfigureNode(metaSubID);
    MetaNodeToSubNodeResult convertObject = mgr.convertMetaNodeToSubNode(metaSubID);
    mgr.getNodeContainer(metaSubID, SubNodeContainer.class, true);
    executeAllAndWait();
    checkState(mgr, EXECUTED);
    mgr.resetAndConfigureNode(metaSubID);
    assertTrue("Should be undo-able", convertObject.canUndo());
    convertObject.undo();
    mgr.getNodeContainer(metaSubID, WorkflowManager.class, true);
    executeAllAndWait();
    checkState(mgr, EXECUTED);
    mgr.resetAndConfigureNode(metaSubID);
    convertObject = mgr.convertMetaNodeToSubNode(metaSubID);
    // no flow var ports at '0' for meta nodes
    mgr.addConnection(m_javaEdit_7, 1, metaSubID, 0);
    // no flow var ports at '0' for meta nodes
    mgr.addConnection(metaSubID, 0, m_tableView_6, 0);
    assertEquals("wrong number inputs", 3, mgr.getIncomingConnectionsFor(metaSubID).size());
    assertEquals("wrong number outputs", 3, mgr.getOutgoingConnectionsFor(metaSubID).size());
    executeAllAndWait();
    checkState(mgr, EXECUTED);
    mgr.resetAndConfigureNode(metaSubID);
    SubNodeToMetaNodeResult convertSubNodeToMetaNodeResult = mgr.convertSubNodeToMetaNode(metaSubID);
    mgr.getNodeContainer(metaSubID, WorkflowManager.class, true);
    assertEquals("wrong number inputs", 2, mgr.getIncomingConnectionsFor(metaSubID).size());
    assertEquals("wrong number outputs", 2, mgr.getOutgoingConnectionsFor(metaSubID).size());
    executeAllAndWait();
    checkState(mgr, EXECUTED);
    convertSubNodeToMetaNodeResult.undo();
    mgr.getNodeContainer(metaSubID, SubNodeContainer.class, true);
    executeAllAndWait();
    checkState(mgr, EXECUTED);
}
Also used : MetaNodeToSubNodeResult(org.knime.core.node.workflow.action.MetaNodeToSubNodeResult) CollapseIntoMetaNodeResult(org.knime.core.node.workflow.action.CollapseIntoMetaNodeResult) SubNodeToMetaNodeResult(org.knime.core.node.workflow.action.SubNodeToMetaNodeResult) Test(org.junit.Test)

Aggregations

CollapseIntoMetaNodeResult (org.knime.core.node.workflow.action.CollapseIntoMetaNodeResult)7 Test (org.junit.Test)5 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)3 LinkedHashSet (java.util.LinkedHashSet)2 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 After (org.junit.After)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNull (org.junit.Assert.assertNull)1 Before (org.junit.Before)1 RunWith (org.junit.runner.RunWith)1 Parameterized (org.junit.runners.Parameterized)1 Parameter (org.junit.runners.Parameterized.Parameter)1 Parameters (org.junit.runners.Parameterized.Parameters)1