Third part of onap rename
[appc.git] / appc-inbound / appc-artifact-handler / provider / src / main / java / org / onap / appc / artifact / handler / dbservices / DBService.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.artifact.handler.dbservices;
26
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
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.SvcLogicResource;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
34 import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants;
35
36 import java.sql.SQLException;
37 import java.util.HashMap;
38 import org.apache.commons.lang.StringUtils;
39
40 public class DBService {
41
42     private static final EELFLogger log = EELFManager.getInstance().getLogger(DBService.class);
43     private SvcLogicResource serviceLogic;
44     private static DBService dgGeneralDBService = null;
45
46     public static DBService initialise() {
47         if (dgGeneralDBService == null) {
48             dgGeneralDBService = new DBService();
49         }
50         return dgGeneralDBService;
51     }
52
53     private DBService() {
54         if (serviceLogic == null) {
55             serviceLogic = new SqlResource();
56         }
57     }
58
59     protected DBService(SqlResource svcLogic) {
60         if (serviceLogic == null) {
61             serviceLogic = svcLogic;
62         }
63     }
64
65     public String getInternalVersionNumber(SvcLogicContext ctx, String artifactName, String prefix)
66             throws SvcLogicException {
67         String fn = "DBService.getInternalVersionNumber";
68         QueryStatus status = null;
69         String artifactInternalVersion = null;
70         if (serviceLogic != null && ctx != null) {
71             String key = "select max(internal_version) as maximum from ASDC_ARTIFACTS  WHERE ARTIFACT_NAME = '"
72                     + artifactName + "'";
73             log.info("Getting internal Versoin :" + key);
74             status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx);
75             if (status.toString().equals("FAILURE"))
76                 throw new SvcLogicException("Error - getting internal Artifact Number");
77             artifactInternalVersion = ctx.getAttribute("maximum");
78             log.info("Internal Version received as : " + artifactInternalVersion);
79             log.info("Internal Version received as1 : " + ctx.getAttribute("max(internal_version)"));
80             log.info("Internal Version received as1 : " + ctx.getAttribute("max"));
81             log.info("Internal Version received as1 : " + ctx.getAttribute("internal_version"));
82             log.info("Internal Version received as1 : " + ctx.getAttributeKeySet().toString());
83         }
84         return artifactInternalVersion;
85     }
86
87     public String getArtifactID(SvcLogicContext ctx, String artifactName) throws SvcLogicException {
88         String fn = "DBService.getArtifactID";
89         QueryStatus status = null;
90         String artifactID = null;
91         if (serviceLogic != null && ctx != null) {
92             String key = "select max(ASDC_ARTIFACTS_ID) as id from ASDC_ARTIFACTS  WHERE ARTIFACT_NAME = '"
93                     + artifactName + "'";
94             log.info("Getting Artifact ID String :" + key);
95             status = serviceLogic.query("SQL", false, null, key, null, null, ctx);
96             if (status.toString().equals("FAILURE"))
97                 throw new SvcLogicException("Error - getting  Artifact ID from database");
98             artifactID = ctx.getAttribute("id");
99             log.info("SDC_ARTIFACTS_ID received as : " + ctx.getAttribute("id"));
100         }
101         return artifactID;
102     }
103
104     public QueryStatus saveArtifacts(SvcLogicContext ctx, int intversion) throws SvcLogicException {
105         String fn = "DBService.saveArtifacts";
106         QueryStatus status = null;
107         if (serviceLogic != null && ctx != null) {
108             String key = "INSERT INTO ASDC_ARTIFACTS " + "SET SERVICE_UUID    =  $service-uuid , "
109                     + " DISTRIBUTION_ID    =  $distribution-id ," + " SERVICE_NAME    =  $service-name ,"
110                     + " SERVICE_DESCRIPTION    =  $service-description ," + " RESOURCE_UUID    = $resource-uuid ,"
111                     + " RESOURCE_INSTANCE_NAME    = $resource-instance-name ," + " RESOURCE_NAME    = $resource-name ,"
112                     + " RESOURCE_VERSION    = $resource-version ," + " RESOURCE_TYPE    = $resource-type ,"
113                     + " ARTIFACT_UUID    = $artifact-uuid ," + " ARTIFACT_TYPE    = $artifact-type ,"
114                     + " ARTIFACT_VERSION    = $artifact-version ," + " ARTIFACT_DESCRIPTION    = $artifact-description ,"
115                     + " INTERNAL_VERSION    = " + intversion + "," + " ARTIFACT_NAME       =  $artifact-name ,"
116                     + " ARTIFACT_CONTENT    =  $artifact-contents ";
117
118             status = serviceLogic.save("SQL", false, false, key, null, null, ctx);
119             if (status.toString().equals("FAILURE"))
120                 throw new SvcLogicException("Error While processing storing Artifact: "
121                         + ctx.getAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME));
122         }
123         return status;
124
125     }
126
127     public QueryStatus logData(SvcLogicContext ctx, String prefix) throws SvcLogicException {
128         String fn = "DBService.saveReferenceData";
129         QueryStatus status = null;
130         if (serviceLogic != null && ctx != null) {
131             String key = "INSERT INTO CONFIG_TRANSACTION_LOG " + " SET request_id = $request-id , "
132                     + " message_type = $log-message-type , " + " message = $log-message ;";
133             status = serviceLogic.save("SQL", false, false, key, null, prefix, ctx);
134             if (status.toString().equals("FAILURE"))
135                 throw new SvcLogicException("Error while loging data");
136
137         }
138         return status;
139     }
140
141     public void processConfigureActionDg(SvcLogicContext context, boolean isUpdate) {
142         String fn = "DBService.processConfigureActionDg";
143         log.info("Update Parameter for SDC Reference " + isUpdate);
144         String key = "";
145         QueryStatus status = null;
146         if (isUpdate)
147             ;
148     }
149
150     public void processSdcReferences(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
151         String fn = "DBService.processSdcReferences";
152         String key = "";
153         QueryStatus status = null;
154
155         if (isUpdate && context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY).equals(SdcArtifactHandlerConstants.CAPABILITY)) {
156             log.info("Updating capability artifact in ASDC_REFERENCE");
157             key = "update " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + "  set ARTIFACT_NAME = $"
158                     + SdcArtifactHandlerConstants.ARTIFACT_NAME + " where " + "FILE_CATEGORY = $"
159                     + SdcArtifactHandlerConstants.FILE_CATEGORY + " and VNF_TYPE = $"
160                     + SdcArtifactHandlerConstants.VNF_TYPE ;
161         } else if (isUpdate)
162             key = "update " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + "  set ARTIFACT_NAME = $"
163                     + SdcArtifactHandlerConstants.ARTIFACT_NAME + " where VNFC_TYPE = $"
164                     + SdcArtifactHandlerConstants.VNFC_TYPE + " and FILE_CATEGORY = $"
165                     + SdcArtifactHandlerConstants.FILE_CATEGORY + " and ACTION = $"
166                     + SdcArtifactHandlerConstants.ACTION + " and VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE;
167
168         else {
169             if (context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY).equals(SdcArtifactHandlerConstants.CAPABILITY)) {
170                 key = "insert into " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set VNFC_TYPE = null "
171                         + " , FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY + " , VNF_TYPE = $"
172                         + SdcArtifactHandlerConstants.VNF_TYPE + " , ACTION = null " + " , ARTIFACT_TYPE = null "
173                         + " , ARTIFACT_NAME = $" + SdcArtifactHandlerConstants.ARTIFACT_NAME;
174             } else {
175                 key = "insert into " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set VNFC_TYPE = $"
176                         + SdcArtifactHandlerConstants.VNFC_TYPE + " , FILE_CATEGORY = $"
177                         + SdcArtifactHandlerConstants.FILE_CATEGORY + " , VNF_TYPE = $"
178                         + SdcArtifactHandlerConstants.VNF_TYPE + " , ACTION = $" + SdcArtifactHandlerConstants.ACTION
179                         + " , ARTIFACT_TYPE = $" + SdcArtifactHandlerConstants.ARTIFACT_TYPE + " , ARTIFACT_NAME = $"
180                         + SdcArtifactHandlerConstants.ARTIFACT_NAME;
181             }
182         }
183         if (serviceLogic != null && context != null) {
184             log.info("Insert Key: " + key);
185             status = serviceLogic.save("SQL", false, false, key, null, null, context);
186             if (status.toString().equals("FAILURE"))
187                 throw new SvcLogicException("Error While processing sdc_reference table ");
188         }
189     }
190
191     public boolean isArtifactUpdateRequired(SvcLogicContext context, String db) throws SvcLogicException, SQLException {
192         String fn = "DBService.isArtifactUpdateRequired";
193         log.info("Checking if Update required for this data");
194
195         log.info("db" + db);
196         log.info("ACTION=" + context.getAttribute(SdcArtifactHandlerConstants.ACTION));
197         log.info("VNFC_TYPE=" + context.getAttribute(SdcArtifactHandlerConstants.VNFC_TYPE));
198         log.info("VNFC_INSTANCE=" + context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE));
199         log.info("VM_INSTANCE=" + context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE));
200         log.info("VNF_TYPE=" + context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE));
201         String whereClause = "";
202
203         QueryStatus status = null;
204         whereClause = " where VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE;
205
206         if (db != null) {
207             if (db.equals(SdcArtifactHandlerConstants.DB_SDC_REFERENCE)
208                     && context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY)
209                     .equals(SdcArtifactHandlerConstants.CAPABILITY)
210                     && context.getAttribute(SdcArtifactHandlerConstants.ACTION) == null) {
211                 whereClause = whereClause + " and FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY;
212             }
213
214             else if (db.equals(SdcArtifactHandlerConstants.DB_SDC_REFERENCE)) {
215                 whereClause = whereClause + " and VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE
216                         + " and FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY + " and ACTION = $"
217                         + SdcArtifactHandlerConstants.ACTION;
218             }
219
220             else if (db.equals(SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE)) {
221                 whereClause = " where PROTOCOL = $" + SdcArtifactHandlerConstants.DEVICE_PROTOCOL;
222             } else if (db.equals(SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG)) {
223                 whereClause = whereClause + " and ACTION = $" + SdcArtifactHandlerConstants.ACTION;
224             } else if (db.equals(SdcArtifactHandlerConstants.DB_VNFC_REFERENCE)) {
225                 int vm_instance = -1;
226                 if (context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE) != null)
227                     vm_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE));
228                 int vnfc_instance = -1;
229                 if (context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE) != null)
230                     vnfc_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE));
231                 whereClause = whereClause + " and ACTION = $" + SdcArtifactHandlerConstants.ACTION + " and VNFC_TYPE = $"
232                         + SdcArtifactHandlerConstants.VNFC_TYPE + " and VNFC_INSTANCE = $"
233                         + SdcArtifactHandlerConstants.VNFC_INSTANCE + " and VM_INSTANCE = $"
234                         + SdcArtifactHandlerConstants.VM_INSTANCE;
235
236             }
237         }
238
239         if (serviceLogic != null && context != null) {
240             String key = "select COUNT(*) from " + db + whereClause;
241             log.info("SELECT String : " + key);
242             status = serviceLogic.query("SQL", false, null, key, null, null, context);
243             if (status.toString().equals("FAILURE")) {
244                 throw new SvcLogicException("Error while reading data from " + db);
245             }
246             String count = context.getAttribute("COUNT(*)");
247             log.info("Number of row Returned : " + count + ": " + status + ":");
248             if (count != null && Integer.parseInt(count) > 0) {
249                 context.setAttribute(count, null);
250                 return true;
251             } else
252                 return false;
253         }
254         return false;
255     }
256
257     public void processDeviceInterfaceProtocol(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
258         String fn = "DBService.processDeviceInterfaceProtocol";
259         log.info("Starting DB operation for Device Interface Protocol " + isUpdate);
260         String key = "";
261         QueryStatus status = null;
262         if (isUpdate)
263             key = "update " + SdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL + " set PROTOCOL = $"
264                     + SdcArtifactHandlerConstants.DEVICE_PROTOCOL + " , DG_RPC = 'getDeviceRunningConfig' "
265                     + " , MODULE = 'APPC' " + " where VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE;
266         else
267             key = "insert into " + SdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL + " set  VNF_TYPE = $"
268                     + SdcArtifactHandlerConstants.VNF_TYPE + " , PROTOCOL = $"
269                     + SdcArtifactHandlerConstants.DEVICE_PROTOCOL + " , DG_RPC = 'getDeviceRunningConfig' "
270                     + " , MODULE = 'APPC' ";
271
272         if (serviceLogic != null && context != null) {
273
274             status = serviceLogic.save("SQL", false, false, key, null, null, context);
275             if (status.toString().equals("FAILURE"))
276                 throw new SvcLogicException("Error While processing DEVICE_INTERFACE_PROTOCOL table ");
277         }
278
279     }
280
281     public void processDeviceAuthentication(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
282         String fn = "DBService.processDeviceAuthentication";
283         log.info(fn + "Starting DB operation for Device Authentication " + isUpdate);
284         String key = "";
285         QueryStatus status = null;
286         if (isUpdate)
287             key = "update " + SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION + " set USER_NAME = $"
288                     + SdcArtifactHandlerConstants.USER_NAME +/* " , PASSWORD = 'dummy' " +*/ " , PORT_NUMBER = $"
289                     + SdcArtifactHandlerConstants.PORT_NUMBER + " where VNF_TYPE = $"
290                     + SdcArtifactHandlerConstants.VNF_TYPE;
291         else
292             key = "insert into " + SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION + " set  VNF_TYPE = $"
293                     + SdcArtifactHandlerConstants.VNF_TYPE + " , USER_NAME = $" + SdcArtifactHandlerConstants.USER_NAME
294                     +/* " , PASSWORD = 'dummy' " + */ " , PORT_NUMBER = $" + SdcArtifactHandlerConstants.PORT_NUMBER;
295
296         if (serviceLogic != null && context != null) {
297             status = serviceLogic.save("SQL", false, false, key, null, null, context);
298             if (status.toString().equals("FAILURE"))
299                 throw new SvcLogicException("Error While processing DEVICE_AUTHENTICATION table ");
300         }
301     }
302
303     public void processVnfcReference(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
304         String fn = "DBService.processVnfcReference";
305         log.info(fn + "Starting DB operation for Vnfc Reference " + isUpdate);
306         String key = "";
307         int vm_instance = -1;
308         if (context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE) != null)
309             vm_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE));
310         int vnfc_instance = -1;
311         if (context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE) != null)
312             vnfc_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE));
313         QueryStatus status = null;
314         if (isUpdate)
315             key = "update " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE + " set VM_INSTANCE = " + vm_instance
316                     + " , VNFC_INSTANCE = " + vnfc_instance + " , VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE
317                     + " , VNFC_FUNCTION_CODE = $" + SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE
318                     + " , GROUP_NOTATION_TYPE = $" + SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE
319                     + " , GROUP_NOTATION_VALUE = $" + SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE
320                     + " , IPADDRESS_V4_OAM_VIP = $" + SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP
321                     + " where VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE + " and ACTION = $"
322                     + SdcArtifactHandlerConstants.ACTION + " and VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE
323                     + " and VNFC_INSTANCE = $" + SdcArtifactHandlerConstants.VNFC_INSTANCE + " and VM_INSTANCE = $"
324                     + SdcArtifactHandlerConstants.VM_INSTANCE;
325         else
326             key = "insert into " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE + " set  VNF_TYPE = $"
327                     + SdcArtifactHandlerConstants.VNF_TYPE + " , ACTION = $" + SdcArtifactHandlerConstants.ACTION
328                     + " , VM_INSTANCE = $" + SdcArtifactHandlerConstants.VM_INSTANCE + " , VNFC_INSTANCE = $"
329                     + SdcArtifactHandlerConstants.VNFC_INSTANCE + " , VNFC_TYPE = $"
330                     + SdcArtifactHandlerConstants.VNFC_TYPE + " , VNFC_FUNCTION_CODE = $"
331                     + SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE + " , GROUP_NOTATION_TYPE = $"
332                     + SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE + " , IPADDRESS_V4_OAM_VIP = $"
333                     + SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP + " , GROUP_NOTATION_VALUE = $"
334                     + SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE;
335
336         if (serviceLogic != null && context != null) {
337             status = serviceLogic.save("SQL", false, false, key, null, null, context);
338             if (status.toString().equals("FAILURE"))
339                 throw new SvcLogicException("Error While processing VNFC_REFERENCE table ");
340         }
341     }
342
343     public void processDownloadDgReference(SvcLogicContext context, boolean isUpdate)
344             throws SvcLogicException, SQLException {
345         String fn = "DBService.processDownloadDgReference";
346         log.info(fn + "Starting DB operation for Download DG Reference " + isUpdate);
347         String key = "";
348         QueryStatus status = null;
349
350         if (isUpdate)
351             key = "update " + SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE + " set DOWNLOAD_CONFIG_DG = $"
352                     + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " where PROTOCOL = $"
353                     + SdcArtifactHandlerConstants.DEVICE_PROTOCOL;
354         else
355             key = "insert into " + SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE + " set DOWNLOAD_CONFIG_DG = $"
356                     + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " , PROTOCOL = $"
357                     + SdcArtifactHandlerConstants.DEVICE_PROTOCOL;
358
359         if (serviceLogic != null && context != null)
360             status = serviceLogic.save("SQL", false, false, key, null, null, context);
361         if ((status == null) || status.toString().equals("FAILURE"))
362             throw new SvcLogicException("Error While processing DOWNLOAD_DG_REFERENCE table ");
363     }
364
365     public void processConfigActionDg(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
366         String fn = "DBService.processConfigActionDg";
367         log.info(fn + "Starting DB operation for Config DG Action " + isUpdate);
368         String key = "";
369         QueryStatus status = null;
370
371         if (context.getAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE) != null
372                 && context.getAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE).length() > 0) {
373             if (isUpdate)
374                 key = "update " + SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG + " set DOWNLOAD_CONFIG_DG = $"
375                         + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " where ACTION = $"
376                         + SdcArtifactHandlerConstants.ACTION + " and VNF_TYPE = $"
377                         + SdcArtifactHandlerConstants.VNF_TYPE;
378             else
379                 key = "insert into " + SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG + " set DOWNLOAD_CONFIG_DG = $"
380                         + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " , ACTION = $"
381                         + SdcArtifactHandlerConstants.ACTION + " , VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE;
382
383             if (serviceLogic != null && context != null)
384                 status = serviceLogic.save("SQL", false, false, key, null, null, context);
385             if ((status == null) || status.toString().equals("FAILURE"))
386                 throw new SvcLogicException("Error While processing Configure DG Action table ");
387         } else
388             log.info("No Update required for Config DG Action");
389
390     }
391
392     public String getModelDataInformationbyArtifactName(String artifact_name) throws SvcLogicException {
393         String fn = "DBService.getVnfData";
394         String key = "";
395         SvcLogicContext con = new SvcLogicContext();
396         HashMap<String, String> modelData = new HashMap<String, String>();
397         QueryStatus status = null;
398         key = "select VNF_TYPE, VNFC_TYPE, ACTION, FILE_CATEGORY, ARTIFACT_TYPE from ASDC_REFERENCE where  ARTIFACT_NAME = "
399                 + artifact_name;
400
401         if (serviceLogic != null && con != null) {
402             log.info(fn + "select Key: " + key);
403             status = serviceLogic.query("SQL", false, null, key, null, null, con);
404             if (status.toString().equals("FAILURE"))
405                 throw new SvcLogicException("Error While processing is ArtifactUpdateRequiredforPD table ");
406
407         }
408
409         log.info(fn + "Vnf_received :" + con.getAttribute("VNF_TYPE"));
410
411         return con.getAttribute("VNF_TYPE");
412
413     }
414
415     public void updateYangContents(SvcLogicContext context, String artifactId, String yangContents)
416             throws SvcLogicException {
417         String fn = "DBService.updateYangContents";
418         log.info(fn + "Starting DB operation for  updateYangContents");
419         String key = "";
420         QueryStatus status = null;
421
422         key = "update ASDC_ARTIFACTS " + " set ARTIFACT_CONTENT = '" + yangContents + "'"
423                 + " where ASDC_ARTIFACTS_ID = " + artifactId;
424
425         if (serviceLogic != null && context != null)
426             status = serviceLogic.save("SQL", false, false, key, null, null, context);
427         if ((status == null) || status.toString().equals("FAILURE"))
428             throw new SvcLogicException("Error While processing Configure DG Action table ");
429
430     }
431
432
433     public void insertProtocolReference(SvcLogicContext context, String vnfType, String protocol, String action,
434             String action_level, String template) throws SvcLogicException {
435         String fn = "DBService.insertProtocolReference";
436         log.info(fn + "Starting DB operation for  insertProtocolReference");
437         String key = "";
438         QueryStatus status = null;
439
440         key = "insert into PROTOCOL_REFERENCE (ACTION, VNF_TYPE, PROTOCOL, UPDATED_DATE, TEMPLATE, ACTION_LEVEL)"
441                 + " values  (" + "'" + action + "', '" + vnfType + "', '" + protocol + "', now(),'" + template + "', '"
442                 + action_level + "')";
443
444         if (serviceLogic != null && context != null)
445             status = serviceLogic.save("SQL", false, false, key, null, null, context);
446         if ((status == null) || status.toString().equals("FAILURE"))
447             throw new SvcLogicException("Error While processing insertProtocolReference ");
448
449     }
450
451     public boolean isProtocolReferenceUpdateRequired(SvcLogicContext context, String vnfType, String protocol,
452              String action, String action_level, String template) throws SvcLogicException {
453         SvcLogicContext localContext = new SvcLogicContext();
454         String fn = "DBService.isProtocolReferenceUpdateRequired";
455         log.info(fn + "Starting DB operation for  isProtocolReferenceUpdateRequired");
456         String key = "";
457         QueryStatus status = null;
458
459         key = "select COUNT(*) from PROTOCOL_REFERENCE where ACTION='" + action + "' and ACTION_LEVEL='" + action_level
460                 + "' and VNF_TYPE='" + vnfType + "'";
461         status = serviceLogic.query("SQL", false, null, key, null, null, localContext);
462         String countStr = localContext.getAttribute("COUNT(*)");
463         int count = Integer.parseInt(countStr);
464         if (count > 0)
465             return true;
466         else
467             return false;
468     }
469
470     public void updateProtocolReference(SvcLogicContext context, String vnfType, String protocol, String action,
471                 String action_level, String template) throws SvcLogicException {
472
473         String fn = "DBService.isProtocolReferenceUpdateRequired";
474         log.info(fn + "Starting DB operation for  isProtocolReferenceUpdateRequired");
475         String key = "";
476         QueryStatus status = null;
477
478         key = "update PROTOCOL_REFERENCE set UPDATED_DATE=now(), template='" + template + "' where ACTION='" + action
479                 + "' and ACTION_LEVEL='" + action_level + "' and VNF_TYPE='" + vnfType + "'";
480         status = serviceLogic.save("SQL", false, false, key, null, null, context);
481         if (status == QueryStatus.FAILURE) {
482             log.info("updateProtocolReference:: Error updating protocol reference");
483             throw new SvcLogicException("Error - updating PROTOCOL_REFERENCE_TABLE in updateProtocolReference");
484         }
485         return;
486     }
487
488     public String getDownLoadDGReference(SvcLogicContext context) throws Exception {
489         String fn = "DBService.setDownLoadDGReference";
490         String downloadConfigDg = null;
491         log.info(fn + "Setting Download DG Reference from DB");
492         String key = "";
493         QueryStatus status = null;
494         String protocol = context.getAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL);
495         if (StringUtils.isBlank(protocol)) {
496             log.info(fn + " :: Protocol is Blank!! Returning without querying DB");
497             throw new Exception(fn+":: Protocol is Blank!! Returning without querying DB");
498         }
499         key = "select download_config_dg from " + SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE
500                 + " where protocol = '" + protocol + "'";
501         SvcLogicContext localContext = new SvcLogicContext();
502         status = serviceLogic.query("SQL", false, null, key, null, null, localContext);
503         if (status == QueryStatus.FAILURE) {
504             log.info(fn + ":: Error retrieving download_config_dg");
505             throw new SvcLogicException("Error retrieving download_config_dg");
506         }
507         if (status == QueryStatus.NOT_FOUND) {
508             log.info(fn + ":: NOT_FOUND! No data found for download_config_dg!!");
509             throw new Exception(fn + ":: NOT_FOUND! No data found for download_config_dg!");
510         }
511         downloadConfigDg = localContext.getAttribute("download-config-dg");
512         log.info(fn + "download_config_dg::" + downloadConfigDg);
513         return downloadConfigDg;
514     }
515
516     public void cleanUpVnfcReferencesForVnf(SvcLogicContext context) throws SvcLogicException {
517         String key1 = "delete from " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE
518                 + " where action = 'Configure' and vnf_type = $" + SdcArtifactHandlerConstants.VNF_TYPE;
519         QueryStatus status = null;
520         log.info("cleanUpVnfcReferencesForVnf()::Query:" + key1);
521         if (serviceLogic != null && context != null) {
522             status = serviceLogic.save("SQL", false, false, key1, null, null, context);
523             if (status.toString().equals("FAILURE")) {
524                 log.debug("Error deleting from VNFC_REFERENCE table");
525                 throw new SvcLogicException("Error While processing VNFC_REFERENCE table ");
526             }
527         }
528     }
529
530
531 }