Improve copy of image for edge

This commit is contained in:
Andrii Landiak 2024-03-05 10:35:04 +02:00
parent 02c9fe3f82
commit 2bd5b1765c
4 changed files with 19 additions and 15 deletions

View File

@ -63,8 +63,8 @@ public class AssetMsgConstructorV1 extends BaseAssetMsgConstructor {
@Override @Override
public AssetProfileUpdateMsg constructAssetProfileUpdatedMsg(UpdateMsgType msgType, AssetProfile assetProfile) { public AssetProfileUpdateMsg constructAssetProfileUpdatedMsg(UpdateMsgType msgType, AssetProfile assetProfile) {
AssetProfile copy = JacksonUtil.clone(assetProfile); assetProfile = JacksonUtil.clone(assetProfile);
imageService.inlineImageForEdge(copy); imageService.inlineImageForEdge(assetProfile);
AssetProfileUpdateMsg.Builder builder = AssetProfileUpdateMsg.newBuilder() AssetProfileUpdateMsg.Builder builder = AssetProfileUpdateMsg.newBuilder()
.setMsgType(msgType) .setMsgType(msgType)
.setIdMSB(assetProfile.getId().getId().getMostSignificantBits()) .setIdMSB(assetProfile.getId().getId().getMostSignificantBits())
@ -82,7 +82,7 @@ public class AssetMsgConstructorV1 extends BaseAssetMsgConstructor {
builder.setDescription(assetProfile.getDescription()); builder.setDescription(assetProfile.getDescription());
} }
if (assetProfile.getImage() != null) { if (assetProfile.getImage() != null) {
builder.setImage(ByteString.copyFrom(copy.getImage().getBytes(StandardCharsets.UTF_8))); builder.setImage(ByteString.copyFrom(assetProfile.getImage().getBytes(StandardCharsets.UTF_8)));
} }
if (assetProfile.getDefaultEdgeRuleChainId() != null) { if (assetProfile.getDefaultEdgeRuleChainId() != null) {
builder.setDefaultRuleChainIdMSB(assetProfile.getDefaultEdgeRuleChainId().getId().getMostSignificantBits()) builder.setDefaultRuleChainIdMSB(assetProfile.getDefaultEdgeRuleChainId().getId().getMostSignificantBits())
@ -90,4 +90,5 @@ public class AssetMsgConstructorV1 extends BaseAssetMsgConstructor {
} }
return builder.build(); return builder.build();
} }
} }

View File

@ -33,8 +33,8 @@ public class DashboardMsgConstructorV1 extends BaseDashboardMsgConstructor {
@Override @Override
public DashboardUpdateMsg constructDashboardUpdatedMsg(UpdateMsgType msgType, Dashboard dashboard) { public DashboardUpdateMsg constructDashboardUpdatedMsg(UpdateMsgType msgType, Dashboard dashboard) {
Dashboard copy = JacksonUtil.clone(dashboard); dashboard = JacksonUtil.clone(dashboard);
imageService.inlineImagesForEdge(copy); imageService.inlineImagesForEdge(dashboard);
DashboardUpdateMsg.Builder builder = DashboardUpdateMsg.newBuilder() DashboardUpdateMsg.Builder builder = DashboardUpdateMsg.newBuilder()
.setMsgType(msgType) .setMsgType(msgType)
.setIdMSB(dashboard.getId().getId().getMostSignificantBits()) .setIdMSB(dashboard.getId().getId().getMostSignificantBits())
@ -46,11 +46,12 @@ public class DashboardMsgConstructorV1 extends BaseDashboardMsgConstructor {
builder.setAssignedCustomers(JacksonUtil.toString(dashboard.getAssignedCustomers())); builder.setAssignedCustomers(JacksonUtil.toString(dashboard.getAssignedCustomers()));
} }
if (dashboard.getImage() != null) { if (dashboard.getImage() != null) {
builder.setImage(copy.getImage()); builder.setImage(dashboard.getImage());
} }
if (dashboard.getMobileOrder() != null) { if (dashboard.getMobileOrder() != null) {
builder.setMobileOrder(dashboard.getMobileOrder()); builder.setMobileOrder(dashboard.getMobileOrder());
} }
return builder.build(); return builder.build();
} }
} }

View File

@ -95,8 +95,8 @@ public class DeviceMsgConstructorV1 extends BaseDeviceMsgConstructor {
@Override @Override
public DeviceProfileUpdateMsg constructDeviceProfileUpdatedMsg(UpdateMsgType msgType, DeviceProfile deviceProfile) { public DeviceProfileUpdateMsg constructDeviceProfileUpdatedMsg(UpdateMsgType msgType, DeviceProfile deviceProfile) {
DeviceProfile copy = JacksonUtil.clone(deviceProfile); deviceProfile = JacksonUtil.clone(deviceProfile);
imageService.inlineImageForEdge(copy); imageService.inlineImageForEdge(deviceProfile);
DeviceProfileUpdateMsg.Builder builder = DeviceProfileUpdateMsg.newBuilder() DeviceProfileUpdateMsg.Builder builder = DeviceProfileUpdateMsg.newBuilder()
.setMsgType(msgType) .setMsgType(msgType)
.setIdMSB(deviceProfile.getId().getId().getMostSignificantBits()) .setIdMSB(deviceProfile.getId().getId().getMostSignificantBits())
@ -121,7 +121,7 @@ public class DeviceMsgConstructorV1 extends BaseDeviceMsgConstructor {
builder.setProvisionDeviceKey(deviceProfile.getProvisionDeviceKey()); builder.setProvisionDeviceKey(deviceProfile.getProvisionDeviceKey());
} }
if (deviceProfile.getImage() != null) { if (deviceProfile.getImage() != null) {
builder.setImage(ByteString.copyFrom(copy.getImage().getBytes(StandardCharsets.UTF_8))); builder.setImage(ByteString.copyFrom(deviceProfile.getImage().getBytes(StandardCharsets.UTF_8)));
} }
if (deviceProfile.getFirmwareId() != null) { if (deviceProfile.getFirmwareId() != null) {
builder.setFirmwareIdMSB(deviceProfile.getFirmwareId().getId().getMostSignificantBits()) builder.setFirmwareIdMSB(deviceProfile.getFirmwareId().getId().getMostSignificantBits())
@ -141,4 +141,5 @@ public class DeviceMsgConstructorV1 extends BaseDeviceMsgConstructor {
} }
return builder.build(); return builder.build();
} }
} }

