Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -6,5 +6,6 @@ Basic NGSI-LD active measures support (#841)
Add GeoJSON and DateTime, unitCode and observedAt NGSI-LD support (#843)
- The NGSI v2 `TimeInstant` element has been mapped onto the NGSI-LD `observedAt` property
- The NGSI v2 `metadata.unitCode` attribute has been mapped onto the NGSI-LD `unitCode` property
Add NGSI-LD multi-measures support (#847)
Add NGSIv2 metadata support to attributeAlias plugin.
Add mongodb authentication: IOTA_MONGO_USER, IOTA_MONGO_PASSWORD and IOTA_MONGO_AUTH_SOURCE (#844)
34 changes: 26 additions & 8 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@

'use strict';

const LOCATION_TYPE = 'geo:point';
const LOCATION_DEFAULT = '0, 0';
const DATETIME_TYPE = 'DateTime';
const DATETIME_DEFAULT = '1970-01-01T00:00:00.000Z';
const ATTRIBUTE_DEFAULT = ' ';

/**
* Provides a default value for DateTime, GeoProperty and Property Attributes.
*
* @param {String} type The type of attribute being created.
* @return {String} A default value to use in the entity
*/
function getInitialValueForType(type) {
switch (type) {
case LOCATION_TYPE:
return LOCATION_DEFAULT;
case DATETIME_TYPE:
return DATETIME_DEFAULT;
default:
return ATTRIBUTE_DEFAULT;
}
}

module.exports = {
TIMESTAMP_ATTRIBUTE: 'TimeInstant',
TIMESTAMP_TYPE: 'ISO8601',
Expand All @@ -47,14 +70,9 @@ module.exports = {
DEFAULT_MONGODB_RETRIES: 5,
DEFAULT_MONGODB_RETRY_TIME: 5,

ATTRIBUTE_DEFAULT: ' ',

LOCATION_TYPE: 'geo:point',
LOCATION_DEFAULT: '0, 0',
DATETIME_TYPE: 'DateTime',
DATETIME_DEFAULT: '1970-01-01T00:00:00.000Z',

MONGO_ALARM: 'MONGO-ALARM',
ORION_ALARM: 'ORION-ALARM',
IOTAM_ALARM: 'IOTAM-ALARM'
IOTAM_ALARM: 'IOTAM-ALARM',

getInitialValueForType: getInitialValueForType
};
2 changes: 1 addition & 1 deletion lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = {
},
UnsupportedContentType: function(type) {
this.name = 'UNSUPPORTED_CONTENT_TYPE';
this.message = 'Unsuported content type in the context request: ' + type;
this.message = 'Unsupported content type in the context request: ' + type;
this.code = 400;
},
TypeNotFound: function(id, type) {
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/attributeAlias.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var config = require('../commonConfig'),
context = {
op: 'IoTAgentNGSI.attributeAlias'
},
ngsiService = require('../services/ngsi/ngsiService');
ngsiUtils = require('../services/ngsi/ngsiUtils');

function extractSingleMapping(previous, current) {
/* jshint camelcase: false */
Expand Down Expand Up @@ -100,7 +100,7 @@ function updateAttribute(entity, typeInformation, callback) {
var attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
attsArray = attsArray.map(applyAlias(mappings));
entity = utils.createNgsi2Entity(entity.id, entity.type, attsArray, true);
ngsiService.castJsonNativeAttributes(entity);
ngsiUtils.castJsonNativeAttributes(entity);
} else {
entity.contextElements[0].attributes = entity.contextElements[0].attributes.map(applyAlias(mappings));
}
Expand Down
4 changes: 2 additions & 2 deletions lib/services/devices/deviceRegistryMemory.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ function listDevices(type, service, subservice, limit, offset, callback) {
var result = [],
skipped = 0,
deviceList = getDevicesByService(service, subservice);

var countNumber = deviceList.length;
for (var i in deviceList) {
if (registeredDevices[service].hasOwnProperty(deviceList[i])) {
if (offset && skipped < parseInt(offset, 10)) {
skipped++;
} else if (type && registeredDevices[service][deviceList[i]].type === type){
} else if (type && registeredDevices[service][deviceList[i]].type === type) {
result.push(registeredDevices[service][deviceList[i]]);
} else if (type) {
countNumber--;
Expand Down
42 changes: 30 additions & 12 deletions lib/services/devices/deviceRegistryMongoDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,35 @@ function saveDeviceHandler(callback) {
*/
function storeDevice(newDevice, callback) {
var deviceObj = new Device.model(),
attributeList = ['id', 'type', 'name', 'service', 'subservice', 'lazy', 'commands', 'staticAttributes',
'active', 'registrationId', 'internalId', 'internalAttributes', 'resource', 'apikey', 'protocol',
'endpoint', 'transport', 'polling', 'timestamp', 'autoprovision'];
attributeList = [
'id',
'type',
'name',
'service',
'subservice',
'lazy',
'commands',
'staticAttributes',
'active',
'registrationId',
'internalId',
'internalAttributes',
'resource',
'apikey',
'protocol',
'endpoint',
'transport',
'polling',
'timestamp',
'autoprovision'
];

for (var i = 0; i < attributeList.length; i++) {
deviceObj[attributeList[i]] = newDevice[attributeList[i]];
}

// Ensure protocol is in newDevice
if ( !newDevice.protocol && config.getConfig().iotManager && config.getConfig().iotManager.protocol) {
if (!newDevice.protocol && config.getConfig().iotManager && config.getConfig().iotManager.protocol) {
deviceObj.protocol = config.getConfig().iotManager.protocol;
}

Expand Down Expand Up @@ -155,10 +174,10 @@ function listDevices(type, service, subservice, limit, offset, callback) {
query.skip(parseInt(offset, 10));
}

async.series([
query.exec.bind(query),
Device.model.countDocuments.bind(Device.model, condition)
], function(error, results) {
async.series([query.exec.bind(query), Device.model.countDocuments.bind(Device.model, condition)], function(
error,
results
) {
callback(error, {
count: results[1],
devices: results[0]
Expand All @@ -184,7 +203,7 @@ function getDeviceById(id, service, subservice, callback) {
logger.debug(context, 'Looking for device with id [%s].', id);

query = Device.model.findOne(queryParams);
query.select({__v: 0});
query.select({ __v: 0 });

query.exec(function handleGet(error, data) {
if (error) {
Expand All @@ -209,7 +228,6 @@ function getDeviceById(id, service, subservice, callback) {
* @param {String} subservice Division inside the service.
*/
function getDevice(id, service, subservice, callback) {

getDeviceById(id, service, subservice, function(error, data) {
if (error) {
callback(error);
Expand All @@ -230,7 +248,7 @@ function getByName(name, service, servicepath, callback) {
subservice: servicepath
});

query.select({__v: 0});
query.select({ __v: 0 });

query.exec(function handleGet(error, data) {
if (error) {
Expand Down Expand Up @@ -304,7 +322,7 @@ function getDevicesByAttribute(name, value, service, subservice, callback) {
logger.debug(context, 'Looking for device with filter [%j].', filter);

query = Device.model.find(filter);
query.select({__v: 0});
query.select({ __v: 0 });

query.exec(function handleGet(error, devices) {
if (error) {
Expand Down
Loading