e8f5817991fc2405daaa8ac90404f13a1cded68c
[ccsdk/features.git] /
1 /*\r
2  * Copyright © 2017-2018 AT&T Intellectual Property.\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
5  * in compliance with the License. You may obtain a copy of the License at\r
6  * \r
7  * http://www.apache.org/licenses/LICENSE-2.0\r
8  * \r
9  * Unless required by applicable law or agreed to in writing, software distributed under the License\r
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
11  * or implied. See the License for the specific language governing permissions and limitations under\r
12  * the License.\r
13  */\r
14 \r
15 package org.onap.ccsdk.config.data.adaptor.service;\r
16 \r
17 import java.util.Map;\r
18 import org.apache.commons.lang3.StringUtils;\r
19 import org.onap.ccsdk.config.data.adaptor.DataAdaptorConstants;\r
20 import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog;\r
21 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
22 import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
23 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;\r
24 \r
25 public class ConfigResourceNode implements SvcLogicJavaPlugin {\r
26     \r
27     private ConfigResourceService configResourceService;\r
28     \r
29     public ConfigResourceNode(ConfigResourceService configResourceService) {\r
30         this.configResourceService = configResourceService;\r
31     }\r
32     \r
33     public void saveConfigTransactionLog(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {\r
34         String responsePrefix = inParams.get(DataAdaptorConstants.INPUT_PARAM_RESPONSE_PRIFIX);\r
35         try {\r
36             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";\r
37             \r
38             String messageType = inParams.get(DataAdaptorConstants.INPUT_PARAM_MESSAGE_TYPE);\r
39             String message = inParams.get(DataAdaptorConstants.INPUT_PARAM_MESSAGE);\r
40             String requestId = ctx.getAttribute("request-id");\r
41             \r
42             TransactionLog transactionLog = new TransactionLog();\r
43             \r
44             transactionLog.setMessage(message);\r
45             transactionLog.setMessageType(messageType);\r
46             transactionLog.setRequestId(requestId);\r
47             \r
48             configResourceService.save(transactionLog);\r
49             \r
50         } catch (Exception e) {\r
51             ctx.setAttribute(responsePrefix + DataAdaptorConstants.OUTPUT_PARAM_STATUS,\r
52                     DataAdaptorConstants.OUTPUT_STATUS_FAILURE);\r
53             ctx.setAttribute(responsePrefix + DataAdaptorConstants.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());\r
54             throw new SvcLogicException("Failed in saveConfigTransactionLog :" + e.getMessage());\r
55         }\r
56     }\r
57     \r
58 }\r