Browse Source

compose the failed dependency sentence in the dialog, not in the service

The service was pre-composing "Failed to install dependency '<name>':",
which can never be translated and made the backend depend on the dialog
already printing the root item above the details. It now reports the
failure itself, and the dialog prefixes a localized sentence when the
entry that failed is not the root.
pull/16117/head
dpinkevych 3 months ago
parent
commit
811713c338
Failed to extract signature
  1. 5
      application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultIotHubService.java
  2. 5
      application/src/main/java/org/thingsboard/server/service/solutions/DefaultSolutionService.java
  3. 15
      application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultIotHubServiceTest.java
  4. 6
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-install-dialog.component.ts
  5. 1
      ui-ngx/src/assets/locale/locale.constant-en_US.json

5
application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultIotHubService.java

@ -1011,10 +1011,7 @@ public class DefaultIotHubService implements IotHubService {
boolean rolledBack = rollbackInstalledItems(user, rollbackIds);
result.setSuccess(false);
result.setRolledBack(rolledBack);
// The dialog already says "Failed to install '<root item>'" above the details, so only a
// failing dependency is worth naming here - for the root entry that would just repeat itself.
result.setErrorMessage(entry.isRoot() ? e.getMessage()
: "Failed to install dependency '" + entry.getName() + "': " + e.getMessage());
result.setErrorMessage(e.getMessage());
result.setEntries(resultEntries);
result.setMissingItemIds(missingItemIds);
return result;

5
application/src/main/java/org/thingsboard/server/service/solutions/DefaultSolutionService.java

@ -299,11 +299,6 @@ public class DefaultSolutionService implements SolutionService {
}
}
/**
* Reports every entity of the template that would clash with an entity the tenant already has, naming each
* conflict, before anything is created. Returns {@code null} when the template can be installed as is.
* Package-private so the conflict detection can be unit-tested in isolation.
*/
SolutionInstallResponse validateSolution(TenantId tenantId, Path tempDir) {
//TODO: check other entities.

15
application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultIotHubServiceTest.java

@ -345,7 +345,7 @@ class DefaultIotHubServiceTest {
}
@Test
void installPlan_rootFails_errorMessageIsNotPrefixedWithTheItemName() throws Exception {
void installPlan_errorMessageIsTheFailureItselfWithoutAnyPrefix() throws Exception {
mockTenant();
HttpServletRequest request = mock(HttpServletRequest.class);
String rootVersionId = UUID.randomUUID().toString();
@ -356,12 +356,12 @@ class DefaultIotHubServiceTest {
InstallPlanResult result = service.installPlan(user, new InstallPlan(rootVersionId, List.of(root)), null, request);
// the install dialog already shows "Failed to install '<item>'" right above these details
// the sentence around the failure belongs to the dialog, which localizes it
assertThat(result.getErrorMessage()).isEqualTo("install failed");
}
@Test
void installPlan_dependencyFails_errorMessageNamesTheDependency() throws Exception {
void installPlan_dependencyFails_failureIsReportedOnTheEntryAndAsTheResultMessage() throws Exception {
mockTenant();
HttpServletRequest request = mock(HttpServletRequest.class);
String depVersionId = UUID.randomUUID().toString();
@ -374,8 +374,13 @@ class DefaultIotHubServiceTest {
InstallPlanResult result = service.installPlan(user, new InstallPlan(rootVersionId, List.of(dep, root)), null, request);
// a failing dependency is not the item the dialog names, so it has to be named here
assertThat(result.getErrorMessage()).isEqualTo("Failed to install dependency 'Dep': install failed");
// the dialog names the failing dependency itself, from the entry it finds in the result
assertThat(result.getErrorMessage()).isEqualTo("install failed");
assertThat(result.getEntries()).anySatisfy(entry -> {
assertThat(entry.getName()).isEqualTo("Dep");
assertThat(entry.isRoot()).isFalse();
assertThat(entry.getErrorMessage()).isEqualTo("install failed");
});
verify(service, never()).doInstallVersion(eq(user), eq(rootVersionId), any(), any());
}

6
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-install-dialog.component.ts

@ -345,6 +345,12 @@ export class TbIotHubInstallDialogComponent extends DialogComponent<TbIotHubInst
if (!result.success) {
this.state = 'error';
let message = result.errorMessage || this.translate.instant('iot-hub.install-error', { name: this.item.name });
// The title already names the item being installed, so only a failing dependency has to be
// named here - the service reports the failure itself and does not compose this sentence.
const failedDependency = (result.entries ?? []).find(entry => !entry.root && entry.errorMessage);
if (failedDependency) {
message = this.translate.instant('iot-hub.install-dependency-error', { name: failedDependency.name }) + ' ' + message;
}
// A failed cascade rolls back the items installed so far. When something was actually being
// installed and the rollback came back partial (rolledBack === false), some entities are left
// behind — tell the admin so they know manual cleanup may be needed. The willInstall guard

1
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -4337,6 +4337,7 @@
"goto-main-dashboard": "Go to main dashboard",
"install-error-title": "Installation Failed",
"install-error-message": "Failed to install '{{name}}'.",
"install-dependency-error": "Failed to install the dependency '{{name}}':",
"install-plan-title": "Install '{{name}}' and its dependencies",
"install-plan-will-install": "{{count}} item(s) will be installed.",
"install-plan-will-update": "{{count}} item(s) already installed and will be skipped.",

Loading…
Cancel
Save