Commit 117547ae6b239f728406860c2230bb748678e8b9

Authored by Volodymyr Babak
1 parent f1517376

Fixed relation propagation to edge. Code review improvements

... ... @@ -92,7 +92,8 @@ public class AlarmController extends BaseController {
92 92 getCurrentUser().getCustomerId(),
93 93 alarm.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
94 94
95   - sendNotificationMsgToEdgeService(getTenantId(), savedAlarm.getId(), alarm.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
  95 + sendNotificationMsgToEdgeService(getTenantId(), savedAlarm.getId(),
  96 + alarm.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
96 97
97 98 return savedAlarm;
98 99 } catch (Exception e) {
... ...
... ... @@ -88,13 +88,13 @@ public class AssetController extends BaseController {
88 88
89 89 Asset savedAsset = checkNotNull(assetService.saveAsset(asset));
90 90
91   - sendNotificationMsgToEdgeService(savedAsset.getTenantId(), null,
92   - savedAsset.getId(), EdgeEventType.ASSET, asset.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
93   -
94 91 logEntityAction(savedAsset.getId(), savedAsset,
95 92 savedAsset.getCustomerId(),
96 93 asset.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
97 94
  95 + sendNotificationMsgToEdgeService(getTenantId(), savedAsset.getId(),
  96 + asset.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
  97 +
98 98 return savedAsset;
99 99 } catch (Exception e) {
100 100 logEntityAction(emptyId(EntityType.ASSET), asset,
... ... @@ -117,7 +117,7 @@ public class AssetController extends BaseController {
117 117 asset.getCustomerId(),
118 118 ActionType.DELETED, null, strAssetId);
119 119
120   - sendNotificationMsgToEdgeService(getTenantId(), null, assetId, EdgeEventType.ASSET, ActionType.DELETED);
  120 + sendNotificationMsgToEdgeService(getTenantId(), assetId, ActionType.DELETED);
121 121 } catch (Exception e) {
122 122 logEntityAction(emptyId(EntityType.ASSET),
123 123 null,
... ... @@ -360,7 +360,7 @@ public class AssetController extends BaseController {
360 360 savedAsset.getCustomerId(),
361 361 ActionType.ASSIGNED_TO_EDGE, null, strAssetId, strEdgeId, edge.getName());
362 362
363   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EdgeEventType.ASSET, ActionType.ASSIGNED_TO_EDGE);
  363 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), ActionType.ASSIGNED_TO_EDGE);
364 364
365 365 return savedAsset;
366 366 } catch (Exception e) {
... ... @@ -393,8 +393,7 @@ public class AssetController extends BaseController {
393 393 asset.getCustomerId(),
394 394 ActionType.UNASSIGNED_FROM_EDGE, null, strAssetId, edge.getId().toString(), edge.getName());
395 395
396   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(),
397   - EdgeEventType.ASSET, ActionType.UNASSIGNED_FROM_EDGE);
  396 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), ActionType.UNASSIGNED_FROM_EDGE);
398 397
399 398 return savedAsset;
400 399 } catch (Exception e) {
... ...
... ... @@ -126,7 +126,7 @@ public class AuthController extends BaseController {
126 126 userCredentials.setPassword(passwordEncoder.encode(newPassword));
127 127 userService.replaceUserCredentials(securityUser.getTenantId(), userCredentials);
128 128
129   - sendNotificationMsgToEdgeService(getTenantId(), null, userCredentials.getUserId(), EdgeEventType.USER, ActionType.CREDENTIALS_UPDATED);
  129 + sendNotificationMsgToEdgeService(getTenantId(), userCredentials.getUserId(), ActionType.CREDENTIALS_UPDATED);
130 130
131 131 } catch (Exception e) {
132 132 throw handleException(e);
... ...
... ... @@ -730,16 +730,16 @@ public abstract class BaseController {
730 730 }
731 731
732 732 protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, ActionType edgeEventAction) {
  733 + sendNotificationMsgToEdgeService(tenantId, null, entityId, edgeEventAction);
  734 + }
  735 +
  736 + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, ActionType edgeEventAction) {
733 737 EdgeEventType edgeEventType = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType());
734 738 if (edgeEventType != null) {
735   - sendNotificationMsgToEdgeService(tenantId, null, entityId, null, edgeEventType, edgeEventAction);
  739 + sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, null, edgeEventType, edgeEventAction);
736 740 }
737 741 }
738 742
739   - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, EdgeEventType edgeEventType, ActionType edgeEventAction) {
740   - sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, null, edgeEventType, edgeEventAction);
741   - }
742   -
743 743 private void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, String entityBody, EdgeEventType edgeEventType, ActionType edgeEventAction) {
744 744 TransportProtos.EdgeNotificationMsgProto.Builder builder = TransportProtos.EdgeNotificationMsgProto.newBuilder();
745 745 builder.setTenantIdMSB(tenantId.getId().getMostSignificantBits());
... ...
... ... @@ -117,8 +117,8 @@ public class DashboardController extends BaseController {
117 117 null,
118 118 dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
119 119
120   - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), null, savedDashboard.getId(),
121   - EdgeEventType.DASHBOARD, savedDashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
  120 + sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(),
  121 + dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
122 122
123 123 return savedDashboard;
124 124 } catch (Exception e) {
... ... @@ -143,7 +143,7 @@ public class DashboardController extends BaseController {
143 143 null,
144 144 ActionType.DELETED, null, strDashboardId);
145 145
146   - sendNotificationMsgToEdgeService(getTenantId(), null, dashboardId, EdgeEventType.DASHBOARD, ActionType.DELETED);
  146 + sendNotificationMsgToEdgeService(getTenantId(), dashboardId, ActionType.DELETED);
147 147 } catch (Exception e) {
148 148
149 149 logEntityAction(emptyId(EntityType.DASHBOARD),
... ... @@ -500,8 +500,7 @@ public class DashboardController extends BaseController {
500 500 null,
501 501 ActionType.ASSIGNED_TO_EDGE, null, strDashboardId, strEdgeId, edge.getName());
502 502
503   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(),
504   - EdgeEventType.DASHBOARD, ActionType.ASSIGNED_TO_EDGE);
  503 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), ActionType.ASSIGNED_TO_EDGE);
