|
@@ -14,7 +14,7 @@ |
|
@@ -14,7 +14,7 @@ |
14
|
/// limitations under the License.
|
14
|
/// limitations under the License.
|
15
|
///
|
15
|
///
|
16
|
|
16
|
|
17
|
-import { Injectable } from '@angular/core';
|
17
|
+import { Inject, Injectable } from '@angular/core';
|
18
|
import { EMPTY, forkJoin, Observable, of, throwError } from 'rxjs';
|
18
|
import { EMPTY, forkJoin, Observable, of, throwError } from 'rxjs';
|
19
|
import { HttpClient } from '@angular/common/http';
|
19
|
import { HttpClient } from '@angular/common/http';
|
20
|
import { PageLink } from '@shared/models/page/page-link';
|
20
|
import { PageLink } from '@shared/models/page/page-link';
|
|
@@ -46,7 +46,7 @@ import { UtilsService } from '@core/services/utils.service'; |
|
@@ -46,7 +46,7 @@ import { UtilsService } from '@core/services/utils.service'; |
46
|
import { AliasFilterType, EntityAlias, EntityAliasFilter, EntityAliasFilterResult } from '@shared/models/alias.models';
|
46
|
import { AliasFilterType, EntityAlias, EntityAliasFilter, EntityAliasFilterResult } from '@shared/models/alias.models';
|
47
|
import { entityFields, EntityInfo, ImportEntitiesResultInfo, ImportEntityData } from '@shared/models/entity.models';
|
47
|
import { entityFields, EntityInfo, ImportEntitiesResultInfo, ImportEntityData } from '@shared/models/entity.models';
|
48
|
import { EntityRelationService } from '@core/http/entity-relation.service';
|
48
|
import { EntityRelationService } from '@core/http/entity-relation.service';
|
49
|
-import { deepClone, isDefined, isDefinedAndNotNull } from '@core/utils';
|
49
|
+import { deepClone, generateSecret, guid, isDefined, isDefinedAndNotNull } from '@core/utils';
|
50
|
import { Asset } from '@shared/models/asset.models';
|
50
|
import { Asset } from '@shared/models/asset.models';
|
51
|
import { Device, DeviceCredentialsType } from '@shared/models/device.models';
|
51
|
import { Device, DeviceCredentialsType } from '@shared/models/device.models';
|
52
|
import { AttributeService } from '@core/http/attribute.service';
|
52
|
import { AttributeService } from '@core/http/attribute.service';
|
|
@@ -71,6 +71,7 @@ import { alarmFields } from '@shared/models/alarm.models'; |
|
@@ -71,6 +71,7 @@ import { alarmFields } from '@shared/models/alarm.models'; |
71
|
import { EdgeService } from "@core/http/edge.service";
|
71
|
import { EdgeService } from "@core/http/edge.service";
|
72
|
import { ruleChainType } from "@shared/models/rule-chain.models";
|
72
|
import { ruleChainType } from "@shared/models/rule-chain.models";
|
73
|
import { Edge } from '@shared/models/edge.models';
|
73
|
import { Edge } from '@shared/models/edge.models';
|
|
|
74
|
+import { WINDOW } from "@core/services/window.service";
|
74
|
|
75
|
|
75
|
@Injectable({
|
76
|
@Injectable({
|
76
|
providedIn: 'root'
|
77
|
providedIn: 'root'
|
|
@@ -91,7 +92,8 @@ export class EntityService { |
|
@@ -91,7 +92,8 @@ export class EntityService { |
91
|
private dashboardService: DashboardService,
|
92
|
private dashboardService: DashboardService,
|
92
|
private entityRelationService: EntityRelationService,
|
93
|
private entityRelationService: EntityRelationService,
|
93
|
private attributeService: AttributeService,
|
94
|
private attributeService: AttributeService,
|
94
|
- private utils: UtilsService
|
95
|
+ private utils: UtilsService,
|
|
|
96
|
+ @Inject(WINDOW) protected window: Window
|
95
|
) { }
|
97
|
) { }
|
96
|
|
98
|
|
97
|
private getEntityObservable(entityType: EntityType, entityId: string,
|
99
|
private getEntityObservable(entityType: EntityType, entityId: string,
|
|
@@ -901,6 +903,15 @@ export class EntityService { |
|
@@ -901,6 +903,15 @@ export class EntityService { |
901
|
cloudEndpoint: entityData.cloudEndpoint,
|
903
|
cloudEndpoint: entityData.cloudEndpoint,
|
902
|
routingKey: entityData.routingKey,
|
904
|
routingKey: entityData.routingKey,
|
903
|
secret: entityData.secret
|
905
|
secret: entityData.secret
|
|
|
906
|
+ };
|
|
|
907
|
+ if (edge.cloudEndpoint === '') {
|
|
|
908
|
+ edge.cloudEndpoint = this.window.location.origin;
|
|
|
909
|
+ }
|
|
|
910
|
+ if (edge.routingKey === '') {
|
|
|
911
|
+ edge.routingKey = guid();
|
|
|
912
|
+ }
|
|
|
913
|
+ if (edge.secret === '') {
|
|
|
914
|
+ edge.secret = generateSecret(20);
|
904
|
}
|
915
|
}
|
905
|
saveEntityObservable = this.edgeService.saveEdge(edge, config);
|
916
|
saveEntityObservable = this.edgeService.saveEdge(edge, config);
|
906
|
break;
|
917
|
break;
|
|
@@ -924,30 +935,67 @@ export class EntityService { |
|
@@ -924,30 +935,67 @@ export class EntityService { |
924
|
case EntityType.ASSET:
|
935
|
case EntityType.ASSET:
|
925
|
findEntityObservable = this.assetService.findByName(entityData.name, config);
|
936
|
findEntityObservable = this.assetService.findByName(entityData.name, config);
|
926
|
break;
|
937
|
break;
|
|
|
938
|
+ case EntityType.EDGE:
|
|
|
939
|
+ findEntityObservable = this.edgeService.findByName(entityData.name, config);
|
|
|
940
|
+ break;
|
927
|
}
|
941
|
}
|
928
|
return findEntityObservable.pipe(
|
942
|
return findEntityObservable.pipe(
|
929
|
mergeMap((entity) => {
|
943
|
mergeMap((entity) => {
|
930
|
const tasks: Observable<any>[] = [];
|
944
|
const tasks: Observable<any>[] = [];
|
931
|
- const result: Device | Asset = entity as (Device | Asset);
|
|
|
932
|
- const additionalInfo = result.additionalInfo || {};
|
|
|
933
|
- if (result.label !== entityData.label ||
|
|
|
934
|
- result.type !== entityData.type ||
|
|
|
935
|
- additionalInfo.description !== entityData.description ||
|
|
|
936
|
- (result.id.entityType === EntityType.DEVICE && (additionalInfo.gateway !== entityData.gateway)) ) {
|
|
|
937
|
- result.label = entityData.label;
|
|
|
938
|
- result.type = entityData.type;
|
|
|
939
|
- result.additionalInfo = additionalInfo;
|
|
|
940
|
- result.additionalInfo.description = entityData.description;
|
|
|
941
|
- if (result.id.entityType === EntityType.DEVICE) {
|
|
|
942
|
- result.additionalInfo.gateway = entityData.gateway;
|
945
|
+ if (entity.id.entityType === EntityType.EDGE) {
|
|
|
946
|
+ const result: Edge = entity as Edge;
|
|
|
947
|
+ const additionalInfo = result.additionalInfo || {};
|
|
|
948
|
+ if (result.label !== entityData.label ||
|
|
|
949
|
+ result.type !== entityData.type ||
|
|
|
950
|
+ result.cloudEndpoint !== entityData.cloudEndpoint ||
|
|
|
951
|
+ result.edgeLicenseKey !== entityData.edgeLicenseKey ||
|
|
|
952
|
+ result.routingKey !== entityData.routingKey ||
|
|
|
953
|
+ result.secret !== entityData.secret ||
|
|
|
954
|
+ additionalInfo.description !== entityData.description) {
|
|
|
955
|
+ result.type = entityData.type;
|
|
|
956
|
+ if (entityData.label !== '') {
|
|
|
957
|
+ result.label = entityData.label;
|
|
|
958
|
+ }
|
|
|
959
|
+ if (entityData.description !== '') {
|
|
|
960
|
+ result.additionalInfo = additionalInfo;
|
|
|
961
|
+ result.additionalInfo.description = entityData.description;
|
|
|
962
|
+ }
|
|
|
963
|
+ if (entityData.cloudEndpoint !== '') {
|
|
|
964
|
+ result.cloudEndpoint = entityData.cloudEndpoint;
|
|
|
965
|
+ }
|
|
|
966
|
+ if (entityData.edgeLicenseKey !== '') {
|
|
|
967
|
+ result.edgeLicenseKey = entityData.edgeLicenseKey;
|
|
|
968
|
+ }
|
|
|
969
|
+ if (entityData.routingKey !== '') {
|
|
|
970
|
+ result.routingKey = entityData.routingKey;
|
|
|
971
|
+ }
|
|
|
972
|
+ if (entityData.cloudEndpoint !== '') {
|
|
|
973
|
+ result.secret = entityData.secret;
|
|
|
974
|
+ }
|
|
|
975
|
+ tasks.push(this.edgeService.saveEdge(result, config));
|
943
|
}
|
976
|
}
|
944
|
- switch (result.id.entityType) {
|
|
|
945
|
- case EntityType.DEVICE:
|
|
|
946
|
- tasks.push(this.deviceService.saveDevice(result, config));
|
|
|
947
|
- break;
|
|
|
948
|
- case EntityType.ASSET:
|
|
|
949
|
- tasks.push(this.assetService.saveAsset(result, config));
|
|
|
950
|
- break;
|
977
|
+ } else {
|
|
|
978
|
+ const result: Device | Asset = entity as (Device | Asset);
|
|
|
979
|
+ const additionalInfo = result.additionalInfo || {};
|
|
|
980
|
+ if (result.label !== entityData.label ||
|
|
|
981
|
+ result.type !== entityData.type ||
|
|
|
982
|
+ additionalInfo.description !== entityData.description ||
|
|
|
983
|
+ (result.id.entityType === EntityType.DEVICE && (additionalInfo.gateway !== entityData.gateway)) ) {
|
|
|
984
|
+ result.label = entityData.label;
|
|
|
985
|
+ result.type = entityData.type;
|
|
|
986
|
+ result.additionalInfo = additionalInfo;
|
|
|
987
|
+ result.additionalInfo.description = entityData.description;
|
|
|
988
|
+ if (result.id.entityType === EntityType.DEVICE) {
|
|
|
989
|
+ result.additionalInfo.gateway = entityData.gateway;
|
|
|
990
|
+ }
|
|
|
991
|
+ switch (result.id.entityType) {
|
|
|
992
|
+ case EntityType.DEVICE:
|
|
|
993
|
+ tasks.push(this.deviceService.saveDevice(result, config));
|
|
|
994
|
+ break;
|
|
|
995
|
+ case EntityType.ASSET:
|
|
|
996
|
+ tasks.push(this.assetService.saveAsset(result, config));
|
|
|
997
|
+ break;
|
|
|
998
|
+ }
|
951
|
}
|
999
|
}
|
952
|
}
|
1000
|
}
|
953
|
tasks.push(this.saveEntityData(entity.id, entityData, config));
|
1001
|
tasks.push(this.saveEntityData(entity.id, entityData, config));
|