...
|
...
|
@@ -21,16 +21,11 @@ import { Store } from '@ngrx/store'; |
21
|
21
|
import { AppState } from '@app/core/core.state';
|
22
|
22
|
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
23
|
23
|
import {
|
24
|
|
- ATTR,
|
|
24
|
+ INSTANCES, RESOURCES, OBSERVE_ATTR_TELEMETRY, OBSERVE, ATTRIBUTE, TELEMETRY, KEY_NAME,
|
25
|
25
|
getDefaultProfileConfig,
|
26
|
|
- Instance,
|
27
|
|
- KEY_NAME,
|
28
|
26
|
ObjectLwM2M,
|
29
|
|
- OBSERVE,
|
30
|
|
- OBSERVE_ATTR,
|
31
|
27
|
ProfileConfigModels,
|
32
|
|
- ResourceLwM2M,
|
33
|
|
- TELEMETRY
|
|
28
|
+ ModelValue
|
34
|
29
|
} from './profile-config.models';
|
35
|
30
|
import { DeviceProfileService } from '@core/http/device-profile.service';
|
36
|
31
|
import { deepClone, isDefinedAndNotNull, isUndefined } from '@core/utils';
|
...
|
...
|
@@ -55,11 +50,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
55
|
50
|
|
56
|
51
|
lwm2mDeviceProfileFormGroup: FormGroup;
|
57
|
52
|
lwm2mDeviceConfigFormGroup: FormGroup;
|
58
|
|
- observeAttr = OBSERVE_ATTR;
|
59
|
|
- observe = OBSERVE;
|
60
|
|
- attribute = ATTR;
|
61
|
|
- telemetry = TELEMETRY;
|
62
|
|
- keyName = KEY_NAME;
|
63
|
53
|
bootstrapServers: string;
|
64
|
54
|
bootstrapServer: string;
|
65
|
55
|
lwm2mServer: string;
|
...
|
...
|
@@ -122,7 +112,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
122
|
112
|
}
|
123
|
113
|
}
|
124
|
114
|
|
125
|
|
- writeValue(value: any | null): void {
|
|
115
|
+ writeValue(value: ProfileConfigModels | null): void {
|
126
|
116
|
this.configurationValue = (Object.keys(value).length === 0) ? getDefaultProfileConfig() : value;
|
127
|
117
|
this.lwm2mDeviceConfigFormGroup.patchValue({
|
128
|
118
|
configurationJson: this.configurationValue
|
...
|
...
|
@@ -131,7 +121,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
131
|
121
|
}
|
132
|
122
|
|
133
|
123
|
private initWriteValue = (): void => {
|
134
|
|
- const modelValue = {objectIds: null, objectsList: []};
|
|
124
|
+ const modelValue = {objectIds: null, objectsList: []} as ModelValue;
|
135
|
125
|
modelValue.objectIds = this.getObjectsFromJsonAllConfig();
|
136
|
126
|
if (modelValue.objectIds !== null) {
|
137
|
127
|
const sortOrder = {
|
...
|
...
|
@@ -149,11 +139,10 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
149
|
139
|
}
|
150
|
140
|
}
|
151
|
141
|
|
152
|
|
- private updateWriteValue = (value: any): void => {
|
153
|
|
- const objectsList = value.objectsList;
|
|
142
|
+ private updateWriteValue = (value: ModelValue): void => {
|
154
|
143
|
this.lwm2mDeviceProfileFormGroup.patchValue({
|
155
|
144
|
objectIds: value,
|
156
|
|
- observeAttrTelemetry: this.getObserveAttrTelemetryObjects(objectsList),
|
|
145
|
+ observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value['objectsList']),
|
157
|
146
|
shortId: this.configurationValue.bootstrap.servers.shortId,
|
158
|
147
|
lifetime: this.configurationValue.bootstrap.servers.lifetime,
|
159
|
148
|
defaultMinPeriod: this.configurationValue.bootstrap.servers.defaultMinPeriod,
|
...
|
...
|
@@ -199,22 +188,22 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
199
|
188
|
|
200
|
189
|
private getObserveAttrTelemetryObjects = (listObject: ObjectLwM2M[]): object => {
|
201
|
190
|
const clientObserveAttrTelemetry = listObject;
|
202
|
|
- if (this.configurationValue[this.observeAttr]) {
|
203
|
|
- const observeArray = this.configurationValue[this.observeAttr][this.observe];
|
204
|
|
- const attributeArray = this.configurationValue[this.observeAttr][this.attribute];
|
205
|
|
- const telemetryArray = this.configurationValue[this.observeAttr][this.telemetry];
|
206
|
|
- const keyNameJson = this.configurationValue[this.observeAttr][this.keyName];
|
|
191
|
+ if (this.configurationValue.observeAttr) {
|
|
192
|
+ const observeArray = this.configurationValue.observeAttr.observe;
|
|
193
|
+ const attributeArray = this.configurationValue.observeAttr.attribute;
|
|
194
|
+ const telemetryArray = this.configurationValue.observeAttr.telemetry;
|
|
195
|
+ const keyNameJson = this.configurationValue.observeAttr.keyName;
|
207
|
196
|
if (this.includesNotZeroInstance(attributeArray, telemetryArray)) {
|
208
|
197
|
this.addInstances(attributeArray, telemetryArray, clientObserveAttrTelemetry);
|
209
|
198
|
}
|
210
|
199
|
if (isDefinedAndNotNull(observeArray)) {
|
211
|
|
- this.updateObserveAttrTelemetryObjects(observeArray, clientObserveAttrTelemetry, 'observe');
|
|
200
|
+ this.updateObserveAttrTelemetryObjects(observeArray, clientObserveAttrTelemetry, OBSERVE);
|
212
|
201
|
}
|
213
|
202
|
if (isDefinedAndNotNull(attributeArray)) {
|
214
|
|
- this.updateObserveAttrTelemetryObjects(attributeArray, clientObserveAttrTelemetry, 'attribute');
|
|
203
|
+ this.updateObserveAttrTelemetryObjects(attributeArray, clientObserveAttrTelemetry, ATTRIBUTE);
|
215
|
204
|
}
|
216
|
205
|
if (isDefinedAndNotNull(telemetryArray)) {
|
217
|
|
- this.updateObserveAttrTelemetryObjects(telemetryArray, clientObserveAttrTelemetry, 'telemetry');
|
|
206
|
+ this.updateObserveAttrTelemetryObjects(telemetryArray, clientObserveAttrTelemetry, TELEMETRY);
|
218
|
207
|
}
|
219
|
208
|
if (isDefinedAndNotNull(keyNameJson)) {
|
220
|
209
|
this.updateKeyNameObjects(keyNameJson, clientObserveAttrTelemetry);
|
...
|
...
|
@@ -273,74 +262,51 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
273
|
262
|
const telemetryArray: Array<string> = [];
|
274
|
263
|
const keyNameNew = {};
|
275
|
264
|
const observeJson: ObjectLwM2M[] = JSON.parse(JSON.stringify(val));
|
276
|
|
- const paths = new Set<string>();
|
277
|
|
- let pathObj;
|
278
|
|
- let pathInst;
|
279
|
|
- let pathRes;
|
280
|
265
|
observeJson.forEach(obj => {
|
281
|
|
- for (const [key, value] of Object.entries(obj)) {
|
282
|
|
- if (key === 'id') {
|
283
|
|
- pathObj = value;
|
284
|
|
- }
|
285
|
|
- if (key === 'instances') {
|
286
|
|
- const instancesJson = value as Instance[];
|
287
|
|
- if (instancesJson.length > 0) {
|
288
|
|
- instancesJson.forEach(instance => {
|
289
|
|
- for (const [instanceKey, instanceValue] of Object.entries(instance)) {
|
290
|
|
- if (instanceKey === 'id') {
|
291
|
|
- pathInst = instanceValue;
|
|
266
|
+ if (obj.hasOwnProperty(INSTANCES) && Array.isArray(obj.instances)) {
|
|
267
|
+ obj.instances.forEach(instance => {
|
|
268
|
+ if (instance.hasOwnProperty(RESOURCES) && Array.isArray(instance.resources)) {
|
|
269
|
+ instance.resources.forEach(resource => {
|
|
270
|
+ if (resource.attribute || resource.telemetry) {
|
|
271
|
+ let pathRes = `/${obj.id}/${instance.id}/${resource.id}`;
|
|
272
|
+ if (resource.observe) {
|
|
273
|
+ observeArray.push(pathRes);
|
|
274
|
+ }
|
|
275
|
+ if (resource.attribute) {
|
|
276
|
+ attributeArray.push(pathRes);
|
292
|
277
|
}
|
293
|
|
- if (instanceKey === 'resources') {
|
294
|
|
- const resourcesJson = instanceValue as ResourceLwM2M[];
|
295
|
|
- if (resourcesJson.length > 0) {
|
296
|
|
- resourcesJson.forEach(res => {
|
297
|
|
- for (const [resourceKey, value] of Object.entries(res)) {
|
298
|
|
- if (resourceKey === 'id') {
|
299
|
|
- pathRes = `/${pathObj}/${pathInst}/${value}`;
|
300
|
|
- } else if (resourceKey === 'observe' && value) {
|
301
|
|
- observeArray.push(pathRes);
|
302
|
|
- } else if (resourceKey === 'attribute' && value) {
|
303
|
|
- attributeArray.push(pathRes);
|
304
|
|
- paths.add(pathRes);
|
305
|
|
- } else if (resourceKey === 'telemetry' && value) {
|
306
|
|
- telemetryArray.push(pathRes);
|
307
|
|
- paths.add(pathRes);
|
308
|
|
- }
|
309
|
|
- else if (resourceKey === this.keyName && paths.has(pathRes)) {
|
310
|
|
- console.warn(pathRes, value);
|
311
|
|
- keyNameNew[pathRes] = value;
|
312
|
|
- }
|
313
|
|
- }
|
314
|
|
- });
|
315
|
|
- }
|
|
278
|
+ if (resource.telemetry) {
|
|
279
|
+ telemetryArray.push(pathRes);
|
316
|
280
|
}
|
|
281
|
+ keyNameNew[pathRes] = resource.keyName;
|
317
|
282
|
}
|
318
|
|
- });
|
|
283
|
+ })
|
319
|
284
|
}
|
320
|
|
- }
|
|
285
|
+ })
|
321
|
286
|
}
|
322
|
287
|
});
|
323
|
|
- if (isUndefined(this.configurationValue[this.observeAttr])) {
|
324
|
|
- this.configurationValue[this.observeAttr] = {
|
325
|
|
- [this.observe]: observeArray,
|
326
|
|
- [this.attribute]: attributeArray,
|
327
|
|
- [this.telemetry]: telemetryArray
|
|
288
|
+ if (isUndefined(this.configurationValue.observeAttr)) {
|
|
289
|
+ this.configurationValue.observeAttr = {
|
|
290
|
+ observe: observeArray,
|
|
291
|
+ attribute: attributeArray,
|
|
292
|
+ telemetry: telemetryArray,
|
|
293
|
+ keyName: this.sortObjectKeyPathJson(KEY_NAME, keyNameNew)
|
328
|
294
|
};
|
329
|
295
|
} else {
|
330
|
|
- this.configurationValue[this.observeAttr][this.observe] = observeArray;
|
331
|
|
- this.configurationValue[this.observeAttr][this.attribute] = attributeArray;
|
332
|
|
- this.configurationValue[this.observeAttr][this.telemetry] = telemetryArray;
|
|
296
|
+ this.configurationValue.observeAttr.observe = observeArray;
|
|
297
|
+ this.configurationValue.observeAttr.attribute = attributeArray;
|
|
298
|
+ this.configurationValue.observeAttr.telemetry = telemetryArray;
|
|
299
|
+ this.configurationValue.observeAttr.keyName = this.sortObjectKeyPathJson(KEY_NAME, keyNameNew);
|
333
|
300
|
}
|
334
|
|
- this.configurationValue[this.observeAttr][this.keyName] = this.sortObjectKeyPathJson('keyName', keyNameNew);
|
335
|
301
|
}
|
336
|
302
|
|
337
|
303
|
sortObjectKeyPathJson = (key: string, value: object): object => {
|
338
|
|
- if (key === 'keyName') {
|
|
304
|
+ if (key === KEY_NAME) {
|
339
|
305
|
return Object.keys(value).sort(this.sortPath).reduce((obj, keySort) => {
|
340
|
306
|
obj[keySort] = value[keySort];
|
341
|
307
|
return obj;
|
342
|
308
|
}, {});
|
343
|
|
- } else if (key === 'observe' || key === 'attribute' || key === 'telemetry') {
|
|
309
|
+ } else if (key === OBSERVE || key === ATTRIBUTE || key === TELEMETRY) {
|
344
|
310
|
return Object.values(value).sort(this.sortPath).reduce((arr, arrValue) => {
|
345
|
311
|
arr.push(arrValue);
|
346
|
312
|
return arr;
|
...
|
...
|
@@ -359,19 +325,19 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
359
|
325
|
|
360
|
326
|
private getObjectsFromJsonAllConfig = (): number[] => {
|
361
|
327
|
const objectsIds = new Set<number>();
|
362
|
|
- if (this.configurationValue[this.observeAttr]) {
|
363
|
|
- if (this.configurationValue[this.observeAttr][this.observe]) {
|
364
|
|
- this.configurationValue[this.observeAttr][this.observe].forEach(obj => {
|
|
328
|
+ if (this.configurationValue.observeAttr) {
|
|
329
|
+ if (this.configurationValue.observeAttr.observe) {
|
|
330
|
+ this.configurationValue.observeAttr.observe.forEach(obj => {
|
365
|
331
|
objectsIds.add(Array.from(obj.substring(1).split('/'), Number)[0]);
|
366
|
332
|
});
|
367
|
333
|
}
|
368
|
|
- if (this.configurationValue[this.observeAttr][this.attribute]) {
|
369
|
|
- this.configurationValue[this.observeAttr][this.attribute].forEach(obj => {
|
|
334
|
+ if (this.configurationValue.observeAttr.attribute) {
|
|
335
|
+ this.configurationValue.observeAttr.attribute.forEach(obj => {
|
370
|
336
|
objectsIds.add(Array.from(obj.substring(1).split('/'), Number)[0]);
|
371
|
337
|
});
|
372
|
338
|
}
|
373
|
|
- if (this.configurationValue[this.observeAttr][this.telemetry]) {
|
374
|
|
- this.configurationValue[this.observeAttr][this.telemetry].forEach(obj => {
|
|
339
|
+ if (this.configurationValue.observeAttr.telemetry) {
|
|
340
|
+ this.configurationValue.observeAttr.telemetry.forEach(obj => {
|
375
|
341
|
objectsIds.add(Array.from(obj.substring(1).split('/'), Number)[0]);
|
376
|
342
|
});
|
377
|
343
|
}
|
...
|
...
|
@@ -390,15 +356,15 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
390
|
356
|
}
|
391
|
357
|
|
392
|
358
|
removeObjectsList = (value: ObjectLwM2M): void => {
|
393
|
|
- const objectsOld = this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').value.clientLwM2M;
|
|
359
|
+ const objectsOld = this.lwm2mDeviceProfileFormGroup.get(OBSERVE_ATTR_TELEMETRY).value.clientLwM2M;
|
394
|
360
|
const isIdIndex = (element) => element.id === value.id;
|
395
|
361
|
const index = objectsOld.findIndex(isIdIndex);
|
396
|
362
|
if (index >= 0) {
|
397
|
363
|
objectsOld.splice(index, 1);
|
398
|
364
|
}
|
399
|
|
- this.removeObserveAttrTelemetryFromJson(this.observe, value.id);
|
400
|
|
- this.removeObserveAttrTelemetryFromJson(this.telemetry, value.id);
|
401
|
|
- this.removeObserveAttrTelemetryFromJson(this.attribute, value.id);
|
|
365
|
+ this.removeObserveAttrTelemetryFromJson(OBSERVE, value.id);
|
|
366
|
+ this.removeObserveAttrTelemetryFromJson(TELEMETRY, value.id);
|
|
367
|
+ this.removeObserveAttrTelemetryFromJson(ATTRIBUTE, value.id);
|
402
|
368
|
this.removeKeyNameFromJson(value.id);
|
403
|
369
|
this.updateObserveAttrTelemetryObjectFormGroup(objectsOld);
|
404
|
370
|
this.upDateJsonAllConfig();
|
...
|
...
|
@@ -406,15 +372,15 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
406
|
372
|
|
407
|
373
|
private removeObserveAttrTelemetryFromJson = (observeAttrTel: string, id: number): void => {
|
408
|
374
|
const isIdIndex = (element) => element.startsWith(`/${id}`);
|
409
|
|
- let index = this.configurationValue[this.observeAttr][observeAttrTel].findIndex(isIdIndex);
|
|
375
|
+ let index = this.configurationValue.observeAttr[observeAttrTel].findIndex(isIdIndex);
|
410
|
376
|
while (index >= 0) {
|
411
|
|
- this.configurationValue[this.observeAttr][observeAttrTel].splice(index, 1);
|
412
|
|
- index = this.configurationValue[this.observeAttr][observeAttrTel].findIndex(isIdIndex, index);
|
|
377
|
+ this.configurationValue.observeAttr[observeAttrTel].splice(index, 1);
|
|
378
|
+ index = this.configurationValue.observeAttr[observeAttrTel].findIndex(isIdIndex, index);
|
413
|
379
|
}
|
414
|
380
|
}
|
415
|
381
|
|
416
|
382
|
private removeKeyNameFromJson = (id: number): void => {
|
417
|
|
- const keyNameJson = this.configurationValue[this.observeAttr][this.keyName];
|
|
383
|
+ const keyNameJson = this.configurationValue.observeAttr.keyName;
|
418
|
384
|
Object.keys(keyNameJson).forEach(key => {
|
419
|
385
|
if (key.startsWith(`/${id}`)) {
|
420
|
386
|
delete keyNameJson[key];
|
...
|
...
|
@@ -423,17 +389,17 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
423
|
389
|
}
|
424
|
390
|
|
425
|
391
|
isPathInJson(path: string): boolean {
|
426
|
|
- let isPath = this.findPathInJson(path, this.attribute);
|
|
392
|
+ let isPath = this.findPathInJson(path, ATTRIBUTE);
|
427
|
393
|
if (!isPath) {
|
428
|
|
- isPath = this.findPathInJson(path, this.telemetry);
|
|
394
|
+ isPath = this.findPathInJson(path, TELEMETRY);
|
429
|
395
|
}
|
430
|
396
|
return !!isPath;
|
431
|
397
|
}
|
432
|
398
|
|
433
|
399
|
private findPathInJson = (path: string, side: string): string => {
|
434
|
|
- if (this.configurationValue[this.observeAttr]) {
|
435
|
|
- if (this.configurationValue[this.observeAttr][side]) {
|
436
|
|
- return this.configurationValue[this.observeAttr][side].find(
|
|
400
|
+ if (this.configurationValue.observeAttr) {
|
|
401
|
+ if (this.configurationValue.observeAttr[side]) {
|
|
402
|
+ return this.configurationValue.bootstrap[side].find(
|
437
|
403
|
pathJs => pathJs === path);
|
438
|
404
|
}
|
439
|
405
|
}
|
...
|
...
|
|