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