summaryrefslogtreecommitdiffstats
path: root/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/node/ConfigResourceNode.java
blob: f389ff8d938d1973b51970dfa9021462c91ce52c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
/*-
 * ============LICENSE_START=======================================================
 * ONAP : APP-C
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property.  All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.appc.data.services.node;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;

import org.openecomp.appc.data.services.AppcDataServiceConstant;
import org.openecomp.appc.data.services.db.DGGeneralDBService;
import org.openecomp.appc.data.services.utils.EscapeUtils;

import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;

public class ConfigResourceNode implements SvcLogicJavaPlugin {

    private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);

    public void getConfigFileReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {

        log.info("Received getConfigFiles call with params : " + inParams);

        String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);

        try {

            responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
            DGGeneralDBService db = DGGeneralDBService.initialise();
            QueryStatus status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-deviceconfig",
                    "device_configuration");

            if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                throw new Exception("Unable to Read ConfigFileReference:device-configuration");

            status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-success",
                    "configuration_success");

            if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                throw new Exception("Unable to Read ConfigFileReference:configuration_success");

            status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-failure",
                    "configuration_error");

            if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                throw new Exception("Unable to Read ConfigFileReference:configuration_error");

            status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-log", "log");

            if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                throw new Exception("Unable to Read ConfigFileReference:configuration_log");


            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
            log.info("GetConfigFileReference Successful ");
        } catch (Exception e) {
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
            log.error("Failed in GetConfigFileReference " + e.getMessage());

            throw new SvcLogicException(e.getMessage());
        }
    }

    public void getCommonConfigInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {

        log.info("Received getDeviceInfo call with params : " + inParams);

        String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);

        try {

            responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
            DGGeneralDBService db = DGGeneralDBService.initialise();
            QueryStatus status = db.getDeviceAuthenticationByVnfType(ctx, "device-authentication");

            if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                throw new Exception("Unable to Read device_authentication");

            status = db.getDeviceProtocolByVnfType(ctx, "tmp.deviceinterfaceprotocol");

            if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                throw new Exception("Unable to Read device_interface_protocol");

            status = db.getConfigureActionDGByVnfTypeNAction(ctx, "tmp.configureactiondg");
            if (status == QueryStatus.FAILURE)
                throw new Exception("Unable to Read configure_action_dg");

            if (status == QueryStatus.NOT_FOUND) {
                status = db.getConfigureActionDGByVnfType(ctx, "tmp.configureactiondg");

                if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                    throw new Exception("Unable to Read configure_action_dg");
            }





            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
            log.info("getCommonConfigInfo Successful ");
        } catch (Exception e) {
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
            log.error("Failed in getCommonConfigInfo " + e.getMessage());

            throw new SvcLogicException(e.getMessage());
        }
    }


    // fileCategory Can be  config_template, parameter_definitions, parameter_yang
    public void getTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {

        log.info("Received getTemplate call with params : " + inParams);


        String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
        String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
        String templateName = ctx.getAttribute("template-name");
        QueryStatus status = null;
        String responsePrefix1 = "";

        try {

            responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
            log.info("RESPONSEPREFIX : " + responsePrefix);
            log.info("RESPONSEPREFIX1 : " + responsePrefix1);

            DGGeneralDBService db = DGGeneralDBService.initialise();

            if (StringUtils.isBlank(templateName)) {

                //if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {


                status = db.getTemplate(ctx, responsePrefix, fileCategory);
                if (status == QueryStatus.FAILURE)
                    throw new Exception("Unable to Read " + fileCategory );
                //}

                if (status == QueryStatus.NOT_FOUND) {


                    status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory);

                    if (status == QueryStatus.FAILURE)
                        throw new Exception("Unable to Read " + fileCategory );

                    if (status == QueryStatus.NOT_FOUND) {

                        //status = db.getTemplateByVnfType(ctx, responsePrefix, fileCategory);

                        //if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                            throw new Exception("Unable to Read " + fileCategory );
                    }
                }
            } else {

                status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName);

                if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                    throw new Exception("Unable to Read " + fileCategory + " template");
            }


            ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
            log.info("GetTemplate Successful ");
        } catch (Exception e) {
            ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
            ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
            log.error("Failed in getTemplate " + e.getMessage());

            throw new SvcLogicException(e.getMessage());
        }
    }

    public void saveConfigFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {

        log.info("Received saveConfigFiles call with params : " + inParams);

        String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);

        try {

            responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
            DGGeneralDBService db = DGGeneralDBService.initialise();
            QueryStatus status = db.saveConfigFiles(ctx, "tmp.configFiles");

            if (status == QueryStatus.FAILURE)
                throw new Exception("Unable to Save " + ctx.getAttribute("file-category") + " in configfiles");

            status = db.getMaxConfigFileId(ctx, "tmp.configfilesmax", ctx.getAttribute("file-category"));

            if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                throw new Exception("Unable to get " + ctx.getAttribute("file-category") + " from configfiles");

            status = db.savePrepareRelationship(ctx, "tmp.preparerel",
                    ctx.getAttribute("tmp.configfilesmax.configfileid"), "N");
            if (status == QueryStatus.FAILURE)
                throw new Exception("Unable to save prepare_relationship");

            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
            log.info("saveConfigFiles Successful ");
        } catch (Exception e) {
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
            log.error("Failed in saveConfigFiles " + e.getMessage());

            throw new SvcLogicException(e.getMessage());
        }
    }

    public void updateUploadConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {

        log.info("Received updateUploadConfig call with params : " + inParams);

        String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);

        try {

            responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
            DGGeneralDBService db = DGGeneralDBService.initialise();

            ctx.setAttribute("tmp.escaped.devicerunningconfig",
                    EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));

            QueryStatus status = db.saveUploadConfig(ctx, "tmp.uploadConfig");

            if (status == QueryStatus.FAILURE)
                throw new Exception("Unable to Save configuration in upload_config");

            /*status = db.getMaxUploadConfigFileId(ctx, "tmp.uploadconfigmax");

            if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                throw new Exception("Unable to get record from upload_config");

            status = db.updateUploadConfig(ctx, "tmp.uploadConfig",
                    Integer.parseInt(ctx.getAttribute("tmp.uploadconfigmax.uploadconfigid")));
            if (status == QueryStatus.FAILURE)
                throw new Exception("Unable to upload upload_config");*/

            status = db.getUploadConfigInfo(ctx, "tmp.uploadConfigInfo");

            if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                throw new Exception("Unable to get record from upload_config");

            status = db.updateUploadConfig(ctx, "tmp.uploadConfig",
                    Integer.parseInt(ctx.getAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID")));
            if (status == QueryStatus.FAILURE)
                throw new Exception("Unable to upload upload_config");

            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
            log.info("updateUploadConfig Successful ");
        } catch (Exception e) {
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
            log.error("Failed in updateUploadConfig  " + e.getMessage());

            throw new SvcLogicException(e.getMessage());
        }
    }

    public void savePrepareRelationship(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {

        log.info("Received savePrepareRelationship call with params : " + inParams);

        String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
        String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND);
        String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID);
        try {

            responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
            DGGeneralDBService db = DGGeneralDBService.initialise();

            QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel", fileId, sdcArtifactInd);
            if (status == QueryStatus.FAILURE)
                throw new Exception("Unable to save prepare_relationship");

            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
            log.info("savePrepareRelationship Successful ");
        } catch (Exception e) {
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
            log.error("Failed in saveConfigFiles " + e.getMessage());

            throw new SvcLogicException(e.getMessage());
        }
    }

    public void saveConfigBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {

        log.info("Received saveConfigBlock call with params : " + inParams);

        String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);

        try {

            responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
            ctx.setAttribute("tmp.convertconfig.escapeData",
                    EscapeUtils.escapeSql(ctx.getAttribute("configuration")));
            DGGeneralDBService db = DGGeneralDBService.initialise();

            if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {
                saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute("tmp.convertconfig.escapeData"),
                        ctx.getAttribute("configuration"));
            } else {

                saveConfigurationBlock(inParams, ctx);

                ctx.setAttribute("tmp.convertconfig.escapeData",
                        EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
                saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
                        ctx.getAttribute("tmp.merge.mergedData"));

                saveConfigurationData(inParams, ctx);
            }

            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
            log.info("saveConfigBlock Successful ");
        } catch (Exception e) {
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
            log.error("Failed in saveConfigBlock " + e.getMessage());

            throw new SvcLogicException(e.getMessage());
        }
    }

    public void saveTemplateConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {

        log.info("Received saveTemplateConfig call with params : " + inParams);

        String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);

        try {

            responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
            DGGeneralDBService db = DGGeneralDBService.initialise();

            if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) {

                ctx.setAttribute("tmp.convertconfig.escapeData",
                        EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content")));
                saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute("tmp.convertconfig.escapeData"),
                        ctx.getAttribute("config-template.file-content"));

            } else {
                saveConfigurationData(inParams, ctx);

                ctx.setAttribute("tmp.convertconfig.escapeData",
                        EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
                saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"),
                        ctx.getAttribute("tmp.merge.mergedData"));

            }

            QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel",
                    ctx.getAttribute("config-template.config-file-id"), "Y");
            if (status == QueryStatus.FAILURE)
                throw new Exception("Unable to save prepare_relationship");

            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
            log.info("saveTemplateConfig Successful ");
        } catch (Exception e) {
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
            log.error("Failed in saveTemplateConfig " + e.getMessage());

            throw new SvcLogicException(e.getMessage());
        }
    }




    public void saveStyleSheetConfig(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {


        log.info("Received saveStyleSheet call with params : " + inParams);

        String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);

        try {

            responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
            ctx.setAttribute("tmp.convertconfig.escapeData",
                    EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData")));
            saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute("tmp.convertconfig.escapeData"),
                    ctx.getAttribute("tmp.merge.mergedData"));


            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
            log.info("saveStyleSheet Successful ");
        } catch (Exception e) {
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE,e.getMessage());
            log.error("Failed in saveStyleSheet " + e.getMessage());

            throw new SvcLogicException(e.getMessage());
        }
    }


    public void getSmmChainKeyFiles(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {


        log.info("Received saveStyleSheet call with params : " + inParams);

        String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
        String siteLocation = ctx.getAttribute("site-location");

        QueryStatus status = null;

        try{


            responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
            DGGeneralDBService db = DGGeneralDBService.initialise();



            status = db.getTemplateByArtifactType(ctx,  "smm", "smm", siteLocation);

            if ( status == QueryStatus.FAILURE )
                throw new Exception("Unable to Read smm file");


            status = db.getTemplateByArtifactType(ctx,  "intermediate-ca-chain", "intermediate_ca_chain", siteLocation);

            if ( status == QueryStatus.FAILURE )
                throw new Exception("Unable to Read intermediate_ca_chain file");




            status = db.getTemplateByArtifactType(ctx,  "server-certificate-and-key", "server_certificate_and_key", siteLocation);

            if ( status == QueryStatus.FAILURE )
                throw new Exception("Unable to Read server_certificate_and_key file");


            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
            log.info("saveStyleSheet Successful ");
        } catch (Exception e) {
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE,e.getMessage());
            log.error("Failed in saveStyleSheet " + e.getMessage());

            throw new SvcLogicException(e.getMessage());
        }
    }


    public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
            String fileContent, String deviceConfig) throws SvcLogicException {
        ctx.setAttribute("data-source", dataSource);
        ctx.setAttribute("file-content", fileContent);
        ctx.setAttribute("file-category", "device_configuration");
        ctx.setAttribute("deviceconfig-file-content", deviceConfig);

        saveConfigFiles(inParams, ctx);
    }

    public void saveConfigurationBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
        ctx.setAttribute("data-source", "Request");
        ctx.setAttribute("file-content", ctx.getAttribute("tmp.convertconfig.escapeData"));
        ctx.setAttribute("file-category", "configuration_block");
        saveConfigFiles(inParams, ctx);
    }

    public void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
        ctx.setAttribute("data-source", ctx.getAttribute("originator-id"));
        ctx.setAttribute("file-content", ctx.getAttribute("configuration-params"));
        ctx.setAttribute("file-category", "config_data");
        saveConfigFiles(inParams, ctx);
    }


    public void getConfigFilesByVnfVmNCategory(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {

        log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams);

        String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
        String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
        String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID);
        String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
        try {


            DGGeneralDBService db = DGGeneralDBService.initialise();

            QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);

            if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                throw new Exception("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");


            responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
            log.info("getConfigFilesByVnfVmNCategory Successful " + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
        } catch (Exception e) {
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
            log.error("Failed in getConfigFilesByVnfVmNCategory " + e.getMessage());

            throw new SvcLogicException(e.getMessage());
        }
    }


    public void getDownloadConfigTemplateByVnf(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {

        log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams);

        String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
        try {
            DGGeneralDBService db = DGGeneralDBService.initialise();

            QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix);

            if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                throw new Exception("Unable to get download config template.");


            responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,    AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
            log.info("getDownloadConfigTemplateByVnf Successful " + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
        } catch (Exception e) {
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
            log.error("Failed in getDownloadConfigTemplateByVnf " + e.getMessage());

            throw new SvcLogicException(e.getMessage());
        }
    }


    public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {



        String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);

        String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
        String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);

        try {

            SvcLogicContext logctx = new SvcLogicContext();

            String escapedMessage = EscapeUtils.escapeSql(message);


            logctx.setAttribute("request-id", ctx.getAttribute("request-id"));
            logctx.setAttribute("log-message-type", messageType);
            logctx.setAttribute("log-message", escapedMessage);


            responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
            DGGeneralDBService db = DGGeneralDBService.initialise();
            QueryStatus status = db.saveConfigTransactionLog( logctx, responsePrefix);

            logctx.setAttribute("log-message", null);

            if (status == QueryStatus.FAILURE)
                throw new Exception("Unable to insert into config_transaction_log");


        } catch (Exception e) {
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());


            throw new SvcLogicException(e.getMessage());
        }
    }



    public void getVnfcReference(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {

        log.info("Received getVnfcReference call with params : " + inParams);

        String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);


        QueryStatus status = null;

        try {


            DGGeneralDBService db = DGGeneralDBService.initialise();

            if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
                status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);

                if ( status == QueryStatus.FAILURE)
                    throw new Exception("Unable to Read vnfc-reference");
            }
            //else if (status == QueryStatus.NOT_FOUND ) {
            status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix);

            if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
                throw new Exception("Unable to Read vnfc reference");

            //}

            responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
            log.info("getVnfcReference Successful ");
        } catch (Exception e) {
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
            log.error("Failed in getVnfcReference " + e.getMessage());

            throw new SvcLogicException(e.getMessage());
        }
    }

    public void getCapability(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
        log.info("Received getCapability call with params : " + inParams);
        String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
        responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
        String caplevel = inParams.get("caplevel");
        String findCapability = inParams.get("checkCapability");

        try {            
            DGGeneralDBService db = DGGeneralDBService.initialise();            
            String cap = db.getCapability(ctx, inParams.get("vnf-type"));
            log.info("getCapability::returned from DB::+cap");
            if (StringUtils.isBlank(cap)) {
                ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
                log.info("getCapability Successful - No capability blocks found");
                return;
            }

            ObjectMapper mapper = new ObjectMapper();
            JsonNode caps = mapper.readTree(cap);
            log.info("From DB =   " + caps);
            JsonNode capabilities = caps.get("capabilities");
            log.info("capabilities =   " + capabilities);
            if(caplevel !=null && !caplevel.isEmpty()){
                JsonNode subCapabilities = capabilities.get(caplevel);
                log.info("subCapabilities =  " +  caplevel + " : " + subCapabilities);
                if(findCapability !=null && !findCapability.isEmpty()){
                    if(subCapabilities != null && subCapabilities.toString().contains(findCapability))
                        ctx.setAttribute(responsePrefix + "capabilities." + caplevel + "." +  findCapability,
                                "Supported");
                    else
                        ctx.setAttribute(responsePrefix + "capabilities." + caplevel + "." +  findCapability,
                                "Not-Supported");
                }
                else
                {
                    ctx.setAttribute(responsePrefix + "capabilities." + caplevel,
                            subCapabilities.toString());
                }
            
            }
            else
                ctx.setAttribute(responsePrefix + "capabilities",
                        capabilities.toString());
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS);
            log.info("getCapability Successful ");
        } catch (Exception e) {
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
                    AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
            ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
            log.error("Failed in getCapability " + e.getMessage());

            throw new SvcLogicException(e.getMessage());
        }
    }


}