Fixed sonar in SequenceGeneratorDBservices.java
[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  * Modifications Copyright (C) 2018 IBM.
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  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.seqgen.dbservices;
25
26 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
27 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
29 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
31
32 import com.att.eelf.configuration.EELFLogger;
33 import com.att.eelf.configuration.EELFManager;
34
35 public class SequenceGeneratorDBServices {
36
37     private static final EELFLogger log = EELFManager.getInstance().getLogger(SequenceGeneratorDBServices.class);
38     private static SequenceGeneratorDBServices dgGeneralDBService = null;
39     private final SvcLogicResource serviceLogic;
40
41     public SequenceGeneratorDBServices() {
42         serviceLogic = new SqlResource();
43     }
44
45     public static SequenceGeneratorDBServices initialise() {
46         if (dgGeneralDBService == null) {
47             dgGeneralDBService = new SequenceGeneratorDBServices();
48         }
49         return dgGeneralDBService;
50     }
51
52
53
54     public String getOutputPayloadTemplate(SvcLogicContext localContext) throws SvcLogicException {
55         String fn = "DBService.getPayloadOutput";
56         String outputPayloadTemplate = "null";
57         String ASDC_ARTIFACTS = "asdc_artifacts";
58         log.info("Entering getOutputPayloadTemplate()");
59         QueryStatus status = null;
60         if (localContext == null) {
61             return null;
62         }
63         localContext.setAttribute("file_category", "output_payload");
64         String queryString = "select max(internal_version) as maxInternalVersion, artifact_name as artifactName from "
65                 + ASDC_ARTIFACTS + " where artifact_name in (select artifact_name from " + ASDC_ARTIFACTS
66                 + " where file_category = '" + "payload" + "' )";
67
68         log.info(fn + "Query String : " + queryString);
69         status = serviceLogic.query("SQL", false, null, queryString, null, null, localContext);
70
71         if (status == QueryStatus.FAILURE)
72             throw new SvcLogicException("Error - while getting output payload template");
73
74         String queryString1 = "select artifact_content from " + ASDC_ARTIFACTS
75                 + " where artifact_name = $artifactName  and internal_version = $maxInternalVersion ";
76
77         log.debug(fn + "Query String : " + queryString1);
78         status = serviceLogic.query("SQL", false, null, queryString1, null, null, localContext);
79         if (status == QueryStatus.FAILURE)
80             throw new SvcLogicException("Error - while getting output payload template");
81         log.debug("Template for the payload data:" + localContext.getAttribute("artifact-content"));
82
83         if(localContext != null ){
84             outputPayloadTemplate = localContext.getAttribute("artifact-content");
85
86         }
87         return outputPayloadTemplate;
88     }
89 }