@@ -41,20 +41,19 @@ const utils = require('./pluginUtils');
4141/* eslint-disable-next-line no-unused-vars */
4242const aliasPlugin = require ( './attributeAlias' ) ;
4343
44-
4544function checkJexl ( typeInformation ) {
4645 if (
4746 config . getConfig ( ) . defaultExpressionLanguage === 'jexl' &&
48- typeInformation . expressionLanguage &&
49- typeInformation . expressionLanguage !== 'legacy'
47+ typeInformation . expressionLanguage &&
48+ typeInformation . expressionLanguage !== 'legacy'
5049 ) {
5150 return true ;
5251 } else if ( config . getConfig ( ) . defaultExpressionLanguage === 'jexl' && ! typeInformation . expressionLanguage ) {
5352 return true ;
5453 } else if (
5554 config . getConfig ( ) . defaultExpressionLanguage === 'legacy' &&
56- typeInformation . expressionLanguage &&
57- typeInformation . expressionLanguage === 'jexl'
55+ typeInformation . expressionLanguage &&
56+ typeInformation . expressionLanguage === 'jexl'
5857 ) {
5958 return true ;
6059 }
@@ -65,6 +64,11 @@ function hasEntityName(item) {
6564 return item . entity_name ;
6665}
6766
67+ function ensureEntityId ( entityName , originalEntityName ) {
68+ // ensure no return null, 0, false, NaN and other invalids entityIDs
69+ return entityName ? entityName : originalEntityName ;
70+ }
71+
6872/**
6973 * Return a list of all the attributes that don't have a multientity option. It considers NGSIv1.
7074 *
@@ -87,20 +91,23 @@ function filterOutMultientitiesNgsi1(originalAttrs, meAttributes) {
8791 */
8892function filterOutMultientitiesNgsi2 ( originalAttrs , meAttributes ) {
8993 const result = { } ;
90- const meNamesList = _ . pluck ( meAttributes , 'name' ) ;
91- const meObjectsList = _ . pluck ( meAttributes , 'object_id' ) ;
94+ const meNamesList = _ . pluck ( meAttributes , 'name' ) ;
95+ const meObjectsList = _ . pluck ( meAttributes , 'object_id' ) ;
9296 let toBeFilteredByObj = [ ] ;
9397
9498 for ( const att in originalAttrs ) {
9599 if ( originalAttrs . hasOwnProperty ( att ) ) {
96100 if ( ! _ . contains ( meNamesList , att ) ) {
97101 result [ att ] = originalAttrs [ att ] ;
98102 }
99- if ( originalAttrs [ att ] . hasOwnProperty ( 'multi' ) ) {
100- let cleanAttributes = _ . union ( [ _ . clone ( originalAttrs [ att ] ) ] , originalAttrs [ att ] . multi ) ;
101- delete cleanAttributes [ 0 ] . multi ;
102- cleanAttributes = _ . map ( cleanAttributes , function ( val ) { val [ 'name' ] = att ; return val ; } ) ;
103- toBeFilteredByObj = _ . union ( toBeFilteredByObj , cleanAttributes ) ;
103+ if ( originalAttrs [ att ] . hasOwnProperty ( 'multi' ) ) {
104+ let cleanAttributes = _ . union ( [ _ . clone ( originalAttrs [ att ] ) ] , originalAttrs [ att ] . multi ) ;
105+ delete cleanAttributes [ 0 ] . multi ;
106+ cleanAttributes = _ . map ( cleanAttributes , function ( val ) {
107+ val [ 'name' ] = att ;
108+ return val ;
109+ } ) ;
110+ toBeFilteredByObj = _ . union ( toBeFilteredByObj , cleanAttributes ) ;
104111 }
105112 }
106113 }
@@ -157,7 +164,7 @@ function generateNewCEsNgsi1(entity, newEntities, entityTypes, typeInformation,
157164 result . push ( {
158165 type : entityTypes [ newEntities [ i ] ] ,
159166 isPattern : 'false' ,
160- id : entityName ,
167+ id : ensureEntityId ( entityName , newEntities [ i ] ) ,
161168 attributes : newEntityAttributes
162169 } ) ;
163170 }
@@ -231,7 +238,7 @@ function generateNewCEsNgsi2(entity, newEntities, entityTypes, typeInformation,
231238 entityName = parser . applyExpression ( newEntities [ i ] , ctx , typeInformation ) ;
232239
233240 newEntityAttributes . type = entityTypes [ newEntities [ i ] ] ;
234- newEntityAttributes . id = entityName ;
241+ newEntityAttributes . id = ensureEntityId ( entityName , newEntities [ i ] ) ;
235242
236243 result . push ( newEntityAttributes ) ;
237244 }
0 commit comments