Add/update license text part 3
[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 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24 package org.onap.appc.data.services.db;
25
26 import java.util.Map;
27 import java.util.Set;
28
29 import org.apache.commons.lang3.StringUtils;
30
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
35 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
36
37 import org.onap.appc.data.services.AppcDataServiceConstant;
38 import org.onap.appc.data.services.utils.EscapeUtils;
39
40 import com.att.eelf.configuration.EELFLogger;
41 import com.att.eelf.configuration.EELFManager;
42
43 public class GeneralDataService {
44
45     private static final EELFLogger log = EELFManager.getInstance().getLogger(GeneralDataService.class);
46     
47     public void saveTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException 
48     {
49         SvcLogicContext logger = new SvcLogicContext();
50         String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
51         String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE);
52         String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE);
53         try 
54         {
55             
56             String escapedMessage = EscapeUtils.escapeSql(message);
57             logger.setAttribute("request-id", ctx.getAttribute("request-id"));
58             logger.setAttribute("log-message-type", messageType);
59             logger.setAttribute("log-message", escapedMessage);
60
61             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
62             DGGeneralDBService db = DGGeneralDBService.initialise();
63             QueryStatus status = db.saveConfigTransactionLog( logger, responsePrefix);
64
65             logger.setAttribute("log-message", null);
66             logger.setAttribute("log-message-type", null);
67             logger.setAttribute("request-id", null);
68
69             if (status == QueryStatus.FAILURE)
70                 throw new Exception("Unable to insert into config_transaction_log");
71
72
73         } 
74         catch (Exception e) 
75         {
76             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS,
77             AppcDataServiceConstant.OUTPUT_STATUS_FAILURE);
78             ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
79             throw new SvcLogicException(e.getMessage());
80         }
81     }
82     
83 }