2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.sdnc.sli.provider;
24 import org.openecomp.sdnc.sli.BreakNodeException;
25 import org.openecomp.sdnc.sli.SvcLogicContext;
26 import org.openecomp.sdnc.sli.SvcLogicException;
27 import org.openecomp.sdnc.sli.SvcLogicExpression;
28 import org.openecomp.sdnc.sli.SvcLogicNode;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class WhileNodeExecutor extends SvcLogicNodeExecutor {
34 private static final Logger LOG = LoggerFactory.getLogger(WhileNodeExecutor.class);
37 public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException {
39 String testResult = evaluateNodeTest(node, ctx);
40 SvcLogicExpression silentFailureExpr = node.getAttribute("do");
41 String doWhile = SvcLogicExpressionResolver.evaluate(silentFailureExpr, node, ctx);
42 if ("true".equals(doWhile)) {
43 LOG.debug("While loop will execute once regardless of expression because do is set to true");
47 while ("true".equals(testResult) || "true".equals(doWhile)) {
48 if (!"true".equals(doWhile)) {
49 LOG.debug("Test expression (" + node.getAttribute("test") + ") evaluates to true, executing loop.");
51 int numOutcomes = node.getNumOutcomes() + 1;
52 for (int i = 0; i < numOutcomes; i++) {
53 SvcLogicNode nextNode = node.getOutcomeValue("" + (i + 1));
54 if (nextNode != null) {
55 while (nextNode != null) {
56 nextNode = svc.executeNode(nextNode, ctx);
59 if ("true".equals(doWhile)) {
60 LOG.debug("Do executed, will only execute again if test expression is true.");
63 testResult = evaluateNodeTest(node, ctx);
64 LOG.debug("test expression (" + node.getAttribute("test") + ") evaluates to " + testResult);
68 LOG.debug("testResult was " + testResult + " which is not equal to true, exiting while loop.");
69 } catch (BreakNodeException e) {
70 LOG.debug("WhileNodeExecutor caught break");