From b4800ac4c58424f4d8852b8b03c370575cf7e1dd Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Fri, 22 Jan 2021 10:49:20 +0200 Subject: [PATCH] Fixes for import --- ui-ngx/src/app/core/http/entity.service.ts | 74 +++++++++---------- .../import-dialog-csv.component.ts | 7 +- 2 files changed, 38 insertions(+), 43 deletions(-) diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index 585050d637..7da7bf61f7 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -53,7 +53,7 @@ import { ImportEntityData } from '@shared/models/entity.models'; import { EntityRelationService } from '@core/http/entity-relation.service'; -import { deepClone, isDefined, isDefinedAndNotNull } from '@core/utils'; +import { deepClone, generateSecret, guid, isDefined, isDefinedAndNotNull } from '@core/utils'; import { Asset } from '@shared/models/asset.models'; import { Device, DeviceCredentialsType } from '@shared/models/device.models'; import { AttributeService } from '@core/http/attribute.service'; @@ -1011,9 +1011,9 @@ export class EntityService { description: edgeEntityData.description }, edgeLicenseKey: edgeEntityData.edgeLicenseKey, - cloudEndpoint: edgeEntityData.cloudEndpoint, - routingKey: edgeEntityData.routingKey, - secret: edgeEntityData.secret + cloudEndpoint: edgeEntityData.cloudEndpoint !== '' ? edgeEntityData.cloudEndpoint : window.location.origin, + routingKey: edgeEntityData.routingKey !== '' ? edgeEntityData.routingKey : guid(), + secret: edgeEntityData.secret !== '' ? edgeEntityData.secret : generateSecret(20) }; saveEntityObservable = this.edgeService.saveEdge(edge, config); break; @@ -1028,41 +1028,6 @@ export class EntityService { let result; let additionalInfo; switch (entityType) { - case EntityType.EDGE: - result = entity as Edge; - additionalInfo = result.additionalInfo || {}; - const edgeEntityData: EdgeImportEntityData = entityData as EdgeImportEntityData; - if (result.label !== edgeEntityData.label || - result.type !== edgeEntityData.type || - result.cloudEndpoint !== edgeEntityData.cloudEndpoint || - result.edgeLicenseKey !== edgeEntityData.edgeLicenseKey || - result.routingKey !== edgeEntityData.routingKey || - result.secret !== edgeEntityData.secret || - additionalInfo.description !== edgeEntityData.description) { - result.type = edgeEntityData.type; - if (edgeEntityData.label !== '') { - result.label = edgeEntityData.label; - } - if (edgeEntityData.description !== '') { - result.additionalInfo = additionalInfo; - result.additionalInfo.description = edgeEntityData.description; - } - if (edgeEntityData.cloudEndpoint !== '') { - result.cloudEndpoint = edgeEntityData.cloudEndpoint; - } - if (edgeEntityData.edgeLicenseKey !== '') { - result.edgeLicenseKey = edgeEntityData.edgeLicenseKey; - } - if (edgeEntityData.routingKey !== '') { - result.routingKey = edgeEntityData.routingKey; - } - if (edgeEntityData.cloudEndpoint !== '') { - result.secret = edgeEntityData.secret; - } - tasks.push(this.edgeService.saveEdge(result, config)); - } - tasks.push(this.saveEntityData(entity.id, edgeEntityData, config)); - break; case EntityType.ASSET: case EntityType.DEVICE: result = entity as (Device | Asset); @@ -1089,6 +1054,37 @@ export class EntityService { } tasks.push(this.saveEntityData(entity.id, entityData, config)); break; + case EntityType.EDGE: + result = entity as Edge; + additionalInfo = result.additionalInfo || {}; + const edgeEntityData: EdgeImportEntityData = entityData as EdgeImportEntityData; + if (result.label !== edgeEntityData.label || + result.type !== edgeEntityData.type || + (edgeEntityData.cloudEndpoint !== '' && result.cloudEndpoint !== edgeEntityData.cloudEndpoint) || + (edgeEntityData.edgeLicenseKey !== '' && result.edgeLicenseKey !== edgeEntityData.edgeLicenseKey) || + (edgeEntityData.routingKey !== '' && result.routingKey !== edgeEntityData.routingKey) || + (edgeEntityData.secret !== '' && result.secret !== edgeEntityData.secret) || + additionalInfo.description !== edgeEntityData.description) { + result.label = edgeEntityData.label; + result.type = edgeEntityData.type; + result.additionalInfo = additionalInfo; + result.additionalInfo.description = edgeEntityData.description; + if (edgeEntityData.cloudEndpoint !== '') { + result.cloudEndpoint = edgeEntityData.cloudEndpoint; + } + if (edgeEntityData.edgeLicenseKey !== '') { + result.edgeLicenseKey = edgeEntityData.edgeLicenseKey; + } + if (edgeEntityData.routingKey !== '') { + result.routingKey = edgeEntityData.routingKey; + } + if (edgeEntityData.secret !== '') { + result.secret = edgeEntityData.secret; + } + tasks.push(this.edgeService.saveEdge(result, config)); + } + tasks.push(this.saveEntityData(entity.id, edgeEntityData, config)); + break; } return tasks; } diff --git a/ui-ngx/src/app/modules/home/components/import-export/import-dialog-csv.component.ts b/ui-ngx/src/app/modules/home/components/import-export/import-dialog-csv.component.ts index c7e40e92ea..f878d67dee 100644 --- a/ui-ngx/src/app/modules/home/components/import-export/import-dialog-csv.component.ts +++ b/ui-ngx/src/app/modules/home/components/import-export/import-dialog-csv.component.ts @@ -34,7 +34,6 @@ import { } from '@home/components/import-export/import-export.models'; import { EdgeImportEntityData, ImportEntitiesResultInfo, ImportEntityData } from '@app/shared/models/entity.models'; import { ImportExportService } from '@home/components/import-export/import-export.service'; -import { generateSecret, guid } from '@core/utils'; export interface ImportDialogCsvData { entityType: EntityType; @@ -284,9 +283,9 @@ export class ImportDialogCsvComponent extends DialogComponent