Browse Source

Added 'Overwrite activity time' column type to device bulk import (#16017)

* Add 'Overwrite activity time' column type to device bulk import

* Fix overwriteActivityTime column type not being disabled after selection in bulk import
Remove dead locale key import.column-type.activity-time-from-gateway-device
    from all 23 locale files

* Use DataConstants keys for gateway and overwriteActivityTime in device bulk import

* Group gateway columns in bulk import and reuse device.overwrite-activity-time label

* Fixed auto-detection of gateway columns in device bulk import

---------

Co-authored-by: Vladyslav_Prykhodko <vprykhodko@thingsboard.io>
pull/16631/head
Dmytro Khylko 3 weeks ago
committed by GitHub
parent
commit
d11464b848
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      application/src/main/java/org/thingsboard/server/service/device/DeviceBulkImportService.java
  2. 37
      application/src/test/java/org/thingsboard/server/controller/DeviceControllerTest.java
  3. 1
      common/data/src/main/java/org/thingsboard/server/common/data/sync/ie/importing/csv/BulkImportColumnType.java
  4. 2
      ui-ngx/src/app/shared/import-export/import-dialog-csv.component.ts
  5. 2
      ui-ngx/src/app/shared/import-export/import-export.models.ts
  6. 7
      ui-ngx/src/app/shared/import-export/table-columns-assignment.component.html
  7. 18
      ui-ngx/src/app/shared/import-export/table-columns-assignment.component.ts
  8. 1
      ui-ngx/src/assets/locale/locale.constant-ar_AE.json
  9. 1
      ui-ngx/src/assets/locale/locale.constant-ca_ES.json
  10. 1
      ui-ngx/src/assets/locale/locale.constant-cs_CZ.json
  11. 1
      ui-ngx/src/assets/locale/locale.constant-da_DK.json
  12. 1
      ui-ngx/src/assets/locale/locale.constant-de_DE.json
  13. 1
      ui-ngx/src/assets/locale/locale.constant-el_GR.json
  14. 2
      ui-ngx/src/assets/locale/locale.constant-en_US.json
  15. 1
      ui-ngx/src/assets/locale/locale.constant-es_ES.json
  16. 1
      ui-ngx/src/assets/locale/locale.constant-fr_FR.json
  17. 1
      ui-ngx/src/assets/locale/locale.constant-hi_IN.json
  18. 1
      ui-ngx/src/assets/locale/locale.constant-it_IT.json
  19. 1
      ui-ngx/src/assets/locale/locale.constant-ja_JP.json
  20. 1
      ui-ngx/src/assets/locale/locale.constant-ko_KR.json
  21. 1
      ui-ngx/src/assets/locale/locale.constant-lt_LT.json
  22. 1
      ui-ngx/src/assets/locale/locale.constant-nl_BE.json
  23. 1
      ui-ngx/src/assets/locale/locale.constant-nl_NL.json
  24. 1
      ui-ngx/src/assets/locale/locale.constant-no_NO.json
  25. 1
      ui-ngx/src/assets/locale/locale.constant-pl_PL.json
  26. 1
      ui-ngx/src/assets/locale/locale.constant-pt_BR.json
  27. 1
      ui-ngx/src/assets/locale/locale.constant-sl_SI.json
  28. 1
      ui-ngx/src/assets/locale/locale.constant-tr_TR.json
  29. 1
      ui-ngx/src/assets/locale/locale.constant-uk_UA.json
  30. 1
      ui-ngx/src/assets/locale/locale.constant-zh_CN.json
  31. 1
      ui-ngx/src/assets/locale/locale.constant-zh_TW.json

6
application/src/main/java/org/thingsboard/server/service/device/DeviceBulkImportService.java

@ -11,6 +11,7 @@ import lombok.SneakyThrows;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.DataConstants;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
@ -89,7 +90,10 @@ public class DeviceBulkImportService extends AbstractBulkImportService<Device> {
additionalInfo.set("description", new TextNode(value));
break;
case IS_GATEWAY:
additionalInfo.set("gateway", BooleanNode.valueOf(Boolean.parseBoolean(value)));
additionalInfo.set(DataConstants.GATEWAY_PARAMETER, BooleanNode.valueOf(Boolean.parseBoolean(value)));
break;
case OVERWRITE_ACTIVITY_TIME:
additionalInfo.set(DataConstants.OVERWRITE_ACTIVITY_TIME_PARAMETER, BooleanNode.valueOf(Boolean.parseBoolean(value)));
break;
}
device.setAdditionalInfo(additionalInfo);

37
application/src/test/java/org/thingsboard/server/controller/DeviceControllerTest.java

@ -1404,6 +1404,43 @@ public class DeviceControllerTest extends AbstractControllerTest {
assertThat(retrieved.get().getStrValue()).isNotPresent();
}
@Test
public void testBulkImportDeviceWithOverwriteActivityTime() throws Exception {
String deviceName = "some_device";
String deviceType = "some_type";
BulkImportRequest request = new BulkImportRequest();
request.setFile(String.format("NAME,TYPE,OVERWRITE_ACTIVITY_TIME\n%s,%s,true", deviceName, deviceType));
BulkImportRequest.Mapping mapping = new BulkImportRequest.Mapping();
BulkImportRequest.ColumnMapping name = new BulkImportRequest.ColumnMapping();
name.setType(BulkImportColumnType.NAME);
BulkImportRequest.ColumnMapping type = new BulkImportRequest.ColumnMapping();
type.setType(BulkImportColumnType.TYPE);
BulkImportRequest.ColumnMapping overwriteActivityTime = new BulkImportRequest.ColumnMapping();
overwriteActivityTime.setType(BulkImportColumnType.OVERWRITE_ACTIVITY_TIME);
List<BulkImportRequest.ColumnMapping> columns = new ArrayList<>();
columns.add(name);
columns.add(type);
columns.add(overwriteActivityTime);
mapping.setColumns(columns);
mapping.setDelimiter(',');
mapping.setUpdate(true);
mapping.setHeader(true);
request.setMapping(mapping);
BulkImportResult<Device> result = doPostWithTypedResponse("/api/device/bulk_import", request, new TypeReference<>() {});
Assert.assertEquals(1, result.getCreated().get());
Assert.assertEquals(0, result.getErrors().get());
Assert.assertTrue(result.getErrorsList().isEmpty());
Device savedDevice = doGet("/api/tenant/devices?deviceName=" + deviceName, Device.class);
Assert.assertNotNull(savedDevice);
Assert.assertNotNull(savedDevice.getAdditionalInfo());
Assert.assertTrue(savedDevice.getAdditionalInfo().get("overwriteActivityTime").asBoolean());
}
@Test
public void testSaveDeviceWithOutdatedVersion() throws Exception {
Device device = createDevice("Device v1.0");

1
common/data/src/main/java/org/thingsboard/server/common/data/sync/ie/importing/csv/BulkImportColumnType.java

@ -36,6 +36,7 @@ public enum BulkImportColumnType {
SNMP_VERSION,
SNMP_COMMUNITY_STRING,
IS_GATEWAY,
OVERWRITE_ACTIVITY_TIME,
DESCRIPTION,
EDGE_LICENSE_KEY,
CLOUD_ENDPOINT,

2
ui-ngx/src/app/shared/import-export/import-dialog-csv.component.ts

@ -123,7 +123,7 @@ export class ImportDialogCsvComponent extends DialogComponent<ImportDialogCsvCom
ngAfterViewInit() {
let columns = this.columnsAssignmentComponent.columnTypes;
if (this.entityType === EntityType.DEVICE) {
columns = columns.concat(this.columnsAssignmentComponent.columnDeviceCredentials);
columns = columns.concat(this.columnsAssignmentComponent.columnDeviceCredentials, this.columnsAssignmentComponent.columnDeviceGateway);
}
this.allowAssignColumn = columns.map(column => column.value);
}

2
ui-ngx/src/app/shared/import-export/import-export.models.ts

@ -58,6 +58,7 @@ export enum ImportEntityColumnType {
snmpVersion = 'SNMP_VERSION',
snmpCommunityString = 'SNMP_COMMUNITY_STRING',
isGateway = 'IS_GATEWAY',
overwriteActivityTime = 'OVERWRITE_ACTIVITY_TIME',
description = 'DESCRIPTION',
edgeLicenseKey = 'EDGE_LICENSE_KEY',
cloudEndpoint = 'CLOUD_ENDPOINT',
@ -95,6 +96,7 @@ export const importEntityColumnTypeTranslations = new Map<ImportEntityColumnType
[ImportEntityColumnType.snmpVersion, 'import.column-type.snmp.version'],
[ImportEntityColumnType.snmpCommunityString, 'import.column-type.snmp.community-string'],
[ImportEntityColumnType.isGateway, 'import.column-type.isgateway'],
[ImportEntityColumnType.overwriteActivityTime, 'device.overwrite-activity-time'],
[ImportEntityColumnType.description, 'import.column-type.description'],
[ImportEntityColumnType.edgeLicenseKey, 'import.column-type.edge-license-key'],
[ImportEntityColumnType.cloudEndpoint, 'import.column-type.cloud-endpoint'],

7
ui-ngx/src/app/shared/import-export/table-columns-assignment.component.html

@ -34,6 +34,13 @@
</mat-option>
}
</mat-optgroup>
<mat-optgroup label="{{ 'import.gateway' | translate }}">
@for (gatewayColumn of columnDeviceGateway; track gatewayColumn) {
<mat-option [value]="gatewayColumn.value" [disabled]="gatewayColumn.disabled">
{{ columnTypesTranslations.get(gatewayColumn.value) | translate }}
</mat-option>
}
</mat-optgroup>
}
</mat-select>
</mat-cell>

18
ui-ngx/src/app/shared/import-export/table-columns-assignment.component.ts

@ -47,6 +47,8 @@ export class TableColumnsAssignmentComponent implements OnInit, ControlValueAcce
columnDeviceCredentials: AssignmentColumnType[] = [];
columnDeviceGateway: AssignmentColumnType[] = [];
columnTypesTranslations = importEntityColumnTypeTranslations;
readonly entityTypeDevice = EntityType.DEVICE;
@ -76,8 +78,11 @@ export class TableColumnsAssignmentComponent implements OnInit, ControlValueAcce
this.columnTypes.push(
{ value: ImportEntityColumnType.sharedAttribute },
{ value: ImportEntityColumnType.serverAttribute },
{ value: ImportEntityColumnType.timeseries },
{ value: ImportEntityColumnType.isGateway }
{ value: ImportEntityColumnType.timeseries }
);
this.columnDeviceGateway.push(
{ value: ImportEntityColumnType.isGateway },
{ value: ImportEntityColumnType.overwriteActivityTime }
);
this.columnDeviceCredentials.push(
{ value: ImportEntityColumnType.accessToken },
@ -155,12 +160,9 @@ export class TableColumnsAssignmentComponent implements OnInit, ControlValueAcce
this.columnTypes.find((columnType) => columnType.value === ImportEntityColumnType.description).disabled = isSelectDescription;
if (this.entityType === EntityType.DEVICE) {
const isSelectGateway = this.columns.findIndex((column) => column.type === ImportEntityColumnType.isGateway) > -1;
const isGatewayColumnType = this.columnTypes.find((columnType) => columnType.value === ImportEntityColumnType.isGateway);
if (isGatewayColumnType) {
isGatewayColumnType.disabled = isSelectGateway;
}
this.columnDeviceGateway.forEach((columnType) => {
columnType.disabled = this.columns.findIndex(column => column.type === columnType.value) > -1;
});
this.columnDeviceCredentials.forEach((columnCredential) => {
columnCredential.disabled = this.columns.findIndex(column => column.type === columnCredential.value) > -1;

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

@ -3362,7 +3362,6 @@
"community-string": "سلسلة المجتمع SNMP"
},
"isgateway": "هل هو بوابة",
"activity-time-from-gateway-device": "وقت النشاط من جهاز البوابة",
"description": "الوصف",
"edge-license-key": "مفتاح الترخيص",
"cloud-endpoint": "نقطة نهاية السحابة",

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

@ -2821,7 +2821,6 @@
"lwm2m-server-public-key-id": "ID o clau pública del servidor LwM2M"
},
"isgateway": "Es Gateway",
"activity-time-from-gateway-device": "Data d'activitat des del dispositiu gateway",
"description": "Descripció",
"edge-license-key": "Clau de llicència",
"cloud-endpoint": "Punt final del núvol",

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

@ -2133,7 +2133,6 @@
"entity-field": "Pole entity",
"access-token": "Přístupový token",
"isgateway": "Je bránou",
"activity-time-from-gateway-device": "Čas aktivity ze zařízení brány",
"description": "Popis",
"edge-license-key": "Licenční klíč",
"cloud-endpoint": "Cloud Endpoint",

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

@ -5426,7 +5426,6 @@
"community-string": "SNMP-community-streng"
},
"isgateway": "Er Gateway",
"activity-time-from-gateway-device": "Aktivitetstid fra gateway-enhed",
"description": "Beskrivelse",
"edge-license-key": "Licensnøgle",
"cloud-endpoint": "Cloud Endpoint",

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

@ -5424,7 +5424,6 @@
"community-string": "SNMP-Community-String"
},
"isgateway": "Ist Gateway",
"activity-time-from-gateway-device": "Aktivitätszeit vom Gateway-Gerät",
"description": "Beschreibung",
"edge-license-key": "Lizenzschlüssel",
"cloud-endpoint": "Cloud-Endpunkt",

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

@ -5426,7 +5426,6 @@
"community-string": "Community string SNMP"
},
"isgateway": "Είναι Gateway",
"activity-time-from-gateway-device": "Χρόνος δραστηριότητας από συσκευή Gateway",
"description": "Περιγραφή",
"edge-license-key": "Κλειδί άδειας χρήσης",
"cloud-endpoint": "Τελικό σημείο Cloud",

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

@ -5409,6 +5409,7 @@
"column-example": "Example value data",
"column-key": "Attribute/telemetry key",
"credentials": "Credentials",
"gateway": "Gateway",
"csv-delimiter": "CSV delimiter",
"csv-first-line-header": "First line contains column names",
"csv-update-data": "Update attributes/telemetry",
@ -5452,7 +5453,6 @@
"community-string": "SNMP community string"
},
"isgateway": "Is Gateway",
"activity-time-from-gateway-device": "Activity time from gateway device",
"description": "Description",
"edge-license-key": "License Key",
"cloud-endpoint": "Cloud Endpoint",

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

