From 9cee5b499a72136faa2e55f26418e7c1f3cf5e9c Mon Sep 17 00:00:00 2001 From: dpinkevych Date: Mon, 16 Nov 2026 18:23:06 +0200 Subject: [PATCH] IoT Hub device package delete: the dialog scrolls and keeps long names in the box, log level checked in tests (PROD-9340 review) --- .../iot_hub/DefaultIotHubServiceTest.java | 58 ++++++++++++++++--- .../iot-hub-delete-dialog.component.html | 7 ++- .../iot-hub-delete-dialog.component.scss | 6 ++ 3 files changed, 59 insertions(+), 12 deletions(-) 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 f21dd20726..fe42513490 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 @@ -3,6 +3,10 @@ // SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1 package org.thingsboard.server.service.iot_hub; +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; import jakarta.servlet.http.HttpServletRequest; @@ -14,6 +18,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; +import org.slf4j.LoggerFactory; import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.id.DashboardId; @@ -802,8 +807,10 @@ class DefaultIotHubServiceTest { void findKeptEntities_devicePackage_aSharedProfileKeepsWhatItRefersTo() { DeviceProfile profile = new DeviceProfile(new DeviceProfileId(UUID.randomUUID())); RuleChainId ruleChainId = new RuleChainId(UUID.randomUUID()); + RuleChainId edgeRuleChainId = new RuleChainId(UUID.randomUUID()); profile.setDefaultRuleChainId(ruleChainId); - IotHubInstalledItem checked = devicePackage(ruleChainId, profile.getId()); + profile.setDefaultEdgeRuleChainId(edgeRuleChainId); + IotHubInstalledItem checked = devicePackage(ruleChainId, edgeRuleChainId, profile.getId()); IotHubInstalledItem other = devicePackage(profile.getId()); when(iotHubInstalledItemService.findById(tenantId, checked.getId())).thenReturn(checked); when(iotHubInstalledItemService.findByTenantId(eq(tenantId), eq(List.of("DEVICE")), isNull(), any())) @@ -813,7 +820,8 @@ class DefaultIotHubServiceTest { InstalledItemKeptEntities kept = service.findKeptEntities(tenantId, checked.getId()); assertThat(kept.getEntities()).extracting(InstalledItemKeptEntities.KeptEntity::getEntityId).containsExactly(profile.getId()); - assertThat(kept.getReferencedEntities()).extracting(InstalledItemKeptEntities.KeptEntity::getEntityId).containsExactly(ruleChainId); + assertThat(kept.getReferencedEntities()).extracting(InstalledItemKeptEntities.KeptEntity::getEntityId) + .containsExactly(ruleChainId, edgeRuleChainId); } @Test @@ -860,7 +868,30 @@ class DefaultIotHubServiceTest { } @Test - void deleteInstalledItem_devicePackage_anEntitySomethingElseRefersToStays() throws Exception { + void deleteInstalledItem_devicePackage_anEntitySomethingElseRefersToStays_loggedAsKept() throws Exception { + // A profile the user made after the install uses the package's rule chain + List logs = deleteRuleChainFailingWith( + new DataValidationException("The rule chain referenced by the device profiles cannot be deleted!")); + + assertThat(logs).anySatisfy(event -> { + assertThat(event.getLevel()).isEqualTo(Level.INFO); + assertThat(event.getFormattedMessage()).contains("Kept RULE_CHAIN").contains("referenced by the device profiles"); + }); + assertThat(logs).noneMatch(event -> event.getLevel() == Level.ERROR); + } + + @Test + void deleteInstalledItem_devicePackage_aFailedDelete_staysAnError() throws Exception { + List logs = deleteRuleChainFailingWith(new RuntimeException("Database is down")); + + assertThat(logs).anySatisfy(event -> { + assertThat(event.getLevel()).isEqualTo(Level.ERROR); + assertThat(event.getFormattedMessage()).contains("Failed to delete device package entity"); + }); + } + + /** Deletes a package whose only entity is a rule chain that fails to delete with {@code failure}; the service's logs. */ + private List deleteRuleChainFailingWith(Exception failure) throws Exception { mockTenant(); RuleChain ruleChain = new RuleChain(new RuleChainId(UUID.randomUUID())); IotHubInstalledItem deleted = devicePackage(ruleChain.getId()); @@ -868,13 +899,22 @@ class DefaultIotHubServiceTest { when(iotHubInstalledItemService.findByTenantId(eq(tenantId), eq(List.of("DEVICE")), isNull(), any())) .thenReturn(new PageData<>(List.of(deleted), 1, 1, false)); when(ruleChainService.findRuleChainById(tenantId, ruleChain.getId())).thenReturn(ruleChain); - // A profile the user made after the install uses the package's rule chain - doThrow(new DataValidationException("The rule chain referenced by the device profiles cannot be deleted!")) - .when(tbRuleChainService).delete(ruleChain, user); - - service.deleteInstalledItem(user, deleted.getId()); - + doThrow(failure).when(tbRuleChainService).delete(ruleChain, user); + Logger logger = (Logger) LoggerFactory.getLogger(DefaultIotHubService.class); + ListAppender appender = new ListAppender<>(); + appender.start(); + logger.addAppender(appender); + Level level = logger.getLevel(); + logger.setLevel(Level.INFO); + try { + service.deleteInstalledItem(user, deleted.getId()); + } finally { + logger.setLevel(level); + logger.detachAppender(appender); + } + // The delete goes on either way verify(iotHubInstalledItemService).deleteById(tenantId, deleted.getId()); + return appender.list; } private void noDevices(DeviceProfileId profileId) { diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.html b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.html index 9ee22d6bc7..be62922e11 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.html +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.html @@ -5,15 +5,16 @@ SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1 --> -
+ +

{{ 'iot-hub.remove-confirm-title' | translate:{ name: data.itemName } }}

{{ description }}

@if (keptGroups.length) {
info_outline -
+
{{ keptTitle }}
-
+
@for (group of keptGroups; track group.reason; let i = $index; let first = $first) {
diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.scss b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.scss index 95dcd79e2d..ab3f9b9ebc 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.scss +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.scss @@ -35,9 +35,15 @@ &:before { display: none; } + + // A long name breaks inside the box instead of running past its border + td.tb-entity-name { + overflow-wrap: anywhere; + } } } +// Not divide-y: with preflight off, divide-solid draws the side borders of the groups too .tb-iot-hub-kept-group-next { border-top: 1px solid rgba(0, 0, 0, 0.08); }