View File

@ -43,8 +43,8 @@ public class WidgetMsgConstructorV1 extends BaseWidgetMsgConstructor {
@Override @Override
public WidgetsBundleUpdateMsg constructWidgetsBundleUpdateMsg(UpdateMsgType msgType, WidgetsBundle widgetsBundle, List<String> widgets) { public WidgetsBundleUpdateMsg constructWidgetsBundleUpdateMsg(UpdateMsgType msgType, WidgetsBundle widgetsBundle, List<String> widgets) {
WidgetsBundle copy = JacksonUtil.clone(widgetsBundle); widgetsBundle = JacksonUtil.clone(widgetsBundle);
imageService.inlineImageForEdge(copy); imageService.inlineImageForEdge(widgetsBundle);
WidgetsBundleUpdateMsg.Builder builder = WidgetsBundleUpdateMsg.newBuilder() WidgetsBundleUpdateMsg.Builder builder = WidgetsBundleUpdateMsg.newBuilder()
.setMsgType(msgType) .setMsgType(msgType)
.setIdMSB(widgetsBundle.getId().getId().getMostSignificantBits()) .setIdMSB(widgetsBundle.getId().getId().getMostSignificantBits())
@ -52,7 +52,7 @@ public class WidgetMsgConstructorV1 extends BaseWidgetMsgConstructor {
.setTitle(widgetsBundle.getTitle()) .setTitle(widgetsBundle.getTitle())
.setAlias(widgetsBundle.getAlias()); .setAlias(widgetsBundle.getAlias());
if (widgetsBundle.getImage() != null) { if (widgetsBundle.getImage() != null) {
builder.setImage(ByteString.copyFrom(copy.getImage().getBytes(StandardCharsets.UTF_8))); builder.setImage(ByteString.copyFrom(widgetsBundle.getImage().getBytes(StandardCharsets.UTF_8)));
} }
if (widgetsBundle.getDescription() != null) { if (widgetsBundle.getDescription() != null) {
builder.setDescription(widgetsBundle.getDescription()); builder.setDescription(widgetsBundle.getDescription());
@ -69,8 +69,8 @@ public class WidgetMsgConstructorV1 extends BaseWidgetMsgConstructor {
@Override @Override
public WidgetTypeUpdateMsg constructWidgetTypeUpdateMsg(UpdateMsgType msgType, WidgetTypeDetails widgetTypeDetails, EdgeVersion edgeVersion) { public WidgetTypeUpdateMsg constructWidgetTypeUpdateMsg(UpdateMsgType msgType, WidgetTypeDetails widgetTypeDetails, EdgeVersion edgeVersion) {
WidgetTypeDetails copy = JacksonUtil.clone(widgetTypeDetails); widgetTypeDetails = JacksonUtil.clone(widgetTypeDetails);
imageService.inlineImagesForEdge(copy); imageService.inlineImagesForEdge(widgetTypeDetails);
WidgetTypeUpdateMsg.Builder builder = WidgetTypeUpdateMsg.newBuilder() WidgetTypeUpdateMsg.Builder builder = WidgetTypeUpdateMsg.newBuilder()
.setMsgType(msgType) .setMsgType(msgType)
.setIdMSB(widgetTypeDetails.getId().getId().getMostSignificantBits()) .setIdMSB(widgetTypeDetails.getId().getId().getMostSignificantBits())
@ -95,7 +95,7 @@ public class WidgetMsgConstructorV1 extends BaseWidgetMsgConstructor {
builder.setIsSystem(true); builder.setIsSystem(true);
} }
if (widgetTypeDetails.getImage() != null) { if (widgetTypeDetails.getImage() != null) {
builder.setImage(copy.getImage()); builder.setImage(widgetTypeDetails.getImage());
} }
if (widgetTypeDetails.getDescription() != null) { if (widgetTypeDetails.getDescription() != null) {
if (EdgeVersionUtils.isEdgeVersionOlderThan(edgeVersion, EdgeVersion.V_3_6_0) && if (EdgeVersionUtils.isEdgeVersionOlderThan(edgeVersion, EdgeVersion.V_3_6_0) &&
@ -111,4 +111,5 @@ public class WidgetMsgConstructorV1 extends BaseWidgetMsgConstructor {
} }
return builder.build(); return builder.build();
} }
} }