@ -5424,7 +5424,6 @@
"community-string": "Cadena de comunidad SNMP"
},
"isgateway": "Es Gateway",
"activity-time-from-gateway-device": "Hora de actividad desde dispositivo Gateway",
"description": "Descripción",
"edge-license-key": "Clave de licencia",
"cloud-endpoint": "Endpoint de la nube",

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

@ -5424,7 +5424,6 @@
"community-string": "Chaîne de communauté SNMP"
},
"isgateway": "Est une Gateway",
"activity-time-from-gateway-device": "Heure d’activité depuis l’appareil Gateway",
"description": "Description",
"edge-license-key": "Clé de licence",
"cloud-endpoint": "Point de terminaison Cloud",

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

@ -5452,7 +5452,6 @@
"community-string": "SNMP कम्युनिटी स्ट्रिंग"
},
"isgateway": "Gateway है",
"activity-time-from-gateway-device": "Gateway डिवाइस से गतिविधि समय",
"description": "विवरण",
"edge-license-key": "Edge लाइसेंस कुंजी",
"cloud-endpoint": "क्लाउड एंडपॉइंट",

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

@ -5424,7 +5424,6 @@
"community-string": "Stringa community SNMP"
},
"isgateway": "È un gateway",
"activity-time-from-gateway-device": "Orario attività dal dispositivo gateway",
"description": "Descrizione",
"edge-license-key": "Chiave licenza",
"cloud-endpoint": "Endpoint cloud",

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

