2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 European Software Marketing Ltd.
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.modelloader.gizmo;
23 import com.google.gson.JsonElement;
24 import com.google.gson.JsonObject;
25 import com.google.gson.JsonParser;
26 import java.util.ArrayList;
27 import java.util.List;
30 public class GizmoEdgeOperation {
31 private String operation;
32 private String internalId;
33 private GizmoEdge edge;
35 public GizmoEdgeOperation(String op, String id, GizmoEdge edge) {
41 public JsonElement toJsonElement() {
42 JsonObject opObj = new JsonObject();
43 JsonObject edgeObj = JsonParser.parseString(edge.toJson()).getAsJsonObject();
45 opObj.addProperty(GizmoBulkPayload.OP_KEY, operation);
46 opObj.add(internalId, edgeObj);
51 public static GizmoEdgeOperation fromJsonElement(JsonElement element) {
52 List<Map.Entry<String, JsonElement>> entries = new ArrayList<>(element.getAsJsonObject().entrySet());
56 GizmoEdge edge = null;
58 for (Map.Entry<String, JsonElement> entry : entries) {
59 if (entry.getKey().equalsIgnoreCase(GizmoBulkPayload.OP_KEY)) {
60 op = entry.getValue().getAsString();
63 edge = GizmoEdge.fromJson(entry.getValue().getAsJsonObject().toString());
69 op = GizmoBulkPayload.EXISTS_OP;
72 return new GizmoEdgeOperation(op, id, edge);
75 public String getOperation() {
79 public String getInternalId() {
83 public GizmoEdge getEdge() {