2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.datarouter.query;
23 import java.util.ArrayList;
24 import java.util.List;
27 import org.apache.camel.Exchange;
29 import com.google.gson.JsonElement;
30 import com.google.gson.JsonObject;
31 import com.google.gson.JsonParser;
33 public class ChameleonResponseBuiler {
35 public static void buildEntity(Exchange exchange, String ID){
36 String response = exchange.getIn().getBody().toString();
37 JsonParser parser = new JsonParser();
38 JsonObject root = parser.parse(response).getAsJsonObject();
39 JsonObject champResponse = new JsonObject();
40 if (!root.has("type")) {
41 exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, 400);
44 champResponse.addProperty("key", ID);
45 champResponse.addProperty("type", root.get("type").getAsString());
46 if (root.has("source")) {
47 champResponse.add("source", root.get("source"));
49 if (root.has("target")) {
50 champResponse.add("target", root.get("target"));
53 JsonObject props = new JsonObject();
54 List<Map.Entry<String, JsonElement>> entries = new ArrayList<Map.Entry<String, JsonElement>>(
55 root.getAsJsonObject().entrySet());
56 for (Map.Entry<String, JsonElement> e : entries) {
57 if (!e.getKey().equals("type") && !e.getKey().equals("source") && !e.getKey().equals("target")) {
58 if (e.getKey().equals("source")) {
61 props.addProperty(e.getKey(), e.getValue().getAsString());
66 champResponse.add("properties", props);
68 exchange.getIn().setBody(champResponse.toString());
73 public static void buildObjectRelationship(Exchange exchange, String ID){
74 //TODO: implement when chameleon supports this query
76 public static void buildCollection(Exchange exchange){
77 //TODO: implement when chameleon supports this query