Commit af8562c3a045003fadc772ab2b9edf6bae57c5af

Authored by Volodymyr Babak
1 parent b45bee78

Added support for device profile entity on edge

Showing 41 changed files with 299 additions and 89 deletions
... ... @@ -95,7 +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(),
  98 + sendNotificationMsgToEdgeService(getTenantId(), savedAlarm.getId(), EntityType.ALARM,
99 99 alarm.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
100 100
101 101 return savedAlarm;
... ... @@ -115,7 +115,7 @@ public class AlarmController extends BaseController {
115 115 AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
116 116 checkAlarmId(alarmId, Operation.WRITE);
117 117
118   - sendNotificationMsgToEdgeService(getTenantId(), alarmId, EdgeEventActionType.DELETED);
  118 + sendNotificationMsgToEdgeService(getTenantId(), alarmId, EntityType.ALARM, EdgeEventActionType.DELETED);
119 119
120 120 return alarmService.deleteAlarm(getTenantId(), alarmId);
121 121 } catch (Exception e) {
... ... @@ -137,7 +137,7 @@ public class AlarmController extends BaseController {
137 137 alarm.setStatus(alarm.getStatus().isCleared() ? AlarmStatus.CLEARED_ACK : AlarmStatus.ACTIVE_ACK);
138 138 logEntityAction(alarm.getOriginator(), alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_ACK, null);
139 139
140   - sendNotificationMsgToEdgeService(getTenantId(), alarmId, EdgeEventActionType.ALARM_ACK);
  140 + sendNotificationMsgToEdgeService(getTenantId(), alarmId, EntityType.ALARM, EdgeEventActionType.ALARM_ACK);
141 141 } catch (Exception e) {
142 142 throw handleException(e);
143 143 }
... ... @@ -157,7 +157,7 @@ public class AlarmController extends BaseController {
157 157 alarm.setStatus(alarm.getStatus().isAck() ? AlarmStatus.CLEARED_ACK : AlarmStatus.CLEARED_UNACK);
158 158 logEntityAction(alarm.getOriginator(), alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_CLEAR, null);
159 159
160   - sendNotificationMsgToEdgeService(getTenantId(), alarmId, EdgeEventActionType.ALARM_CLEAR);
  160 + sendNotificationMsgToEdgeService(getTenantId(), alarmId, EntityType.ALARM, EdgeEventActionType.ALARM_CLEAR);
161 161 } catch (Exception e) {
162 162 throw handleException(e);
163 163 }
... ...
... ... @@ -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(), EdgeEventActionType.UPDATED);
  116 + sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(), EntityType.ASSET, EdgeEventActionType.UPDATED);
117 117 }
118 118
119 119 return savedAsset;
... ... @@ -138,7 +138,7 @@ public class AssetController extends BaseController {
138 138 asset.getCustomerId(),
139 139 ActionType.DELETED, null, strAssetId);
140 140
141   - sendNotificationMsgToEdgeService(getTenantId(), assetId, EdgeEventActionType.DELETED);
  141 + sendNotificationMsgToEdgeService(getTenantId(), assetId, EntityType.ASSET, EdgeEventActionType.DELETED);
142 142 } catch (Exception e) {
143 143 logEntityAction(emptyId(EntityType.ASSET),
144 144 null,
... ... @@ -439,7 +439,7 @@ public class AssetController extends BaseController {
439 439 savedAsset.getCustomerId(),
440 440 ActionType.ASSIGNED_TO_EDGE, null, strAssetId, strEdgeId, edge.getName());
441 441
442   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
  442 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EntityType.ASSET, EdgeEventActionType.ASSIGNED_TO_EDGE);
443 443
444 444 return savedAsset;
445 445 } catch (Exception e) {
... ... @@ -472,7 +472,7 @@ public class AssetController extends BaseController {
472 472 asset.getCustomerId(),
473 473 ActionType.UNASSIGNED_FROM_EDGE, null, strAssetId, strEdgeId, edge.getName());
474 474
475   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
  475 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EntityType.ASSET, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
476 476
477 477 return savedAsset;
478 478 } catch (Exception e) {
... ...
... ... @@ -33,32 +33,30 @@ 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;
36 37 import org.thingsboard.server.common.data.User;
37 38 import org.thingsboard.server.common.data.audit.ActionType;
38 39 import org.thingsboard.server.common.data.edge.EdgeEventActionType;
39   -import org.thingsboard.server.common.data.edge.EdgeEventType;
40 40 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
41 41 import org.thingsboard.server.common.data.exception.ThingsboardException;
42 42 import org.thingsboard.server.common.data.id.TenantId;
43 43 import org.thingsboard.server.common.data.security.UserCredentials;
  44 +import org.thingsboard.server.common.data.security.model.SecuritySettings;
  45 +import org.thingsboard.server.common.data.security.model.UserPasswordPolicy;
44 46 import org.thingsboard.server.dao.audit.AuditLogService;
45 47 import org.thingsboard.server.queue.util.TbCoreComponent;
46 48 import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRepository;
47 49 import org.thingsboard.server.service.security.auth.rest.RestAuthenticationDetails;
48   -import org.thingsboard.server.common.data.security.model.SecuritySettings;
49 50 import org.thingsboard.server.service.security.model.SecurityUser;
50   -import org.thingsboard.server.common.data.security.model.UserPasswordPolicy;
51 51 import org.thingsboard.server.service.security.model.UserPrincipal;
52 52 import org.thingsboard.server.service.security.model.token.JwtToken;
53 53 import org.thingsboard.server.service.security.model.token.JwtTokenFactory;
54 54 import org.thingsboard.server.service.security.system.SystemSecurityService;
55   -import org.thingsboard.server.utils.MiscUtils;
56 55 import ua_parser.Client;
57 56
58 57 import javax.servlet.http.HttpServletRequest;
59 58 import java.net.URI;
60 59 import java.net.URISyntaxException;
61   -import java.util.List;
62 60
63 61 @RestController
64 62 @TbCoreComponent
... ... @@ -122,7 +120,7 @@ public class AuthController extends BaseController {
122 120 userCredentials.setPassword(passwordEncoder.encode(newPassword));
123 121 userService.replaceUserCredentials(securityUser.getTenantId(), userCredentials);
124 122
125   - sendNotificationMsgToEdgeService(getTenantId(), userCredentials.getUserId(), EdgeEventActionType.CREDENTIALS_UPDATED);
  123 + sendNotificationMsgToEdgeService(getTenantId(), userCredentials.getUserId(), EntityType.USER, EdgeEventActionType.CREDENTIALS_UPDATED);
126 124
127 125 } catch (Exception e) {
128 126 throw handleException(e);
... ... @@ -232,7 +230,7 @@ public class AuthController extends BaseController {
232 230 }
233 231 }
234 232
235   - sendNotificationMsgToEdgeService(user.getTenantId(), user.getId(), EdgeEventActionType.CREDENTIALS_UPDATED);
  233 + sendNotificationMsgToEdgeService(user.getTenantId(), user.getId(), EntityType.USER, EdgeEventActionType.CREDENTIALS_UPDATED);
236 234
237 235 JwtToken accessToken = tokenFactory.createAccessJwtToken(securityUser);
238 236 JwtToken refreshToken = refreshTokenRepository.requestRefreshToken(securityUser);
... ...
... ... @@ -922,15 +922,15 @@ public abstract class BaseController {
922 922 }
923 923 }
924 924
925   - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, EdgeEventActionType action) {
926   - sendNotificationMsgToEdgeService(tenantId, null, entityId, action);
  925 + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, EntityType entityType, EdgeEventActionType action) {
  926 + sendNotificationMsgToEdgeService(tenantId, null, entityId, entityType, action);
927 927 }
928 928
929   - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, EdgeEventActionType action) {
  929 + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, EntityType entityType, EdgeEventActionType action) {
930 930 if (!edgesRpcEnabled) {
931 931 return;
932 932 }
933   - EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType());
  933 + EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityType);
