From 358ca210f971cdd397b1fa05fbc2578ff11cd162 Mon Sep 17 00:00:00 2001 From: dpinkevych Date: Thu, 5 Nov 2026 08:56:46 +0200 Subject: [PATCH] fix(iot-hub): keep the request config on a device package registration - The registration sends replaceInstalledItemId in the URL: HttpParams.set() returned a plain HttpParams, which dropped ignoreLoading/ignoreErrors, so a failed registration showed a toast next to the wizard's own error. - The stepper header cannot go back while the installed version's entities are being removed, like the Back button. - A version from the Hub without its item is reported as such instead of a NullPointerException. - The wizard registers the entities it keeps from the moment they exist; the second collection of the same ids before each registration is gone. - The tests verify TbDeviceService.delete through the Device overload, as 4.4 and PE also have one for a DeviceId, so the test is the same file everywhere. --- .../service/iot_hub/DefaultIotHubService.java | 6 ++++- .../iot_hub/DefaultIotHubServiceTest.java | 6 ++--- .../src/app/core/http/iot-hub-api.service.ts | 10 ++++----- .../device-install-dialog.component.html | 2 +- .../device-install-dialog.component.ts | 22 ------------------- 5 files changed, 13 insertions(+), 33 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultIotHubService.java b/application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultIotHubService.java index c4389517d0..ece9c0cad9 100644 --- a/application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultIotHubService.java +++ b/application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultIotHubService.java @@ -631,7 +631,11 @@ public class DefaultIotHubService implements IotHubService { if (versionInfo == null) { throw new IllegalArgumentException("Failed to get version info from IoT Hub"); } - checkSameItem(installedItem, UUID.fromString(versionInfo.get(FIELD_ITEM_ID).asText())); + String itemId = optText(versionInfo, FIELD_ITEM_ID); + if (itemId == null) { + throw new IllegalArgumentException("IoT Hub returned the version without its item"); + } + checkSameItem(installedItem, UUID.fromString(itemId)); DeviceInstalledItemDescriptor descriptor = (DeviceInstalledItemDescriptor) installedItem.getDescriptor(); deleteDevicePackageEntities(tenantId, descriptor.getCreatedEntityIds(), user); descriptor.setCreatedEntityIds(null); diff --git a/application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultIotHubServiceTest.java b/application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultIotHubServiceTest.java index b07b3c8195..0d6a8d49b8 100644 --- a/application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultIotHubServiceTest.java +++ b/application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultIotHubServiceTest.java @@ -449,7 +449,7 @@ class DefaultIotHubServiceTest { assertThat(result.isSuccess()).isFalse(); assertThat(result.getErrorMessage()).contains("install wizard"); - verify(tbDeviceService, never()).delete(any(), any()); + verify(tbDeviceService, never()).delete(any(Device.class), any()); verify(iotHubInstalledItemService, never()).deleteById(any(), any()); verify(iotHubInstalledItemService, never()).save(any(), any()); } @@ -652,7 +652,7 @@ class DefaultIotHubServiceTest { service.removeDevicePackageEntities(user, item.getId(), newVersionId); - verify(tbDeviceService, never()).delete(any(), any()); + verify(tbDeviceService, never()).delete(any(Device.class), any()); } @Test @@ -672,7 +672,7 @@ class DefaultIotHubServiceTest { // The registration of that version would be refused: nothing may be removed for it. assertThatThrownBy(() -> service.removeDevicePackageEntities(user, item.getId(), otherVersionId)) .isInstanceOf(IllegalArgumentException.class); - verify(tbDeviceService, never()).delete(any(), any()); + verify(tbDeviceService, never()).delete(any(Device.class), any()); verify(iotHubInstalledItemService, never()).save(any(), any()); } } diff --git a/ui-ngx/src/app/core/http/iot-hub-api.service.ts b/ui-ngx/src/app/core/http/iot-hub-api.service.ts index ba19c0f6e6..07c1c9a64d 100644 --- a/ui-ngx/src/app/core/http/iot-hub-api.service.ts +++ b/ui-ngx/src/app/core/http/iot-hub-api.service.ts @@ -182,14 +182,12 @@ export class IotHubApiService { replaceInstalledItemId?: string, config?: IotHubRequestConfig ): Observable { - let params = this.buildParams(config); - if (replaceInstalledItemId) { - params = params.set('replaceInstalledItemId', replaceInstalledItemId); - } + // In the URL: HttpParams.set() would drop the interceptor config (ignoreLoading, ignoreErrors) of buildParams. + const replace = replaceInstalledItemId ? `&replaceInstalledItemId=${replaceInstalledItemId}` : ''; return this.http.post( - `/api/iot-hub/device/register?versionId=${versionId}`, + `/api/iot-hub/device/register?versionId=${versionId}${replace}`, { type: 'DEVICE', ...descriptor }, - { params } + { params: this.buildParams(config) } ); } diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.html b/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.html index 6db53d1cfb..45060d91bc 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.html +++ b/ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.html @@ -206,7 +206,7 @@ @for (ws of wizardSteps; track ws.label) { - {{ ws.label }} 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 c9aa546f23..51903723b1 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 @@ -878,11 +878,6 @@ export class TbDeviceInstallDialogComponent extends DialogComponent known.id === id.id)) { - this.packageEntityIds.push(id); - } - } const createdEntityIds = [...this.packageEntityIds]; const dashboardId = this.findCreatedDashboardId(); const result = await firstValueFrom( @@ -1215,23 +1210,6 @@ export class TbDeviceInstallDialogComponent extends DialogComponent