@@ -18,6 +18,11 @@ for (var field in IOT_FIELDS) {
1818 }
1919}
2020
21+ const REGEX_PATH_CURRENT = new RegExp ( "^(.+)._current\\.?(.+)?$" )
22+ const REGEX_PATH_ARRAY = new RegExp ( "\\[[0-9]+\\]" )
23+ const REGEX_DATASTREAM_VALUE = new RegExp ( 'value\\.?' )
24+
25+
2126const match_url = {
2227 '/jobs' : 'JOB' ,
2328 '/tasks' : 'TASKS' ,
@@ -150,7 +155,6 @@ const _getDatamodelFields = function(parent, objSearcher){
150155 }
151156 } ) ;
152157 }
153-
154158 if ( rtFilter . and . length > 0 ) {
155159 datamodelSearchBuilder . filter ( rtFilter ) ;
156160 }
@@ -355,24 +359,24 @@ const FIELD_SEARCHER = {
355359 //search de la definición de schemas de opengate
356360 _this . _ogapi . basicTypesSearchBuilder ( ) . withPath ( '$' ) . build ( ) . execute ( ) . then ( function ( basicTypes ) {
357361 const definitions = basicTypes . data . definitions
358- let query = { selectAll : true }
362+ objSearcher . selectAll = true
359363 if ( selectedField ) {
360364 columns = columns . filter ( function ( column ) { return selectedField === column . name } )
361365 const column = columns [ 0 ]
362- const datastreamMatch = column . path . match ( new RegExp ( "^(.+)._current\.?(.+)?$" ) ) ;
363- const datastream = datastreamMatch [ 1 ] . replace ( new RegExp ( "\[[0-9]+\]" ) , "[]" )
364- query = { selectedField : datastream }
366+ const datastreamMatch = column . path . match ( REGEX_PATH_CURRENT ) ;
367+ const datastream = datastreamMatch [ 1 ] . replace ( REGEX_PATH_ARRAY , "[]" )
368+ objSearcher . selectedField = datastream
365369 }
366- query . organization = organization
367370 //recuperamos la defnición de todas las columnas y todos los datastreams
368- _getDatamodelFields ( _this , query ) . then ( function ( datamodelFields ) {
371+ _getDatamodelFields ( _this , objSearcher ) . then ( function ( datamodelFields ) {
369372 columns . forEach ( function ( column ) {
370373 //Expresión regular para recuperar el path del datastream (1) y, si se tratase de un datastream complejo, también el path hasta el dato simple (2).
371374 //Datastream simple: provision.device.identifier._current.value, device.communicationModules[0].subscriber.mobile.icc._current.at
372375 //Datastream complejo: device.model._current.value.manufacturer, device.location._current.value.position.type
373- const datastreamMatch = column . path . match ( new RegExp ( "^(.+)._current\.?(.+)?$" ) ) ;
374- const datastream = datastreamMatch [ 1 ] . replace ( new RegExp ( "\[[0-9]+\]" ) , "[]" )
375- const subdatastream = datastreamMatch [ 2 ] . replace ( new RegExp ( 'value\.?' ) , '' ) ;
376+ const datastreamMatch = column . path . match ( REGEX_PATH_CURRENT ) ;
377+ //Eliminamos el indice para los modulos de comunicaciones y los arrays para el resto de datastreams
378+ const datastream = datastreamMatch [ 1 ] . replace ( REGEX_PATH_ARRAY , "[]" )
379+ const subdatastream = datastreamMatch [ 2 ] . replace ( REGEX_DATASTREAM_VALUE , '' ) . replace ( REGEX_PATH_ARRAY , '' ) ;
376380 //Buscamos la definición del datastream en el datamodel
377381 const datamodelField = Array . isArray ( datamodelFields ) ? datamodelFields . find ( function ( df ) {
378382 return datastream === df . identifier
0 commit comments