Added support for device profile entity on edge
This commit is contained in:
parent
b45bee7843
commit
af8562c3a0
@ -95,7 +95,7 @@ public class AlarmController extends BaseController {
|
||||
getCurrentUser().getCustomerId(),
|
||||
alarm.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), savedAlarm.getId(),
|
||||
sendNotificationMsgToEdgeService(getTenantId(), savedAlarm.getId(), EntityType.ALARM,
|
||||
alarm.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
|
||||
|
||||
return savedAlarm;
|
||||
@ -115,7 +115,7 @@ public class AlarmController extends BaseController {
|
||||
AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
|
||||
checkAlarmId(alarmId, Operation.WRITE);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), alarmId, EdgeEventActionType.DELETED);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), alarmId, EntityType.ALARM, EdgeEventActionType.DELETED);
|
||||
|
||||
return alarmService.deleteAlarm(getTenantId(), alarmId);
|
||||
} catch (Exception e) {
|
||||
@ -137,7 +137,7 @@ public class AlarmController extends BaseController {
|
||||
alarm.setStatus(alarm.getStatus().isCleared() ? AlarmStatus.CLEARED_ACK : AlarmStatus.ACTIVE_ACK);
|
||||
logEntityAction(alarm.getOriginator(), alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_ACK, null);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), alarmId, EdgeEventActionType.ALARM_ACK);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), alarmId, EntityType.ALARM, EdgeEventActionType.ALARM_ACK);
|
||||
} catch (Exception e) {
|
||||
throw handleException(e);
|
||||
}
|
||||
@ -157,7 +157,7 @@ public class AlarmController extends BaseController {
|
||||
alarm.setStatus(alarm.getStatus().isAck() ? AlarmStatus.CLEARED_ACK : AlarmStatus.CLEARED_UNACK);
|
||||
logEntityAction(alarm.getOriginator(), alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_CLEAR, null);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), alarmId, EdgeEventActionType.ALARM_CLEAR);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), alarmId, EntityType.ALARM, EdgeEventActionType.ALARM_CLEAR);
|
||||
} catch (Exception e) {
|
||||
throw handleException(e);
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ public class AssetController extends BaseController {
|
||||
asset.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
|
||||
|
||||
if (asset.getId() != null) {
|
||||
sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(), EdgeEventActionType.UPDATED);
|
||||
sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(), EntityType.ASSET, EdgeEventActionType.UPDATED);
|
||||
}
|
||||
|
||||
return savedAsset;
|
||||
@ -138,7 +138,7 @@ public class AssetController extends BaseController {
|
||||
asset.getCustomerId(),
|
||||
ActionType.DELETED, null, strAssetId);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), assetId, EdgeEventActionType.DELETED);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), assetId, EntityType.ASSET, EdgeEventActionType.DELETED);
|
||||
} catch (Exception e) {
|
||||
logEntityAction(emptyId(EntityType.ASSET),
|
||||
null,
|
||||
@ -439,7 +439,7 @@ public class AssetController extends BaseController {
|
||||
savedAsset.getCustomerId(),
|
||||
ActionType.ASSIGNED_TO_EDGE, null, strAssetId, strEdgeId, edge.getName());
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EntityType.ASSET, EdgeEventActionType.ASSIGNED_TO_EDGE);
|
||||
|
||||
return savedAsset;
|
||||
} catch (Exception e) {
|
||||
@ -472,7 +472,7 @@ public class AssetController extends BaseController {
|
||||
asset.getCustomerId(),
|
||||
ActionType.UNASSIGNED_FROM_EDGE, null, strAssetId, strEdgeId, edge.getName());
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EntityType.ASSET, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
|
||||
|
||||
return savedAsset;
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -33,32 +33,30 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.thingsboard.rule.engine.api.MailService;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.User;
|
||||
import org.thingsboard.server.common.data.audit.ActionType;
|
||||
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
|
||||
import org.thingsboard.server.common.data.edge.EdgeEventType;
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.security.UserCredentials;
|
||||
import org.thingsboard.server.common.data.security.model.SecuritySettings;
|
||||
import org.thingsboard.server.common.data.security.model.UserPasswordPolicy;
|
||||
import org.thingsboard.server.dao.audit.AuditLogService;
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||
import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRepository;
|
||||
import org.thingsboard.server.service.security.auth.rest.RestAuthenticationDetails;
|
||||
import org.thingsboard.server.common.data.security.model.SecuritySettings;
|
||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||
import org.thingsboard.server.common.data.security.model.UserPasswordPolicy;
|
||||
import org.thingsboard.server.service.security.model.UserPrincipal;
|
||||
import org.thingsboard.server.service.security.model.token.JwtToken;
|
||||
import org.thingsboard.server.service.security.model.token.JwtTokenFactory;
|
||||
import org.thingsboard.server.service.security.system.SystemSecurityService;
|
||||
import org.thingsboard.server.utils.MiscUtils;
|
||||
import ua_parser.Client;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@TbCoreComponent
|
||||
@ -122,7 +120,7 @@ public class AuthController extends BaseController {
|
||||
userCredentials.setPassword(passwordEncoder.encode(newPassword));
|
||||
userService.replaceUserCredentials(securityUser.getTenantId(), userCredentials);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), userCredentials.getUserId(), EdgeEventActionType.CREDENTIALS_UPDATED);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), userCredentials.getUserId(), EntityType.USER, EdgeEventActionType.CREDENTIALS_UPDATED);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw handleException(e);
|
||||
@ -232,7 +230,7 @@ public class AuthController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
sendNotificationMsgToEdgeService(user.getTenantId(), user.getId(), EdgeEventActionType.CREDENTIALS_UPDATED);
|
||||
sendNotificationMsgToEdgeService(user.getTenantId(), user.getId(), EntityType.USER, EdgeEventActionType.CREDENTIALS_UPDATED);
|
||||
|
||||
JwtToken accessToken = tokenFactory.createAccessJwtToken(securityUser);
|
||||
JwtToken refreshToken = refreshTokenRepository.requestRefreshToken(securityUser);
|
||||
|
||||
@ -922,15 +922,15 @@ public abstract class BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, EdgeEventActionType action) {
|
||||
sendNotificationMsgToEdgeService(tenantId, null, entityId, action);
|
||||
protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, EntityType entityType, EdgeEventActionType action) {
|
||||
sendNotificationMsgToEdgeService(tenantId, null, entityId, entityType, action);
|
||||
}
|
||||
|
||||
protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, EdgeEventActionType action) {
|
||||
protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, EntityType entityType, EdgeEventActionType action) {
|
||||
if (!edgesRpcEnabled) {
|
||||
return;
|
||||
}
|
||||
EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType());
|
||||
EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityType);
|
||||
if (type != null) {
|
||||
sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, null, type, action);
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ public class CustomerController extends BaseController {
|
||||
customer.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
|
||||
|
||||
if (customer.getId() != null) {
|
||||
sendNotificationMsgToEdgeService(savedCustomer.getTenantId(), savedCustomer.getId(), EdgeEventActionType.UPDATED);
|
||||
sendNotificationMsgToEdgeService(savedCustomer.getTenantId(), savedCustomer.getId(), EntityType.CUSTOMER, EdgeEventActionType.UPDATED);
|
||||
}
|
||||
|
||||
return savedCustomer;
|
||||
@ -137,7 +137,7 @@ public class CustomerController extends BaseController {
|
||||
customer.getId(),
|
||||
ActionType.DELETED, null, strCustomerId);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), customerId, EdgeEventActionType.DELETED);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), customerId, EntityType.CUSTOMER, EdgeEventActionType.DELETED);
|
||||
} catch (Exception e) {
|
||||
|
||||
logEntityAction(emptyId(EntityType.CUSTOMER),
|
||||
|
||||
@ -116,7 +116,7 @@ public class DashboardController extends BaseController {
|
||||
dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
|
||||
|
||||
if (dashboard.getId() != null) {
|
||||
sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), EdgeEventActionType.UPDATED);
|
||||
sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), EntityType.DASHBOARD, EdgeEventActionType.UPDATED);
|
||||
}
|
||||
|
||||
return savedDashboard;
|
||||
@ -142,7 +142,7 @@ public class DashboardController extends BaseController {
|
||||
null,
|
||||
ActionType.DELETED, null, strDashboardId);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), dashboardId, EdgeEventActionType.DELETED);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), dashboardId, EntityType.DASHBOARD, EdgeEventActionType.DELETED);
|
||||
} catch (Exception e) {
|
||||
|
||||
logEntityAction(emptyId(EntityType.DASHBOARD),
|
||||
@ -506,7 +506,7 @@ public class DashboardController extends BaseController {
|
||||
null,
|
||||
ActionType.ASSIGNED_TO_EDGE, null, strDashboardId, strEdgeId, edge.getName());
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EntityType.DASHBOARD, EdgeEventActionType.ASSIGNED_TO_EDGE);
|
||||
|
||||
return savedDashboard;
|
||||
} catch (Exception e) {
|
||||
@ -538,7 +538,7 @@ public class DashboardController extends BaseController {
|
||||
null,
|
||||
ActionType.UNASSIGNED_FROM_EDGE, null, strDashboardId, strEdgeId, edge.getName());
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EntityType.DASHBOARD, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
|
||||
|
||||
return savedDashboard;
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -132,7 +132,7 @@ public class DeviceController extends BaseController {
|
||||
device.getId() == null ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
|
||||
|
||||
if (device.getId() != null) {
|
||||
sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(), EdgeEventActionType.UPDATED);
|
||||
sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(), EntityType.DEVICE, EdgeEventActionType.UPDATED);
|
||||
}
|
||||
|
||||
logEntityAction(savedDevice.getId(), savedDevice,
|
||||
@ -169,7 +169,7 @@ public class DeviceController extends BaseController {
|
||||
device.getCustomerId(),
|
||||
ActionType.DELETED, null, strDeviceId);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), deviceId, EdgeEventActionType.DELETED);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), deviceId, EntityType.DEVICE, EdgeEventActionType.DELETED);
|
||||
|
||||
deviceStateService.onDeviceDeleted(device);
|
||||
} catch (Exception e) {
|
||||
@ -300,7 +300,7 @@ public class DeviceController extends BaseController {
|
||||
|
||||
tbClusterService.pushMsgToCore(new DeviceCredentialsUpdateNotificationMsg(getCurrentUser().getTenantId(), deviceCredentials.getDeviceId()), null);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), device.getId(), EdgeEventActionType.CREDENTIALS_UPDATED);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), device.getId(), EntityType.DEVICE, EdgeEventActionType.CREDENTIALS_UPDATED);
|
||||
|
||||
logEntityAction(device.getId(), device,
|
||||
device.getCustomerId(),
|
||||
@ -664,7 +664,7 @@ public class DeviceController extends BaseController {
|
||||
savedDevice.getCustomerId(),
|
||||
ActionType.ASSIGNED_TO_EDGE, null, strDeviceId, strEdgeId, edge.getName());
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EntityType.DEVICE, EdgeEventActionType.ASSIGNED_TO_EDGE);
|
||||
|
||||
return savedDevice;
|
||||
} catch (Exception e) {
|
||||
@ -698,7 +698,7 @@ public class DeviceController extends BaseController {
|
||||
device.getCustomerId(),
|
||||
ActionType.UNASSIGNED_FROM_EDGE, null, strDeviceId, strEdgeId, edge.getName());
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EntityType.DEVICE, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
|
||||
|
||||
return savedDevice;
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -30,6 +30,7 @@ import org.thingsboard.server.common.data.DeviceProfile;
|
||||
import org.thingsboard.server.common.data.DeviceProfileInfo;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.audit.ActionType;
|
||||
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
@ -102,6 +103,9 @@ public class DeviceProfileController extends BaseController {
|
||||
null,
|
||||
savedDeviceProfile.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), deviceProfile.getId(), EntityType.DEVICE_PROFILE,
|
||||
deviceProfile.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
|
||||
|
||||
return savedDeviceProfile;
|
||||
} catch (Exception e) {
|
||||
logEntityAction(emptyId(EntityType.DEVICE_PROFILE), deviceProfile,
|
||||
@ -127,6 +131,7 @@ public class DeviceProfileController extends BaseController {
|
||||
null,
|
||||
ActionType.DELETED, null, strDeviceProfileId);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), deviceProfile.getId(), EntityType.DEVICE_PROFILE, EdgeEventActionType.DELETED);
|
||||
} catch (Exception e) {
|
||||
logEntityAction(emptyId(EntityType.DEVICE_PROFILE),
|
||||
null,
|
||||
|
||||
@ -162,7 +162,7 @@ public class EntityViewController extends BaseController {
|
||||
entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
|
||||
|
||||
if (entityView.getId() != null) {
|
||||
sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(), EdgeEventActionType.UPDATED);
|
||||
sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(), EntityType.ENTITY_VIEW, EdgeEventActionType.UPDATED);
|
||||
}
|
||||
|
||||
return savedEntityView;
|
||||
@ -364,7 +364,7 @@ public class EntityViewController extends BaseController {
|
||||
logEntityAction(entityViewId, entityView, entityView.getCustomerId(),
|
||||
ActionType.DELETED, null, strEntityViewId);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), entityViewId, EdgeEventActionType.DELETED);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), entityViewId, EntityType.ENTITY_VIEW, EdgeEventActionType.DELETED);
|
||||
} catch (Exception e) {
|
||||
logEntityAction(emptyId(EntityType.ENTITY_VIEW),
|
||||
null,
|
||||
@ -629,7 +629,7 @@ public class EntityViewController extends BaseController {
|
||||
savedEntityView.getCustomerId(),
|
||||
ActionType.ASSIGNED_TO_EDGE, null, strEntityViewId, strEdgeId, edge.getName());
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EntityType.ENTITY_VIEW, EdgeEventActionType.ASSIGNED_TO_EDGE);
|
||||
|
||||
return savedEntityView;
|
||||
} catch (Exception e) {
|
||||
@ -659,7 +659,7 @@ public class EntityViewController extends BaseController {
|
||||
entityView.getCustomerId(),
|
||||
ActionType.UNASSIGNED_FROM_EDGE, null, strEntityViewId, strEdgeId, edge.getName());
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EntityType.ENTITY_VIEW, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
|
||||
|
||||
return savedEntityView;
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -153,7 +153,7 @@ public class RuleChainController extends BaseController {
|
||||
|
||||
if (RuleChainType.EDGE.equals(savedRuleChain.getType())) {
|
||||
if (!created) {
|
||||
sendNotificationMsgToEdgeService(savedRuleChain.getTenantId(), savedRuleChain.getId(), EdgeEventActionType.UPDATED);
|
||||
sendNotificationMsgToEdgeService(savedRuleChain.getTenantId(), savedRuleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.UPDATED);
|
||||
}
|
||||
}
|
||||
|
||||
@ -256,7 +256,7 @@ public class RuleChainController extends BaseController {
|
||||
|
||||
if (RuleChainType.EDGE.equals(ruleChain.getType())) {
|
||||
sendNotificationMsgToEdgeService(ruleChain.getTenantId(),
|
||||
ruleChain.getId(), EdgeEventActionType.UPDATED);
|
||||
ruleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.UPDATED);
|
||||
}
|
||||
|
||||
return savedRuleChainMetaData;
|
||||
@ -321,7 +321,7 @@ public class RuleChainController extends BaseController {
|
||||
ActionType.DELETED, null, strRuleChainId);
|
||||
|
||||
if (RuleChainType.EDGE.equals(ruleChain.getType())) {
|
||||
sendNotificationMsgToEdgeService(ruleChain.getTenantId(), ruleChain.getId(), EdgeEventActionType.DELETED);
|
||||
sendNotificationMsgToEdgeService(ruleChain.getTenantId(), ruleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.DELETED);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
@ -483,7 +483,7 @@ public class RuleChainController extends BaseController {
|
||||
null,
|
||||
ActionType.ASSIGNED_TO_EDGE, null, strRuleChainId, strEdgeId, edge.getName());
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.ASSIGNED_TO_EDGE);
|
||||
|
||||
return savedRuleChain;
|
||||
} catch (Exception e) {
|
||||
@ -515,7 +515,7 @@ public class RuleChainController extends BaseController {
|
||||
null,
|
||||
ActionType.UNASSIGNED_FROM_EDGE, null, strRuleChainId, strEdgeId, edge.getName());
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
|
||||
|
||||
return savedRuleChain;
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -167,7 +167,7 @@ public class UserController extends BaseController {
|
||||
savedUser.getCustomerId(),
|
||||
user.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), savedUser.getId(),
|
||||
sendNotificationMsgToEdgeService(getTenantId(), savedUser.getId(), EntityType.USER,
|
||||
user.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
|
||||
|
||||
return savedUser;
|
||||
@ -245,7 +245,7 @@ public class UserController extends BaseController {
|
||||
user.getCustomerId(),
|
||||
ActionType.DELETED, null, strUserId);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), user.getId(), EdgeEventActionType.DELETED);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), user.getId(), EntityType.USER, EdgeEventActionType.DELETED);
|
||||
|
||||
} catch (Exception e) {
|
||||
logEntityAction(emptyId(EntityType.USER),
|
||||
|
||||
@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.thingsboard.server.common.data.audit.ActionType;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
@ -73,7 +73,7 @@ public class WidgetTypeController extends BaseController {
|
||||
checkEntity(widgetType.getId(), widgetType, Resource.WIDGET_TYPE);
|
||||
WidgetType savedWidgetType = widgetTypeService.saveWidgetType(widgetType);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), savedWidgetType.getId(),
|
||||
sendNotificationMsgToEdgeService(getTenantId(), savedWidgetType.getId(), EntityType.WIDGET_TYPE,
|
||||
widgetType.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
|
||||
|
||||
return checkNotNull(savedWidgetType);
|
||||
@ -92,7 +92,7 @@ public class WidgetTypeController extends BaseController {
|
||||
checkWidgetTypeId(widgetTypeId, Operation.DELETE);
|
||||
widgetTypeService.deleteWidgetType(getCurrentUser().getTenantId(), widgetTypeId);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), widgetTypeId, EdgeEventActionType.DELETED);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), widgetTypeId, EntityType.WIDGET_TYPE, EdgeEventActionType.DELETED);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw handleException(e);
|
||||
|
||||
@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.thingsboard.server.common.data.audit.ActionType;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
@ -72,7 +72,7 @@ public class WidgetsBundleController extends BaseController {
|
||||
checkEntity(widgetsBundle.getId(), widgetsBundle, Resource.WIDGETS_BUNDLE);
|
||||
WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), savedWidgetsBundle.getId(),
|
||||
sendNotificationMsgToEdgeService(getTenantId(), savedWidgetsBundle.getId(), EntityType.WIDGETS_BUNDLE,
|
||||
widgetsBundle.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
|
||||
|
||||
return checkNotNull(savedWidgetsBundle);
|
||||
@ -91,7 +91,7 @@ public class WidgetsBundleController extends BaseController {
|
||||
checkWidgetsBundleId(widgetsBundleId, Operation.DELETE);
|
||||
widgetsBundleService.deleteWidgetsBundle(getTenantId(), widgetsBundleId);
|
||||
|
||||
sendNotificationMsgToEdgeService(getTenantId(), widgetsBundleId, EdgeEventActionType.DELETED);
|
||||
sendNotificationMsgToEdgeService(getTenantId(), widgetsBundleId, EntityType.WIDGETS_BUNDLE, EdgeEventActionType.DELETED);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw handleException(e);
|
||||
|
||||
@ -170,6 +170,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
|
||||
case USER:
|
||||
case ASSET:
|
||||
case DEVICE:
|
||||
case DEVICE_PROFILE:
|
||||
case ENTITY_VIEW:
|
||||
case DASHBOARD:
|
||||
case RULE_CHAIN:
|
||||
|
||||
@ -27,6 +27,7 @@ import org.thingsboard.server.dao.attributes.AttributesService;
|
||||
import org.thingsboard.server.dao.customer.CustomerService;
|
||||
import org.thingsboard.server.dao.dashboard.DashboardService;
|
||||
import org.thingsboard.server.dao.device.DeviceCredentialsService;
|
||||
import org.thingsboard.server.dao.device.DeviceProfileService;
|
||||
import org.thingsboard.server.dao.device.DeviceService;
|
||||
import org.thingsboard.server.dao.edge.EdgeService;
|
||||
import org.thingsboard.server.dao.entityview.EntityViewService;
|
||||
@ -44,6 +45,7 @@ import org.thingsboard.server.service.edge.rpc.constructor.AssetMsgConstructor;
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.CustomerMsgConstructor;
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.DashboardMsgConstructor;
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.DeviceMsgConstructor;
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.DeviceProfileMsgConstructor;
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.EntityDataMsgConstructor;
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.EntityViewMsgConstructor;
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.RelationMsgConstructor;
|
||||
@ -84,6 +86,10 @@ public class EdgeContextComponent {
|
||||
@Autowired
|
||||
private DeviceService deviceService;
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private DeviceProfileService deviceProfileService;
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private DeviceCredentialsService deviceCredentialsService;
|
||||
@ -156,6 +162,10 @@ public class EdgeContextComponent {
|
||||
@Autowired
|
||||
private DeviceMsgConstructor deviceMsgConstructor;
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private DeviceProfileMsgConstructor deviceProfileMsgConstructor;
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private AssetMsgConstructor assetMsgConstructor;
|
||||
|
||||
@ -33,6 +33,7 @@ import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.Dashboard;
|
||||
import org.thingsboard.server.common.data.DataConstants;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.DeviceProfile;
|
||||
import org.thingsboard.server.common.data.EntityView;
|
||||
import org.thingsboard.server.common.data.HasCustomerId;
|
||||
import org.thingsboard.server.common.data.User;
|
||||
@ -47,6 +48,7 @@ import org.thingsboard.server.common.data.id.AssetId;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.DashboardId;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||
import org.thingsboard.server.common.data.id.EdgeId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.EntityViewId;
|
||||
@ -81,6 +83,7 @@ import org.thingsboard.server.gen.edge.CustomerUpdateMsg;
|
||||
import org.thingsboard.server.gen.edge.DashboardUpdateMsg;
|
||||
import org.thingsboard.server.gen.edge.DeviceCredentialsRequestMsg;
|
||||
import org.thingsboard.server.gen.edge.DeviceCredentialsUpdateMsg;
|
||||
import org.thingsboard.server.gen.edge.DeviceProfileUpdateMsg;
|
||||
import org.thingsboard.server.gen.edge.DeviceRpcCallMsg;
|
||||
import org.thingsboard.server.gen.edge.DeviceUpdateMsg;
|
||||
import org.thingsboard.server.gen.edge.DownlinkMsg;
|
||||
@ -467,6 +470,8 @@ public final class EdgeGrpcSession implements Closeable {
|
||||
switch (edgeEvent.getType()) {
|
||||
case DEVICE:
|
||||
return processDevice(edgeEvent, msgType, action);
|
||||
case DEVICE_PROFILE:
|
||||
return processDeviceProfile(edgeEvent, msgType, action);
|
||||
case ASSET:
|
||||
return processAsset(edgeEvent, msgType, action);
|
||||
case ENTITY_VIEW:
|
||||
@ -539,6 +544,39 @@ public final class EdgeGrpcSession implements Closeable {
|
||||
return downlinkMsg;
|
||||
}
|
||||
|
||||
private DownlinkMsg processDeviceProfile(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
|
||||
DeviceProfileId deviceProfileId = new DeviceProfileId(edgeEvent.getEntityId());
|
||||
DownlinkMsg downlinkMsg = null;
|
||||
switch (action) {
|
||||
case ADDED:
|
||||
case UPDATED:
|
||||
DeviceProfile deviceProfile = ctx.getDeviceProfileService().findDeviceProfileById(edgeEvent.getTenantId(), deviceProfileId);
|
||||
if (deviceProfile != null) {
|
||||
|
||||
// TODO: voba HACK
|
||||
// PageData<RuleChain> ruleChainsByTenantIdAndEdgeId = ctx.getRuleChainService().findRuleChainsByTenantIdAndEdgeId(edgeEvent.getTenantId(), edgeEvent.getEdgeId(), new TimePageLink(100));
|
||||
// RuleChain ruleChain = ruleChainsByTenantIdAndEdgeId.getData().get(0);
|
||||
// deviceProfile.setDefaultRuleChainId(ruleChain.getId());
|
||||
|
||||
DeviceProfileUpdateMsg deviceProfileUpdateMsg =
|
||||
ctx.getDeviceProfileMsgConstructor().constructDeviceProfileUpdatedMsg(msgType, deviceProfile);
|
||||
downlinkMsg = DownlinkMsg.newBuilder()
|
||||
.addAllDeviceProfileUpdateMsg(Collections.singletonList(deviceProfileUpdateMsg))
|
||||
.build();
|
||||
}
|
||||
break;
|
||||
case DELETED:
|
||||
DeviceProfileUpdateMsg deviceProfileUpdateMsg =
|
||||
ctx.getDeviceProfileMsgConstructor().constructDeviceProfileDeleteMsg(deviceProfileId);
|
||||
downlinkMsg = DownlinkMsg.newBuilder()
|
||||
.addAllDeviceProfileUpdateMsg(Collections.singletonList(deviceProfileUpdateMsg))
|
||||
.build();
|
||||
break;
|
||||
}
|
||||
log.trace("[{}] device profile processed [{}]", this.sessionId, downlinkMsg);
|
||||
return downlinkMsg;
|
||||
}
|
||||
|
||||
private DownlinkMsg processAsset(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
|
||||
AssetId assetId = new AssetId(edgeEvent.getEntityId());
|
||||
DownlinkMsg downlinkMsg = null;
|
||||
|
||||
@ -52,6 +52,10 @@ public class DeviceMsgConstructor {
|
||||
builder.setCustomerIdMSB(customerId.getId().getMostSignificantBits());
|
||||
builder.setCustomerIdLSB(customerId.getId().getLeastSignificantBits());
|
||||
}
|
||||
if (device.getDeviceProfileId() != null) {
|
||||
builder.setDeviceProfileIdMSB(device.getDeviceProfileId().getId().getMostSignificantBits());
|
||||
builder.setDeviceProfileIdLSB(device.getDeviceProfileId().getId().getLeastSignificantBits());
|
||||
}
|
||||
if (device.getAdditionalInfo() != null) {
|
||||
builder.setAdditionalInfo(JacksonUtil.toString(device.getAdditionalInfo()));
|
||||
}
|
||||
|
||||
@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Copyright © 2016-2020 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.service.edge.rpc.constructor;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.thingsboard.server.common.data.DeviceProfile;
|
||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||
import org.thingsboard.server.common.transport.util.DataDecodingEncodingService;
|
||||
import org.thingsboard.server.gen.edge.DeviceProfileUpdateMsg;
|
||||
import org.thingsboard.server.gen.edge.UpdateMsgType;
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||
|
||||
@Component
|
||||
@TbCoreComponent
|
||||
public class DeviceProfileMsgConstructor {
|
||||
|
||||
@Autowired
|
||||
private DataDecodingEncodingService dataDecodingEncodingService;
|
||||
|
||||
public DeviceProfileUpdateMsg constructDeviceProfileUpdatedMsg(UpdateMsgType msgType, DeviceProfile deviceProfile) {
|
||||
DeviceProfileUpdateMsg.Builder builder = DeviceProfileUpdateMsg.newBuilder()
|
||||
.setMsgType(msgType)
|
||||
.setIdMSB(deviceProfile.getId().getId().getMostSignificantBits())
|
||||
.setIdLSB(deviceProfile.getId().getId().getLeastSignificantBits())
|
||||
.setName(deviceProfile.getName())
|
||||
.setDescription(deviceProfile.getDescription())
|
||||
.setDefault(deviceProfile.isDefault())
|
||||
.setType(deviceProfile.getType().name())
|
||||
.setTransportType(deviceProfile.getTransportType().name())
|
||||
.setProvisionType(deviceProfile.getProvisionType().name())
|
||||
.setProfileDataBytes(ByteString.copyFrom(dataDecodingEncodingService.encode(deviceProfile.getProfileData())));
|
||||
if (deviceProfile.getDefaultRuleChainId() != null) {
|
||||
builder.setDefaultRuleChainIdMSB(deviceProfile.getDefaultRuleChainId().getId().getMostSignificantBits())
|
||||
.setDefaultRuleChainIdLSB(deviceProfile.getDefaultRuleChainId().getId().getLeastSignificantBits());
|
||||
}
|
||||
if (deviceProfile.getDefaultQueueName() != null) {
|
||||
builder.setDefaultQueueName(deviceProfile.getDefaultQueueName());
|
||||
}
|
||||
if (deviceProfile.getProvisionDeviceKey() != null) {
|
||||
builder.setProvisionDeviceKey(deviceProfile.getProvisionDeviceKey());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public DeviceProfileUpdateMsg constructDeviceProfileDeleteMsg(DeviceProfileId deviceProfileId) {
|
||||
return DeviceProfileUpdateMsg.newBuilder()
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE)
|
||||
.setIdMSB(deviceProfileId.getId().getMostSignificantBits())
|
||||
.setIdLSB(deviceProfileId.getId().getLeastSignificantBits()).build();
|
||||
}
|
||||
|
||||
}
|
||||
@ -33,8 +33,8 @@ import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.server.common.data.AdminSettings;
|
||||
import org.thingsboard.server.common.data.DashboardInfo;
|
||||
import org.thingsboard.server.common.data.DataConstants;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.DeviceProfile;
|
||||
import org.thingsboard.server.common.data.EdgeUtils;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.EntityView;
|
||||
@ -55,7 +55,6 @@ import org.thingsboard.server.common.data.id.UserId;
|
||||
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
|
||||
import org.thingsboard.server.common.data.kv.DataType;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.common.data.page.TimePageLink;
|
||||
import org.thingsboard.server.common.data.relation.EntityRelation;
|
||||
import org.thingsboard.server.common.data.relation.EntityRelationsQuery;
|
||||
@ -67,6 +66,7 @@ import org.thingsboard.server.common.data.widget.WidgetsBundle;
|
||||
import org.thingsboard.server.dao.asset.AssetService;
|
||||
import org.thingsboard.server.dao.attributes.AttributesService;
|
||||
import org.thingsboard.server.dao.dashboard.DashboardService;
|
||||
import org.thingsboard.server.dao.device.DeviceProfileService;
|
||||
import org.thingsboard.server.dao.device.DeviceService;
|
||||
import org.thingsboard.server.dao.edge.EdgeEventService;
|
||||
import org.thingsboard.server.dao.entityview.EntityViewService;
|
||||
@ -117,6 +117,9 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
|
||||
@Autowired
|
||||
private DeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
private DeviceProfileService deviceProfileService;
|
||||
|
||||
@Autowired
|
||||
private AssetService assetService;
|
||||
|
||||
@ -152,6 +155,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
|
||||
// TODO: voba - implement this functionality
|
||||
// syncAdminSettings(edge);
|
||||
syncRuleChains(edge);
|
||||
syncDeviceProfiles(edge);
|
||||
syncUsers(edge);
|
||||
syncDevices(edge);
|
||||
syncAssets(edge);
|
||||
@ -206,6 +210,28 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
|
||||
}
|
||||
}
|
||||
|
||||
private void syncDeviceProfiles(Edge edge) {
|
||||
log.trace("[{}] syncDeviceProfiles [{}]", edge.getTenantId(), edge.getName());
|
||||
try {
|
||||
TimePageLink pageLink = new TimePageLink(DEFAULT_LIMIT);
|
||||
PageData<DeviceProfile> pageData;
|
||||
do {
|
||||
pageData = deviceProfileService.findDeviceProfiles(edge.getTenantId(), pageLink);
|
||||
if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
|
||||
log.trace("[{}] [{}] user(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size());
|
||||
for (DeviceProfile deviceProfile : pageData.getData()) {
|
||||
saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.DEVICE_PROFILE, EdgeEventActionType.ADDED, deviceProfile.getId(), null);
|
||||
}
|
||||
if (pageData.hasNext()) {
|
||||
pageLink = pageLink.nextPageLink();
|
||||
}
|
||||
}
|
||||
} while (pageData != null && pageData.hasNext());
|
||||
} catch (Exception e) {
|
||||
log.error("Exception during loading device profile(s) on sync!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void syncAssets(Edge edge) {
|
||||
log.trace("[{}] syncAssets [{}]", edge.getTenantId(), edge.getName());
|
||||
try {
|
||||
|
||||
@ -34,6 +34,7 @@ import org.thingsboard.server.common.data.edge.EdgeEventActionType;
|
||||
import org.thingsboard.server.common.data.edge.EdgeEventType;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||
import org.thingsboard.server.common.data.id.EdgeId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
@ -164,6 +165,11 @@ public class DeviceProcessor extends BaseProcessor {
|
||||
device.setType(deviceUpdateMsg.getType());
|
||||
device.setLabel(deviceUpdateMsg.getLabel());
|
||||
device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo()));
|
||||
if (deviceUpdateMsg.getDeviceProfileIdMSB() != 0 && deviceUpdateMsg.getDeviceProfileIdLSB() != 0) {
|
||||
DeviceProfileId deviceProfileId = new DeviceProfileId(
|
||||
new UUID(deviceUpdateMsg.getDeviceProfileIdMSB(), deviceUpdateMsg.getDeviceProfileIdLSB()));
|
||||
device.setDeviceProfileId(deviceProfileId);
|
||||
}
|
||||
deviceService.saveDevice(device);
|
||||
saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.CREDENTIALS_REQUEST, deviceId, null);
|
||||
} else {
|
||||
@ -183,6 +189,11 @@ public class DeviceProcessor extends BaseProcessor {
|
||||
device.setType(deviceUpdateMsg.getType());
|
||||
device.setLabel(deviceUpdateMsg.getLabel());
|
||||
device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo()));
|
||||
if (deviceUpdateMsg.getDeviceProfileIdMSB() != 0 && deviceUpdateMsg.getDeviceProfileIdLSB() != 0) {
|
||||
DeviceProfileId deviceProfileId = new DeviceProfileId(
|
||||
new UUID(deviceUpdateMsg.getDeviceProfileIdMSB(), deviceUpdateMsg.getDeviceProfileIdLSB()));
|
||||
device.setDeviceProfileId(deviceProfileId);
|
||||
}
|
||||
device = deviceService.saveDevice(device);
|
||||
createRelationFromEdge(tenantId, edge.getId(), device.getId());
|
||||
deviceStateService.onDeviceAdded(device);
|
||||
|
||||
@ -180,7 +180,6 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
|
||||
testAttributes();
|
||||
testSendMessagesToCloud();
|
||||
testRpcCall();
|
||||
// TODO: voba - test conflict messages in case device with current name already exist or ID is already used
|
||||
}
|
||||
|
||||
private Device findDeviceByName(String deviceName) throws Exception {
|
||||
|
||||
@ -30,6 +30,8 @@ public final class EdgeUtils {
|
||||
return EdgeEventType.EDGE;
|
||||
case DEVICE:
|
||||
return EdgeEventType.DEVICE;
|
||||
case DEVICE_PROFILE:
|
||||
return EdgeEventType.DEVICE_PROFILE;
|
||||
case ASSET:
|
||||
return EdgeEventType.ASSET;
|
||||
case ENTITY_VIEW:
|
||||
|
||||
@ -19,12 +19,12 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Data;
|
||||
import org.thingsboard.server.common.data.query.KeyFilter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class AlarmCondition {
|
||||
public class AlarmCondition implements Serializable {
|
||||
|
||||
private List<KeyFilter> condition;
|
||||
private AlarmConditionSpec spec;
|
||||
|
||||
@ -20,6 +20,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonTypeInfo(
|
||||
use = JsonTypeInfo.Id.NAME,
|
||||
@ -29,7 +31,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
@JsonSubTypes.Type(value = SimpleAlarmConditionSpec.class, name = "SIMPLE"),
|
||||
@JsonSubTypes.Type(value = DurationAlarmConditionSpec.class, name = "DURATION"),
|
||||
@JsonSubTypes.Type(value = RepeatingAlarmConditionSpec.class, name = "REPEATING")})
|
||||
public interface AlarmConditionSpec {
|
||||
public interface AlarmConditionSpec extends Serializable {
|
||||
|
||||
@JsonIgnore
|
||||
AlarmConditionSpecType getType();
|
||||
|
||||
@ -17,8 +17,10 @@ package org.thingsboard.server.common.data.device.profile;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class AlarmRule {
|
||||
public class AlarmRule implements Serializable {
|
||||
|
||||
private AlarmCondition condition;
|
||||
private AlarmSchedule schedule;
|
||||
|
||||
@ -19,6 +19,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonTypeInfo(
|
||||
use = JsonTypeInfo.Id.NAME,
|
||||
@ -28,7 +30,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
@JsonSubTypes.Type(value = AnyTimeSchedule.class, name = "ANY_TIME"),
|
||||
@JsonSubTypes.Type(value = SpecificTimeSchedule.class, name = "SPECIFIC_TIME"),
|
||||
@JsonSubTypes.Type(value = CustomTimeSchedule.class, name = "CUSTOM")})
|
||||
public interface AlarmSchedule {
|
||||
public interface AlarmSchedule extends Serializable {
|
||||
|
||||
AlarmScheduleType getType();
|
||||
|
||||
|
||||
@ -17,10 +17,10 @@ package org.thingsboard.server.common.data.device.profile;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class CustomTimeScheduleItem {
|
||||
public class CustomTimeScheduleItem implements Serializable {
|
||||
|
||||
private boolean enabled;
|
||||
private int dayOfWeek;
|
||||
|
||||
@ -18,11 +18,12 @@ package org.thingsboard.server.common.data.device.profile;
|
||||
import lombok.Data;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmSeverity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@Data
|
||||
public class DeviceProfileAlarm {
|
||||
public class DeviceProfileAlarm implements Serializable {
|
||||
|
||||
private String id;
|
||||
private String alarmType;
|
||||
|
||||
@ -21,6 +21,8 @@ import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import org.thingsboard.server.common.data.DeviceProfileType;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonTypeInfo(
|
||||
use = JsonTypeInfo.Id.NAME,
|
||||
@ -28,7 +30,7 @@ import org.thingsboard.server.common.data.DeviceProfileType;
|
||||
property = "type")
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(value = DefaultDeviceProfileConfiguration.class, name = "DEFAULT")})
|
||||
public interface DeviceProfileConfiguration {
|
||||
public interface DeviceProfileConfiguration extends Serializable {
|
||||
|
||||
@JsonIgnore
|
||||
DeviceProfileType getType();
|
||||
|
||||
@ -17,10 +17,11 @@ package org.thingsboard.server.common.data.device.profile;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class DeviceProfileData {
|
||||
public class DeviceProfileData implements Serializable {
|
||||
|
||||
private DeviceProfileConfiguration configuration;
|
||||
private DeviceProfileTransportConfiguration transportConfiguration;
|
||||
|
||||
@ -21,6 +21,8 @@ import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonTypeInfo(
|
||||
@ -31,7 +33,7 @@ import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
@JsonSubTypes.Type(value = DisabledDeviceProfileProvisionConfiguration.class, name = "DISABLED"),
|
||||
@JsonSubTypes.Type(value = AllowCreateNewDevicesDeviceProfileProvisionConfiguration.class, name = "ALLOW_CREATE_NEW_DEVICES"),
|
||||
@JsonSubTypes.Type(value = CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration.class, name = "CHECK_PRE_PROVISIONED_DEVICES")})
|
||||
public interface DeviceProfileProvisionConfiguration {
|
||||
public interface DeviceProfileProvisionConfiguration extends Serializable {
|
||||
|
||||
String getProvisionDeviceSecret();
|
||||
|
||||
|
||||
@ -19,9 +19,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import org.thingsboard.server.common.data.DeviceProfileType;
|
||||
import org.thingsboard.server.common.data.DeviceTransportType;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonTypeInfo(
|
||||
use = JsonTypeInfo.Id.NAME,
|
||||
@ -31,7 +32,7 @@ import org.thingsboard.server.common.data.DeviceTransportType;
|
||||
@JsonSubTypes.Type(value = DefaultDeviceProfileTransportConfiguration.class, name = "DEFAULT"),
|
||||
@JsonSubTypes.Type(value = MqttDeviceProfileTransportConfiguration.class, name = "MQTT"),
|
||||
@JsonSubTypes.Type(value = Lwm2mDeviceProfileTransportConfiguration.class, name = "LWM2M")})
|
||||
public interface DeviceProfileTransportConfiguration {
|
||||
public interface DeviceProfileTransportConfiguration extends Serializable {
|
||||
|
||||
@JsonIgnore
|
||||
DeviceTransportType getType();
|
||||
|
||||
@ -19,6 +19,7 @@ public enum EdgeEventType {
|
||||
DASHBOARD,
|
||||
ASSET,
|
||||
DEVICE,
|
||||
DEVICE_PROFILE,
|
||||
ENTITY_VIEW,
|
||||
ALARM,
|
||||
RULE_CHAIN,
|
||||
|
||||
@ -85,6 +85,8 @@ public class EntityIdFactory {
|
||||
return new DashboardId(uuid);
|
||||
case DEVICE:
|
||||
return new DeviceId(uuid);
|
||||
case DEVICE_PROFILE:
|
||||
return new DeviceProfileId(uuid);
|
||||
case ASSET:
|
||||
return new AssetId(uuid);
|
||||
case ALARM:
|
||||
|
||||
@ -19,8 +19,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class DynamicValue<T> {
|
||||
public class DynamicValue<T> implements Serializable {
|
||||
|
||||
@JsonIgnore
|
||||
private T resolvedValue;
|
||||
|
||||
@ -17,8 +17,10 @@ package org.thingsboard.server.common.data.query;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class EntityKey {
|
||||
public class EntityKey implements Serializable {
|
||||
private final EntityKeyType type;
|
||||
private final String key;
|
||||
}
|
||||
|
||||
@ -21,8 +21,10 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class FilterPredicateValue<T> {
|
||||
public class FilterPredicateValue<T> implements Serializable {
|
||||
|
||||
@Getter
|
||||
private final T defaultValue;
|
||||
|
||||
@ -17,8 +17,10 @@ package org.thingsboard.server.common.data.query;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class KeyFilter {
|
||||
public class KeyFilter implements Serializable {
|
||||
|
||||
private EntityKey key;
|
||||
private EntityKeyValueType valueType;
|
||||
|
||||
@ -19,6 +19,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@JsonTypeInfo(
|
||||
use = JsonTypeInfo.Id.NAME,
|
||||
include = JsonTypeInfo.As.PROPERTY,
|
||||
@ -28,7 +30,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
@JsonSubTypes.Type(value = NumericFilterPredicate.class, name = "NUMERIC"),
|
||||
@JsonSubTypes.Type(value = BooleanFilterPredicate.class, name = "BOOLEAN"),
|
||||
@JsonSubTypes.Type(value = ComplexFilterPredicate.class, name = "COMPLEX")})
|
||||
public interface KeyFilterPredicate {
|
||||
public interface KeyFilterPredicate extends Serializable {
|
||||
|
||||
@JsonIgnore
|
||||
FilterPredicateType getType();
|
||||
|
||||
@ -178,11 +178,30 @@ message DeviceUpdateMsg {
|
||||
int64 idLSB = 3;
|
||||
int64 customerIdMSB = 4;
|
||||
int64 customerIdLSB = 5;
|
||||
string name = 6;
|
||||
int64 deviceProfileIdMSB = 6;
|
||||
int64 deviceProfileIdLSB = 7;
|
||||
string name = 8;
|
||||
string type = 9;
|
||||
string label = 10;
|
||||
string additionalInfo = 11;
|
||||
string conflictName = 12;
|
||||
}
|
||||
|
||||
message DeviceProfileUpdateMsg {
|
||||
UpdateMsgType msgType = 1;
|
||||
int64 idMSB = 2;
|
||||
int64 idLSB = 3;
|
||||
string name = 4;
|
||||
string description = 5;
|
||||
bool default = 6;
|
||||
string type = 7;
|
||||
string label = 8;
|
||||
string additionalInfo = 9;
|
||||
string conflictName = 10;
|
||||
string transportType = 8;
|
||||
string provisionType = 9;
|
||||
int64 defaultRuleChainIdMSB = 10;
|
||||
int64 defaultRuleChainIdLSB = 11;
|
||||
string defaultQueueName = 12;
|
||||
bytes profileDataBytes = 13;
|
||||
string provisionDeviceKey = 14;
|
||||
}
|
||||
|
||||
message DeviceCredentialsUpdateMsg {
|
||||
@ -400,20 +419,21 @@ message DownlinkMsg {
|
||||
repeated EntityDataProto entityData = 2;
|
||||
repeated DeviceCredentialsRequestMsg deviceCredentialsRequestMsg = 3;
|
||||
repeated DeviceUpdateMsg deviceUpdateMsg = 4;
|
||||
repeated DeviceCredentialsUpdateMsg deviceCredentialsUpdateMsg = 5;
|
||||
repeated RuleChainUpdateMsg ruleChainUpdateMsg = 6;
|
||||
repeated RuleChainMetadataUpdateMsg ruleChainMetadataUpdateMsg = 7;
|
||||
repeated DashboardUpdateMsg dashboardUpdateMsg = 8;
|
||||
repeated AssetUpdateMsg assetUpdateMsg = 9;
|
||||
repeated EntityViewUpdateMsg entityViewUpdateMsg = 10;
|
||||
repeated AlarmUpdateMsg alarmUpdateMsg = 11;
|
||||
repeated UserUpdateMsg userUpdateMsg = 12;
|
||||
repeated UserCredentialsUpdateMsg userCredentialsUpdateMsg = 13;
|
||||
repeated CustomerUpdateMsg customerUpdateMsg = 14;
|
||||
repeated RelationUpdateMsg relationUpdateMsg = 15;
|
||||
repeated WidgetsBundleUpdateMsg widgetsBundleUpdateMsg = 16;
|
||||
repeated WidgetTypeUpdateMsg widgetTypeUpdateMsg = 17;
|
||||
repeated AdminSettingsUpdateMsg adminSettingsUpdateMsg = 18;
|
||||
repeated DeviceRpcCallMsg deviceRpcCallMsg = 19;
|
||||
repeated DeviceProfileUpdateMsg deviceProfileUpdateMsg = 5;
|
||||
repeated DeviceCredentialsUpdateMsg deviceCredentialsUpdateMsg = 6;
|
||||
repeated RuleChainUpdateMsg ruleChainUpdateMsg = 7;
|
||||
repeated RuleChainMetadataUpdateMsg ruleChainMetadataUpdateMsg = 8;
|
||||
repeated DashboardUpdateMsg dashboardUpdateMsg = 9;
|
||||
repeated AssetUpdateMsg assetUpdateMsg = 10;
|
||||
repeated EntityViewUpdateMsg entityViewUpdateMsg = 11;
|
||||
repeated AlarmUpdateMsg alarmUpdateMsg = 12;
|
||||
repeated UserUpdateMsg userUpdateMsg = 13;
|
||||
repeated UserCredentialsUpdateMsg userCredentialsUpdateMsg = 14;
|
||||
repeated CustomerUpdateMsg customerUpdateMsg = 15;
|
||||
repeated RelationUpdateMsg relationUpdateMsg = 16;
|
||||
repeated WidgetsBundleUpdateMsg widgetsBundleUpdateMsg = 17;
|
||||
repeated WidgetTypeUpdateMsg widgetTypeUpdateMsg = 18;
|
||||
repeated AdminSettingsUpdateMsg adminSettingsUpdateMsg = 19;
|
||||
repeated DeviceRpcCallMsg deviceRpcCallMsg = 20;
|
||||
}
|
||||
|
||||
|
||||
@ -472,12 +472,15 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
|
||||
@Override
|
||||
public ListenableFuture<List<EdgeId>> findRelatedEdgeIdsByEntityId(TenantId tenantId, EntityId entityId) {
|
||||
log.trace("[{}] Executing findRelatedEdgeIdsByEntityId [{}]", tenantId, entityId);
|
||||
if (EntityType.TENANT.equals(entityId.getEntityType()) || EntityType.CUSTOMER.equals(entityId.getEntityType())) {
|
||||
if (EntityType.TENANT.equals(entityId.getEntityType()) ||
|
||||
EntityType.CUSTOMER.equals(entityId.getEntityType()) ||
|
||||
EntityType.DEVICE_PROFILE.equals(entityId.getEntityType())) {
|
||||
List<EdgeId> result = new ArrayList<>();
|
||||
PageLink pageLink = new PageLink(DEFAULT_LIMIT);
|
||||
PageData<Edge> pageData;
|
||||
do {
|
||||
if (EntityType.TENANT.equals(entityId.getEntityType())) {
|
||||
if (EntityType.TENANT.equals(entityId.getEntityType()) ||
|
||||
EntityType.DEVICE_PROFILE.equals(entityId.getEntityType())) {
|
||||
pageData = findEdgesByTenantId(tenantId, pageLink);
|
||||
} else {
|
||||
pageData = findEdgesByTenantIdAndCustomerId(tenantId, new CustomerId(entityId.getId()), pageLink);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user