...
|
...
|
@@ -82,7 +82,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
82
|
82
|
private deviceProfileService: DeviceProfileService,
|
83
|
83
|
@Inject(WINDOW) private window: Window) {
|
84
|
84
|
this.lwm2mDeviceProfileFormGroup = this.fb.group({
|
85
|
|
- objectIds: [[], Validators.required],
|
|
85
|
+ objectIds: [null, Validators.required],
|
86
|
86
|
observeAttrTelemetry: [null, Validators.required],
|
87
|
87
|
shortId: [null, Validators.required],
|
88
|
88
|
lifetime: [null, Validators.required],
|
...
|
...
|
@@ -96,15 +96,10 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
96
|
96
|
configurationJson: [null, Validators.required]
|
97
|
97
|
});
|
98
|
98
|
this.lwm2mDeviceProfileFormGroup.valueChanges.subscribe((value) => {
|
99
|
|
- if (!this.disabled) {
|
100
|
|
- this.updateDeviceProfileValue(value);
|
101
|
|
- }
|
|
99
|
+ this.updateDeviceProfileValue(value);
|
102
|
100
|
});
|
103
|
101
|
this.lwm2mDeviceConfigFormGroup.valueChanges.subscribe(() => {
|
104
|
|
- console.warn('config form');
|
105
|
|
- if (!this.disabled) {
|
106
|
|
- this.updateModel();
|
107
|
|
- }
|
|
102
|
+ this.updateModel();
|
108
|
103
|
});
|
109
|
104
|
this.sortFunction = this.sortObjectKeyPathJson;
|
110
|
105
|
}
|
...
|
...
|
@@ -188,7 +183,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
188
|
183
|
|
189
|
184
|
private updateDeviceProfileValue(config): void {
|
190
|
185
|
if (this.lwm2mDeviceProfileFormGroup.valid) {
|
191
|
|
- this.upDateObserveAttrTelemetryFromGroupToJson(config.observeAttrTelemetry.clientLwM2M);
|
|
186
|
+ this.updateObserveAttrTelemetryFromGroupToJson(config.observeAttrTelemetry.clientLwM2M);
|
192
|
187
|
this.configurationValue.bootstrap.bootstrapServer = config.bootstrapServer;
|
193
|
188
|
this.configurationValue.bootstrap.lwm2mServer = config.lwm2mServer;
|
194
|
189
|
const bootstrapServers = this.configurationValue.bootstrap.servers;
|
...
|
...
|
@@ -225,9 +220,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
225
|
220
|
this.updateKeyNameObjects(keyNameJson, clientObserveAttrTelemetry);
|
226
|
221
|
}
|
227
|
222
|
}
|
228
|
|
- clientObserveAttrTelemetry.forEach(obj => {
|
229
|
|
- obj.instances.sort((a, b) => a.id - b.id);
|
230
|
|
- });
|
231
|
223
|
return {clientLwM2M: clientObserveAttrTelemetry};
|
232
|
224
|
}
|
233
|
225
|
|
...
|
...
|
@@ -239,8 +231,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
239
|
231
|
private addInstances = (attribute: string[], telemetry: string[], clientObserveAttrTelemetry: ObjectLwM2M[]): void => {
|
240
|
232
|
const instancesPath = attribute.concat(telemetry)
|
241
|
233
|
.filter(instance => !instance.includes('/0/'))
|
242
|
|
- .map(instance => this.convertPathToInstance(instance))
|
243
|
|
- .sort();
|
|
234
|
+ .map(instance => instance.slice(1, instance.lastIndexOf('/')))
|
|
235
|
+ .sort(this.sortPath);
|
244
|
236
|
|
245
|
237
|
new Set(instancesPath).forEach(path => {
|
246
|
238
|
const pathParameter = Array.from(path.split('/'), Number);
|
...
|
...
|
@@ -253,24 +245,14 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
253
|
245
|
});
|
254
|
246
|
}
|
255
|
247
|
|
256
|
|
- private convertPathToInstance = (path: string): string => {
|
257
|
|
- const [objectId, instanceId] = path.substring(1).split('/');
|
258
|
|
- return `${objectId}/${instanceId}`;
|
259
|
|
- }
|
260
|
|
-
|
261
|
248
|
private updateObserveAttrTelemetryObjects = (parameters: string[], clientObserveAttrTelemetry: ObjectLwM2M[],
|
262
|
249
|
nameParameter: string): void => {
|
263
|
250
|
parameters.forEach(parameter => {
|
264
|
251
|
const [objectId, instanceId, resourceId] = Array.from(parameter.substring(1).split('/'), Number);
|
265
|
|
- clientObserveAttrTelemetry
|
266
|
|
- .forEach(key => {
|
267
|
|
- if (key.id === objectId) {
|
268
|
|
- const instance = key.instances.find(itrInstance => itrInstance.id === instanceId);
|
269
|
|
- if (isDefinedAndNotNull(instance)) {
|
270
|
|
- instance.resources.find(resource => resource.id === resourceId)[nameParameter] = true;
|
271
|
|
- }
|
272
|
|
- }
|
273
|
|
- });
|
|
252
|
+ clientObserveAttrTelemetry.find(objectLwm2m => objectLwm2m.id === objectId)
|
|
253
|
+ .instances.find(itrInstance => itrInstance.id === instanceId)
|
|
254
|
+ .resources.find(resource => resource.id === resourceId)
|
|
255
|
+ [nameParameter] = true;
|
274
|
256
|
});
|
275
|
257
|
}
|
276
|
258
|
|
...
|
...
|
@@ -278,62 +260,60 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
278
|
260
|
const keyName = JSON.parse(JSON.stringify(nameJson));
|
279
|
261
|
Object.keys(keyName).forEach(key => {
|
280
|
262
|
const [objectId, instanceId, resourceId] = Array.from(key.substring(1).split('/'), Number);
|
281
|
|
- clientObserveAttrTelemetry
|
282
|
|
- .forEach(object => {
|
283
|
|
- if (object.id === objectId) {
|
284
|
|
- object.instances
|
285
|
|
- .find(instance => instance.id === instanceId).resources
|
286
|
|
- .find(resource => resource.id === resourceId).keyName = keyName[key];
|
287
|
|
- }
|
288
|
|
- });
|
|
263
|
+ clientObserveAttrTelemetry.find(objectLwm2m => objectLwm2m.id === objectId)
|
|
264
|
+ .instances.find(instance => instance.id === instanceId)
|
|
265
|
+ .resources.find(resource => resource.id === resourceId)
|
|
266
|
+ .keyName = keyName[key];
|
289
|
267
|
});
|
290
|
268
|
}
|
291
|
269
|
|
292
|
|
- private upDateObserveAttrTelemetryFromGroupToJson = (val: ObjectLwM2M[]): void => {
|
|
270
|
+ private updateObserveAttrTelemetryFromGroupToJson = (val: ObjectLwM2M[]): void => {
|
293
|
271
|
const observeArray: Array<string> = [];
|
294
|
272
|
const attributeArray: Array<string> = [];
|
295
|
273
|
const telemetryArray: Array<string> = [];
|
296
|
274
|
const observeJson: ObjectLwM2M[] = JSON.parse(JSON.stringify(val));
|
|
275
|
+ const paths = new Set<string>();
|
297
|
276
|
let pathObj;
|
298
|
277
|
let pathInst;
|
299
|
278
|
let pathRes;
|
300
|
279
|
observeJson.forEach(obj => {
|
301
|
|
- Object.entries(obj).forEach(([key, value]) => {
|
|
280
|
+ for (const [key, value] of Object.entries(obj)) {
|
302
|
281
|
if (key === 'id') {
|
303
|
282
|
pathObj = value;
|
304
|
283
|
}
|
305
|
284
|
if (key === 'instances') {
|
306
|
|
- const instancesJson = JSON.parse(JSON.stringify(value)) as Instance[];
|
|
285
|
+ const instancesJson = value as Instance[];
|
307
|
286
|
if (instancesJson.length > 0) {
|
308
|
287
|
instancesJson.forEach(instance => {
|
309
|
|
- Object.entries(instance).forEach(([instanceKey, instanceValue]) => {
|
|
288
|
+ for (const [instanceKey, instanceValue] of Object.entries(instance)) {
|
310
|
289
|
if (instanceKey === 'id') {
|
311
|
290
|
pathInst = instanceValue;
|
312
|
291
|
}
|
313
|
292
|
if (instanceKey === 'resources') {
|
314
|
|
- const resourcesJson = JSON.parse(JSON.stringify(instanceValue)) as ResourceLwM2M[];
|
|
293
|
+ const resourcesJson = instanceValue as ResourceLwM2M[];
|
315
|
294
|
if (resourcesJson.length > 0) {
|
316
|
295
|
resourcesJson.forEach(res => {
|
317
|
|
- Object.entries(res).forEach(([resourceKey, resourceValue]) => {
|
|
296
|
+ for (const [resourceKey, idResource] of Object.entries(res)) {
|
318
|
297
|
if (resourceKey === 'id') {
|
319
|
|
- // pathRes = resourceValue
|
320
|
|
- pathRes = '/' + pathObj + '/' + pathInst + '/' + resourceValue;
|
321
|
|
- } else if (resourceKey === 'observe' && resourceValue) {
|
|
298
|
+ pathRes = `/${pathObj}/${pathInst}/${idResource}`;
|
|
299
|
+ } else if (resourceKey === 'observe' && idResource) {
|
322
|
300
|
observeArray.push(pathRes);
|
323
|
|
- } else if (resourceKey === 'attribute' && resourceValue) {
|
|
301
|
+ } else if (resourceKey === 'attribute' && idResource) {
|
324
|
302
|
attributeArray.push(pathRes);
|
325
|
|
- } else if (resourceKey === 'telemetry' && resourceValue) {
|
|
303
|
+ paths.add(pathRes);
|
|
304
|
+ } else if (resourceKey === 'telemetry' && idResource) {
|
326
|
305
|
telemetryArray.push(pathRes);
|
|
306
|
+ paths.add(pathRes);
|
327
|
307
|
}
|
328
|
|
- });
|
|
308
|
+ }
|
329
|
309
|
});
|
330
|
310
|
}
|
331
|
311
|
}
|
332
|
|
- });
|
|
312
|
+ }
|
333
|
313
|
});
|
334
|
314
|
}
|
335
|
315
|
}
|
336
|
|
- });
|
|
316
|
+ }
|
337
|
317
|
});
|
338
|
318
|
if (isUndefined(this.configurationValue[this.observeAttr])) {
|
339
|
319
|
this.configurationValue[this.observeAttr] = {
|
...
|
...
|
@@ -346,7 +326,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
346
|
326
|
this.configurationValue[this.observeAttr][this.attribute] = attributeArray;
|
347
|
327
|
this.configurationValue[this.observeAttr][this.telemetry] = telemetryArray;
|
348
|
328
|
}
|
349
|
|
- this.updateKeyName();
|
|
329
|
+ this.updateKeyName(paths);
|
350
|
330
|
}
|
351
|
331
|
|
352
|
332
|
sortObjectKeyPathJson = (key: string, value: object): object => {
|
...
|
...
|
@@ -366,23 +346,13 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
366
|
346
|
}
|
367
|
347
|
|
368
|
348
|
private sortPath = (a, b): number => {
|
369
|
|
- const aLC = Array.from(a.substring(1).split('/'), Number);
|
370
|
|
- const bLC = Array.from(b.substring(1).split('/'), Number);
|
371
|
|
- return aLC[0] === bLC[0] ? aLC[1] - bLC[1] : aLC[0] - bLC[0];
|
|
349
|
+ return a.localeCompare(b, undefined, {
|
|
350
|
+ numeric: true,
|
|
351
|
+ sensitivity: 'base'
|
|
352
|
+ });
|
372
|
353
|
}
|
373
|
354
|
|
374
|
|
- private updateKeyName = (): void => {
|
375
|
|
- const paths = new Set<string>();
|
376
|
|
- if (this.configurationValue[this.observeAttr][this.attribute]) {
|
377
|
|
- this.configurationValue[this.observeAttr][this.attribute].forEach(path => {
|
378
|
|
- paths.add(path);
|
379
|
|
- });
|
380
|
|
- }
|
381
|
|
- if (this.configurationValue[this.observeAttr][this.telemetry]) {
|
382
|
|
- this.configurationValue[this.observeAttr][this.telemetry].forEach(path => {
|
383
|
|
- paths.add(path);
|
384
|
|
- });
|
385
|
|
- }
|
|
355
|
+ private updateKeyName = (paths: Set<string>): void => {
|
386
|
356
|
const keyNameNew = {};
|
387
|
357
|
paths.forEach(path => {
|
388
|
358
|
const pathParameter = this.findIndexesForIds(path);
|
...
|
...
|
@@ -395,19 +365,19 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
395
|
365
|
}
|
396
|
366
|
|
397
|
367
|
private findIndexesForIds = (path: string): number[] => {
|
398
|
|
- const pathParameter = Array.from(path.substring(1).split('/'), Number);
|
|
368
|
+ const [objectId, instanceId, resourceId] = Array.from(path.substring(1).split('/'), Number);
|
|
369
|
+ // TODO: All paths to map
|
399
|
370
|
const pathParameterIndexes: number[] = [];
|
400
|
|
- const objectsOld = deepClone(
|
401
|
|
- this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').value.clientLwM2M) as ObjectLwM2M[];
|
402
|
|
- let isIdIndex = (element) => element.id === pathParameter[0];
|
|
371
|
+ const objectsOld = this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').value.clientLwM2M as ObjectLwM2M[];
|
|
372
|
+ let isIdIndex = (element) => element.id === objectId;
|
403
|
373
|
const objIndex = objectsOld.findIndex(isIdIndex);
|
404
|
374
|
if (objIndex >= 0) {
|
405
|
375
|
pathParameterIndexes.push(objIndex);
|
406
|
|
- isIdIndex = (element) => element.id === pathParameter[1];
|
|
376
|
+ isIdIndex = (element) => element.id === instanceId;
|
407
|
377
|
const instIndex = objectsOld[objIndex].instances.findIndex(isIdIndex);
|
408
|
378
|
if (instIndex >= 0) {
|
409
|
379
|
pathParameterIndexes.push(instIndex);
|
410
|
|
- isIdIndex = (element) => element.id === pathParameter[2];
|
|
380
|
+ isIdIndex = (element) => element.id === resourceId;
|
411
|
381
|
const resIndex = objectsOld[objIndex].instances[instIndex].resources.findIndex(isIdIndex);
|
412
|
382
|
if (resIndex >= 0) {
|
413
|
383
|
pathParameterIndexes.push(resIndex);
|
...
|
...
|
@@ -456,16 +426,16 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
456
|
426
|
if (index >= 0) {
|
457
|
427
|
objectsOld.splice(index, 1);
|
458
|
428
|
}
|
459
|
|
- this.updateObserveAttrTelemetryObjectFormGroup(objectsOld);
|
460
|
429
|
this.removeObserveAttrTelemetryFromJson(this.observe, value.id);
|
461
|
430
|
this.removeObserveAttrTelemetryFromJson(this.telemetry, value.id);
|
462
|
431
|
this.removeObserveAttrTelemetryFromJson(this.attribute, value.id);
|
463
|
432
|
this.removeKeyNameFromJson(value.id);
|
|
433
|
+ this.updateObserveAttrTelemetryObjectFormGroup(objectsOld);
|
464
|
434
|
this.upDateJsonAllConfig();
|
465
|
435
|
}
|
466
|
436
|
|
467
|
437
|
private removeObserveAttrTelemetryFromJson = (observeAttrTel: string, id: number): void => {
|
468
|
|
- const isIdIndex = (element: string) => element.startsWith(`/${id}`);
|
|
438
|
+ const isIdIndex = (element) => element.startsWith(`/${id}`);
|
469
|
439
|
let index = this.configurationValue[this.observeAttr][observeAttrTel].findIndex(isIdIndex);
|
470
|
440
|
while (index >= 0) {
|
471
|
441
|
this.configurationValue[this.observeAttr][observeAttrTel].splice(index, 1);
|
...
|
...
|
|