e5be5e3a77b9a402a5eb794a23aa249d44256b72
[sdnc/northbound.git] / generic-resource-api / provider / src / main / java / org / onap / sdnc / northbound / GenericResourceApiSvcLogicServiceClient.java
1 package org.onap.sdnc.northbound;
2
3 import java.util.Properties;
4
5 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
6 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
7 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.preload.data.PreloadDataBuilder;
8 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.data.ServiceDataBuilder;
9 import org.osgi.framework.BundleContext;
10 import org.osgi.framework.FrameworkUtil;
11 import org.osgi.framework.ServiceReference;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14
15 public class GenericResourceApiSvcLogicServiceClient {
16
17         private static final Logger LOG = LoggerFactory
18                         .getLogger(GenericResourceApiSvcLogicServiceClient.class);
19
20         private SvcLogicService svcLogic = null;
21
22         public GenericResourceApiSvcLogicServiceClient(SvcLogicService svcLogic)
23         {
24                 this.svcLogic = svcLogic;
25         }
26
27         public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException
28         {
29                 return(svcLogic.hasGraph(module, rpc, version, mode));
30         }
31
32         public Properties execute(String module, String rpc, String version, String mode, ServiceDataBuilder serviceData)
33                         throws SvcLogicException {
34
35                 Properties parms = new Properties();
36
37                 return execute(module,rpc,version, mode,serviceData,parms);
38         }
39
40         public Properties execute(String module, String rpc, String version, String mode, PreloadDataBuilder serviceData)
41                         throws SvcLogicException {
42
43                 Properties parms = new Properties();
44
45                 return execute(module,rpc,version, mode,serviceData,parms);
46         }
47
48
49         public Properties execute(String module, String rpc, String version, String mode, ServiceDataBuilder serviceData, Properties parms)
50                                 throws SvcLogicException {
51
52                 parms = GenericResourceApiUtil.toProperties(parms, serviceData);
53
54                 if (LOG.isDebugEnabled())
55                 {
56                         LOG.debug("Parameters passed to SLI");
57
58                         for (Object key : parms.keySet()) {
59                                 String parmName = (String) key;
60                                 String parmValue = parms.getProperty(parmName);
61
62                                 LOG.debug(parmName+" = "+parmValue);
63
64                         }
65                 }
66
67
68                 Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
69
70
71                 if (LOG.isDebugEnabled())
72                 {
73                         LOG.debug("Parameters returned by SLI");
74
75                         for (Object key : respProps.keySet()) {
76                                 String parmName = (String) key;
77                                 String parmValue = respProps.getProperty(parmName);
78
79                                 LOG.debug(parmName+" = "+parmValue);
80
81                         }
82                 }
83                 if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
84                         return (respProps);
85                 }
86
87                 GenericResourceApiUtil.toBuilder(respProps, serviceData);
88
89                 return (respProps);
90         }
91
92
93         public Properties execute(String module, String rpc, String version, String mode, PreloadDataBuilder serviceData, Properties parms)
94                                 throws SvcLogicException {
95
96                 parms = GenericResourceApiUtil.toProperties(parms, serviceData);
97
98                 if (LOG.isDebugEnabled())
99                 {
100                         LOG.debug("Parameters passed to SLI");
101
102                         for (Object key : parms.keySet()) {
103                                 String parmName = (String) key;
104                                 String parmValue = parms.getProperty(parmName);
105
106                                 LOG.debug(parmName+" = "+parmValue);
107
108                         }
109                 }
110
111                 Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
112
113                 if (LOG.isDebugEnabled())
114                 {
115                         LOG.debug("Parameters returned by SLI");
116
117                         for (Object key : respProps.keySet()) {
118                                 String parmName = (String) key;
119                                 String parmValue = respProps.getProperty(parmName);
120
121                                 LOG.debug(parmName+" = "+parmValue);
122
123                         }
124                 }
125                 if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
126                         return (respProps);
127                 }
128
129                 GenericResourceApiUtil.toBuilder(respProps, serviceData);
130
131                 return (respProps);
132         }
133 }