169 changed files with 1396 additions and 6142 deletions
@ -0,0 +1,544 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2024 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; |
||||
|
|
||||
|
import com.fasterxml.jackson.databind.JsonNode; |
||||
|
import com.google.gson.Gson; |
||||
|
import com.google.gson.JsonArray; |
||||
|
import com.google.gson.JsonElement; |
||||
|
import com.google.gson.JsonObject; |
||||
|
import com.google.gson.JsonPrimitive; |
||||
|
import com.google.gson.reflect.TypeToken; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.thingsboard.common.util.JacksonUtil; |
||||
|
import org.thingsboard.server.common.adaptor.JsonConverter; |
||||
|
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.OtaPackage; |
||||
|
import org.thingsboard.server.common.data.StringUtils; |
||||
|
import org.thingsboard.server.common.data.TbResource; |
||||
|
import org.thingsboard.server.common.data.Tenant; |
||||
|
import org.thingsboard.server.common.data.TenantProfile; |
||||
|
import org.thingsboard.server.common.data.User; |
||||
|
import org.thingsboard.server.common.data.alarm.Alarm; |
||||
|
import org.thingsboard.server.common.data.alarm.AlarmComment; |
||||
|
import org.thingsboard.server.common.data.asset.Asset; |
||||
|
import org.thingsboard.server.common.data.asset.AssetProfile; |
||||
|
import org.thingsboard.server.common.data.domain.DomainInfo; |
||||
|
import org.thingsboard.server.common.data.edge.Edge; |
||||
|
import org.thingsboard.server.common.data.edge.EdgeEventActionType; |
||||
|
import org.thingsboard.server.common.data.id.AssetId; |
||||
|
import org.thingsboard.server.common.data.id.AssetProfileId; |
||||
|
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.DomainId; |
||||
|
import org.thingsboard.server.common.data.id.EntityId; |
||||
|
import org.thingsboard.server.common.data.id.EntityViewId; |
||||
|
import org.thingsboard.server.common.data.id.NotificationRuleId; |
||||
|
import org.thingsboard.server.common.data.id.NotificationTargetId; |
||||
|
import org.thingsboard.server.common.data.id.NotificationTemplateId; |
||||
|
import org.thingsboard.server.common.data.id.OAuth2ClientId; |
||||
|
import org.thingsboard.server.common.data.id.OtaPackageId; |
||||
|
import org.thingsboard.server.common.data.id.QueueId; |
||||
|
import org.thingsboard.server.common.data.id.RuleChainId; |
||||
|
import org.thingsboard.server.common.data.id.TbResourceId; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.id.UserId; |
||||
|
import org.thingsboard.server.common.data.id.WidgetTypeId; |
||||
|
import org.thingsboard.server.common.data.id.WidgetsBundleId; |
||||
|
import org.thingsboard.server.common.data.notification.rule.NotificationRule; |
||||
|
import org.thingsboard.server.common.data.notification.targets.NotificationTarget; |
||||
|
import org.thingsboard.server.common.data.notification.template.NotificationTemplate; |
||||
|
import org.thingsboard.server.common.data.oauth2.OAuth2Client; |
||||
|
import org.thingsboard.server.common.data.queue.Queue; |
||||
|
import org.thingsboard.server.common.data.relation.EntityRelation; |
||||
|
import org.thingsboard.server.common.data.rule.RuleChain; |
||||
|
import org.thingsboard.server.common.data.rule.RuleChainMetaData; |
||||
|
import org.thingsboard.server.common.data.security.DeviceCredentials; |
||||
|
import org.thingsboard.server.common.data.security.UserCredentials; |
||||
|
import org.thingsboard.server.common.data.widget.WidgetTypeDetails; |
||||
|
import org.thingsboard.server.common.data.widget.WidgetsBundle; |
||||
|
import org.thingsboard.server.gen.edge.v1.AlarmCommentUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.AlarmUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.AssetProfileUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.AssetUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.AttributeDeleteMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.DashboardUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.DeviceCredentialsUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.EdgeConfiguration; |
||||
|
import org.thingsboard.server.gen.edge.v1.EntityDataProto; |
||||
|
import org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.NotificationRuleUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.NotificationTargetUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.NotificationTemplateUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.OAuth2ClientUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.OAuth2DomainUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.OtaPackageUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.QueueUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.RelationUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.ResourceUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.RpcRequestMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.RpcResponseMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.TenantProfileUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.TenantUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
||||
|
import org.thingsboard.server.gen.edge.v1.UserCredentialsUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.UserUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg; |
||||
|
import org.thingsboard.server.gen.transport.TransportProtos; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.UUID; |
||||
|
|
||||
|
@Slf4j |
||||
|
public class EdgeMsgConstructorUtils { |
||||
|
|
||||
|
public static AlarmUpdateMsg constructAlarmUpdatedMsg(UpdateMsgType msgType, Alarm alarm) { |
||||
|
return AlarmUpdateMsg.newBuilder().setMsgType(msgType) |
||||
|
.setEntity(JacksonUtil.toString(alarm)) |
||||
|
.setIdMSB(alarm.getId().getId().getMostSignificantBits()) |
||||
|
.setIdLSB(alarm.getId().getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static AlarmCommentUpdateMsg constructAlarmCommentUpdatedMsg(UpdateMsgType msgType, AlarmComment alarmComment) { |
||||
|
return AlarmCommentUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(alarmComment)).build(); |
||||
|
} |
||||
|
|
||||
|
public static AssetUpdateMsg constructAssetUpdatedMsg(UpdateMsgType msgType, Asset asset) { |
||||
|
return AssetUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(asset)) |
||||
|
.setIdMSB(asset.getUuidId().getMostSignificantBits()) |
||||
|
.setIdLSB(asset.getUuidId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static AssetUpdateMsg constructAssetDeleteMsg(AssetId assetId) { |
||||
|
return AssetUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(assetId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(assetId.getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static AssetProfileUpdateMsg constructAssetProfileUpdatedMsg(UpdateMsgType msgType, AssetProfile assetProfile) { |
||||
|
return AssetProfileUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(assetProfile)) |
||||
|
.setIdMSB(assetProfile.getId().getId().getMostSignificantBits()) |
||||
|
.setIdLSB(assetProfile.getId().getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static AssetProfileUpdateMsg constructAssetProfileDeleteMsg(AssetProfileId assetProfileId) { |
||||
|
return AssetProfileUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(assetProfileId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(assetProfileId.getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static CustomerUpdateMsg constructCustomerUpdatedMsg(UpdateMsgType msgType, Customer customer) { |
||||
|
return CustomerUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(customer)) |
||||
|
.setIdMSB(customer.getId().getId().getMostSignificantBits()) |
||||
|
.setIdLSB(customer.getId().getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static CustomerUpdateMsg constructCustomerDeleteMsg(CustomerId customerId) { |
||||
|
return CustomerUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(customerId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(customerId.getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static DashboardUpdateMsg constructDashboardUpdatedMsg(UpdateMsgType msgType, Dashboard dashboard) { |
||||
|
return DashboardUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(dashboard)) |
||||
|
.setIdMSB(dashboard.getId().getId().getMostSignificantBits()) |
||||
|
.setIdLSB(dashboard.getId().getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static DashboardUpdateMsg constructDashboardDeleteMsg(DashboardId dashboardId) { |
||||
|
return DashboardUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(dashboardId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(dashboardId.getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static DeviceUpdateMsg constructDeviceUpdatedMsg(UpdateMsgType msgType, Device device) { |
||||
|
return DeviceUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(device)) |
||||
|
.setIdMSB(device.getId().getId().getMostSignificantBits()) |
||||
|
.setIdLSB(device.getId().getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static DeviceUpdateMsg constructDeviceDeleteMsg(DeviceId deviceId) { |
||||
|
return DeviceUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(deviceId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(deviceId.getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static DeviceCredentialsUpdateMsg constructDeviceCredentialsUpdatedMsg(DeviceCredentials deviceCredentials) { |
||||
|
return DeviceCredentialsUpdateMsg.newBuilder().setEntity(JacksonUtil.toString(deviceCredentials)).build(); |
||||
|
} |
||||
|
|
||||
|
public static DeviceProfileUpdateMsg constructDeviceProfileUpdatedMsg(UpdateMsgType msgType, DeviceProfile deviceProfile) { |
||||
|
return DeviceProfileUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(deviceProfile)) |
||||
|
.setIdMSB(deviceProfile.getId().getId().getMostSignificantBits()) |
||||
|
.setIdLSB(deviceProfile.getId().getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static DeviceProfileUpdateMsg constructDeviceProfileDeleteMsg(DeviceProfileId deviceProfileId) { |
||||
|
return DeviceProfileUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(deviceProfileId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(deviceProfileId.getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static DeviceRpcCallMsg constructDeviceRpcCallMsg(UUID deviceId, JsonNode body) { |
||||
|
DeviceRpcCallMsg.Builder builder = constructDeviceRpcMsg(deviceId, body); |
||||
|
if (body.has("error") || body.has("response")) { |
||||
|
RpcResponseMsg.Builder responseBuilder = RpcResponseMsg.newBuilder(); |
||||
|
if (body.has("error")) { |
||||
|
responseBuilder.setError(body.get("error").asText()); |
||||
|
} else { |
||||
|
responseBuilder.setResponse(body.get("response").asText()); |
||||
|
} |
||||
|
builder.setResponseMsg(responseBuilder.build()); |
||||
|
} else { |
||||
|
RpcRequestMsg.Builder requestBuilder = RpcRequestMsg.newBuilder(); |
||||
|
requestBuilder.setMethod(body.get("method").asText()); |
||||
|
requestBuilder.setParams(body.get("params").asText()); |
||||
|
builder.setRequestMsg(requestBuilder.build()); |
||||
|
} |
||||
|
return builder.build(); |
||||
|
} |
||||
|
|
||||
|
private static DeviceRpcCallMsg.Builder constructDeviceRpcMsg(UUID deviceId, JsonNode body) { |
||||
|
DeviceRpcCallMsg.Builder builder = DeviceRpcCallMsg.newBuilder() |
||||
|
.setDeviceIdMSB(deviceId.getMostSignificantBits()) |
||||
|
.setDeviceIdLSB(deviceId.getLeastSignificantBits()) |
||||
|
.setRequestId(body.get("requestId").asInt()); |
||||
|
if (body.get("oneway") != null) { |
||||
|
builder.setOneway(body.get("oneway").asBoolean()); |
||||
|
} |
||||
|
if (body.get("requestUUID") != null) { |
||||
|
UUID requestUUID = UUID.fromString(body.get("requestUUID").asText()); |
||||
|
builder.setRequestUuidMSB(requestUUID.getMostSignificantBits()) |
||||
|
.setRequestUuidLSB(requestUUID.getLeastSignificantBits()); |
||||
|
} |
||||
|
if (body.get("expirationTime") != null) { |
||||
|
builder.setExpirationTime(body.get("expirationTime").asLong()); |
||||
|
} |
||||
|
if (body.get("persisted") != null) { |
||||
|
builder.setPersisted(body.get("persisted").asBoolean()); |
||||
|
} |
||||
|
if (body.get("retries") != null) { |
||||
|
builder.setRetries(body.get("retries").asInt()); |
||||
|
} |
||||
|
if (body.get("additionalInfo") != null) { |
||||
|
builder.setAdditionalInfo(JacksonUtil.toString(body.get("additionalInfo"))); |
||||
|
} |
||||
|
if (body.get("serviceId") != null) { |
||||
|
builder.setServiceId(body.get("serviceId").asText()); |
||||
|
} |
||||
|
if (body.get("sessionId") != null) { |
||||
|
builder.setSessionId(body.get("sessionId").asText()); |
||||
|
} |
||||
|
return builder; |
||||
|
} |
||||
|
|
||||
|
public static EdgeConfiguration constructEdgeConfiguration(Edge edge) { |
||||
|
EdgeConfiguration.Builder builder = EdgeConfiguration.newBuilder() |
||||
|
.setEdgeIdMSB(edge.getId().getId().getMostSignificantBits()) |
||||
|
.setEdgeIdLSB(edge.getId().getId().getLeastSignificantBits()) |
||||
|
.setTenantIdMSB(edge.getTenantId().getId().getMostSignificantBits()) |
||||
|
.setTenantIdLSB(edge.getTenantId().getId().getLeastSignificantBits()) |
||||
|
.setName(edge.getName()) |
||||
|
.setType(edge.getType()) |
||||
|
.setRoutingKey(edge.getRoutingKey()) |
||||
|
.setSecret(edge.getSecret()) |
||||
|
.setAdditionalInfo(JacksonUtil.toString(edge.getAdditionalInfo())) |
||||
|
.setCloudType("CE"); |
||||
|
if (edge.getCustomerId() != null) { |
||||
|
builder.setCustomerIdMSB(edge.getCustomerId().getId().getMostSignificantBits()) |
||||
|
.setCustomerIdLSB(edge.getCustomerId().getId().getLeastSignificantBits()); |
||||
|
} |
||||
|
return builder.build(); |
||||
|
} |
||||
|
|
||||
|
public static EntityViewUpdateMsg constructEntityViewUpdatedMsg(UpdateMsgType msgType, EntityView entityView) { |
||||
|
return EntityViewUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(entityView)) |
||||
|
.setIdMSB(entityView.getId().getId().getMostSignificantBits()) |
||||
|
.setIdLSB(entityView.getId().getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static EntityViewUpdateMsg constructEntityViewDeleteMsg(EntityViewId entityViewId) { |
||||
|
return EntityViewUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(entityViewId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(entityViewId.getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static NotificationRuleUpdateMsg constructNotificationRuleUpdateMsg(UpdateMsgType msgType, NotificationRule notificationRule) { |
||||
|
return NotificationRuleUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(notificationRule)).build(); |
||||
|
} |
||||
|
|
||||
|
public static NotificationRuleUpdateMsg constructNotificationRuleDeleteMsg(NotificationRuleId notificationRuleId) { |
||||
|
return NotificationRuleUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(notificationRuleId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(notificationRuleId.getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static NotificationTargetUpdateMsg constructNotificationTargetUpdateMsg(UpdateMsgType msgType, NotificationTarget notificationTarget) { |
||||
|
return NotificationTargetUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(notificationTarget)).build(); |
||||
|
} |
||||
|
|
||||
|
public static NotificationTargetUpdateMsg constructNotificationTargetDeleteMsg(NotificationTargetId notificationTargetId) { |
||||
|
return NotificationTargetUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(notificationTargetId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(notificationTargetId.getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static NotificationTemplateUpdateMsg constructNotificationTemplateUpdateMsg(UpdateMsgType msgType, NotificationTemplate notificationTemplate) { |
||||
|
return NotificationTemplateUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(notificationTemplate)).build(); |
||||
|
} |
||||
|
|
||||
|
public static NotificationTemplateUpdateMsg constructNotificationTemplateDeleteMsg(NotificationTemplateId notificationTemplateId) { |
||||
|
return NotificationTemplateUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(notificationTemplateId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(notificationTemplateId.getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static OAuth2ClientUpdateMsg constructOAuth2ClientUpdateMsg(UpdateMsgType msgType, OAuth2Client oAuth2Client) { |
||||
|
return OAuth2ClientUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(oAuth2Client)) |
||||
|
.setIdMSB(oAuth2Client.getId().getId().getMostSignificantBits()) |
||||
|
.setIdLSB(oAuth2Client.getId().getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static OAuth2ClientUpdateMsg constructOAuth2ClientDeleteMsg(OAuth2ClientId oAuth2ClientId) { |
||||
|
return OAuth2ClientUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(oAuth2ClientId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(oAuth2ClientId.getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static OAuth2DomainUpdateMsg constructOAuth2DomainUpdateMsg(UpdateMsgType msgType, DomainInfo domainInfo) { |
||||
|
return OAuth2DomainUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(domainInfo)) |
||||
|
.setIdMSB(domainInfo.getId().getId().getMostSignificantBits()) |
||||
|
.setIdLSB(domainInfo.getId().getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static OAuth2DomainUpdateMsg constructOAuth2DomainDeleteMsg(DomainId domainId) { |
||||
|
return OAuth2DomainUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(domainId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(domainId.getId().getLeastSignificantBits()) |
||||
|
.build(); |
||||
|
} |
||||
|
|
||||
|
public static OtaPackageUpdateMsg constructOtaPackageUpdatedMsg(UpdateMsgType msgType, OtaPackage otaPackage) { |
||||
|
return OtaPackageUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(otaPackage)) |
||||
|
.setIdMSB(otaPackage.getId().getId().getMostSignificantBits()) |
||||
|
.setIdLSB(otaPackage.getId().getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static OtaPackageUpdateMsg constructOtaPackageDeleteMsg(OtaPackageId otaPackageId) { |
||||
|
return OtaPackageUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(otaPackageId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(otaPackageId.getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static QueueUpdateMsg constructQueueUpdatedMsg(UpdateMsgType msgType, Queue queue) { |
||||
|
return QueueUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(queue)) |
||||
|
.setIdMSB(queue.getId().getId().getMostSignificantBits()) |
||||
|
.setIdLSB(queue.getId().getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static QueueUpdateMsg constructQueueDeleteMsg(QueueId queueId) { |
||||
|
return QueueUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(queueId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(queueId.getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static RelationUpdateMsg constructRelationUpdatedMsg(UpdateMsgType msgType, EntityRelation entityRelation) { |
||||
|
return RelationUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(entityRelation)).build(); |
||||
|
} |
||||
|
|
||||
|
public static ResourceUpdateMsg constructResourceUpdatedMsg(UpdateMsgType msgType, TbResource tbResource) { |
||||
|
return ResourceUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(tbResource)) |
||||
|
.setIdMSB(tbResource.getId().getId().getMostSignificantBits()) |
||||
|
.setIdLSB(tbResource.getId().getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static ResourceUpdateMsg constructResourceDeleteMsg(TbResourceId tbResourceId) { |
||||
|
return ResourceUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(tbResourceId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(tbResourceId.getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static RuleChainUpdateMsg constructRuleChainUpdatedMsg(UpdateMsgType msgType, RuleChain ruleChain, boolean isRoot) { |
||||
|
boolean isTemplateRoot = ruleChain.isRoot(); |
||||
|
ruleChain.setRoot(isRoot); |
||||
|
RuleChainUpdateMsg result = RuleChainUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(ruleChain)) |
||||
|
.setIdMSB(ruleChain.getId().getId().getMostSignificantBits()) |
||||
|
.setIdLSB(ruleChain.getId().getId().getLeastSignificantBits()).build(); |
||||
|
ruleChain.setRoot(isTemplateRoot); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
public static RuleChainUpdateMsg constructRuleChainDeleteMsg(RuleChainId ruleChainId) { |
||||
|
return RuleChainUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(ruleChainId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(ruleChainId.getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static RuleChainMetadataUpdateMsg constructRuleChainMetadataUpdatedMsg(UpdateMsgType msgType, RuleChainMetaData ruleChainMetaData) { |
||||
|
return RuleChainMetadataUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(ruleChainMetaData)).build(); |
||||
|
} |
||||
|
|
||||
|
public static EntityDataProto constructEntityDataMsg(TenantId tenantId, EntityId entityId, EdgeEventActionType actionType, JsonElement entityData) { |
||||
|
EntityDataProto.Builder builder = EntityDataProto.newBuilder() |
||||
|
.setEntityIdMSB(entityId.getId().getMostSignificantBits()) |
||||
|
.setEntityIdLSB(entityId.getId().getLeastSignificantBits()) |
||||
|
.setEntityType(entityId.getEntityType().name()); |
||||
|
switch (actionType) { |
||||
|
case TIMESERIES_UPDATED: |
||||
|
try { |
||||
|
JsonObject data = entityData.getAsJsonObject(); |
||||
|
long ts; |
||||
|
if (data.get("ts") != null && !data.get("ts").isJsonNull()) { |
||||
|
ts = data.getAsJsonPrimitive("ts").getAsLong(); |
||||
|
} else { |
||||
|
ts = System.currentTimeMillis(); |
||||
|
} |
||||
|
builder.setPostTelemetryMsg(JsonConverter.convertToTelemetryProto(data.getAsJsonObject("data"), ts)); |
||||
|
} catch (Exception e) { |
||||
|
log.warn("[{}][{}] Can't convert to telemetry proto, entityData [{}]", tenantId, entityId, entityData, e); |
||||
|
} |
||||
|
break; |
||||
|
case ATTRIBUTES_UPDATED: |
||||
|
try { |
||||
|
JsonObject data = entityData.getAsJsonObject(); |
||||
|
TransportProtos.PostAttributeMsg attributesUpdatedMsg = JsonConverter.convertToAttributesProto(data.getAsJsonObject("kv")); |
||||
|
builder.setAttributesUpdatedMsg(attributesUpdatedMsg); |
||||
|
builder.setPostAttributeScope(getScopeOfDefault(data)); |
||||
|
} catch (Exception e) { |
||||
|
log.warn("[{}][{}] Can't convert to AttributesUpdatedMsg proto, entityData [{}]", tenantId, entityId, entityData, e); |
||||
|
} |
||||
|
break; |
||||
|
case POST_ATTRIBUTES: |
||||
|
try { |
||||
|
JsonObject data = entityData.getAsJsonObject(); |
||||
|
TransportProtos.PostAttributeMsg postAttributesMsg = JsonConverter.convertToAttributesProto(data.getAsJsonObject("kv")); |
||||
|
builder.setPostAttributesMsg(postAttributesMsg); |
||||
|
builder.setPostAttributeScope(getScopeOfDefault(data)); |
||||
|
} catch (Exception e) { |
||||
|
log.warn("[{}][{}] Can't convert to PostAttributesMsg, entityData [{}]", tenantId, entityId, entityData, e); |
||||
|
} |
||||
|
break; |
||||
|
case ATTRIBUTES_DELETED: |
||||
|
try { |
||||
|
AttributeDeleteMsg.Builder attributeDeleteMsg = AttributeDeleteMsg.newBuilder(); |
||||
|
attributeDeleteMsg.setScope(entityData.getAsJsonObject().getAsJsonPrimitive("scope").getAsString()); |
||||
|
JsonArray jsonArray = entityData.getAsJsonObject().getAsJsonArray("keys"); |
||||
|
List<String> keys = new Gson().fromJson(jsonArray.toString(), new TypeToken<>(){}.getType()); |
||||
|
attributeDeleteMsg.addAllAttributeNames(keys); |
||||
|
attributeDeleteMsg.build(); |
||||
|
builder.setAttributeDeleteMsg(attributeDeleteMsg); |
||||
|
} catch (Exception e) { |
||||
|
log.warn("[{}][{}] Can't convert to AttributeDeleteMsg proto, entityData [{}]", tenantId, entityId, entityData, e); |
||||
|
} |
||||
|
break; |
||||
|
} |
||||
|
return builder.build(); |
||||
|
} |
||||
|
|
||||
|
private static String getScopeOfDefault(JsonObject data) { |
||||
|
JsonPrimitive scope = data.getAsJsonPrimitive("scope"); |
||||
|
String result = DataConstants.SERVER_SCOPE; |
||||
|
if (scope != null && StringUtils.isNotBlank(scope.getAsString())) { |
||||
|
result = scope.getAsString(); |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
public static TenantUpdateMsg constructTenantUpdateMsg(UpdateMsgType msgType, Tenant tenant) { |
||||
|
return TenantUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(tenant)).build(); |
||||
|
} |
||||
|
|
||||
|
public static TenantProfileUpdateMsg constructTenantProfileUpdateMsg(UpdateMsgType msgType, TenantProfile tenantProfile) { |
||||
|
return TenantProfileUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(tenantProfile)).build(); |
||||
|
} |
||||
|
|
||||
|
public static UserUpdateMsg constructUserUpdatedMsg(UpdateMsgType msgType, User user) { |
||||
|
return UserUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(user)) |
||||
|
.setIdMSB(user.getId().getId().getMostSignificantBits()) |
||||
|
.setIdLSB(user.getId().getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static UserUpdateMsg constructUserDeleteMsg(UserId userId) { |
||||
|
return UserUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(userId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(userId.getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static UserCredentialsUpdateMsg constructUserCredentialsUpdatedMsg(UserCredentials userCredentials) { |
||||
|
return UserCredentialsUpdateMsg.newBuilder().setEntity(JacksonUtil.toString(userCredentials)).build(); |
||||
|
} |
||||
|
|
||||
|
public static WidgetsBundleUpdateMsg constructWidgetsBundleUpdateMsg(UpdateMsgType msgType, WidgetsBundle widgetsBundle, List<String> widgets) { |
||||
|
return WidgetsBundleUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(widgetsBundle)) |
||||
|
.setWidgets(JacksonUtil.toString(widgets)) |
||||
|
.setIdMSB(widgetsBundle.getId().getId().getMostSignificantBits()) |
||||
|
.setIdLSB(widgetsBundle.getId().getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static WidgetsBundleUpdateMsg constructWidgetsBundleDeleteMsg(WidgetsBundleId widgetsBundleId) { |
||||
|
return WidgetsBundleUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(widgetsBundleId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(widgetsBundleId.getId().getLeastSignificantBits()) |
||||
|
.build(); |
||||
|
} |
||||
|
|
||||
|
public static WidgetTypeUpdateMsg constructWidgetTypeUpdateMsg(UpdateMsgType msgType, WidgetTypeDetails widgetTypeDetails) { |
||||
|
return WidgetTypeUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(widgetTypeDetails)) |
||||
|
.setIdMSB(widgetTypeDetails.getId().getId().getMostSignificantBits()) |
||||
|
.setIdLSB(widgetTypeDetails.getId().getId().getLeastSignificantBits()).build(); |
||||
|
} |
||||
|
|
||||
|
public static WidgetTypeUpdateMsg constructWidgetTypeDeleteMsg(WidgetTypeId widgetTypeId) { |
||||
|
return WidgetTypeUpdateMsg.newBuilder() |
||||
|
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
||||
|
.setIdMSB(widgetTypeId.getId().getMostSignificantBits()) |
||||
|
.setIdLSB(widgetTypeId.getId().getLeastSignificantBits()) |
||||
|
.build(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -1,40 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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 org.springframework.beans.factory.annotation.Autowired; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public abstract class BaseMsgConstructorFactory<T extends MsgConstructor, U extends MsgConstructor> { |
|
||||
|
|
||||
@Autowired |
|
||||
protected T v1Constructor; |
|
||||
|
|
||||
@Autowired |
|
||||
protected U v2Constructor; |
|
||||
|
|
||||
public MsgConstructor getMsgConstructorByEdgeVersion(EdgeVersion edgeVersion) { |
|
||||
return switch (edgeVersion) { |
|
||||
case V_3_3_0, V_3_3_3, V_3_4_0, V_3_6_0, V_3_6_1 -> v1Constructor; |
|
||||
default -> v2Constructor; |
|
||||
}; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,20 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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; |
|
||||
|
|
||||
public interface MsgConstructor { |
|
||||
|
|
||||
} |
|
||||
@ -1,30 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.alarm; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.alarm.Alarm; |
|
||||
import org.thingsboard.server.common.data.alarm.AlarmComment; |
|
||||
import org.thingsboard.server.gen.edge.v1.AlarmCommentUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.AlarmUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|
||||
|
|
||||
public interface AlarmMsgConstructor extends MsgConstructor { |
|
||||
|
|
||||
AlarmUpdateMsg constructAlarmUpdatedMsg(UpdateMsgType msgType, Alarm alarm, String entityName); |
|
||||
|
|
||||
AlarmCommentUpdateMsg constructAlarmCommentUpdatedMsg(UpdateMsgType msgType, AlarmComment alarmComment); |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.alarm; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.BaseMsgConstructorFactory; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class AlarmMsgConstructorFactory extends BaseMsgConstructorFactory<AlarmMsgConstructorV1, AlarmMsgConstructorV2> { |
|
||||
|
|
||||
} |
|
||||
@ -1,50 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.alarm; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.alarm.Alarm; |
|
||||
import org.thingsboard.server.gen.edge.v1.AlarmUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class AlarmMsgConstructorV1 extends BaseAlarmMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public AlarmUpdateMsg constructAlarmUpdatedMsg(UpdateMsgType msgType, Alarm alarm, String entityName) { |
|
||||
return AlarmUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(alarm.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(alarm.getId().getId().getLeastSignificantBits()) |
|
||||
.setName(alarm.getName()) |
|
||||
.setType(alarm.getType()) |
|
||||
.setOriginatorName(entityName) |
|
||||
.setOriginatorType(alarm.getOriginator().getEntityType().name()) |
|
||||
.setSeverity(alarm.getSeverity().name()) |
|
||||
.setStatus(alarm.getStatus().name()) |
|
||||
.setStartTs(alarm.getStartTs()) |
|
||||
.setEndTs(alarm.getEndTs()) |
|
||||
.setAckTs(alarm.getAckTs()) |
|
||||
.setClearTs(alarm.getClearTs()) |
|
||||
.setDetails(JacksonUtil.toString(alarm.getDetails())) |
|
||||
.setPropagate(alarm.isPropagate()) |
|
||||
.setPropagateToOwner(alarm.isPropagateToOwner()) |
|
||||
.setPropagateToTenant(alarm.isPropagateToTenant()).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,36 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.alarm; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.alarm.Alarm; |
|
||||
import org.thingsboard.server.gen.edge.v1.AlarmUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class AlarmMsgConstructorV2 extends BaseAlarmMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public AlarmUpdateMsg constructAlarmUpdatedMsg(UpdateMsgType msgType, Alarm alarm, String entityName) { |
|
||||
return AlarmUpdateMsg.newBuilder().setMsgType(msgType) |
|
||||
.setEntity(JacksonUtil.toString(alarm)) |
|
||||
.setIdMSB(alarm.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(alarm.getId().getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,36 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.asset; |
|
||||
|
|
||||
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.AssetProfileId; |
|
||||
import org.thingsboard.server.gen.edge.v1.AssetProfileUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.AssetUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|
||||
|
|
||||
public interface AssetMsgConstructor extends MsgConstructor { |
|
||||
|
|
||||
AssetUpdateMsg constructAssetUpdatedMsg(UpdateMsgType msgType, Asset asset); |
|
||||
|
|
||||
AssetUpdateMsg constructAssetDeleteMsg(AssetId assetId); |
|
||||
|
|
||||
AssetProfileUpdateMsg constructAssetProfileUpdatedMsg(UpdateMsgType msgType, AssetProfile assetProfile); |
|
||||
|
|
||||
AssetProfileUpdateMsg constructAssetProfileDeleteMsg(AssetProfileId assetProfileId); |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.asset; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.BaseMsgConstructorFactory; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class AssetMsgConstructorFactory extends BaseMsgConstructorFactory<AssetMsgConstructorV1, AssetMsgConstructorV2> { |
|
||||
|
|
||||
} |
|
||||
@ -1,94 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.asset; |
|
||||
|
|
||||
import com.google.protobuf.ByteString; |
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.asset.Asset; |
|
||||
import org.thingsboard.server.common.data.asset.AssetProfile; |
|
||||
import org.thingsboard.server.dao.resource.ImageService; |
|
||||
import org.thingsboard.server.gen.edge.v1.AssetProfileUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.AssetUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
import java.nio.charset.StandardCharsets; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class AssetMsgConstructorV1 extends BaseAssetMsgConstructor { |
|
||||
|
|
||||
@Autowired |
|
||||
private ImageService imageService; |
|
||||
|
|
||||
@Override |
|
||||
public AssetUpdateMsg constructAssetUpdatedMsg(UpdateMsgType msgType, Asset asset) { |
|
||||
AssetUpdateMsg.Builder builder = AssetUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(asset.getUuidId().getMostSignificantBits()) |
|
||||
.setIdLSB(asset.getUuidId().getLeastSignificantBits()) |
|
||||
.setName(asset.getName()) |
|
||||
.setType(asset.getType()); |
|
||||
if (asset.getLabel() != null) { |
|
||||
builder.setLabel(asset.getLabel()); |
|
||||
} |
|
||||
if (asset.getCustomerId() != null) { |
|
||||
builder.setCustomerIdMSB(asset.getCustomerId().getId().getMostSignificantBits()); |
|
||||
builder.setCustomerIdLSB(asset.getCustomerId().getId().getLeastSignificantBits()); |
|
||||
} |
|
||||
if (asset.getAssetProfileId() != null) { |
|
||||
builder.setAssetProfileIdMSB(asset.getAssetProfileId().getId().getMostSignificantBits()); |
|
||||
builder.setAssetProfileIdLSB(asset.getAssetProfileId().getId().getLeastSignificantBits()); |
|
||||
} |
|
||||
if (asset.getAdditionalInfo() != null) { |
|
||||
builder.setAdditionalInfo(JacksonUtil.toString(asset.getAdditionalInfo())); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public AssetProfileUpdateMsg constructAssetProfileUpdatedMsg(UpdateMsgType msgType, AssetProfile assetProfile) { |
|
||||
assetProfile = JacksonUtil.clone(assetProfile); |
|
||||
imageService.inlineImageForEdge(assetProfile); |
|
||||
AssetProfileUpdateMsg.Builder builder = AssetProfileUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(assetProfile.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(assetProfile.getId().getId().getLeastSignificantBits()) |
|
||||
.setName(assetProfile.getName()) |
|
||||
.setDefault(assetProfile.isDefault()); |
|
||||
if (assetProfile.getDefaultDashboardId() != null) { |
|
||||
builder.setDefaultDashboardIdMSB(assetProfile.getDefaultDashboardId().getId().getMostSignificantBits()) |
|
||||
.setDefaultDashboardIdLSB(assetProfile.getDefaultDashboardId().getId().getLeastSignificantBits()); |
|
||||
} |
|
||||
if (assetProfile.getDefaultQueueName() != null) { |
|
||||
builder.setDefaultQueueName(assetProfile.getDefaultQueueName()); |
|
||||
} |
|
||||
if (assetProfile.getDescription() != null) { |
|
||||
builder.setDescription(assetProfile.getDescription()); |
|
||||
} |
|
||||
if (assetProfile.getImage() != null) { |
|
||||
builder.setImage(ByteString.copyFrom(assetProfile.getImage().getBytes(StandardCharsets.UTF_8))); |
|
||||
} |
|
||||
if (assetProfile.getDefaultEdgeRuleChainId() != null) { |
|
||||
builder.setDefaultRuleChainIdMSB(assetProfile.getDefaultEdgeRuleChainId().getId().getMostSignificantBits()) |
|
||||
.setDefaultRuleChainIdLSB(assetProfile.getDefaultEdgeRuleChainId().getId().getLeastSignificantBits()); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,44 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.asset; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.asset.Asset; |
|
||||
import org.thingsboard.server.common.data.asset.AssetProfile; |
|
||||
import org.thingsboard.server.gen.edge.v1.AssetProfileUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.AssetUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class AssetMsgConstructorV2 extends BaseAssetMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public AssetUpdateMsg constructAssetUpdatedMsg(UpdateMsgType msgType, Asset asset) { |
|
||||
return AssetUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(asset)) |
|
||||
.setIdMSB(asset.getUuidId().getMostSignificantBits()) |
|
||||
.setIdLSB(asset.getUuidId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public AssetProfileUpdateMsg constructAssetProfileUpdatedMsg(UpdateMsgType msgType, AssetProfile assetProfile) { |
|
||||
return AssetProfileUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(assetProfile)) |
|
||||
.setIdMSB(assetProfile.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(assetProfile.getId().getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,41 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.asset; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.id.AssetId; |
|
||||
import org.thingsboard.server.common.data.id.AssetProfileId; |
|
||||
import org.thingsboard.server.gen.edge.v1.AssetProfileUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.AssetUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
|
|
||||
public abstract class BaseAssetMsgConstructor implements AssetMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public AssetUpdateMsg constructAssetDeleteMsg(AssetId assetId) { |
|
||||
return AssetUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(assetId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(assetId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public AssetProfileUpdateMsg constructAssetProfileDeleteMsg(AssetProfileId assetProfileId) { |
|
||||
return AssetProfileUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(assetProfileId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(assetProfileId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,31 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.customer; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.id.CustomerId; |
|
||||
import org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
|
|
||||
public abstract class BaseCustomerMsgConstructor implements CustomerMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public CustomerUpdateMsg constructCustomerDeleteMsg(CustomerId customerId) { |
|
||||
return CustomerUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(customerId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(customerId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,29 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.customer; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.Customer; |
|
||||
import org.thingsboard.server.common.data.id.CustomerId; |
|
||||
import org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|
||||
|
|
||||
public interface CustomerMsgConstructor extends MsgConstructor { |
|
||||
|
|
||||
CustomerUpdateMsg constructCustomerUpdatedMsg(UpdateMsgType msgType, Customer customer); |
|
||||
|
|
||||
CustomerUpdateMsg constructCustomerDeleteMsg(CustomerId customerId); |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.customer; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.BaseMsgConstructorFactory; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class CustomerMsgConstructorFactory extends BaseMsgConstructorFactory<CustomerMsgConstructorV1, CustomerMsgConstructorV2> { |
|
||||
|
|
||||
} |
|
||||
@ -1,65 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.customer; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.Customer; |
|
||||
import org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class CustomerMsgConstructorV1 extends BaseCustomerMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public CustomerUpdateMsg constructCustomerUpdatedMsg(UpdateMsgType msgType, Customer customer) { |
|
||||
CustomerUpdateMsg.Builder builder = CustomerUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(customer.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(customer.getId().getId().getLeastSignificantBits()) |
|
||||
.setTitle(customer.getTitle()); |
|
||||
if (customer.getCountry() != null) { |
|
||||
builder.setCountry(customer.getCountry()); |
|
||||
} |
|
||||
if (customer.getState() != null) { |
|
||||
builder.setState(customer.getState()); |
|
||||
} |
|
||||
if (customer.getCity() != null) { |
|
||||
builder.setCity(customer.getCity()); |
|
||||
} |
|
||||
if (customer.getAddress() != null) { |
|
||||
builder.setAddress(customer.getAddress()); |
|
||||
} |
|
||||
if (customer.getAddress2() != null) { |
|
||||
builder.setAddress2(customer.getAddress2()); |
|
||||
} |
|
||||
if (customer.getZip() != null) { |
|
||||
builder.setZip(customer.getZip()); |
|
||||
} |
|
||||
if (customer.getPhone() != null) { |
|
||||
builder.setPhone(customer.getPhone()); |
|
||||
} |
|
||||
if (customer.getEmail() != null) { |
|
||||
builder.setEmail(customer.getEmail()); |
|
||||
} |
|
||||
if (customer.getAdditionalInfo() != null) { |
|
||||
builder.setAdditionalInfo(JacksonUtil.toString(customer.getAdditionalInfo())); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,35 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.customer; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.Customer; |
|
||||
import org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class CustomerMsgConstructorV2 extends BaseCustomerMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public CustomerUpdateMsg constructCustomerUpdatedMsg(UpdateMsgType msgType, Customer customer) { |
|
||||
return CustomerUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(customer)) |
|
||||
.setIdMSB(customer.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(customer.getId().getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,32 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.dashboard; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.id.DashboardId; |
|
||||
import org.thingsboard.server.gen.edge.v1.DashboardUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
|
|
||||
public abstract class BaseDashboardMsgConstructor implements DashboardMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public DashboardUpdateMsg constructDashboardDeleteMsg(DashboardId dashboardId) { |
|
||||
return DashboardUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(dashboardId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(dashboardId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,30 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.dashboard; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.Dashboard; |
|
||||
import org.thingsboard.server.common.data.id.DashboardId; |
|
||||
import org.thingsboard.server.gen.edge.v1.DashboardUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|
||||
|
|
||||
public interface DashboardMsgConstructor extends MsgConstructor { |
|
||||
|
|
||||
DashboardUpdateMsg constructDashboardUpdatedMsg(UpdateMsgType msgType, Dashboard dashboard); |
|
||||
|
|
||||
DashboardUpdateMsg constructDashboardDeleteMsg(DashboardId dashboardId); |
|
||||
|
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.dashboard; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.BaseMsgConstructorFactory; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class DashboardMsgConstructorFactory extends BaseMsgConstructorFactory<DashboardMsgConstructorV1, DashboardMsgConstructorV2> { |
|
||||
|
|
||||
} |
|
||||
@ -1,57 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.dashboard; |
|
||||
|
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.Dashboard; |
|
||||
import org.thingsboard.server.dao.resource.ImageService; |
|
||||
import org.thingsboard.server.gen.edge.v1.DashboardUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class DashboardMsgConstructorV1 extends BaseDashboardMsgConstructor { |
|
||||
|
|
||||
@Autowired |
|
||||
private ImageService imageService; |
|
||||
|
|
||||
@Override |
|
||||
public DashboardUpdateMsg constructDashboardUpdatedMsg(UpdateMsgType msgType, Dashboard dashboard) { |
|
||||
dashboard = JacksonUtil.clone(dashboard); |
|
||||
imageService.inlineImagesForEdge(dashboard); |
|
||||
DashboardUpdateMsg.Builder builder = DashboardUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(dashboard.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(dashboard.getId().getId().getLeastSignificantBits()) |
|
||||
.setTitle(dashboard.getTitle()) |
|
||||
.setConfiguration(JacksonUtil.toString(dashboard.getConfiguration())) |
|
||||
.setMobileHide(dashboard.isMobileHide()); |
|
||||
if (dashboard.getAssignedCustomers() != null) { |
|
||||
builder.setAssignedCustomers(JacksonUtil.toString(dashboard.getAssignedCustomers())); |
|
||||
} |
|
||||
if (dashboard.getImage() != null) { |
|
||||
builder.setImage(dashboard.getImage()); |
|
||||
} |
|
||||
if (dashboard.getMobileOrder() != null) { |
|
||||
builder.setMobileOrder(dashboard.getMobileOrder()); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,36 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.dashboard; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.Dashboard; |
|
||||
import org.thingsboard.server.gen.edge.v1.DashboardUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class DashboardMsgConstructorV2 extends BaseDashboardMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public DashboardUpdateMsg constructDashboardUpdatedMsg(UpdateMsgType msgType, Dashboard dashboard) { |
|
||||
return DashboardUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(dashboard)) |
|
||||
.setIdMSB(dashboard.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(dashboard.getId().getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,102 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.device; |
|
||||
|
|
||||
import com.fasterxml.jackson.databind.JsonNode; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.id.DeviceId; |
|
||||
import org.thingsboard.server.common.data.id.DeviceProfileId; |
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.RpcRequestMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.RpcResponseMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
|
|
||||
import java.util.UUID; |
|
||||
|
|
||||
public abstract class BaseDeviceMsgConstructor implements DeviceMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public DeviceUpdateMsg constructDeviceDeleteMsg(DeviceId deviceId) { |
|
||||
return DeviceUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(deviceId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(deviceId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public DeviceProfileUpdateMsg constructDeviceProfileDeleteMsg(DeviceProfileId deviceProfileId) { |
|
||||
return DeviceProfileUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(deviceProfileId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(deviceProfileId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public DeviceRpcCallMsg constructDeviceRpcCallMsg(UUID deviceId, JsonNode body) { |
|
||||
DeviceRpcCallMsg.Builder builder = constructDeviceRpcMsg(deviceId, body); |
|
||||
if (body.has("error") || body.has("response")) { |
|
||||
RpcResponseMsg.Builder responseBuilder = RpcResponseMsg.newBuilder(); |
|
||||
if (body.has("error")) { |
|
||||
responseBuilder.setError(body.get("error").asText()); |
|
||||
} else { |
|
||||
responseBuilder.setResponse(body.get("response").asText()); |
|
||||
} |
|
||||
builder.setResponseMsg(responseBuilder.build()); |
|
||||
} else { |
|
||||
RpcRequestMsg.Builder requestBuilder = RpcRequestMsg.newBuilder(); |
|
||||
requestBuilder.setMethod(body.get("method").asText()); |
|
||||
requestBuilder.setParams(body.get("params").asText()); |
|
||||
builder.setRequestMsg(requestBuilder.build()); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
|
|
||||
private DeviceRpcCallMsg.Builder constructDeviceRpcMsg(UUID deviceId, JsonNode body) { |
|
||||
DeviceRpcCallMsg.Builder builder = DeviceRpcCallMsg.newBuilder() |
|
||||
.setDeviceIdMSB(deviceId.getMostSignificantBits()) |
|
||||
.setDeviceIdLSB(deviceId.getLeastSignificantBits()) |
|
||||
.setRequestId(body.get("requestId").asInt()); |
|
||||
if (body.get("oneway") != null) { |
|
||||
builder.setOneway(body.get("oneway").asBoolean()); |
|
||||
} |
|
||||
if (body.get("requestUUID") != null) { |
|
||||
UUID requestUUID = UUID.fromString(body.get("requestUUID").asText()); |
|
||||
builder.setRequestUuidMSB(requestUUID.getMostSignificantBits()) |
|
||||
.setRequestUuidLSB(requestUUID.getLeastSignificantBits()); |
|
||||
} |
|
||||
if (body.get("expirationTime") != null) { |
|
||||
builder.setExpirationTime(body.get("expirationTime").asLong()); |
|
||||
} |
|
||||
if (body.get("persisted") != null) { |
|
||||
builder.setPersisted(body.get("persisted").asBoolean()); |
|
||||
} |
|
||||
if (body.get("retries") != null) { |
|
||||
builder.setRetries(body.get("retries").asInt()); |
|
||||
} |
|
||||
if (body.get("additionalInfo") != null) { |
|
||||
builder.setAdditionalInfo(JacksonUtil.toString(body.get("additionalInfo"))); |
|
||||
} |
|
||||
if (body.get("serviceId") != null) { |
|
||||
builder.setServiceId(body.get("serviceId").asText()); |
|
||||
} |
|
||||
if (body.get("sessionId") != null) { |
|
||||
builder.setSessionId(body.get("sessionId").asText()); |
|
||||
} |
|
||||
return builder; |
|
||||
} |
|
||||
} |
|
||||
@ -1,47 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.device; |
|
||||
|
|
||||
import com.fasterxml.jackson.databind.JsonNode; |
|
||||
import org.thingsboard.server.common.data.Device; |
|
||||
import org.thingsboard.server.common.data.DeviceProfile; |
|
||||
import org.thingsboard.server.common.data.id.DeviceId; |
|
||||
import org.thingsboard.server.common.data.id.DeviceProfileId; |
|
||||
import org.thingsboard.server.common.data.security.DeviceCredentials; |
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceCredentialsUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|
||||
|
|
||||
import java.util.UUID; |
|
||||
|
|
||||
public interface DeviceMsgConstructor extends MsgConstructor { |
|
||||
|
|
||||
DeviceUpdateMsg constructDeviceUpdatedMsg(UpdateMsgType msgType, Device device); |
|
||||
|
|
||||
DeviceUpdateMsg constructDeviceDeleteMsg(DeviceId deviceId); |
|
||||
|
|
||||
DeviceCredentialsUpdateMsg constructDeviceCredentialsUpdatedMsg(DeviceCredentials deviceCredentials); |
|
||||
|
|
||||
DeviceProfileUpdateMsg constructDeviceProfileUpdatedMsg(UpdateMsgType msgType, DeviceProfile deviceProfile); |
|
||||
|
|
||||
DeviceProfileUpdateMsg constructDeviceProfileDeleteMsg(DeviceProfileId deviceProfileId); |
|
||||
|
|
||||
DeviceRpcCallMsg constructDeviceRpcCallMsg(UUID deviceId, JsonNode body); |
|
||||
|
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.device; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.BaseMsgConstructorFactory; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class DeviceMsgConstructorFactory extends BaseMsgConstructorFactory<DeviceMsgConstructorV1, DeviceMsgConstructorV2> { |
|
||||
|
|
||||
} |
|
||||
@ -1,141 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.device; |
|
||||
|
|
||||
import com.google.protobuf.ByteString; |
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.Device; |
|
||||
import org.thingsboard.server.common.data.DeviceProfile; |
|
||||
import org.thingsboard.server.common.data.security.DeviceCredentials; |
|
||||
import org.thingsboard.server.dao.resource.ImageService; |
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceCredentialsUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
import java.nio.charset.StandardCharsets; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class DeviceMsgConstructorV1 extends BaseDeviceMsgConstructor { |
|
||||
|
|
||||
@Autowired |
|
||||
private ImageService imageService; |
|
||||
|
|
||||
@Override |
|
||||
public DeviceUpdateMsg constructDeviceUpdatedMsg(UpdateMsgType msgType, Device device) { |
|
||||
DeviceUpdateMsg.Builder builder = DeviceUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(device.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(device.getId().getId().getLeastSignificantBits()) |
|
||||
.setName(device.getName()) |
|
||||
.setType(device.getType()); |
|
||||
if (device.getLabel() != null) { |
|
||||
builder.setLabel(device.getLabel()); |
|
||||
} |
|
||||
if (device.getCustomerId() != null) { |
|
||||
builder.setCustomerIdMSB(device.getCustomerId().getId().getMostSignificantBits()); |
|
||||
builder.setCustomerIdLSB(device.getCustomerId().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())); |
|
||||
} |
|
||||
if (device.getFirmwareId() != null) { |
|
||||
builder.setFirmwareIdMSB(device.getFirmwareId().getId().getMostSignificantBits()) |
|
||||
.setFirmwareIdLSB(device.getFirmwareId().getId().getLeastSignificantBits()); |
|
||||
} |
|
||||
if (device.getSoftwareId() != null) { |
|
||||
builder.setSoftwareIdMSB(device.getSoftwareId().getId().getMostSignificantBits()) |
|
||||
.setSoftwareIdLSB(device.getSoftwareId().getId().getLeastSignificantBits()); |
|
||||
} |
|
||||
if (device.getDeviceData() != null) { |
|
||||
builder.setDeviceDataBytes(ByteString.copyFrom(device.getDeviceDataBytes())); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public DeviceCredentialsUpdateMsg constructDeviceCredentialsUpdatedMsg(DeviceCredentials deviceCredentials) { |
|
||||
DeviceCredentialsUpdateMsg.Builder builder = DeviceCredentialsUpdateMsg.newBuilder() |
|
||||
.setDeviceIdMSB(deviceCredentials.getDeviceId().getId().getMostSignificantBits()) |
|
||||
.setDeviceIdLSB(deviceCredentials.getDeviceId().getId().getLeastSignificantBits()); |
|
||||
if (deviceCredentials.getCredentialsType() != null) { |
|
||||
builder.setCredentialsType(deviceCredentials.getCredentialsType().name()) |
|
||||
.setCredentialsId(deviceCredentials.getCredentialsId()); |
|
||||
} |
|
||||
if (deviceCredentials.getCredentialsValue() != null) { |
|
||||
builder.setCredentialsValue(deviceCredentials.getCredentialsValue()); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public DeviceProfileUpdateMsg constructDeviceProfileUpdatedMsg(UpdateMsgType msgType, DeviceProfile deviceProfile) { |
|
||||
deviceProfile = JacksonUtil.clone(deviceProfile); |
|
||||
imageService.inlineImageForEdge(deviceProfile); |
|
||||
DeviceProfileUpdateMsg.Builder builder = DeviceProfileUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(deviceProfile.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(deviceProfile.getId().getId().getLeastSignificantBits()) |
|
||||
.setName(deviceProfile.getName()) |
|
||||
.setDefault(deviceProfile.isDefault()) |
|
||||
.setType(deviceProfile.getType().name()) |
|
||||
.setProfileDataBytes(ByteString.copyFrom(deviceProfile.getProfileDataBytes())); |
|
||||
if (deviceProfile.getDefaultQueueName() != null) { |
|
||||
builder.setDefaultQueueName(deviceProfile.getDefaultQueueName()); |
|
||||
} |
|
||||
if (deviceProfile.getDescription() != null) { |
|
||||
builder.setDescription(deviceProfile.getDescription()); |
|
||||
} |
|
||||
if (deviceProfile.getTransportType() != null) { |
|
||||
builder.setTransportType(deviceProfile.getTransportType().name()); |
|
||||
} |
|
||||
if (deviceProfile.getProvisionType() != null) { |
|
||||
builder.setProvisionType(deviceProfile.getProvisionType().name()); |
|
||||
} |
|
||||
if (deviceProfile.getProvisionDeviceKey() != null) { |
|
||||
builder.setProvisionDeviceKey(deviceProfile.getProvisionDeviceKey()); |
|
||||
} |
|
||||
if (deviceProfile.getImage() != null) { |
|
||||
builder.setImage(ByteString.copyFrom(deviceProfile.getImage().getBytes(StandardCharsets.UTF_8))); |
|
||||
} |
|
||||
if (deviceProfile.getFirmwareId() != null) { |
|
||||
builder.setFirmwareIdMSB(deviceProfile.getFirmwareId().getId().getMostSignificantBits()) |
|
||||
.setFirmwareIdLSB(deviceProfile.getFirmwareId().getId().getLeastSignificantBits()); |
|
||||
} |
|
||||
if (deviceProfile.getSoftwareId() != null) { |
|
||||
builder.setSoftwareIdMSB(deviceProfile.getSoftwareId().getId().getMostSignificantBits()) |
|
||||
.setSoftwareIdLSB(deviceProfile.getSoftwareId().getId().getLeastSignificantBits()); |
|
||||
} |
|
||||
if (deviceProfile.getDefaultEdgeRuleChainId() != null) { |
|
||||
builder.setDefaultRuleChainIdMSB(deviceProfile.getDefaultEdgeRuleChainId().getId().getMostSignificantBits()) |
|
||||
.setDefaultRuleChainIdLSB(deviceProfile.getDefaultEdgeRuleChainId().getId().getLeastSignificantBits()); |
|
||||
} |
|
||||
if (deviceProfile.getDefaultDashboardId() != null) { |
|
||||
builder.setDefaultDashboardIdMSB(deviceProfile.getDefaultDashboardId().getId().getMostSignificantBits()) |
|
||||
.setDefaultDashboardIdLSB(deviceProfile.getDefaultDashboardId().getId().getLeastSignificantBits()); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,52 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.device; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.Device; |
|
||||
import org.thingsboard.server.common.data.DeviceProfile; |
|
||||
import org.thingsboard.server.common.data.security.DeviceCredentials; |
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceCredentialsUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class DeviceMsgConstructorV2 extends BaseDeviceMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public DeviceUpdateMsg constructDeviceUpdatedMsg(UpdateMsgType msgType, Device device) { |
|
||||
return DeviceUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(device)) |
|
||||
.setIdMSB(device.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(device.getId().getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public DeviceCredentialsUpdateMsg constructDeviceCredentialsUpdatedMsg(DeviceCredentials deviceCredentials) { |
|
||||
return DeviceCredentialsUpdateMsg.newBuilder().setEntity(JacksonUtil.toString(deviceCredentials)).build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public DeviceProfileUpdateMsg constructDeviceProfileUpdatedMsg(UpdateMsgType msgType, DeviceProfile deviceProfile) { |
|
||||
return DeviceProfileUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(deviceProfile)) |
|
||||
.setIdMSB(deviceProfile.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(deviceProfile.getId().getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,47 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.edge; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.edge.Edge; |
|
||||
import org.thingsboard.server.gen.edge.v1.EdgeConfiguration; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class EdgeMsgConstructor { |
|
||||
|
|
||||
public EdgeConfiguration constructEdgeConfiguration(Edge edge) { |
|
||||
EdgeConfiguration.Builder builder = EdgeConfiguration.newBuilder() |
|
||||
.setEdgeIdMSB(edge.getId().getId().getMostSignificantBits()) |
|
||||
.setEdgeIdLSB(edge.getId().getId().getLeastSignificantBits()) |
|
||||
.setTenantIdMSB(edge.getTenantId().getId().getMostSignificantBits()) |
|
||||
.setTenantIdLSB(edge.getTenantId().getId().getLeastSignificantBits()) |
|
||||
.setName(edge.getName()) |
|
||||
.setType(edge.getType()) |
|
||||
.setRoutingKey(edge.getRoutingKey()) |
|
||||
.setSecret(edge.getSecret()) |
|
||||
.setAdditionalInfo(JacksonUtil.toString(edge.getAdditionalInfo())) |
|
||||
.setCloudType("CE"); |
|
||||
if (edge.getCustomerId() != null) { |
|
||||
builder.setCustomerIdMSB(edge.getCustomerId().getId().getMostSignificantBits()) |
|
||||
.setCustomerIdLSB(edge.getCustomerId().getId().getLeastSignificantBits()); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,32 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.entityview; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.id.EntityViewId; |
|
||||
import org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
|
|
||||
public abstract class BaseEntityViewMsgConstructor implements EntityViewMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public EntityViewUpdateMsg constructEntityViewDeleteMsg(EntityViewId entityViewId) { |
|
||||
return EntityViewUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(entityViewId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(entityViewId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,30 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.entityview; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.EntityView; |
|
||||
import org.thingsboard.server.common.data.id.EntityViewId; |
|
||||
import org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|
||||
|
|
||||
public interface EntityViewMsgConstructor extends MsgConstructor { |
|
||||
|
|
||||
EntityViewUpdateMsg constructEntityViewUpdatedMsg(UpdateMsgType msgType, EntityView entityView); |
|
||||
|
|
||||
EntityViewUpdateMsg constructEntityViewDeleteMsg(EntityViewId entityViewId); |
|
||||
|
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.entityview; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.BaseMsgConstructorFactory; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class EntityViewMsgConstructorFactory extends BaseMsgConstructorFactory<EntityViewMsgConstructorV1, EntityViewMsgConstructorV2> { |
|
||||
|
|
||||
} |
|
||||
@ -1,61 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.entityview; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.EntityType; |
|
||||
import org.thingsboard.server.common.data.EntityView; |
|
||||
import org.thingsboard.server.gen.edge.v1.EdgeEntityType; |
|
||||
import org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class EntityViewMsgConstructorV1 extends BaseEntityViewMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public EntityViewUpdateMsg constructEntityViewUpdatedMsg(UpdateMsgType msgType, EntityView entityView) { |
|
||||
EdgeEntityType edgeEntityType = checkEntityType(entityView.getEntityId().getEntityType()); |
|
||||
EntityViewUpdateMsg.Builder builder = EntityViewUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(entityView.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(entityView.getId().getId().getLeastSignificantBits()) |
|
||||
.setName(entityView.getName()) |
|
||||
.setType(entityView.getType()) |
|
||||
.setEntityIdMSB(entityView.getEntityId().getId().getMostSignificantBits()) |
|
||||
.setEntityIdLSB(entityView.getEntityId().getId().getLeastSignificantBits()) |
|
||||
.setEntityType(edgeEntityType); |
|
||||
if (entityView.getCustomerId() != null) { |
|
||||
builder.setCustomerIdMSB(entityView.getCustomerId().getId().getMostSignificantBits()); |
|
||||
builder.setCustomerIdLSB(entityView.getCustomerId().getId().getLeastSignificantBits()); |
|
||||
} |
|
||||
if (entityView.getAdditionalInfo() != null) { |
|
||||
builder.setAdditionalInfo(JacksonUtil.toString(entityView.getAdditionalInfo())); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
|
|
||||
private EdgeEntityType checkEntityType(EntityType entityType) { |
|
||||
return switch (entityType) { |
|
||||
case DEVICE -> EdgeEntityType.DEVICE; |
|
||||
case ASSET -> EdgeEntityType.ASSET; |
|
||||
default -> throw new RuntimeException("Unsupported entity type [" + entityType + "]"); |
|
||||
}; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,36 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.entityview; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.EntityView; |
|
||||
import org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class EntityViewMsgConstructorV2 extends BaseEntityViewMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public EntityViewUpdateMsg constructEntityViewUpdatedMsg(UpdateMsgType msgType, EntityView entityView) { |
|
||||
return EntityViewUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(entityView)) |
|
||||
.setIdMSB(entityView.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(entityView.getId().getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,43 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.notification; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.id.NotificationRuleId; |
|
||||
import org.thingsboard.server.common.data.id.NotificationTargetId; |
|
||||
import org.thingsboard.server.common.data.id.NotificationTemplateId; |
|
||||
import org.thingsboard.server.common.data.notification.rule.NotificationRule; |
|
||||
import org.thingsboard.server.common.data.notification.targets.NotificationTarget; |
|
||||
import org.thingsboard.server.common.data.notification.template.NotificationTemplate; |
|
||||
import org.thingsboard.server.gen.edge.v1.NotificationRuleUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.NotificationTargetUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.NotificationTemplateUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
|
|
||||
public interface NotificationMsgConstructor { |
|
||||
|
|
||||
NotificationRuleUpdateMsg constructNotificationRuleUpdateMsg(UpdateMsgType msgType, NotificationRule notificationRule); |
|
||||
|
|
||||
NotificationRuleUpdateMsg constructNotificationRuleDeleteMsg(NotificationRuleId notificationRuleId); |
|
||||
|
|
||||
NotificationTargetUpdateMsg constructNotificationTargetUpdateMsg(UpdateMsgType msgType, NotificationTarget notificationTarget); |
|
||||
|
|
||||
NotificationTargetUpdateMsg constructNotificationTargetDeleteMsg(NotificationTargetId notificationTargetId); |
|
||||
|
|
||||
NotificationTemplateUpdateMsg constructNotificationTemplateUpdateMsg(UpdateMsgType msgType, NotificationTemplate notificationTemplate); |
|
||||
|
|
||||
NotificationTemplateUpdateMsg constructNotificationTemplateDeleteMsg(NotificationTemplateId notificationTemplateId); |
|
||||
|
|
||||
} |
|
||||
@ -1,75 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.notification; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.id.NotificationRuleId; |
|
||||
import org.thingsboard.server.common.data.id.NotificationTargetId; |
|
||||
import org.thingsboard.server.common.data.id.NotificationTemplateId; |
|
||||
import org.thingsboard.server.common.data.notification.rule.NotificationRule; |
|
||||
import org.thingsboard.server.common.data.notification.targets.NotificationTarget; |
|
||||
import org.thingsboard.server.common.data.notification.template.NotificationTemplate; |
|
||||
import org.thingsboard.server.gen.edge.v1.NotificationRuleUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.NotificationTargetUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.NotificationTemplateUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class NotificationMsgConstructorImpl implements NotificationMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public NotificationRuleUpdateMsg constructNotificationRuleUpdateMsg(UpdateMsgType msgType, NotificationRule notificationRule) { |
|
||||
return NotificationRuleUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(notificationRule)).build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public NotificationRuleUpdateMsg constructNotificationRuleDeleteMsg(NotificationRuleId notificationRuleId) { |
|
||||
return NotificationRuleUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(notificationRuleId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(notificationRuleId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public NotificationTargetUpdateMsg constructNotificationTargetUpdateMsg(UpdateMsgType msgType, NotificationTarget notificationTarget) { |
|
||||
return NotificationTargetUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(notificationTarget)).build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public NotificationTargetUpdateMsg constructNotificationTargetDeleteMsg(NotificationTargetId notificationTargetId) { |
|
||||
return NotificationTargetUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(notificationTargetId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(notificationTargetId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public NotificationTemplateUpdateMsg constructNotificationTemplateUpdateMsg(UpdateMsgType msgType, NotificationTemplate notificationTemplate) { |
|
||||
return NotificationTemplateUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(notificationTemplate)).build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public NotificationTemplateUpdateMsg constructNotificationTemplateDeleteMsg(NotificationTemplateId notificationTemplateId) { |
|
||||
return NotificationTemplateUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(notificationTemplateId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(notificationTemplateId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,60 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.oauth2; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.domain.DomainInfo; |
|
||||
import org.thingsboard.server.common.data.id.DomainId; |
|
||||
import org.thingsboard.server.common.data.id.OAuth2ClientId; |
|
||||
import org.thingsboard.server.common.data.oauth2.OAuth2Client; |
|
||||
import org.thingsboard.server.gen.edge.v1.OAuth2ClientUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.OAuth2DomainUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class OAuth2MsgConstructor { |
|
||||
|
|
||||
public OAuth2ClientUpdateMsg constructOAuth2ClientUpdateMsg(UpdateMsgType msgType, OAuth2Client oAuth2Client) { |
|
||||
return OAuth2ClientUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(oAuth2Client)) |
|
||||
.setIdMSB(oAuth2Client.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(oAuth2Client.getId().getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
public OAuth2ClientUpdateMsg constructOAuth2ClientDeleteMsg(OAuth2ClientId oAuth2ClientId) { |
|
||||
return OAuth2ClientUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(oAuth2ClientId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(oAuth2ClientId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
public OAuth2DomainUpdateMsg constructOAuth2DomainUpdateMsg(UpdateMsgType msgType, DomainInfo domainInfo) { |
|
||||
return OAuth2DomainUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(domainInfo)) |
|
||||
.setIdMSB(domainInfo.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(domainInfo.getId().getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
public OAuth2DomainUpdateMsg constructOAuth2DomainDeleteMsg(DomainId domainId) { |
|
||||
return OAuth2DomainUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(domainId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(domainId.getId().getLeastSignificantBits()) |
|
||||
.build(); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,31 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.ota; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.id.OtaPackageId; |
|
||||
import org.thingsboard.server.gen.edge.v1.OtaPackageUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
|
|
||||
public abstract class BaseOtaPackageMsgConstructor implements OtaPackageMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public OtaPackageUpdateMsg constructOtaPackageDeleteMsg(OtaPackageId otaPackageId) { |
|
||||
return OtaPackageUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(otaPackageId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(otaPackageId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,29 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.ota; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.OtaPackage; |
|
||||
import org.thingsboard.server.common.data.id.OtaPackageId; |
|
||||
import org.thingsboard.server.gen.edge.v1.OtaPackageUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|
||||
|
|
||||
public interface OtaPackageMsgConstructor extends MsgConstructor { |
|
||||
|
|
||||
OtaPackageUpdateMsg constructOtaPackageUpdatedMsg(UpdateMsgType msgType, OtaPackage otaPackage); |
|
||||
|
|
||||
OtaPackageUpdateMsg constructOtaPackageDeleteMsg(OtaPackageId otaPackageId); |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.ota; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.BaseMsgConstructorFactory; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class OtaPackageMsgConstructorFactory extends BaseMsgConstructorFactory<OtaPackageMsgConstructorV1, OtaPackageMsgConstructorV2> { |
|
||||
|
|
||||
} |
|
||||
@ -1,72 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.ota; |
|
||||
|
|
||||
import com.google.protobuf.ByteString; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.OtaPackage; |
|
||||
import org.thingsboard.server.gen.edge.v1.OtaPackageUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class OtaPackageMsgConstructorV1 extends BaseOtaPackageMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public OtaPackageUpdateMsg constructOtaPackageUpdatedMsg(UpdateMsgType msgType, OtaPackage otaPackage) { |
|
||||
OtaPackageUpdateMsg.Builder builder = OtaPackageUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(otaPackage.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(otaPackage.getId().getId().getLeastSignificantBits()) |
|
||||
.setType(otaPackage.getType().name()) |
|
||||
.setTitle(otaPackage.getTitle()) |
|
||||
.setVersion(otaPackage.getVersion()) |
|
||||
.setTag(otaPackage.getTag()); |
|
||||
|
|
||||
if (otaPackage.getDeviceProfileId() != null) { |
|
||||
builder.setDeviceProfileIdMSB(otaPackage.getDeviceProfileId().getId().getMostSignificantBits()) |
|
||||
.setDeviceProfileIdLSB(otaPackage.getDeviceProfileId().getId().getLeastSignificantBits()); |
|
||||
} |
|
||||
|
|
||||
if (otaPackage.getUrl() != null) { |
|
||||
builder.setUrl(otaPackage.getUrl()); |
|
||||
} |
|
||||
if (otaPackage.getAdditionalInfo() != null) { |
|
||||
builder.setAdditionalInfo(JacksonUtil.toString(otaPackage.getAdditionalInfo())); |
|
||||
} |
|
||||
if (otaPackage.getFileName() != null) { |
|
||||
builder.setFileName(otaPackage.getFileName()); |
|
||||
} |
|
||||
if (otaPackage.getContentType() != null) { |
|
||||
builder.setContentType(otaPackage.getContentType()); |
|
||||
} |
|
||||
if (otaPackage.getChecksumAlgorithm() != null) { |
|
||||
builder.setChecksumAlgorithm(otaPackage.getChecksumAlgorithm().name()); |
|
||||
} |
|
||||
if (otaPackage.getChecksum() != null) { |
|
||||
builder.setChecksum(otaPackage.getChecksum()); |
|
||||
} |
|
||||
if (otaPackage.getDataSize() != null) { |
|
||||
builder.setDataSize(otaPackage.getDataSize()); |
|
||||
} |
|
||||
if (otaPackage.getData() != null) { |
|
||||
builder.setData(ByteString.copyFrom(otaPackage.getData().array())); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,35 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.ota; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.OtaPackage; |
|
||||
import org.thingsboard.server.gen.edge.v1.OtaPackageUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class OtaPackageMsgConstructorV2 extends BaseOtaPackageMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public OtaPackageUpdateMsg constructOtaPackageUpdatedMsg(UpdateMsgType msgType, OtaPackage otaPackage) { |
|
||||
return OtaPackageUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(otaPackage)) |
|
||||
.setIdMSB(otaPackage.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(otaPackage.getId().getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,31 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.queue; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.id.QueueId; |
|
||||
import org.thingsboard.server.gen.edge.v1.QueueUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
|
|
||||
public abstract class BaseQueueMsgConstructor implements QueueMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public QueueUpdateMsg constructQueueDeleteMsg(QueueId queueId) { |
|
||||
return QueueUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(queueId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(queueId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,29 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.queue; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.id.QueueId; |
|
||||
import org.thingsboard.server.common.data.queue.Queue; |
|
||||
import org.thingsboard.server.gen.edge.v1.QueueUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|
||||
|
|
||||
public interface QueueMsgConstructor extends MsgConstructor { |
|
||||
|
|
||||
QueueUpdateMsg constructQueueUpdatedMsg(UpdateMsgType msgType, Queue queue); |
|
||||
|
|
||||
QueueUpdateMsg constructQueueDeleteMsg(QueueId queueId); |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.queue; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.BaseMsgConstructorFactory; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class QueueMsgConstructorFactory extends BaseMsgConstructorFactory<QueueMsgConstructorV1, QueueMsgConstructorV2> { |
|
||||
|
|
||||
} |
|
||||
@ -1,74 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.queue; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.common.data.id.QueueId; |
|
||||
import org.thingsboard.server.common.data.queue.ProcessingStrategy; |
|
||||
import org.thingsboard.server.common.data.queue.Queue; |
|
||||
import org.thingsboard.server.common.data.queue.SubmitStrategy; |
|
||||
import org.thingsboard.server.gen.edge.v1.ProcessingStrategyProto; |
|
||||
import org.thingsboard.server.gen.edge.v1.QueueUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.SubmitStrategyProto; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class QueueMsgConstructorV1 extends BaseQueueMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public QueueUpdateMsg constructQueueUpdatedMsg(UpdateMsgType msgType, Queue queue) { |
|
||||
return QueueUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(queue.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(queue.getId().getId().getLeastSignificantBits()) |
|
||||
.setTenantIdMSB(queue.getTenantId().getId().getMostSignificantBits()) |
|
||||
.setTenantIdLSB(queue.getTenantId().getId().getLeastSignificantBits()) |
|
||||
.setName(queue.getName()) |
|
||||
.setTopic(queue.getTopic()) |
|
||||
.setPollInterval(queue.getPollInterval()) |
|
||||
.setPartitions(queue.getPartitions()) |
|
||||
.setConsumerPerPartition(queue.isConsumerPerPartition()) |
|
||||
.setPackProcessingTimeout(queue.getPackProcessingTimeout()) |
|
||||
.setSubmitStrategy(createSubmitStrategyProto(queue.getSubmitStrategy())) |
|
||||
.setProcessingStrategy(createProcessingStrategyProto(queue.getProcessingStrategy())).build(); |
|
||||
} |
|
||||
|
|
||||
private ProcessingStrategyProto createProcessingStrategyProto(ProcessingStrategy processingStrategy) { |
|
||||
return ProcessingStrategyProto.newBuilder() |
|
||||
.setType(processingStrategy.getType().name()) |
|
||||
.setRetries(processingStrategy.getRetries()) |
|
||||
.setFailurePercentage(processingStrategy.getFailurePercentage()) |
|
||||
.setPauseBetweenRetries(processingStrategy.getPauseBetweenRetries()) |
|
||||
.setMaxPauseBetweenRetries(processingStrategy.getMaxPauseBetweenRetries()) |
|
||||
.build(); |
|
||||
} |
|
||||
|
|
||||
private SubmitStrategyProto createSubmitStrategyProto(SubmitStrategy submitStrategy) { |
|
||||
return SubmitStrategyProto.newBuilder() |
|
||||
.setType(submitStrategy.getType().name()) |
|
||||
.setBatchSize(submitStrategy.getBatchSize()) |
|
||||
.build(); |
|
||||
} |
|
||||
|
|
||||
public QueueUpdateMsg constructQueueDeleteMsg(QueueId queueId) { |
|
||||
return QueueUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(queueId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(queueId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,35 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.queue; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.queue.Queue; |
|
||||
import org.thingsboard.server.gen.edge.v1.QueueUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class QueueMsgConstructorV2 extends BaseQueueMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public QueueUpdateMsg constructQueueUpdatedMsg(UpdateMsgType msgType, Queue queue) { |
|
||||
return QueueUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(queue)) |
|
||||
.setIdMSB(queue.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(queue.getId().getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.relation; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.relation.EntityRelation; |
|
||||
import org.thingsboard.server.gen.edge.v1.RelationUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|
||||
|
|
||||
public interface RelationMsgConstructor extends MsgConstructor { |
|
||||
|
|
||||
RelationUpdateMsg constructRelationUpdatedMsg(UpdateMsgType msgType, EntityRelation entityRelation); |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.relation; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.BaseMsgConstructorFactory; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class RelationMsgConstructorFactory extends BaseMsgConstructorFactory<RelationMsgConstructorV1, RelationMsgConstructorV2> { |
|
||||
|
|
||||
} |
|
||||
@ -1,48 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.relation; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.relation.EntityRelation; |
|
||||
import org.thingsboard.server.gen.edge.v1.RelationUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class RelationMsgConstructorV1 implements RelationMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public RelationUpdateMsg constructRelationUpdatedMsg(UpdateMsgType msgType, EntityRelation entityRelation) { |
|
||||
RelationUpdateMsg.Builder builder = RelationUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setFromIdMSB(entityRelation.getFrom().getId().getMostSignificantBits()) |
|
||||
.setFromIdLSB(entityRelation.getFrom().getId().getLeastSignificantBits()) |
|
||||
.setFromEntityType(entityRelation.getFrom().getEntityType().name()) |
|
||||
.setToIdMSB(entityRelation.getTo().getId().getMostSignificantBits()) |
|
||||
.setToIdLSB(entityRelation.getTo().getId().getLeastSignificantBits()) |
|
||||
.setToEntityType(entityRelation.getTo().getEntityType().name()) |
|
||||
.setType(entityRelation.getType()); |
|
||||
if (entityRelation.getAdditionalInfo() != null) { |
|
||||
builder.setAdditionalInfo(JacksonUtil.toString(entityRelation.getAdditionalInfo())); |
|
||||
} |
|
||||
if (entityRelation.getTypeGroup() != null) { |
|
||||
builder.setTypeGroup(entityRelation.getTypeGroup().name()); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,34 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.relation; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.relation.EntityRelation; |
|
||||
import org.thingsboard.server.gen.edge.v1.RelationUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class RelationMsgConstructorV2 implements RelationMsgConstructor { |
|
||||
|
|
||||
|
|
||||
@Override |
|
||||
public RelationUpdateMsg constructRelationUpdatedMsg(UpdateMsgType msgType, EntityRelation entityRelation) { |
|
||||
return RelationUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(entityRelation)).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,31 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.resource; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.id.TbResourceId; |
|
||||
import org.thingsboard.server.gen.edge.v1.ResourceUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
|
|
||||
public abstract class BaseResourceMsgConstructor implements ResourceMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public ResourceUpdateMsg constructResourceDeleteMsg(TbResourceId tbResourceId) { |
|
||||
return ResourceUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(tbResourceId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(tbResourceId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,29 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.resource; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.TbResource; |
|
||||
import org.thingsboard.server.common.data.id.TbResourceId; |
|
||||
import org.thingsboard.server.gen.edge.v1.ResourceUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|
||||
|
|
||||
public interface ResourceMsgConstructor extends MsgConstructor { |
|
||||
|
|
||||
ResourceUpdateMsg constructResourceUpdatedMsg(UpdateMsgType msgType, TbResource tbResource); |
|
||||
|
|
||||
ResourceUpdateMsg constructResourceDeleteMsg(TbResourceId tbResourceId); |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.resource; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.BaseMsgConstructorFactory; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class ResourceMsgConstructorFactory extends BaseMsgConstructorFactory<ResourceMsgConstructorV1, ResourceMsgConstructorV2> { |
|
||||
|
|
||||
} |
|
||||
@ -1,56 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.resource; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.common.data.ResourceType; |
|
||||
import org.thingsboard.server.common.data.TbResource; |
|
||||
import org.thingsboard.server.common.data.id.TenantId; |
|
||||
import org.thingsboard.server.gen.edge.v1.ResourceUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class ResourceMsgConstructorV1 extends BaseResourceMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public ResourceUpdateMsg constructResourceUpdatedMsg(UpdateMsgType msgType, TbResource tbResource) { |
|
||||
if (ResourceType.IMAGE.equals(tbResource.getResourceType())) { |
|
||||
// Exclude support for a recently added resource type when dealing with older Edges
|
|
||||
// to maintain compatibility and avoid potential issues.
|
|
||||
return null; |
|
||||
} |
|
||||
ResourceUpdateMsg.Builder builder = ResourceUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(tbResource.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(tbResource.getId().getId().getLeastSignificantBits()) |
|
||||
.setTitle(tbResource.getTitle()) |
|
||||
.setResourceKey(tbResource.getResourceKey()) |
|
||||
.setResourceType(tbResource.getResourceType().name()) |
|
||||
.setFileName(tbResource.getFileName()); |
|
||||
if (tbResource.getData() != null) { |
|
||||
builder.setData(tbResource.getEncodedData()); |
|
||||
} |
|
||||
if (tbResource.getEtag() != null) { |
|
||||
builder.setEtag(tbResource.getEtag()); |
|
||||
} |
|
||||
if (TenantId.SYS_TENANT_ID.equals(tbResource.getTenantId())) { |
|
||||
builder.setIsSystem(true); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,35 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.resource; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.TbResource; |
|
||||
import org.thingsboard.server.gen.edge.v1.ResourceUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class ResourceMsgConstructorV2 extends BaseResourceMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public ResourceUpdateMsg constructResourceUpdatedMsg(UpdateMsgType msgType, TbResource tbResource) { |
|
||||
return ResourceUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(tbResource)) |
|
||||
.setIdMSB(tbResource.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(tbResource.getId().getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,133 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.rule; |
|
||||
|
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode; |
|
||||
import lombok.AllArgsConstructor; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.id.TenantId; |
|
||||
import org.thingsboard.server.common.data.rule.NodeConnectionInfo; |
|
||||
import org.thingsboard.server.common.data.rule.RuleChainConnectionInfo; |
|
||||
import org.thingsboard.server.common.data.rule.RuleChainMetaData; |
|
||||
import org.thingsboard.server.common.data.rule.RuleNode; |
|
||||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|
||||
import org.thingsboard.server.gen.edge.v1.NodeConnectionInfoProto; |
|
||||
import org.thingsboard.server.gen.edge.v1.RuleChainConnectionInfoProto; |
|
||||
import org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.RuleNodeProto; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
|
|
||||
import java.util.ArrayList; |
|
||||
import java.util.List; |
|
||||
import java.util.NavigableSet; |
|
||||
|
|
||||
@Slf4j |
|
||||
@AllArgsConstructor |
|
||||
public abstract class BaseRuleChainMetadataConstructor implements RuleChainMetadataConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public RuleChainMetadataUpdateMsg constructRuleChainMetadataUpdatedMsg(TenantId tenantId, |
|
||||
UpdateMsgType msgType, |
|
||||
RuleChainMetaData ruleChainMetaData, |
|
||||
EdgeVersion edgeVersion) { |
|
||||
RuleChainMetadataUpdateMsg.Builder builder = RuleChainMetadataUpdateMsg.newBuilder(); |
|
||||
constructRuleChainMetadataUpdatedMsg(tenantId, builder, ruleChainMetaData); |
|
||||
builder.setMsgType(msgType); |
|
||||
return builder.build(); |
|
||||
} |
|
||||
|
|
||||
protected abstract void constructRuleChainMetadataUpdatedMsg(TenantId tenantId, |
|
||||
RuleChainMetadataUpdateMsg.Builder builder, |
|
||||
RuleChainMetaData ruleChainMetaData); |
|
||||
|
|
||||
protected List<NodeConnectionInfoProto> constructConnections(List<NodeConnectionInfo> connections) { |
|
||||
List<NodeConnectionInfoProto> result = new ArrayList<>(); |
|
||||
if (connections != null && !connections.isEmpty()) { |
|
||||
for (NodeConnectionInfo connection : connections) { |
|
||||
result.add(constructConnection(connection)); |
|
||||
} |
|
||||
} |
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
private NodeConnectionInfoProto constructConnection(NodeConnectionInfo connection) { |
|
||||
return NodeConnectionInfoProto.newBuilder() |
|
||||
.setFromIndex(connection.getFromIndex()) |
|
||||
.setToIndex(connection.getToIndex()) |
|
||||
.setType(connection.getType()) |
|
||||
.build(); |
|
||||
} |
|
||||
|
|
||||
protected List<RuleNodeProto> constructNodes(List<RuleNode> nodes) { |
|
||||
List<RuleNodeProto> result = new ArrayList<>(); |
|
||||
if (nodes != null && !nodes.isEmpty()) { |
|
||||
for (RuleNode node : nodes) { |
|
||||
result.add(constructNode(node)); |
|
||||
} |
|
||||
} |
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
private RuleNodeProto constructNode(RuleNode node) { |
|
||||
return RuleNodeProto.newBuilder() |
|
||||
.setIdMSB(node.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(node.getId().getId().getLeastSignificantBits()) |
|
||||
.setType(node.getType()) |
|
||||
.setName(node.getName()) |
|
||||
.setDebugSettings(JacksonUtil.toString(node.getDebugSettings())) |
|
||||
.setConfiguration(JacksonUtil.toString(node.getConfiguration())) |
|
||||
.setAdditionalInfo(JacksonUtil.toString(node.getAdditionalInfo())) |
|
||||
.setSingletonMode(node.isSingletonMode()) |
|
||||
.setConfigurationVersion(node.getConfigurationVersion()) |
|
||||
.build(); |
|
||||
} |
|
||||
|
|
||||
protected List<RuleChainConnectionInfoProto> constructRuleChainConnections(List<RuleChainConnectionInfo> ruleChainConnections, |
|
||||
NavigableSet<Integer> removedNodeIndexes) { |
|
||||
List<RuleChainConnectionInfoProto> result = new ArrayList<>(); |
|
||||
if (ruleChainConnections != null && !ruleChainConnections.isEmpty()) { |
|
||||
for (RuleChainConnectionInfo ruleChainConnectionInfo : ruleChainConnections) { |
|
||||
if (!removedNodeIndexes.isEmpty()) { // 3_3_0 only
|
|
||||
int fromIndex = ruleChainConnectionInfo.getFromIndex(); |
|
||||
// decrease index because of removed nodes
|
|
||||
for (Integer removedIndex : removedNodeIndexes) { |
|
||||
if (fromIndex > removedIndex) { |
|
||||
fromIndex = fromIndex - 1; |
|
||||
} |
|
||||
} |
|
||||
ruleChainConnectionInfo.setFromIndex(fromIndex); |
|
||||
ObjectNode additionalInfo = (ObjectNode) ruleChainConnectionInfo.getAdditionalInfo(); |
|
||||
if (additionalInfo.get("ruleChainNodeId") == null) { |
|
||||
additionalInfo.put("ruleChainNodeId", "rule-chain-node-UNDEFINED"); |
|
||||
} |
|
||||
} |
|
||||
result.add(constructRuleChainConnection(ruleChainConnectionInfo)); |
|
||||
} |
|
||||
} |
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
private RuleChainConnectionInfoProto constructRuleChainConnection(RuleChainConnectionInfo ruleChainConnectionInfo) { |
|
||||
return RuleChainConnectionInfoProto.newBuilder() |
|
||||
.setFromIndex(ruleChainConnectionInfo.getFromIndex()) |
|
||||
.setTargetRuleChainIdMSB(ruleChainConnectionInfo.getTargetRuleChainId().getId().getMostSignificantBits()) |
|
||||
.setTargetRuleChainIdLSB(ruleChainConnectionInfo.getTargetRuleChainId().getId().getLeastSignificantBits()) |
|
||||
.setType(ruleChainConnectionInfo.getType()) |
|
||||
.setAdditionalInfo(JacksonUtil.toString(ruleChainConnectionInfo.getAdditionalInfo())) |
|
||||
.build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,44 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.rule; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.id.RuleChainId; |
|
||||
import org.thingsboard.server.common.data.id.TenantId; |
|
||||
import org.thingsboard.server.common.data.rule.RuleChainMetaData; |
|
||||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|
||||
import org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
|
|
||||
public abstract class BaseRuleChainMsgConstructor implements RuleChainMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public RuleChainUpdateMsg constructRuleChainDeleteMsg(RuleChainId ruleChainId) { |
|
||||
return RuleChainUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(ruleChainId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(ruleChainId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public RuleChainMetadataUpdateMsg constructRuleChainMetadataUpdatedMsg(TenantId tenantId, |
|
||||
UpdateMsgType msgType, |
|
||||
RuleChainMetaData ruleChainMetaData, |
|
||||
EdgeVersion edgeVersion) { |
|
||||
RuleChainMetadataConstructor ruleChainMetadataConstructor = RuleChainMetadataConstructorFactory.getByEdgeVersion(edgeVersion); |
|
||||
return ruleChainMetadataConstructor.constructRuleChainMetadataUpdatedMsg(tenantId, msgType, ruleChainMetaData, edgeVersion); |
|
||||
} |
|
||||
} |
|
||||
@ -1,30 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.rule; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.id.TenantId; |
|
||||
import org.thingsboard.server.common.data.rule.RuleChainMetaData; |
|
||||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|
||||
import org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
|
|
||||
public interface RuleChainMetadataConstructor { |
|
||||
|
|
||||
RuleChainMetadataUpdateMsg constructRuleChainMetadataUpdatedMsg(TenantId tenantId, |
|
||||
UpdateMsgType msgType, |
|
||||
RuleChainMetaData ruleChainMetaData, |
|
||||
EdgeVersion edgeVersion); |
|
||||
} |
|
||||
@ -1,36 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.rule; |
|
||||
|
|
||||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|
||||
|
|
||||
public final class RuleChainMetadataConstructorFactory { |
|
||||
|
|
||||
public static RuleChainMetadataConstructor getByEdgeVersion(EdgeVersion edgeVersion) { |
|
||||
switch (edgeVersion) { |
|
||||
case V_3_3_0: |
|
||||
return new RuleChainMetadataConstructorV330(); |
|
||||
case V_3_3_3: |
|
||||
case V_3_4_0: |
|
||||
case V_3_6_0: |
|
||||
case V_3_6_1: |
|
||||
return new RuleChainMetadataConstructorV340(); |
|
||||
case V_3_6_2: |
|
||||
default: |
|
||||
return new RuleChainMetadataConstructorV362(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,166 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.rule; |
|
||||
|
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.rule.engine.flow.TbRuleChainInputNode; |
|
||||
import org.thingsboard.rule.engine.flow.TbRuleChainInputNodeConfiguration; |
|
||||
import org.thingsboard.rule.engine.flow.TbRuleChainOutputNode; |
|
||||
import org.thingsboard.server.common.data.id.RuleChainId; |
|
||||
import org.thingsboard.server.common.data.id.TenantId; |
|
||||
import org.thingsboard.server.common.data.rule.NodeConnectionInfo; |
|
||||
import org.thingsboard.server.common.data.rule.RuleChainConnectionInfo; |
|
||||
import org.thingsboard.server.common.data.rule.RuleChainMetaData; |
|
||||
import org.thingsboard.server.common.data.rule.RuleNode; |
|
||||
import org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg; |
|
||||
|
|
||||
import java.util.ArrayList; |
|
||||
import java.util.List; |
|
||||
import java.util.NavigableSet; |
|
||||
import java.util.TreeSet; |
|
||||
import java.util.UUID; |
|
||||
import java.util.stream.Collectors; |
|
||||
|
|
||||
@Slf4j |
|
||||
public class RuleChainMetadataConstructorV330 extends BaseRuleChainMetadataConstructor { |
|
||||
|
|
||||
private static final String RULE_CHAIN_INPUT_NODE = TbRuleChainInputNode.class.getName(); |
|
||||
private static final String TB_RULE_CHAIN_OUTPUT_NODE = TbRuleChainOutputNode.class.getName(); |
|
||||
|
|
||||
@Override |
|
||||
protected void constructRuleChainMetadataUpdatedMsg(TenantId tenantId, |
|
||||
RuleChainMetadataUpdateMsg.Builder builder, |
|
||||
RuleChainMetaData ruleChainMetaData) { |
|
||||
builder.setRuleChainIdMSB(ruleChainMetaData.getRuleChainId().getId().getMostSignificantBits()) |
|
||||
.setRuleChainIdLSB(ruleChainMetaData.getRuleChainId().getId().getLeastSignificantBits()); |
|
||||
List<RuleNode> supportedNodes = filterNodes(ruleChainMetaData.getNodes()); |
|
||||
|
|
||||
NavigableSet<Integer> removedNodeIndexes = getRemovedNodeIndexes(ruleChainMetaData.getNodes(), ruleChainMetaData.getConnections()); |
|
||||
List<NodeConnectionInfo> connections = filterConnections(ruleChainMetaData.getNodes(), ruleChainMetaData.getConnections(), removedNodeIndexes); |
|
||||
|
|
||||
List<RuleChainConnectionInfo> ruleChainConnections = new ArrayList<>(); |
|
||||
if (ruleChainMetaData.getRuleChainConnections() != null) { |
|
||||
ruleChainConnections.addAll(ruleChainMetaData.getRuleChainConnections()); |
|
||||
} |
|
||||
ruleChainConnections.addAll(addRuleChainConnections(ruleChainMetaData.getNodes(), ruleChainMetaData.getConnections())); |
|
||||
builder.addAllNodes(constructNodes(supportedNodes)) |
|
||||
.addAllConnections(constructConnections(connections)) |
|
||||
.addAllRuleChainConnections(constructRuleChainConnections(ruleChainConnections, removedNodeIndexes)); |
|
||||
if (ruleChainMetaData.getFirstNodeIndex() != null) { |
|
||||
Integer firstNodeIndex = ruleChainMetaData.getFirstNodeIndex(); |
|
||||
// decrease index because of removed nodes
|
|
||||
for (Integer removedIndex : removedNodeIndexes) { |
|
||||
if (firstNodeIndex > removedIndex) { |
|
||||
firstNodeIndex = firstNodeIndex - 1; |
|
||||
} |
|
||||
} |
|
||||
builder.setFirstNodeIndex(firstNodeIndex); |
|
||||
} else { |
|
||||
builder.setFirstNodeIndex(-1); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private NavigableSet<Integer> getRemovedNodeIndexes(List<RuleNode> nodes, List<NodeConnectionInfo> connections) { |
|
||||
TreeSet<Integer> removedIndexes = new TreeSet<>(); |
|
||||
for (NodeConnectionInfo connection : connections) { |
|
||||
for (int i = 0; i < nodes.size(); i++) { |
|
||||
RuleNode node = nodes.get(i); |
|
||||
if (node.getType().equalsIgnoreCase(RULE_CHAIN_INPUT_NODE) |
|
||||
|| node.getType().equalsIgnoreCase(TB_RULE_CHAIN_OUTPUT_NODE)) { |
|
||||
if (connection.getFromIndex() == i || connection.getToIndex() == i) { |
|
||||
removedIndexes.add(i); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
return removedIndexes.descendingSet(); |
|
||||
} |
|
||||
|
|
||||
private List<NodeConnectionInfo> filterConnections(List<RuleNode> nodes, |
|
||||
List<NodeConnectionInfo> connections, |
|
||||
NavigableSet<Integer> removedNodeIndexes) { |
|
||||
List<NodeConnectionInfo> result = new ArrayList<>(); |
|
||||
if (connections != null) { |
|
||||
result = connections.stream().filter(conn -> { |
|
||||
for (int i = 0; i < nodes.size(); i++) { |
|
||||
RuleNode node = nodes.get(i); |
|
||||
if (node.getType().equalsIgnoreCase(RULE_CHAIN_INPUT_NODE) |
|
||||
|| node.getType().equalsIgnoreCase(TB_RULE_CHAIN_OUTPUT_NODE)) { |
|
||||
if (conn.getFromIndex() == i || conn.getToIndex() == i) { |
|
||||
return false; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
return true; |
|
||||
}).map(conn -> { |
|
||||
NodeConnectionInfo newConn = new NodeConnectionInfo(); |
|
||||
newConn.setFromIndex(conn.getFromIndex()); |
|
||||
newConn.setToIndex(conn.getToIndex()); |
|
||||
newConn.setType(conn.getType()); |
|
||||
return newConn; |
|
||||
}).collect(Collectors.toList()); |
|
||||
} |
|
||||
|
|
||||
// decrease index because of removed nodes
|
|
||||
for (Integer removedIndex : removedNodeIndexes) { |
|
||||
for (NodeConnectionInfo newConn : result) { |
|
||||
if (newConn.getToIndex() > removedIndex) { |
|
||||
newConn.setToIndex(newConn.getToIndex() - 1); |
|
||||
} |
|
||||
if (newConn.getFromIndex() > removedIndex) { |
|
||||
newConn.setFromIndex(newConn.getFromIndex() - 1); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
private List<RuleNode> filterNodes(List<RuleNode> nodes) { |
|
||||
List<RuleNode> result = new ArrayList<>(); |
|
||||
for (RuleNode node : nodes) { |
|
||||
if (RULE_CHAIN_INPUT_NODE.equals(node.getType()) |
|
||||
|| TB_RULE_CHAIN_OUTPUT_NODE.equals(node.getType())) { |
|
||||
log.trace("Skipping not supported rule node {}", node); |
|
||||
} else { |
|
||||
result.add(node); |
|
||||
} |
|
||||
} |
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
private List<RuleChainConnectionInfo> addRuleChainConnections(List<RuleNode> nodes, List<NodeConnectionInfo> connections) { |
|
||||
List<RuleChainConnectionInfo> result = new ArrayList<>(); |
|
||||
for (int i = 0; i < nodes.size(); i++) { |
|
||||
RuleNode node = nodes.get(i); |
|
||||
if (node.getType().equalsIgnoreCase(RULE_CHAIN_INPUT_NODE)) { |
|
||||
for (NodeConnectionInfo connection : connections) { |
|
||||
if (connection.getToIndex() == i) { |
|
||||
RuleChainConnectionInfo e = new RuleChainConnectionInfo(); |
|
||||
e.setFromIndex(connection.getFromIndex()); |
|
||||
TbRuleChainInputNodeConfiguration configuration = JacksonUtil.treeToValue(node.getConfiguration(), TbRuleChainInputNodeConfiguration.class); |
|
||||
e.setTargetRuleChainId(new RuleChainId(UUID.fromString(configuration.getRuleChainId()))); |
|
||||
e.setAdditionalInfo(node.getAdditionalInfo()); |
|
||||
e.setType(connection.getType()); |
|
||||
result.add(e); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
return result; |
|
||||
} |
|
||||
} |
|
||||
@ -1,43 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.rule; |
|
||||
|
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.thingsboard.server.common.data.id.TenantId; |
|
||||
import org.thingsboard.server.common.data.rule.RuleChainMetaData; |
|
||||
import org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg; |
|
||||
|
|
||||
import java.util.TreeSet; |
|
||||
|
|
||||
@Slf4j |
|
||||
public class RuleChainMetadataConstructorV340 extends BaseRuleChainMetadataConstructor { |
|
||||
|
|
||||
@Override |
|
||||
protected void constructRuleChainMetadataUpdatedMsg(TenantId tenantId, |
|
||||
RuleChainMetadataUpdateMsg.Builder builder, |
|
||||
RuleChainMetaData ruleChainMetaData) { |
|
||||
builder.setRuleChainIdMSB(ruleChainMetaData.getRuleChainId().getId().getMostSignificantBits()) |
|
||||
.setRuleChainIdLSB(ruleChainMetaData.getRuleChainId().getId().getLeastSignificantBits()); |
|
||||
builder.addAllNodes(constructNodes(ruleChainMetaData.getNodes())) |
|
||||
.addAllConnections(constructConnections(ruleChainMetaData.getConnections())) |
|
||||
.addAllRuleChainConnections(constructRuleChainConnections(ruleChainMetaData.getRuleChainConnections(), new TreeSet<>())); |
|
||||
if (ruleChainMetaData.getFirstNodeIndex() != null) { |
|
||||
builder.setFirstNodeIndex(ruleChainMetaData.getFirstNodeIndex()); |
|
||||
} else { |
|
||||
builder.setFirstNodeIndex(-1); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,29 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.rule; |
|
||||
|
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.id.TenantId; |
|
||||
import org.thingsboard.server.common.data.rule.RuleChainMetaData; |
|
||||
import org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg; |
|
||||
|
|
||||
public class RuleChainMetadataConstructorV362 extends BaseRuleChainMetadataConstructor { |
|
||||
|
|
||||
@Override |
|
||||
protected void constructRuleChainMetadataUpdatedMsg(TenantId tenantId, RuleChainMetadataUpdateMsg.Builder builder, RuleChainMetaData ruleChainMetaData) { |
|
||||
builder.setEntity(JacksonUtil.toString(ruleChainMetaData)); |
|
||||
} |
|
||||
} |
|
||||
@ -1,38 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.rule; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.id.RuleChainId; |
|
||||
import org.thingsboard.server.common.data.id.TenantId; |
|
||||
import org.thingsboard.server.common.data.rule.RuleChain; |
|
||||
import org.thingsboard.server.common.data.rule.RuleChainMetaData; |
|
||||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|
||||
import org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|
||||
|
|
||||
public interface RuleChainMsgConstructor extends MsgConstructor { |
|
||||
|
|
||||
RuleChainUpdateMsg constructRuleChainUpdatedMsg(UpdateMsgType msgType, RuleChain ruleChain, boolean isRoot); |
|
||||
|
|
||||
RuleChainUpdateMsg constructRuleChainDeleteMsg(RuleChainId ruleChainId); |
|
||||
|
|
||||
RuleChainMetadataUpdateMsg constructRuleChainMetadataUpdatedMsg(TenantId tenantId, |
|
||||
UpdateMsgType msgType, |
|
||||
RuleChainMetaData ruleChainMetaData, |
|
||||
EdgeVersion edgeVersion); |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.rule; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.BaseMsgConstructorFactory; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class RuleChainMsgConstructorFactory extends BaseMsgConstructorFactory<RuleChainMsgConstructorV1, RuleChainMsgConstructorV2> { |
|
||||
|
|
||||
} |
|
||||
@ -1,45 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.rule; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.rule.RuleChain; |
|
||||
import org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class RuleChainMsgConstructorV1 extends BaseRuleChainMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public RuleChainUpdateMsg constructRuleChainUpdatedMsg(UpdateMsgType msgType, RuleChain ruleChain, boolean isRoot) { |
|
||||
RuleChainUpdateMsg.Builder builder = RuleChainUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(ruleChain.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(ruleChain.getId().getId().getLeastSignificantBits()) |
|
||||
.setName(ruleChain.getName()) |
|
||||
.setRoot(isRoot) |
|
||||
.setDebugMode(ruleChain.isDebugMode()) |
|
||||
.setConfiguration(JacksonUtil.toString(ruleChain.getConfiguration())); |
|
||||
if (ruleChain.getFirstRuleNodeId() != null) { |
|
||||
builder.setFirstRuleNodeIdMSB(ruleChain.getFirstRuleNodeId().getId().getMostSignificantBits()) |
|
||||
.setFirstRuleNodeIdLSB(ruleChain.getFirstRuleNodeId().getId().getLeastSignificantBits()); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,39 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.rule; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.rule.RuleChain; |
|
||||
import org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class RuleChainMsgConstructorV2 extends BaseRuleChainMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public RuleChainUpdateMsg constructRuleChainUpdatedMsg(UpdateMsgType msgType, RuleChain ruleChain, boolean isRoot) { |
|
||||
boolean isTemplateRoot = ruleChain.isRoot(); |
|
||||
ruleChain.setRoot(isRoot); |
|
||||
RuleChainUpdateMsg result = RuleChainUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(ruleChain)) |
|
||||
.setIdMSB(ruleChain.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(ruleChain.getId().getId().getLeastSignificantBits()).build(); |
|
||||
ruleChain.setRoot(isTemplateRoot); |
|
||||
return result; |
|
||||
} |
|
||||
} |
|
||||
@ -1,25 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.settings; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.AdminSettings; |
|
||||
import org.thingsboard.server.gen.edge.v1.AdminSettingsUpdateMsg; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|
||||
|
|
||||
public interface AdminSettingsMsgConstructor extends MsgConstructor { |
|
||||
|
|
||||
AdminSettingsUpdateMsg constructAdminSettingsUpdateMsg(AdminSettings adminSettings); |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.settings; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.BaseMsgConstructorFactory; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class AdminSettingsMsgConstructorFactory extends BaseMsgConstructorFactory<AdminSettingsMsgConstructorV1, AdminSettingsMsgConstructorV2> { |
|
||||
|
|
||||
} |
|
||||
@ -1,39 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.settings; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.AdminSettings; |
|
||||
import org.thingsboard.server.common.data.id.TenantId; |
|
||||
import org.thingsboard.server.gen.edge.v1.AdminSettingsUpdateMsg; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class AdminSettingsMsgConstructorV1 implements AdminSettingsMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public AdminSettingsUpdateMsg constructAdminSettingsUpdateMsg(AdminSettings adminSettings) { |
|
||||
AdminSettingsUpdateMsg.Builder builder = AdminSettingsUpdateMsg.newBuilder() |
|
||||
.setKey(adminSettings.getKey()) |
|
||||
.setJsonValue(JacksonUtil.toString(adminSettings.getJsonValue())); |
|
||||
if (TenantId.SYS_TENANT_ID.equals(adminSettings.getTenantId())) { |
|
||||
builder.setIsSystem(true); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,32 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.settings; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.AdminSettings; |
|
||||
import org.thingsboard.server.gen.edge.v1.AdminSettingsUpdateMsg; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class AdminSettingsMsgConstructorV2 implements AdminSettingsMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public AdminSettingsUpdateMsg constructAdminSettingsUpdateMsg(AdminSettings adminSettings) { |
|
||||
return AdminSettingsUpdateMsg.newBuilder().setEntity(JacksonUtil.toString(adminSettings)).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,110 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.telemetry; |
|
||||
|
|
||||
import com.google.gson.Gson; |
|
||||
import com.google.gson.JsonArray; |
|
||||
import com.google.gson.JsonElement; |
|
||||
import com.google.gson.JsonObject; |
|
||||
import com.google.gson.JsonPrimitive; |
|
||||
import com.google.gson.reflect.TypeToken; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.common.adaptor.JsonConverter; |
|
||||
import org.thingsboard.server.common.data.DataConstants; |
|
||||
import org.thingsboard.server.common.data.StringUtils; |
|
||||
import org.thingsboard.server.common.data.edge.EdgeEventActionType; |
|
||||
import org.thingsboard.server.common.data.id.EntityId; |
|
||||
import org.thingsboard.server.common.data.id.TenantId; |
|
||||
import org.thingsboard.server.gen.edge.v1.AttributeDeleteMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.EntityDataProto; |
|
||||
import org.thingsboard.server.gen.transport.TransportProtos; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
import java.util.List; |
|
||||
|
|
||||
@Slf4j |
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class EntityDataMsgConstructor { |
|
||||
|
|
||||
public EntityDataProto constructEntityDataMsg(TenantId tenantId, EntityId entityId, EdgeEventActionType actionType, JsonElement entityData) { |
|
||||
EntityDataProto.Builder builder = EntityDataProto.newBuilder() |
|
||||
.setEntityIdMSB(entityId.getId().getMostSignificantBits()) |
|
||||
.setEntityIdLSB(entityId.getId().getLeastSignificantBits()) |
|
||||
.setEntityType(entityId.getEntityType().name()); |
|
||||
switch (actionType) { |
|
||||
case TIMESERIES_UPDATED: |
|
||||
try { |
|
||||
JsonObject data = entityData.getAsJsonObject(); |
|
||||
long ts; |
|
||||
if (data.get("ts") != null && !data.get("ts").isJsonNull()) { |
|
||||
ts = data.getAsJsonPrimitive("ts").getAsLong(); |
|
||||
} else { |
|
||||
ts = System.currentTimeMillis(); |
|
||||
} |
|
||||
builder.setPostTelemetryMsg(JsonConverter.convertToTelemetryProto(data.getAsJsonObject("data"), ts)); |
|
||||
} catch (Exception e) { |
|
||||
log.warn("[{}][{}] Can't convert to telemetry proto, entityData [{}]", tenantId, entityId, entityData, e); |
|
||||
} |
|
||||
break; |
|
||||
case ATTRIBUTES_UPDATED: |
|
||||
try { |
|
||||
JsonObject data = entityData.getAsJsonObject(); |
|
||||
TransportProtos.PostAttributeMsg attributesUpdatedMsg = JsonConverter.convertToAttributesProto(data.getAsJsonObject("kv")); |
|
||||
builder.setAttributesUpdatedMsg(attributesUpdatedMsg); |
|
||||
builder.setPostAttributeScope(getScopeOfDefault(data)); |
|
||||
} catch (Exception e) { |
|
||||
log.warn("[{}][{}] Can't convert to AttributesUpdatedMsg proto, entityData [{}]", tenantId, entityId, entityData, e); |
|
||||
} |
|
||||
break; |
|
||||
case POST_ATTRIBUTES: |
|
||||
try { |
|
||||
JsonObject data = entityData.getAsJsonObject(); |
|
||||
TransportProtos.PostAttributeMsg postAttributesMsg = JsonConverter.convertToAttributesProto(data.getAsJsonObject("kv")); |
|
||||
builder.setPostAttributesMsg(postAttributesMsg); |
|
||||
builder.setPostAttributeScope(getScopeOfDefault(data)); |
|
||||
} catch (Exception e) { |
|
||||
log.warn("[{}][{}] Can't convert to PostAttributesMsg, entityData [{}]", tenantId, entityId, entityData, e); |
|
||||
} |
|
||||
break; |
|
||||
case ATTRIBUTES_DELETED: |
|
||||
try { |
|
||||
AttributeDeleteMsg.Builder attributeDeleteMsg = AttributeDeleteMsg.newBuilder(); |
|
||||
attributeDeleteMsg.setScope(entityData.getAsJsonObject().getAsJsonPrimitive("scope").getAsString()); |
|
||||
JsonArray jsonArray = entityData.getAsJsonObject().getAsJsonArray("keys"); |
|
||||
List<String> keys = new Gson().fromJson(jsonArray.toString(), new TypeToken<>(){}.getType()); |
|
||||
attributeDeleteMsg.addAllAttributeNames(keys); |
|
||||
attributeDeleteMsg.build(); |
|
||||
builder.setAttributeDeleteMsg(attributeDeleteMsg); |
|
||||
} catch (Exception e) { |
|
||||
log.warn("[{}][{}] Can't convert to AttributeDeleteMsg proto, entityData [{}]", tenantId, entityId, entityData, e); |
|
||||
} |
|
||||
break; |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
|
|
||||
private String getScopeOfDefault(JsonObject data) { |
|
||||
JsonPrimitive scope = data.getAsJsonPrimitive("scope"); |
|
||||
String result = DataConstants.SERVER_SCOPE; |
|
||||
if (scope != null && StringUtils.isNotBlank(scope.getAsString())) { |
|
||||
result = scope.getAsString(); |
|
||||
} |
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,31 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.tenant; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.Tenant; |
|
||||
import org.thingsboard.server.common.data.TenantProfile; |
|
||||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|
||||
import org.thingsboard.server.gen.edge.v1.TenantProfileUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.TenantUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|
||||
|
|
||||
public interface TenantMsgConstructor extends MsgConstructor { |
|
||||
|
|
||||
TenantUpdateMsg constructTenantUpdateMsg(UpdateMsgType msgType, Tenant tenant); |
|
||||
|
|
||||
TenantProfileUpdateMsg constructTenantProfileUpdateMsg(UpdateMsgType msgType, TenantProfile tenantProfile, EdgeVersion edgeVersion); |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.tenant; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.BaseMsgConstructorFactory; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class TenantMsgConstructorFactory extends BaseMsgConstructorFactory<TenantMsgConstructorV1, TenantMsgConstructorV2> { |
|
||||
|
|
||||
} |
|
||||
@ -1,111 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.tenant; |
|
||||
|
|
||||
import com.google.protobuf.ByteString; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.Tenant; |
|
||||
import org.thingsboard.server.common.data.TenantProfile; |
|
||||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|
||||
import org.thingsboard.server.gen.edge.v1.TenantProfileUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.TenantUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.utils.EdgeVersionUtils; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class TenantMsgConstructorV1 implements TenantMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public TenantUpdateMsg constructTenantUpdateMsg(UpdateMsgType msgType, Tenant tenant) { |
|
||||
TenantUpdateMsg.Builder builder = TenantUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(tenant.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(tenant.getId().getId().getLeastSignificantBits()) |
|
||||
.setTitle(tenant.getTitle()) |
|
||||
.setProfileIdMSB(tenant.getTenantProfileId().getId().getMostSignificantBits()) |
|
||||
.setProfileIdLSB(tenant.getTenantProfileId().getId().getLeastSignificantBits()) |
|
||||
.setRegion(tenant.getRegion()); |
|
||||
if (tenant.getCountry() != null) { |
|
||||
builder.setCountry(tenant.getCountry()); |
|
||||
} |
|
||||
if (tenant.getState() != null) { |
|
||||
builder.setState(tenant.getState()); |
|
||||
} |
|
||||
if (tenant.getCity() != null) { |
|
||||
builder.setCity(tenant.getCity()); |
|
||||
} |
|
||||
if (tenant.getAddress() != null) { |
|
||||
builder.setAddress(tenant.getAddress()); |
|
||||
} |
|
||||
if (tenant.getAddress2() != null) { |
|
||||
builder.setAddress2(tenant.getAddress2()); |
|
||||
} |
|
||||
if (tenant.getZip() != null) { |
|
||||
builder.setZip(tenant.getZip()); |
|
||||
} |
|
||||
if (tenant.getPhone() != null) { |
|
||||
builder.setPhone(tenant.getPhone()); |
|
||||
} |
|
||||
if (tenant.getEmail() != null) { |
|
||||
builder.setEmail(tenant.getEmail()); |
|
||||
} |
|
||||
if (tenant.getAdditionalInfo() != null) { |
|
||||
builder.setAdditionalInfo(JacksonUtil.toString(tenant.getAdditionalInfo())); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public TenantProfileUpdateMsg constructTenantProfileUpdateMsg(UpdateMsgType msgType, TenantProfile tenantProfile, EdgeVersion edgeVersion) { |
|
||||
tenantProfile = JacksonUtil.clone(tenantProfile); |
|
||||
// clear all config
|
|
||||
var tenantProfileData = tenantProfile.getProfileData(); |
|
||||
var configuration = tenantProfile.getDefaultProfileConfiguration(); |
|
||||
configuration.setRpcTtlDays(0); |
|
||||
configuration.setMaxJSExecutions(0); |
|
||||
configuration.setMaxREExecutions(0); |
|
||||
configuration.setMaxDPStorageDays(0); |
|
||||
configuration.setMaxTbelExecutions(0); |
|
||||
configuration.setQueueStatsTtlDays(0); |
|
||||
configuration.setMaxTransportMessages(0); |
|
||||
configuration.setDefaultStorageTtlDays(0); |
|
||||
configuration.setMaxTransportDataPoints(0); |
|
||||
configuration.setRuleEngineExceptionsTtlDays(0); |
|
||||
configuration.setMaxRuleNodeExecutionsPerMessage(0); |
|
||||
configuration.setMaxDebugModeDurationMinutes(0); |
|
||||
tenantProfileData.setConfiguration(configuration); |
|
||||
tenantProfile.setProfileData(tenantProfileData); |
|
||||
|
|
||||
ByteString profileData = EdgeVersionUtils.isEdgeVersionOlderThan(edgeVersion, EdgeVersion.V_3_6_2) ? |
|
||||
ByteString.empty() : ByteString.copyFrom(tenantProfile.getProfileDataBytes()); |
|
||||
TenantProfileUpdateMsg.Builder builder = TenantProfileUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(tenantProfile.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(tenantProfile.getId().getId().getLeastSignificantBits()) |
|
||||
.setName(tenantProfile.getName()) |
|
||||
.setDefault(tenantProfile.isDefault()) |
|
||||
.setIsolatedRuleChain(tenantProfile.isIsolatedTbRuleEngine()) |
|
||||
.setProfileDataBytes(profileData); |
|
||||
if (tenantProfile.getDescription() != null) { |
|
||||
builder.setDescription(tenantProfile.getDescription()); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,42 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.tenant; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.Tenant; |
|
||||
import org.thingsboard.server.common.data.TenantProfile; |
|
||||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|
||||
import org.thingsboard.server.gen.edge.v1.TenantProfileUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.TenantUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class TenantMsgConstructorV2 implements TenantMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public TenantUpdateMsg constructTenantUpdateMsg(UpdateMsgType msgType, Tenant tenant) { |
|
||||
return TenantUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(tenant)).build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public TenantProfileUpdateMsg constructTenantProfileUpdateMsg(UpdateMsgType msgType, TenantProfile tenantProfile, EdgeVersion edgeVersion) { |
|
||||
return TenantProfileUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(tenantProfile)).build(); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,31 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.user; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.id.UserId; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.gen.edge.v1.UserUpdateMsg; |
|
||||
|
|
||||
public abstract class BaseUserMsgConstructor implements UserMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public UserUpdateMsg constructUserDeleteMsg(UserId userId) { |
|
||||
return UserUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(userId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(userId.getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,33 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.user; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.User; |
|
||||
import org.thingsboard.server.common.data.id.UserId; |
|
||||
import org.thingsboard.server.common.data.security.UserCredentials; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.gen.edge.v1.UserCredentialsUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UserUpdateMsg; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|
||||
|
|
||||
public interface UserMsgConstructor extends MsgConstructor { |
|
||||
|
|
||||
UserUpdateMsg constructUserUpdatedMsg(UpdateMsgType msgType, User user); |
|
||||
|
|
||||
UserUpdateMsg constructUserDeleteMsg(UserId userId); |
|
||||
|
|
||||
UserCredentialsUpdateMsg constructUserCredentialsUpdatedMsg(UserCredentials userCredentials); |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.user; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.BaseMsgConstructorFactory; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class UserMsgConstructorFactory extends BaseMsgConstructorFactory<UserMsgConstructorV1, UserMsgConstructorV2> { |
|
||||
|
|
||||
} |
|
||||
@ -1,63 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.user; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.User; |
|
||||
import org.thingsboard.server.common.data.security.UserCredentials; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.gen.edge.v1.UserCredentialsUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UserUpdateMsg; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class UserMsgConstructorV1 extends BaseUserMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public UserUpdateMsg constructUserUpdatedMsg(UpdateMsgType msgType, User user) { |
|
||||
UserUpdateMsg.Builder builder = UserUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(user.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(user.getId().getId().getLeastSignificantBits()) |
|
||||
.setEmail(user.getEmail()) |
|
||||
.setAuthority(user.getAuthority().name()); |
|
||||
if (user.getCustomerId() != null) { |
|
||||
builder.setCustomerIdMSB(user.getCustomerId().getId().getMostSignificantBits()); |
|
||||
builder.setCustomerIdLSB(user.getCustomerId().getId().getLeastSignificantBits()); |
|
||||
} |
|
||||
if (user.getFirstName() != null) { |
|
||||
builder.setFirstName(user.getFirstName()); |
|
||||
} |
|
||||
if (user.getLastName() != null) { |
|
||||
builder.setLastName(user.getLastName()); |
|
||||
} |
|
||||
if (user.getAdditionalInfo() != null) { |
|
||||
builder.setAdditionalInfo(JacksonUtil.toString(user.getAdditionalInfo())); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public UserCredentialsUpdateMsg constructUserCredentialsUpdatedMsg(UserCredentials userCredentials) { |
|
||||
return UserCredentialsUpdateMsg.newBuilder() |
|
||||
.setUserIdMSB(userCredentials.getUserId().getId().getMostSignificantBits()) |
|
||||
.setUserIdLSB(userCredentials.getUserId().getId().getLeastSignificantBits()) |
|
||||
.setEnabled(userCredentials.isEnabled()) |
|
||||
.setPassword(userCredentials.getPassword()).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,42 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.user; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.User; |
|
||||
import org.thingsboard.server.common.data.security.UserCredentials; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.gen.edge.v1.UserCredentialsUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.UserUpdateMsg; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class UserMsgConstructorV2 extends BaseUserMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public UserUpdateMsg constructUserUpdatedMsg(UpdateMsgType msgType, User user) { |
|
||||
return UserUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(user)) |
|
||||
.setIdMSB(user.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(user.getId().getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public UserCredentialsUpdateMsg constructUserCredentialsUpdatedMsg(UserCredentials userCredentials) { |
|
||||
return UserCredentialsUpdateMsg.newBuilder().setEntity(JacksonUtil.toString(userCredentials)).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,43 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.widget; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.id.WidgetTypeId; |
|
||||
import org.thingsboard.server.common.data.id.WidgetsBundleId; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg; |
|
||||
|
|
||||
public abstract class BaseWidgetMsgConstructor implements WidgetMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public WidgetsBundleUpdateMsg constructWidgetsBundleDeleteMsg(WidgetsBundleId widgetsBundleId) { |
|
||||
return WidgetsBundleUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(widgetsBundleId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(widgetsBundleId.getId().getLeastSignificantBits()) |
|
||||
.build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public WidgetTypeUpdateMsg constructWidgetTypeDeleteMsg(WidgetTypeId widgetTypeId) { |
|
||||
return WidgetTypeUpdateMsg.newBuilder() |
|
||||
.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
||||
.setIdMSB(widgetTypeId.getId().getMostSignificantBits()) |
|
||||
.setIdLSB(widgetTypeId.getId().getLeastSignificantBits()) |
|
||||
.build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,39 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.widget; |
|
||||
|
|
||||
import org.thingsboard.server.common.data.id.WidgetTypeId; |
|
||||
import org.thingsboard.server.common.data.id.WidgetsBundleId; |
|
||||
import org.thingsboard.server.common.data.widget.WidgetTypeDetails; |
|
||||
import org.thingsboard.server.common.data.widget.WidgetsBundle; |
|
||||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.MsgConstructor; |
|
||||
|
|
||||
import java.util.List; |
|
||||
|
|
||||
public interface WidgetMsgConstructor extends MsgConstructor { |
|
||||
|
|
||||
WidgetsBundleUpdateMsg constructWidgetsBundleUpdateMsg(UpdateMsgType msgType, WidgetsBundle widgetsBundle, List<String> widgets); |
|
||||
|
|
||||
WidgetsBundleUpdateMsg constructWidgetsBundleDeleteMsg(WidgetsBundleId widgetsBundleId); |
|
||||
|
|
||||
WidgetTypeUpdateMsg constructWidgetTypeUpdateMsg(UpdateMsgType msgType, WidgetTypeDetails widgetTypeDetails, EdgeVersion edgeVersion); |
|
||||
|
|
||||
WidgetTypeUpdateMsg constructWidgetTypeDeleteMsg(WidgetTypeId widgetTypeId); |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.widget; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.constructor.BaseMsgConstructorFactory; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class WidgetMsgConstructorFactory extends BaseMsgConstructorFactory<WidgetMsgConstructorV1, WidgetMsgConstructorV2> { |
|
||||
|
|
||||
} |
|
||||
@ -1,115 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.widget; |
|
||||
|
|
||||
import com.google.protobuf.ByteString; |
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.id.TenantId; |
|
||||
import org.thingsboard.server.common.data.widget.WidgetTypeDetails; |
|
||||
import org.thingsboard.server.common.data.widget.WidgetsBundle; |
|
||||
import org.thingsboard.server.dao.resource.ImageService; |
|
||||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.utils.EdgeVersionUtils; |
|
||||
|
|
||||
import java.nio.charset.StandardCharsets; |
|
||||
import java.util.Arrays; |
|
||||
import java.util.List; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class WidgetMsgConstructorV1 extends BaseWidgetMsgConstructor { |
|
||||
|
|
||||
@Autowired |
|
||||
private ImageService imageService; |
|
||||
|
|
||||
@Override |
|
||||
public WidgetsBundleUpdateMsg constructWidgetsBundleUpdateMsg(UpdateMsgType msgType, WidgetsBundle widgetsBundle, List<String> widgets) { |
|
||||
widgetsBundle = JacksonUtil.clone(widgetsBundle); |
|
||||
imageService.inlineImageForEdge(widgetsBundle); |
|
||||
WidgetsBundleUpdateMsg.Builder builder = WidgetsBundleUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(widgetsBundle.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(widgetsBundle.getId().getId().getLeastSignificantBits()) |
|
||||
.setTitle(widgetsBundle.getTitle()) |
|
||||
.setAlias(widgetsBundle.getAlias()); |
|
||||
if (widgetsBundle.getImage() != null) { |
|
||||
builder.setImage(ByteString.copyFrom(widgetsBundle.getImage().getBytes(StandardCharsets.UTF_8))); |
|
||||
} |
|
||||
if (widgetsBundle.getDescription() != null) { |
|
||||
builder.setDescription(widgetsBundle.getDescription()); |
|
||||
} |
|
||||
if (widgetsBundle.getOrder() != null) { |
|
||||
builder.setOrder(widgetsBundle.getOrder()); |
|
||||
} |
|
||||
if (widgetsBundle.getTenantId().equals(TenantId.SYS_TENANT_ID)) { |
|
||||
builder.setIsSystem(true); |
|
||||
} |
|
||||
builder.setWidgets(JacksonUtil.toString(widgets)); |
|
||||
return builder.build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public WidgetTypeUpdateMsg constructWidgetTypeUpdateMsg(UpdateMsgType msgType, WidgetTypeDetails widgetTypeDetails, EdgeVersion edgeVersion) { |
|
||||
widgetTypeDetails = JacksonUtil.clone(widgetTypeDetails); |
|
||||
imageService.inlineImagesForEdge(widgetTypeDetails); |
|
||||
WidgetTypeUpdateMsg.Builder builder = WidgetTypeUpdateMsg.newBuilder() |
|
||||
.setMsgType(msgType) |
|
||||
.setIdMSB(widgetTypeDetails.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(widgetTypeDetails.getId().getId().getLeastSignificantBits()); |
|
||||
if (widgetTypeDetails.getFqn() != null) { |
|
||||
builder.setFqn(widgetTypeDetails.getFqn()); |
|
||||
if (widgetTypeDetails.getFqn().contains(".")) { |
|
||||
String[] aliases = widgetTypeDetails.getFqn().split("\\.", 2); |
|
||||
if (aliases.length == 2) { |
|
||||
builder.setBundleAlias(aliases[0]); |
|
||||
builder.setAlias(aliases[1]); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
if (widgetTypeDetails.getName() != null) { |
|
||||
builder.setName(widgetTypeDetails.getName()); |
|
||||
} |
|
||||
if (widgetTypeDetails.getDescriptor() != null) { |
|
||||
builder.setDescriptorJson(JacksonUtil.toString(widgetTypeDetails.getDescriptor())); |
|
||||
} |
|
||||
if (widgetTypeDetails.getTenantId().equals(TenantId.SYS_TENANT_ID)) { |
|
||||
builder.setIsSystem(true); |
|
||||
} |
|
||||
if (widgetTypeDetails.getImage() != null) { |
|
||||
builder.setImage(widgetTypeDetails.getImage()); |
|
||||
} |
|
||||
if (widgetTypeDetails.getDescription() != null) { |
|
||||
if (EdgeVersionUtils.isEdgeVersionOlderThan(edgeVersion, EdgeVersion.V_3_6_0) && |
|
||||
widgetTypeDetails.getDescription().length() > 255) { |
|
||||
builder.setDescription(widgetTypeDetails.getDescription().substring(0, 254)); |
|
||||
} else { |
|
||||
builder.setDescription(widgetTypeDetails.getDescription()); |
|
||||
} |
|
||||
} |
|
||||
builder.setDeprecated(widgetTypeDetails.isDeprecated()); |
|
||||
if (widgetTypeDetails.getTags() != null) { |
|
||||
builder.addAllTags(Arrays.asList(widgetTypeDetails.getTags())); |
|
||||
} |
|
||||
return builder.build(); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,48 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.widget; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.widget.WidgetTypeDetails; |
|
||||
import org.thingsboard.server.common.data.widget.WidgetsBundle; |
|
||||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|
||||
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
||||
import org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg; |
|
||||
import org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
import java.util.List; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class WidgetMsgConstructorV2 extends BaseWidgetMsgConstructor { |
|
||||
|
|
||||
@Override |
|
||||
public WidgetsBundleUpdateMsg constructWidgetsBundleUpdateMsg(UpdateMsgType msgType, WidgetsBundle widgetsBundle, List<String> widgets) { |
|
||||
return WidgetsBundleUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(widgetsBundle)) |
|
||||
.setWidgets(JacksonUtil.toString(widgets)) |
|
||||
.setIdMSB(widgetsBundle.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(widgetsBundle.getId().getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public WidgetTypeUpdateMsg constructWidgetTypeUpdateMsg(UpdateMsgType msgType, WidgetTypeDetails widgetTypeDetails, EdgeVersion edgeVersion) { |
|
||||
return WidgetTypeUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(widgetTypeDetails)) |
|
||||
.setIdMSB(widgetTypeDetails.getId().getId().getMostSignificantBits()) |
|
||||
.setIdLSB(widgetTypeDetails.getId().getId().getLeastSignificantBits()).build(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,40 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.processor; |
|
||||
|
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public abstract class BaseEdgeProcessorFactory<T extends EdgeProcessor, U extends EdgeProcessor> { |
|
||||
|
|
||||
@Autowired |
|
||||
protected T v1Processor; |
|
||||
|
|
||||
@Autowired |
|
||||
protected U v2Processor; |
|
||||
|
|
||||
public EdgeProcessor getProcessorByEdgeVersion(EdgeVersion edgeVersion) { |
|
||||
return switch (edgeVersion) { |
|
||||
case V_3_3_0, V_3_3_3, V_3_4_0, V_3_6_0, V_3_6_1 -> v1Processor; |
|
||||
default -> v2Processor; |
|
||||
}; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.processor.alarm; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
import org.thingsboard.server.service.edge.rpc.processor.BaseEdgeProcessorFactory; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class AlarmEdgeProcessorFactory extends BaseEdgeProcessorFactory<AlarmEdgeProcessorV1, AlarmEdgeProcessorV2> { |
|
||||
|
|
||||
} |
|
||||
@ -1,69 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.processor.alarm; |
|
||||
|
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.EntityType; |
|
||||
import org.thingsboard.server.common.data.alarm.Alarm; |
|
||||
import org.thingsboard.server.common.data.alarm.AlarmSeverity; |
|
||||
import org.thingsboard.server.common.data.alarm.AlarmStatus; |
|
||||
import org.thingsboard.server.common.data.id.AlarmId; |
|
||||
import org.thingsboard.server.common.data.id.EntityId; |
|
||||
import org.thingsboard.server.common.data.id.TenantId; |
|
||||
import org.thingsboard.server.gen.edge.v1.AlarmUpdateMsg; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class AlarmEdgeProcessorV1 extends AlarmEdgeProcessor { |
|
||||
|
|
||||
@Override |
|
||||
protected Alarm constructAlarmFromUpdateMsg(TenantId tenantId, AlarmId alarmId, EntityId originatorId, AlarmUpdateMsg alarmUpdateMsg) { |
|
||||
Alarm alarm = new Alarm(); |
|
||||
alarm.setId(alarmId); |
|
||||
alarm.setTenantId(tenantId); |
|
||||
alarm.setOriginator(originatorId); |
|
||||
alarm.setType(alarmUpdateMsg.getName()); |
|
||||
alarm.setSeverity(AlarmSeverity.valueOf(alarmUpdateMsg.getSeverity())); |
|
||||
alarm.setStartTs(alarmUpdateMsg.getStartTs()); |
|
||||
AlarmStatus alarmStatus = AlarmStatus.valueOf(alarmUpdateMsg.getStatus()); |
|
||||
alarm.setClearTs(alarmUpdateMsg.getClearTs()); |
|
||||
alarm.setPropagate(alarmUpdateMsg.getPropagate()); |
|
||||
alarm.setCleared(alarmStatus.isCleared()); |
|
||||
alarm.setAcknowledged(alarmStatus.isAck()); |
|
||||
alarm.setAckTs(alarmUpdateMsg.getAckTs()); |
|
||||
alarm.setEndTs(alarmUpdateMsg.getEndTs()); |
|
||||
alarm.setDetails(JacksonUtil.toJsonNode(alarmUpdateMsg.getDetails())); |
|
||||
return alarm; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
protected EntityId getAlarmOriginatorFromMsg(TenantId tenantId, AlarmUpdateMsg alarmUpdateMsg) { |
|
||||
return getAlarmOriginator(tenantId, alarmUpdateMsg.getOriginatorName(), |
|
||||
EntityType.valueOf(alarmUpdateMsg.getOriginatorType())); |
|
||||
} |
|
||||
|
|
||||
private EntityId getAlarmOriginator(TenantId tenantId, String entityName, EntityType entityType) { |
|
||||
return switch (entityType) { |
|
||||
case DEVICE -> edgeCtx.getDeviceService().findDeviceByTenantIdAndName(tenantId, entityName).getId(); |
|
||||
case ASSET -> edgeCtx.getAssetService().findAssetByTenantIdAndName(tenantId, entityName).getId(); |
|
||||
case ENTITY_VIEW -> edgeCtx.getEntityViewService().findEntityViewByTenantIdAndName(tenantId, entityName).getId(); |
|
||||
default -> null; |
|
||||
}; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,44 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 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.processor.alarm; |
|
||||
|
|
||||
import org.springframework.context.annotation.Primary; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.thingsboard.common.util.JacksonUtil; |
|
||||
import org.thingsboard.server.common.data.alarm.Alarm; |
|
||||
import org.thingsboard.server.common.data.id.AlarmId; |
|
||||
import org.thingsboard.server.common.data.id.EntityId; |
|
||||
import org.thingsboard.server.common.data.id.TenantId; |
|
||||
import org.thingsboard.server.gen.edge.v1.AlarmUpdateMsg; |
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
||||
|
|
||||
@Primary |
|
||||
@Component |
|
||||
@TbCoreComponent |
|
||||
public class AlarmEdgeProcessorV2 extends AlarmEdgeProcessor { |
|
||||
|
|
||||
@Override |
|
||||
protected EntityId getAlarmOriginatorFromMsg(TenantId tenantId, AlarmUpdateMsg alarmUpdateMsg) { |
|
||||
Alarm alarm = JacksonUtil.fromString(alarmUpdateMsg.getEntity(), Alarm.class, true); |
|
||||
return alarm != null ? alarm.getOriginator() : null; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
protected Alarm constructAlarmFromUpdateMsg(TenantId tenantId, AlarmId alarmId, EntityId originatorId, AlarmUpdateMsg alarmUpdateMsg) { |
|
||||
return JacksonUtil.fromString(alarmUpdateMsg.getEntity(), Alarm.class, true); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -0,0 +1,93 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2024 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.processor.alarm.comment; |
||||
|
|
||||
|
import com.google.common.util.concurrent.Futures; |
||||
|
import com.google.common.util.concurrent.ListenableFuture; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.thingsboard.common.util.JacksonUtil; |
||||
|
import org.thingsboard.server.common.data.EdgeUtils; |
||||
|
import org.thingsboard.server.common.data.alarm.Alarm; |
||||
|
import org.thingsboard.server.common.data.alarm.AlarmComment; |
||||
|
import org.thingsboard.server.common.data.edge.EdgeEvent; |
||||
|
import org.thingsboard.server.common.data.edge.EdgeEventActionType; |
||||
|
import org.thingsboard.server.common.data.edge.EdgeEventType; |
||||
|
import org.thingsboard.server.common.data.id.AlarmId; |
||||
|
import org.thingsboard.server.common.data.id.EdgeId; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.gen.edge.v1.AlarmCommentUpdateMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.DownlinkMsg; |
||||
|
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
||||
|
import org.thingsboard.server.gen.transport.TransportProtos; |
||||
|
import org.thingsboard.server.queue.util.TbCoreComponent; |
||||
|
import org.thingsboard.server.service.edge.EdgeMsgConstructorUtils; |
||||
|
import org.thingsboard.server.service.edge.rpc.processor.alarm.BaseAlarmProcessor; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.UUID; |
||||
|
|
||||
|
@Slf4j |
||||
|
@Component |
||||
|
@TbCoreComponent |
||||
|
public class AlarmCommentEdgeProcessor extends BaseAlarmProcessor implements AlarmCommentProcessor { |
||||
|
|
||||
|
@Override |
||||
|
public ListenableFuture<Void> processAlarmCommentMsgFromEdge(TenantId tenantId, EdgeId edgeId, AlarmCommentUpdateMsg alarmCommentUpdateMsg) { |
||||
|
log.trace("[{}] processAlarmCommentMsgFromEdge [{}]", tenantId, alarmCommentUpdateMsg); |
||||
|
try { |
||||
|
edgeSynchronizationManager.getEdgeId().set(edgeId); |
||||
|
return processAlarmCommentMsg(tenantId, alarmCommentUpdateMsg); |
||||
|
} finally { |
||||
|
edgeSynchronizationManager.getEdgeId().remove(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public DownlinkMsg convertEdgeEventToDownlink(EdgeEvent edgeEvent) { |
||||
|
UpdateMsgType msgType = getUpdateMsgType(edgeEvent.getAction()); |
||||
|
switch (edgeEvent.getAction()) { |
||||
|
case ADDED_COMMENT: |
||||
|
case UPDATED_COMMENT: |
||||
|
case DELETED_COMMENT: |
||||
|
AlarmComment alarmComment = JacksonUtil.convertValue(edgeEvent.getBody(), AlarmComment.class); |
||||
|
if (alarmComment != null) { |
||||
|
return DownlinkMsg.newBuilder() |
||||
|
.setDownlinkMsgId(EdgeUtils.nextPositiveInt()) |
||||
|
.addAlarmCommentUpdateMsg(EdgeMsgConstructorUtils.constructAlarmCommentUpdatedMsg(msgType, alarmComment)) |
||||
|
.build(); |
||||
|
} |
||||
|
default: |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public ListenableFuture<Void> processEntityNotification(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) { |
||||
|
EdgeEventActionType actionType = EdgeEventActionType.valueOf(edgeNotificationMsg.getAction()); |
||||
|
AlarmId alarmId = new AlarmId(new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB())); |
||||
|
EdgeId originatorEdgeId = safeGetEdgeId(edgeNotificationMsg.getOriginatorEdgeIdMSB(), edgeNotificationMsg.getOriginatorEdgeIdLSB()); |
||||
|
AlarmComment alarmComment = JacksonUtil.fromString(edgeNotificationMsg.getBody(), AlarmComment.class); |
||||
|
if (alarmComment == null) { |
||||
|
return Futures.immediateFuture(null); |
||||
|
} |
||||
|
Alarm alarmById = edgeCtx.getAlarmService().findAlarmById(tenantId, new AlarmId(alarmComment.getAlarmId().getId())); |
||||
|
List<ListenableFuture<Void>> delFutures = pushEventToAllRelatedEdges(tenantId, alarmById.getOriginator(), |
||||
|
alarmId, actionType, JacksonUtil.valueToTree(alarmComment), originatorEdgeId, EdgeEventType.ALARM_COMMENT); |
||||
|
return Futures.transform(Futures.allAsList(delFutures), voids -> null, dbCallbackExecutorService); |
||||
|
} |
||||
|
|
||||
|
} |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue