Search in sources :

Example 1 with FileStoreReferenceURIPortObject

use of com.genericworkflownodes.knime.base.data.port.FileStoreReferenceURIPortObject in project GenericKnimeNodes by genericworkflownodes.

the class ListZipLoopEndNodeModel method execute.

@Override
protected PortObject[] execute(PortObject[] inObjects, ExecutionContext exec) {
    if (!(getLoopStartNode() instanceof LoopStartNodeTerminator)) {
        throw new IllegalStateException("Loop End is not connected" + " to matching/corresponding Loop Start node. You" + " are trying to create an infinite loop!");
    }
    if (!m_loopStarted) {
        // first time we are getting to this: create container
        m_incomingPortObjects = new ArrayList<List<IURIPortObject>>(PORT_COUNT);
        m_bufferedContainers = new BufferedDataContainer[PORT_COUNT];
        for (int i = 0; i < PORT_COUNT; ++i) {
            // create data container
            m_bufferedContainers[i] = exec.createDataContainer(createPseudoSpec());
            // create container to collect the incoming port objects
            m_incomingPortObjects.add(new ArrayList<IURIPortObject>());
        }
        m_loopStarted = true;
    }
    for (int i = 0; i < PORT_COUNT; i++) {
        if (inObjects[i] == null) {
            // skip unconnected ports
            continue;
        }
        IURIPortObject po = (IURIPortObject) inObjects[i];
        // some data we need
        int currentIteration = peekFlowVariableInt("currentIteration");
        if (po.getURIContents().size() > 1) {
            LOGGER.warn(String.format("More then one incoming object at port %d. The outgoing port will only hold the first one.", i));
        }
        // collect port object for later use
        m_incomingPortObjects.get(i).add(po);
        // AbstractFileStoreURIPortObject
        if (po instanceof AbstractFileStoreURIPortObject) {
            PortObjectHandlerCell pfsc = new PortObjectHandlerCell((AbstractFileStoreURIPortObject) po);
            String rowKey = String.format("Row_%d_%d", i, currentIteration);
            m_bufferedContainers[i].addRowToTable(new DefaultRow(rowKey, pfsc));
        }
    }
    // check if this is the last iteration
    if (((LoopStartNodeTerminator) getLoopStartNode()).terminateLoop()) {
        FileStoreReferenceURIPortObject[] portObjects = new FileStoreReferenceURIPortObject[PORT_COUNT];
        for (int i = 0; i < PORT_COUNT; i++) {
            // assign collected uris to new portobject
            portObjects[i] = FileStoreReferenceURIPortObject.create(m_incomingPortObjects.get(i));
            // close the container
            m_bufferedContainers[i].close();
        }
        m_loopStarted = false;
        return portObjects;
    } else {
        continueLoop();
        return new PortObject[PORT_COUNT];
    }
}
Also used : PortObjectHandlerCell(com.genericworkflownodes.knime.base.data.port.PortObjectHandlerCell) AbstractFileStoreURIPortObject(com.genericworkflownodes.knime.base.data.port.AbstractFileStoreURIPortObject) IURIPortObject(org.knime.core.data.uri.IURIPortObject) FileStoreReferenceURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStoreReferenceURIPortObject) LoopStartNodeTerminator(org.knime.core.node.workflow.LoopStartNodeTerminator) ArrayList(java.util.ArrayList) List(java.util.List) DefaultRow(org.knime.core.data.def.DefaultRow) FileStoreReferenceURIPortObject(com.genericworkflownodes.knime.base.data.port.FileStoreReferenceURIPortObject) AbstractFileStoreURIPortObject(com.genericworkflownodes.knime.base.data.port.AbstractFileStoreURIPortObject) IURIPortObject(org.knime.core.data.uri.IURIPortObject) PortObject(org.knime.core.node.port.PortObject)

Aggregations

AbstractFileStoreURIPortObject (com.genericworkflownodes.knime.base.data.port.AbstractFileStoreURIPortObject)1 FileStoreReferenceURIPortObject (com.genericworkflownodes.knime.base.data.port.FileStoreReferenceURIPortObject)1 PortObjectHandlerCell (com.genericworkflownodes.knime.base.data.port.PortObjectHandlerCell)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DefaultRow (org.knime.core.data.def.DefaultRow)1 IURIPortObject (org.knime.core.data.uri.IURIPortObject)1 PortObject (org.knime.core.node.port.PortObject)1 LoopStartNodeTerminator (org.knime.core.node.workflow.LoopStartNodeTerminator)1