Commit 24f2ea502c54f96aa098b63941fdecb90ae2a22f

Authored by Volodymyr Babak
1 parent 2f85f703

Push credentials updates to edge

... ... @@ -565,6 +565,7 @@ public abstract class BaseController {
565 565 }
566 566 if (e == null) {
567 567 pushEntityActionToRuleEngine(entityId, entity, user, customerId, actionType, additionalInfo);
  568 + // TODO: voba - refactor to push events to edge queue directly, instead of the rule engine flow
568 569 }
569 570 auditLogService.logEntityAction(user.getTenantId(), customerId, user.getId(), user.getName(), entityId, entity, actionType, e, additionalInfo);
570 571 }
... ... @@ -611,6 +612,10 @@ public abstract class BaseController {
611 612 case UNASSIGNED_FROM_EDGE:
612 613 msgType = DataConstants.ENTITY_UNASSIGNED_FROM_EDGE;
613 614 break;
  615 + case CREDENTIALS_UPDATED:
  616 + //TODO: voba - this is not efficient way to do this. Refactor on later stages
  617 + msgType = DataConstants.ENTITY_UPDATED;
  618 + break;
614 619 }
615 620 if (!StringUtils.isEmpty(msgType)) {
616 621 try {
... ...
... ... @@ -16,8 +16,11 @@
16 16 package org.thingsboard.server.service.edge.rpc.constructor;
17 17
18 18 import lombok.extern.slf4j.Slf4j;
  19 +import org.springframework.beans.factory.annotation.Autowired;
19 20 import org.springframework.stereotype.Component;
20 21 import org.thingsboard.server.common.data.Device;
  22 +import org.thingsboard.server.common.data.security.DeviceCredentials;
  23 +import org.thingsboard.server.dao.device.DeviceCredentialsService;
21 24 import org.thingsboard.server.gen.edge.DeviceUpdateMsg;
22 25 import org.thingsboard.server.gen.edge.UpdateMsgType;
23 26
... ... @@ -25,11 +28,21 @@ import org.thingsboard.server.gen.edge.UpdateMsgType;
25 28 @Slf4j
26 29 public class DeviceUpdateMsgConstructor {
27 30
  31 + @Autowired
  32 + private DeviceCredentialsService deviceCredentialsService;
  33 +
28 34 public DeviceUpdateMsg constructDeviceUpdatedMsg(UpdateMsgType msgType, Device device) {
  35 + DeviceCredentials deviceCredentials
  36 + = deviceCredentialsService.findDeviceCredentialsByDeviceId(device.getTenantId(), device.getId());
29 37 DeviceUpdateMsg.Builder builder = DeviceUpdateMsg.newBuilder()
30 38 .setMsgType(msgType)
31 39 .setName(device.getName())
32   - .setType(device.getType());
  40 + .setType(device.getType())
  41 + .setCredentialsType(deviceCredentials.getCredentialsType().name())
  42 + .setCredentialsId(deviceCredentials.getCredentialsId());
  43 + if (deviceCredentials.getCredentialsValue() != null) {
  44 + builder.setCredentialsValue(deviceCredentials.getCredentialsValue());
  45 + }
33 46 return builder.build();
34 47 }
35 48 }
... ...
... ... @@ -15,12 +15,10 @@
15 15 */
16 16 package org.thingsboard.server.dao.edge;
17 17
18   -import com.fasterxml.jackson.core.JsonProcessingException;
19 18 import com.google.common.util.concurrent.FutureCallback;
20 19 import com.google.common.util.concurrent.ListenableFuture;
21 20 import org.thingsboard.server.common.data.EntitySubtype;
22 21 import org.thingsboard.server.common.data.Event;
23   -import org.thingsboard.server.common.data.Tenant;
24 22 import org.thingsboard.server.common.data.edge.Edge;
25 23 import org.thingsboard.server.common.data.edge.EdgeSearchQuery;
26 24 import org.thingsboard.server.common.data.id.CustomerId;
... ...
... ... @@ -160,6 +160,9 @@ message DeviceUpdateMsg {
160 160 UpdateMsgType msgType = 1;
161 161 string name = 2;
162 162 string type = 3;
  163 + string credentialsType = 4;
  164 + string credentialsId = 5;
  165 + string credentialsValue = 6;
163 166 }
164 167
165 168 message AssetUpdateMsg {
... ...