Commit 555778bf7dcb94106b41d2b4db171f8fe765f76a

Authored by Volodymyr Babak
2 parents 02d1bad0 0e7af5a6

Merge remote-tracking branch 'origin/develop/2.6-edge' into develop/3.3-edge

... ... @@ -95,8 +95,7 @@ public class AlarmController extends BaseController {
95 95 getCurrentUser().getCustomerId(),
96 96 alarm.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
97 97
98   - sendNotificationMsgToEdgeService(getTenantId(), savedAlarm.getId(), EntityType.ALARM,
99   - alarm.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
  98 + sendEntityNotificationMsg(getTenantId(), savedAlarm.getId(), alarm.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
100 99
101 100 return savedAlarm;
102 101 } catch (Exception e) {
... ... @@ -115,7 +114,7 @@ public class AlarmController extends BaseController {
115 114 AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
116 115 checkAlarmId(alarmId, Operation.WRITE);
117 116
118   - sendNotificationMsgToEdgeService(getTenantId(), alarmId, EntityType.ALARM, EdgeEventActionType.DELETED);
  117 + sendEntityNotificationMsg(getTenantId(), alarmId, EdgeEventActionType.DELETED);
119 118
120 119 return alarmService.deleteAlarm(getTenantId(), alarmId);
121 120 } catch (Exception e) {
... ... @@ -137,7 +136,7 @@ public class AlarmController extends BaseController {
137 136 alarm.setStatus(alarm.getStatus().isCleared() ? AlarmStatus.CLEARED_ACK : AlarmStatus.ACTIVE_ACK);
138 137 logEntityAction(alarm.getOriginator(), alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_ACK, null);
139 138
140   - sendNotificationMsgToEdgeService(getTenantId(), alarmId, EntityType.ALARM, EdgeEventActionType.ALARM_ACK);
  139 + sendEntityNotificationMsg(getTenantId(), alarmId, EdgeEventActionType.ALARM_ACK);
141 140 } catch (Exception e) {
142 141 throw handleException(e);
143 142 }
... ... @@ -157,7 +156,7 @@ public class AlarmController extends BaseController {
157 156 alarm.setStatus(alarm.getStatus().isAck() ? AlarmStatus.CLEARED_ACK : AlarmStatus.CLEARED_UNACK);
158 157 logEntityAction(alarm.getOriginator(), alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_CLEAR, null);
159 158
160   - sendNotificationMsgToEdgeService(getTenantId(), alarmId, EntityType.ALARM, EdgeEventActionType.ALARM_CLEAR);
  159 + sendEntityNotificationMsg(getTenantId(), alarmId, EdgeEventActionType.ALARM_CLEAR);
161 160 } catch (Exception e) {
162 161 throw handleException(e);
163 162 }
... ...
... ... @@ -113,7 +113,7 @@ public class AssetController extends BaseController {
113 113 asset.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
114 114
115 115 if (asset.getId() != null) {
116   - sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(), EntityType.ASSET, EdgeEventActionType.UPDATED);
  116 + sendEntityNotificationMsg(savedAsset.getTenantId(), savedAsset.getId(), EdgeEventActionType.UPDATED);
117 117 }
118 118
119 119 return savedAsset;
... ... @@ -141,7 +141,7 @@ public class AssetController extends BaseController {
141 141 asset.getCustomerId(),
142 142 ActionType.DELETED, null, strAssetId);
143 143
144   - sendDeleteNotificationMsgToEdgeService(getTenantId(), assetId, EntityType.ASSET, relatedEdgeIds);
  144 + sendDeleteNotificationMsg(getTenantId(), assetId, relatedEdgeIds);
145 145 } catch (Exception e) {
146 146 logEntityAction(emptyId(EntityType.ASSET),
147 147 null,
... ... @@ -171,7 +171,7 @@ public class AssetController extends BaseController {
171 171 savedAsset.getCustomerId(),
172 172 ActionType.ASSIGNED_TO_CUSTOMER, null, strAssetId, strCustomerId, customer.getName());
173 173
174   - sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(),
  174 + sendEntityAssignToCustomerNotificationMsg(savedAsset.getTenantId(), savedAsset.getId(),
175 175 customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
176 176
177 177 return savedAsset;
... ... @@ -205,7 +205,7 @@ public class AssetController extends BaseController {
205 205 asset.getCustomerId(),
206 206 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strAssetId, customer.getId().toString(), customer.getName());
207 207
208   - sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(),
  208 + sendEntityAssignToCustomerNotificationMsg(savedAsset.getTenantId(), savedAsset.getId(),
209 209 customer.getId(), EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
210 210
211 211 return savedAsset;
... ... @@ -442,7 +442,7 @@ public class AssetController extends BaseController {
442 442 savedAsset.getCustomerId(),
443 443 ActionType.ASSIGNED_TO_EDGE, null, strAssetId, strEdgeId, edge.getName());
444 444
445   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EntityType.ASSET, EdgeEventActionType.ASSIGNED_TO_EDGE);
  445 + sendEntityAssignToEdgeNotificationMsg(getTenantId(), edgeId, savedAsset.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
446 446
447 447 return savedAsset;
448 448 } catch (Exception e) {
... ... @@ -475,7 +475,7 @@ public class AssetController extends BaseController {
475 475 asset.getCustomerId(),
476 476 ActionType.UNASSIGNED_FROM_EDGE, null, strAssetId, strEdgeId, edge.getName());
477 477
478   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EntityType.ASSET, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
  478 + sendEntityAssignToEdgeNotificationMsg(getTenantId(), edgeId, savedAsset.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
479 479
480 480 return savedAsset;
481 481 } catch (Exception e) {
... ...
... ... @@ -33,7 +33,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
33 33 import org.springframework.web.bind.annotation.ResponseStatus;
34 34 import org.springframework.web.bind.annotation.RestController;
35 35 import org.thingsboard.rule.engine.api.MailService;
36   -import org.thingsboard.server.common.data.EntityType;
37 36 import org.thingsboard.server.common.data.User;
38 37 import org.thingsboard.server.common.data.audit.ActionType;
39 38 import org.thingsboard.server.common.data.edge.EdgeEventActionType;
... ... @@ -120,7 +119,7 @@ public class AuthController extends BaseController {
120 119 userCredentials.setPassword(passwordEncoder.encode(newPassword));
121 120 userService.replaceUserCredentials(securityUser.getTenantId(), userCredentials);
122 121
123   - sendNotificationMsgToEdgeService(getTenantId(), userCredentials.getUserId(), EntityType.USER, EdgeEventActionType.CREDENTIALS_UPDATED);
  122 + sendEntityNotificationMsg(getTenantId(), userCredentials.getUserId(), EdgeEventActionType.CREDENTIALS_UPDATED);
124 123
125 124 } catch (Exception e) {
126 125 throw handleException(e);
... ... @@ -230,7 +229,7 @@ public class AuthController extends BaseController {
230 229 }
231 230 }
232 231
233   - sendNotificationMsgToEdgeService(user.getTenantId(), user.getId(), EntityType.USER, EdgeEventActionType.CREDENTIALS_UPDATED);
  232 + sendEntityNotificationMsg(user.getTenantId(), user.getId(), EdgeEventActionType.CREDENTIALS_UPDATED);
234 233
235 234 JwtToken accessToken = tokenFactory.createAccessJwtToken(securityUser);
236 235 JwtToken refreshToken = refreshTokenRepository.requestRefreshToken(securityUser);
... ...
... ... @@ -927,35 +927,7 @@ public abstract class BaseController {
927 927 return null;
928 928 }
929 929
930   - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, CustomerId customerId, EdgeEventActionType action) {
931   - if (!edgesEnabled) {
932   - return;
933   - }
934   - try {
935   - sendNotificationMsgToEdgeService(tenantId, edgeId, null, json.writeValueAsString(customerId), EdgeEventType.EDGE, action);
936   - } catch (Exception e) {
937   - log.warn("Failed to push assign/unassign to/from customer to core: {}", customerId, e);
938   - }
939   - }
940   -
941   - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, CustomerId customerId, EdgeEventActionType action) {
942   - if (!edgesEnabled) {
943   - return;
944   - }
945   - EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType());
946   - try {
947   - if (type != null) {
948   - sendNotificationMsgToEdgeService(tenantId, null, entityId, json.writeValueAsString(customerId), type, action);
949   - }
950   - } catch (Exception e) {
951   - log.warn("Failed to push assign/unassign to/from customer to core: {}", customerId, e);
952   - }
953   - }
954   -
955   - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityRelation relation, EdgeEventActionType action) {
956   - if (!edgesEnabled) {
957   - return;
958   - }
  930 + protected void sendRelationNotificationMsg(TenantId tenantId, EntityRelation relation, EdgeEventActionType action) {
959 931 try {
960 932 if (!relation.getFrom().getEntityType().equals(EntityType.EDGE) &&
961 933 !relation.getTo().getEntityType().equals(EntityType.EDGE)) {
... ... @@ -966,45 +938,46 @@ public abstract class BaseController {
966 938 }
967 939 }
968 940
969   - protected List<EdgeId> findRelatedEdgeIds(TenantId tenantId, EntityId entityId) {
970   - if (!edgesEnabled) {
971   - return null;
  941 + protected void sendDeleteNotificationMsg(TenantId tenantId, EntityId entityId, List<EdgeId> edgeIds) {
  942 + if (edgeIds != null && !edgeIds.isEmpty()) {
  943 + for (EdgeId edgeId : edgeIds) {
  944 + sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, null, null, EdgeEventActionType.DELETED);
  945 + }
972 946 }
973   - List<EdgeId> result = null;
  947 + }
  948 +
  949 + protected void sendEntityAssignToCustomerNotificationMsg(TenantId tenantId, EntityId entityId, CustomerId customerId, EdgeEventActionType action) {
974 950 try {
975   - result = edgeService.findRelatedEdgeIdsByEntityId(tenantId, entityId).get();
  951 + sendNotificationMsgToEdgeService(tenantId, null, entityId, json.writeValueAsString(customerId), null, action);
976 952 } catch (Exception e) {
977   - log.error("[{}] can't find related edge ids for entity [{}]", tenantId, entityId, e);
  953 + log.warn("Failed to push assign/unassign to/from customer to core: {}", customerId, e);
978 954 }
979   - return result;
980 955 }
981 956
982   - protected void sendDeleteNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, EntityType entityType, List<EdgeId> edgeIds) {
983   - if (!edgesEnabled) {
984   - return;
985   - }
986   - if (edgeIds != null && !edgeIds.isEmpty()) {
987   - for (EdgeId edgeId : edgeIds) {
988   - sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, entityType, EdgeEventActionType.DELETED);
989   - }
990   - }
  957 + protected void sendEntityNotificationMsg(TenantId tenantId, EntityId entityId, EdgeEventActionType action) {
  958 + sendNotificationMsgToEdgeService(tenantId, null, entityId, null, null, action);
991 959 }
992 960
993   - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, EntityType entityType, EdgeEventActionType action) {
994   - sendNotificationMsgToEdgeService(tenantId, null, entityId, entityType, action);
  961 + protected void sendEntityAssignToEdgeNotificationMsg(TenantId tenantId, EdgeId edgeId, EntityId entityId, EdgeEventActionType action) {
  962 + sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, null, null, action);
995 963 }
996 964
997   - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, EntityType entityType, EdgeEventActionType action) {
  965 + private void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, String body, EdgeEventType type, EdgeEventActionType action) {
998 966 if (!edgesEnabled) {
999 967 return;
1000 968 }
1001   - EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityType);
1002   - if (type != null) {
1003   - sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, null, type, action);
  969 + if (type == null) {
  970 + if (entityId != null) {
  971 + type = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType());
  972 + } else {
  973 + log.trace("[{}] entity id and type are null. Ignoring this notification", tenantId);
  974 + return;
  975 + }
  976 + if (type == null) {
  977 + log.trace("[{}] edge event type is null. Ignoring this notification [{}]", tenantId, entityId);
  978 + return;
  979 + }
1004 980 }
1005   - }
1006   -
1007   - private void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, String body, EdgeEventType type, EdgeEventActionType action) {
1008 981 TransportProtos.EdgeNotificationMsgProto.Builder builder = TransportProtos.EdgeNotificationMsgProto.newBuilder();
1009 982 builder.setTenantIdMSB(tenantId.getId().getMostSignificantBits());
1010 983 builder.setTenantIdLSB(tenantId.getId().getLeastSignificantBits());
... ... @@ -1028,6 +1001,19 @@ public abstract class BaseController {
1028 1001 TransportProtos.ToCoreMsg.newBuilder().setEdgeNotificationMsg(msg).build(), null);
1029 1002 }
1030 1003
  1004 + protected List<EdgeId> findRelatedEdgeIds(TenantId tenantId, EntityId entityId) {
  1005 + if (!edgesEnabled) {
  1006 + return null;
  1007 + }
  1008 + List<EdgeId> result = null;
  1009 + try {
  1010 + result = edgeService.findRelatedEdgeIdsByEntityId(tenantId, entityId).get();
  1011 + } catch (Exception e) {
  1012 + log.error("[{}] can't find related edge ids for entity [{}]", tenantId, entityId, e);
  1013 + }
  1014 + return result;
  1015 + }
  1016 +
1031 1017 private void addTimeseries(ObjectNode entityNode, List<TsKvEntry> timeseries) throws Exception {
1032 1018 if (timeseries != null && !timeseries.isEmpty()) {
1033 1019 ArrayNode result = entityNode.putArray("timeseries");
... ...
... ... @@ -113,7 +113,7 @@ public class CustomerController extends BaseController {
113 113 customer.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
114 114
115 115 if (customer.getId() != null) {
116   - sendNotificationMsgToEdgeService(savedCustomer.getTenantId(), savedCustomer.getId(), EntityType.CUSTOMER, EdgeEventActionType.UPDATED);
  116 + sendEntityNotificationMsg(savedCustomer.getTenantId(), savedCustomer.getId(), EdgeEventActionType.UPDATED);
117 117 }
118 118
119 119 return savedCustomer;
... ... @@ -143,7 +143,7 @@ public class CustomerController extends BaseController {
143 143 customer.getId(),
144 144 ActionType.DELETED, null, strCustomerId);
145 145
146   - sendDeleteNotificationMsgToEdgeService(getTenantId(), customerId, EntityType.CUSTOMER, relatedEdgeIds);
  146 + sendDeleteNotificationMsg(getTenantId(), customerId, relatedEdgeIds);
147 147 } catch (Exception e) {
148 148
149 149 logEntityAction(emptyId(EntityType.CUSTOMER),
... ...
... ... @@ -118,7 +118,7 @@ public class DashboardController extends BaseController {
118 118 dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
119 119
120 120 if (dashboard.getId() != null) {
121   - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), EntityType.DASHBOARD, EdgeEventActionType.UPDATED);
  121 + sendEntityNotificationMsg(savedDashboard.getTenantId(), savedDashboard.getId(), EdgeEventActionType.UPDATED);
122 122 }
123 123
124 124 return savedDashboard;
... ... @@ -147,7 +147,7 @@ public class DashboardController extends BaseController {
147 147 null,
148 148 ActionType.DELETED, null, strDashboardId);
149 149
150   - sendDeleteNotificationMsgToEdgeService(getTenantId(), dashboardId, EntityType.DASHBOARD, relatedEdgeIds);
  150 + sendDeleteNotificationMsg(getTenantId(), dashboardId, relatedEdgeIds);
151 151 } catch (Exception e) {
152 152
153 153 logEntityAction(emptyId(EntityType.DASHBOARD),
... ... @@ -179,7 +179,7 @@ public class DashboardController extends BaseController {
179 179 customerId,
180 180 ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, strCustomerId, customer.getName());
181 181
182   - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
  182 + sendEntityAssignToCustomerNotificationMsg(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
183 183
184 184 return savedDashboard;
185 185 } catch (Exception e) {
... ... @@ -211,7 +211,7 @@ public class DashboardController extends BaseController {
211 211 customerId,
212 212 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customer.getId().toString(), customer.getName());
213 213
214   - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
  214 + sendEntityAssignToCustomerNotificationMsg(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
215 215
216 216 return savedDashboard;
217 217 } catch (Exception e) {
... ... @@ -268,7 +268,7 @@ public class DashboardController extends BaseController {
268 268 logEntityAction(dashboardId, savedDashboard,
269 269 customerId,
270 270 ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
271   - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
  271 + sendEntityAssignToCustomerNotificationMsg(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
272 272 }
273 273 for (CustomerId customerId : removedCustomerIds) {
274 274 ShortCustomerInfo customerInfo = dashboard.getAssignedCustomerInfo(customerId);
... ... @@ -276,7 +276,7 @@ public class DashboardController extends BaseController {
276 276 logEntityAction(dashboardId, dashboard,
277 277 customerId,
278 278 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
279   - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
  279 + sendEntityAssignToCustomerNotificationMsg(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
280 280 }
281 281 return savedDashboard;
282 282 }
... ... @@ -320,7 +320,7 @@ public class DashboardController extends BaseController {
320 320 logEntityAction(dashboardId, savedDashboard,
321 321 customerId,
322 322 ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
323   - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
  323 + sendEntityAssignToCustomerNotificationMsg(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
324 324 }
325 325 return savedDashboard;
326 326 }
... ... @@ -364,7 +364,7 @@ public class DashboardController extends BaseController {
364 364 logEntityAction(dashboardId, dashboard,
365 365 customerId,
366 366 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
367   - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
  367 + sendEntityAssignToCustomerNotificationMsg(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
368 368 }
369 369 return savedDashboard;
370 370 }
... ... @@ -511,7 +511,7 @@ public class DashboardController extends BaseController {
511 511 null,
512 512 ActionType.ASSIGNED_TO_EDGE, null, strDashboardId, strEdgeId, edge.getName());
513 513
514   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EntityType.DASHBOARD, EdgeEventActionType.ASSIGNED_TO_EDGE);
  514 + sendEntityAssignToEdgeNotificationMsg(getTenantId(), edgeId, savedDashboard.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
515 515
516 516 return savedDashboard;
517 517 } catch (Exception e) {
... ... @@ -543,7 +543,7 @@ public class DashboardController extends BaseController {
543 543 null,
544 544 ActionType.UNASSIGNED_FROM_EDGE, null, strDashboardId, strEdgeId, edge.getName());
545 545
546   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EntityType.DASHBOARD, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
  546 + sendEntityAssignToEdgeNotificationMsg(getTenantId(), edgeId, savedDashboard.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
547 547
548 548 return savedDashboard;
549 549 } catch (Exception e) {
... ...
... ... @@ -132,7 +132,7 @@ public class DeviceController extends BaseController {
132 132 device.getId() == null ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
133 133
134 134 if (device.getId() != null) {
135   - sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(), EntityType.DEVICE, EdgeEventActionType.UPDATED);
  135 + sendEntityNotificationMsg(savedDevice.getTenantId(), savedDevice.getId(), EdgeEventActionType.UPDATED);
136 136 }
137 137
138 138 logEntityAction(savedDevice.getId(), savedDevice,
... ... @@ -172,7 +172,7 @@ public class DeviceController extends BaseController {
172 172 device.getCustomerId(),
173 173 ActionType.DELETED, null, strDeviceId);
174 174
175   - sendDeleteNotificationMsgToEdgeService(getTenantId(), deviceId, EntityType.DEVICE, relatedEdgeIds);
  175 + sendDeleteNotificationMsg(getTenantId(), deviceId, relatedEdgeIds);
176 176
177 177 deviceStateService.onDeviceDeleted(device);
178 178 } catch (Exception e) {
... ... @@ -204,7 +204,7 @@ public class DeviceController extends BaseController {
204 204 savedDevice.getCustomerId(),
205 205 ActionType.ASSIGNED_TO_CUSTOMER, null, strDeviceId, strCustomerId, customer.getName());
206 206
207   - sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(),
  207 + sendEntityAssignToCustomerNotificationMsg(savedDevice.getTenantId(), savedDevice.getId(),
208 208 customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
209 209
210 210 return savedDevice;
... ... @@ -235,7 +235,7 @@ public class DeviceController extends BaseController {
235 235 device.getCustomerId(),
236 236 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDeviceId, customer.getId().toString(), customer.getName());
237 237
238   - sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(),
  238 + sendEntityAssignToCustomerNotificationMsg(savedDevice.getTenantId(), savedDevice.getId(),
239 239 customer.getId(), EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
240 240
241 241 return savedDevice;
... ... @@ -303,7 +303,8 @@ public class DeviceController extends BaseController {
303 303 //log.info("0 LwM2M CredentialsUpdate start)
304 304 tbClusterService.pushMsgToCore(new DeviceCredentialsUpdateNotificationMsg(getCurrentUser().getTenantId(), deviceCredentials.getDeviceId(), result), null);
305 305
306   - sendNotificationMsgToEdgeService(getTenantId(), device.getId(), EntityType.DEVICE, EdgeEventActionType.CREDENTIALS_UPDATED);
  306 + sendEntityNotificationMsg(getTenantId(), device.getId(), EdgeEventActionType.CREDENTIALS_UPDATED);
  307 +
307 308 logEntityAction(device.getId(), device,
308 309 device.getCustomerId(),
309 310 ActionType.CREDENTIALS_UPDATED, null, deviceCredentials);
... ... @@ -666,7 +667,7 @@ public class DeviceController extends BaseController {
666 667 savedDevice.getCustomerId(),
667 668 ActionType.ASSIGNED_TO_EDGE, null, strDeviceId, strEdgeId, edge.getName());
668 669
669   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EntityType.DEVICE, EdgeEventActionType.ASSIGNED_TO_EDGE);
  670 + sendEntityAssignToEdgeNotificationMsg(getTenantId(), edgeId, savedDevice.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
670 671
671 672 return savedDevice;
672 673 } catch (Exception e) {
... ... @@ -700,7 +701,7 @@ public class DeviceController extends BaseController {
700 701 device.getCustomerId(),
701 702 ActionType.UNASSIGNED_FROM_EDGE, null, strDeviceId, strEdgeId, edge.getName());
702 703
703   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EntityType.DEVICE, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
  704 + sendEntityAssignToEdgeNotificationMsg(getTenantId(), edgeId, savedDevice.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
704 705
705 706 return savedDevice;
706 707 } catch (Exception e) {
... ...
... ... @@ -154,7 +154,7 @@ public class DeviceProfileController extends BaseController {
154 154 null,
155 155 created ? ActionType.ADDED : ActionType.UPDATED, null);
156 156
157   - sendNotificationMsgToEdgeService(getTenantId(), savedDeviceProfile.getId(), EntityType.DEVICE_PROFILE,
  157 + sendEntityNotificationMsg(getTenantId(), savedDeviceProfile.getId(),
158 158 deviceProfile.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
159 159
160 160 return savedDeviceProfile;
... ... @@ -182,7 +182,7 @@ public class DeviceProfileController extends BaseController {
182 182 null,
183 183 ActionType.DELETED, null, strDeviceProfileId);
184 184
185   - sendNotificationMsgToEdgeService(getTenantId(), deviceProfile.getId(), EntityType.DEVICE_PROFILE, EdgeEventActionType.DELETED);
  185 + sendEntityNotificationMsg(getTenantId(), deviceProfile.getId(), EdgeEventActionType.DELETED);
186 186 } catch (Exception e) {
187 187 logEntityAction(emptyId(EntityType.DEVICE_PROFILE),
188 188 null,
... ...
... ... @@ -216,7 +216,7 @@ public class EdgeController extends BaseController {
216 216 savedEdge.getCustomerId(),
217 217 ActionType.ASSIGNED_TO_CUSTOMER, null, strEdgeId, strCustomerId, customer.getName());
218 218
219   - sendNotificationMsgToEdgeService(savedEdge.getTenantId(), savedEdge.getId(),
  219 + sendEntityAssignToCustomerNotificationMsg(savedEdge.getTenantId(), savedEdge.getId(),
220 220 customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
221 221
222 222 return savedEdge;
... ... @@ -250,7 +250,7 @@ public class EdgeController extends BaseController {
250 250 edge.getCustomerId(),
251 251 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strEdgeId, customer.getId().toString(), customer.getName());
252 252
253   - sendNotificationMsgToEdgeService(savedEdge.getTenantId(), savedEdge.getId(),
  253 + sendEntityAssignToCustomerNotificationMsg(savedEdge.getTenantId(), savedEdge.getId(),
254 254 customer.getId(), EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
255 255
256 256 return savedEdge;
... ...
... ... @@ -70,7 +70,7 @@ public class EntityRelationController extends BaseController {
70 70 logEntityAction(relation.getTo(), null, getCurrentUser().getCustomerId(),
71 71 ActionType.RELATION_ADD_OR_UPDATE, null, relation);
72 72
73   - sendNotificationMsgToEdgeService(getTenantId(), relation, EdgeEventActionType.RELATION_ADD_OR_UPDATE);
  73 + sendRelationNotificationMsg(getTenantId(), relation, EdgeEventActionType.RELATION_ADD_OR_UPDATE);
74 74 } catch (Exception e) {
75 75 logEntityAction(relation.getFrom(), null, getCurrentUser().getCustomerId(),
76 76 ActionType.RELATION_ADD_OR_UPDATE, e, relation);
... ... @@ -109,7 +109,7 @@ public class EntityRelationController extends BaseController {
109 109 logEntityAction(relation.getTo(), null, getCurrentUser().getCustomerId(),
110 110 ActionType.RELATION_DELETED, null, relation);
111 111
112   - sendNotificationMsgToEdgeService(getTenantId(), relation, EdgeEventActionType.RELATION_DELETED);
  112 + sendRelationNotificationMsg(getTenantId(), relation, EdgeEventActionType.RELATION_DELETED);
113 113 } catch (Exception e) {
114 114 logEntityAction(relation.getFrom(), null, getCurrentUser().getCustomerId(),
115 115 ActionType.RELATION_DELETED, e, relation);
... ...
... ... @@ -163,7 +163,7 @@ public class EntityViewController extends BaseController {
163 163 entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
164 164
165 165 if (entityView.getId() != null) {
166   - sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(), EntityType.ENTITY_VIEW, EdgeEventActionType.UPDATED);
  166 + sendEntityNotificationMsg(savedEntityView.getTenantId(), savedEntityView.getId(), EdgeEventActionType.UPDATED);
167 167 }
168 168
169 169 return savedEntityView;
... ... @@ -368,7 +368,7 @@ public class EntityViewController extends BaseController {
368 368 logEntityAction(entityViewId, entityView, entityView.getCustomerId(),
369 369 ActionType.DELETED, null, strEntityViewId);
370 370
371   - sendDeleteNotificationMsgToEdgeService(getTenantId(), entityViewId, EntityType.ENTITY_VIEW, relatedEdgeIds);
  371 + sendDeleteNotificationMsg(getTenantId(), entityViewId, relatedEdgeIds);
372 372 } catch (Exception e) {
373 373 logEntityAction(emptyId(EntityType.ENTITY_VIEW),
374 374 null,
... ... @@ -410,7 +410,7 @@ public class EntityViewController extends BaseController {
410 410 savedEntityView.getCustomerId(),
411 411 ActionType.ASSIGNED_TO_CUSTOMER, null, strEntityViewId, strCustomerId, customer.getName());
412 412
413   - sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(),
  413 + sendEntityAssignToCustomerNotificationMsg(savedEntityView.getTenantId(), savedEntityView.getId(),
414 414 customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
415 415
416 416 return savedEntityView;
... ... @@ -439,7 +439,7 @@ public class EntityViewController extends BaseController {
439 439 entityView.getCustomerId(),
440 440 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strEntityViewId, customer.getId().toString(), customer.getName());
441 441
442   - sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(),
  442 + sendEntityAssignToCustomerNotificationMsg(savedEntityView.getTenantId(), savedEntityView.getId(),
443 443 customer.getId(), EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
444 444
445 445 return savedEntityView;
... ... @@ -633,7 +633,7 @@ public class EntityViewController extends BaseController {
633 633 savedEntityView.getCustomerId(),
634 634 ActionType.ASSIGNED_TO_EDGE, null, strEntityViewId, strEdgeId, edge.getName());
635 635
636   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EntityType.ENTITY_VIEW, EdgeEventActionType.ASSIGNED_TO_EDGE);
  636 + sendEntityAssignToEdgeNotificationMsg(getTenantId(), edgeId, savedEntityView.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
637 637
638 638 return savedEntityView;
639 639 } catch (Exception e) {
... ... @@ -663,7 +663,7 @@ public class EntityViewController extends BaseController {
663 663 entityView.getCustomerId(),
664 664 ActionType.UNASSIGNED_FROM_EDGE, null, strEntityViewId, strEdgeId, edge.getName());
665 665
666   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EntityType.ENTITY_VIEW, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
  666 + sendEntityAssignToEdgeNotificationMsg(getTenantId(), edgeId, savedEntityView.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
667 667
668 668 return savedEntityView;
669 669 } catch (Exception e) {
... ...
... ... @@ -152,7 +152,7 @@ public class RuleChainController extends BaseController {
152 152
153 153 if (RuleChainType.EDGE.equals(savedRuleChain.getType())) {
154 154 if (!created) {
155   - sendNotificationMsgToEdgeService(savedRuleChain.getTenantId(), savedRuleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.UPDATED);
  155 + sendEntityNotificationMsg(savedRuleChain.getTenantId(), savedRuleChain.getId(), EdgeEventActionType.UPDATED);
156 156 }
157 157 }
158 158
... ... @@ -254,8 +254,8 @@ public class RuleChainController extends BaseController {
254 254 ActionType.UPDATED, null, ruleChainMetaData);
255 255
256 256 if (RuleChainType.EDGE.equals(ruleChain.getType())) {
257   - sendNotificationMsgToEdgeService(ruleChain.getTenantId(),
258   - ruleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.UPDATED);
  257 + sendEntityNotificationMsg(ruleChain.getTenantId(),
  258 + ruleChain.getId(), EdgeEventActionType.UPDATED);
259 259 }
260 260
261 261 return savedRuleChainMetaData;
... ... @@ -325,7 +325,7 @@ public class RuleChainController extends BaseController {
325 325 ActionType.DELETED, null, strRuleChainId);
326 326
327 327 if (RuleChainType.EDGE.equals(ruleChain.getType())) {
328   - sendDeleteNotificationMsgToEdgeService(ruleChain.getTenantId(), ruleChain.getId(), EntityType.RULE_CHAIN, relatedEdgeIds);
  328 + sendDeleteNotificationMsg(ruleChain.getTenantId(), ruleChain.getId(), relatedEdgeIds);
329 329 }
330 330
331 331 } catch (Exception e) {
... ... @@ -487,7 +487,7 @@ public class RuleChainController extends BaseController {
487 487 null,
488 488 ActionType.ASSIGNED_TO_EDGE, null, strRuleChainId, strEdgeId, edge.getName());
489 489
490   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.ASSIGNED_TO_EDGE);
  490 + sendEntityAssignToEdgeNotificationMsg(getTenantId(), edgeId, savedRuleChain.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
491 491
492 492 return savedRuleChain;
493 493 } catch (Exception e) {
... ... @@ -519,7 +519,7 @@ public class RuleChainController extends BaseController {
519 519 null,
520 520 ActionType.UNASSIGNED_FROM_EDGE, null, strRuleChainId, strEdgeId, edge.getName());
521 521
522   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
  522 + sendEntityAssignToEdgeNotificationMsg(getTenantId(), edgeId, savedRuleChain.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
523 523
524 524 return savedRuleChain;
525 525 } catch (Exception e) {
... ...
... ... @@ -168,7 +168,7 @@ public class UserController extends BaseController {
168 168 savedUser.getCustomerId(),
169 169 user.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
170 170
171   - sendNotificationMsgToEdgeService(getTenantId(), savedUser.getId(), EntityType.USER,
  171 + sendEntityNotificationMsg(getTenantId(), savedUser.getId(),
172 172 user.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
173 173
174 174 return savedUser;
... ... @@ -249,7 +249,7 @@ public class UserController extends BaseController {
249 249 user.getCustomerId(),
250 250 ActionType.DELETED, null, strUserId);
251 251
252   - sendDeleteNotificationMsgToEdgeService(getTenantId(), userId, EntityType.USER, relatedEdgeIds);
  252 + sendDeleteNotificationMsg(getTenantId(), userId, relatedEdgeIds);
253 253
254 254 } catch (Exception e) {
255 255 logEntityAction(emptyId(EntityType.USER),
... ...
... ... @@ -73,7 +73,7 @@ public class WidgetTypeController extends BaseController {
73 73 checkEntity(widgetType.getId(), widgetType, Resource.WIDGET_TYPE);
74 74 WidgetType savedWidgetType = widgetTypeService.saveWidgetType(widgetType);
75 75
76   - sendNotificationMsgToEdgeService(getTenantId(), savedWidgetType.getId(), EntityType.WIDGET_TYPE,
  76 + sendEntityNotificationMsg(getTenantId(), savedWidgetType.getId(),
77 77 widgetType.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
78 78
79 79 return checkNotNull(savedWidgetType);
... ... @@ -92,7 +92,7 @@ public class WidgetTypeController extends BaseController {
92 92 checkWidgetTypeId(widgetTypeId, Operation.DELETE);
93 93 widgetTypeService.deleteWidgetType(getCurrentUser().getTenantId(), widgetTypeId);
94 94
95   - sendNotificationMsgToEdgeService(getTenantId(), widgetTypeId, EntityType.WIDGET_TYPE, EdgeEventActionType.DELETED);
  95 + sendEntityNotificationMsg(getTenantId(), widgetTypeId, EdgeEventActionType.DELETED);
96 96
97 97 } catch (Exception e) {
98 98 throw handleException(e);
... ...
... ... @@ -25,7 +25,6 @@ import org.springframework.web.bind.annotation.RequestParam;
25 25 import org.springframework.web.bind.annotation.ResponseBody;
26 26 import org.springframework.web.bind.annotation.ResponseStatus;
27 27 import org.springframework.web.bind.annotation.RestController;
28   -import org.thingsboard.server.common.data.EntityType;
29 28 import org.thingsboard.server.common.data.edge.EdgeEventActionType;
30 29 import org.thingsboard.server.common.data.exception.ThingsboardException;
31 30 import org.thingsboard.server.common.data.id.TenantId;
... ... @@ -72,7 +71,7 @@ public class WidgetsBundleController extends BaseController {
72 71 checkEntity(widgetsBundle.getId(), widgetsBundle, Resource.WIDGETS_BUNDLE);
73 72 WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
74 73
75   - sendNotificationMsgToEdgeService(getTenantId(), savedWidgetsBundle.getId(), EntityType.WIDGETS_BUNDLE,
  74 + sendEntityNotificationMsg(getTenantId(), savedWidgetsBundle.getId(),
76 75 widgetsBundle.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
77 76
78 77 return checkNotNull(savedWidgetsBundle);
... ... @@ -91,7 +90,7 @@ public class WidgetsBundleController extends BaseController {
91 90 checkWidgetsBundleId(widgetsBundleId, Operation.DELETE);
92 91 widgetsBundleService.deleteWidgetsBundle(getTenantId(), widgetsBundleId);
93 92
94   - sendNotificationMsgToEdgeService(getTenantId(), widgetsBundleId, EntityType.WIDGETS_BUNDLE, EdgeEventActionType.DELETED);
  93 + sendEntityNotificationMsg(getTenantId(), widgetsBundleId, EdgeEventActionType.DELETED);
95 94
96 95 } catch (Exception e) {
97 96 throw handleException(e);
... ...
... ... @@ -263,19 +263,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
263 263 case ADDED:
264 264 case UPDATED:
265 265 case DELETED:
266   - PageLink pageLink = new PageLink(DEFAULT_LIMIT);
267   - PageData<Edge> pageData;
268   - do {
269   - pageData = edgeService.findEdgesByTenantId(tenantId, pageLink);
270   - if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
271   - for (Edge edge : pageData.getData()) {
272   - saveEdgeEvent(tenantId, edge.getId(), type, actionType, entityId, null);
273   - }
274   - if (pageData.hasNext()) {
275   - pageLink = pageLink.nextPageLink();
276   - }
277   - }
278   - } while (pageData != null && pageData.hasNext());
  266 + processActionForAllEdges(tenantId, type, actionType, entityId);
279 267 break;
280 268 }
281 269 }
... ... @@ -495,6 +483,22 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
495 483 }, dbCallbackExecutorService);
496 484 }
497 485 }
  486 +
  487 + private void processActionForAllEdges(TenantId tenantId, EdgeEventType type, EdgeEventActionType actionType, EntityId entityId) {
  488 + PageLink pageLink = new PageLink(DEFAULT_LIMIT);
  489 + PageData<Edge> pageData;
  490 + do {
  491 + pageData = edgeService.findEdgesByTenantId(tenantId, pageLink);
  492 + if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
  493 + for (Edge edge : pageData.getData()) {
  494 + saveEdgeEvent(tenantId, edge.getId(), type, actionType, entityId, null);
  495 + }
  496 + if (pageData.hasNext()) {
  497 + pageLink = pageLink.nextPageLink();
  498 + }
  499 + }
  500 + } while (pageData != null && pageData.hasNext());
  501 + }
498 502 }
499 503
500 504
... ...
... ... @@ -1257,6 +1257,7 @@
1257 1257 "unassign-from-edge": "Unassign from edge",
1258 1258 "dashboards": "Edge Dashboards",
1259 1259 "manage-edge-rulechains": "Edge rule chains",
  1260 + "rulechain-template": "Rule chain template",
1260 1261 "edge-key": "Edge key",
1261 1262 "copy-edge-key": "Copy Edge key",
1262 1263 "edge-key-copied-message": "Edge key has been copied to clipboard",
... ...