Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
85bfea1
Remove NGSI-v1
jason-fox Feb 24, 2021
de1bfaf
Linter fixes - mainly removing reference to config.
jason-fox Feb 24, 2021
a80871e
Remove NGSI-v1 references.
jason-fox Feb 24, 2021
cd21823
Deleting unused NGSI-v1 stubs.
jason-fox Feb 24, 2021
fca1722
Remove unused consts.
jason-fox Feb 24, 2021
5368dd4
Pruning more NGSI-v1
jason-fox Feb 24, 2021
d178cb2
Remove exports
jason-fox Feb 24, 2021
addb3c2
Re-add devices test
jason-fox Feb 24, 2021
fd6b3b7
Re-add Group tests
jason-fox Feb 24, 2021
94e1cb8
Enable more tests.
jason-fox Feb 24, 2021
fdb3c0f
Merge branch 'master' into feature/ngsi-v1
jason-fox Apr 12, 2021
d9d85e0
Remove obsolete files
jason-fox Apr 12, 2021
d6f3235
Add missing file
jason-fox Apr 12, 2021
13dc709
Fix path
jason-fox Apr 12, 2021
aefdb3e
Merge branch 'master' into feature/ngsi-v1
jason-fox May 17, 2021
b693b04
Merge branch 'master' into feature/ngsi-v1
jason-fox May 21, 2021
9e5155a
Merge branch 'master' into feature/ngsi-v1
jason-fox Jun 1, 2021
a951418
Merge branch 'master' into feature/ngsi-v1
jason-fox Jun 24, 2021
8a75a01
Switch Post to Patch
jason-fox Jun 24, 2021
deee380
Update text to reflect NGSI-v2
jason-fox Jul 15, 2021
cba02f1
Merge branch 'master' into feature/ngsi-v1
jason-fox Jul 15, 2021
451ea19
Remove isCurrentNgsi
jason-fox Jul 15, 2021
ae33e1f
Remove export
jason-fox Jul 15, 2021
562b6fa
remove require
jason-fox Jul 15, 2021
e98d298
Remove function.
jason-fox Jul 19, 2021
c0dc200
Re-add missing tests.
jason-fox Jul 19, 2021
dd4c544
Remove useUnifiedTopology: true
jason-fox Jul 19, 2021
b966458
Convert test.
jason-fox Jul 19, 2021
4ab2559
Merge branch 'master' into feature/ngsi-v1
jason-fox Aug 31, 2021
d408225
Adding test
jason-fox Aug 31, 2021
982b90c
Adding test
jason-fox Aug 31, 2021
6a15fed
Add missing v2 tests. Add defensive code.
jason-fox Aug 31, 2021
abc5f86
Add missing v2 tests.
jason-fox Aug 31, 2021
359f1f3
Fix ENV test side-effect.
jason-fox Aug 31, 2021
40f432c
Add missing test case
jason-fox Aug 31, 2021
6ea97f9
Remove unused import
jason-fox Aug 31, 2021
8967676
Add missing tests.
jason-fox Aug 31, 2021
5772aef
Remove NGSIv1 error handler.
jason-fox Sep 1, 2021
5ae0683
Add missing test.
jason-fox Sep 1, 2021
d7e0cb6
Enable test
jason-fox Sep 1, 2021
b1758c3
Use error classes
jason-fox Sep 1, 2021
56d67b2
Simplify entities error handling logic
jason-fox Sep 2, 2021
2304aae
Removal of NGSI-v1 error class
jason-fox Sep 2, 2021
3be10f7
Update test descriptions
jason-fox Sep 2, 2021
4a9fd4c
Update CNR
jason-fox Sep 2, 2021
e3e61fc
Merge branch 'master' into feature/ngsi-v1
jason-fox Sep 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Remove: NGSI-v1 implementation (#966)
- FIx: export fillDomains function to iotagent-node-lib available functions (needed to fix logs in iotagent-json#587 and iotagent-ul#508)
- Fix: keep internalAttributes stored in device mongo collection when update it (#1092)
15 changes: 1 addition & 14 deletions lib/commonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,19 +525,7 @@ function ngsiVersion() {
return 'unknown';
}

/**
* It checks if the configuration file states a non-legacy format,
* either v2, LD or mixed.
*
* @return {boolean} Result of the checking
*/
function isCurrentNgsi() {
if (config.contextBroker && config.contextBroker.ngsiVersion) {
const version = config.contextBroker.ngsiVersion.toLowerCase();
return version === 'v2' || version === 'ld' || version === 'mixed';
}
return false;
}

/**
* It checks if a combination of typeInformation or common Config is LD
*
Expand Down Expand Up @@ -566,7 +554,6 @@ exports.setCommandRegistry = setCommandRegistry;
exports.getCommandRegistry = getCommandRegistry;
exports.ngsiVersion = ngsiVersion;
exports.checkNgsiLD = checkNgsiLD;
exports.isCurrentNgsi = isCurrentNgsi;
exports.setSecurityService = setSecurityService;
exports.getSecurityService = getSecurityService;
exports.getSecretData = getSecretData;
16 changes: 0 additions & 16 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,6 @@ class DeviceNotFound {
this.code = 404;
}
}
class AttributeNotFound {
constructor() {
this.name = 'ATTRIBUTE_NOT_FOUND';
this.message = 'Some of the attributes does not exist';
this.code = 404;
}
}
class DuplicateDeviceId {
constructor(id) {
this.name = 'DUPLICATE_DEVICE_ID';
Expand Down Expand Up @@ -190,13 +183,6 @@ class MissingConfigParams {
this.code = 400;
}
}
class NotificationError {
constructor(code) {
this.name = 'NOTIFICATION_ERROR';
this.message = 'Incoming notification with non-200 status code: ' + code;
this.code = 400;
}
}
class DeviceGroupNotFound {
constructor(fields, values) {
this.name = 'DEVICE_GROUP_NOT_FOUND';
Expand Down Expand Up @@ -269,7 +255,6 @@ module.exports = {
TypeNotFound,
MissingAttributes,
DeviceNotFound,
AttributeNotFound,
DuplicateDeviceId,
DuplicateGroup,
SecurityInformationMissing,
Expand All @@ -282,7 +267,6 @@ module.exports = {
WrongSyntax,
CommandNotFound,
MissingConfigParams,
NotificationError,
DeviceGroupNotFound,
GroupNotFound,
WrongExpressionType,
Expand Down
19 changes: 6 additions & 13 deletions lib/plugins/attributeAlias.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* Modified by: Daniel Calvo - ATOS Research & Innovation
*/

const config = require('../commonConfig');
const utils = require('./pluginUtils');
/* eslint-disable no-unused-vars */
const logger = require('logops');
Expand Down Expand Up @@ -73,10 +72,7 @@ function extractAllMappings(typeInformation) {
function applyAlias(mappings) {
return function aliasApplier(attribute) {
if (mappings.direct[attribute.name]) {
if (config.isCurrentNgsi()) {
/*jshint camelcase: false */
attribute.object_id = attribute.name; // inverse not usefull due to collision
}
attribute.object_id = attribute.name;
attribute.metadata = mappings.metadata[attribute.name];
attribute.type = mappings.types[attribute.name];
attribute.name = mappings.direct[attribute.name];
Expand All @@ -93,14 +89,11 @@ function applyAlias(mappings) {
*/
function updateAttribute(entity, typeInformation, callback) {
const mappings = extractAllMappings(typeInformation);
if (config.isCurrentNgsi()) {
let attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
attsArray = attsArray.map(applyAlias(mappings));
entity = utils.createNgsi2Entity(entity.id, entity.type, attsArray, true);
ngsiUtils.castJsonNativeAttributes(entity);
} else {
entity.contextElements[0].attributes = entity.contextElements[0].attributes.map(applyAlias(mappings));
}

let attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
attsArray = attsArray.map(applyAlias(mappings));
entity = utils.createNgsi2Entity(entity.id, entity.type, attsArray, true);
ngsiUtils.castJsonNativeAttributes(entity);

callback(null, entity, typeInformation);
}
Expand Down
22 changes: 1 addition & 21 deletions lib/plugins/bidirectionalData.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const deviceService = require('../services/devices/deviceService');
const context = {
op: 'IoTAgentNGSI.BidirectionalPlugin'
};
const config = require('../commonConfig');

/**
* Extract a list of all the bidirectional attributes (those containing reverse expressions) from a device object.
Expand Down Expand Up @@ -98,21 +97,6 @@ function extractVariables(item) {
* @param {Array} attributeList List of active attributes for subscription.
*/
function sendSubscriptions(device, attributeList, callback) {
function sendSingleSubscriptionNgsi1(item, innerCb) {
const variables = extractVariables(item);

subscriptions.subscribe(device, [item.name], variables, function handleSubscription(error, subId) {
if (error) {
innerCb(error);
} else {
innerCb(null, {
id: subId,
triggers: [item.name]
});
}
});
}

function sendSingleSubscriptionNgsi2(item, innerCb) {
const variables = extractVariables(item);

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

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

if (config.isCurrentNgsi()) {
async.map(attributeList, sendSingleSubscriptionNgsi2, callback);
} else {
async.map(attributeList, sendSingleSubscriptionNgsi1, callback);
}
async.map(attributeList, sendSingleSubscriptionNgsi2, callback);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions lib/plugins/expressionParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
const Parser = require('jison').Parser;
const errors = require('../errors');
const logger = require('logops');
const config = require('../commonConfig');
const _ = require('underscore');
const logContext = {
op: 'IoTAgentNGSI.Expression'
Expand Down Expand Up @@ -192,7 +191,7 @@ function expressionApplier(context, typeInformation) {
};

/*jshint camelcase: false */
if (config.isCurrentNgsi() && attribute.object_id) {
if (attribute.object_id) {
newAttribute.object_id = attribute.object_id;
}

Expand Down
27 changes: 3 additions & 24 deletions lib/plugins/expressionPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,6 @@ function update(entity, typeInformation, callback) {
return false;
}

function processEntityUpdateNgsi1(entity) {
let parser = legacyParser;
if (checkJexl(typeInformation)) {
parser = jexlParser;
}
let expressionAttributes = [];
const ctx = parser.extractContext(entity.attributes);

if (typeInformation.active) {
expressionAttributes = parser.processExpressionAttributes(typeInformation, typeInformation.active, ctx);
}

entity.attributes = mergeAttributes(entity.attributes, expressionAttributes);

return entity;
}

function processEntityUpdateNgsi2(attributes) {
let parser = legacyParser;
if (checkJexl(typeInformation)) {
Expand All @@ -124,13 +107,9 @@ function update(entity, typeInformation, callback) {
}

try {
if (config.isCurrentNgsi()) {
let attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
attsArray = processEntityUpdateNgsi2(attsArray);
entity = utils.createNgsi2Entity(entity.id, entity.type, attsArray, true);
} else {
entity.contextElements = entity.contextElements.map(processEntityUpdateNgsi1);
}
let attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
attsArray = processEntityUpdateNgsi2(attsArray);
entity = utils.createNgsi2Entity(entity.id, entity.type, attsArray, true);

callback(null, entity, typeInformation);
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/jexlParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function extractContext(attributeList) {
function applyExpression(expression, context, typeInformation) {
const result = jexl.evalSync(expression, context);
logger.debug(logContext, 'applyExpression "[%j]" over "[%j]" result "[%j]" ', expression, context, result);
let expressionResult = result !== undefined ? result : expression;
const expressionResult = result !== undefined ? result : expression;
return expressionResult;
}

Expand All @@ -118,7 +118,7 @@ function expressionApplier(context, typeInformation) {
};

/*jshint camelcase: false */
if (config.isCurrentNgsi() && attribute.object_id) {
if (attribute.object_id) {
newAttribute.object_id = attribute.object_id;
}

Expand Down
94 changes: 1 addition & 93 deletions lib/plugins/multiEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,6 @@ function ensureEntityId(entityName, originalEntityName) {
return entityName ? entityName : originalEntityName;
}

/**
* Return a list of all the attributes that don't have a multientity option. It considers NGSIv1.
*
* @param {Array} originalAttrs Array of original attributes coming from the single-entity device.
* @param {Array} meAttributes Array of all the multientity attributes.
* @return {Array} List of all the attrbiutes without multientity flag.
*/
function filterOutMultientitiesNgsi1(originalAttrs, meAttributes) {
return originalAttrs.filter(function (item) {
return !_.contains(meAttributes, item.name);
});
}

/**
* Return a list of all the attributes that don't have a multientity option. It considers NGSIv2.
*
Expand Down Expand Up @@ -121,59 +108,6 @@ function filterOutMultientitiesNgsi2(originalAttrs, meAttributes) {
return result;
}

/**
* Generate new Context Elements for each new Entity, with the attributes of the original entity matching its
* entity_name. It considers Ngsiv1.
*
* @param {Object} entity The original entity
* @param {Array} newEntities List of the new entities that will be generated
* @param {Array} entityTypes Map of the types for each entity ID
* @param {Object} typeInformation Object with all the data about the device type
* @param {Array} multiEntityAttributes List of attributes with multientity option
* @return {Array} List of the new Context Entities
*/
function generateNewCEsNgsi1(entity, newEntities, entityTypes, typeInformation, multiEntityAttributes) {
const result = [];
let newEntityAttributes;
let newEntityAttributeNames;
let entityName;
let parser = legacyParser;
if (checkJexl(typeInformation)) {
parser = jexlParser;
}
function filterByEntityName(entityName) {
return function (item) {
return item.entity_name === entityName;
};
}

function filterByAttributeNames(item) {
return _.contains(newEntityAttributeNames, item.name);
}

const ctx = parser.extractContext(entity.contextElements[0].attributes);

for (let i = 0; i < newEntities.length; i++) {
newEntityAttributeNames = _.pluck(multiEntityAttributes.filter(filterByEntityName(newEntities[i])), 'name');

newEntityAttributes = entity.contextElements[0].attributes.filter(filterByAttributeNames);
// Fix duplicated attributes in entity
newEntityAttributes = _.uniq(newEntityAttributes, JSON.stringify);
if (parser.contextAvailable(newEntities[i], ctx)) {
entityName = parser.applyExpression(newEntities[i], ctx, typeInformation);
}

result.push({
type: entityTypes[newEntities[i]],
isPattern: 'false',
id: ensureEntityId(entityName, newEntities[i]),
attributes: newEntityAttributes
});
}

return result;
}

/**
* Generate new Context Elements for each new Entity, with the attributes of the original entity matching its
* entity_name. It considers Ngsiv2.
Expand Down Expand Up @@ -295,25 +229,7 @@ function propagateTimestamp(entity, entities) {
});
}

function updateAttributeNgsi1(entity, typeInformation, callback) {
if (typeInformation.active) {
const multiEntityAttributes = typeInformation.active.filter(hasEntityName);
const newEntities = _.uniq(_.pluck(multiEntityAttributes, 'entity_name'));
const attributesList = _.pluck(multiEntityAttributes, 'name');
const entityTypes = extractTypes(multiEntityAttributes, entity.contextElements[0].type);
const resultAttributes = filterOutMultientitiesNgsi1(entity.contextElements[0].attributes, attributesList);

entity.contextElements = entity.contextElements.concat(
generateNewCEsNgsi1(entity, newEntities, entityTypes, typeInformation, multiEntityAttributes)
);

entity.contextElements[0].attributes = resultAttributes;
}

callback(null, entity, typeInformation);
}

function updateAttributeNgsi2(entity, typeInformation, callback) {
function updateAttribute(entity, typeInformation, callback) {
let entities = [];
entities.push(entity);
if (typeInformation.active) {
Expand Down Expand Up @@ -341,12 +257,4 @@ function updateAttributeNgsi2(entity, typeInformation, callback) {
callback(null, entities, typeInformation);
}

function updateAttribute(entity, typeInformation, callback) {
if (config.isCurrentNgsi()) {
updateAttributeNgsi2(entity, typeInformation, callback);
} else {
updateAttributeNgsi1(entity, typeInformation, callback);
}
}

exports.update = updateAttribute;
Loading