From b9d402abba7bf87379968337e7d9a7a591daf6c0 Mon Sep 17 00:00:00 2001 From: IrynaMatveieva Date: Thu, 14 Aug 2025 09:39:42 +0300 Subject: [PATCH 1/3] parse long to int --- .../ctx/state/SingleValueArgumentEntry.java | 5 ++++ .../state/ScriptCalculatedFieldStateTest.java | 24 +++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/cf/ctx/state/SingleValueArgumentEntry.java b/application/src/main/java/org/thingsboard/server/service/cf/ctx/state/SingleValueArgumentEntry.java index 1585c9b2a9..1ceea2c621 100644 --- a/application/src/main/java/org/thingsboard/server/service/cf/ctx/state/SingleValueArgumentEntry.java +++ b/application/src/main/java/org/thingsboard/server/service/cf/ctx/state/SingleValueArgumentEntry.java @@ -101,6 +101,11 @@ public class SingleValueArgumentEntry implements ArgumentEntry { } catch (Exception e) { } } + if (value instanceof Long longValue) { + if (longValue >= Integer.MIN_VALUE && longValue <= Integer.MAX_VALUE) { + value = longValue.intValue(); + } + } return new TbelCfSingleValueArg(ts, value); } diff --git a/application/src/test/java/org/thingsboard/server/service/cf/ctx/state/ScriptCalculatedFieldStateTest.java b/application/src/test/java/org/thingsboard/server/service/cf/ctx/state/ScriptCalculatedFieldStateTest.java index 91eced64f6..8ed42c43e8 100644 --- a/application/src/test/java/org/thingsboard/server/service/cf/ctx/state/ScriptCalculatedFieldStateTest.java +++ b/application/src/test/java/org/thingsboard/server/service/cf/ctx/state/ScriptCalculatedFieldStateTest.java @@ -20,7 +20,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.script.api.tbel.DefaultTbelInvokeService; import org.thingsboard.script.api.tbel.TbelInvokeService; @@ -60,7 +60,7 @@ public class ScriptCalculatedFieldStateTest { private final DeviceId DEVICE_ID = new DeviceId(UUID.fromString("5512071d-5abc-411d-a907-4cdb6539c2eb")); private final AssetId ASSET_ID = new AssetId(UUID.fromString("5bc010ae-bcfd-46c8-98b9-8ee8c8955a76")); - private final SingleValueArgumentEntry assetHumidityArgEntry = new SingleValueArgumentEntry(System.currentTimeMillis() - 10, new DoubleDataEntry("assetHumidity", 43.0), 122L); + private final SingleValueArgumentEntry assetHumidityArgEntry = new SingleValueArgumentEntry(System.currentTimeMillis() - 10, new DoubleDataEntry("assetHumidity", 86.0), 122L); private final TsRollingArgumentEntry deviceTemperatureArgEntry = createRollingArgEntry(); private final long ts = System.currentTimeMillis(); @@ -71,7 +71,7 @@ public class ScriptCalculatedFieldStateTest { @Autowired private TbelInvokeService tbelInvokeService; - @MockBean + @MockitoBean private ApiLimitService apiLimitService; @BeforeEach @@ -133,6 +133,22 @@ public class ScriptCalculatedFieldStateTest { assertThat(result.getResult()).isEqualTo(JacksonUtil.valueToTree(Map.of("maxDeviceTemperature", 17.0, "assetHumidity", 43.0))); } + @Test + void testPerformCalculationWithLongEntry() throws ExecutionException, InterruptedException { + state.arguments = new HashMap<>(Map.of( + "deviceTemperature", deviceTemperatureArgEntry, + "assetHumidity", new SingleValueArgumentEntry(System.currentTimeMillis() - 10, new LongDataEntry("a", 45L), 10L) + )); + + CalculatedFieldResult result = state.performCalculation(ctx).get(); + + assertThat(result).isNotNull(); + Output output = getCalculatedFieldConfig().getOutput(); + assertThat(result.getType()).isEqualTo(output.getType()); + assertThat(result.getScope()).isEqualTo(output.getScope()); + assertThat(result.getResult()).isEqualTo(JacksonUtil.valueToTree(Map.of("maxDeviceTemperature", 17.0, "assetHumidity", 22.5))); + } + @Test void testIsReadyWhenNotAllArgPresent() { assertThat(state.isReady()).isFalse(); @@ -193,7 +209,7 @@ public class ScriptCalculatedFieldStateTest { config.setArguments(Map.of("deviceTemperature", argument1, "assetHumidity", argument2)); - config.setExpression("return {\"maxDeviceTemperature\": deviceTemperature.max(), \"assetHumidity\": assetHumidity}"); + config.setExpression("return {\"maxDeviceTemperature\": deviceTemperature.max(), \"assetHumidity\": assetHumidity / 2 }"); Output output = new Output(); output.setType(OutputType.ATTRIBUTES); From 96df3819ac099605e7379131c246932e60c99b48 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Thu, 14 Aug 2025 10:25:55 +0300 Subject: [PATCH 2/3] UI: Fixed tranlate format in da_DK --- ui-ngx/src/assets/locale/locale.constant-da_DK.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-ngx/src/assets/locale/locale.constant-da_DK.json b/ui-ngx/src/assets/locale/locale.constant-da_DK.json index c77b87f3e0..624053b088 100644 --- a/ui-ngx/src/assets/locale/locale.constant-da_DK.json +++ b/ui-ngx/src/assets/locale/locale.constant-da_DK.json @@ -5276,7 +5276,7 @@ "add-originator-attributes-to": "Tilføj afsenders attributter til", "originator-attributes": "Afsenders attributter", "fetch-latest-telemetry-with-timestamp": "Hent seneste telemetry med tidsstempel", - "fetch-latest-telemetry-with-timestamp-tooltip": "Inkluderer tidsstempel i metadata, f.eks.: \"{{latestTsKeyName}}\": \"{ts:1574329385897, value:42}\"", + "fetch-latest-telemetry-with-timestamp-tooltip": "Inkluderer tidsstempel i metadata, f.eks.: \"{{latestTsKeyName}}\": \"{\"ts\":1574329385897, \"value\":42}\"", "tell-failure": "Rapportér fejl hvis attribut mangler", "tell-failure-tooltip": "Rapporterer fejl hvis mindst én valgt nøgle mangler.", "created-time": "Oprettelsestid", From 30cfda777b3026f10f41f41be52fdd728d56d930 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Thu, 14 Aug 2025 15:44:17 +0300 Subject: [PATCH 3/3] UI: Fixed autofill password --- .../home/components/ai-model/ai-model-dialog.component.html | 6 +++--- .../rule-node/common/credentials-config.component.html | 4 ++-- .../rule-node/external/rabbit-mq-config.component.html | 2 +- .../rule-node/external/send-email-config.component.html | 2 +- .../sms/aws-sns-provider-configuration.component.html | 2 +- .../app/modules/home/pages/admin/mail-server.component.html | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/ai-model/ai-model-dialog.component.html b/ui-ngx/src/app/modules/home/components/ai-model/ai-model-dialog.component.html index 860e615410..5f9c189399 100644 --- a/ui-ngx/src/app/modules/home/components/ai-model/ai-model-dialog.component.html +++ b/ui-ngx/src/app/modules/home/components/ai-model/ai-model-dialog.component.html @@ -59,7 +59,7 @@ @if (providerFieldsList.includes('personalAccessToken')) { ai-models.personal-access-token - + {{ 'ai-models.personal-access-token-required' | translate }} @@ -115,7 +115,7 @@ @if (providerFieldsList.includes('apiKey')) { ai-models.api-key - + {{ 'ai-models.api-key-required' | translate }} @@ -143,7 +143,7 @@ @if (providerFieldsList.includes('secretAccessKey')) { ai-models.secret-access-key - + {{ 'ai-models.secret-access-key-required' | translate }} diff --git a/ui-ngx/src/app/modules/home/components/rule-node/common/credentials-config.component.html b/ui-ngx/src/app/modules/home/components/rule-node/common/credentials-config.component.html index 7f7d50db3e..59bfa7ce9f 100644 --- a/ui-ngx/src/app/modules/home/components/rule-node/common/credentials-config.component.html +++ b/ui-ngx/src/app/modules/home/components/rule-node/common/credentials-config.component.html @@ -49,7 +49,7 @@ rule-node-config.password - + {{ 'rule-node-config.password-required' | translate }} @@ -85,7 +85,7 @@ rule-node-config.private-key-password - + diff --git a/ui-ngx/src/app/modules/home/components/rule-node/external/rabbit-mq-config.component.html b/ui-ngx/src/app/modules/home/components/rule-node/external/rabbit-mq-config.component.html index 0676af17f9..6adf2e6a4e 100644 --- a/ui-ngx/src/app/modules/home/components/rule-node/external/rabbit-mq-config.component.html +++ b/ui-ngx/src/app/modules/home/components/rule-node/external/rabbit-mq-config.component.html @@ -64,7 +64,7 @@ rule-node-config.password - + diff --git a/ui-ngx/src/app/modules/home/components/rule-node/external/send-email-config.component.html b/ui-ngx/src/app/modules/home/components/rule-node/external/send-email-config.component.html index 0e9db748bf..545f9ba985 100644 --- a/ui-ngx/src/app/modules/home/components/rule-node/external/send-email-config.component.html +++ b/ui-ngx/src/app/modules/home/components/rule-node/external/send-email-config.component.html @@ -109,7 +109,7 @@ rule-node-config.password - + diff --git a/ui-ngx/src/app/modules/home/components/sms/aws-sns-provider-configuration.component.html b/ui-ngx/src/app/modules/home/components/sms/aws-sns-provider-configuration.component.html index 14d4a227ff..afd272e1cd 100644 --- a/ui-ngx/src/app/modules/home/components/sms/aws-sns-provider-configuration.component.html +++ b/ui-ngx/src/app/modules/home/components/sms/aws-sns-provider-configuration.component.html @@ -25,7 +25,7 @@ admin.aws-secret-access-key - + {{ 'admin.aws-secret-access-key-required' | translate }} diff --git a/ui-ngx/src/app/modules/home/pages/admin/mail-server.component.html b/ui-ngx/src/app/modules/home/pages/admin/mail-server.component.html index 948571dbe0..a3dc30da87 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/mail-server.component.html +++ b/ui-ngx/src/app/modules/home/pages/admin/mail-server.component.html @@ -136,7 +136,7 @@ admin.proxy-password - +