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