Changes to ProtocolReference table insert
[appc.git] / appc-inbound / appc-artifact-handler / provider / src / main / java / org / openecomp / 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.openecomp.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.openecomp.appc.artifact.handler.utils.SdcArtifactHandlerConstants;
35
36 import java.sql.SQLException;
37 import java.util.HashMap;
38
39 public class DBService {
40
41     private static final EELFLogger log = EELFManager.getInstance().getLogger(DBService.class);
42     private SvcLogicResource serviceLogic;
43     private static DBService dgGeneralDBService = null;
44
45     public static DBService initialise() {
46         if (dgGeneralDBService == null) {
47             dgGeneralDBService = new DBService();
48         }
49         return dgGeneralDBService;
50     }
51
52     private DBService() {
53         if (serviceLogic == null) {
54             serviceLogic = new SqlResource();
55         }
56     }
57
58     protected DBService(SqlResource svcLogic) {
59         if (serviceLogic == null) {
60             serviceLogic = svcLogic;
61         }
62     }
63
64     public String getInternalVersionNumber(SvcLogicContext ctx, String artifactName, String prefix)
65             throws SvcLogicException {
66         String fn = "DBService.getInternalVersionNumber";
67         QueryStatus status = null;
68         String artifactInternalVersion = null;
69         if (serviceLogic != null && ctx != null) {
70             String key = "select max(internal_version) as maximum from ASDC_ARTIFACTS  WHERE ARTIFACT_NAME = '"
71                     + artifactName + "'";
72             log.info("Getting internal Versoin :" + key);
73             status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx);
74             if (status.toString().equals("FAILURE"))
75                 throw new SvcLogicException("Error - getting internal Artifact Number");
76             artifactInternalVersion = ctx.getAttribute("maximum");
77             log.info("Internal Version received as : " + artifactInternalVersion);
78             log.info("Internal Version received as1 : " + ctx.getAttribute("max(internal_version)"));
79             log.info("Internal Version received as1 : " + ctx.getAttribute("max"));
80             log.info("Internal Version received as1 : " + ctx.getAttribute("internal_version"));
81             log.info("Internal Version received as1 : " + ctx.getAttributeKeySet().toString());
82         }
83         return artifactInternalVersion;
84     }
85
86     public String getArtifactID(SvcLogicContext ctx, String artifactName) throws SvcLogicException {
87         String fn = "DBService.getArtifactID";
88         QueryStatus status = null;
89         String artifactID = null;
90         if (serviceLogic != null && ctx != null) {
91             String key = "select max(ASDC_ARTIFACTS_ID) as id from ASDC_ARTIFACTS  WHERE ARTIFACT_NAME = '"
92                     + artifactName + "'";
93             log.info("Getting Artifact ID String :" + key);
94             status = serviceLogic.query("SQL", false, null, key, null, null, ctx);
95             if (status.toString().equals("FAILURE"))
96                 throw new SvcLogicException("Error - getting  Artifact ID from database");
97             artifactID = ctx.getAttribute("id");
98             log.info("SDC_ARTIFACTS_ID received as : " + ctx.getAttribute("id"));
99         }
100         return artifactID;
101     }
102
103     public QueryStatus saveArtifacts(SvcLogicContext ctx, int intversion) throws SvcLogicException {
104         String fn = "DBService.saveArtifacts";
105         QueryStatus status = null;
106         if (serviceLogic != null && ctx != null) {
107             String key = "INSERT INTO ASDC_ARTIFACTS " + "SET SERVICE_UUID    =  $service-uuid , "
108                     + " DISTRIBUTION_ID    =  $distribution-id ," + " SERVICE_NAME    =  $service-name ,"
109                     + " SERVICE_DESCRIPTION    =  $service-description ," + " RESOURCE_UUID    = $resource-uuid ,"
110                     + " RESOURCE_INSTANCE_NAME    = $resource-instance-name ," + " RESOURCE_NAME    = $resource-name ,"
111                     + " RESOURCE_VERSION    = $resource-version ," + " RESOURCE_TYPE    = $resource-type ,"
112                     + " ARTIFACT_UUID    = $artifact-uuid ," + " ARTIFACT_TYPE    = $artifact-type ,"
113                     + " ARTIFACT_VERSION    = $artifact-version ," + " ARTIFACT_DESCRIPTION    = $artifact-description ,"
114                     + " INTERNAL_VERSION    = " + intversion + "," + " ARTIFACT_NAME       =  $artifact-name ,"
115                     + " ARTIFACT_CONTENT    =  $artifact-contents ";
116
117             status = serviceLogic.save("SQL", false, false, key, null, null, ctx);
118             if (status.toString().equals("FAILURE"))
119                 throw new SvcLogicException("Error While processing storing Artifact: "
120                         + ctx.getAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME));
121         }
122         return status;
123
124     }
125
126     public QueryStatus logData(SvcLogicContext ctx, String prefix) throws SvcLogicException {
127         String fn = "DBService.saveReferenceData";
128         QueryStatus status = null;
129         if (serviceLogic != null && ctx != null) {
130             String key = "INSERT INTO CONFIG_TRANSACTION_LOG " + " SET request_id = $request-id , "
131                     + " message_type = $log-message-type , " + " message = $log-message ;";
132             status = serviceLogic.save("SQL", false, false, key, null, prefix, ctx);
133             if (status.toString().equals("FAILURE"))
134                 throw new SvcLogicException("Error while loging data");
135
136         }
137         return status;
138     }
139
140     public void processConfigureActionDg(SvcLogicContext context, boolean isUpdate) {
141         String fn = "DBService.processConfigureActionDg";
142         log.info("Update Parameter for SDC Reference " + isUpdate);
143         String key = "";
144         QueryStatus status = null;
145         if (isUpdate)
146             ;
147     }
148
149     public void processSdcReferences(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
150         String fn = "DBService.processSdcReferences";
151         String key = "";
152         QueryStatus status = null;
153
154         if (isUpdate && SdcArtifactHandlerConstants.FILE_CATEGORY.equals(SdcArtifactHandlerConstants.CAPABILITY)) {
155             key = "update " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + "  set ARTIFACT_NAME = $"
156                     + SdcArtifactHandlerConstants.ARTIFACT_NAME + " where VNFC_TYPE = $"
157                     + SdcArtifactHandlerConstants.VNFC_TYPE + " and FILE_CATEGORY = $"
158                     + SdcArtifactHandlerConstants.FILE_CATEGORY + " and ACTION = null";
159         } else if (isUpdate)
160             key = "update " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + "  set ARTIFACT_NAME = $"
161                     + SdcArtifactHandlerConstants.ARTIFACT_NAME + " where VNFC_TYPE = $"
162                     + SdcArtifactHandlerConstants.VNFC_TYPE + " and FILE_CATEGORY = $"
163                     + SdcArtifactHandlerConstants.FILE_CATEGORY + " and ACTION = $"
164                     + SdcArtifactHandlerConstants.ACTION;
165
166         else {
167             if (SdcArtifactHandlerConstants.FILE_CATEGORY.equals(SdcArtifactHandlerConstants.CAPABILITY)) {
168                 key = "insert into " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set VNFC_TYPE = null "
169                         + " , FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY + " , VNF_TYPE = $"
170                         + SdcArtifactHandlerConstants.VNF_TYPE + " , ACTION = null " + " , ARTIFACT_TYPE = null "
171                         + " , ARTIFACT_NAME = $" + SdcArtifactHandlerConstants.ARTIFACT_NAME;
172             } else {
173                 key = "insert into " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set VNFC_TYPE = $"
174                         + SdcArtifactHandlerConstants.VNFC_TYPE + " , FILE_CATEGORY = $"
175                         + SdcArtifactHandlerConstants.FILE_CATEGORY + " , VNF_TYPE = $"
176                         + SdcArtifactHandlerConstants.VNF_TYPE + " , ACTION = $" + SdcArtifactHandlerConstants.ACTION
177                         + " , ARTIFACT_TYPE = $" + SdcArtifactHandlerConstants.ARTIFACT_TYPE + " , ARTIFACT_NAME = $"
178                         + SdcArtifactHandlerConstants.ARTIFACT_NAME;
179             }
180         }
181         if (serviceLogic != null && context != null) {
182             log.info("Insert Key: " + key);
183             status = serviceLogic.save("SQL", false, false, key, null, null, context);
184             if (status.toString().equals("FAILURE"))
185                 throw new SvcLogicException("Error While processing sdc_reference table ");
186         }
187     }
188
189     public boolean isArtifactUpdateRequired(SvcLogicContext context, String db) throws SvcLogicException, SQLException {
190         String fn = "DBService.isArtifactUpdateRequired";
191         log.info("Checking if Update required for this data");
192
193         log.info("db" + db);
194         log.info("ACTION=" + context.getAttribute(SdcArtifactHandlerConstants.ACTION));
195         log.info("VNFC_TYPE=" + context.getAttribute(SdcArtifactHandlerConstants.VNFC_TYPE));
196         log.info("VNFC_INSTANCE=" + context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE));
197         log.info("VM_INSTANCE=" + context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE));
198         log.info("VNF_TYPE=" + context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE));
199         String whereClause = "";
200
201         QueryStatus status = null;
202         whereClause = " where VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE;
203
204         if (db != null) {
205             if (db.equals(SdcArtifactHandlerConstants.DB_SDC_REFERENCE)
206                     && context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY)
207                     .equals(SdcArtifactHandlerConstants.CAPABILITY)
208                     && context.getAttribute(SdcArtifactHandlerConstants.ACTION) == null) {
209                 whereClause = whereClause + " and FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY;
210             }
211
212             else if (db.equals(SdcArtifactHandlerConstants.DB_SDC_REFERENCE)) {
213                 whereClause = whereClause + " and VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE
214                         + " and FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY + " and ACTION = $"
215                         + SdcArtifactHandlerConstants.ACTION;
216             }
217
218             else if (db.equals(SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE)) {
219                 whereClause = " where PROTOCOL = $" + SdcArtifactHandlerConstants.DEVICE_PROTOCOL;
220             } else if (db.equals(SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG)) {
221                 whereClause = whereClause + " and ACTION = $" + SdcArtifactHandlerConstants.ACTION;
222             } else if (db.equals(SdcArtifactHandlerConstants.DB_VNFC_REFERENCE)) {
223                 int vm_instance = -1;
224                 if (context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE) != null)
225                     vm_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE));
226                 int vnfc_instance = -1;
227                 if (context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE) != null)
228                     vnfc_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE));
229                 whereClause = whereClause + " and ACTION = $" + SdcArtifactHandlerConstants.ACTION + " and VNFC_TYPE = $"
230                         + SdcArtifactHandlerConstants.VNFC_TYPE + " and VNFC_INSTANCE = $"
231                         + SdcArtifactHandlerConstants.VNFC_INSTANCE + " and VM_INSTANCE = $"
232                         + SdcArtifactHandlerConstants.VM_INSTANCE;
233
234             }
235         }
236
237         if (serviceLogic != null && context != null) {
238             String key = "select COUNT(*) from " + db + whereClause;
239             log.info("SELECT String : " + key);
240             status = serviceLogic.query("SQL", false, null, key, null, null, context);
241             if (status.toString().equals("FAILURE")) {
242                 throw new SvcLogicException("Error while reading data from " + db);
243             }
244             String count = context.getAttribute("COUNT(*)");
245             log.info("Number of row Returned : " + count + ": " + status + ":");
246             if (count != null && Integer.parseInt(count) > 0) {
247                 context.setAttribute(count, null);
248                 return true;
249             } else
250                 return false;
251         }
252         return false;
253     }
254
255     public void processDeviceInterfaceProtocol(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
256         String fn = "DBService.processDeviceInterfaceProtocol";
257         log.info("Starting DB operation for Device Interface Protocol " + isUpdate);
258         String key = "";
259         QueryStatus status = null;
260         if (isUpdate)
261             key = "update " + SdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL + " set PROTOCOL = $"
262                     + SdcArtifactHandlerConstants.DEVICE_PROTOCOL + " , DG_RPC = 'getDeviceRunningConfig' "
263                     + " , MODULE = 'APPC' " + " where VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE;
264         else
265             key = "insert into " + SdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL + " set  VNF_TYPE = $"
266                     + SdcArtifactHandlerConstants.VNF_TYPE + " , PROTOCOL = $"
267                     + SdcArtifactHandlerConstants.DEVICE_PROTOCOL + " , DG_RPC = 'getDeviceRunningConfig' "
268                     + " , MODULE = 'APPC' ";
269
270         if (serviceLogic != null && context != null) {
271
272             status = serviceLogic.save("SQL", false, false, key, null, null, context);
273             if (status.toString().equals("FAILURE"))
274                 throw new SvcLogicException("Error While processing DEVICE_INTERFACE_PROTOCOL table ");
275         }
276
277     }
278
279     public void processDeviceAuthentication(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
280         String fn = "DBService.processDeviceAuthentication";
281         log.info(fn + "Starting DB operation for Device Authentication " + isUpdate);
282         String key = "";
283         QueryStatus status = null;
284         if (isUpdate)
285             key = "update " + SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION + " set USER_NAME = $"
286                     + SdcArtifactHandlerConstants.USER_NAME + " , PASSWORD = 'dummy' " + " , PORT_NUMBER = $"
287                     + SdcArtifactHandlerConstants.PORT_NUMBER + " where VNF_TYPE = $"
288                     + SdcArtifactHandlerConstants.VNF_TYPE;
289         else
290             key = "insert into " + SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION + " set  VNF_TYPE = $"
291                     + SdcArtifactHandlerConstants.VNF_TYPE + " , USER_NAME = $" + SdcArtifactHandlerConstants.USER_NAME
292                     + " , PASSWORD = 'dummy' " + " , PORT_NUMBER = $" + SdcArtifactHandlerConstants.PORT_NUMBER;
293
294         if (serviceLogic != null && context != null) {
295             status = serviceLogic.save("SQL", false, false, key, null, null, context);
296             if (status.toString().equals("FAILURE"))
297                 throw new SvcLogicException("Error While processing DEVICE_AUTHENTICATION table ");
298         }
299     }
300
301     public void processVnfcReference(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
302         String fn = "DBService.processVnfcReference";
303         log.info(fn + "Starting DB operation for Vnfc Reference " + isUpdate);
304         String key = "";
305         int vm_instance = -1;
306         if (context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE) != null)
307             vm_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE));
308         int vnfc_instance = -1;
309         if (context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE) != null)
310             vnfc_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE));
311         QueryStatus status = null;
312         if (isUpdate)
313             key = "update " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE + " set VM_INSTANCE = " + vm_instance
314                     + " , VNFC_INSTANCE = " + vnfc_instance + " , VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE
315                     + " , VNFC_FUNCTION_CODE = $" + SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE
316                     + " , GROUP_NOTATION_TYPE = $" + SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE
317                     + " , GROUP_NOTATION_VALUE = $" + SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE
318                     + " , IPADDRESS_V4_OAM_VIP = $" + SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP
319                     + " where VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE + " and ACTION = $"
320                     + SdcArtifactHandlerConstants.ACTION + " and VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE
321                     + " and VNFC_INSTANCE = $" + SdcArtifactHandlerConstants.VNFC_INSTANCE + " and VM_INSTANCE = $"
322                     + SdcArtifactHandlerConstants.VM_INSTANCE;
323         else
324             key = "insert into " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE + " set  VNF_TYPE = $"
325                     + SdcArtifactHandlerConstants.VNF_TYPE + " , ACTION = $" + SdcArtifactHandlerConstants.ACTION
326                     + " , VM_INSTANCE = $" + SdcArtifactHandlerConstants.VM_INSTANCE + " , VNFC_INSTANCE = $"
327                     + SdcArtifactHandlerConstants.VNFC_INSTANCE + " , VNFC_TYPE = $"
328                     + SdcArtifactHandlerConstants.VNFC_TYPE + " , VNFC_FUNCTION_CODE = $"
329                     + SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE + " , GROUP_NOTATION_TYPE = $"
330                     + SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE + " , IPADDRESS_V4_OAM_VIP = $"
331                     + SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP + " , GROUP_NOTATION_VALUE = $"
332                     + SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE;
333
334         if (serviceLogic != null && context != null) {
335             status = serviceLogic.save("SQL", false, false, key, null, null, context);
336             if (status.toString().equals("FAILURE"))
337                 throw new SvcLogicException("Error While processing VNFC_REFERENCE table ");
338         }
339     }
340
341     public void processDownloadDgReference(SvcLogicContext context, boolean isUpdate)
342             throws SvcLogicException, SQLException {
343         String fn = "DBService.processDownloadDgReference";
344         log.info(fn + "Starting DB operation for Download DG Reference " + isUpdate);
345         String key = "";
346         QueryStatus status = null;
347
348         if (isUpdate)
349             key = "update " + SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE + " set DOWNLOAD_CONFIG_DG = $"
350                     + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " where PROTOCOL = $"
351                     + SdcArtifactHandlerConstants.DEVICE_PROTOCOL;
352         else
353             key = "insert into " + SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE + " set DOWNLOAD_CONFIG_DG = $"
354                     + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " , PROTOCOL = $"
355                     + SdcArtifactHandlerConstants.DEVICE_PROTOCOL;
356
357         if (serviceLogic != null && context != null)
358             status = serviceLogic.save("SQL", false, false, key, null, null, context);
359         if ((status == null) || status.toString().equals("FAILURE"))
360             throw new SvcLogicException("Error While processing DOWNLOAD_DG_REFERENCE table ");
361     }
362
363     public void processConfigActionDg(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
364         String fn = "DBService.processConfigActionDg";
365         log.info(fn + "Starting DB operation for Config DG Action " + isUpdate);
366         String key = "";
367         QueryStatus status = null;
368
369         if (context.getAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE) != null
370                 && context.getAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE).length() > 0) {
371             if (isUpdate)
372                 key = "update " + SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG + " set DOWNLOAD_CONFIG_DG = $"
373                         + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " where ACTION = $"
374                         + SdcArtifactHandlerConstants.ACTION + " and VNF_TYPE = $"
375                         + SdcArtifactHandlerConstants.VNF_TYPE;
376             else
377                 key = "insert into " + SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG + " set DOWNLOAD_CONFIG_DG = $"
378                         + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " , ACTION = $"
379                         + SdcArtifactHandlerConstants.ACTION + " , VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE;
380
381             if (serviceLogic != null && context != null)
382                 status = serviceLogic.save("SQL", false, false, key, null, null, context);
383             if ((status == null) || status.toString().equals("FAILURE"))
384                 throw new SvcLogicException("Error While processing Configure DG Action table ");
385         } else
386             log.info("No Update required for Config DG Action");
387
388     }
389
390     public String getModelDataInformationbyArtifactName(String artifact_name) throws SvcLogicException {
391         String fn = "DBService.getVnfData";
392         String key = "";
393         SvcLogicContext con = new SvcLogicContext();
394         HashMap<String, String> modelData = new HashMap<String, String>();
395         QueryStatus status = null;
396         key = "select VNF_TYPE, VNFC_TYPE, ACTION, FILE_CATEGORY, ARTIFACT_TYPE from ASDC_REFERENCE where  ARTIFACT_NAME = "
397                 + artifact_name;
398
399         if (serviceLogic != null && con != null) {
400             log.info(fn + "select Key: " + key);
401             status = serviceLogic.query("SQL", false, null, key, null, null, con);
402             if (status.toString().equals("FAILURE"))
403                 throw new SvcLogicException("Error While processing is ArtifactUpdateRequiredforPD table ");
404
405         }
406
407         log.info(fn + "Vnf_received :" + con.getAttribute("VNF_TYPE"));
408
409         return con.getAttribute("VNF_TYPE");
410
411     }
412
413     public void updateYangContents(SvcLogicContext context, String artifactId, String yangContents)
414             throws SvcLogicException {
415         String fn = "DBService.updateYangContents";
416         log.info(fn + "Starting DB operation for  updateYangContents");
417         String key = "";
418         QueryStatus status = null;
419
420         key = "update ASDC_ARTIFACTS " + " set ARTIFACT_CONTENT = '" + yangContents + "'"
421                 + " where ASDC_ARTIFACTS_ID = " + artifactId;
422
423         if (serviceLogic != null && context != null)
424             status = serviceLogic.save("SQL", false, false, key, null, null, context);
425         if ((status == null) || status.toString().equals("FAILURE"))
426             throw new SvcLogicException("Error While processing Configure DG Action table ");
427
428     }
429
430
431     public void insertProtocolReference(SvcLogicContext context, String vnfType, String protocol, String action,
432             String action_level, String template) throws SvcLogicException {
433         String fn = "DBService.insertProtocolReference";
434         log.info(fn + "Starting DB operation for  insertProtocolReference");
435         String key = "";
436         QueryStatus status = null;
437
438         key = "insert into PROTOCOL_REFERENCE (ACTION, VNF_TYPE, PROTOCOL, UPDATED_DATE, TEMPLATE, ACTION_LEVEL)"
439                 + " values  (" + "'" + action + "', '" + vnfType + "', '" + protocol + "', now(),'" + template + "', '"
440                 + action_level + "')";
441
442         if (serviceLogic != null && context != null)
443             status = serviceLogic.save("SQL", false, false, key, null, null, context);
444         if ((status == null) || status.toString().equals("FAILURE"))
445             throw new SvcLogicException("Error While processing insertProtocolReference ");
446         
447     }
448     
449     public boolean isProtocolReferenceUpdateRequired(SvcLogicContext context, String vnfType, String protocol,
450              String action, String action_level, String template) throws SvcLogicException {
451         SvcLogicContext localContext = new SvcLogicContext();
452         String fn = "DBService.isProtocolReferenceUpdateRequired";
453         log.info(fn + "Starting DB operation for  isProtocolReferenceUpdateRequired");
454         String key = "";
455         QueryStatus status = null;
456
457         key = "select COUNT(*) from PROTOCOL_REFERENCE where ACTION='" + action + "' and ACTION_LEVEL='" + action_level
458                 + "' and VNF_TYPE='" + vnfType + "'";
459         status = serviceLogic.query("SQL", false, null, key, null, null, localContext);
460         String countStr = localContext.getAttribute("COUNT(*)");
461         int count = Integer.parseInt(countStr);
462         if (count > 0)
463             return true;
464         else
465             return false;
466     }
467
468     public void updateProtocolReference(SvcLogicContext context, String vnfType, String protocol, String action,
469                 String action_level, String template) throws SvcLogicException {
470
471         String fn = "DBService.isProtocolReferenceUpdateRequired";
472         log.info(fn + "Starting DB operation for  isProtocolReferenceUpdateRequired");
473         String key = "";
474         QueryStatus status = null;
475
476         key = "update PROTOCOL_REFERENCE set UPDATED_DATE=now(), template='" + template + "' where ACTION='" + action
477                 + "' and ACTION_LEVEL='" + action_level + "' and VNF_TYPE='" + vnfType + "'";
478         status = serviceLogic.save("SQL", false, false, key, null, null, context);
479         if (status == QueryStatus.FAILURE) {
480             log.info("updateProtocolReference:: Error updating protocol reference");
481             throw new SvcLogicException("Error - updating PROTOCOL_REFERENCE_TABLE in updateProtocolReference");
482         }
483         return;
484     }
485
486 }