f389ff8d938d1973b51970dfa9021462c91ce52c
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property.  All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.appc.data.services.node;
22
23 import java.util.Map;
24
25 import org.apache.commons.lang3.StringUtils;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import com.fasterxml.jackson.databind.JsonNode;
29 import com.fasterxml.jackson.databind.ObjectMapper;
30
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.SvcLogicJavaPlugin;
34
35 import org.openecomp.appc.data.services.AppcDataServiceConstant;
36 import org.openecomp.appc.data.services.db.DGGeneralDBService;
37 import org.openecomp.appc.data.services.utils.EscapeUtils;
38
39 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
40
41 public class ConfigResourceNode implements SvcLogicJavaPlugin {
42
43     private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
44
45     public void getConfigFileReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
46
47         log.info("Received getConfigFiles call with params : " + inParams);
48
49         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
50
51         try {
52
53             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
54             DGGeneralDBService db = DGGeneralDBService.initialise();
55             QueryStatus status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-deviceconfig",
56                     "device_configuration");
57
58             if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
59                 throw new Exception("Unable to Read ConfigFileReference:device-configuration");
60
61             status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-success",
62                     "configuration_success");
63
64             if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
65                 throw new Exception("Unable to Read ConfigFileReference:configuration_success");
66
67             status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-failure",
68                     "configuration_error");
69
70             if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
71                 throw new Exception("Unable to Read ConfigFileReference:configuration_error");
72
73             status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-log", "log");
74
75             if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
76                 throw new Exception("Unable to Read ConfigFileReference:configuration_log");
77
78
79             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
80                     AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
81             log.info("GetConfigFileReference Successful ");
82         } catch (Exception e) {
83             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
84                     AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
85             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
86             log.error("Failed in GetConfigFileReference " + e.getMessage());
87
88             throw new SvcLogicException(e.getMessage());
89         }
90     }
91
92     public void getCommonConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
93
94         log.info("Received getDeviceInfo call with params : " + inParams);
95
96         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
97
98         try {
99
100             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
101             DGGeneralDBService db = DGGeneralDBService.initialise();
102             QueryStatus status = db.getDeviceAuthenticationByVnfType(ctx, "device-authentication");
103
104             if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
105                 throw new Exception("Unable to Read device_authentication");
106
107             status = db.getDeviceProtocolByVnfType(ctx, "tmp.deviceinterfaceprotocol");
108
109             if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
110                 throw new Exception("Unable to Read device_interface_protocol");
111
112             status = db.getConfigureActionDGByVnfTypeNAction(ctx, "tmp.configureactiondg");
113             if (status == QueryStatus.FAILURE)
114                 throw new Exception("Unable to Read configure_action_dg");
115
116             if (status == QueryStatus.NOT_FOUND) {
117                 status = db.getConfigureActionDGByVnfType(ctx, "tmp.configureactiondg");
118
119                 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
120                     throw new Exception("Unable to Read configure_action_dg");
121             }
122
123
124
125
126
127             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
128                     AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
129             log.info("getCommonConfigInfo Successful ");
130         } catch (Exception e) {
131             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
132                     AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
133             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
134             log.error("Failed in getCommonConfigInfo " + e.getMessage());
135
136             throw new SvcLogicException(e.getMessage());
137         }
138     }
139
140
141     // fileCategory Can be  config_template, parameter_definitions, parameter_yang
142     public void getTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
143
144         log.info("Received getTemplate call with params : " + inParams);
145
146
147         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
148         String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
149         String templateName = ctx.getAttribute("template-name");
150         QueryStatus status = null;
151         String responsePrefix1 = "";
152
153         try {
154
155             responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
156             log.info("RESPONSEPREFIX : " + responsePrefix);
157             log.info("RESPONSEPREFIX1 : " + responsePrefix1);
158
159             DGGeneralDBService db = DGGeneralDBService.initialise();
160
161             if (StringUtils.isBlank(templateName)) {
162
163                 //if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
164
165
166                 status = db.getTemplate(ctx, responsePrefix, fileCategory);
167                 if (status == QueryStatus.FAILURE)
168                     throw new Exception("Unable to Read " + fileCategory );
169                 //}
170
171                 if (status == QueryStatus.NOT_FOUND) {
172
173
174                     status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory);
175
176                     if (status == QueryStatus.FAILURE)
177                         throw new Exception("Unable to Read " + fileCategory );
178
179                     if (status == QueryStatus.NOT_FOUND) {
180
181                         //status = db.getTemplateByVnfType(ctx, responsePrefix, fileCategory);
182
183                         //if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
184                             throw new Exception("Unable to Read " + fileCategory );
185                     }
186                 }
187             } else {
188
189                 status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName);
190
191                 if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
192                     throw new Exception("Unable to Read " + fileCategory + " template");
193             }
194
195
196             ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
197                     AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
198             log.info("GetTemplate Successful ");
199         } catch (Exception e) {
200             ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
201                     AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
202             ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
203             log.error("Failed in getTemplate " + e.getMessage());
204
205             throw new SvcLogicException(e.getMessage());
206         }
207     }
208
209     public void saveConfigFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
210
211         log.info("Received saveConfigFiles call with params : " + inParams);
212
213         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
214
215         try {
216
217             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
218             DGGeneralDBService db = DGGeneralDBService.initialise();
219             QueryStatus status = db.saveConfigFiles(ctx, "tmp.configFiles");
220
221             if (status == QueryStatus.FAILURE)
222                 throw new Exception("Unable to Save " + ctx.getAttribute("file-category") + " in configfiles");
223
224             status = db.getMaxConfigFileId(ctx, "tmp.configfilesmax", ctx.getAttribute("file-category"));
225
226             if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
227                 throw new Exception("Unable to get " + ctx.getAttribute("file-category") + " from configfiles");
228
229             status = db.savePrepareRelationship(ctx, "tmp.preparerel",
230                     ctx.getAttribute("tmp.configfilesmax.configfileid"), "N");
231             if (status == QueryStatus.FAILURE)
232                 throw new Exception("Unable to save prepare_relationship");
233
234             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
235                     AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
236             log.info("saveConfigFiles Successful ");
237         } catch (Exception e) {
238             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
239                     AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
240             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
241             log.error("Failed in saveConfigFiles " + e.getMessage());
242
243             throw new SvcLogicException(e.getMessage());
244         }
245     }
246
247     public void updateUploadConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
248
249         log.info("Received updateUploadConfig call with params : " + inParams);
250
251         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
252
253         try {
254
255             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
256             DGGeneralDBService db = DGGeneralDBService.initialise();
257
258             ctx.setAttribute("tmp.escaped.devicerunningconfig",
259                     EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
260
261             QueryStatus status = db.saveUploadConfig(ctx, "tmp.uploadConfig");
262
263             if (status == QueryStatus.FAILURE)
264                 throw new Exception("Unable to Save configuration in upload_config");
265
266             /*status = db.getMaxUploadConfigFileId(ctx, "tmp.uploadconfigmax");
267
268             if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
269                 throw new Exception("Unable to get record from upload_config");
270
271             status = db.updateUploadConfig(ctx, "tmp.uploadConfig",
272                     Integer.parseInt(ctx.getAttribute("tmp.uploadconfigmax.uploadconfigid")));
273             if (status == QueryStatus.FAILURE)
274                 throw new Exception("Unable to upload upload_config");*/
275
276             status = db.getUploadConfigInfo(ctx, "tmp.uploadConfigInfo");
277
278             if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
279                 throw new Exception("Unable to get record from upload_config");
280
281             status = db.updateUploadConfig(ctx, "tmp.uploadConfig",
282                     Integer.parseInt(ctx.getAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID")));
283             if (status == QueryStatus.FAILURE)
284                 throw new Exception("Unable to upload upload_config");
285
286             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
287                     AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
288             log.info("updateUploadConfig Successful ");
289         } catch (Exception e) {
290             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
291                     AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
292             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
293             log.error("Failed in updateUploadConfig  " + e.getMessage());
294
295             throw new SvcLogicException(e.getMessage());
296         }
297     }
298
299     public void savePrepareRelationship(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
300
301         log.info("Received savePrepareRelationship call with params : " + inParams);
302
303         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
304         String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND);
305         String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID);
306         try {
307
308             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
309             DGGeneralDBService db = DGGeneralDBService.initialise();
310
311             QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel", fileId, sdcArtifactInd);
312             if (status == QueryStatus.FAILURE)
313                 throw new Exception("Unable to save prepare_relationship");
314
315             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
316                     AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
317             log.info("savePrepareRelationship Successful ");
318         } catch (Exception e) {
319             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
320                     AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
321             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
322             log.error("Failed in saveConfigFiles " + e.getMessage());
323
324             throw new SvcLogicException(e.getMessage());
325         }
326     }
327
328     public void saveConfigBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
329
330         log.info("Received saveConfigBlock call with params : " + inParams);
331
332         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
333
334         try {
335
336             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
337             ctx.setAttribute("tmp.convertconfig.escapeData",
338                     EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
339             DGGeneralDBService db = DGGeneralDBService.initialise();
340
341             if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
342                 saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute("tmp.convertconfig.escapeData"),
343                         ctx.getAttribute("configuration"));
344             } else {
345
346                 saveConfigurationBlock(inParams, ctx);
347
348                 ctx.setAttribute("tmp.convertconfig.escapeData",
349                         EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
350                 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
351                         ctx.getAttribute("tmp.merge.mergedData"));
352
353                 saveConfigurationData(inParams, ctx);
354             }
355
356             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
357                     AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
358             log.info("saveConfigBlock Successful ");
359         } catch (Exception e) {
360             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
361                     AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
362             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
363             log.error("Failed in saveConfigBlock " + e.getMessage());
364
365             throw new SvcLogicException(e.getMessage());
366         }
367     }
368
369     public void saveTemplateConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
370
371         log.info("Received saveTemplateConfig call with params : " + inParams);
372
373         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
374
375         try {
376
377             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
378             DGGeneralDBService db = DGGeneralDBService.initialise();
379
380             if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
381
382                 ctx.setAttribute("tmp.convertconfig.escapeData",
383                         EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content")));
384                 saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute("tmp.convertconfig.escapeData"),
385                         ctx.getAttribute("config-template.file-content"));
386
387             } else {
388                 saveConfigurationData(inParams, ctx);
389
390                 ctx.setAttribute("tmp.convertconfig.escapeData",
391                         EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
392                 saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
393                         ctx.getAttribute("tmp.merge.mergedData"));
394
395             }
396
397             QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel",
398                     ctx.getAttribute("config-template.config-file-id"), "Y");
399             if (status == QueryStatus.FAILURE)
400                 throw new Exception("Unable to save prepare_relationship");
401
402             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
403                     AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
404             log.info("saveTemplateConfig Successful ");
405         } catch (Exception e) {
406             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
407                     AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
408             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
409             log.error("Failed in saveTemplateConfig " + e.getMessage());
410
411             throw new SvcLogicException(e.getMessage());
412         }
413     }
414
415
416
417
418     public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
419
420
421         log.info("Received saveStyleSheet call with params : " + inParams);
422
423         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
424
425         try {
426
427             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
428             ctx.setAttribute("tmp.convertconfig.escapeData",
429                     EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
430             saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute("tmp.convertconfig.escapeData"),
431                     ctx.getAttribute("tmp.merge.mergedData"));
432
433
434             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
435             log.info("saveStyleSheet Successful ");
436         } catch (Exception e) {
437             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
438             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE,e.getMessage());
439             log.error("Failed in saveStyleSheet " + e.getMessage());
440
441             throw new SvcLogicException(e.getMessage());
442         }
443     }
444
445
446     public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
447
448
449         log.info("Received saveStyleSheet call with params : " + inParams);
450
451         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
452         String siteLocation = ctx.getAttribute("site-location");
453
454         QueryStatus status = null;
455
456         try{
457
458
459             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
460             DGGeneralDBService db = DGGeneralDBService.initialise();
461
462
463
464             status = db.getTemplateByArtifactType(ctx,  "smm", "smm", siteLocation);
465
466             if ( status == QueryStatus.FAILURE )
467                 throw new Exception("Unable to Read smm file");
468
469
470             status = db.getTemplateByArtifactType(ctx,  "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);
471
472             if ( status == QueryStatus.FAILURE )
473                 throw new Exception("Unable to Read intermediate_ca_chain file");
474
475
476
477
478             status = db.getTemplateByArtifactType(ctx,  "server-certificate-and-key", "server_certificate_and_key", siteLocation);
479
480             if ( status == QueryStatus.FAILURE )
481                 throw new Exception("Unable to Read server_certificate_and_key file");
482
483
484             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
485             log.info("saveStyleSheet Successful ");
486         } catch (Exception e) {
487             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
488             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE,e.getMessage());
489             log.error("Failed in saveStyleSheet " + e.getMessage());
490
491             throw new SvcLogicException(e.getMessage());
492         }
493     }
494
495
496     public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
497             String fileContent, String deviceConfig) throws SvcLogicException {
498         ctx.setAttribute("data-source", dataSource);
499         ctx.setAttribute("file-content", fileContent);
500         ctx.setAttribute("file-category", "device_configuration");
501         ctx.setAttribute("deviceconfig-file-content", deviceConfig);
502
503         saveConfigFiles(inParams, ctx);
504     }
505
506     public void saveConfigurationBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
507         ctx.setAttribute("data-source", "Request");
508         ctx.setAttribute("file-content", ctx.getAttribute("tmp.convertconfig.escapeData"));
509         ctx.setAttribute("file-category", "configuration_block");
510         saveConfigFiles(inParams, ctx);
511     }
512
513     public void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
514         ctx.setAttribute("data-source", ctx.getAttribute("originator-id"));
515         ctx.setAttribute("file-content", ctx.getAttribute("configuration-params"));
516         ctx.setAttribute("file-category", "config_data");
517         saveConfigFiles(inParams, ctx);
518     }
519
520
521     public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
522
523         log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams);
524
525         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
526         String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
527         String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
528         String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
529         try {
530
531
532             DGGeneralDBService db = DGGeneralDBService.initialise();
533
534             QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);
535
536             if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
537                 throw new Exception("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");
538
539
540             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
541             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
542                     AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
543             log.info("getConfigFilesByVnfVmNCategory Successful " + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
544         } catch (Exception e) {
545             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
546                     AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
547             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
548             log.error("Failed in getConfigFilesByVnfVmNCategory " + e.getMessage());
549
550             throw new SvcLogicException(e.getMessage());
551         }
552     }
553
554
555     public void getDownloadConfigTemplateByVnf(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
556
557         log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams);
558
559         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
560         try {
561             DGGeneralDBService db = DGGeneralDBService.initialise();
562
563             QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix);
564
565             if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
566                 throw new Exception("Unable to get download config template.");
567
568
569             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
570             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,    AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
571             log.info("getDownloadConfigTemplateByVnf Successful " + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
572         } catch (Exception e) {
573             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
574                     AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
575             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
576             log.error("Failed in getDownloadConfigTemplateByVnf " + e.getMessage());
577
578             throw new SvcLogicException(e.getMessage());
579         }
580     }
581
582
583     public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
584
585
586
587         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
588
589         String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
590         String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);
591
592         try {
593
594             SvcLogicContext logctx = new SvcLogicContext();
595
596             String escapedMessage = EscapeUtils.escapeSql(message);
597
598
599             logctx.setAttribute("request-id", ctx.getAttribute("request-id"));
600             logctx.setAttribute("log-message-type", messageType);
601             logctx.setAttribute("log-message", escapedMessage);
602
603
604             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
605             DGGeneralDBService db = DGGeneralDBService.initialise();
606             QueryStatus status = db.saveConfigTransactionLog( logctx, responsePrefix);
607
608             logctx.setAttribute("log-message", null);
609
610             if (status == QueryStatus.FAILURE)
611                 throw new Exception("Unable to insert into config_transaction_log");
612
613
614         } catch (Exception e) {
615             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
616                     AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
617             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
618
619
620             throw new SvcLogicException(e.getMessage());
621         }
622     }
623
624
625
626     public void getVnfcReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
627
628         log.info("Received getVnfcReference call with params : " + inParams);
629
630         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
631
632
633         QueryStatus status = null;
634
635         try {
636
637
638             DGGeneralDBService db = DGGeneralDBService.initialise();
639
640             if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
641                 status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
642
643                 if ( status == QueryStatus.FAILURE)
644                     throw new Exception("Unable to Read vnfc-reference");
645             }
646             //else if (status == QueryStatus.NOT_FOUND ) {
647             status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix);
648
649             if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
650                 throw new Exception("Unable to Read vnfc reference");
651
652             //}
653
654             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
655             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
656                     AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
657             log.info("getVnfcReference Successful ");
658         } catch (Exception e) {
659             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
660                     AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
661             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
662             log.error("Failed in getVnfcReference " + e.getMessage());
663
664             throw new SvcLogicException(e.getMessage());
665         }
666     }
667
668     public void getCapability(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
669         log.info("Received getCapability call with params : " + inParams);
670         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
671         responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
672         String caplevel = inParams.get("caplevel");
673         String findCapability = inParams.get("checkCapability");
674
675         try {            
676             DGGeneralDBService db = DGGeneralDBService.initialise();            
677             String cap = db.getCapability(ctx, inParams.get("vnf-type"));
678             log.info("getCapability::returned from DB::+cap");
679             if (StringUtils.isBlank(cap)) {
680                 ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
681                 AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
682                 log.info("getCapability Successful - No capability blocks found");
683                 return;
684             }
685
686             ObjectMapper mapper = new ObjectMapper();
687             JsonNode caps = mapper.readTree(cap);
688             log.info("From DB =   " + caps);
689             JsonNode capabilities = caps.get("capabilities");
690             log.info("capabilities =   " + capabilities);
691             if(caplevel !=null && !caplevel.isEmpty()){
692                 JsonNode subCapabilities = capabilities.get(caplevel);
693                 log.info("subCapabilities =  " +  caplevel + " : " + subCapabilities);
694                 if(findCapability !=null && !findCapability.isEmpty()){
695                     if(subCapabilities != null && subCapabilities.toString().contains(findCapability))
696                         ctx.setAttribute(responsePrefix + "capabilities." + caplevel + "." +  findCapability,
697                                 "Supported");
698                     else
699                         ctx.setAttribute(responsePrefix + "capabilities." + caplevel + "." +  findCapability,
700                                 "Not-Supported");
701                 }
702                 else
703                 {
704                     ctx.setAttribute(responsePrefix + "capabilities." + caplevel,
705                             subCapabilities.toString());
706                 }
707             
708             }
709             else
710                 ctx.setAttribute(responsePrefix + "capabilities",
711                         capabilities.toString());
712             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
713                     AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
714             log.info("getCapability Successful ");
715         } catch (Exception e) {
716             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
717                     AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
718             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
719             log.error("Failed in getCapability " + e.getMessage());
720
721             throw new SvcLogicException(e.getMessage());
722         }
723     }
724
725
726 }