@ -5424,7 +5424,6 @@
"community-string": "SNMPコミュニティ文字列"
},
"isgateway": "Gatewayかどうか",
"activity-time-from-gateway-device": "Gatewayデバイスからの活動時間",
"description": "説明",
"edge-license-key": "ライセンスキー",
"cloud-endpoint": "クラウドエンドポイント",

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

@ -5444,7 +5444,6 @@
"community-string": "SNMP 커뮤니티 문자열"
},
"isgateway": "Gateway 여부",
"activity-time-from-gateway-device": "Gateway 장치의 활동 시간",
"description": "설명",
"edge-license-key": "라이선스 키",
"cloud-endpoint": "클라우드 엔드포인트",

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

@ -5452,7 +5452,6 @@
"community-string": "SNMP bendruomenės eilutė"
},
"isgateway": "Yra Gateway įrenginys",
"activity-time-from-gateway-device": "Aktyvumo laikas iš Gateway įrenginio",
"description": "Aprašymas",
"edge-license-key": "Licencijos raktas",
"cloud-endpoint": "Debesies galinis taškas",

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

@ -5452,7 +5452,6 @@
"community-string": "SNMP community string"
},
"isgateway": "Is Gateway",
"activity-time-from-gateway-device": "Activiteitstijd van gatewayapparaat",
"description": "Beschrijving",
"edge-license-key": "Licentiesleutel",
"cloud-endpoint": "Cloud-endpoint",

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

