2 * ============LICENSE_START=======================================================
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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
20 * ============LICENSE_END=========================================================
23 package org.onap.appc.flow.controller.node;
25 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_PARAM_RESPONSE_PREFIX;
26 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_PARAM_ERROR_MESSAGE;
27 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_PARAM_STATUS;
28 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_STATUS_FAILURE;
29 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_STATUS_SUCCESS;
31 import com.att.eelf.configuration.EELFLogger;
32 import com.att.eelf.configuration.EELFManager;
33 import com.fasterxml.jackson.core.type.TypeReference;
34 import com.fasterxml.jackson.databind.JsonNode;
35 import com.fasterxml.jackson.databind.ObjectMapper;
36 import java.io.IOException;
38 import java.util.Map.Entry;
39 import org.apache.commons.lang3.StringUtils;
40 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
41 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
42 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
44 public class JsonParsingNode implements SvcLogicJavaPlugin {
46 private static final EELFLogger log = EELFManager.getInstance().getLogger(JsonParsingNode.class);
48 public void parse(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
49 String fn = "RestServiceNode.sendRequest";
50 log.info("Received processParamKeys call with params : " + inParams);
51 String responsePrefix = inParams.get(INPUT_PARAM_RESPONSE_PREFIX);
52 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
54 String json = inParams.get("data");
55 log.info("Received response from Interface " + json);
56 JsonNode node = JsonValidator.validate(json);
59 Map<String, String> map = convertToMap(node);
60 for (Entry<String, String> entry : map.entrySet()) {
61 ctx.setAttribute(responsePrefix + entry.getKey(), entry.getValue());
64 ctx.setAttribute(responsePrefix + OUTPUT_PARAM_STATUS, OUTPUT_STATUS_SUCCESS);
66 } catch (Exception e) {
67 ctx.setAttribute(responsePrefix + OUTPUT_PARAM_STATUS, OUTPUT_STATUS_FAILURE);
68 ctx.setAttribute(responsePrefix + OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
69 log.error(fn + " Error Message : " + e.getMessage(), e);
70 throw new SvcLogicException(e.getMessage());
74 private Map<String, String> convertToMap(JsonNode node) throws IOException {
75 return new ObjectMapper().readValue(node.toString(), new TypeReference<Map<String, String>>() {