Added seq generator changes for vnf level actions
[appc.git] / appc-sequence-generator / appc-sequence-generator-bundle / src / main / java / org / onap / appc / seqgen / dbservices / SequenceGeneratorDBServices.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2018 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  *
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.appc.seqgen.dbservices;
23
24 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
25 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
26 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
27 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
29 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
30
31 import com.att.eelf.configuration.EELFLogger;
32 import com.att.eelf.configuration.EELFManager;
33
34 public class SequenceGeneratorDBServices {
35
36     private static final EELFLogger log = EELFManager.getInstance().getLogger(SequenceGeneratorDBServices.class);
37     private static SequenceGeneratorDBServices dgGeneralDBService = null;
38     private final SvcLogicResource serviceLogic;
39
40     public static SequenceGeneratorDBServices initialise() {
41         if (dgGeneralDBService == null) {
42             dgGeneralDBService = new SequenceGeneratorDBServices();
43         }
44         return dgGeneralDBService;
45     }
46
47     public SequenceGeneratorDBServices() {
48            serviceLogic = new SqlResource();
49     }
50
51     public String getOutputPayloadTemplate(SvcLogicContext localContext) throws SvcLogicException {
52         String fn = "DBService.getPayloadOutput";
53         log.info("Entering getOutputPayloadTemplate()");
54         QueryStatus status = null;
55         if (localContext == null) return null;
56         localContext.setAttribute("file_category", "output_payload");
57         String queryString = "select max(internal_version) as maxInternalVersion, artifact_name as artifactName from "
58                 + "asdc_artifacts" + " where artifact_name in (select artifact_name from " + "asdc_artifacts"
59                 + " where file_category = '" + "payload" + "' )";
60
61         log.info(fn + "Query String : " + queryString);
62         status = serviceLogic.query("SQL", false, null, queryString, null, null, localContext);
63
64         if (status == QueryStatus.FAILURE)
65             throw new SvcLogicException("Error - while getting output payload template");
66
67         String queryString1 = "select artifact_content from " + "asdc_artifacts"
68                 + " where artifact_name = $artifactName  and internal_version = $maxInternalVersion ";
69
70         log.debug(fn + "Query String : " + queryString1);
71         status = serviceLogic.query("SQL", false, null, queryString1, null, null, localContext);
72         if (status == QueryStatus.FAILURE)
73             throw new SvcLogicException("Error - while getting output payload template");
74         log.debug("Template for the payload data:" + localContext.getAttribute("artifact-content"));
75         return localContext != null ? localContext.getAttribute("artifact-content") : null;
76     }
77 }