1 |
package org.icesoft.notify.cloud.core; |
2 |
|
3 |
import static org.icesoft.util.ObjectUtilities.isEqual; |
4 |
import static org.icesoft.util.ObjectUtilities.isNotEqual; |
5 |
import static org.icesoft.util.ObjectUtilities.isNotNull; |
6 |
import static org.icesoft.util.StringUtilities.isNotEmpty; |
7 |
|
8 |
import java.io.Serializable; |
9 |
import java.util.logging.Logger; |
10 |
|
11 |
import javax.json.Json; |
12 |
import javax.json.JsonObject; |
13 |
import javax.json.JsonObjectBuilder; |
14 |
|
15 |
import org.bson.Document; |
16 |
|
17 |
public class NotificationProviderBlockingQueueEventData |
18 |
implements Serializable { |
19 |
private static final long serialVersionUID = -2794861123199547303L; |
20 |
|
21 |
private static final Logger LOGGER = Logger.getLogger(NotificationProviderBlockingQueueEventData.class.getName()); |
22 |
|
23 |
private static final class Identifier { |
24 |
private static final class JSON { |
25 |
private static final String MESSAGE = "message"; |
26 |
private static final String NAME = "name"; |
27 |
private static final String STATUS = "status"; |
28 |
} |
29 |
} |
30 |
|
31 |
private String message; |
32 |
private String name; |
33 |
private String status; |
34 |
|
35 |
public NotificationProviderBlockingQueueEventData() { |
36 |
|
37 |
} |
38 |
|
39 |
protected NotificationProviderBlockingQueueEventData(final String message, final String name, final String status) { |
40 |
setMessage(message); |
41 |
setName(name); |
42 |
setStatus(status); |
43 |
} |
44 |
|
45 |
@Override |
46 |
public boolean equals(final Object object) { |
47 |
return |
48 |
object instanceof NotificationProviderBlockingQueueEventData && |
49 |
isEqual(((NotificationProviderBlockingQueueEventData)object).getMessage(), getMessage()) && |
50 |
isEqual(((NotificationProviderBlockingQueueEventData)object).getName(), getName()) && |
51 |
isEqual(((NotificationProviderBlockingQueueEventData)object).getStatus(), getStatus()); |
52 |
} |
53 |
|
54 |
public String getMessage() { |
55 |
return message; |
56 |
} |
57 |
|
58 |
public String getName() { |
59 |
return name; |
60 |
} |
61 |
|
62 |
public String getStatus() { |
63 |
return status; |
64 |
} |
65 |
|
66 |
public boolean hasMessage() { |
67 |
return isNotNull(getMessage()); |
68 |
} |
69 |
|
70 |
public boolean hasName() { |
71 |
return isNotNull(getName()); |
72 |
} |
73 |
|
74 |
public boolean hasStatus() { |
75 |
return isNotNull(getStatus()); |
76 |
} |
77 |
|
78 |
@Override |
79 |
public int hashCode() { |
80 |
int _hashCode; |
81 |
_hashCode = hasMessage() ? getMessage().hashCode() : 0; |
82 |
_hashCode = 31 * _hashCode + (hasName() ? getName().hashCode() : 0); |
83 |
_hashCode = 31 * _hashCode + (hasStatus() ? getStatus().hashCode() : 0); |
84 |
return _hashCode; |
85 |
} |
86 |
|
87 |
public static NotificationProviderBlockingQueueEventData parseBSONDocument(final Document bsonDocument) { |
88 |
if (isNotNull(bsonDocument)) { |
89 |
NotificationProviderBlockingQueueEventData _notificationProviderBlockingQueueEventData = |
90 |
new NotificationProviderBlockingQueueEventData(); |
91 |
parseBSONDocument(_notificationProviderBlockingQueueEventData, bsonDocument); |
92 |
return _notificationProviderBlockingQueueEventData; |
93 |
} else { |
94 |
return null; |
95 |
} |
96 |
} |
97 |
|
98 |
public static NotificationProviderBlockingQueueEventData parseJSONObject(final JsonObject jsonObject) { |
99 |
if (isNotNull(jsonObject)) { |
100 |
NotificationProviderBlockingQueueEventData _notificationProviderBlockingQueueEventData = |
101 |
new NotificationProviderBlockingQueueEventData(); |
102 |
parseJSONObject(_notificationProviderBlockingQueueEventData, jsonObject); |
103 |
return _notificationProviderBlockingQueueEventData; |
104 |
} else { |
105 |
return null; |
106 |
} |
107 |
} |
108 |
|
109 |
public void setMessage(final String message) { |
110 |
if (isNotEqual(getMessage(), message)) { |
111 |
this.message = message; |
112 |
} |
113 |
} |
114 |
|
115 |
public void setName(final String name) { |
116 |
if (isNotEqual(getName(), name)) { |
117 |
this.name = name; |
118 |
} |
119 |
} |
120 |
|
121 |
public void setStatus(final String status) { |
122 |
if (isNotEqual(getStatus(), status)) { |
123 |
this.status = status; |
124 |
} |
125 |
} |
126 |
|
127 |
public Document toBSONDocument() { |
128 |
Document _bsonDocument = new Document(); |
129 |
if (hasMessage() && isNotEmpty(getMessage())) { |
130 |
_bsonDocument.append(Identifier.JSON.MESSAGE, getMessage()); |
131 |
} |
132 |
if (hasName() && isNotEmpty(getName())) { |
133 |
_bsonDocument.append(Identifier.JSON.NAME, getName()); |
134 |
} |
135 |
if (hasStatus() && isNotEmpty(getStatus())) { |
136 |
_bsonDocument.append(Identifier.JSON.STATUS, getStatus()); |
137 |
} |
138 |
return _bsonDocument; |
139 |
} |
140 |
|
141 |
public JsonObject toJSONObject() { |
142 |
return buildJSONObject(Json.createObjectBuilder()).build(); |
143 |
} |
144 |
|
145 |
@Override |
146 |
public String toString() { |
147 |
return "NotificationProviderBlockingQueueEventData[" + classMembersToString() + "]"; |
148 |
} |
149 |
|
150 |
public NotificationProviderBlockingQueueEventData withMessage(final String message) { |
151 |
setMessage(message); |
152 |
return this; |
153 |
} |
154 |
|
155 |
public NotificationProviderBlockingQueueEventData withName(final String name) { |
156 |
setName(name); |
157 |
return this; |
158 |
} |
159 |
|
160 |
public NotificationProviderBlockingQueueEventData withStatus(final String status) { |
161 |
setStatus(status); |
162 |
return this; |
163 |
} |
164 |
|
165 |
protected JsonObjectBuilder buildJSONObject(final JsonObjectBuilder jsonObjectBuilder) { |
166 |
JsonObjectBuilder _jsonObjectBuilder; |
167 |
if (isNotNull(jsonObjectBuilder)) { |
168 |
_jsonObjectBuilder = jsonObjectBuilder; |
169 |
} else { |
170 |
_jsonObjectBuilder = Json.createObjectBuilder(); |
171 |
} |
172 |
if (hasMessage() && isNotEmpty(getMessage())) { |
173 |
_jsonObjectBuilder.add(Identifier.JSON.MESSAGE, getMessage()); |
174 |
} |
175 |
if (hasName() && isNotEmpty(getName())) { |
176 |
_jsonObjectBuilder.add(Identifier.JSON.NAME, getName()); |
177 |
} |
178 |
if (hasStatus() && isNotEmpty(getStatus())) { |
179 |
_jsonObjectBuilder.add(Identifier.JSON.STATUS, getStatus()); |
180 |
} |
181 |
return _jsonObjectBuilder; |
182 |
} |
183 |
|
184 |
protected String classMembersToString() { |
185 |
return |
186 |
"message: '" + getMessage() + "', " + |
187 |
"name: '" + getName() + "', " + |
188 |
"status: '" + getStatus() + "'"; |
189 |
} |
190 |
|
191 |
protected static void parseBSONDocument( |
192 |
final NotificationProviderBlockingQueueEventData notificationProviderBlockingQueueEventData, |
193 |
final Document bsonDocument) { |
194 |
|
195 |
if (isNotNull(notificationProviderBlockingQueueEventData) && isNotNull(bsonDocument)) { |
196 |
if (bsonDocument.containsKey(Identifier.JSON.MESSAGE)) { |
197 |
String _message = bsonDocument.getString(Identifier.JSON.MESSAGE); |
198 |
if (isNotEmpty(_message)) { |
199 |
notificationProviderBlockingQueueEventData.setMessage(_message); |
200 |
} |
201 |
} |
202 |
if (bsonDocument.containsKey(Identifier.JSON.NAME)) { |
203 |
String _name = bsonDocument.getString(Identifier.JSON.NAME); |
204 |
if (isNotEmpty(_name)) { |
205 |
notificationProviderBlockingQueueEventData.setName(_name); |
206 |
} |
207 |
} |
208 |
if (bsonDocument.containsKey(Identifier.JSON.STATUS)) { |
209 |
String _status = bsonDocument.getString(Identifier.JSON.STATUS); |
210 |
if (isNotEmpty(_status)) { |
211 |
notificationProviderBlockingQueueEventData.setStatus(_status); |
212 |
} |
213 |
} |
214 |
} |
215 |
} |
216 |
|
217 |
protected static void parseJSONObject( |
218 |
final NotificationProviderBlockingQueueEventData notificationProviderBlockingQueueEventData, |
219 |
final JsonObject jsonObject) { |
220 |
|
221 |
if (isNotNull(notificationProviderBlockingQueueEventData) && isNotNull(jsonObject)) { |
222 |
if (jsonObject.containsKey(Identifier.JSON.MESSAGE)) { |
223 |
String _message = jsonObject.getJsonString(Identifier.JSON.MESSAGE).getString(); |
224 |
if (isNotEmpty(_message)) { |
225 |
notificationProviderBlockingQueueEventData.setMessage(_message); |
226 |
} |
227 |
} |
228 |
if (jsonObject.containsKey(Identifier.JSON.NAME)) { |
229 |
String _name = jsonObject.getJsonString(Identifier.JSON.NAME).getString(); |
230 |
if (isNotEmpty(_name)) { |
231 |
notificationProviderBlockingQueueEventData.setName(_name); |
232 |
} |
233 |
} |
234 |
if (jsonObject.containsKey(Identifier.JSON.STATUS)) { |
235 |
String _status = jsonObject.getJsonString(Identifier.JSON.STATUS).getString(); |
236 |
if (isNotEmpty(_status)) { |
237 |
notificationProviderBlockingQueueEventData.setStatus(_status); |
238 |
} |
239 |
} |
240 |
} |
241 |
} |
242 |
} |