505 504
506 505 return savedDashboard;
507 506 } catch (Exception e) {
... ... @@ -533,8 +532,7 @@ public class DashboardController extends BaseController {
533 532 null,
534 533 ActionType.UNASSIGNED_FROM_EDGE, null, strDashboardId, edge.getId().toString(), edge.getName());
535 534
536   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(),
537   - EdgeEventType.DASHBOARD, ActionType.UNASSIGNED_FROM_EDGE);
  535 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), ActionType.UNASSIGNED_FROM_EDGE);
538 536
539 537 return savedDashboard;
540 538 } catch (Exception e) {
... ...
... ... @@ -108,8 +108,8 @@ public class DeviceController extends BaseController {
108 108 tbClusterService.pushMsgToCore(new DeviceNameOrTypeUpdateMsg(savedDevice.getTenantId(),
109 109 savedDevice.getId(), savedDevice.getName(), savedDevice.getType()), null);
110 110
111   - sendNotificationMsgToEdgeService(savedDevice.getTenantId(), null, savedDevice.getId(),
112   - EdgeEventType.DEVICE, device.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
  111 + sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(),
  112 + device.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
113 113
114 114 logEntityAction(savedDevice.getId(), savedDevice,
115 115 savedDevice.getCustomerId(),
... ... @@ -142,7 +142,7 @@ public class DeviceController extends BaseController {
142 142 device.getCustomerId(),
143 143 ActionType.DELETED, null, strDeviceId);
144 144
145   - sendNotificationMsgToEdgeService(getTenantId(), null, deviceId, EdgeEventType.DEVICE, ActionType.DELETED);
  145 + sendNotificationMsgToEdgeService(getTenantId(), deviceId, ActionType.DELETED);
146 146
147 147 deviceStateService.onDeviceDeleted(device);
148 148 } catch (Exception e) {
... ... @@ -267,7 +267,7 @@ public class DeviceController extends BaseController {
267 267
268 268 tbClusterService.pushMsgToCore(new DeviceCredentialsUpdateNotificationMsg(getCurrentUser().getTenantId(), deviceCredentials.getDeviceId()), null);
269 269
270   - sendNotificationMsgToEdgeService(getTenantId(), null, device.getId(), EdgeEventType.DEVICE, ActionType.CREDENTIALS_UPDATED);
  270 + sendNotificationMsgToEdgeService(getTenantId(), device.getId(), ActionType.CREDENTIALS_UPDATED);
271 271
272 272 logEntityAction(device.getId(), device,
273 273 device.getCustomerId(),
... ... @@ -518,7 +518,7 @@ public class DeviceController extends BaseController {
518 518 savedDevice.getCustomerId(),
519 519 ActionType.ASSIGNED_TO_EDGE, null, strDeviceId, strEdgeId, edge.getName());
520 520
521   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EdgeEventType.DEVICE, ActionType.ASSIGNED_TO_EDGE);
  521 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), ActionType.ASSIGNED_TO_EDGE);
522 522
523 523 return savedDevice;
524 524 } catch (Exception e) {
... ... @@ -549,7 +549,7 @@ public class DeviceController extends BaseController {
549 549 device.getCustomerId(),
550 550 ActionType.UNASSIGNED_FROM_EDGE, null, strDeviceId, edge.getId().toString(), edge.getName());
551 551
552   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EdgeEventType.DEVICE, ActionType.UNASSIGNED_FROM_EDGE);
  552 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), ActionType.UNASSIGNED_FROM_EDGE);
