|
|
|
@ -33,7 +33,7 @@ import { |
|
|
|
OBSERVE, |
|
|
|
OBSERVE_ATTR, |
|
|
|
TELEMETRY, |
|
|
|
ObjectLwM2M, getDefaultProfileConfig, KEY_NAME, Instance |
|
|
|
ObjectLwM2M, getDefaultProfileConfig, KEY_NAME, Instance, ProfileConfigModels, ResourceLwM2M |
|
|
|
} from "./profile-config.models"; |
|
|
|
import { DeviceProfileService } from "@core/http/device-profile.service"; |
|
|
|
import { deepClone, isUndefined } from "@core/utils"; |
|
|
|
@ -44,7 +44,6 @@ import { isNotNullOrUndefined } from 'codelyzer/util/isNotNullOrUndefined'; |
|
|
|
@Component({ |
|
|
|
selector: 'tb-profile-lwm2m-device-transport-configuration', |
|
|
|
templateUrl: './lwm2m-device-profile-transport-configuration.component.html', |
|
|
|
styleUrls: [], |
|
|
|
providers: [{ |
|
|
|
provide: NG_VALUE_ACCESSOR, |
|
|
|
useExisting: forwardRef(() => Lwm2mDeviceProfileTransportConfigurationComponent), |
|
|
|
@ -53,6 +52,10 @@ import { isNotNullOrUndefined } from 'codelyzer/util/isNotNullOrUndefined'; |
|
|
|
}) |
|
|
|
export class Lwm2mDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, OnInit, Validators { |
|
|
|
|
|
|
|
private configurationValue: ProfileConfigModels; |
|
|
|
private requiredValue: boolean; |
|
|
|
private disabled = false; |
|
|
|
|
|
|
|
lwm2mDeviceProfileTransportConfFormGroup: FormGroup; |
|
|
|
observeAttr = OBSERVE_ATTR as string; |
|
|
|
observe = OBSERVE as string; |
|
|
|
@ -62,9 +65,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
bootstrapServers: string; |
|
|
|
bootstrapServer: string; |
|
|
|
lwm2mServer: string; |
|
|
|
private configurationValue: {}; |
|
|
|
private requiredValue: boolean; |
|
|
|
private disabled = false as boolean; |
|
|
|
sortFunction = this.sortObjectKeyPathJson; |
|
|
|
|
|
|
|
get required(): boolean { |
|
|
|
@ -76,8 +76,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
this.requiredValue = coerceBooleanProperty(value); |
|
|
|
} |
|
|
|
|
|
|
|
private propagateChange = (v: any) => { |
|
|
|
}; |
|
|
|
private propagateChange = (v: any) => { }; |
|
|
|
|
|
|
|
constructor(private store: Store<AppState>, |
|
|
|
private fb: FormBuilder, |
|
|
|
@ -85,17 +84,17 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
@Inject(WINDOW) private window: Window) { |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup = this.fb.group({ |
|
|
|
objectIds: [{}, Validators.required], |
|
|
|
observeAttrTelemetry: [{'clientLwM2M': [] as ObjectLwM2M []}, Validators.required], |
|
|
|
observeAttrTelemetry: [{clientLwM2M: [] as ObjectLwM2M[]}, Validators.required], |
|
|
|
shortId: [null, Validators.required], |
|
|
|
lifetime: [null, Validators.required], |
|
|
|
defaultMinPeriod: [null, Validators.required], |
|
|
|
notifIfDisabled: [true, []], |
|
|
|
binding: ["U", Validators.required], |
|
|
|
binding: ['U', Validators.required], |
|
|
|
bootstrapServer: [null, Validators.required], |
|
|
|
lwm2mServer: [null, Validators.required], |
|
|
|
configurationJson: [null, Validators.required], |
|
|
|
}); |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.valueChanges.subscribe(value => { |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.valueChanges.subscribe(() => { |
|
|
|
if (!this.disabled) { |
|
|
|
this.updateModel(); |
|
|
|
} |
|
|
|
@ -122,7 +121,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
} |
|
|
|
|
|
|
|
writeValue(value: any | null): void { |
|
|
|
value = (Object.keys(value).length == 0) ? getDefaultProfileConfig() : value; |
|
|
|
value = (Object.keys(value).length === 0) ? getDefaultProfileConfig() : value; |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({ |
|
|
|
configurationJson: value |
|
|
|
}, |
|
|
|
@ -132,14 +131,14 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
} |
|
|
|
|
|
|
|
private initWriteValue(): void { |
|
|
|
let modelValue = {"objectIds": null, "objectsList": []}; |
|
|
|
const modelValue = {objectIds: null, objectsList: []}; |
|
|
|
modelValue.objectIds = this.getObjectsFromJsonAllConfig(); |
|
|
|
if (modelValue.objectIds !== null) { |
|
|
|
this.deviceProfileService.getLwm2mObjects(modelValue.objectIds).subscribe( |
|
|
|
(objectsList) => { |
|
|
|
modelValue.objectsList = objectsList; |
|
|
|
this.updateWriteValue(modelValue); |
|
|
|
} |
|
|
|
(objectsList) => { |
|
|
|
modelValue.objectsList = objectsList; |
|
|
|
this.updateWriteValue(modelValue); |
|
|
|
} |
|
|
|
); |
|
|
|
} else { |
|
|
|
this.updateWriteValue(modelValue); |
|
|
|
@ -147,17 +146,17 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
} |
|
|
|
|
|
|
|
private updateWriteValue(value: any): void { |
|
|
|
let objectsList = deepClone(value.objectsList); |
|
|
|
const objectsList = deepClone(value.objectsList); |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({ |
|
|
|
objectIds: value, |
|
|
|
observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)}, |
|
|
|
shortId: this.configurationValue['bootstrap'].servers.shortId, |
|
|
|
lifetime: this.configurationValue['bootstrap'].servers.lifetime, |
|
|
|
defaultMinPeriod: this.configurationValue['bootstrap'].servers.defaultMinPeriod, |
|
|
|
notifIfDisabled: this.configurationValue['bootstrap'].servers.notifIfDisabled, |
|
|
|
binding: this.configurationValue['bootstrap'].servers.binding, |
|
|
|
bootstrapServer: this.configurationValue['bootstrap'].bootstrapServer, |
|
|
|
lwm2mServer: this.configurationValue['bootstrap'].lwm2mServer |
|
|
|
shortId: this.configurationValue.bootstrap.servers.shortId, |
|
|
|
lifetime: this.configurationValue.bootstrap.servers.lifetime, |
|
|
|
defaultMinPeriod: this.configurationValue.bootstrap.servers.defaultMinPeriod, |
|
|
|
notifIfDisabled: this.configurationValue.bootstrap.servers.notifIfDisabled, |
|
|
|
binding: this.configurationValue.bootstrap.servers.binding, |
|
|
|
bootstrapServer: this.configurationValue.bootstrap.bootstrapServer, |
|
|
|
lwm2mServer: this.configurationValue.bootstrap.lwm2mServer |
|
|
|
}, |
|
|
|
{emitEvent: false}); |
|
|
|
} |
|
|
|
@ -174,10 +173,10 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
|
|
|
|
private updateObserveAttrTelemetryObjectFormGroup(objectsList: ObjectLwM2M[]) { |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({ |
|
|
|
observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)} |
|
|
|
}, |
|
|
|
{emitEvent: false}); |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").markAsPristine({ |
|
|
|
observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)} |
|
|
|
}, |
|
|
|
{emitEvent: false}); |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').markAsPristine({ |
|
|
|
onlySelf: true |
|
|
|
}); |
|
|
|
} |
|
|
|
@ -188,9 +187,11 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
} |
|
|
|
|
|
|
|
upDateValueToJsonTab_0(): void { |
|
|
|
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").pristine) { |
|
|
|
this.upDateObserveAttrTelemetryFromGroupToJson(this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").value['clientLwM2M']); |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").markAsPristine({ |
|
|
|
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').pristine) { |
|
|
|
this.upDateObserveAttrTelemetryFromGroupToJson( |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').value.clientLwM2M |
|
|
|
); |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').markAsPristine({ |
|
|
|
onlySelf: true |
|
|
|
}); |
|
|
|
this.upDateJsonAllConfig(); |
|
|
|
@ -200,14 +201,14 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
upDateValueToJsonTab_1(): void { |
|
|
|
this.upDateValueServersToJson(); |
|
|
|
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').pristine) { |
|
|
|
this.configurationValue['bootstrap'].bootstrapServer = this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').value; |
|
|
|
this.configurationValue.bootstrap.bootstrapServer = this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').value; |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').markAsPristine({ |
|
|
|
onlySelf: true |
|
|
|
}); |
|
|
|
this.upDateJsonAllConfig(); |
|
|
|
} |
|
|
|
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').pristine) { |
|
|
|
this.configurationValue['bootstrap'].lwm2mServer = this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').value; |
|
|
|
this.configurationValue.bootstrap.lwm2mServer = this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').value; |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').markAsPristine({ |
|
|
|
onlySelf: true |
|
|
|
}); |
|
|
|
@ -216,36 +217,37 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
} |
|
|
|
|
|
|
|
upDateValueServersToJson(): void { |
|
|
|
const bootstrapServers = this.configurationValue.bootstrap.servers; |
|
|
|
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').pristine) { |
|
|
|
this.configurationValue['bootstrap'].servers.shortId = this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').value; |
|
|
|
bootstrapServers.shortId = this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').value; |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').markAsPristine({ |
|
|
|
onlySelf: true |
|
|
|
}); |
|
|
|
this.upDateJsonAllConfig(); |
|
|
|
} |
|
|
|
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').pristine) { |
|
|
|
this.configurationValue['bootstrap'].servers.lifetime = this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').value; |
|
|
|
bootstrapServers.lifetime = this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').value; |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').markAsPristine({ |
|
|
|
onlySelf: true |
|
|
|
}); |
|
|
|
this.upDateJsonAllConfig(); |
|
|
|
} |
|
|
|
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').pristine) { |
|
|
|
this.configurationValue['bootstrap'].servers.defaultMinPeriod = this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').value; |
|
|
|
bootstrapServers.defaultMinPeriod = this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').value; |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').markAsPristine({ |
|
|
|
onlySelf: true |
|
|
|
}); |
|
|
|
this.upDateJsonAllConfig(); |
|
|
|
} |
|
|
|
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').pristine) { |
|
|
|
this.configurationValue['bootstrap'].servers.notifIfDisabled = this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').value; |
|
|
|
bootstrapServers.notifIfDisabled = this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').value; |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').markAsPristine({ |
|
|
|
onlySelf: true |
|
|
|
}); |
|
|
|
this.upDateJsonAllConfig(); |
|
|
|
} |
|
|
|
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').pristine) { |
|
|
|
this.configurationValue['bootstrap'].servers.binding = this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').value; |
|
|
|
bootstrapServers.binding = this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').value; |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').markAsPristine({ |
|
|
|
onlySelf: true |
|
|
|
}); |
|
|
|
@ -254,122 +256,130 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
} |
|
|
|
|
|
|
|
getObserveAttrTelemetryObjects(listObject: ObjectLwM2M[]): ObjectLwM2M [] { |
|
|
|
let clientObserveAttr = deepClone(listObject) as ObjectLwM2M[]; |
|
|
|
const clientObserveAttr = deepClone(listObject); |
|
|
|
if (this.configurationValue[this.observeAttr]) { |
|
|
|
let observeArray = this.configurationValue[this.observeAttr][this.observe] as Array<string>; |
|
|
|
let attributeArray = this.configurationValue[this.observeAttr][this.attribute] as Array<string>; |
|
|
|
let telemetryArray = this.configurationValue[this.observeAttr][this.telemetry] as Array<string>; |
|
|
|
let keyNameJson = this.configurationValue[this.observeAttr][this.keyName] as JsonObject; |
|
|
|
if (this.includesInstancesNo(attributeArray, telemetryArray, clientObserveAttr)) { |
|
|
|
const observeArray = this.configurationValue[this.observeAttr][this.observe] as Array<string>; |
|
|
|
const attributeArray = this.configurationValue[this.observeAttr][this.attribute] as Array<string>; |
|
|
|
const telemetryArray = this.configurationValue[this.observeAttr][this.telemetry] as Array<string>; |
|
|
|
const keyNameJson = this.configurationValue[this.observeAttr][this.keyName] as JsonObject; |
|
|
|
if (this.includesInstancesNo(attributeArray, telemetryArray)) { |
|
|
|
this.addInstances(attributeArray, telemetryArray, clientObserveAttr); |
|
|
|
} |
|
|
|
if (observeArray) this.updateObserveAttrTelemetryObjects(observeArray, clientObserveAttr, "observe"); |
|
|
|
if (attributeArray) this.updateObserveAttrTelemetryObjects(attributeArray, clientObserveAttr, "attribute"); |
|
|
|
if (telemetryArray) this.updateObserveAttrTelemetryObjects(telemetryArray, clientObserveAttr, "telemetry"); |
|
|
|
if (keyNameJson) this.updateKeyNameObjects(deepClone(keyNameJson), clientObserveAttr); |
|
|
|
if (observeArray) { |
|
|
|
this.updateObserveAttrTelemetryObjects(observeArray, clientObserveAttr, 'observe'); |
|
|
|
} |
|
|
|
if (attributeArray) { |
|
|
|
this.updateObserveAttrTelemetryObjects(attributeArray, clientObserveAttr, 'attribute'); |
|
|
|
} |
|
|
|
if (telemetryArray) { |
|
|
|
this.updateObserveAttrTelemetryObjects(telemetryArray, clientObserveAttr, 'telemetry'); |
|
|
|
} |
|
|
|
if (keyNameJson) { |
|
|
|
this.updateKeyNameObjects(deepClone(keyNameJson), clientObserveAttr); |
|
|
|
} |
|
|
|
} |
|
|
|
clientObserveAttr.forEach(obj => { |
|
|
|
obj.instances.sort((a,b) => a.id - b.id);; |
|
|
|
}) |
|
|
|
obj.instances.sort((a, b) => a.id - b.id); |
|
|
|
}); |
|
|
|
return clientObserveAttr; |
|
|
|
} |
|
|
|
|
|
|
|
includesInstancesNo(attributeArray: Array<string>, telemetryArray: Array<string>, clientObserveAttr: ObjectLwM2M[]): boolean { |
|
|
|
let isIdIndex = (element) => !element.includes("/0/"); |
|
|
|
return attributeArray.findIndex(isIdIndex) >= 0 || telemetryArray.findIndex(isIdIndex) >= 0 |
|
|
|
|
|
|
|
includesInstancesNo(attributeArray: Array<string>, telemetryArray: Array<string>): boolean { |
|
|
|
const isIdIndex = (element) => !element.includes('/0/'); |
|
|
|
return attributeArray.findIndex(isIdIndex) >= 0 || telemetryArray.findIndex(isIdIndex) >= 0; |
|
|
|
} |
|
|
|
|
|
|
|
addInstances(attributeArray: Array<string>, telemetryArray: Array<string>, clientObserveAttr: ObjectLwM2M[]): void { |
|
|
|
let attr = [] as Array<string>; |
|
|
|
[...attributeArray].filter(x => (!x.includes("/0/"))).forEach(x => { |
|
|
|
const attr = [] as Array<string>; |
|
|
|
[...attributeArray].filter(x => (!x.includes('/0/'))).forEach(x => { |
|
|
|
attr.push(this.convertPathToInstance(x)); |
|
|
|
}); |
|
|
|
let telemetry = [] as Array<string>; |
|
|
|
[...telemetryArray].filter(x => (!x.includes("/0/"))).forEach(x => { |
|
|
|
const telemetry = [] as Array<string>; |
|
|
|
[...telemetryArray].filter(x => (!x.includes('/0/'))).forEach(x => { |
|
|
|
telemetry.push(this.convertPathToInstance(x)); |
|
|
|
}); |
|
|
|
let instancesNoZero = new Set(attr.concat(telemetry).sort()); |
|
|
|
const instancesNoZero = new Set(attr.concat(telemetry).sort()); |
|
|
|
instancesNoZero.forEach(path => { |
|
|
|
let pathParameter = Array.from(path.split('/'), Number); |
|
|
|
let objectLwM2M = clientObserveAttr.find(x => (x.id === pathParameter[0])); |
|
|
|
const pathParameter = Array.from(path.split('/'), Number); |
|
|
|
const objectLwM2M = clientObserveAttr.find(x => (x.id === pathParameter[0])); |
|
|
|
if (objectLwM2M) { |
|
|
|
let instance = deepClone(objectLwM2M.instances[0]) as Instance; |
|
|
|
const instance = deepClone(objectLwM2M.instances[0]) as Instance; |
|
|
|
instance.id = pathParameter[1]; |
|
|
|
objectLwM2M.instances.push(instance); |
|
|
|
} |
|
|
|
}) |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
convertPathToInstance(path: string): string { |
|
|
|
let newX = Array.from(path.substring(1).split('/'), Number); |
|
|
|
return [newX[0], newX[1]].join("/"); |
|
|
|
const newX = Array.from(path.substring(1).split('/'), Number); |
|
|
|
return [newX[0], newX[1]].join('/'); |
|
|
|
} |
|
|
|
|
|
|
|
updateObserveAttrTelemetryObjects(isParameter: Array<string>, clientObserveAttr: ObjectLwM2M[], nameParameter: string): void { |
|
|
|
isParameter.forEach(attr => { |
|
|
|
let idKeys = Array.from(attr.substring(1).split('/'), Number); |
|
|
|
const idKeys = Array.from(attr.substring(1).split('/'), Number); |
|
|
|
clientObserveAttr |
|
|
|
.forEach(e => { |
|
|
|
if (e.id == idKeys[0]) { |
|
|
|
let instance = e.instances.find(e => e.id == idKeys[1]); |
|
|
|
if (isNotNullOrUndefined(instance)) { |
|
|
|
instance.resources.find(e => e.id == idKeys[2])[nameParameter] = true; |
|
|
|
.forEach(e => { |
|
|
|
if (e.id === idKeys[0]) { |
|
|
|
const instance = e.instances.find(itrInstance => itrInstance.id === idKeys[1]); |
|
|
|
if (isNotNullOrUndefined(instance)) { |
|
|
|
instance.resources.find(resource => resource.id === idKeys[2])[nameParameter] = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
updateKeyNameObjects(nameJson: JsonObject, clientObserveAttr: ObjectLwM2M[]): void { |
|
|
|
let keyName = JSON.parse(JSON.stringify(nameJson)); |
|
|
|
Object.keys(keyName).forEach(function (key) { |
|
|
|
let idKeys = Array.from(key.substring(1).split('/'), Number); |
|
|
|
const keyName = JSON.parse(JSON.stringify(nameJson)); |
|
|
|
Object.keys(keyName).forEach(key => { |
|
|
|
const idKeys = Array.from(key.substring(1).split('/'), Number); |
|
|
|
clientObserveAttr |
|
|
|
.forEach(e => { |
|
|
|
if (e.id == idKeys[0]) { |
|
|
|
e.instances.find(e => e.id == idKeys[1]).resources |
|
|
|
.find(e => e.id == idKeys[2]).keyName = keyName[key]; |
|
|
|
} |
|
|
|
}); |
|
|
|
.forEach(e => { |
|
|
|
if (e.id === idKeys[0]) { |
|
|
|
e.instances |
|
|
|
.find(instance => instance.id === idKeys[1]).resources |
|
|
|
.find(resource => resource.id === idKeys[2]).keyName = keyName[key]; |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
upDateObserveAttrTelemetryFromGroupToJson(val: ObjectLwM2M []): void { |
|
|
|
let observeArray = [] as Array<string>; |
|
|
|
let attributeArray = [] as Array<string>; |
|
|
|
let telemetryArray = [] as Array<string>; |
|
|
|
let observeJson = JSON.parse(JSON.stringify(val)); |
|
|
|
upDateObserveAttrTelemetryFromGroupToJson(val: ObjectLwM2M[]): void { |
|
|
|
const observeArray: Array<string> = []; |
|
|
|
const attributeArray: Array<string> = []; |
|
|
|
const telemetryArray: Array<string> = []; |
|
|
|
const observeJson: ObjectLwM2M[] = JSON.parse(JSON.stringify(val)); |
|
|
|
let pathObj; |
|
|
|
let pathInst; |
|
|
|
let pathRes |
|
|
|
let pathRes; |
|
|
|
observeJson.forEach(obj => { |
|
|
|
Object.entries(obj).forEach(([key, value]) => { |
|
|
|
if (key === 'id') { |
|
|
|
pathObj = value; |
|
|
|
} |
|
|
|
if (key === 'instances') { |
|
|
|
let instancesJson = JSON.parse(JSON.stringify(value)) as []; |
|
|
|
const instancesJson = JSON.parse(JSON.stringify(value)) as Instance[]; |
|
|
|
if (instancesJson.length > 0) { |
|
|
|
instancesJson.forEach(instance => { |
|
|
|
Object.entries(instance).forEach(([key, value]) => { |
|
|
|
if (key === 'id') { |
|
|
|
pathInst = value; |
|
|
|
Object.entries(instance).forEach(([instanceKey, instanceValue]) => { |
|
|
|
if (instanceKey === 'id') { |
|
|
|
pathInst = instanceValue; |
|
|
|
} |
|
|
|
if (key === 'resources') { |
|
|
|
let resourcesJson = JSON.parse(JSON.stringify(value)) as []; |
|
|
|
if (instanceKey === 'resources') { |
|
|
|
const resourcesJson = JSON.parse(JSON.stringify(instanceValue)) as ResourceLwM2M[]; |
|
|
|
if (resourcesJson.length > 0) { |
|
|
|
resourcesJson.forEach(res => { |
|
|
|
Object.entries(res).forEach(([key, value]) => { |
|
|
|
if (key === 'id') { |
|
|
|
// pathRes = value
|
|
|
|
pathRes = '/' + pathObj + '/' + pathInst + '/' + value; |
|
|
|
} else if (key === 'observe' && value) { |
|
|
|
observeArray.push(pathRes) |
|
|
|
} else if (key === 'attribute' && value) { |
|
|
|
attributeArray.push(pathRes) |
|
|
|
} else if (key === 'telemetry' && value) { |
|
|
|
telemetryArray.push(pathRes) |
|
|
|
Object.entries(res).forEach(([resourceKey, resourceValue]) => { |
|
|
|
if (resourceKey === 'id') { |
|
|
|
// pathRes = resourceValue
|
|
|
|
pathRes = '/' + pathObj + '/' + pathInst + '/' + resourceValue; |
|
|
|
} else if (resourceKey === 'observe' && resourceValue) { |
|
|
|
observeArray.push(pathRes); |
|
|
|
} else if (resourceKey === 'attribute' && resourceValue) { |
|
|
|
attributeArray.push(pathRes); |
|
|
|
} else if (resourceKey === 'telemetry' && resourceValue) { |
|
|
|
telemetryArray.push(pathRes); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
@ -396,19 +406,19 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
} |
|
|
|
|
|
|
|
sortObjectKeyPathJson(key, value) { |
|
|
|
if (key == "keyName") { |
|
|
|
if (key === 'keyName') { |
|
|
|
return Object.keys(value).sort((a, b) => { |
|
|
|
let aLC = Array.from(a.substring(1).split('/'), Number); |
|
|
|
let bLC = Array.from(b.substring(1).split('/'), Number); |
|
|
|
return aLC[0] == bLC[0] ? aLC[1] - bLC[1] : aLC[0] - bLC[0]; |
|
|
|
}).reduce((r, k) => (r[k] = value[k], r), {}); |
|
|
|
const aLC = Array.from(a.substring(1).split('/'), Number); |
|
|
|
const bLC = Array.from(b.substring(1).split('/'), Number); |
|
|
|
return aLC[0] === bLC[0] ? aLC[1] - bLC[1] : aLC[0] - bLC[0]; |
|
|
|
}).reduce((r, k) => r[k] = value[k], {}); |
|
|
|
} else { |
|
|
|
return value |
|
|
|
return value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
updateKeyName(): void { |
|
|
|
let paths = new Set<string>(); |
|
|
|
const paths = new Set<string>(); |
|
|
|
if (this.configurationValue[this.observeAttr][this.attribute]) { |
|
|
|
this.configurationValue[this.observeAttr][this.attribute].forEach(path => { |
|
|
|
paths.add(path); |
|
|
|
@ -419,31 +429,32 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
paths.add(path); |
|
|
|
}); |
|
|
|
} |
|
|
|
let keyNameNew = {}; |
|
|
|
const keyNameNew = {}; |
|
|
|
paths.forEach(path => { |
|
|
|
let pathParameter = this.findIndexsForIds(path); |
|
|
|
const pathParameter = this.findIndexsForIds(path); |
|
|
|
if (pathParameter.length === 3) { |
|
|
|
let value = this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").value['clientLwM2M'][pathParameter[0]].instances[pathParameter[1]].resources[pathParameter[2]][this.keyName]; |
|
|
|
keyNameNew[path] = value; |
|
|
|
keyNameNew[path] = this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').value |
|
|
|
.clientLwM2M[pathParameter[0]].instances[pathParameter[1]].resources[pathParameter[2]][this.keyName]; |
|
|
|
} |
|
|
|
}); |
|
|
|
this.configurationValue[this.observeAttr][this.keyName] = this.sortObjectKeyPathJson("keyName", keyNameNew); |
|
|
|
this.configurationValue[this.observeAttr][this.keyName] = this.sortObjectKeyPathJson('keyName', keyNameNew); |
|
|
|
} |
|
|
|
|
|
|
|
findIndexsForIds(path: string): number[] { |
|
|
|
let pathParameter = Array.from(path.substring(1).split('/'), Number); |
|
|
|
let pathParameterIndexes = [] as number[]; |
|
|
|
let objectsOld = deepClone(this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").value.clientLwM2M) as ObjectLwM2M[]; |
|
|
|
const pathParameter = Array.from(path.substring(1).split('/'), Number); |
|
|
|
const pathParameterIndexes: number[] = []; |
|
|
|
const objectsOld = deepClone( |
|
|
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').value.clientLwM2M) as ObjectLwM2M[]; |
|
|
|
let isIdIndex = (element) => element.id === pathParameter[0]; |
|
|
|
let objIndex = objectsOld.findIndex(isIdIndex); |
|
|
|
const objIndex = objectsOld.findIndex(isIdIndex); |
|
|
|
if (objIndex >= 0) { |
|
|
|
pathParameterIndexes.push(objIndex); |
|
|
|
isIdIndex = (element) => element.id === pathParameter[1]; |
|
|
|
let instIndex = objectsOld[objIndex].instances.findIndex(isIdIndex); |
|
|
|
const instIndex = objectsOld[objIndex].instances.findIndex(isIdIndex); |
|
|
|
if (instIndex >= 0) { |
|
|
|
pathParameterIndexes.push(instIndex); |
|
|
|
isIdIndex = (element) => element.id === pathParameter[2]; |
|
|
|
let resIndex = objectsOld[objIndex].instances[instIndex].resources.findIndex(isIdIndex); |
|
|
|
const resIndex = objectsOld[objIndex].instances[instIndex].resources.findIndex(isIdIndex); |
|
|
|
if (resIndex >= 0) { |
|
|
|
pathParameterIndexes.push(resIndex); |
|
|
|
} |
|
|
|
@ -453,7 +464,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
} |
|
|
|
|
|
|
|
getObjectsFromJsonAllConfig(): number [] { |
|
|
|
let objectsIds = new Set<number>(); |
|
|
|
const objectsIds = new Set<number>(); |
|
|
|
if (this.configurationValue[this.observeAttr]) { |
|
|
|
if (this.configurationValue[this.observeAttr][this.observe]) { |
|
|
|
this.configurationValue[this.observeAttr][this.observe].forEach(obj => { |
|
|
|
@ -488,9 +499,9 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
} |
|
|
|
|
|
|
|
removeObjectsList(value: ObjectLwM2M): void { |
|
|
|
let objectsOld = deepClone(this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").value.clientLwM2M); |
|
|
|
const objectsOld = deepClone(this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').value.clientLwM2M); |
|
|
|
const isIdIndex = (element) => element.id === value.id; |
|
|
|
let index = objectsOld.findIndex(isIdIndex); |
|
|
|
const index = objectsOld.findIndex(isIdIndex); |
|
|
|
if (index >= 0) { |
|
|
|
objectsOld.splice(index, 1); |
|
|
|
} |
|
|
|
@ -504,7 +515,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
} |
|
|
|
|
|
|
|
removeObserveAttrTelemetryFromJson(observeAttrTel: string, id: number): void { |
|
|
|
let isIdIndex = (element) => Array.from(element.substring(1).split('/'), Number)[0] === id; |
|
|
|
const isIdIndex = (element) => Array.from(element.substring(1).split('/'), Number)[0] === id; |
|
|
|
let index = this.configurationValue[this.observeAttr][observeAttrTel].findIndex(isIdIndex); |
|
|
|
while (index >= 0) { |
|
|
|
this.configurationValue[this.observeAttr][observeAttrTel].splice(index, 1); |
|
|
|
@ -513,9 +524,9 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
} |
|
|
|
|
|
|
|
removeKeyNameFromJson(id: number): void { |
|
|
|
let keyNmaeJson = this.configurationValue[this.observeAttr][this.keyName]; |
|
|
|
Object.keys(keyNmaeJson).forEach(function (key) { |
|
|
|
let idKey = Array.from(key.substring(1).split('/'), Number)[0]; |
|
|
|
const keyNmaeJson = this.configurationValue[this.observeAttr][this.keyName]; |
|
|
|
Object.keys(keyNmaeJson).forEach(key => { |
|
|
|
const idKey = Array.from(key.substring(1).split('/'), Number)[0]; |
|
|
|
if (idKey === id) { |
|
|
|
delete keyNmaeJson[key]; |
|
|
|
} |
|
|
|
|