Update groupId to org.onap.ccsdk.sli
[ccsdk/sli/core.git] / sli / provider / src / main / java / org / onap / ccsdk / sli / core / sli / provider / CallNodeExecutor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
4  * ================================================================================
5  * Copyright (C) 2017 ONAP
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.ccsdk.sli.core.sli.provider;
22
23 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
24 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
25 import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
26 import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
27 import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 public class CallNodeExecutor extends SvcLogicNodeExecutor {
33
34         private static final Logger LOG = LoggerFactory
35                         .getLogger(CallNodeExecutor.class);
36         
37         @Override
38         public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx)
39                         throws SvcLogicException {
40
41                 String outValue = "not-found";
42                 
43                 SvcLogicGraph myGraph = node.getGraph();
44                 
45                 if (myGraph == null)
46                 {
47                         LOG.debug("execute: getGraph returned null");
48                 }
49                 else
50                 {
51                         LOG.debug("execute: got SvcLogicGraph");
52                 }
53                 
54                 SvcLogicExpression moduleExpr = null;
55                 
56                 String module = null;
57                 
58                 moduleExpr = node.getAttribute("module");
59                 if (moduleExpr != null)
60                 {
61                         module  = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx);
62                 }
63                 
64                 if ((module == null) || (module.length() == 0))
65                 {
66                         if (myGraph != null)
67                         {
68                                 module = myGraph.getModule();
69                                 LOG.debug("myGraph.getModule() returned "+module);
70                         }
71                 }
72                 
73                 SvcLogicExpression rpcExpr = null;
74                 String rpc = null;
75                 rpcExpr = node.getAttribute("rpc");
76                 if (rpcExpr != null)
77                 {
78                         rpc  = SvcLogicExpressionResolver.evaluate(rpcExpr, node, ctx);
79                 }
80                 
81                 if ((rpc == null) || (rpc.length() == 0))
82                 {
83                         if (myGraph != null)
84                         {
85                                 rpc = myGraph.getRpc();
86                                 LOG.debug("myGraph.getRpc() returned "+rpc);
87                         }
88                 }
89                 
90                 String mode = null;
91                 
92                 moduleExpr = node.getAttribute("mode");
93                 if (moduleExpr != null)
94                 {
95                         mode  = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx);
96                 }
97
98                 if ((mode == null) || (mode.length() == 0))
99                 {
100                         if (myGraph != null)
101                         {
102                                 mode = myGraph.getMode();
103
104                                 LOG.debug("myGraph.getMode() returned "+mode);
105                         }
106                 }
107                 
108                 String version = null;
109                 
110                 moduleExpr = node.getAttribute("version");
111                 if (moduleExpr != null)
112                 {
113                         version  = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx);
114                 }
115
116                 String parentGraph = ctx.getAttribute("currentGraph");
117         ctx.setAttribute("parentGraph", parentGraph);
118                 
119                 SvcLogicStore store = getStore();
120                 
121         if (store != null) {
122                         SvcLogicGraph calledGraph = store.fetch(module, rpc, version, mode);
123             LOG.debug("Parent " + parentGraph + " is calling child " + calledGraph.toString());
124             ctx.setAttribute("currentGraph", calledGraph.toString());
125             if (calledGraph != null) {
126                                 svc.execute(calledGraph, ctx);
127                                 
128                                 outValue = ctx.getStatus();
129             } else {
130                 LOG.error("Could not find service logic for [" + module + "," + rpc + "," + version + "," + mode + "]");
131                         }
132                 }
133                 else
134                 {
135                         LOG.debug("Could not get SvcLogicStore reference");
136                 }
137                 
138                 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
139                 if (nextNode != null) {
140                         if (LOG.isDebugEnabled()) {
141                                 LOG.debug("about to execute " + outValue + " branch");
142                         }
143             ctx.setAttribute("currentGraph", parentGraph);
144                         return (nextNode);
145                 }
146
147                 nextNode = node.getOutcomeValue("Other");
148                 if (nextNode != null) {
149                         if (LOG.isDebugEnabled()) {
150                                 LOG.debug("about to execute Other branch");
151                         }
152                 } else {
153                         if (LOG.isDebugEnabled()) {
154                                 LOG.debug("no " + outValue + " or Other branch found");
155                         }
156                 }
157         ctx.setAttribute("currentGraph", parentGraph);
158         ctx.setAttribute("parentGraph", null);
159
160                 return (nextNode);
161
162         }
163
164 }