553 553
554 554 return savedDevice;
555 555 } catch (Exception e) {
... ...
... ... @@ -118,8 +118,8 @@ public class EntityViewController extends BaseController {
118 118 logEntityAction(savedEntityView.getId(), savedEntityView, null,
119 119 entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
120 120
121   - sendNotificationMsgToEdgeService(getTenantId(), null, savedEntityView.getId(),
122   - EdgeEventType.ENTITY_VIEW, entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
  121 + sendNotificationMsgToEdgeService(getTenantId(), savedEntityView.getId(),
  122 + entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
123 123 return savedEntityView;
124 124 } catch (Exception e) {
125 125 logEntityAction(emptyId(EntityType.ENTITY_VIEW), entityView, null,
... ... @@ -190,7 +190,7 @@ public class EntityViewController extends BaseController {
190 190 logEntityAction(entityViewId, entityView, entityView.getCustomerId(),
191 191 ActionType.DELETED, null, strEntityViewId);
192 192
193   - sendNotificationMsgToEdgeService(getTenantId(), null, entityViewId, EdgeEventType.ENTITY_VIEW, ActionType.DELETED);
  193 + sendNotificationMsgToEdgeService(getTenantId(), entityViewId, ActionType.DELETED);
194 194 } catch (Exception e) {
195 195 logEntityAction(emptyId(EntityType.ENTITY_VIEW),
196 196 null,
... ... @@ -396,8 +396,7 @@ public class EntityViewController extends BaseController {
396 396 savedEntityView.getCustomerId(),
397 397 ActionType.ASSIGNED_TO_EDGE, null, strEntityViewId, strEdgeId, edge.getName());
398 398
399   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(),
400   - EdgeEventType.ENTITY_VIEW, ActionType.ASSIGNED_TO_EDGE);
  399 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), ActionType.ASSIGNED_TO_EDGE);
401 400
402 401 return savedEntityView;
403 402 } catch (Exception e) {
... ... @@ -427,8 +426,7 @@ public class EntityViewController extends BaseController {
427 426 entityView.getCustomerId(),
428 427 ActionType.UNASSIGNED_FROM_EDGE, null, strEntityViewId, edge.getId().toString(), edge.getName());
429 428
430   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(),
431   - EdgeEventType.ENTITY_VIEW, ActionType.UNASSIGNED_FROM_EDGE);
  429 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), ActionType.UNASSIGNED_FROM_EDGE);
432 430
433 431 return savedEntityView;
434 432 } catch (Exception e) {
... ...
... ... @@ -145,9 +145,8 @@ public class RuleChainController extends BaseController {
145 145 created ? ActionType.ADDED : ActionType.UPDATED, null);
146 146
147 147 if (RuleChainType.EDGE.equals(savedRuleChain.getType())) {
148   - sendNotificationMsgToEdgeService(savedRuleChain.getTenantId(), null,
149   - savedRuleChain.getId(), EdgeEventType.RULE_CHAIN,
150   - savedRuleChain.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
  148 + sendNotificationMsgToEdgeService(savedRuleChain.getTenantId(), savedRuleChain.getId(),
  149 + created ? ActionType.ADDED : ActionType.UPDATED);
151 150 }
152 151
153 152 return savedRuleChain;
... ... @@ -226,9 +225,7 @@ public class RuleChainController extends BaseController {
226 225
227 226 if (RuleChainType.EDGE.equals(ruleChain.getType())) {
228 227 sendNotificationMsgToEdgeService(ruleChain.getTenantId(),
229   - null,
230   - ruleChain.getId(), EdgeEventType.RULE_CHAIN,
231   - ActionType.UPDATED);
  228 + ruleChain.getId(), ActionType.UPDATED);
232 229 }
233 230
234 231 return savedRuleChainMetaData;
... ... @@ -293,8 +290,7 @@ public class RuleChainController extends BaseController {
293 290 ActionType.DELETED, null, strRuleChainId);
294 291
295 292 if (RuleChainType.EDGE.equals(ruleChain.getType())) {
296   - sendNotificationMsgToEdgeService(ruleChain.getTenantId(), null,
297   - ruleChain.getId(), EdgeEventType.RULE_CHAIN, ActionType.DELETED);
  293 + sendNotificationMsgToEdgeService(ruleChain.getTenantId(), ruleChain.getId(), ActionType.DELETED);
298 294 }
299 295
300 296 } catch (Exception e) {
... ... @@ -426,8 +422,7 @@ public class RuleChainController extends BaseController {
426 422 null,
427 423 ActionType.ASSIGNED_TO_EDGE, null, strRuleChainId, strEdgeId, edge.getName());
428 424
429   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(),
430   - EdgeEventType.RULE_CHAIN, ActionType.ASSIGNED_TO_EDGE);
  425 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), ActionType.ASSIGNED_TO_EDGE);
