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