2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * ============LICENSE_END=========================================================
22 package org.onap.appc.seqgen.dbservices;
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;
31 import com.att.eelf.configuration.EELFLogger;
32 import com.att.eelf.configuration.EELFManager;
34 public class SequenceGeneratorDBServices {
36 private static final EELFLogger log = EELFManager.getInstance().getLogger(SequenceGeneratorDBServices.class);
37 private static SequenceGeneratorDBServices dgGeneralDBService = null;
38 private final SvcLogicResource serviceLogic;
40 public static SequenceGeneratorDBServices initialise() {
41 if (dgGeneralDBService == null) {
42 dgGeneralDBService = new SequenceGeneratorDBServices();
44 return dgGeneralDBService;
47 public SequenceGeneratorDBServices() {
48 serviceLogic = new SqlResource();
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" + "' )";
61 log.info(fn + "Query String : " + queryString);
62 status = serviceLogic.query("SQL", false, null, queryString, null, null, localContext);
64 if (status == QueryStatus.FAILURE)
65 throw new SvcLogicException("Error - while getting output payload template");
67 String queryString1 = "select artifact_content from " + "asdc_artifacts"
68 + " where artifact_name = $artifactName and internal_version = $maxInternalVersion ";
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;