Refactor dblib
[ccsdk/sli/core.git] / sli / provider / src / main / java / org / onap / ccsdk / sli / core / sli / provider / ReturnNodeExecutor.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 java.util.Iterator;
24 import java.util.Map;
25 import java.util.Set;
26
27 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class ReturnNodeExecutor extends SvcLogicNodeExecutor {
35
36         private static final Logger LOG = LoggerFactory
37                         .getLogger(ReturnNodeExecutor.class);
38         
39         @Override
40         public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
41                         SvcLogicContext ctx) throws SvcLogicException {
42
43                 String status = SvcLogicExpressionResolver.evaluate(
44                                 node.getAttribute("status"), node, ctx);
45
46                 if (status != null) {
47                         if (LOG.isDebugEnabled()) {
48                                 LOG.debug("Returning status " + status);
49                         }
50                         ctx.setStatus(status);
51                 } else {
52                         if (LOG.isWarnEnabled()) {
53                                 LOG.warn("Return node has no status attribute set");
54                         }
55                 }
56
57                 Set<Map.Entry<String, SvcLogicExpression>> parameterSet = node
58                                 .getParameterSet();
59
60                 for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parameterSet
61                                 .iterator(); iter.hasNext();) {
62                         Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
63                         String curName = curEnt.getKey();
64                         String curValue = SvcLogicExpressionResolver.evaluate(
65                                         curEnt.getValue(), node, ctx);
66
67                         if (LOG.isDebugEnabled()) {
68                                 LOG.debug("Setting context attribute " + curName + " to "
69                                                 + curValue);
70                         }
71                         ctx.setAttribute(curName, curValue);
72                 }
73                 return null;
74         }
75
76
77 }