2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.seqgen.dbservices;
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;
32 import com.att.eelf.configuration.EELFLogger;
33 import com.att.eelf.configuration.EELFManager;
35 public class SequenceGeneratorDBServices {
37 private static final EELFLogger log = EELFManager.getInstance().getLogger(SequenceGeneratorDBServices.class);
38 private static SequenceGeneratorDBServices dgGeneralDBService = null;
39 private final SvcLogicResource serviceLogic;
41 public SequenceGeneratorDBServices() {
42 serviceLogic = new SqlResource();
45 public static SequenceGeneratorDBServices initialise() {
46 if (dgGeneralDBService == null) {
47 dgGeneralDBService = new SequenceGeneratorDBServices();
49 return dgGeneralDBService;
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) {
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" + "' )";
68 log.info(fn + "Query String : " + queryString);
69 status = serviceLogic.query("SQL", false, null, queryString, null, null, localContext);
71 if (status == QueryStatus.FAILURE)
72 throw new SvcLogicException("Error - while getting output payload template");
74 String queryString1 = "select artifact_content from " + ASDC_ARTIFACTS
75 + " where artifact_name = $artifactName and internal_version = $maxInternalVersion ";
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"));
83 if(localContext != null ){
84 outputPayloadTemplate = localContext.getAttribute("artifact-content");
87 return outputPayloadTemplate;