934 934 if (type != null) {
935 935 sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, null, type, action);
936 936 }
... ...
... ... @@ -110,7 +110,7 @@ public class CustomerController extends BaseController {
110 110 customer.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
111 111
112 112 if (customer.getId() != null) {
113   - sendNotificationMsgToEdgeService(savedCustomer.getTenantId(), savedCustomer.getId(), EdgeEventActionType.UPDATED);
  113 + sendNotificationMsgToEdgeService(savedCustomer.getTenantId(), savedCustomer.getId(), EntityType.CUSTOMER, EdgeEventActionType.UPDATED);
114 114 }
115 115
116 116 return savedCustomer;
... ... @@ -137,7 +137,7 @@ public class CustomerController extends BaseController {
137 137 customer.getId(),
138 138 ActionType.DELETED, null, strCustomerId);
139 139
140   - sendNotificationMsgToEdgeService(getTenantId(), customerId, EdgeEventActionType.DELETED);
  140 + sendNotificationMsgToEdgeService(getTenantId(), customerId, EntityType.CUSTOMER, EdgeEventActionType.DELETED);
141 141 } catch (Exception e) {
142 142
143 143 logEntityAction(emptyId(EntityType.CUSTOMER),
... ...
... ... @@ -116,7 +116,7 @@ public class DashboardController extends BaseController {
116 116 dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
117 117
118 118 if (dashboard.getId() != null) {
119   - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), EdgeEventActionType.UPDATED);
  119 + sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), EntityType.DASHBOARD, EdgeEventActionType.UPDATED);
120 120 }
121 121
122 122 return savedDashboard;
... ... @@ -142,7 +142,7 @@ public class DashboardController extends BaseController {
142 142 null,
143 143 ActionType.DELETED, null, strDashboardId);
144 144
145   - sendNotificationMsgToEdgeService(getTenantId(), dashboardId, EdgeEventActionType.DELETED);
  145 + sendNotificationMsgToEdgeService(getTenantId(), dashboardId, EntityType.DASHBOARD, EdgeEventActionType.DELETED);
146 146 } catch (Exception e) {
147 147
148 148 logEntityAction(emptyId(EntityType.DASHBOARD),
... ... @@ -506,7 +506,7 @@ public class DashboardController extends BaseController {
506 506 null,
507 507 ActionType.ASSIGNED_TO_EDGE, null, strDashboardId, strEdgeId, edge.getName());
508 508
509   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
  509 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EntityType.DASHBOARD, EdgeEventActionType.ASSIGNED_TO_EDGE);
510 510
511 511 return savedDashboard;
512 512 } catch (Exception e) {
... ... @@ -538,7 +538,7 @@ public class DashboardController extends BaseController {
538 538 null,
539 539 ActionType.UNASSIGNED_FROM_EDGE, null, strDashboardId, strEdgeId, edge.getName());
540 540
541   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
  541 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EntityType.DASHBOARD, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
542 542
543 543 return savedDashboard;
544 544 } 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(), EdgeEventActionType.UPDATED);
  135 + sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(), EntityType.DEVICE, EdgeEventActionType.UPDATED);
