Commit 5f3cf1e3a2a77a13cde03d3309540824d43cf059

Authored by nickAS21
1 parent c14e2c81

Lwm2m: front: update filter for keyName

@@ -154,7 +154,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { @@ -154,7 +154,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
154 lwM2MClient.setLwM2MTransportServiceImpl(this); 154 lwM2MClient.setLwM2MTransportServiceImpl(this);
155 lwM2MClient.setSessionUuid(UUID.randomUUID()); 155 lwM2MClient.setSessionUuid(UUID.randomUUID());
156 this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client Registered", registration); 156 this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client Registered", registration);
157 -// this.setLwM2mFromClientValue(lwServer, registration, lwM2MClient); 157 + this.setLwM2mFromClientValue(lwServer, registration, lwM2MClient);
158 SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration); 158 SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
159 if (sessionInfo != null) { 159 if (sessionInfo != null) {
160 lwM2MClient.setDeviceUuid(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB())); 160 lwM2MClient.setDeviceUuid(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB()));
@@ -93,7 +93,7 @@ public class LwM2MClient implements Cloneable { @@ -93,7 +93,7 @@ public class LwM2MClient implements Cloneable {
93 this.pendingRequests.remove(path); 93 this.pendingRequests.remove(path);
94 if (this.pendingRequests.size() == 0) { 94 if (this.pendingRequests.size() == 0) {
95 this.initValue(); 95 this.initValue();
96 -// this.lwM2MTransportServiceImpl.putDelayedUpdateResourcesThingsboard(this); 96 + this.lwM2MTransportServiceImpl.putDelayedUpdateResourcesThingsboard(this);
97 } 97 }
98 } 98 }
99 99
@@ -106,7 +106,7 @@ public class LwM2MClient implements Cloneable { @@ -106,7 +106,7 @@ public class LwM2MClient implements Cloneable {
106 ((LwM2mObjectInstance)((ReadResponse)resp).getContent()).getResources().forEach((k, v) -> { 106 ((LwM2mObjectInstance)((ReadResponse)resp).getContent()).getResources().forEach((k, v) -> {
107 String rez = pathIds.toString() + "/" + k; 107 String rez = pathIds.toString() + "/" + k;
108 if (((LwM2mObjectInstance) ((ReadResponse) resp).getContent()).getResource(k) instanceof LwM2mMultipleResource){ 108 if (((LwM2mObjectInstance) ((ReadResponse) resp).getContent()).getResource(k) instanceof LwM2mMultipleResource){
109 -// this.resources.put(rez, new ResourceValue(v.getInstances().values(), null, true)); 109 + this.resources.put(rez, new ResourceValue(v.getValues(), null, true));
110 } 110 }
111 else { 111 else {
112 this.resources.put(rez, new ResourceValue(null, v.getValue(), false)); 112 this.resources.put(rez, new ResourceValue(null, v.getValue(), false));
@@ -271,6 +271,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -271,6 +271,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
271 const observeArray: Array<string> = []; 271 const observeArray: Array<string> = [];
272 const attributeArray: Array<string> = []; 272 const attributeArray: Array<string> = [];
273 const telemetryArray: Array<string> = []; 273 const telemetryArray: Array<string> = [];
  274 + const keyNameNew = {};
274 const observeJson: ObjectLwM2M[] = JSON.parse(JSON.stringify(val)); 275 const observeJson: ObjectLwM2M[] = JSON.parse(JSON.stringify(val));
275 const paths = new Set<string>(); 276 const paths = new Set<string>();
276 let pathObj; 277 let pathObj;
@@ -293,18 +294,22 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -293,18 +294,22 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
293 const resourcesJson = instanceValue as ResourceLwM2M[]; 294 const resourcesJson = instanceValue as ResourceLwM2M[];
294 if (resourcesJson.length > 0) { 295 if (resourcesJson.length > 0) {
295 resourcesJson.forEach(res => { 296 resourcesJson.forEach(res => {
296 - for (const [resourceKey, idResource] of Object.entries(res)) { 297 + for (const [resourceKey, value] of Object.entries(res)) {
297 if (resourceKey === 'id') { 298 if (resourceKey === 'id') {
298 - pathRes = `/${pathObj}/${pathInst}/${idResource}`;  
299 - } else if (resourceKey === 'observe' && idResource) { 299 + pathRes = `/${pathObj}/${pathInst}/${value}`;
  300 + } else if (resourceKey === 'observe' && value) {
300 observeArray.push(pathRes); 301 observeArray.push(pathRes);
301 - } else if (resourceKey === 'attribute' && idResource) { 302 + } else if (resourceKey === 'attribute' && value) {
302 attributeArray.push(pathRes); 303 attributeArray.push(pathRes);
303 paths.add(pathRes); 304 paths.add(pathRes);
304 - } else if (resourceKey === 'telemetry' && idResource) { 305 + } else if (resourceKey === 'telemetry' && value) {
305 telemetryArray.push(pathRes); 306 telemetryArray.push(pathRes);
306 paths.add(pathRes); 307 paths.add(pathRes);
307 } 308 }
  309 + else if (resourceKey === this.keyName && paths.has(pathRes)) {
  310 + console.warn(pathRes, value);
  311 + keyNameNew[pathRes] = value;
  312 + }
308 } 313 }
309 }); 314 });
310 } 315 }
@@ -326,7 +331,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -326,7 +331,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
326 this.configurationValue[this.observeAttr][this.attribute] = attributeArray; 331 this.configurationValue[this.observeAttr][this.attribute] = attributeArray;
327 this.configurationValue[this.observeAttr][this.telemetry] = telemetryArray; 332 this.configurationValue[this.observeAttr][this.telemetry] = telemetryArray;
328 } 333 }
329 - this.updateKeyName(paths); 334 + this.configurationValue[this.observeAttr][this.keyName] = this.sortObjectKeyPathJson('keyName', keyNameNew);
330 } 335 }
331 336
332 sortObjectKeyPathJson = (key: string, value: object): object => { 337 sortObjectKeyPathJson = (key: string, value: object): object => {
@@ -352,41 +357,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -352,41 +357,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
352 }); 357 });
353 } 358 }
354 359
355 - private updateKeyName = (paths: Set<string>): void => {  
356 - const keyNameNew = {};  
357 - paths.forEach(path => {  
358 - const pathParameter = this.findIndexesForIds(path);  
359 - if (pathParameter.length === 3) {  
360 - keyNameNew[path] = this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').value  
361 - .clientLwM2M[pathParameter[0]].instances[pathParameter[1]].resources[pathParameter[2]][this.keyName];  
362 - }  
363 - });  
364 - this.configurationValue[this.observeAttr][this.keyName] = this.sortObjectKeyPathJson('keyName', keyNameNew);  
365 - }  
366 -  
367 - private findIndexesForIds = (path: string): number[] => {  
368 - const [objectId, instanceId, resourceId] = Array.from(path.substring(1).split('/'), Number);  
369 - // TODO: All paths to map  
370 - const pathParameterIndexes: number[] = [];  
371 - const objectsOld = this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').value.clientLwM2M as ObjectLwM2M[];  
372 - let isIdIndex = (element) => element.id === objectId;  
373 - const objIndex = objectsOld.findIndex(isIdIndex);  
374 - if (objIndex >= 0) {  
375 - pathParameterIndexes.push(objIndex);  
376 - isIdIndex = (element) => element.id === instanceId;  
377 - const instIndex = objectsOld[objIndex].instances.findIndex(isIdIndex);  
378 - if (instIndex >= 0) {  
379 - pathParameterIndexes.push(instIndex);  
380 - isIdIndex = (element) => element.id === resourceId;  
381 - const resIndex = objectsOld[objIndex].instances[instIndex].resources.findIndex(isIdIndex);  
382 - if (resIndex >= 0) {  
383 - pathParameterIndexes.push(resIndex);  
384 - }  
385 - }  
386 - }  
387 - return pathParameterIndexes;  
388 - }  
389 -  
390 private getObjectsFromJsonAllConfig = (): number[] => { 360 private getObjectsFromJsonAllConfig = (): number[] => {
391 const objectsIds = new Set<number>(); 361 const objectsIds = new Set<number>();
392 if (this.configurationValue[this.observeAttr]) { 362 if (this.configurationValue[this.observeAttr]) {