Browse Source

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.
pull/16553/head
dpinkevych 4 weeks ago
parent
commit
358ca210f9
Failed to extract signature
  1. 6
      application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultIotHubService.java
  2. 6
      application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultIotHubServiceTest.java
  3. 10
      ui-ngx/src/app/core/http/iot-hub-api.service.ts
  4. 2
      ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.html
  5. 22
      ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts

6
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);

6
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());
}
}

10
ui-ngx/src/app/core/http/iot-hub-api.service.ts

@ -182,14 +182,12 @@ export class IotHubApiService {
replaceInstalledItemId?: string,
config?: IotHubRequestConfig
): Observable<InstallItemVersionResult> {
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<InstallItemVersionResult>(
`/api/iot-hub/device/register?versionId=${versionId}`,
`/api/iot-hub/device/register?versionId=${versionId}${replace}`,
{ type: 'DEVICE', ...descriptor },
{ params }
{ params: this.buildParams(config) }
);
}

2
ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.html

@ -206,7 +206,7 @@
</ng-template>
@for (ws of wizardSteps; track ws.label) {
<mat-step [editable]="true"
<mat-step [editable]="!removingReplaced"
[completed]="ws.completed"
[stepControl]="ws.type === 'form' ? ws.formGroup : null">
<ng-template matStepLabel>{{ ws.label }}</ng-template>

22
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<TbDeviceInst
// All done — register install with created entity IDs. The step is done only then: until it is registered,
// nothing tracks the entities, so the package could be neither updated nor removed from IoT Hub.
try {
for (const id of this.collectCreatedEntityIds()) {
if (!this.packageEntityIds.some(known => 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<TbDeviceInst
return state;
}
private collectCreatedEntityIds(): { entityType: string; id: string }[] {
const ids: { entityType: string; id: string }[] = [];
for (const ws of this.wizardSteps) {
if (ws.type === 'progress' && ws.entitySteps) {
for (const ep of ws.entitySteps) {
if (ep.status === 'success' && ep.entityOutput) {
const entityType = this.stepTypeToEntityType(ep.step.type);
if (entityType) {
ids.push({ entityType, id: ep.entityOutput.id });
}
}
}
}
}
return ids;
}
private findCreatedDashboardId(): { entityType: string; id: string } | undefined {
for (const ws of this.wizardSteps) {
if (ws.type === 'progress' && ws.entitySteps) {

Loading…
Cancel
Save