431 426
432 427 return savedRuleChain;
433 428 } catch (Exception e) {
... ... @@ -459,8 +454,7 @@ public class RuleChainController extends BaseController {
459 454 null,
460 455 ActionType.UNASSIGNED_FROM_EDGE, null, strRuleChainId, edge.getId().toString(), edge.getName());
461 456
462   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(),
463   - EdgeEventType.RULE_CHAIN, ActionType.UNASSIGNED_FROM_EDGE);
  457 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), ActionType.UNASSIGNED_FROM_EDGE);
464 458
465 459 return savedRuleChain;
466 460 } catch (Exception e) {
... ...
... ... @@ -162,7 +162,8 @@ public class UserController extends BaseController {
162 162 savedUser.getCustomerId(),
163 163 user.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
164 164
165   - sendNotificationMsgToEdgeService(getTenantId(), null, user.getId(), EdgeEventType.USER, user.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
  165 + sendNotificationMsgToEdgeService(getTenantId(), savedUser.getId(),
  166 + user.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
166 167
167 168 return savedUser;
168 169 } catch (Exception e) {
... ... @@ -239,7 +240,7 @@ public class UserController extends BaseController {
239 240 user.getCustomerId(),
240 241 ActionType.DELETED, null, strUserId);
241 242
242   - sendNotificationMsgToEdgeService(getTenantId(), null, user.getId(), EdgeEventType.USER, ActionType.DELETED);
  243 + sendNotificationMsgToEdgeService(getTenantId(), user.getId(), ActionType.DELETED);
243 244
244 245 } catch (Exception e) {
245 246 logEntityAction(emptyId(EntityType.USER),
... ...
... ... @@ -72,7 +72,8 @@ public class WidgetTypeController extends BaseController {
72 72 checkEntity(widgetType.getId(), widgetType, Resource.WIDGET_TYPE);
73 73 WidgetType savedWidgetType = widgetTypeService.saveWidgetType(widgetType);
74 74
75   - sendNotificationMsgToEdgeService(getTenantId(), savedWidgetType.getId(), widgetType.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
  75 + sendNotificationMsgToEdgeService(getTenantId(), savedWidgetType.getId(),
  76 + widgetType.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
76 77
77 78 return checkNotNull(savedWidgetType);
78 79 } catch (Exception e) {
... ...
... ... @@ -71,7 +71,8 @@ public class WidgetsBundleController extends BaseController {
71 71 checkEntity(widgetsBundle.getId(), widgetsBundle, Resource.WIDGETS_BUNDLE);
72 72 WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
73 73
74   - sendNotificationMsgToEdgeService(getTenantId(), savedWidgetsBundle.getId(), widgetsBundle.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
  74 + sendNotificationMsgToEdgeService(getTenantId(), savedWidgetsBundle.getId(),
  75 + widgetsBundle.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
75 76
76 77 return checkNotNull(savedWidgetsBundle);
77 78 } catch (Exception e) {
... ...
... ... @@ -234,6 +234,8 @@ public final class EdgeGrpcSession implements Closeable {
234 234 case ALARM_ACK:
235 235 case ALARM_CLEAR:
236 236 case CREDENTIALS_UPDATED:
  237 + case RELATION_ADD_OR_UPDATE:
  238 + case RELATION_DELETED:
237 239 processEntityMessage(edgeEvent, edgeEventAction);
238 240 break;
239 241 case ATTRIBUTES_UPDATED:
... ... @@ -687,9 +689,11 @@ public final class EdgeGrpcSession implements Closeable {
687 689 return UpdateMsgType.ENTITY_UPDATED_RPC_MESSAGE;
688 690 case ADDED:
689 691 case ASSIGNED_TO_EDGE:
  692 + case RELATION_ADD_OR_UPDATE:
690 693 return ENTITY_CREATED_RPC_MESSAGE;
691 694 case DELETED:
692 695 case UNASSIGNED_FROM_EDGE:
  696 + case RELATION_DELETED:
693 697 return UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE;
694 698 case ALARM_ACK:
695 699 return UpdateMsgType.ALARM_ACK_RPC_MESSAGE;
... ...