Commit a5d75e380068b8562c1a43d0c66385f40ad10d55

Authored by Volodymyr Babak
1 parent 4b9642fc

Removed CREDENTIALS type. Use action instead

@@ -35,6 +35,7 @@ import org.springframework.web.bind.annotation.RestController; @@ -35,6 +35,7 @@ import org.springframework.web.bind.annotation.RestController;
35 import org.thingsboard.rule.engine.api.MailService; 35 import org.thingsboard.rule.engine.api.MailService;
36 import org.thingsboard.server.common.data.User; 36 import org.thingsboard.server.common.data.User;
37 import org.thingsboard.server.common.data.audit.ActionType; 37 import org.thingsboard.server.common.data.audit.ActionType;
  38 +import org.thingsboard.server.common.data.edge.EdgeEventType;
38 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; 39 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
39 import org.thingsboard.server.common.data.exception.ThingsboardException; 40 import org.thingsboard.server.common.data.exception.ThingsboardException;
40 import org.thingsboard.server.common.data.id.TenantId; 41 import org.thingsboard.server.common.data.id.TenantId;
@@ -124,6 +125,9 @@ public class AuthController extends BaseController { @@ -124,6 +125,9 @@ public class AuthController extends BaseController {
124 } 125 }
125 userCredentials.setPassword(passwordEncoder.encode(newPassword)); 126 userCredentials.setPassword(passwordEncoder.encode(newPassword));
126 userService.replaceUserCredentials(securityUser.getTenantId(), userCredentials); 127 userService.replaceUserCredentials(securityUser.getTenantId(), userCredentials);
  128 +
  129 + sendNotificationMsgToEdgeService(getTenantId(), null, userCredentials.getUserId(), EdgeEventType.USER, ActionType.CREDENTIALS_UPDATED);
  130 +
