d2fe35d75f57ce5d9cb383c7c2fe58d1870898b4
[ccsdk/sli/core.git] / sli / provider-base / src / main / java / org / onap / ccsdk / sli / core / sli / provider / base / ReturnNodeExecutor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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=========================================================
20  */
21
22 package org.onap.ccsdk.sli.core.sli.provider.base;
23
24 import java.util.Iterator;
25 import java.util.Map;
26 import java.util.Set;
27
28 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 public class ReturnNodeExecutor extends AbstractSvcLogicNodeExecutor {
36
37         private static final Logger LOG = LoggerFactory
38                         .getLogger(ReturnNodeExecutor.class);
39         
40         @Override
41         public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node,
42                         SvcLogicContext ctx) throws SvcLogicException {
43
44                 String status = SvcLogicExpressionResolver.evaluate(
45                                 node.getAttribute("status"), node, ctx);
46
47                 if (status != null) {
48                         if (LOG.isDebugEnabled()) {
49                                 LOG.debug("Returning status " + status);
50                         }
51                         ctx.setStatus(status);
52                 } else {
53                         if (LOG.isWarnEnabled()) {
54                                 LOG.warn("Return node has no status attribute set");
55                         }
56                 }
57
58                 Set<Map.Entry<String, SvcLogicExpression>> parameterSet = node
59                                 .getParameterSet();
60
61                 for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parameterSet
62                                 .iterator(); iter.hasNext();) {
63                         Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
64                         String curName = curEnt.getKey();
65                         String curValue = SvcLogicExpressionResolver.evaluate(
66                                         curEnt.getValue(), node, ctx);
67
68                         if (LOG.isDebugEnabled()) {
69                                 LOG.debug("Setting context attribute " + curName + " to "
70                                                 + curValue);
71                         }
72                         ctx.setAttribute(curName, curValue);
73                 }
74                 return null;
75         }
76
77
78 }