@@ -69,19 +69,6 @@ function ensureEntityId(entityName, originalEntityName) {
6969 return entityName ? entityName : originalEntityName ;
7070}
7171
72- /**
73- * Return a list of all the attributes that don't have a multientity option. It considers NGSIv1.
74- *
75- * @param {Array } originalAttrs Array of original attributes coming from the single-entity device.
76- * @param {Array } meAttributes Array of all the multientity attributes.
77- * @return {Array } List of all the attrbiutes without multientity flag.
78- */
79- function filterOutMultientitiesNgsi1 ( originalAttrs , meAttributes ) {
80- return originalAttrs . filter ( function ( item ) {
81- return ! _ . contains ( meAttributes , item . name ) ;
82- } ) ;
83- }
84-
8572/**
8673 * Return a list of all the attributes that don't have a multientity option. It considers NGSIv2.
8774 *
@@ -121,59 +108,6 @@ function filterOutMultientitiesNgsi2(originalAttrs, meAttributes) {
121108 return result ;
122109}
123110
124- /**
125- * Generate new Context Elements for each new Entity, with the attributes of the original entity matching its
126- * entity_name. It considers Ngsiv1.
127- *
128- * @param {Object } entity The original entity
129- * @param {Array } newEntities List of the new entities that will be generated
130- * @param {Array } entityTypes Map of the types for each entity ID
131- * @param {Object } typeInformation Object with all the data about the device type
132- * @param {Array } multiEntityAttributes List of attributes with multientity option
133- * @return {Array } List of the new Context Entities
134- */
135- function generateNewCEsNgsi1 ( entity , newEntities , entityTypes , typeInformation , multiEntityAttributes ) {
136- const result = [ ] ;
137- let newEntityAttributes ;
138- let newEntityAttributeNames ;
139- let entityName ;
140- let parser = legacyParser ;
141- if ( checkJexl ( typeInformation ) ) {
142- parser = jexlParser ;
143- }
144- function filterByEntityName ( entityName ) {
145- return function ( item ) {
146- return item . entity_name === entityName ;
147- } ;
148- }
149-
150- function filterByAttributeNames ( item ) {
151- return _ . contains ( newEntityAttributeNames , item . name ) ;
152- }
153-
154- const ctx = parser . extractContext ( entity . contextElements [ 0 ] . attributes ) ;
155-
156- for ( let i = 0 ; i < newEntities . length ; i ++ ) {
157- newEntityAttributeNames = _ . pluck ( multiEntityAttributes . filter ( filterByEntityName ( newEntities [ i ] ) ) , 'name' ) ;
158-
159- newEntityAttributes = entity . contextElements [ 0 ] . attributes . filter ( filterByAttributeNames ) ;
160- // Fix duplicated attributes in entity
161- newEntityAttributes = _ . uniq ( newEntityAttributes , JSON . stringify ) ;
162- if ( parser . contextAvailable ( newEntities [ i ] , ctx ) ) {
163- entityName = parser . applyExpression ( newEntities [ i ] , ctx , typeInformation ) ;
164- }
165-
166- result . push ( {
167- type : entityTypes [ newEntities [ i ] ] ,
168- isPattern : 'false' ,
169- id : ensureEntityId ( entityName , newEntities [ i ] ) ,
170- attributes : newEntityAttributes
171- } ) ;
172- }
173-
174- return result ;
175- }
176-
177111/**
178112 * Generate new Context Elements for each new Entity, with the attributes of the original entity matching its
179113 * entity_name. It considers Ngsiv2.
@@ -295,25 +229,7 @@ function propagateTimestamp(entity, entities) {
295229 } ) ;
296230}
297231
298- function updateAttributeNgsi1 ( entity , typeInformation , callback ) {
299- if ( typeInformation . active ) {
300- const multiEntityAttributes = typeInformation . active . filter ( hasEntityName ) ;
301- const newEntities = _ . uniq ( _ . pluck ( multiEntityAttributes , 'entity_name' ) ) ;
302- const attributesList = _ . pluck ( multiEntityAttributes , 'name' ) ;
303- const entityTypes = extractTypes ( multiEntityAttributes , entity . contextElements [ 0 ] . type ) ;
304- const resultAttributes = filterOutMultientitiesNgsi1 ( entity . contextElements [ 0 ] . attributes , attributesList ) ;
305-
306- entity . contextElements = entity . contextElements . concat (
307- generateNewCEsNgsi1 ( entity , newEntities , entityTypes , typeInformation , multiEntityAttributes )
308- ) ;
309-
310- entity . contextElements [ 0 ] . attributes = resultAttributes ;
311- }
312-
313- callback ( null , entity , typeInformation ) ;
314- }
315-
316- function updateAttributeNgsi2 ( entity , typeInformation , callback ) {
232+ function updateAttribute ( entity , typeInformation , callback ) {
317233 let entities = [ ] ;
318234 entities . push ( entity ) ;
319235 if ( typeInformation . active ) {
@@ -341,12 +257,4 @@ function updateAttributeNgsi2(entity, typeInformation, callback) {
341257 callback ( null , entities , typeInformation ) ;
342258}
343259
344- function updateAttribute ( entity , typeInformation , callback ) {
345- if ( config . isCurrentNgsi ( ) ) {
346- updateAttributeNgsi2 ( entity , typeInformation , callback ) ;
347- } else {
348- updateAttributeNgsi1 ( entity , typeInformation , callback ) ;
349- }
350- }
351-
352260exports . update = updateAttribute ;
0 commit comments