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.Gson;
24 import com.google.gson.GsonBuilder;
25 import com.google.gson.JsonElement;
26 import java.util.ArrayList;
27 import java.util.List;
29 public class GizmoBulkPayload {
31 public static final String ADD_OP = "add";
32 public static final String UPDATE_OP = "modify";
33 public static final String DELETE_OP = "delete";
34 public static final String PATCH_OP = "patch";
35 public static final String EXISTS_OP = "exists";
36 public static final String ALL_OPS = "all";
37 public static final String OP_KEY = "operation";
40 private List<JsonElement> objects = new ArrayList<>();
41 private List<JsonElement> relationships = new ArrayList<>();
43 private static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
45 public String toJson() {
46 return gson.toJson(this);
49 public static GizmoBulkPayload fromJson(String payload) {
50 return gson.fromJson(payload, GizmoBulkPayload.class);
53 public List<JsonElement> getObjects() {
57 public void setObjects(List<JsonElement> objects) {
58 this.objects = objects;
61 public List<JsonElement> getRelationships() {
65 public void setRelationships(List<JsonElement> relationships) {
66 this.relationships = relationships;
69 public List<GizmoVertexOperation> getVertexOperations() {
70 return getVertexOperations(ALL_OPS);
73 public List<GizmoVertexOperation> getVertexOperations(String opType) {
74 List<GizmoVertexOperation> ops = new ArrayList<>();
75 for (JsonElement v : getObjects()) {
76 GizmoVertexOperation op = GizmoVertexOperation.fromJsonElement(v);
78 if ((opType.equalsIgnoreCase(ALL_OPS)) || (op.getOperation().equalsIgnoreCase(opType))) {
86 public void addVertexOperation(GizmoVertexOperation newOp) {
87 objects.add(newOp.toJsonElement());
90 public List<GizmoEdgeOperation> getEdgeOperations() {
91 return getEdgeOperations(ALL_OPS);
94 public List<GizmoEdgeOperation> getEdgeOperations(String opType) {
95 List<GizmoEdgeOperation> ops = new ArrayList<>();
97 for (JsonElement v : getRelationships()) {
98 GizmoEdgeOperation op = GizmoEdgeOperation.fromJsonElement(v);
100 if ((opType.equalsIgnoreCase(ALL_OPS)) || (op.getOperation().equalsIgnoreCase(opType))) {
108 public void addEdgeOperation(GizmoEdgeOperation newOp) {
109 relationships.add(newOp.toJsonElement());