@ -5424,7 +5424,6 @@
"community-string": "SNMP community string"
},
"isgateway": "Is Gateway",
"activity-time-from-gateway-device": "Activiteitstijd van gatewayapparaat",
"description": "Beschrijving",
"edge-license-key": "Licentiesleutel",
"cloud-endpoint": "Cloud endpoint",

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

@ -5426,7 +5426,6 @@
"community-string": "SNMP-fellesskapsstreng"
},
"isgateway": "Er gateway",
"activity-time-from-gateway-device": "Aktivitetstid fra gateway-enhet",
"description": "Beskrivelse",
"edge-license-key": "Lisensnøkkel",
"cloud-endpoint": "Cloud-endepunkt",

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

@ -5452,7 +5452,6 @@
"community-string": "Ciąg community SNMP"
},
"isgateway": "Czy Gateway",
"activity-time-from-gateway-device": "Czas aktywności z urządzenia Gateway",
"description": "Opis",
"edge-license-key": "Klucz licencyjny",
"cloud-endpoint": "Punkt końcowy w chmurze",

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

@ -5424,7 +5424,6 @@
"community-string": "String de comunidade SNMP"
},
"isgateway": "É Gateway",
"activity-time-from-gateway-device": "Tempo de atividade do dispositivo gateway",
"description": "Descrição",
"edge-license-key": "Chave de licença",
"cloud-endpoint": "Cloud Endpoint",

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

