4529d701ab6c582ffa34edce649dcff15d998971
[aai/gizmo.git] / src / main / java / org / onap / crud / service / VertexPayload.java
1 /**
2  * ============LICENSE_START=======================================================
3  * Gizmo
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *    http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  *
22  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23  */
24 package org.onap.crud.service;
25
26 import com.google.gson.Gson;
27 import com.google.gson.GsonBuilder;
28 import com.google.gson.JsonElement;
29
30 import org.onap.crud.exception.CrudException;
31
32 import java.util.ArrayList;
33 import java.util.List;
34 import javax.ws.rs.core.Response.Status;
35
36 public class VertexPayload {
37
38   private String id;
39   private String type;
40   private String url;
41   private JsonElement properties;
42   private List<EdgePayload> in = new ArrayList<EdgePayload>();
43   private List<EdgePayload> out = new ArrayList<EdgePayload>();
44
45   private static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
46
47   public String toJson() {
48     return gson.toJson(this);
49   }
50
51   public static VertexPayload fromJson(String payload) throws CrudException {
52     try {
53       if (payload == null || payload.isEmpty()) {
54         throw new CrudException("Invalid Json Payload", Status.BAD_REQUEST);
55       }
56       return gson.fromJson(payload, VertexPayload.class);
57     } catch (Exception ex) {
58       throw new CrudException("Invalid Json Payload", Status.BAD_REQUEST);
59     }
60   }
61
62   public String getId() {
63     return id;
64   }
65
66   public void setId(String id) {
67     this.id = id;
68   }
69
70   public String getType() {
71     return type;
72   }
73
74   public void setType(String type) {
75     this.type = type;
76   }
77
78   public String getUrl() {
79     return url;
80   }
81
82   public void setUrl(String url) {
83     this.url = url;
84   }
85
86   public JsonElement getProperties() {
87     return properties;
88   }
89
90   public void setProperties(JsonElement properties) {
91     this.properties = properties;
92   }
93
94   public List<EdgePayload> getIn() {
95     return in;
96   }
97
98   public void setIn(List<EdgePayload> in) {
99     this.in = in;
100   }
101
102   public List<EdgePayload> getOut() {
103     return out;
104   }
105
106   public void setOut(List<EdgePayload> out) {
107     this.out = out;
108   }
109
110
111   @Override
112   public String toString() {
113     return "VertexPayload [id=" + id + ", type=" + type + ", url=" + url + ", properties="
114         + properties + ", in=" + in + ", out=" + out + "]";
115   }
116
117 }