Skip to content

Commit 2a7ad46

Browse files
authored
Merge pull request devicehive#394 from devicehive/DEV-223-networkId-notifications
DEV-233 - Add networkId to websocket notification message
2 parents 70913bd + 9e7cb58 commit 2a7ad46

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

devicehive-common/src/main/java/com/devicehive/model/DeviceCommand.java

+18
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public class DeviceCommand implements HiveEntity, HazelcastEntity, Portable {
7474
POST_COMMAND_TO_DEVICE, COMMAND_LISTED})
7575
private String deviceId;
7676

77+
@SerializedName("networkId")
78+
@JsonPolicyDef({COMMAND_FROM_CLIENT, COMMAND_TO_DEVICE, COMMAND_UPDATE_TO_CLIENT, COMMAND_UPDATE_FROM_DEVICE,
79+
POST_COMMAND_TO_DEVICE, COMMAND_LISTED})
80+
private Long networkId;
81+
7782
@SerializedName("parameters")
7883
@JsonPolicyDef({COMMAND_FROM_CLIENT, COMMAND_TO_DEVICE, COMMAND_UPDATE_TO_CLIENT, COMMAND_UPDATE_FROM_DEVICE,
7984
POST_COMMAND_TO_DEVICE, COMMAND_LISTED})
@@ -150,6 +155,14 @@ public void setDeviceId(String deviceId) {
150155
this.deviceId = deviceId;
151156
}
152157