@ -5442,7 +5442,6 @@
"community-string": "Niz skupnosti SNMP"
},
"isgateway": "Je Gateway",
"activity-time-from-gateway-device": "Čas aktivnosti iz naprave Gateway",
"description": "Opis",
"edge-license-key": "Licenčni ključ",
"cloud-endpoint": "Končna točka v oblaku",

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

@ -5426,7 +5426,6 @@
"community-string": "SNMP topluluk dizesi"
},
"isgateway": "Gateway mi",
"activity-time-from-gateway-device": "Gateway cihazından etkinlik zamanı",
"description": "Açıklama",
"edge-license-key": "Lisans Anahtarı",
"cloud-endpoint": "Bulut Uç Noktası",

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

@ -5424,7 +5424,6 @@
"community-string": "Рядок спільноти SNMP"
},
"isgateway": "Це Gateway",
"activity-time-from-gateway-device": "Час активності з пристрою Gateway",
"description": "Опис",
"edge-license-key": "Ліцензійний ключ",
"cloud-endpoint": "Кінцева точка хмари",

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

@ -5426,7 +5426,6 @@
"community-string": "SNMP 团体字符串"
},
"isgateway": "是否为 Gateway",
"activity-time-from-gateway-device": "来自 Gateway 设备的活动时间",
"description": "描述",
"edge-license-key": "许可证密钥",
"cloud-endpoint": "Cloud Endpoint",

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

@ -3299,7 +3299,6 @@
"lwm2m-server-public-key-id": "LwM2M 伺服器公鑰或識別碼"
},
"isgateway": "是否為 Gateway",
"activity-time-from-gateway-device": "來自 Gateway 裝置的活動時間",
"description": "描述",
"routing-key": "Edge 金鑰",
"secret": "Edge 密鑰",

Loading…
Cancel
Save