Commit b4800ac4c58424f4d8852b8b03c370575cf7e1dd

Authored by Volodymyr Babak
1 parent cd59a8d9

Fixes for import

@@ -53,7 +53,7 @@ import { @@ -53,7 +53,7 @@ import {
53 ImportEntityData 53 ImportEntityData
54 } from '@shared/models/entity.models'; 54 } from '@shared/models/entity.models';
55 import { EntityRelationService } from '@core/http/entity-relation.service'; 55 import { EntityRelationService } from '@core/http/entity-relation.service';
56 -import { deepClone, isDefined, isDefinedAndNotNull } from '@core/utils'; 56 +import { deepClone, generateSecret, guid, isDefined, isDefinedAndNotNull } from '@core/utils';
57 import { Asset } from '@shared/models/asset.models'; 57 import { Asset } from '@shared/models/asset.models';
58 import { Device, DeviceCredentialsType } from '@shared/models/device.models'; 58 import { Device, DeviceCredentialsType } from '@shared/models/device.models';
59 import { AttributeService } from '@core/http/attribute.service'; 59 import { AttributeService } from '@core/http/attribute.service';
@@ -1011,9 +1011,9 @@ export class EntityService { @@ -1011,9 +1011,9 @@ export class EntityService {
1011 description: edgeEntityData.description 1011 description: edgeEntityData.description
1012 }, 1012 },
1013 edgeLicenseKey: edgeEntityData.edgeLicenseKey, 1013 edgeLicenseKey: edgeEntityData.edgeLicenseKey,
1014 - cloudEndpoint: edgeEntityData.cloudEndpoint,  
1015 - routingKey: edgeEntityData.routingKey,  
1016 - secret: edgeEntityData.secret 1014 + cloudEndpoint: edgeEntityData.cloudEndpoint !== '' ? edgeEntityData.cloudEndpoint : window.location.origin,
  1015 + routingKey: edgeEntityData.routingKey !== '' ? edgeEntityData.routingKey : guid(),
  1016 + secret: edgeEntityData.secret !== '' ? edgeEntityData.secret : generateSecret(20)
