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.onap.ccsdk.sli.core.sli.provider.base;
24 import java.util.HashMap;
25 import java.util.Iterator;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 public abstract class AbstractSvcLogicNodeExecutor {
41 protected SvcLogicResolver resolver;
42 public abstract SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException;
44 private static final Logger LOG = LoggerFactory.getLogger(AbstractSvcLogicNodeExecutor.class);
45 protected static final String PARAMETER_DEBUG_PATTERN = "Parameter: {} resolves to: {} which came from the expression: {}";
46 protected static final String SETTING_DEBUG_PATTERN = "Setting context attribute: {} to: {} which came from the expression: {}";
48 protected String evaluateNodeTest(SvcLogicNode node, SvcLogicContext ctx)
49 throws SvcLogicException {
54 return (SvcLogicExpressionResolver.evaluate(node.getAttribute("test"),
59 public void setResolver(SvcLogicResolver resolver) {
60 this.resolver = resolver;
63 protected SvcLogicAdaptor getAdaptor(String adaptorName) {
64 return resolver.getSvcLogicAdaptor(adaptorName);
67 protected SvcLogicResource getSvcLogicResource(String resourceName) {
68 return resolver.getSvcLogicResource(resourceName);
71 protected SvcLogicRecorder getSvcLogicRecorder(String recorderName) {
72 return resolver.getSvcLogicRecorder(recorderName);
75 protected SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName){
76 return resolver.getSvcLogicJavaPlugin(pluginName);
79 protected SvcLogicNode getNextNode(SvcLogicNode node, String outValue) {
80 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
81 if (nextNode != null) {
82 if (LOG.isDebugEnabled()) {
83 LOG.debug("about to execute " + outValue + " branch");
88 nextNode = node.getOutcomeValue("Other");
89 if (nextNode != null) {
90 if (LOG.isDebugEnabled()) {
91 LOG.debug("about to execute Other branch");
94 if (LOG.isDebugEnabled()) {
95 LOG.debug("no " + outValue + " or Other branch found");
101 protected Map<String, String> getResolvedParameters(SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException{
102 Map<String, String> parmMap = new HashMap<>();
104 Set<Map.Entry<String, SvcLogicExpression>> parmSet = node
107 for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parmSet
108 .iterator(); iter.hasNext();) {
109 Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
110 String curName = curEnt.getKey();
111 SvcLogicExpression curExpr = curEnt.getValue();
112 String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr, node, ctx);
113 LOG.trace(PARAMETER_DEBUG_PATTERN, curName, curExprValue, curExpr.toString());
114 parmMap.put(curName,curExprValue);