dc25497f8dbd46c76b48d3719328cc222f24bb7b
[aai/gizmo.git] / src / main / java / org / onap / crud / service / EdgePayload.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 javax.ws.rs.core.Response.Status;
33
34 public class EdgePayload {
35
36   private String id;
37   private String type;
38   private String url;
39   private String source;
40   private String target;
41   private JsonElement properties;
42
43   private static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
44
45
46   @Override
47   public String toString() {
48     return "EdgePayload [id=" + id + ", type=" + type + ", url=" + url + ", source="
49         + source + ", target=" + target + ", properties=" + properties + "]";
50   }
51
52   public String toJson() {
53     return gson.toJson(this);
54   }
55
56   public static EdgePayload fromJson(String payload) throws CrudException {
57     try {
58       if (payload == null || payload.isEmpty()) {
59         throw new CrudException("Invalid Json Payload", Status.BAD_REQUEST);
60       }
61       return gson.fromJson(payload, EdgePayload.class);
62     } catch (Exception ex) {
63       throw new CrudException("Invalid Json Payload", Status.BAD_REQUEST);
64     }
65   }
66
67   public String getId() {
68     return id;
69   }
70
71   public void setId(String id) {
72     this.id = id;
73   }
74
75   public String getType() {
76     return type;
77   }
78
79   public void setType(String type) {
80     this.type = type;
81   }
82
83   public String getUrl() {
84     return url;
85   }
86
87   public void setUrl(String url) {
88     this.url = url;
89   }
90
91   public String getSource() {
92     return source;
93   }
94
95   public void setSource(String source) {
96     this.source = source;
97   }
98
99   public String getTarget() {
100     return target;
101   }
102
103   public void setTarget(String target) {
104     this.target = target;
105   }
106
107   public JsonElement getProperties() {
108     return properties;
109   }
110
111   public void setProperties(JsonElement properties) {
112     this.properties = properties;
113   }
114
115 }