Examples of ForEachNode


Examples of anvil.script.expression.ForeachNode

      }
      jj_consume_token(FOREACH);
      InlineFunction();
      Node block = pop();
      Node self = pop();
      push(new ForeachNode(self, block));
    }
  }
View Full Code Here

Examples of com.google.template.soy.soytree.ForeachNode

        "  {/foreach}\n";

    List<StandaloneNode> nodes = parseTemplateBody(templateBody);
    assertEquals(2, nodes.size());

    ForeachNode fn0 = (ForeachNode) nodes.get(0);
    assertEquals("goo", fn0.getVarName());
    assertEquals("$goose", fn0.getExprText());
    assertEquals(0, ((DataRefNode) fn0.getExpr().getChild(0)).numChildren());
    assertEquals(1, fn0.numChildren());

    ForeachNonemptyNode fn0fnn0 = (ForeachNonemptyNode) fn0.getChild(0);
    assertEquals(2, fn0fnn0.numChildren());
    assertEquals("$goose.numKids", ((PrintNode) fn0fnn0.getChild(0)).getExprText());
    assertEquals(" goslings.\n", ((RawTextNode) fn0fnn0.getChild(1)).getRawText());

    ForeachNode fn1 = (ForeachNode) nodes.get(1);
    assertEquals("boo", fn1.getVarName());
    assertEquals("$foo.booze", fn1.getExprText());
    assertEquals(1, ((DataRefNode) fn1.getExpr().getChild(0)).numChildren());
    assertEquals(2, fn1.numChildren());

    ForeachNonemptyNode fn1fnn0 = (ForeachNonemptyNode) fn1.getChild(0);
    assertEquals("boo", fn1fnn0.getVarName());
    assertEquals("$foo.booze", fn1fnn0.getExprText());
    assertEquals("boo", fn1fnn0.getVarName());
    assertEquals(4, fn1fnn0.numChildren());
    IfNode fn1fnn0in = (IfNode) fn1fnn0.getChild(3);
    assertEquals(1, fn1fnn0in.numChildren());
    assertEquals("not isLast($boo)", ((IfCondNode) fn1fnn0in.getChild(0)).getExprText());

    ForeachIfemptyNode fn1fin1 = (ForeachIfemptyNode) fn1.getChild(1);
    assertEquals(1, fn1fin1.numChildren());
    assertEquals("Sorry, no booze.", ((RawTextNode) fn1fin1.getChild(0)).getRawText());
  }
View Full Code Here

Examples of com.google.template.soy.soytree.ForeachNode

    PrintNode a = (PrintNode) template.getChild(0);
    PrintNode bc = (PrintNode) template.getChild(1);
    IfNode ifNode = (IfNode) template.getChild(2);
    IfCondNode ifCondNode = (IfCondNode) ifNode.getChild(0);
    PrintNode e = (PrintNode) ifCondNode.getChild(0);
    ForeachNode foreachNode = (ForeachNode) ifCondNode.getChild(1);
    ForeachNonemptyNode foreachNonemptyNode = (ForeachNonemptyNode) foreachNode.getChild(0);
    PrintNode f = (PrintNode) foreachNonemptyNode.getChild(0);
    PrintNode gh = (PrintNode) foreachNonemptyNode.getChild(1);
    PrintDirectiveNode ghPdn = gh.getChild(0);
    MsgNode msgNode = (MsgNode) foreachNonemptyNode.getChild(2);
    MsgPlaceholderNode iPh = (MsgPlaceholderNode) msgNode.getChild(0);
View Full Code Here

