Skip to content

Commit

Permalink
Merge 9035411 into a0a90ae
Browse files Browse the repository at this point in the history
  • Loading branch information
fgalan committed Oct 10, 2019
2 parents a0a90ae + 9035411 commit 4532c12
Show file tree
Hide file tree
Showing 48 changed files with 2,495 additions and 80 deletions.
2 changes: 2 additions & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
- Add autoprovision (appendMode) in device and group provosion (#805)
- Add: basic operations of NGSIv2 context forwarding (#527)
- Fix: using "append" instead of "APPEND" (which is deprecated) in NGSIv2 operations
- Allow blank as an override for defaultResource
4 changes: 2 additions & 2 deletions lib/plugins/multiEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ function updateAttributeNgsi1(entity, typeInformation, callback) {

function updateAttributeNgsi2(entity, typeInformation, callback) {
var entities = [];
entities.push(entity);
if (typeInformation.active) {
entities.push(entity);


var multiEntityAttributes = typeInformation.active.filter(hasEntityName),
newEntities = _.pluck(multiEntityAttributes, 'entity_name'),
attributesList = _.pluck(multiEntityAttributes, 'name'),
Expand Down
11 changes: 8 additions & 3 deletions lib/services/devices/deviceRegistryMemory.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,20 @@ function getDevicesByService(service, subservice) {
* @param {Number} limit Maximum number of entries to return.
* @param {Number} offset Number of entries to skip for pagination.
*/
function listDevices(service, subservice, limit, offset, callback) {
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){
result.push(registeredDevices[service][deviceList[i]]);
} else if (type) {
countNumber--;
} else {
result.push(registeredDevices[service][deviceList[i]]);
}
Expand All @@ -131,7 +136,7 @@ function listDevices(service, subservice, limit, offset, callback) {
}

callback(null, {
count: deviceList.length,
count: countNumber,
devices: result
});
}
Expand Down
7 changes: 6 additions & 1 deletion lib/services/devices/deviceRegistryMongoDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,20 @@ function removeDevice(id, service, subservice, callback) {
/**
* Return the list of currently registered devices (via callback).
*
* @param {String} tyoe Type for which the devices are requested.
* @param {String} service Service for which the devices are requested.
* @param {String} subservice Subservice inside the service for which the devices are requested.
* @param {Number} limit Maximum number of entries to return.
* @param {Number} offset Number of entries to skip for pagination.
*/
function listDevices(service, subservice, limit, offset, callback) {
function listDevices(type, service, subservice, limit, offset, callback) {
var condition = {},
query;

if (type) {
condition.type = type;
}

if (service) {
condition.service = service;
}
Expand Down
42 changes: 38 additions & 4 deletions lib/services/devices/deviceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,15 @@ function updateEntityNgsi2(deviceData, updatedDevice, callback) {
};
}

logger.debug(context, 'Updating entity in the Context Broker:\n %s', JSON.stringify(options, null, 4));

request(options, updateEntityHandlerNgsi2(deviceData, updatedDevice, callback));
// FIXME: maybe there is be a better way to theck options.json = {}
if (Object.keys(options.json).length === 0 && options.json.constructor === Object) {
logger.debug(context, 'Skip updating entity in the Context Broker (no actual attribute change)');
callback(null, updatedDevice);
}
else{
logger.debug(context, 'Updating entity in the Context Broker:\n %s', JSON.stringify(options, null, 4));
request(options, updateEntityHandlerNgsi2(deviceData, updatedDevice, callback));
}
}

/**
Expand Down Expand Up @@ -1003,6 +1009,33 @@ function updateRegisterDevice(deviceObj, callback) {
}
}

/**
* Return a list of all the devices registered in the system. This function can be invoked in three different ways:
* with just one parameter (the callback) with three parameters (service, subservice and callback) or with five
* parameters (including limit and offset).
*
* @param {String} type Type for which the devices are requested.
* @param {String} service Service for which the devices are requested.
* @param {String} subservice Subservice inside the service for which the devices are requested.
* @param {Number} limit Maximum number of entries to return.
* @param {Number} offset Number of entries to skip for pagination.
*/
function listDevicesWithType(type, service, subservice, limit, offset, callback) {
if (!callback) {
if (service && subservice && limit) {
callback = limit;
} else if (service) {
callback = service;
service = null;
subservice = null;
} else {
logger.fatal(context, 'GENERAL-001: Couldn\'t find callback in listDevices() call.');
}
}

config.getRegistry().list(type, service, subservice, limit, offset, callback);
}

/**
* Return a list of all the devices registered in the system. This function can be invoked in three different ways:
* with just one parameter (the callback) with three parameters (service, subservice and callback) or with five
Expand All @@ -1026,7 +1059,7 @@ function listDevices(service, subservice, limit, offset, callback) {
}
}

config.getRegistry().list(service, subservice, limit, offset, callback);
config.getRegistry().list(null, service, subservice, limit, offset, callback);
}

/**
Expand Down Expand Up @@ -1165,6 +1198,7 @@ function retrieveDevice(deviceId, apiKey, callback) {
}

exports.listDevices = intoTrans(context, checkRegistry)(listDevices);
exports.listDevicesWithType = intoTrans(context, checkRegistry)(listDevicesWithType);
exports.getDevice = intoTrans(context, checkRegistry)(getDevice);
exports.getDevicesByAttribute = intoTrans(context, checkRegistry)(getDevicesByAttribute);
exports.getDeviceByName = intoTrans(context, checkRegistry)(getDeviceByName);
Expand Down
3 changes: 1 addition & 2 deletions lib/services/devices/registrationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ function sendRegistrationsNgsi2(unregister, deviceData, callback) {
provider: {
http: {
url: config.getConfig().providerUrl
},
legacyForwarding: true
}
}
},
headers: {
Expand Down
2 changes: 1 addition & 1 deletion lib/services/ngsi/ngsiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ function sendUpdateValueNgsi2(entityName, attributes, typeInformation, token, ca
}

options.json = {
actionType: 'APPEND',
actionType: 'append',
entities: result
};
} else {
Expand Down
Loading

0 comments on commit 4532c12

Please sign in to comment.