|
|
|
@ -43,6 +43,8 @@ import org.thingsboard.server.common.data.StringUtils; |
|
|
|
import org.thingsboard.server.common.data.TenantProfile; |
|
|
|
import org.thingsboard.server.common.data.alarm.Alarm; |
|
|
|
import org.thingsboard.server.common.data.asset.Asset; |
|
|
|
import org.thingsboard.server.common.data.asset.AssetProfile; |
|
|
|
import org.thingsboard.server.common.data.id.AssetId; |
|
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
|
import org.thingsboard.server.common.data.id.DeviceId; |
|
|
|
import org.thingsboard.server.common.data.id.EdgeId; |
|
|
|
@ -328,7 +330,7 @@ class DefaultTbContext implements TbContext { |
|
|
|
|
|
|
|
public TbMsg deviceCreatedMsg(Device device, RuleNodeId ruleNodeId) { |
|
|
|
RuleChainId ruleChainId = null; |
|
|
|
String queueName = null; |
|
|
|
String queueName = null; |
|
|
|
if (device.getDeviceProfileId() != null) { |
|
|
|
DeviceProfile deviceProfile = mainCtx.getDeviceProfileCache().find(device.getDeviceProfileId()); |
|
|
|
if (deviceProfile == null) { |
|
|
|
@ -342,7 +344,18 @@ class DefaultTbContext implements TbContext { |
|
|
|
} |
|
|
|
|
|
|
|
public TbMsg assetCreatedMsg(Asset asset, RuleNodeId ruleNodeId) { |
|
|
|
return entityActionMsg(asset, asset.getId(), ruleNodeId, DataConstants.ENTITY_CREATED); |
|
|
|
RuleChainId ruleChainId = null; |
|
|
|
String queueName = null; |
|
|
|
if (asset.getAssetProfileId() != null) { |
|
|
|
AssetProfile assetProfile = mainCtx.getAssetProfileCache().find(asset.getAssetProfileId()); |
|
|
|
if (assetProfile == null) { |
|
|
|
log.warn("[{}] Asset profile is null!", asset.getAssetProfileId()); |
|
|
|
} else { |
|
|
|
ruleChainId = assetProfile.getDefaultRuleChainId(); |
|
|
|
queueName = assetProfile.getDefaultQueueName(); |
|
|
|
} |
|
|
|
} |
|
|
|
return entityActionMsg(asset, asset.getId(), ruleNodeId, DataConstants.ENTITY_CREATED, queueName, ruleChainId); |
|
|
|
} |
|
|
|
|
|
|
|
public TbMsg alarmActionMsg(Alarm alarm, RuleNodeId ruleNodeId, String action) { |
|
|
|
@ -357,6 +370,15 @@ class DefaultTbContext implements TbContext { |
|
|
|
ruleChainId = deviceProfile.getDefaultRuleChainId(); |
|
|
|
queueName = deviceProfile.getDefaultQueueName(); |
|
|
|
} |
|
|
|
} else if (EntityType.ASSET.equals(alarm.getOriginator().getEntityType())) { |
|
|
|
AssetId assetId = new AssetId(alarm.getOriginator().getId()); |
|
|
|
AssetProfile assetProfile = mainCtx.getAssetProfileCache().get(getTenantId(), assetId); |
|
|
|
if (assetProfile == null) { |
|
|
|
log.warn("[{}] Asset profile is null!", assetId); |
|
|
|
} else { |
|
|
|
ruleChainId = assetProfile.getDefaultRuleChainId(); |
|
|
|
queueName = assetProfile.getDefaultQueueName(); |
|
|
|
} |
|
|
|
} |
|
|
|
return entityActionMsg(alarm, alarm.getId(), ruleNodeId, action, queueName, ruleChainId); |
|
|
|
} |
|
|
|
@ -653,9 +675,15 @@ class DefaultTbContext implements TbContext { |
|
|
|
mainCtx.getDeviceProfileCache().addListener(getTenantId(), getSelfId(), profileListener, deviceListener); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void addAssetProfileListeners(Consumer<AssetProfile> profileListener, BiConsumer<AssetId, AssetProfile> assetListener) { |
|
|
|
mainCtx.getAssetProfileCache().addListener(getTenantId(), getSelfId(), profileListener, assetListener); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void removeListeners() { |
|
|
|
mainCtx.getDeviceProfileCache().removeListener(getTenantId(), getSelfId()); |
|
|
|
mainCtx.getAssetProfileCache().removeListener(getTenantId(), getSelfId()); |
|
|
|
mainCtx.getTenantProfileCache().removeListener(getTenantId(), getSelfId()); |
|
|
|
} |
|
|
|
|
|
|
|
|