Examples of edu.indiana.extreme.xbaya.graph.system.ForEachNode

        } else if (GraphSchema.NODE_TYPE_OUTPUT.equals(type)) {
            node = new OutputNode(nodeElement);
        } else if (GraphSchema.NODE_TYPE_CONSTANT.equals(type)) {
            node = new ConstantNode(nodeElement);
        } else if (GraphSchema.NODE_TYPE_SPLIT.equals(type)) {
            node = new ForEachNode(nodeElement);
        } else if (GraphSchema.NODE_TYPE_MERGE.equals(type)) {
            node = new EndForEachNode(nodeElement);
        } else if (GraphSchema.NODE_TYPE_IF.equals(type)) {
            node = new IfNode(nodeElement);
        } else if (GraphSchema.NODE_TYPE_ENDIF.equals(type)) {
View Full Code Here

Examples of edu.indiana.extreme.xbaya.graph.system.ForEachNode

    /**
     * @see edu.indiana.extreme.xbaya.component.Component#createNode(edu.indiana.extreme.xbaya.graph.Graph)
     */
    @Override
    public Node createNode(Graph graph) {
        ForEachNode node = new ForEachNode(graph);

        node.setName(NAME);
        node.setComponent(this);

        // Creates a unique ID for the node. This has to be after setName().
        node.createID();

        createPorts(node);

        return node;
    }
View Full Code Here

Examples of edu.indiana.extreme.xbaya.graph.system.ForEachNode

    dynamicInvoker.invoke();
    node.getGUI().setBodyColor(NodeState.FINISHED.color);
  }

  private void handleForEach(Node node) throws XBayaException {
    final ForEachNode forEachNode = (ForEachNode) node;
    EndForEachNode endForEachNode = null;
    Collection<Node> repeatNodes = node.getOutputPort(0).getToNodes();
    // we will support only one for now
    if (repeatNodes.size() != 1) {
      throw new WorkFlowInterpreterException("Only one node allowed inside foreach");
    }
    Iterator<Node> iterator = repeatNodes.iterator();
    if (iterator.hasNext()) {

      Node middleNode = iterator.next();

      if (!(middleNode instanceof WSNode)) {
        throw new WorkFlowInterpreterException("Encountered Node inside foreach that is not a WSNode" + middleNode);
      }
      Iterator<Node> endForEachNodeItr = middleNode.getOutputPort(0).getToNodes().iterator();
      while (endForEachNodeItr.hasNext()) {
        Node node2 = endForEachNodeItr.next();
        if (!(node2 instanceof EndForEachNode)) {
          throw new WorkFlowInterpreterException("Found More than one node inside foreach");
        } else {
          endForEachNode = (EndForEachNode) node2;
        }

      }
      final WSNode foreachWSNode = (WSNode) middleNode;
      WorkflowInvoker workflowInvoker = this.invokerMap.get(forEachNode.getInputPort(0).getFromNode());
      final LinkedList<String> listOfValues = new LinkedList<String>();
      if (workflowInvoker != null) {
        if (workflowInvoker instanceof GenericInvoker) {
          String message = ((GenericInvoker) workflowInvoker).getOutputs().toString();
          XmlElement msgElmt = XmlConstants.BUILDER.parseFragmentFromString(message);
          Iterator children = msgElmt.children().iterator();
          while (children.hasNext()) {
            Object object = children.next();
            if (object instanceof XmlElement) {
              XmlElement child = (XmlElement) object;
              Iterator valItr = child.children().iterator();
              if (valItr.hasNext()) {
                Object object2 = valItr.next();
                if (object2 instanceof String) {
                  listOfValues.add(object2.toString());
                }

              }
            }

          }
        }
        if (listOfValues.size() > 0) {
          forEachNode.getGUI().setBodyColor(NodeState.EXECUTING.color);
          foreachWSNode.getGUI().setBodyColor(NodeState.EXECUTING.color);
          endForEachNode.getGUI().setBodyColor(NodeState.EXECUTING.color);
          final EndForEachNode tempendForEachNode = endForEachNode;
          final SystemComponentInvoker systemInvoker = new SystemComponentInvoker();
          this.invokerMap.put(endForEachNode, systemInvoker);
View Full Code Here

Examples of org.apache.airavata.workflow.model.graph.system.ForEachNode

    /**
     * @see org.apache.airavata.workflow.model.component.Component#createNode(org.apache.airavata.workflow.model.graph.Graph)
     */
    @Override
    public Node createNode(Graph graph) {
        ForEachNode node = new ForEachNode(graph);

        node.setName(NAME);
        node.setComponent(this);

        // Creates a unique ID for the node. This has to be after setName().
        node.createID();

        createPorts(node);

        return node;
    }
View Full Code Here

Examples of org.apache.airavata.workflow.model.graph.system.ForEachNode

    } else if (GraphSchema.NODE_TYPE_OUTPUT.equals(type)) {
      node = new OutputNode(nodeElement);
    } else if (GraphSchema.NODE_TYPE_CONSTANT.equals(type)) {
      node = new ConstantNode(nodeElement);
    } else if (GraphSchema.NODE_TYPE_SPLIT.equals(type)) {
      node = new ForEachNode(nodeElement);
    } else if (GraphSchema.NODE_TYPE_MERGE.equals(type)) {
      node = new EndForEachNode(nodeElement);
    } else if (GraphSchema.NODE_TYPE_IF.equals(type)) {
      node = new IfNode(nodeElement);
    } else if (GraphSchema.NODE_TYPE_ENDIF.equals(type)) {
View Full Code Here

Examples of org.apache.airavata.workflow.model.graph.system.ForEachNode

    dynamicInvoker.invoke();
    node.setState(NodeExecutionState.FINISHED);
  }

  private void handleForEach(Node node) throws WorkflowException {
    final ForEachNode forEachNode = (ForEachNode) node;
    EndForEachNode endForEachNode = null;
    Collection<Node> repeatNodes = node.getOutputPort(0).getToNodes();
    // we will support only one for now
    if (repeatNodes.size() != 1) {
      throw new WorkFlowInterpreterException("Only one node allowed inside foreach");
    }
    Iterator<Node> iterator = repeatNodes.iterator();
    if (iterator.hasNext()) {

      Node middleNode = iterator.next();

      // forEachNode should point to a WSNode and should have only one
      // output
      if ((!(middleNode instanceof WSNode)) && (!(middleNode instanceof SubWorkflowNode))) {
        throw new WorkFlowInterpreterException("Encountered Node inside foreach that is not a WSNode" + middleNode);
      } else if (middleNode instanceof SubWorkflowNode) {
        /* Get the EndforEach Node of the Subworkflow */
        Iterator<Node> subWorkflowOut = middleNode.getOutputPort(0).getToNodes().iterator();
        while (subWorkflowOut.hasNext()) {
          Node node2 = subWorkflowOut.next();
          if (node2 instanceof EndForEachNode) {
            endForEachNode = (EndForEachNode) node2;
          }
        }

        final LinkedList<String> listOfValues = new LinkedList<String>();
        InterpreterUtil.getInputsForForEachNode(forEachNode, listOfValues, this.invokerMap);
        final Integer[] inputNumbers = InterpreterUtil.getNumberOfInputsForForEachNode(forEachNode, this.invokerMap);
        Workflow workflow1 = ((SubWorkflowNode) middleNode).getWorkflow();
        List<NodeImpl> nodes = workflow1.getGraph().getNodes();
        List<Node> wsNodes = new ArrayList<Node>();
        /* Take the List of WSNodes in the subworkflow */
        for (NodeImpl subWorkflowNode : nodes) {
          if (subWorkflowNode instanceof WSNode) {
            wsNodes.add(subWorkflowNode);
          }
        }

        for (int i = 0; i < wsNodes.size(); i++) {
          final WSNode node1 = (WSNode) wsNodes.get(i);
          SystemComponentInvoker systemInvoker = null;
          List<DataPort> outputPorts1 = node1.getOutputPorts();
          List<Node> endForEachNodes = new ArrayList<Node>();
          for (DataPort port : outputPorts1) {
            Iterator<Node> endForEachNodeItr1 = port.getToNodes().iterator();
            while (endForEachNodeItr1.hasNext()) {
              Node node2 = endForEachNodeItr1.next();
              if (node2 instanceof EndForEachNode) {
                endForEachNodes.add(node2);
              } else if (node2 instanceof OutputNode) {
                // intentionally left noop
              } else {
                throw new WorkFlowInterpreterException("Found More than one node inside foreach");
              }

            }
          }
          final List<Node> finalEndForEachNodes = endForEachNodes;

          Iterator<Node> endForEachNodeItr1 = node1.getOutputPort(0).getToNodes().iterator();
          while (endForEachNodeItr1.hasNext()) {
            Node node2 = endForEachNodeItr1.next();
            // Start reading input came for foreach node
            int parallelRuns = listOfValues.size() * node1.getOutputPorts().size();
            if (listOfValues.size() > 0) {
              forEachNode.setState(NodeExecutionState.EXECUTING);
              node1.setState(NodeExecutionState.EXECUTING);
              List<DataPort> outputPorts = node1.getOutputPorts();
              final AtomicInteger counter = new AtomicInteger();
              for (Node endFor : endForEachNodes) {
                systemInvoker = new SystemComponentInvoker();
                this.invokerMap.put(endFor, systemInvoker);
              }
              final Map<Node, Invoker> finalMap = this.invokerMap;
              new Thread() {
                @Override
                public void run() {
                  try {
                    runInThread(listOfValues, forEachNode, node1, finalEndForEachNodes, finalMap, counter, inputNumbers);
                  } catch (WorkflowException e) {

                    WorkflowInterpreter.this.config.getGUI().getErrorWindow().error(e);
                  }
                }

              }.start();

              while (counter.intValue() < parallelRuns) {
                try {
                  Thread.sleep(100);
                } catch (InterruptedException e) {
                  Thread.currentThread().interrupt();
                }

              }
              if (!(node2 instanceof OutputNode)) {
                listOfValues.removeAll(listOfValues);
                String output = (String) systemInvoker.getOutput(node1.getOutputPort(0).getName());
                XmlElement xmlElement = XMLUtil.stringToXmlElement("<result>" + output + "</result>");
                Iterator iterator1 = xmlElement.children().iterator();
                while (iterator1.hasNext()) {
                  Object next1 = iterator1.next();
                  if (next1 instanceof XmlElement) {
                    listOfValues.add((String) ((XmlElement) next1).children().iterator().next());
                  }
                }
              }
            }
          }
        }
        // we have finished execution so end foreach is finished
        // todo this has to be done in a separate thread
        endForEachNode.setState(NodeExecutionState.FINISHED);
        middleNode.setState(NodeExecutionState.FINISHED);
        node.setState(NodeExecutionState.FINISHED);

      } else {

        // First node after foreach should end with EndForEachNode
        List<DataPort> outputPorts1 = middleNode.getOutputPorts();
        List<Node> endForEachNodes = new ArrayList<Node>();
        for (DataPort port : outputPorts1) {
          Iterator<Node> endForEachNodeItr1 = port.getToNodes().iterator();
          while (endForEachNodeItr1.hasNext()) {
            Node node2 = endForEachNodeItr1.next();
            if (node2 instanceof EndForEachNode) {
              endForEachNodes.add(node2);
            } else if (node2 instanceof OutputNode) {
              // intentionally left noop
            } else {
              throw new WorkFlowInterpreterException("Found More than one node inside foreach");
            }

          }
        }
        final List<Node> finalEndForEachNodes = endForEachNodes;
        final Node foreachWSNode = middleNode;
        final LinkedList<String> listOfValues = new LinkedList<String>();

        // Start reading input came for foreach node
        InterpreterUtil.getInputsForForEachNode(forEachNode, listOfValues, this.invokerMap);
        final Integer[] inputNumbers = InterpreterUtil.getNumberOfInputsForForEachNode(forEachNode, this.invokerMap);

        int parallelRuns = createInputValues(listOfValues, inputNumbers).size() * outputPorts1.size();
        if (listOfValues.size() > 0) {

          forEachNode.setState(NodeExecutionState.EXECUTING);
          foreachWSNode.setState(NodeExecutionState.EXECUTING);
          List<DataPort> outputPorts = middleNode.getOutputPorts();
          final AtomicInteger counter = new AtomicInteger();
          for (Node endFor : endForEachNodes) {
            final SystemComponentInvoker systemInvoker = new SystemComponentInvoker();
View Full Code Here

Examples of org.apache.airavata.workflow.model.graph.system.ForEachNode

    dynamicInvoker.invoke();
    NodeController.getGUI(node).setBodyColor(NodeState.FINISHED.color);
  }

  private void handleForEach(Node node) throws WorkflowException {
    final ForEachNode forEachNode = (ForEachNode) node;
    EndForEachNode endForEachNode = null;
    Collection<Node> repeatNodes = node.getOutputPort(0).getToNodes();
    // we will support only one for now
    if (repeatNodes.size() != 1) {
      throw new WorkFlowInterpreterException("Only one node allowed inside foreach");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.