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