1017 }; 1017 };
1018 saveEntityObservable = this.edgeService.saveEdge(edge, config); 1018 saveEntityObservable = this.edgeService.saveEdge(edge, config);
1019 break; 1019 break;
@@ -1028,41 +1028,6 @@ export class EntityService { @@ -1028,41 +1028,6 @@ export class EntityService {
1028 let result; 1028 let result;
1029 let additionalInfo; 1029 let additionalInfo;
1030 switch (entityType) { 1030 switch (entityType) {
1031 - case EntityType.EDGE:  
1032 - result = entity as Edge;  
1033 - additionalInfo = result.additionalInfo || {};  
1034 - const edgeEntityData: EdgeImportEntityData = entityData as EdgeImportEntityData;  
1035 - if (result.label !== edgeEntityData.label ||  
1036 - result.type !== edgeEntityData.type ||  
1037 - result.cloudEndpoint !== edgeEntityData.cloudEndpoint ||  
1038 - result.edgeLicenseKey !== edgeEntityData.edgeLicenseKey ||  
1039 - result.routingKey !== edgeEntityData.routingKey ||  
1040 - result.secret !== edgeEntityData.secret ||  
1041 - additionalInfo.description !== edgeEntityData.description) {  
1042 - result.type = edgeEntityData.type;  
1043 - if (edgeEntityData.label !== '') {  
1044 - result.label = edgeEntityData.label;  
1045 - }  
1046 - if (edgeEntityData.description !== '') {  
1047 - result.additionalInfo = additionalInfo;  
1048 - result.additionalInfo.description = edgeEntityData.description;  
1049 - }  
1050 - if (edgeEntityData.cloudEndpoint !== '') {  
1051 - result.cloudEndpoint = edgeEntityData.cloudEndpoint;  
1052 - }  
1053 - if (edgeEntityData.edgeLicenseKey !== '') {  
1054 - result.edgeLicenseKey = edgeEntityData.edgeLicenseKey;  
1055 - }  
1056 - if (edgeEntityData.routingKey !== '') {  
1057 - result.routingKey = edgeEntityData.routingKey;  
1058 - }  
1059 - if (edgeEntityData.cloudEndpoint !== '') {  
1060 - result.secret = edgeEntityData.secret;  
1061 - }  
1062 - tasks.push(this.edgeService.saveEdge(result, config));  
1063 - }  
1064 - tasks.push(this.saveEntityData(entity.id, edgeEntityData, config));  
1065 - break;  
1066 case EntityType.ASSET: 1031 case EntityType.ASSET:
1067 case EntityType.DEVICE: 1032 case EntityType.DEVICE:
1068 result = entity as (Device | Asset); 1033 result = entity as (Device | Asset);
@@ -1089,6 +1054,37 @@ export class EntityService { @@ -1089,6 +1054,37 @@ export class EntityService {
1089 } 1054 }
1090 tasks.push(this.saveEntityData(entity.id, entityData, config)); 1055 tasks.push(this.saveEntityData(entity.id, entityData, config));
1091 break; 1056 break;
  1057 + case EntityType.EDGE:
  1058 + result = entity as Edge;
  1059 + additionalInfo = result.additionalInfo || {};
  1060 + const edgeEntityData: EdgeImportEntityData = entityData as EdgeImportEntityData;
  1061 + if (result.label !== edgeEntityData.label ||
  1062 + result.type !== edgeEntityData.type ||
  1063 + (edgeEntityData.cloudEndpoint !== '' && result.cloudEndpoint !== edgeEntityData.cloudEndpoint) ||
  1064 + (edgeEntityData.edgeLicenseKey !== '' && result.edgeLicenseKey !== edgeEntityData.edgeLicenseKey) ||
  1065 + (edgeEntityData.routingKey !== '' && result.routingKey !== edgeEntityData.routingKey) ||
  1066 + (edgeEntityData.secret !== '' && result.secret !== edgeEntityData.secret) ||
  1067 + additionalInfo.description !== edgeEntityData.description) {
  1068 + result.label = edgeEntityData.label;
  1069 + result.type = edgeEntityData.type;
  1070 + result.additionalInfo = additionalInfo;
  1071 + result.additionalInfo.description = edgeEntityData.description;
  1072 + if (edgeEntityData.cloudEndpoint !== '') {
  1073 + result.cloudEndpoint = edgeEntityData.cloudEndpoint;
  1074 + }
  1075 + if (edgeEntityData.edgeLicenseKey !== '') {
  1076 + result.edgeLicenseKey = edgeEntityData.edgeLicenseKey;
  1077 + }
  1078 + if (edgeEntityData.routingKey !== '') {
  1079 + result.routingKey = edgeEntityData.routingKey;
  1080 + }
  1081 + if (edgeEntityData.secret !== '') {
  1082 + result.secret = edgeEntityData.secret;
  1083 + }
  1084 + tasks.push(this.edgeService.saveEdge(result, config));
  1085 + }
  1086 + tasks.push(this.saveEntityData(entity.id, edgeEntityData, config));
  1087 + break;
1092 } 1088 }
1093 return tasks; 1089 return tasks;
1094 } 1090 }
@@ -34,7 +34,6 @@ import { @@ -34,7 +34,6 @@ import {
34 } from '@home/components/import-export/import-export.models'; 34 } from '@home/components/import-export/import-export.models';
35 import { EdgeImportEntityData, ImportEntitiesResultInfo, ImportEntityData } from '@app/shared/models/entity.models'; 35 import { EdgeImportEntityData, ImportEntitiesResultInfo, ImportEntityData } from '@app/shared/models/entity.models';
36 import { ImportExportService } from '@home/components/import-export/import-export.service'; 36 import { ImportExportService } from '@home/components/import-export/import-export.service';
37 -import { generateSecret, guid } from '@core/utils';  
38 37
39 export interface ImportDialogCsvData { 38 export interface ImportDialogCsvData {
40 entityType: EntityType; 39 entityType: EntityType;
@@ -284,9 +283,9 @@ export class ImportDialogCsvComponent extends DialogComponent<ImportDialogCsvCom @@ -284,9 +283,9 @@ export class ImportDialogCsvComponent extends DialogComponent<ImportDialogCsvCom
284 if (this.entityType === EntityType.EDGE) { 283 if (this.entityType === EntityType.EDGE) {
285 const edgeEntityData: EdgeImportEntityData = entityData as EdgeImportEntityData; 284 const edgeEntityData: EdgeImportEntityData = entityData as EdgeImportEntityData;
286 edgeEntityData.edgeLicenseKey = ''; 285 edgeEntityData.edgeLicenseKey = '';
287 - edgeEntityData.cloudEndpoint = window.location.origin;  
288 - edgeEntityData.routingKey = guid();  
289 - edgeEntityData.secret = generateSecret(20); 286 + edgeEntityData.cloudEndpoint = '';
  287 + edgeEntityData.routingKey = '';
  288 + edgeEntityData.secret = '';
290 return edgeEntityData; 289 return edgeEntityData;
291 } else { 290 } else {
292 return entityData; 291 return entityData;