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;
27 import java.util.ArrayList;
28 import java.util.List;
30 public class GizmoBulkPayload {
32 public static final String ADD_OP = "add";
33 public static final String UPDATE_OP = "modify";
34 public static final String DELETE_OP = "delete";
35 public static final String PATCH_OP = "patch";
36 public static final String EXISTS_OP = "exists";
37 public static final String ALL_OPS = "all";
38 public static final String OP_KEY = "operation";
41 private List<JsonElement> objects = new ArrayList<JsonElement>();
42 private List<JsonElement> relationships = new ArrayList<JsonElement>();
44 private static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
46 public String toJson() {
47 return gson.toJson(this);
50 public static GizmoBulkPayload fromJson(String payload) {
51 return gson.fromJson(payload, GizmoBulkPayload.class);
54 public List<JsonElement> getObjects() {
58 public void setObjects(List<JsonElement> objects) {
59 this.objects = objects;
62 public List<JsonElement> getRelationships() {
66 public void setRelationships(List<JsonElement> relationships) {
67 this.relationships = relationships;
70 public List<GizmoVertexOperation> getVertexOperations() {
71 return getVertexOperations(ALL_OPS);
74 public List<GizmoVertexOperation> getVertexOperations(String opType) {
75 List<GizmoVertexOperation> ops = new ArrayList<GizmoVertexOperation>();
76 for (JsonElement v : getObjects()) {
77 GizmoVertexOperation op = GizmoVertexOperation.fromJsonElement(v);
79 if ( (opType.equalsIgnoreCase(ALL_OPS)) || (op.getOperation().equalsIgnoreCase(opType)) ) {
87 public void addVertexOperation(GizmoVertexOperation newOp) {
88 objects.add(newOp.toJsonElement());
91 public List<GizmoEdgeOperation> getEdgeOperations() {
92 return getEdgeOperations(ALL_OPS);
95 public List<GizmoEdgeOperation> getEdgeOperations(String opType) {
96 List<GizmoEdgeOperation> ops = new ArrayList<GizmoEdgeOperation>();
98 for (JsonElement v : getRelationships()) {
99 GizmoEdgeOperation op = GizmoEdgeOperation.fromJsonElement(v);
101 if ( (opType.equalsIgnoreCase(ALL_OPS)) || (op.getOperation().equalsIgnoreCase(opType)) ) {
109 public void addEdgeOperation(GizmoEdgeOperation newOp) {
110 relationships.add(newOp.toJsonElement());