Skip to content

Commit 8df7a56

Browse files
authored
Merge pull request #995 from jason-fox/feature/ngsi-v1
Fix #966 - Remove Legacy NGSI-v1 from codebase
2 parents 4400cb1 + e3e61fc commit 8df7a56

File tree

213 files changed

+721
-15575
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

213 files changed

+721
-15575
lines changed

CHANGES_NEXT_RELEASE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- Remove: NGSI-v1 implementation (#966)
12
- FIx: export fillDomains function to iotagent-node-lib available functions (needed to fix logs in iotagent-json#587 and iotagent-ul#508)
23
- Fix: keep internalAttributes stored in device mongo collection when update it (#1092)
34
- Add: new JEXL get TimeZone Offset (valid for summer winter schedulles) and binary shifting for bitwise operator

lib/commonConfig.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -525,19 +525,7 @@ function ngsiVersion() {
525525
return 'unknown';
526526
}
527527

528-
/**
529-
* It checks if the configuration file states a non-legacy format,
530-
* either v2, LD or mixed.
531-
*
532-
* @return {boolean} Result of the checking
533-
*/
534-
function isCurrentNgsi() {
535-
if (config.contextBroker && config.contextBroker.ngsiVersion) {
536-
const version = config.contextBroker.ngsiVersion.toLowerCase();
537-
return version === 'v2' || version === 'ld' || version === 'mixed';
538-
}
539-
return false;
540-
}
528+
541529
/**
542530
* It checks if a combination of typeInformation or common Config is LD
543531
*
@@ -566,7 +554,6 @@ exports.setCommandRegistry = setCommandRegistry;
566554
exports.getCommandRegistry = getCommandRegistry;
567555
exports.ngsiVersion = ngsiVersion;
568556
exports.checkNgsiLD = checkNgsiLD;
569-
exports.isCurrentNgsi = isCurrentNgsi;
570557
exports.setSecurityService = setSecurityService;
571558
exports.getSecurityService = getSecurityService;
572559
exports.getSecretData = getSecretData;

lib/errors.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,6 @@ class DeviceNotFound {
9696
this.code = 404;
9797
}
9898
}
99-
class AttributeNotFound {
100-
constructor() {
101-
this.name = 'ATTRIBUTE_NOT_FOUND';
102-
this.message = 'Some of the attributes does not exist';
103-
this.code = 404;
104-
}
105-
}
10699
class DuplicateDeviceId {
107100
constructor(id) {
108101
this.name = 'DUPLICATE_DEVICE_ID';
@@ -190,13 +183,6 @@ class MissingConfigParams {
190183
this.code = 400;
191184
}
192185
}
193-
class NotificationError {
194-
constructor(code) {
195-
this.name = 'NOTIFICATION_ERROR';
196-
this.message = 'Incoming notification with non-200 status code: ' + code;
197-
this.code = 400;
198-
}
199-
}
200186
class DeviceGroupNotFound {
201187
constructor(fields, values) {
202188
this.name = 'DEVICE_GROUP_NOT_FOUND';
@@ -269,7 +255,6 @@ module.exports = {
269255
TypeNotFound,
270256
MissingAttributes,
271257
DeviceNotFound,
272-
AttributeNotFound,
273258
DuplicateDeviceId,
274259
DuplicateGroup,
275260
SecurityInformationMissing,
@@ -282,7 +267,6 @@ module.exports = {
282267
WrongSyntax,
283268
CommandNotFound,
284269
MissingConfigParams,
285-
NotificationError,
286270
DeviceGroupNotFound,
287271
GroupNotFound,
288272
WrongExpressionType,

lib/plugins/attributeAlias.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
* Modified by: Daniel Calvo - ATOS Research & Innovation
2424
*/
2525

26-
const config = require('../commonConfig');
2726
const utils = require('./pluginUtils');
2827
/* eslint-disable no-unused-vars */
2928
const logger = require('logops');
@@ -73,10 +72,7 @@ function extractAllMappings(typeInformation) {
7372
function applyAlias(mappings) {
7473
return function aliasApplier(attribute) {
7574
if (mappings.direct[attribute.name]) {
76-
if (config.isCurrentNgsi()) {
77-
/*jshint camelcase: false */
78-
attribute.object_id = attribute.name; // inverse not usefull due to collision
79-
}
75+
attribute.object_id = attribute.name;
8076
attribute.metadata = mappings.metadata[attribute.name];
8177
attribute.type = mappings.types[attribute.name];
8278
attribute.name = mappings.direct[attribute.name];
@@ -93,14 +89,11 @@ function applyAlias(mappings) {
9389
*/
9490
function updateAttribute(entity, typeInformation, callback) {
9591
const mappings = extractAllMappings(typeInformation);
96-
if (config.isCurrentNgsi()) {
97-
let attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
98-
attsArray = attsArray.map(applyAlias(mappings));
99-
entity = utils.createNgsi2Entity(entity.id, entity.type, attsArray, true);
100-
ngsiUtils.castJsonNativeAttributes(entity);
101-
} else {
102-
entity.contextElements[0].attributes = entity.contextElements[0].attributes.map(applyAlias(mappings));
103-
}
92+
93+
let attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
94+
attsArray = attsArray.map(applyAlias(mappings));
95+
entity = utils.createNgsi2Entity(entity.id, entity.type, attsArray, true);
96+
ngsiUtils.castJsonNativeAttributes(entity);
10497

10598
callback(null, entity, typeInformation);
10699
}

lib/plugins/bidirectionalData.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const deviceService = require('../services/devices/deviceService');
3333
const context = {
3434
op: 'IoTAgentNGSI.BidirectionalPlugin'
3535
};
36-
const config = require('../commonConfig');
3736

3837
/**
3938
* Extract a list of all the bidirectional attributes (those containing reverse expressions) from a device object.
@@ -98,21 +97,6 @@ function extractVariables(item) {
9897
* @param {Array} attributeList List of active attributes for subscription.
9998
*/
10099
function sendSubscriptions(device, attributeList, callback) {
101-
function sendSingleSubscriptionNgsi1(item, innerCb) {
102-
const variables = extractVariables(item);
103-
104-
subscriptions.subscribe(device, [item.name], variables, function handleSubscription(error, subId) {
105-
if (error) {
106-
innerCb(error);
107-
} else {
108-
innerCb(null, {
109-
id: subId,
110-
triggers: [item.name]
111-
});
112-
}
113-
});
114-
}
115-
116100
function sendSingleSubscriptionNgsi2(item, innerCb) {
117101
const variables = extractVariables(item);
118102

@@ -130,11 +114,7 @@ function sendSubscriptions(device, attributeList, callback) {
130114

131115
logger.debug(context, 'Sending bidirectionality subscriptions for device [%s]', device.id);
132116

133-
if (config.isCurrentNgsi()) {
134-
async.map(attributeList, sendSingleSubscriptionNgsi2, callback);
135-
} else {
136-
async.map(attributeList, sendSingleSubscriptionNgsi1, callback);
137-
}
117+
async.map(attributeList, sendSingleSubscriptionNgsi2, callback);
138118
}
139119

140120
/**

lib/plugins/expressionParser.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
const Parser = require('jison').Parser;
2929
const errors = require('../errors');
3030
const logger = require('logops');
31-
const config = require('../commonConfig');
3231
const _ = require('underscore');
3332
const logContext = {
3433
op: 'IoTAgentNGSI.Expression'
@@ -192,7 +191,7 @@ function expressionApplier(context, typeInformation) {
192191
};
193192

194193
/*jshint camelcase: false */
195-
if (config.isCurrentNgsi() && attribute.object_id) {
194+
if (attribute.object_id) {
196195
newAttribute.object_id = attribute.object_id;
197196
}
198197

lib/plugins/expressionPlugin.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,6 @@ function update(entity, typeInformation, callback) {
9090
return false;
9191
}
9292

93-
function processEntityUpdateNgsi1(entity) {
94-
let parser = legacyParser;
95-
if (checkJexl(typeInformation)) {
96-
parser = jexlParser;
97-
}
98-
let expressionAttributes = [];
99-
const ctx = parser.extractContext(entity.attributes);
100-
101-
if (typeInformation.active) {
102-
expressionAttributes = parser.processExpressionAttributes(typeInformation, typeInformation.active, ctx);
103-
}
104-
105-
entity.attributes = mergeAttributes(entity.attributes, expressionAttributes);
106-
107-
return entity;
108-
}
109-
11093
function processEntityUpdateNgsi2(attributes) {
11194
let parser = legacyParser;
11295
if (checkJexl(typeInformation)) {
@@ -124,13 +107,9 @@ function update(entity, typeInformation, callback) {
124107
}
125108

126109
try {
127-
if (config.isCurrentNgsi()) {
128-
let attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
129-
attsArray = processEntityUpdateNgsi2(attsArray);
130-
entity = utils.createNgsi2Entity(entity.id, entity.type, attsArray, true);
131-
} else {
132-
entity.contextElements = entity.contextElements.map(processEntityUpdateNgsi1);
133-
}
110+
let attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
111+
attsArray = processEntityUpdateNgsi2(attsArray);
112+
entity = utils.createNgsi2Entity(entity.id, entity.type, attsArray, true);
134113

135114
callback(null, entity, typeInformation);
136115
} catch (e) {

lib/plugins/jexlParser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function extractContext(attributeList) {
9696
function applyExpression(expression, context, typeInformation) {
9797
const result = jexl.evalSync(expression, context);
9898
logger.debug(logContext, 'applyExpression "[%j]" over "[%j]" result "[%j]" ', expression, context, result);
99-
let expressionResult = result !== undefined ? result : expression;
99+
const expressionResult = result !== undefined ? result : expression;
100100
return expressionResult;
101101
}
102102

@@ -118,7 +118,7 @@ function expressionApplier(context, typeInformation) {
118118
};
119119

120120
/*jshint camelcase: false */
121-
if (config.isCurrentNgsi() && attribute.object_id) {
121+
if (attribute.object_id) {
122122
newAttribute.object_id = attribute.object_id;
123123
}
124124

lib/plugins/multiEntity.js

Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
352260
exports.update = updateAttribute;

0 commit comments

Comments
 (0)