158+
public Long getNetworkId() {
159+
return networkId;
160+
}
161+
162+
public void setNetworkId(Long networkId) {
163+
this.networkId = networkId;
164+
}
165+
153166
public JsonStringWrapper getParameters() {
154167
return parameters;
155168
}
@@ -199,6 +212,7 @@ public boolean equals(Object o) {
199212

200213
if (command != null ? !command.equals(message.command) : message.command != null) return false;
201214
if (deviceId != null ? !deviceId.equals(message.deviceId) : message.deviceId != null) return false;
215+
if (networkId != null ? !networkId.equals(message.networkId) : message.networkId != null) return false;
202216
if (id != null ? !id.equals(message.id) : message.id != null) return false;
203217
if (isUpdated != null ? !isUpdated.equals(message.isUpdated) : message.isUpdated != null) return false;
204218
if (lifetime != null ? !lifetime.equals(message.lifetime) : message.lifetime != null) return false;
@@ -218,6 +232,7 @@ public int hashCode() {
218232
result1 = 31 * result1 + (timestamp != null ? timestamp.hashCode() : 0);
219233
result1 = 31 * result1 + (userId != null ? userId.hashCode() : 0);
220234
result1 = 31 * result1 + (deviceId != null ? deviceId.hashCode() : 0);
235+
result1 = 31 * result1 + (networkId != null ? networkId.hashCode() : 0);
221236
result1 = 31 * result1 + (parameters != null ? parameters.hashCode() : 0);
222237
result1 = 31 * result1 + (lifetime != null ? lifetime.hashCode() : 0);
223238
result1 = 31 * result1 + (status != null ? status.hashCode() : 0);
@@ -235,6 +250,7 @@ public String toString() {
235250
", lastUpdated=" + lastUpdated +
236251
", userId=" + userId +
237252
", deviceId='" + deviceId + '\'' +
253+
", networkId='" + networkId + '\'' +
238254
", parameters=" + parameters +
239255
", lifetime=" + lifetime +
240256
", status='" + status + '\'' +
@@ -269,6 +285,7 @@ public void writePortable(PortableWriter portableWriter) throws IOException {
269285
portableWriter.writeLong("lastUpdated", Objects.nonNull(lastUpdated) ? lastUpdated.getTime() :0);
270286
portableWriter.writeLong("userId", Objects.nonNull(userId) ? userId : 0);
271287
portableWriter.writeUTF("deviceId", deviceId);
288+
portableWriter.writeLong("networkId", Objects.nonNull(networkId) ? networkId : 0);
272289
boolean parametersIsNotNull = Objects.nonNull(parameters) && Objects.nonNull(parameters.getJsonString());
273290
portableWriter.writeUTF("parameters", parametersIsNotNull ? parameters.getJsonString() : null);
274291
portableWriter.writeInt("lifetime", Objects.nonNull(lifetime) ? lifetime : 0);
@@ -286,6 +303,7 @@ public void readPortable(PortableReader portableReader) throws IOException {
286303
lastUpdated = new Date(portableReader.readLong("lastUpdated"));
287304
userId = portableReader.readLong("userId");
288305
deviceId = portableReader.readUTF("deviceId");
306+
networkId = portableReader.readLong("networkId");
289307
String parametersString = portableReader.readUTF("parameters");
290308
if (Objects.nonNull(parametersString)) {
291309
parameters = new JsonStringWrapper(parametersString);

devicehive-common/src/main/java/com/devicehive/model/DeviceNotification.java

+17
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public class DeviceNotification implements HiveEntity, HazelcastEntity, Portable
5555
@JsonPolicyDef({NOTIFICATION_TO_CLIENT, NOTIFICATION_TO_DEVICE})
5656
private String deviceId;
5757

58+
@SerializedName("networkId")
59+
@JsonPolicyDef({NOTIFICATION_TO_CLIENT, NOTIFICATION_TO_DEVICE})
60+
private Long networkId;
61+
5862
@SerializedName("timestamp")
5963
@JsonPolicyDef({NOTIFICATION_TO_CLIENT, NOTIFICATION_TO_DEVICE})
6064
@Temporal(TemporalType.TIMESTAMP)
@@ -104,6 +108,14 @@ public void setDeviceId(String deviceId) {
104108
this.deviceId = deviceId;
105109
}
106110

111+
public Long getNetworkId() {
112+
return networkId;
113+
}
114+
115+
public void setNetworkId(Long networkId) {
116+
this.networkId = networkId;
117+
}
118+
107119
@Override
108120
public boolean equals(Object o) {
109121
if (this == o) return true;
@@ -112,6 +124,7 @@ public boolean equals(Object o) {
112124
DeviceNotification message = (DeviceNotification) o;
113125

114126
if (deviceId != null ? !deviceId.equals(message.deviceId) : message.deviceId != null) return false;
127+
if (networkId != null ? !networkId.equals(message.networkId) : message.networkId != null) return false;
115128
if (id != null ? !id.equals(message.id) : message.id != null) return false;
116129
if (notification != null ? !notification.equals(message.notification) : message.notification != null)
117130
return false;
@@ -126,6 +139,7 @@ public int hashCode() {
126139
int result = id != null ? id.hashCode() : 0;
127140
result = 31 * result + (notification != null ? notification.hashCode() : 0);
128141
result = 31 * result + (deviceId != null ? deviceId.hashCode() : 0);
142+
result = 31 * result + (networkId != null ? networkId.hashCode() : 0);
129143
result = 31 * result + (timestamp != null ? timestamp.hashCode() : 0);
130144
result = 31 * result + (parameters != null ? parameters.hashCode() : 0);
131145
return result;
@@ -137,6 +151,7 @@ public String toString() {
137151
"id=" + id +
138152
", notification='" + notification + '\'' +
139153
", deviceId='" + deviceId + '\'' +
154+
", networkId='" + networkId + '\'' +
140155
", timestamp=" + timestamp +
141156
", parameters='" + parameters + '\'' +
142157
'}';
@@ -165,6 +180,7 @@ public void writePortable(PortableWriter portableWriter) throws IOException {
165180
portableWriter.writeLong("id", Objects.nonNull(id) ? id : 0);
166181
portableWriter.writeUTF("notification", notification);
167182
portableWriter.writeUTF("deviceId", deviceId);
183+
portableWriter.writeLong("networkId", Objects.nonNull(networkId) ? networkId : 0);
168184
portableWriter.writeLong("timestamp", Objects.nonNull(timestamp) ? timestamp.getTime() :0);
169185
boolean parametersIsNotNull = Objects.nonNull(parameters) && Objects.nonNull(parameters.getJsonString());
170186
portableWriter.writeUTF("parameters", parametersIsNotNull ? parameters.getJsonString() : null);
@@ -175,6 +191,7 @@ public void readPortable(PortableReader portableReader) throws IOException {
175191
id = portableReader.readLong("id");
176192
notification = portableReader.readUTF("notification");
177193
deviceId = portableReader.readUTF("deviceId");
194+
networkId = portableReader.readLong("networkId");
178195
timestamp = new Date(portableReader.readLong("timestamp"));
179196
String parametersString = portableReader.readUTF("parameters");
180197
if (Objects.nonNull(parametersString)) {

devicehive-frontend/src/main/java/com/devicehive/service/DeviceCommandService.java

+1
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ private DeviceCommand convertWrapperToCommand(DeviceCommandWrapper commandWrappe
265265
DeviceCommand command = new DeviceCommand();
266266
command.setId(Math.abs(new Random().nextInt()));
267267
command.setDeviceId(device.getDeviceId());
268+
command.setNetworkId(device.getNetworkId());
268269
command.setIsUpdated(false);
269270

270271
if (commandWrapper.getTimestamp().isPresent()) {

devicehive-frontend/src/main/java/com/devicehive/service/DeviceNotificationService.java

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ public DeviceNotification convertWrapperToNotification(DeviceNotificationWrapper
214214
DeviceNotification notification = new DeviceNotification();
215215
notification.setId(Math.abs(new Random().nextInt()));
216216
notification.setDeviceId(device.getDeviceId());
217+
notification.setNetworkId(device.getNetworkId());
217218
if (notificationSubmit.getTimestamp() == null) {
218219
notification.setTimestamp(timestampService.getDate());
219220
} else {

0 commit comments

Comments
 (0)