Changed to unmaintained
[appc.git] / appc-config / appc-data-services / provider / src / main / java / org / onap / appc / data / services / db / GeneralDataService.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
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 package org.onap.appc.data.services.db;
24
25 import java.util.Map;
26
27 import org.apache.commons.lang3.StringUtils;
28
29 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
32
33 import org.onap.appc.data.services.AppcDataServiceConstant;
34 import org.onap.appc.data.services.utils.EscapeUtils;
35
36 import com.att.eelf.configuration.EELFLogger;
37 import com.att.eelf.configuration.EELFManager;
38
39 public class GeneralDataService {
40
41     private static final EELFLogger log = EELFManager.getInstance().getLogger(GeneralDataService.class);
42     
43     public void saveTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException 
44     {
45         SvcLogicContext logger = new SvcLogicContext();
46         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
47         String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
48         String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);
49         try 
50         {
51             
52             String escapedMessage = EscapeUtils.escapeSql(message);
53             logger.setAttribute("request-id", ctx.getAttribute("request-id"));
54             logger.setAttribute("log-message-type", messageType);
55             logger.setAttribute("log-message", escapedMessage);
56
57             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
58             DGGeneralDBService db = DGGeneralDBService.initialise();
59             QueryStatus status = db.saveConfigTransactionLog( logger, responsePrefix);
60
61             logger.setAttribute("log-message", null);
62             logger.setAttribute("log-message-type", null);
63             logger.setAttribute("request-id", null);
64
65             if (status == QueryStatus.FAILURE)
66                 throw new Exception("Unable to insert into config_transaction_log");
67
68
69         } 
70         catch (Exception e) 
71         {
72             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
73             AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
74             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
75             throw new SvcLogicException(e.getMessage());
76         }
77     }
78     
79 }