From f536a08e21117c49ba42e7dac70dfc80c5675bd7 Mon Sep 17 00:00:00 2001 From: dpinkevych Date: Mon, 2 Nov 2026 10:45:51 +0200 Subject: [PATCH] fix(iot-hub): the server keeps the package's own entities, the name fallback only without the installed version --- .../iot_hub/DefaultDevicePackageUpdateService.java | 10 +++++++--- .../DefaultDevicePackageUpdateServiceTest.java | 14 ++++++++++++++ .../device-install-dialog.component.ts | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultDevicePackageUpdateService.java b/application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultDevicePackageUpdateService.java index 6b8445d16e..380f372ea7 100644 --- a/application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultDevicePackageUpdateService.java +++ b/application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultDevicePackageUpdateService.java @@ -271,6 +271,7 @@ public class DefaultDevicePackageUpdateService extends AbstractTbEntityService i private Applied applySteps(TenantId tenantId, DevicePackage devicePackage, DeviceUpdateRequest request, JsonNode versionInfo) { IotHubInstalledItem installedItem = lockInstalledItem(tenantId, devicePackage, request); DeviceInstalledItemDescriptor previous = devicePackage.descriptor(); + Set ownedIds = createdIds(previous).keySet(); Map aliasOutputs = new HashMap<>(); Map outputs = new LinkedHashMap<>(); Map installState = new LinkedHashMap<>(); @@ -303,7 +304,10 @@ public class DefaultDevicePackageUpdateService extends AbstractTbEntityService i outputs.put(step.getName(), output); ObjectNode state = JacksonUtil.newObjectNode(); state.set("entityOutput", output); - state.put("resolution", step.getResolution() != null ? step.getResolution() : "created"); + // The package's own entity stays the package's, whatever the request says, so later versions update it + boolean owned = step.getEntityId() != null && ownedIds.contains(step.getEntityId()); + String resolution = step.getResolution() == null || (owned && "use-existing".equals(step.getResolution())) ? "created" : step.getResolution(); + state.put("resolution", resolution); // A kept entity keeps the checksum of what the package left: the current one would take the // user's changes for the package's, and the next update would overwrite them without a warning String checksum = step.getAction() == DeviceUpdateRequest.Action.KEEP ? previousChecksum(previous, step.getEntityId()) : result.checksum(); @@ -311,7 +315,7 @@ public class DefaultDevicePackageUpdateService extends AbstractTbEntityService i state.put("checksum", checksum); } installState.put(step.getId() != null ? step.getId() : step.getName(), state); - if (!"use-existing".equals(step.getResolution())) { + if (!"use-existing".equals(resolution)) { stepEntityIds.add(result.entityId()); } if (result.entityId() instanceof DashboardId id) { @@ -320,7 +324,7 @@ public class DefaultDevicePackageUpdateService extends AbstractTbEntityService i if (result.saved() != null) { saved.add(result.saved()); } - if (step.getAction() != DeviceUpdateRequest.Action.KEEP && !"use-existing".equals(step.getResolution())) { + if (step.getAction() != DeviceUpdateRequest.Action.KEEP && !"use-existing".equals(resolution)) { // As at install, the step's attributes go with the entity it saved; written after commit attributes.add(new StepAttributes(step.getName(), result.entityId(), step.getServerAttributes(), step.getSharedAttributes())); } diff --git a/application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultDevicePackageUpdateServiceTest.java b/application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultDevicePackageUpdateServiceTest.java index 6fbf49587c..0d6bed9f0f 100644 --- a/application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultDevicePackageUpdateServiceTest.java +++ b/application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultDevicePackageUpdateServiceTest.java @@ -256,6 +256,20 @@ class DefaultDevicePackageUpdateServiceTest { assertThat(descriptor.getInstallState().get("Dashboard").has("checksum")).isFalse(); } + @Test + void useExistingOfAPackageEntity_staysThePackages() { + when(dashboardService.findDashboardById(tenantId, dashboardId)).thenReturn(dashboard(9L)); + DeviceUpdateRequest.Step step = keep("Overview", "DASHBOARD", dashboardId); + step.setResolution("use-existing"); + + DeviceUpdateResult result = service.apply(user, installedItem.getId(), request(step)); + + assertThat(result.isSuccess()).isTrue(); + DeviceInstalledItemDescriptor descriptor = (DeviceInstalledItemDescriptor) installedItem.getDescriptor(); + assertThat(descriptor.getInstallState().get("Overview").get("resolution").asText()).isEqualTo("created"); + assertThat(descriptor.getCreatedEntityIds()).contains(dashboardId); + } + @Test void twoStepsWithOneKey_areRejected() { DeviceUpdateRequest.Step first = keep("Overview", "DASHBOARD", dashboardId); diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts index 327590d41c..fc1718b108 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts @@ -2344,7 +2344,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent k && installState[k]);