136 136 }
137 137
138 138 logEntityAction(savedDevice.getId(), savedDevice,
... ... @@ -169,7 +169,7 @@ public class DeviceController extends BaseController {
169 169 device.getCustomerId(),
170 170 ActionType.DELETED, null, strDeviceId);
171 171
172   - sendNotificationMsgToEdgeService(getTenantId(), deviceId, EdgeEventActionType.DELETED);
  172 + sendNotificationMsgToEdgeService(getTenantId(), deviceId, EntityType.DEVICE, EdgeEventActionType.DELETED);
173 173
174 174 deviceStateService.onDeviceDeleted(device);
175 175 } catch (Exception e) {
... ... @@ -300,7 +300,7 @@ public class DeviceController extends BaseController {
300 300
301 301 tbClusterService.pushMsgToCore(new DeviceCredentialsUpdateNotificationMsg(getCurrentUser().getTenantId(), deviceCredentials.getDeviceId()), null);
302 302
303   - sendNotificationMsgToEdgeService(getTenantId(), device.getId(), EdgeEventActionType.CREDENTIALS_UPDATED);
  303 + sendNotificationMsgToEdgeService(getTenantId(), device.getId(), EntityType.DEVICE, EdgeEventActionType.CREDENTIALS_UPDATED);
304 304
305 305 logEntityAction(device.getId(), device,
306 306 device.getCustomerId(),
... ... @@ -664,7 +664,7 @@ public class DeviceController extends BaseController {
664 664 savedDevice.getCustomerId(),
665 665 ActionType.ASSIGNED_TO_EDGE, null, strDeviceId, strEdgeId, edge.getName());
666 666
667   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
  667 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EntityType.DEVICE, EdgeEventActionType.ASSIGNED_TO_EDGE);
668 668
669 669 return savedDevice;
670 670 } catch (Exception e) {
... ... @@ -698,7 +698,7 @@ public class DeviceController extends BaseController {
698 698 device.getCustomerId(),
699 699 ActionType.UNASSIGNED_FROM_EDGE, null, strDeviceId, strEdgeId, edge.getName());
700 700
701   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
  701 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EntityType.DEVICE, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
702 702
703 703 return savedDevice;
704 704 } catch (Exception e) {
... ...
... ... @@ -30,6 +30,7 @@ import org.thingsboard.server.common.data.DeviceProfile;
30 30 import org.thingsboard.server.common.data.DeviceProfileInfo;
31 31 import org.thingsboard.server.common.data.EntityType;
32 32 import org.thingsboard.server.common.data.audit.ActionType;
  33 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
33 34 import org.thingsboard.server.common.data.exception.ThingsboardException;
34 35 import org.thingsboard.server.common.data.id.DeviceProfileId;
35 36 import org.thingsboard.server.common.data.page.PageData;
... ... @@ -102,6 +103,9 @@ public class DeviceProfileController extends BaseController {
102 103 null,
103 104 savedDeviceProfile.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
104 105
  106 + sendNotificationMsgToEdgeService(getTenantId(), deviceProfile.getId(), EntityType.DEVICE_PROFILE,
  107 + deviceProfile.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
  108 +
105 109 return savedDeviceProfile;
106 110 } catch (Exception e) {
107 111 logEntityAction(emptyId(EntityType.DEVICE_PROFILE), deviceProfile,
... ... @@ -127,6 +131,7 @@ public class DeviceProfileController extends BaseController {
127 131 null,
128 132 ActionType.DELETED, null, strDeviceProfileId);
129 133
  134 + sendNotificationMsgToEdgeService(getTenantId(), deviceProfile.getId(), EntityType.DEVICE_PROFILE, EdgeEventActionType.DELETED);
130 135 } catch (Exception e) {
131 136 logEntityAction(emptyId(EntityType.DEVICE_PROFILE),
132 137 null,
... ...
... ... @@ -162,7 +162,7 @@ public class EntityViewController extends BaseController {
162 162 entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
163 163
164 164 if (entityView.getId() != null) {
165   - sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(), EdgeEventActionType.UPDATED);
  165 + sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(), EntityType.ENTITY_VIEW, EdgeEventActionType.UPDATED);
166 166 }
167 167
168 168 return savedEntityView;
... ... @@ -364,7 +364,7 @@ public class EntityViewController extends BaseController {
364 364 logEntityAction(entityViewId, entityView, entityView.getCustomerId(),
365 365 ActionType.DELETED, null, strEntityViewId);
366 366
367   - sendNotificationMsgToEdgeService(getTenantId(), entityViewId, EdgeEventActionType.DELETED);
  367 + sendNotificationMsgToEdgeService(getTenantId(), entityViewId, EntityType.ENTITY_VIEW, EdgeEventActionType.DELETED);
368 368 } catch (Exception e) {
369 369 logEntityAction(emptyId(EntityType.ENTITY_VIEW),
370 370 null,
... ... @@ -629,7 +629,7 @@ public class EntityViewController extends BaseController {
629 629 savedEntityView.getCustomerId(),
630 630 ActionType.ASSIGNED_TO_EDGE, null, strEntityViewId, strEdgeId, edge.getName());
631 631
632   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
  632 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EntityType.ENTITY_VIEW, EdgeEventActionType.ASSIGNED_TO_EDGE);
633 633
634 634 return savedEntityView;
635 635 } catch (Exception e) {
... ... @@ -659,7 +659,7 @@ public class EntityViewController extends BaseController {
659 659 entityView.getCustomerId(),
660 660 ActionType.UNASSIGNED_FROM_EDGE, null, strEntityViewId, strEdgeId, edge.getName());
661 661
662   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
  662 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EntityType.ENTITY_VIEW, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
663 663
664 664 return savedEntityView;
665 665 } catch (Exception e) {
... ...
... ... @@ -153,7 +153,7 @@ public class RuleChainController extends BaseController {
153 153
154 154 if (RuleChainType.EDGE.equals(savedRuleChain.getType())) {
155 155 if (!created) {
156   - sendNotificationMsgToEdgeService(savedRuleChain.getTenantId(), savedRuleChain.getId(), EdgeEventActionType.UPDATED);
  156 + sendNotificationMsgToEdgeService(savedRuleChain.getTenantId(), savedRuleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.UPDATED);
157 157 }
158 158 }
159 159
... ... @@ -256,7 +256,7 @@ public class RuleChainController extends BaseController {
256 256
257 257 if (RuleChainType.EDGE.equals(ruleChain.getType())) {
258 258 sendNotificationMsgToEdgeService(ruleChain.getTenantId(),
259   - ruleChain.getId(), EdgeEventActionType.UPDATED);
  259 + ruleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.UPDATED);
260 260 }
261 261
262 262 return savedRuleChainMetaData;
... ... @@ -321,7 +321,7 @@ public class RuleChainController extends BaseController {
321 321 ActionType.DELETED, null, strRuleChainId);
322 322
323 323 if (RuleChainType.EDGE.equals(ruleChain.getType())) {
324   - sendNotificationMsgToEdgeService(ruleChain.getTenantId(), ruleChain.getId(), EdgeEventActionType.DELETED);
  324 + sendNotificationMsgToEdgeService(ruleChain.getTenantId(), ruleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.DELETED);
325 325 }
326 326
327 327 } catch (Exception e) {
... ... @@ -483,7 +483,7 @@ public class RuleChainController extends BaseController {
483 483 null,
484 484 ActionType.ASSIGNED_TO_EDGE, null, strRuleChainId, strEdgeId, edge.getName());
485 485
486   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
  486 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.ASSIGNED_TO_EDGE);
487 487
488 488 return savedRuleChain;
489 489 } catch (Exception e) {
... ... @@ -515,7 +515,7 @@ public class RuleChainController extends BaseController {
515 515 null,
516 516 ActionType.UNASSIGNED_FROM_EDGE, null, strRuleChainId, strEdgeId, edge.getName());
517 517
518   - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
  518 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
519 519
520 520 return savedRuleChain;
521 521 } catch (Exception e) {
... ...
... ... @@ -167,7 +167,7 @@ public class UserController extends BaseController {
167 167 savedUser.getCustomerId(),
168 168 user.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
169 169
170   - sendNotificationMsgToEdgeService(getTenantId(), savedUser.getId(),
  170 + sendNotificationMsgToEdgeService(getTenantId(), savedUser.getId(), EntityType.USER,
171 171 user.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
172 172
173 173 return savedUser;
... ... @@ -245,7 +245,7 @@ public class UserController extends BaseController {
245 245 user.getCustomerId(),
246 246 ActionType.DELETED, null, strUserId);
247 247
248   - sendNotificationMsgToEdgeService(getTenantId(), user.getId(), EdgeEventActionType.DELETED);
  248 + sendNotificationMsgToEdgeService(getTenantId(), user.getId(), EntityType.USER, EdgeEventActionType.DELETED);
249 249
250 250 } catch (Exception e) {
251 251 logEntityAction(emptyId(EntityType.USER),
... ...
... ... @@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.RequestParam;
26 26 import org.springframework.web.bind.annotation.ResponseBody;
27 27 import org.springframework.web.bind.annotation.ResponseStatus;
28 28 import org.springframework.web.bind.annotation.RestController;
29   -import org.thingsboard.server.common.data.audit.ActionType;
  29 +import org.thingsboard.server.common.data.EntityType;
30 30 import org.thingsboard.server.common.data.edge.EdgeEventActionType;
31 31 import org.thingsboard.server.common.data.exception.ThingsboardException;
32 32 import org.thingsboard.server.common.data.id.TenantId;
... ... @@ -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(),
  76 + sendNotificationMsgToEdgeService(getTenantId(), savedWidgetType.getId(), EntityType.WIDGET_TYPE,
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, EdgeEventActionType.DELETED);
  95 + sendNotificationMsgToEdgeService(getTenantId(), widgetTypeId, EntityType.WIDGET_TYPE, EdgeEventActionType.DELETED);
96 96
97 97 } catch (Exception e) {
98 98 throw handleException(e);
... ...
... ... @@ -25,7 +25,7 @@ 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.audit.ActionType;
  28 +import org.thingsboard.server.common.data.EntityType;
29 29 import org.thingsboard.server.common.data.edge.EdgeEventActionType;
30 30 import org.thingsboard.server.common.data.exception.ThingsboardException;
31 31 import org.thingsboard.server.common.data.id.TenantId;
... ... @@ -72,7 +72,7 @@ public class WidgetsBundleController extends BaseController {
72 72 checkEntity(widgetsBundle.getId(), widgetsBundle, Resource.WIDGETS_BUNDLE);
73 73 WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
74 74
75   - sendNotificationMsgToEdgeService(getTenantId(), savedWidgetsBundle.getId(),
  75 + sendNotificationMsgToEdgeService(getTenantId(), savedWidgetsBundle.getId(), EntityType.WIDGETS_BUNDLE,
76 76 widgetsBundle.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
77 77
78 78 return checkNotNull(savedWidgetsBundle);
... ... @@ -91,7 +91,7 @@ public class WidgetsBundleController extends BaseController {
91 91 checkWidgetsBundleId(widgetsBundleId, Operation.DELETE);
92 92 widgetsBundleService.deleteWidgetsBundle(getTenantId(), widgetsBundleId);
93 93
94   - sendNotificationMsgToEdgeService(getTenantId(), widgetsBundleId, EdgeEventActionType.DELETED);
  94 + sendNotificationMsgToEdgeService(getTenantId(), widgetsBundleId, EntityType.WIDGETS_BUNDLE, EdgeEventActionType.DELETED);
95 95
96 96 } catch (Exception e) {
97 97 throw handleException(e);
... ...
... ... @@ -170,6 +170,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
170 170 case USER:
171 171 case ASSET:
172 172 case DEVICE:
  173 + case DEVICE_PROFILE:
173 174 case ENTITY_VIEW:
174 175 case DASHBOARD:
175 176 case RULE_CHAIN:
... ...
... ... @@ -27,6 +27,7 @@ import org.thingsboard.server.dao.attributes.AttributesService;
27 27 import org.thingsboard.server.dao.customer.CustomerService;
28 28 import org.thingsboard.server.dao.dashboard.DashboardService;
29 29 import org.thingsboard.server.dao.device.DeviceCredentialsService;
  30 +import org.thingsboard.server.dao.device.DeviceProfileService;
30 31 import org.thingsboard.server.dao.device.DeviceService;
31 32 import org.thingsboard.server.dao.edge.EdgeService;
32 33 import org.thingsboard.server.dao.entityview.EntityViewService;
... ... @@ -44,6 +45,7 @@ import org.thingsboard.server.service.edge.rpc.constructor.AssetMsgConstructor;
44 45 import org.thingsboard.server.service.edge.rpc.constructor.CustomerMsgConstructor;
45 46 import org.thingsboard.server.service.edge.rpc.constructor.DashboardMsgConstructor;
46 47 import org.thingsboard.server.service.edge.rpc.constructor.DeviceMsgConstructor;
  48 +import org.thingsboard.server.service.edge.rpc.constructor.DeviceProfileMsgConstructor;
47 49 import org.thingsboard.server.service.edge.rpc.constructor.EntityDataMsgConstructor;
48 50 import org.thingsboard.server.service.edge.rpc.constructor.EntityViewMsgConstructor;
49 51 import org.thingsboard.server.service.edge.rpc.constructor.RelationMsgConstructor;
... ... @@ -86,6 +88,10 @@ public class EdgeContextComponent {
86 88
87 89 @Lazy
88 90 @Autowired
  91 + private DeviceProfileService deviceProfileService;
  92 +
  93 + @Lazy
  94 + @Autowired
89 95 private DeviceCredentialsService deviceCredentialsService;
90 96
91 97 @Lazy
... ... @@ -158,6 +164,10 @@ public class EdgeContextComponent {
158 164
159 165 @Lazy
160 166 @Autowired
  167 + private DeviceProfileMsgConstructor deviceProfileMsgConstructor;
  168 +
  169 + @Lazy
  170 + @Autowired
161 171 private AssetMsgConstructor assetMsgConstructor;
162 172
163 173 @Lazy
... ...
... ... @@ -33,6 +33,7 @@ import org.thingsboard.server.common.data.Customer;
33 33 import org.thingsboard.server.common.data.Dashboard;
34 34 import org.thingsboard.server.common.data.DataConstants;
35 35 import org.thingsboard.server.common.data.Device;
  36 +import org.thingsboard.server.common.data.DeviceProfile;
36 37 import org.thingsboard.server.common.data.EntityView;
37 38 import org.thingsboard.server.common.data.HasCustomerId;
38 39 import org.thingsboard.server.common.data.User;
... ... @@ -47,6 +48,7 @@ import org.thingsboard.server.common.data.id.AssetId;
47 48 import org.thingsboard.server.common.data.id.CustomerId;
48 49 import org.thingsboard.server.common.data.id.DashboardId;
49 50 import org.thingsboard.server.common.data.id.DeviceId;
  51 +import org.thingsboard.server.common.data.id.DeviceProfileId;
50 52 import org.thingsboard.server.common.data.id.EdgeId;
51 53 import org.thingsboard.server.common.data.id.EntityId;
52 54 import org.thingsboard.server.common.data.id.EntityViewId;
... ... @@ -81,6 +83,7 @@ import org.thingsboard.server.gen.edge.CustomerUpdateMsg;
81 83 import org.thingsboard.server.gen.edge.DashboardUpdateMsg;
82 84 import org.thingsboard.server.gen.edge.DeviceCredentialsRequestMsg;
83 85 import org.thingsboard.server.gen.edge.DeviceCredentialsUpdateMsg;
  86 +import org.thingsboard.server.gen.edge.DeviceProfileUpdateMsg;
84 87 import org.thingsboard.server.gen.edge.DeviceRpcCallMsg;
85 88 import org.thingsboard.server.gen.edge.DeviceUpdateMsg;
86 89 import org.thingsboard.server.gen.edge.DownlinkMsg;
... ... @@ -467,6 +470,8 @@ public final class EdgeGrpcSession implements Closeable {
467 470 switch (edgeEvent.getType()) {
468 471 case DEVICE:
469 472 return processDevice(edgeEvent, msgType, action);
  473 + case DEVICE_PROFILE:
  474 + return processDeviceProfile(edgeEvent, msgType, action);
470 475 case ASSET:
471 476 return processAsset(edgeEvent, msgType, action);
472 477 case ENTITY_VIEW:
... ... @@ -539,6 +544,39 @@ public final class EdgeGrpcSession implements Closeable {
539 544 return downlinkMsg;
540 545 }
541 546
  547 + private DownlinkMsg processDeviceProfile(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
  548 + DeviceProfileId deviceProfileId = new DeviceProfileId(edgeEvent.getEntityId());
  549 + DownlinkMsg downlinkMsg = null;
  550 + switch (action) {
  551 + case ADDED:
  552 + case UPDATED:
  553 + DeviceProfile deviceProfile = ctx.getDeviceProfileService().findDeviceProfileById(edgeEvent.getTenantId(), deviceProfileId);
  554 + if (deviceProfile != null) {
  555 +
  556 + // TODO: voba HACK
  557 +// PageData<RuleChain> ruleChainsByTenantIdAndEdgeId = ctx.getRuleChainService().findRuleChainsByTenantIdAndEdgeId(edgeEvent.getTenantId(), edgeEvent.getEdgeId(), new TimePageLink(100));
  558 +// RuleChain ruleChain = ruleChainsByTenantIdAndEdgeId.getData().get(0);
  559 +// deviceProfile.setDefaultRuleChainId(ruleChain.getId());
  560 +
  561 + DeviceProfileUpdateMsg deviceProfileUpdateMsg =
  562 + ctx.getDeviceProfileMsgConstructor().constructDeviceProfileUpdatedMsg(msgType, deviceProfile);
  563 + downlinkMsg = DownlinkMsg.newBuilder()
  564 + .addAllDeviceProfileUpdateMsg(Collections.singletonList(deviceProfileUpdateMsg))
  565 + .build();
  566 + }
  567 + break;
  568 + case DELETED:
  569 + DeviceProfileUpdateMsg deviceProfileUpdateMsg =
  570 + ctx.getDeviceProfileMsgConstructor().constructDeviceProfileDeleteMsg(deviceProfileId);
  571 + downlinkMsg = DownlinkMsg.newBuilder()
  572 + .addAllDeviceProfileUpdateMsg(Collections.singletonList(deviceProfileUpdateMsg))
  573 + .build();
  574 + break;
  575 + }
  576 + log.trace("[{}] device profile processed [{}]", this.sessionId, downlinkMsg);
  577 + return downlinkMsg;
  578 + }
  579 +
542 580 private DownlinkMsg processAsset(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
543 581 AssetId assetId = new AssetId(edgeEvent.getEntityId());
544 582 DownlinkMsg downlinkMsg = null;
... ...
... ... @@ -52,6 +52,10 @@ public class DeviceMsgConstructor {
52 52 builder.setCustomerIdMSB(customerId.getId().getMostSignificantBits());
53 53 builder.setCustomerIdLSB(customerId.getId().getLeastSignificantBits());
54 54 }
  55 + if (device.getDeviceProfileId() != null) {
  56 + builder.setDeviceProfileIdMSB(device.getDeviceProfileId().getId().getMostSignificantBits());
  57 + builder.setDeviceProfileIdLSB(device.getDeviceProfileId().getId().getLeastSignificantBits());
  58 + }
55 59 if (device.getAdditionalInfo() != null) {
56 60 builder.setAdditionalInfo(JacksonUtil.toString(device.getAdditionalInfo()));
57 61 }
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.service.edge.rpc.constructor;
  17 +
  18 +import com.google.protobuf.ByteString;
  19 +import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.stereotype.Component;
  21 +import org.thingsboard.server.common.data.DeviceProfile;
  22 +import org.thingsboard.server.common.data.id.DeviceProfileId;
  23 +import org.thingsboard.server.common.transport.util.DataDecodingEncodingService;
  24 +import org.thingsboard.server.gen.edge.DeviceProfileUpdateMsg;
  25 +import org.thingsboard.server.gen.edge.UpdateMsgType;
  26 +import org.thingsboard.server.queue.util.TbCoreComponent;
  27 +
  28 +@Component
  29 +@TbCoreComponent
  30 +public class DeviceProfileMsgConstructor {
  31 +
  32 + @Autowired
  33 + private DataDecodingEncodingService dataDecodingEncodingService;
  34 +
  35 + public DeviceProfileUpdateMsg constructDeviceProfileUpdatedMsg(UpdateMsgType msgType, DeviceProfile deviceProfile) {
  36 + DeviceProfileUpdateMsg.Builder builder = DeviceProfileUpdateMsg.newBuilder()
  37 + .setMsgType(msgType)
  38 + .setIdMSB(deviceProfile.getId().getId().getMostSignificantBits())
  39 + .setIdLSB(deviceProfile.getId().getId().getLeastSignificantBits())
  40 + .setName(deviceProfile.getName())
  41 + .setDescription(deviceProfile.getDescription())
  42 + .setDefault(deviceProfile.isDefault())
  43 + .setType(deviceProfile.getType().name())
  44 + .setTransportType(deviceProfile.getTransportType().name())
  45 + .setProvisionType(deviceProfile.getProvisionType().name())
  46 + .setProfileDataBytes(ByteString.copyFrom(dataDecodingEncodingService.encode(deviceProfile.getProfileData())));
  47 + if (deviceProfile.getDefaultRuleChainId() != null) {
  48 + builder.setDefaultRuleChainIdMSB(deviceProfile.getDefaultRuleChainId().getId().getMostSignificantBits())
  49 + .setDefaultRuleChainIdLSB(deviceProfile.getDefaultRuleChainId().getId().getLeastSignificantBits());
  50 + }
  51 + if (deviceProfile.getDefaultQueueName() != null) {
  52 + builder.setDefaultQueueName(deviceProfile.getDefaultQueueName());
  53 + }
  54 + if (deviceProfile.getProvisionDeviceKey() != null) {
  55 + builder.setProvisionDeviceKey(deviceProfile.getProvisionDeviceKey());
  56 + }
  57 + return builder.build();
  58 + }
  59 +
  60 + public DeviceProfileUpdateMsg constructDeviceProfileDeleteMsg(DeviceProfileId deviceProfileId) {
  61 + return DeviceProfileUpdateMsg.newBuilder()
  62 + .setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE)
  63 + .setIdMSB(deviceProfileId.getId().getMostSignificantBits())
  64 + .setIdLSB(deviceProfileId.getId().getLeastSignificantBits()).build();
  65 + }
  66 +
  67 +}
... ...
... ... @@ -33,8 +33,8 @@ import org.springframework.core.io.DefaultResourceLoader;
33 33 import org.springframework.stereotype.Service;
34 34 import org.thingsboard.server.common.data.AdminSettings;
35 35 import org.thingsboard.server.common.data.DashboardInfo;
36   -import org.thingsboard.server.common.data.DataConstants;
37 36 import org.thingsboard.server.common.data.Device;
  37 +import org.thingsboard.server.common.data.DeviceProfile;
38 38 import org.thingsboard.server.common.data.EdgeUtils;
39 39 import org.thingsboard.server.common.data.EntityType;
40 40 import org.thingsboard.server.common.data.EntityView;
... ... @@ -55,7 +55,6 @@ import org.thingsboard.server.common.data.id.UserId;
55 55 import org.thingsboard.server.common.data.kv.AttributeKvEntry;
56 56 import org.thingsboard.server.common.data.kv.DataType;
57 57 import org.thingsboard.server.common.data.page.PageData;
58   -import org.thingsboard.server.common.data.page.PageLink;
59 58 import org.thingsboard.server.common.data.page.TimePageLink;
60 59 import org.thingsboard.server.common.data.relation.EntityRelation;
61 60 import org.thingsboard.server.common.data.relation.EntityRelationsQuery;
... ... @@ -67,6 +66,7 @@ import org.thingsboard.server.common.data.widget.WidgetsBundle;
67 66 import org.thingsboard.server.dao.asset.AssetService;
68 67 import org.thingsboard.server.dao.attributes.AttributesService;
69 68 import org.thingsboard.server.dao.dashboard.DashboardService;
  69 +import org.thingsboard.server.dao.device.DeviceProfileService;
70 70 import org.thingsboard.server.dao.device.DeviceService;
71 71 import org.thingsboard.server.dao.edge.EdgeEventService;
72 72 import org.thingsboard.server.dao.entityview.EntityViewService;
... ... @@ -118,6 +118,9 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
118 118 private DeviceService deviceService;
119 119
120 120 @Autowired
  121 + private DeviceProfileService deviceProfileService;
  122 +
  123 + @Autowired
121 124 private AssetService assetService;
122 125
123 126 @Autowired
... ... @@ -152,6 +155,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
152 155 // TODO: voba - implement this functionality
153 156 // syncAdminSettings(edge);
154 157 syncRuleChains(edge);
  158 + syncDeviceProfiles(edge);
155 159 syncUsers(edge);
156 160 syncDevices(edge);
157 161 syncAssets(edge);
... ... @@ -206,6 +210,28 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
206 210 }
207 211 }
208 212
  213 + private void syncDeviceProfiles(Edge edge) {
  214 + log.trace("[{}] syncDeviceProfiles [{}]", edge.getTenantId(), edge.getName());
  215 + try {
  216 + TimePageLink pageLink = new TimePageLink(DEFAULT_LIMIT);
  217 + PageData<DeviceProfile> pageData;
  218 + do {
  219 + pageData = deviceProfileService.findDeviceProfiles(edge.getTenantId(), pageLink);
  220 + if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
  221 + log.trace("[{}] [{}] user(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size());
  222 + for (DeviceProfile deviceProfile : pageData.getData()) {
  223 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.DEVICE_PROFILE, EdgeEventActionType.ADDED, deviceProfile.getId(), null);
  224 + }
  225 + if (pageData.hasNext()) {
  226 + pageLink = pageLink.nextPageLink();
  227 + }
  228 + }
  229 + } while (pageData != null && pageData.hasNext());
  230 + } catch (Exception e) {
  231 + log.error("Exception during loading device profile(s) on sync!", e);
  232 + }
  233 + }
  234 +
209 235 private void syncAssets(Edge edge) {
210 236 log.trace("[{}] syncAssets [{}]", edge.getTenantId(), edge.getName());
211 237 try {
... ...
... ... @@ -34,6 +34,7 @@ import org.thingsboard.server.common.data.edge.EdgeEventActionType;
34 34 import org.thingsboard.server.common.data.edge.EdgeEventType;
35 35 import org.thingsboard.server.common.data.id.CustomerId;
36 36 import org.thingsboard.server.common.data.id.DeviceId;
  37 +import org.thingsboard.server.common.data.id.DeviceProfileId;
37 38 import org.thingsboard.server.common.data.id.EdgeId;
38 39 import org.thingsboard.server.common.data.id.EntityId;
39 40 import org.thingsboard.server.common.data.id.TenantId;
... ... @@ -164,6 +165,11 @@ public class DeviceProcessor extends BaseProcessor {
164 165 device.setType(deviceUpdateMsg.getType());
165 166 device.setLabel(deviceUpdateMsg.getLabel());
166 167 device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo()));
  168 + if (deviceUpdateMsg.getDeviceProfileIdMSB() != 0 && deviceUpdateMsg.getDeviceProfileIdLSB() != 0) {
  169 + DeviceProfileId deviceProfileId = new DeviceProfileId(
  170 + new UUID(deviceUpdateMsg.getDeviceProfileIdMSB(), deviceUpdateMsg.getDeviceProfileIdLSB()));
  171 + device.setDeviceProfileId(deviceProfileId);
  172 + }
167 173 deviceService.saveDevice(device);
168 174 saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.CREDENTIALS_REQUEST, deviceId, null);
169 175 } else {
... ... @@ -183,6 +189,11 @@ public class DeviceProcessor extends BaseProcessor {
183 189 device.setType(deviceUpdateMsg.getType());
184 190 device.setLabel(deviceUpdateMsg.getLabel());
185 191 device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo()));
  192 + if (deviceUpdateMsg.getDeviceProfileIdMSB() != 0 && deviceUpdateMsg.getDeviceProfileIdLSB() != 0) {
  193 + DeviceProfileId deviceProfileId = new DeviceProfileId(
  194 + new UUID(deviceUpdateMsg.getDeviceProfileIdMSB(), deviceUpdateMsg.getDeviceProfileIdLSB()));
  195 + device.setDeviceProfileId(deviceProfileId);
  196 + }
186 197 device = deviceService.saveDevice(device);
187 198 createRelationFromEdge(tenantId, edge.getId(), device.getId());
188 199 deviceStateService.onDeviceAdded(device);
... ...
... ... @@ -180,7 +180,6 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
180 180 testAttributes();
181 181 testSendMessagesToCloud();
182 182 testRpcCall();
183   - // TODO: voba - test conflict messages in case device with current name already exist or ID is already used
184 183 }
185 184
186 185 private Device findDeviceByName(String deviceName) throws Exception {
... ...
... ... @@ -30,6 +30,8 @@ public final class EdgeUtils {
30 30 return EdgeEventType.EDGE;
31 31 case DEVICE:
32 32 return EdgeEventType.DEVICE;
  33 + case DEVICE_PROFILE:
  34 + return EdgeEventType.DEVICE_PROFILE;
33 35 case ASSET:
34 36 return EdgeEventType.ASSET;
35 37 case ENTITY_VIEW:
... ...
... ... @@ -19,12 +19,12 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
19 19 import lombok.Data;
20 20 import org.thingsboard.server.common.data.query.KeyFilter;
21 21
  22 +import java.io.Serializable;
22 23 import java.util.List;
23   -import java.util.concurrent.TimeUnit;
24 24
25 25 @Data
26 26 @JsonIgnoreProperties(ignoreUnknown = true)
27   -public class AlarmCondition {
  27 +public class AlarmCondition implements Serializable {
28 28
29 29 private List<KeyFilter> condition;
30 30 private AlarmConditionSpec spec;
... ...
... ... @@ -20,6 +20,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
20 20 import com.fasterxml.jackson.annotation.JsonSubTypes;
21 21 import com.fasterxml.jackson.annotation.JsonTypeInfo;
22 22
  23 +import java.io.Serializable;
  24 +
23 25 @JsonIgnoreProperties(ignoreUnknown = true)
24 26 @JsonTypeInfo(
25 27 use = JsonTypeInfo.Id.NAME,
... ... @@ -29,7 +31,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
29 31 @JsonSubTypes.Type(value = SimpleAlarmConditionSpec.class, name = "SIMPLE"),
30 32 @JsonSubTypes.Type(value = DurationAlarmConditionSpec.class, name = "DURATION"),
31 33 @JsonSubTypes.Type(value = RepeatingAlarmConditionSpec.class, name = "REPEATING")})
32   -public interface AlarmConditionSpec {
  34 +public interface AlarmConditionSpec extends Serializable {
33 35
34 36 @JsonIgnore
35 37 AlarmConditionSpecType getType();
... ...
... ... @@ -17,8 +17,10 @@ package org.thingsboard.server.common.data.device.profile;
17 17
18 18 import lombok.Data;
19 19
  20 +import java.io.Serializable;
  21 +
20 22 @Data
21   -public class AlarmRule {
  23 +public class AlarmRule implements Serializable {
22 24
23 25 private AlarmCondition condition;
24 26 private AlarmSchedule schedule;
... ...
... ... @@ -19,6 +19,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
19 19 import com.fasterxml.jackson.annotation.JsonSubTypes;
20 20 import com.fasterxml.jackson.annotation.JsonTypeInfo;
21 21
  22 +import java.io.Serializable;
  23 +
22 24 @JsonIgnoreProperties(ignoreUnknown = true)
23 25 @JsonTypeInfo(
24 26 use = JsonTypeInfo.Id.NAME,
... ... @@ -28,7 +30,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
28 30 @JsonSubTypes.Type(value = AnyTimeSchedule.class, name = "ANY_TIME"),
29 31 @JsonSubTypes.Type(value = SpecificTimeSchedule.class, name = "SPECIFIC_TIME"),
30 32 @JsonSubTypes.Type(value = CustomTimeSchedule.class, name = "CUSTOM")})
31   -public interface AlarmSchedule {
  33 +public interface AlarmSchedule extends Serializable {
32 34
33 35 AlarmScheduleType getType();
34 36
... ...
... ... @@ -17,10 +17,10 @@ package org.thingsboard.server.common.data.device.profile;
17 17
18 18 import lombok.Data;
19 19
20   -import java.util.List;
  20 +import java.io.Serializable;
21 21
22 22 @Data
23   -public class CustomTimeScheduleItem {
  23 +public class CustomTimeScheduleItem implements Serializable {
24 24
25 25 private boolean enabled;
26 26 private int dayOfWeek;
... ...
... ... @@ -18,11 +18,12 @@ package org.thingsboard.server.common.data.device.profile;
18 18 import lombok.Data;
19 19 import org.thingsboard.server.common.data.alarm.AlarmSeverity;
20 20
  21 +import java.io.Serializable;
21 22 import java.util.List;
22 23 import java.util.TreeMap;
23 24
24 25 @Data
25   -public class DeviceProfileAlarm {
  26 +public class DeviceProfileAlarm implements Serializable {
26 27
27 28 private String id;
28 29 private String alarmType;
... ...
... ... @@ -21,6 +21,8 @@ import com.fasterxml.jackson.annotation.JsonSubTypes;
21 21 import com.fasterxml.jackson.annotation.JsonTypeInfo;
22 22 import org.thingsboard.server.common.data.DeviceProfileType;
23 23
  24 +import java.io.Serializable;
  25 +
24 26 @JsonIgnoreProperties(ignoreUnknown = true)
25 27 @JsonTypeInfo(
26 28 use = JsonTypeInfo.Id.NAME,
... ... @@ -28,7 +30,7 @@ import org.thingsboard.server.common.data.DeviceProfileType;
28 30 property = "type")
29 31 @JsonSubTypes({
30 32 @JsonSubTypes.Type(value = DefaultDeviceProfileConfiguration.class, name = "DEFAULT")})
31   -public interface DeviceProfileConfiguration {
  33 +public interface DeviceProfileConfiguration extends Serializable {
32 34
33 35 @JsonIgnore
34 36 DeviceProfileType getType();
... ...
... ... @@ -17,10 +17,11 @@ package org.thingsboard.server.common.data.device.profile;
17 17
18 18 import lombok.Data;
19 19
  20 +import java.io.Serializable;
20 21 import java.util.List;
21 22
22 23 @Data
23   -public class DeviceProfileData {
  24 +public class DeviceProfileData implements Serializable {
24 25
25 26 private DeviceProfileConfiguration configuration;
26 27 private DeviceProfileTransportConfiguration transportConfiguration;
... ...
... ... @@ -21,6 +21,8 @@ import com.fasterxml.jackson.annotation.JsonSubTypes;
21 21 import com.fasterxml.jackson.annotation.JsonTypeInfo;
22 22 import org.thingsboard.server.common.data.DeviceProfileProvisionType;
23 23
  24 +import java.io.Serializable;
  25 +
24 26
25 27 @JsonIgnoreProperties(ignoreUnknown = true)
26 28 @JsonTypeInfo(
... ... @@ -31,7 +33,7 @@ import org.thingsboard.server.common.data.DeviceProfileProvisionType;
31 33 @JsonSubTypes.Type(value = DisabledDeviceProfileProvisionConfiguration.class, name = "DISABLED"),
32 34 @JsonSubTypes.Type(value = AllowCreateNewDevicesDeviceProfileProvisionConfiguration.class, name = "ALLOW_CREATE_NEW_DEVICES"),
33 35 @JsonSubTypes.Type(value = CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration.class, name = "CHECK_PRE_PROVISIONED_DEVICES")})
34   -public interface DeviceProfileProvisionConfiguration {
  36 +public interface DeviceProfileProvisionConfiguration extends Serializable {
35 37
36 38 String getProvisionDeviceSecret();
37 39
... ...
... ... @@ -19,9 +19,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
19 19 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
20 20 import com.fasterxml.jackson.annotation.JsonSubTypes;
21 21 import com.fasterxml.jackson.annotation.JsonTypeInfo;
22   -import org.thingsboard.server.common.data.DeviceProfileType;
23 22 import org.thingsboard.server.common.data.DeviceTransportType;
24 23
  24 +import java.io.Serializable;
  25 +
25 26 @JsonIgnoreProperties(ignoreUnknown = true)
26 27 @JsonTypeInfo(
27 28 use = JsonTypeInfo.Id.NAME,
... ... @@ -31,7 +32,7 @@ import org.thingsboard.server.common.data.DeviceTransportType;
31 32 @JsonSubTypes.Type(value = DefaultDeviceProfileTransportConfiguration.class, name = "DEFAULT"),
32 33 @JsonSubTypes.Type(value = MqttDeviceProfileTransportConfiguration.class, name = "MQTT"),
33 34 @JsonSubTypes.Type(value = Lwm2mDeviceProfileTransportConfiguration.class, name = "LWM2M")})
34   -public interface DeviceProfileTransportConfiguration {
  35 +public interface DeviceProfileTransportConfiguration extends Serializable {
35 36
36 37 @JsonIgnore
37 38 DeviceTransportType getType();
... ...
... ... @@ -19,6 +19,7 @@ public enum EdgeEventType {
19 19 DASHBOARD,
20 20 ASSET,
21 21 DEVICE,
  22 + DEVICE_PROFILE,
22 23 ENTITY_VIEW,
23 24 ALARM,
24 25 RULE_CHAIN,
... ...
... ... @@ -85,6 +85,8 @@ public class EntityIdFactory {
85 85 return new DashboardId(uuid);
86 86 case DEVICE:
87 87 return new DeviceId(uuid);
  88 + case DEVICE_PROFILE:
  89 + return new DeviceProfileId(uuid);
88 90 case ASSET:
89 91 return new AssetId(uuid);
90 92 case ALARM:
... ...
... ... @@ -19,8 +19,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
19 19 import lombok.Data;
20 20 import lombok.Getter;
21 21
  22 +import java.io.Serializable;
  23 +
22 24 @Data
23   -public class DynamicValue<T> {
  25 +public class DynamicValue<T> implements Serializable {
24 26
25 27 @JsonIgnore
26 28 private T resolvedValue;
... ...
... ... @@ -17,8 +17,10 @@ package org.thingsboard.server.common.data.query;
17 17
18 18 import lombok.Data;
19 19
  20 +import java.io.Serializable;
  21 +
20 22 @Data
21   -public class EntityKey {
  23 +public class EntityKey implements Serializable {
22 24 private final EntityKeyType type;
23 25 private final String key;
24 26 }
... ...
... ... @@ -21,8 +21,10 @@ import com.fasterxml.jackson.annotation.JsonProperty;
21 21 import lombok.Data;
22 22 import lombok.Getter;
23 23
  24 +import java.io.Serializable;
  25 +
24 26 @Data
25   -public class FilterPredicateValue<T> {
  27 +public class FilterPredicateValue<T> implements Serializable {
26 28
27 29 @Getter
28 30 private final T defaultValue;
... ...
... ... @@ -17,8 +17,10 @@ package org.thingsboard.server.common.data.query;
17 17
18 18 import lombok.Data;
19 19
  20 +import java.io.Serializable;
  21 +
20 22 @Data
21   -public class KeyFilter {
  23 +public class KeyFilter implements Serializable {
22 24
23 25 private EntityKey key;
24 26 private EntityKeyValueType valueType;
... ...
... ... @@ -19,6 +19,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
19 19 import com.fasterxml.jackson.annotation.JsonSubTypes;
20 20 import com.fasterxml.jackson.annotation.JsonTypeInfo;
21 21
  22 +import java.io.Serializable;
  23 +
22 24 @JsonTypeInfo(
23 25 use = JsonTypeInfo.Id.NAME,
24 26 include = JsonTypeInfo.As.PROPERTY,
... ... @@ -28,7 +30,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
28 30 @JsonSubTypes.Type(value = NumericFilterPredicate.class, name = "NUMERIC"),
29 31 @JsonSubTypes.Type(value = BooleanFilterPredicate.class, name = "BOOLEAN"),
30 32 @JsonSubTypes.Type(value = ComplexFilterPredicate.class, name = "COMPLEX")})
31   -public interface KeyFilterPredicate {
  33 +public interface KeyFilterPredicate extends Serializable {
32 34
33 35 @JsonIgnore
34 36 FilterPredicateType getType();
... ...
... ... @@ -178,11 +178,30 @@ message DeviceUpdateMsg {
178 178 int64 idLSB = 3;
179 179 int64 customerIdMSB = 4;
180 180 int64 customerIdLSB = 5;
181   - string name = 6;
  181 + int64 deviceProfileIdMSB = 6;
  182 + int64 deviceProfileIdLSB = 7;
  183 + string name = 8;
  184 + string type = 9;
  185 + string label = 10;
  186 + string additionalInfo = 11;
  187 + string conflictName = 12;
  188 +}
  189 +
  190 +message DeviceProfileUpdateMsg {
  191 + UpdateMsgType msgType = 1;
  192 + int64 idMSB = 2;
  193 + int64 idLSB = 3;
  194 + string name = 4;
  195 + string description = 5;
  196 + bool default = 6;
182 197 string type = 7;
183   - string label = 8;
184   - string additionalInfo = 9;
185   - string conflictName = 10;
  198 + string transportType = 8;
  199 + string provisionType = 9;
  200 + int64 defaultRuleChainIdMSB = 10;
  201 + int64 defaultRuleChainIdLSB = 11;
  202 + string defaultQueueName = 12;
  203 + bytes profileDataBytes = 13;
  204 + string provisionDeviceKey = 14;
186 205 }
187 206
188 207 message DeviceCredentialsUpdateMsg {
... ... @@ -400,20 +419,21 @@ message DownlinkMsg {
400 419 repeated EntityDataProto entityData = 2;
401 420 repeated DeviceCredentialsRequestMsg deviceCredentialsRequestMsg = 3;
402 421 repeated DeviceUpdateMsg deviceUpdateMsg = 4;
403   - repeated DeviceCredentialsUpdateMsg deviceCredentialsUpdateMsg = 5;
404   - repeated RuleChainUpdateMsg ruleChainUpdateMsg = 6;
405   - repeated RuleChainMetadataUpdateMsg ruleChainMetadataUpdateMsg = 7;
406   - repeated DashboardUpdateMsg dashboardUpdateMsg = 8;
407   - repeated AssetUpdateMsg assetUpdateMsg = 9;
408   - repeated EntityViewUpdateMsg entityViewUpdateMsg = 10;
409   - repeated AlarmUpdateMsg alarmUpdateMsg = 11;
410   - repeated UserUpdateMsg userUpdateMsg = 12;
411   - repeated UserCredentialsUpdateMsg userCredentialsUpdateMsg = 13;
412   - repeated CustomerUpdateMsg customerUpdateMsg = 14;
413   - repeated RelationUpdateMsg relationUpdateMsg = 15;
414   - repeated WidgetsBundleUpdateMsg widgetsBundleUpdateMsg = 16;
415   - repeated WidgetTypeUpdateMsg widgetTypeUpdateMsg = 17;
416   - repeated AdminSettingsUpdateMsg adminSettingsUpdateMsg = 18;
417   - repeated DeviceRpcCallMsg deviceRpcCallMsg = 19;
  422 + repeated DeviceProfileUpdateMsg deviceProfileUpdateMsg = 5;
  423 + repeated DeviceCredentialsUpdateMsg deviceCredentialsUpdateMsg = 6;
  424 + repeated RuleChainUpdateMsg ruleChainUpdateMsg = 7;
  425 + repeated RuleChainMetadataUpdateMsg ruleChainMetadataUpdateMsg = 8;
  426 + repeated DashboardUpdateMsg dashboardUpdateMsg = 9;
  427 + repeated AssetUpdateMsg assetUpdateMsg = 10;
  428 + repeated EntityViewUpdateMsg entityViewUpdateMsg = 11;
  429 + repeated AlarmUpdateMsg alarmUpdateMsg = 12;
  430 + repeated UserUpdateMsg userUpdateMsg = 13;
  431 + repeated UserCredentialsUpdateMsg userCredentialsUpdateMsg = 14;
  432 + repeated CustomerUpdateMsg customerUpdateMsg = 15;
  433 + repeated RelationUpdateMsg relationUpdateMsg = 16;
  434 + repeated WidgetsBundleUpdateMsg widgetsBundleUpdateMsg = 17;
  435 + repeated WidgetTypeUpdateMsg widgetTypeUpdateMsg = 18;
  436 + repeated AdminSettingsUpdateMsg adminSettingsUpdateMsg = 19;
  437 + repeated DeviceRpcCallMsg deviceRpcCallMsg = 20;
418 438 }
419 439
... ...
... ... @@ -472,12 +472,15 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
472 472 @Override
473 473 public ListenableFuture<List<EdgeId>> findRelatedEdgeIdsByEntityId(TenantId tenantId, EntityId entityId) {
474 474 log.trace("[{}] Executing findRelatedEdgeIdsByEntityId [{}]", tenantId, entityId);
475   - if (EntityType.TENANT.equals(entityId.getEntityType()) || EntityType.CUSTOMER.equals(entityId.getEntityType())) {
  475 + if (EntityType.TENANT.equals(entityId.getEntityType()) ||
  476 + EntityType.CUSTOMER.equals(entityId.getEntityType()) ||
  477 + EntityType.DEVICE_PROFILE.equals(entityId.getEntityType())) {
476 478 List<EdgeId> result = new ArrayList<>();
477 479 PageLink pageLink = new PageLink(DEFAULT_LIMIT);
478 480 PageData<Edge> pageData;
479 481 do {
480   - if (EntityType.TENANT.equals(entityId.getEntityType())) {
  482 + if (EntityType.TENANT.equals(entityId.getEntityType()) ||
  483 + EntityType.DEVICE_PROFILE.equals(entityId.getEntityType())) {
481 484 pageData = findEdgesByTenantId(tenantId, pageLink);
482 485 } else {
483 486 pageData = findEdgesByTenantIdAndCustomerId(tenantId, new CustomerId(entityId.getId()), pageLink);
... ...