127 } catch (Exception e) { 131 } catch (Exception e) {
128 throw handleException(e); 132 throw handleException(e);
129 } 133 }
@@ -35,17 +35,14 @@ import org.thingsboard.rule.engine.api.MailService; @@ -35,17 +35,14 @@ import org.thingsboard.rule.engine.api.MailService;
35 import org.thingsboard.server.common.data.EntityType; 35 import org.thingsboard.server.common.data.EntityType;
36 import org.thingsboard.server.common.data.User; 36 import org.thingsboard.server.common.data.User;
37 import org.thingsboard.server.common.data.audit.ActionType; 37 import org.thingsboard.server.common.data.audit.ActionType;
38 -import org.thingsboard.server.common.data.edge.Edge; 38 +import org.thingsboard.server.common.data.edge.EdgeEventType;
39 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; 39 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
40 import org.thingsboard.server.common.data.exception.ThingsboardException; 40 import org.thingsboard.server.common.data.exception.ThingsboardException;
41 import org.thingsboard.server.common.data.id.CustomerId; 41 import org.thingsboard.server.common.data.id.CustomerId;
42 -import org.thingsboard.server.common.data.id.EdgeId;  
43 import org.thingsboard.server.common.data.id.TenantId; 42 import org.thingsboard.server.common.data.id.TenantId;
44 import org.thingsboard.server.common.data.id.UserId; 43 import org.thingsboard.server.common.data.id.UserId;
45 import org.thingsboard.server.common.data.page.TextPageData; 44 import org.thingsboard.server.common.data.page.TextPageData;
46 import org.thingsboard.server.common.data.page.TextPageLink; 45 import org.thingsboard.server.common.data.page.TextPageLink;
47 -import org.thingsboard.server.common.data.page.TimePageData;  
48 -import org.thingsboard.server.common.data.page.TimePageLink;  
49 import org.thingsboard.server.common.data.security.Authority; 46 import org.thingsboard.server.common.data.security.Authority;
50 import org.thingsboard.server.common.data.security.UserCredentials; 47 import org.thingsboard.server.common.data.security.UserCredentials;
51 import org.thingsboard.server.queue.util.TbCoreComponent; 48 import org.thingsboard.server.queue.util.TbCoreComponent;
@@ -60,8 +57,6 @@ import org.thingsboard.server.utils.MiscUtils; @@ -60,8 +57,6 @@ import org.thingsboard.server.utils.MiscUtils;
60 57
61 import javax.servlet.http.HttpServletRequest; 58 import javax.servlet.http.HttpServletRequest;
62 59
63 -import static org.thingsboard.server.controller.EdgeController.EDGE_ID;  
64 -  
65 @RestController 60 @RestController
66 @TbCoreComponent 61 @TbCoreComponent
67 @RequestMapping("/api") 62 @RequestMapping("/api")
@@ -167,6 +162,8 @@ public class UserController extends BaseController { @@ -167,6 +162,8 @@ public class UserController extends BaseController {
167 savedUser.getCustomerId(), 162 savedUser.getCustomerId(),
168 user.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); 163 user.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
169 164
  165 + sendNotificationMsgToEdgeService(getTenantId(), null, user.getId(), EdgeEventType.USER, user.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
  166 +
170 return savedUser; 167 return savedUser;
171 } catch (Exception e) { 168 } catch (Exception e) {
172 169
@@ -242,6 +239,8 @@ public class UserController extends BaseController { @@ -242,6 +239,8 @@ public class UserController extends BaseController {
242 user.getCustomerId(), 239 user.getCustomerId(),
243 ActionType.DELETED, null, strUserId); 240 ActionType.DELETED, null, strUserId);
244 241
  242 + sendNotificationMsgToEdgeService(getTenantId(), null, user.getId(), EdgeEventType.USER, ActionType.DELETED);
  243 +
245 } catch (Exception e) { 244 } catch (Exception e) {
246 logEntityAction(emptyId(EntityType.USER), 245 logEntityAction(emptyId(EntityType.USER),
247 null, 246 null,
@@ -174,6 +174,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -174,6 +174,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
174 // TODO: voba - ADDED is not required for CE version ? 174 // TODO: voba - ADDED is not required for CE version ?
175 // case ADDED: 175 // case ADDED:
176 case UPDATED: 176 case UPDATED:
  177 + case CREDENTIALS_UPDATED:
177 ListenableFuture<List<EdgeId>> edgeIdsFuture = findRelatedEdgeIdsByEntityId(tenantId, entityId); 178 ListenableFuture<List<EdgeId>> edgeIdsFuture = findRelatedEdgeIdsByEntityId(tenantId, entityId);
178 Futures.transform(edgeIdsFuture, edgeIds -> { 179 Futures.transform(edgeIdsFuture, edgeIds -> {
179 if (edgeIds != null && !edgeIds.isEmpty()) { 180 if (edgeIds != null && !edgeIds.isEmpty()) {
@@ -28,9 +28,7 @@ import com.google.gson.JsonObject; @@ -28,9 +28,7 @@ import com.google.gson.JsonObject;
28 import io.grpc.stub.StreamObserver; 28 import io.grpc.stub.StreamObserver;
29 import lombok.Data; 29 import lombok.Data;
30 import lombok.extern.slf4j.Slf4j; 30 import lombok.extern.slf4j.Slf4j;
31 -import org.apache.commons.lang3.RandomStringUtils;  
32 import org.checkerframework.checker.nullness.qual.Nullable; 31 import org.checkerframework.checker.nullness.qual.Nullable;
33 -import org.springframework.util.StringUtils;  
34 import org.thingsboard.server.common.data.Dashboard; 32 import org.thingsboard.server.common.data.Dashboard;
35 import org.thingsboard.server.common.data.DataConstants; 33 import org.thingsboard.server.common.data.DataConstants;
36 import org.thingsboard.server.common.data.Device; 34 import org.thingsboard.server.common.data.Device;
@@ -195,11 +193,23 @@ public final class EdgeGrpcSession implements Closeable { @@ -195,11 +193,23 @@ public final class EdgeGrpcSession implements Closeable {
195 for (EdgeEvent edgeEvent : pageData.getData()) { 193 for (EdgeEvent edgeEvent : pageData.getData()) {
196 log.trace("[{}] Processing edge event [{}]", this.sessionId, edgeEvent); 194 log.trace("[{}] Processing edge event [{}]", this.sessionId, edgeEvent);
197 try { 195 try {
198 - UpdateMsgType msgType = getResponseMsgType(ActionType.valueOf(edgeEvent.getEdgeEventAction()));  
199 - if (msgType == null) {  
200 - processTelemetryMessage(edgeEvent);  
201 - } else {  
202 - processEntityCRUDMessage(edgeEvent, msgType); 196 + ActionType edgeEventAction = ActionType.valueOf(edgeEvent.getEdgeEventAction());
  197 + switch (edgeEventAction) {
  198 + case UPDATED:
  199 + case ADDED:
  200 + case ASSIGNED_TO_EDGE:
  201 + case DELETED:
  202 + case UNASSIGNED_FROM_EDGE:
  203 + case ALARM_ACK:
  204 + case ALARM_CLEAR:
  205 + case CREDENTIALS_UPDATED:
  206 + processEntityMessage(edgeEvent, edgeEventAction);
  207 + break;
  208 + case ATTRIBUTES_UPDATED:
  209 + case ATTRIBUTES_DELETED:
  210 + case TIMESERIES_UPDATED:
  211 + processTelemetryMessage(edgeEvent);
  212 + break;
203 } 213 }
204 } catch (Exception e) { 214 } catch (Exception e) {
205 log.error("Exception during processing records from queue", e); 215 log.error("Exception during processing records from queue", e);
@@ -278,217 +288,212 @@ public final class EdgeGrpcSession implements Closeable { @@ -278,217 +288,212 @@ public final class EdgeGrpcSession implements Closeable {
278 } 288 }
279 } 289 }
280 290
281 - private void processEntityCRUDMessage(EdgeEvent edgeEvent, UpdateMsgType msgType) {  
282 - log.trace("Executing processEntityCRUDMessage, edgeEvent [{}], msgType [{}]", edgeEvent, msgType); 291 + private void processEntityMessage(EdgeEvent edgeEvent, ActionType edgeEventAction) {
  292 + UpdateMsgType msgType = getResponseMsgType(ActionType.valueOf(edgeEvent.getEdgeEventAction()));
  293 + log.trace("Executing processEntityCRUDMessage, edgeEvent [{}], edgeEventAction [{}], msgType [{}]", edgeEvent, edgeEventAction, msgType);
283 switch (edgeEvent.getEdgeEventType()) { 294 switch (edgeEvent.getEdgeEventType()) {
284 case EDGE: 295 case EDGE:
285 // TODO: voba - add edge update logic 296 // TODO: voba - add edge update logic
286 break; 297 break;
287 case DEVICE: 298 case DEVICE:
288 - processDeviceCRUD(edgeEvent, msgType);  
289 - break;  
290 - case DEVICE_CREDENTIALS:  
291 - processDeviceCredentialsCRUD(edgeEvent, msgType); 299 + processDevice(edgeEvent, msgType, edgeEventAction);
292 break; 300 break;
293 case ASSET: 301 case ASSET:
294 - processAssetCRUD(edgeEvent, msgType); 302 + processAsset(edgeEvent, msgType, edgeEventAction);
295 break; 303 break;
296 case ENTITY_VIEW: 304 case ENTITY_VIEW:
297 - processEntityViewCRUD(edgeEvent, msgType); 305 + processEntityView(edgeEvent, msgType, edgeEventAction);
298 break; 306 break;
299 case DASHBOARD: 307 case DASHBOARD:
300 - processDashboardCRUD(edgeEvent, msgType); 308 + processDashboard(edgeEvent, msgType, edgeEventAction);
301 break; 309 break;
302 case RULE_CHAIN: 310 case RULE_CHAIN:
303 - processRuleChainCRUD(edgeEvent, msgType); 311 + processRuleChain(edgeEvent, msgType, edgeEventAction);
304 break; 312 break;
305 case RULE_CHAIN_METADATA: 313 case RULE_CHAIN_METADATA:
306 - processRuleChainMetadataCRUD(edgeEvent, msgType); 314 + processRuleChainMetadata(edgeEvent, msgType);
307 break; 315 break;
308 case ALARM: 316 case ALARM:
309 - processAlarmCRUD(edgeEvent, msgType); 317 + processAlarm(edgeEvent, msgType);
310 break; 318 break;
311 case USER: 319 case USER:
312 - processUserCRUD(edgeEvent, msgType);  
313 - break;  
314 - case USER_CREDENTIALS:  
315 - processUserCredentialsCRUD(edgeEvent, msgType); 320 + processUser(edgeEvent, msgType, edgeEventAction);
316 break; 321 break;
317 case RELATION: 322 case RELATION:
318 - processRelationCRUD(edgeEvent, msgType); 323 + processRelation(edgeEvent, msgType);
319 break; 324 break;
320 } 325 }
321 } 326 }
322 327
323 - private void processDeviceCRUD(EdgeEvent edgeEvent, UpdateMsgType msgType) { 328 + private void processDevice(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType edgeActionType) {
324 DeviceId deviceId = new DeviceId(edgeEvent.getEntityId()); 329 DeviceId deviceId = new DeviceId(edgeEvent.getEntityId());
325 - switch (msgType) {  
326 - case ENTITY_CREATED_RPC_MESSAGE:  
327 - case ENTITY_UPDATED_RPC_MESSAGE:  
328 - case DEVICE_CONFLICT_RPC_MESSAGE: 330 + EntityUpdateMsg entityUpdateMsg = null;
  331 + switch (edgeActionType) {
  332 + case ADDED:
  333 + case UPDATED:
  334 + case ASSIGNED_TO_EDGE:
329 Device device = ctx.getDeviceService().findDeviceById(edgeEvent.getTenantId(), deviceId); 335 Device device = ctx.getDeviceService().findDeviceById(edgeEvent.getTenantId(), deviceId);
330 if (device != null) { 336 if (device != null) {
331 DeviceUpdateMsg deviceUpdateMsg = 337 DeviceUpdateMsg deviceUpdateMsg =
332 ctx.getDeviceUpdateMsgConstructor().constructDeviceUpdatedMsg(msgType, device); 338 ctx.getDeviceUpdateMsgConstructor().constructDeviceUpdatedMsg(msgType, device);
333 - EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder() 339 + entityUpdateMsg = EntityUpdateMsg.newBuilder()
334 .setDeviceUpdateMsg(deviceUpdateMsg) 340 .setDeviceUpdateMsg(deviceUpdateMsg)
335 .build(); 341 .build();
336 - outputStream.onNext(ResponseMsg.newBuilder()  
337 - .setEntityUpdateMsg(entityUpdateMsg)  
338 - .build());  
339 } 342 }
340 break; 343 break;
341 - case ENTITY_DELETED_RPC_MESSAGE: 344 + case DELETED:
  345 + case UNASSIGNED_FROM_EDGE:
342 DeviceUpdateMsg deviceUpdateMsg = 346 DeviceUpdateMsg deviceUpdateMsg =
343 ctx.getDeviceUpdateMsgConstructor().constructDeviceDeleteMsg(deviceId); 347 ctx.getDeviceUpdateMsgConstructor().constructDeviceDeleteMsg(deviceId);
344 - EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder() 348 + entityUpdateMsg = EntityUpdateMsg.newBuilder()
345 .setDeviceUpdateMsg(deviceUpdateMsg) 349 .setDeviceUpdateMsg(deviceUpdateMsg)
346 .build(); 350 .build();
347 - outputStream.onNext(ResponseMsg.newBuilder()  
348 - .setEntityUpdateMsg(entityUpdateMsg)  
349 - .build());  
350 - }  
351 - }  
352 -  
353 - private void processDeviceCredentialsCRUD(EdgeEvent edgeEvent, UpdateMsgType msgType) {  
354 - DeviceId deviceId = new DeviceId(edgeEvent.getEntityId());  
355 - switch (msgType) {  
356 - case ENTITY_CREATED_RPC_MESSAGE:  
357 - case ENTITY_UPDATED_RPC_MESSAGE: 351 + break;
  352 + case CREDENTIALS_UPDATED:
358 DeviceCredentials deviceCredentials = ctx.getDeviceCredentialsService().findDeviceCredentialsByDeviceId(edge.getTenantId(), deviceId); 353 DeviceCredentials deviceCredentials = ctx.getDeviceCredentialsService().findDeviceCredentialsByDeviceId(edge.getTenantId(), deviceId);
359 if (deviceCredentials != null) { 354 if (deviceCredentials != null) {
360 DeviceCredentialsUpdateMsg deviceCredentialsUpdateMsg = 355 DeviceCredentialsUpdateMsg deviceCredentialsUpdateMsg =
361 ctx.getDeviceUpdateMsgConstructor().constructDeviceCredentialsUpdatedMsg(deviceCredentials); 356 ctx.getDeviceUpdateMsgConstructor().constructDeviceCredentialsUpdatedMsg(deviceCredentials);
362 - EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder() 357 + entityUpdateMsg = EntityUpdateMsg.newBuilder()
363 .setDeviceCredentialsUpdateMsg(deviceCredentialsUpdateMsg) 358 .setDeviceCredentialsUpdateMsg(deviceCredentialsUpdateMsg)
364 .build(); 359 .build();
365 - outputStream.onNext(ResponseMsg.newBuilder()  
366 - .setEntityUpdateMsg(entityUpdateMsg)  
367 - .build());  
368 } 360 }
369 break; 361 break;
370 } 362 }
  363 + if (entityUpdateMsg != null) {
  364 + outputStream.onNext(ResponseMsg.newBuilder()
  365 + .setEntityUpdateMsg(entityUpdateMsg)
  366 + .build());
  367 + }
371 } 368 }
372 369
373 - private void processAssetCRUD(EdgeEvent edgeEvent, UpdateMsgType msgType) { 370 + private void processAsset(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType edgeEventAction) {
374 AssetId assetId = new AssetId(edgeEvent.getEntityId()); 371 AssetId assetId = new AssetId(edgeEvent.getEntityId());
375 - switch (msgType) {  
376 - case ENTITY_CREATED_RPC_MESSAGE:  
377 - case ENTITY_UPDATED_RPC_MESSAGE: 372 + EntityUpdateMsg entityUpdateMsg = null;
  373 + switch (edgeEventAction) {
  374 + case ADDED:
  375 + case UPDATED:
  376 + case ASSIGNED_TO_EDGE:
378 Asset asset = ctx.getAssetService().findAssetById(edgeEvent.getTenantId(), assetId); 377 Asset asset = ctx.getAssetService().findAssetById(edgeEvent.getTenantId(), assetId);
379 if (asset != null) { 378 if (asset != null) {
380 AssetUpdateMsg assetUpdateMsg = 379 AssetUpdateMsg assetUpdateMsg =
381 ctx.getAssetUpdateMsgConstructor().constructAssetUpdatedMsg(msgType, asset); 380 ctx.getAssetUpdateMsgConstructor().constructAssetUpdatedMsg(msgType, asset);
382 - EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder() 381 + entityUpdateMsg = EntityUpdateMsg.newBuilder()
383 .setAssetUpdateMsg(assetUpdateMsg) 382 .setAssetUpdateMsg(assetUpdateMsg)
384 .build(); 383 .build();
385 - outputStream.onNext(ResponseMsg.newBuilder()  
386 - .setEntityUpdateMsg(entityUpdateMsg)  
387 - .build());  
388 } 384 }
389 break; 385 break;
390 - case ENTITY_DELETED_RPC_MESSAGE: 386 + case DELETED:
  387 + case UNASSIGNED_FROM_EDGE:
391 AssetUpdateMsg assetUpdateMsg = 388 AssetUpdateMsg assetUpdateMsg =
392 ctx.getAssetUpdateMsgConstructor().constructAssetDeleteMsg(assetId); 389 ctx.getAssetUpdateMsgConstructor().constructAssetDeleteMsg(assetId);
393 - EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder() 390 + entityUpdateMsg = EntityUpdateMsg.newBuilder()
394 .setAssetUpdateMsg(assetUpdateMsg) 391 .setAssetUpdateMsg(assetUpdateMsg)
395 .build(); 392 .build();
396 - outputStream.onNext(ResponseMsg.newBuilder()  
397 - .setEntityUpdateMsg(entityUpdateMsg)  
398 - .build());  
399 break; 393 break;
400 } 394 }
  395 + if (entityUpdateMsg != null) {
  396 + outputStream.onNext(ResponseMsg.newBuilder()
  397 + .setEntityUpdateMsg(entityUpdateMsg)
  398 + .build());
  399 + }
401 } 400 }
402 401
403 - private void processEntityViewCRUD(EdgeEvent edgeEvent, UpdateMsgType msgType) { 402 + private void processEntityView(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType edgeEventAction) {
404 EntityViewId entityViewId = new EntityViewId(edgeEvent.getEntityId()); 403 EntityViewId entityViewId = new EntityViewId(edgeEvent.getEntityId());
405 - switch (msgType) {  
406 - case ENTITY_CREATED_RPC_MESSAGE:  
407 - case ENTITY_UPDATED_RPC_MESSAGE: 404 + EntityUpdateMsg entityUpdateMsg = null;
  405 + switch (edgeEventAction) {
  406 + case ADDED:
  407 + case UPDATED:
  408 + case ASSIGNED_TO_EDGE:
408 EntityView entityView = ctx.getEntityViewService().findEntityViewById(edgeEvent.getTenantId(), entityViewId); 409 EntityView entityView = ctx.getEntityViewService().findEntityViewById(edgeEvent.getTenantId(), entityViewId);
409 if (entityView != null) { 410 if (entityView != null) {
410 EntityViewUpdateMsg entityViewUpdateMsg = 411 EntityViewUpdateMsg entityViewUpdateMsg =
411 ctx.getEntityViewUpdateMsgConstructor().constructEntityViewUpdatedMsg(msgType, entityView); 412 ctx.getEntityViewUpdateMsgConstructor().constructEntityViewUpdatedMsg(msgType, entityView);
412 - EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder() 413 + entityUpdateMsg = EntityUpdateMsg.newBuilder()
413 .setEntityViewUpdateMsg(entityViewUpdateMsg) 414 .setEntityViewUpdateMsg(entityViewUpdateMsg)
414 .build(); 415 .build();
415 - outputStream.onNext(ResponseMsg.newBuilder()  
416 - .setEntityUpdateMsg(entityUpdateMsg)  
417 - .build());  
418 } 416 }
419 break; 417 break;
420 - case ENTITY_DELETED_RPC_MESSAGE: 418 + case DELETED:
  419 + case UNASSIGNED_FROM_EDGE:
421 EntityViewUpdateMsg entityViewUpdateMsg = 420 EntityViewUpdateMsg entityViewUpdateMsg =
422 ctx.getEntityViewUpdateMsgConstructor().constructEntityViewDeleteMsg(entityViewId); 421 ctx.getEntityViewUpdateMsgConstructor().constructEntityViewDeleteMsg(entityViewId);
423 - EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder() 422 + entityUpdateMsg = EntityUpdateMsg.newBuilder()
424 .setEntityViewUpdateMsg(entityViewUpdateMsg) 423 .setEntityViewUpdateMsg(entityViewUpdateMsg)
425 .build(); 424 .build();
426 - outputStream.onNext(ResponseMsg.newBuilder()  
427 - .setEntityUpdateMsg(entityUpdateMsg)  
428 - .build());  
429 break; 425 break;
430 } 426 }
  427 + if (entityUpdateMsg != null) {
  428 + outputStream.onNext(ResponseMsg.newBuilder()
  429 + .setEntityUpdateMsg(entityUpdateMsg)
  430 + .build());
  431 + }
431 } 432 }
432 433
433 - private void processDashboardCRUD(EdgeEvent edgeEvent, UpdateMsgType msgType) { 434 + private void processDashboard(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType edgeEventAction) {
434 DashboardId dashboardId = new DashboardId(edgeEvent.getEntityId()); 435 DashboardId dashboardId = new DashboardId(edgeEvent.getEntityId());
435 - switch (msgType) {  
436 - case ENTITY_CREATED_RPC_MESSAGE:  
437 - case ENTITY_UPDATED_RPC_MESSAGE: 436 + EntityUpdateMsg entityUpdateMsg = null;
  437 + switch (edgeEventAction) {
  438 + case ADDED:
  439 + case UPDATED:
  440 + case ASSIGNED_TO_EDGE:
438 Dashboard dashboard = ctx.getDashboardService().findDashboardById(edgeEvent.getTenantId(), dashboardId); 441 Dashboard dashboard = ctx.getDashboardService().findDashboardById(edgeEvent.getTenantId(), dashboardId);
439 if (dashboard != null) { 442 if (dashboard != null) {
440 DashboardUpdateMsg dashboardUpdateMsg = 443 DashboardUpdateMsg dashboardUpdateMsg =
441 ctx.getDashboardUpdateMsgConstructor().constructDashboardUpdatedMsg(msgType, dashboard); 444 ctx.getDashboardUpdateMsgConstructor().constructDashboardUpdatedMsg(msgType, dashboard);
442 - EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder() 445 + entityUpdateMsg = EntityUpdateMsg.newBuilder()
443 .setDashboardUpdateMsg(dashboardUpdateMsg) 446 .setDashboardUpdateMsg(dashboardUpdateMsg)
444 .build(); 447 .build();
445 - outputStream.onNext(ResponseMsg.newBuilder()  
446 - .setEntityUpdateMsg(entityUpdateMsg)  
447 - .build());  
448 } 448 }
449 break; 449 break;
450 - case ENTITY_DELETED_RPC_MESSAGE: 450 + case DELETED:
  451 + case UNASSIGNED_FROM_EDGE:
451 DashboardUpdateMsg dashboardUpdateMsg = 452 DashboardUpdateMsg dashboardUpdateMsg =
452 ctx.getDashboardUpdateMsgConstructor().constructDashboardDeleteMsg(dashboardId); 453 ctx.getDashboardUpdateMsgConstructor().constructDashboardDeleteMsg(dashboardId);
453 - EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder() 454 + entityUpdateMsg = EntityUpdateMsg.newBuilder()
454 .setDashboardUpdateMsg(dashboardUpdateMsg) 455 .setDashboardUpdateMsg(dashboardUpdateMsg)
455 .build(); 456 .build();
456 - outputStream.onNext(ResponseMsg.newBuilder()  
457 - .setEntityUpdateMsg(entityUpdateMsg)  
458 - .build());  
459 break; 457 break;
460 } 458 }
  459 + if (entityUpdateMsg != null) {
  460 + outputStream.onNext(ResponseMsg.newBuilder()
  461 + .setEntityUpdateMsg(entityUpdateMsg)
  462 + .build());
  463 + }
461 } 464 }
462 465
463 - private void processRuleChainCRUD(EdgeEvent edgeEvent, UpdateMsgType msgType) { 466 + private void processRuleChain(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType edgeEventAction) {
464 RuleChainId ruleChainId = new RuleChainId(edgeEvent.getEntityId()); 467 RuleChainId ruleChainId = new RuleChainId(edgeEvent.getEntityId());
465 - switch (msgType) {  
466 - case ENTITY_CREATED_RPC_MESSAGE:  
467 - case ENTITY_UPDATED_RPC_MESSAGE: 468 + EntityUpdateMsg entityUpdateMsg = null;
  469 + switch (edgeEventAction) {
  470 + case ADDED:
  471 + case UPDATED:
  472 + case ASSIGNED_TO_EDGE:
468 RuleChain ruleChain = ctx.getRuleChainService().findRuleChainById(edgeEvent.getTenantId(), ruleChainId); 473 RuleChain ruleChain = ctx.getRuleChainService().findRuleChainById(edgeEvent.getTenantId(), ruleChainId);
469 if (ruleChain != null) { 474 if (ruleChain != null) {
470 RuleChainUpdateMsg ruleChainUpdateMsg = 475 RuleChainUpdateMsg ruleChainUpdateMsg =
471 ctx.getRuleChainUpdateMsgConstructor().constructRuleChainUpdatedMsg(edge.getRootRuleChainId(), msgType, ruleChain); 476 ctx.getRuleChainUpdateMsgConstructor().constructRuleChainUpdatedMsg(edge.getRootRuleChainId(), msgType, ruleChain);
472 - EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder() 477 + entityUpdateMsg = EntityUpdateMsg.newBuilder()
473 .setRuleChainUpdateMsg(ruleChainUpdateMsg) 478 .setRuleChainUpdateMsg(ruleChainUpdateMsg)
474 .build(); 479 .build();
475 - outputStream.onNext(ResponseMsg.newBuilder()  
476 - .setEntityUpdateMsg(entityUpdateMsg)  
477 - .build());  
478 } 480 }
479 break; 481 break;
480 - case ENTITY_DELETED_RPC_MESSAGE:  
481 - EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder() 482 + case DELETED:
  483 + case UNASSIGNED_FROM_EDGE:
  484 + entityUpdateMsg = EntityUpdateMsg.newBuilder()
482 .setRuleChainUpdateMsg(ctx.getRuleChainUpdateMsgConstructor().constructRuleChainDeleteMsg(ruleChainId)) 485 .setRuleChainUpdateMsg(ctx.getRuleChainUpdateMsgConstructor().constructRuleChainDeleteMsg(ruleChainId))
483 .build(); 486 .build();
484 - outputStream.onNext(ResponseMsg.newBuilder()  
485 - .setEntityUpdateMsg(entityUpdateMsg)  
486 - .build());  
487 break; 487 break;
488 } 488 }
  489 + if (entityUpdateMsg != null) {
  490 + outputStream.onNext(ResponseMsg.newBuilder()
  491 + .setEntityUpdateMsg(entityUpdateMsg)
  492 + .build());
  493 + }
489 } 494 }
490 495
491 - private void processRuleChainMetadataCRUD(EdgeEvent edgeEvent, UpdateMsgType msgType) { 496 + private void processRuleChainMetadata(EdgeEvent edgeEvent, UpdateMsgType msgType) {
492 RuleChainId ruleChainId = new RuleChainId(edgeEvent.getEntityId()); 497 RuleChainId ruleChainId = new RuleChainId(edgeEvent.getEntityId());
493 RuleChain ruleChain = ctx.getRuleChainService().findRuleChainById(edgeEvent.getTenantId(), ruleChainId); 498 RuleChain ruleChain = ctx.getRuleChainService().findRuleChainById(edgeEvent.getTenantId(), ruleChainId);
494 if (ruleChain != null) { 499 if (ruleChain != null) {
@@ -506,53 +511,44 @@ public final class EdgeGrpcSession implements Closeable { @@ -506,53 +511,44 @@ public final class EdgeGrpcSession implements Closeable {
506 } 511 }
507 } 512 }
508 513
509 - private void processUserCRUD(EdgeEvent edgeEvent, UpdateMsgType msgType) { 514 + private void processUser(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType edgeActionType) {
510 UserId userId = new UserId(edgeEvent.getEntityId()); 515 UserId userId = new UserId(edgeEvent.getEntityId());
511 - switch (msgType) {  
512 - case ENTITY_CREATED_RPC_MESSAGE:  
513 - case ENTITY_UPDATED_RPC_MESSAGE: 516 + EntityUpdateMsg entityUpdateMsg = null;
  517 + switch (edgeActionType) {
  518 + case ADDED:
  519 + case UPDATED:
  520 + case ASSIGNED_TO_EDGE:
514 User user = ctx.getUserService().findUserById(edgeEvent.getTenantId(), userId); 521 User user = ctx.getUserService().findUserById(edgeEvent.getTenantId(), userId);
515 if (user != null) { 522 if (user != null) {
516 - EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder() 523 + entityUpdateMsg = EntityUpdateMsg.newBuilder()
517 .setUserUpdateMsg(ctx.getUserUpdateMsgConstructor().constructUserUpdatedMsg(msgType, user)) 524 .setUserUpdateMsg(ctx.getUserUpdateMsgConstructor().constructUserUpdatedMsg(msgType, user))
518 .build(); 525 .build();
519 - outputStream.onNext(ResponseMsg.newBuilder()  
520 - .setEntityUpdateMsg(entityUpdateMsg)  
521 - .build());  
522 } 526 }
523 break; 527 break;
524 - case ENTITY_DELETED_RPC_MESSAGE:  
525 - EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder() 528 + case DELETED:
  529 + case UNASSIGNED_FROM_EDGE:
  530 + entityUpdateMsg = EntityUpdateMsg.newBuilder()
526 .setUserUpdateMsg(ctx.getUserUpdateMsgConstructor().constructUserDeleteMsg(userId)) 531 .setUserUpdateMsg(ctx.getUserUpdateMsgConstructor().constructUserDeleteMsg(userId))
527 .build(); 532 .build();
528 - outputStream.onNext(ResponseMsg.newBuilder()  
529 - .setEntityUpdateMsg(entityUpdateMsg)  
530 - .build());  
531 break; 533 break;
532 - }  
533 - }  
534 -  
535 - private void processUserCredentialsCRUD(EdgeEvent edgeEvent, UpdateMsgType msgType) {  
536 - UserId userId = new UserId(edgeEvent.getEntityId());  
537 - switch (msgType) {  
538 - case ENTITY_CREATED_RPC_MESSAGE:  
539 - case ENTITY_UPDATED_RPC_MESSAGE: 534 + case CREDENTIALS_UPDATED:
540 UserCredentials userCredentialsByUserId = ctx.getUserService().findUserCredentialsByUserId(edge.getTenantId(), userId); 535 UserCredentials userCredentialsByUserId = ctx.getUserService().findUserCredentialsByUserId(edge.getTenantId(), userId);
541 if (userCredentialsByUserId != null) { 536 if (userCredentialsByUserId != null) {
542 UserCredentialsUpdateMsg userCredentialsUpdateMsg = 537 UserCredentialsUpdateMsg userCredentialsUpdateMsg =
543 ctx.getUserUpdateMsgConstructor().constructUserCredentialsUpdatedMsg(userCredentialsByUserId); 538 ctx.getUserUpdateMsgConstructor().constructUserCredentialsUpdatedMsg(userCredentialsByUserId);
544 - EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder() 539 + entityUpdateMsg = EntityUpdateMsg.newBuilder()
545 .setUserCredentialsUpdateMsg(userCredentialsUpdateMsg) 540 .setUserCredentialsUpdateMsg(userCredentialsUpdateMsg)
546 .build(); 541 .build();
547 - outputStream.onNext(ResponseMsg.newBuilder()  
548 - .setEntityUpdateMsg(entityUpdateMsg)  
549 - .build());  
550 } 542 }
551 - break; 543 + }
  544 + if (entityUpdateMsg != null) {
  545 + outputStream.onNext(ResponseMsg.newBuilder()
  546 + .setEntityUpdateMsg(entityUpdateMsg)
  547 + .build());
552 } 548 }
553 } 549 }
554 550
555 - private void processRelationCRUD(EdgeEvent edgeEvent, UpdateMsgType msgType) { 551 + private void processRelation(EdgeEvent edgeEvent, UpdateMsgType msgType) {
556 EntityRelation entityRelation = mapper.convertValue(edgeEvent.getEntityBody(), EntityRelation.class); 552 EntityRelation entityRelation = mapper.convertValue(edgeEvent.getEntityBody(), EntityRelation.class);
557 EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder() 553 EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder()
558 .setRelationUpdateMsg(ctx.getRelationUpdateMsgConstructor().constructRelationUpdatedMsg(msgType, entityRelation)) 554 .setRelationUpdateMsg(ctx.getRelationUpdateMsgConstructor().constructRelationUpdatedMsg(msgType, entityRelation))
@@ -562,7 +558,7 @@ public final class EdgeGrpcSession implements Closeable { @@ -562,7 +558,7 @@ public final class EdgeGrpcSession implements Closeable {
562 .build()); 558 .build());
563 } 559 }
564 560
565 - private void processAlarmCRUD(EdgeEvent edgeEvent, UpdateMsgType msgType) { 561 + private void processAlarm(EdgeEvent edgeEvent, UpdateMsgType msgType) {
566 try { 562 try {
567 AlarmId alarmId = new AlarmId(edgeEvent.getEntityId()); 563 AlarmId alarmId = new AlarmId(edgeEvent.getEntityId());
568 Alarm alarm = ctx.getAlarmService().findAlarmByIdAsync(edgeEvent.getTenantId(), alarmId).get(); 564 Alarm alarm = ctx.getAlarmService().findAlarmByIdAsync(edgeEvent.getTenantId(), alarmId).get();
@@ -593,10 +589,6 @@ public final class EdgeGrpcSession implements Closeable { @@ -593,10 +589,6 @@ public final class EdgeGrpcSession implements Closeable {
593 return UpdateMsgType.ALARM_ACK_RPC_MESSAGE; 589 return UpdateMsgType.ALARM_ACK_RPC_MESSAGE;
594 case ALARM_CLEAR: 590 case ALARM_CLEAR:
595 return UpdateMsgType.ALARM_CLEAR_RPC_MESSAGE; 591 return UpdateMsgType.ALARM_CLEAR_RPC_MESSAGE;
596 - case ATTRIBUTES_UPDATED:  
597 - case ATTRIBUTES_DELETED:  
598 - case TIMESERIES_UPDATED:  
599 - return null;  
600 default: 592 default:
601 throw new RuntimeException("Unsupported actionType [" + actionType + "]"); 593 throw new RuntimeException("Unsupported actionType [" + actionType + "]");
602 } 594 }
@@ -395,7 +395,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -395,7 +395,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
395 public void processDeviceCredentialsRequestMsg(Edge edge, DeviceCredentialsRequestMsg deviceCredentialsRequestMsg) { 395 public void processDeviceCredentialsRequestMsg(Edge edge, DeviceCredentialsRequestMsg deviceCredentialsRequestMsg) {
396 if (deviceCredentialsRequestMsg.getDeviceIdMSB() != 0 && deviceCredentialsRequestMsg.getDeviceIdLSB() != 0) { 396 if (deviceCredentialsRequestMsg.getDeviceIdMSB() != 0 && deviceCredentialsRequestMsg.getDeviceIdLSB() != 0) {
397 DeviceId deviceId = new DeviceId(new UUID(deviceCredentialsRequestMsg.getDeviceIdMSB(), deviceCredentialsRequestMsg.getDeviceIdLSB())); 397 DeviceId deviceId = new DeviceId(new UUID(deviceCredentialsRequestMsg.getDeviceIdMSB(), deviceCredentialsRequestMsg.getDeviceIdLSB()));
398 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.DEVICE_CREDENTIALS, ActionType.ADDED, deviceId, null); 398 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.DEVICE, ActionType.CREDENTIALS_UPDATED, deviceId, null);
399 } 399 }
400 } 400 }
401 401
@@ -403,7 +403,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -403,7 +403,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
403 public void processUserCredentialsRequestMsg(Edge edge, UserCredentialsRequestMsg userCredentialsRequestMsg) { 403 public void processUserCredentialsRequestMsg(Edge edge, UserCredentialsRequestMsg userCredentialsRequestMsg) {
404 if (userCredentialsRequestMsg.getUserIdMSB() != 0 && userCredentialsRequestMsg.getUserIdLSB() != 0) { 404 if (userCredentialsRequestMsg.getUserIdMSB() != 0 && userCredentialsRequestMsg.getUserIdLSB() != 0) {
405 UserId userId = new UserId(new UUID(userCredentialsRequestMsg.getUserIdMSB(), userCredentialsRequestMsg.getUserIdLSB())); 405 UserId userId = new UserId(new UUID(userCredentialsRequestMsg.getUserIdMSB(), userCredentialsRequestMsg.getUserIdLSB()));
406 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.USER_CREDENTIALS, ActionType.ADDED, userId, null); 406 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.USER, ActionType.CREDENTIALS_UPDATED, userId, null);
407 } 407 }
408 } 408 }
409 409
@@ -19,14 +19,12 @@ public enum EdgeEventType { @@ -19,14 +19,12 @@ public enum EdgeEventType {
19 DASHBOARD, 19 DASHBOARD,
20 ASSET, 20 ASSET,
21 DEVICE, 21 DEVICE,
22 - DEVICE_CREDENTIALS,  
23 ENTITY_VIEW, 22 ENTITY_VIEW,
24 ALARM, 23 ALARM,
25 RULE_CHAIN, 24 RULE_CHAIN,
26 RULE_CHAIN_METADATA, 25 RULE_CHAIN_METADATA,
27 EDGE, 26 EDGE,
28 USER, 27 USER,
29 - USER_CREDENTIALS,  
30 CUSTOMER, 28 CUSTOMER,
31 RELATION 29 RELATION
32 } 30 }