Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Refresh Documentation
Add NGSIv2 metadata support to device provisioned attributes
Fix: Error message when sending measures with unknown/undefined attribute
Add Null check within executeWithSecurity() to avoid crash (#829)
Basic NGSI-LD active measures support (#841)
Add NGSIv2 metadata support to attributeAlias plugin.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line seems to belong to PR #839. Thus, I understand that jason-fox:feature/ngsi-ld-measure is a branch of jason-fox:feature/add-v2-metadata.

PR #839 should be merged before, then this PR updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct - this PR is dependent upon and extends the metadata change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #839 has been merged. This PR branch should be upgrade, then this diff will disappear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've merge master which should reduce the diff - Fixed with dd81751

15 changes: 15 additions & 0 deletions doc/installationguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ These are the parameters that can be configured in the global section:
}
```

- If you want to use NGSI-LD (experimental):

```javascript
{
host: '192.168.56.101',
port: '1026',
ngsiVersion: 'ld',
jsonLdContext: 'http://context.json-ld''
}
```

Where `http://context.json-ld` is the location of the NGSI-LD `@context` element which provides additional information allowing the computer to
interpret the rest of the data with more clarity and depth. Read the [JSON-LD specification](https://w3c.github.io/json-ld-syntax/#the-context) for more informtaion.

- **server**: configuration used to create the Context Server (port where the IoT Agent will be listening as a Context
Provider and base root to prefix all the paths). The `port` attribute is required. If no `baseRoot` attribute is
used, '/' is used by default. E.g.:
Expand Down Expand Up @@ -262,3 +276,4 @@ overrides.
| IOTA_POLLING_DAEMON_FREQ | `pollingDaemonFrequency` |
| IOTA_AUTOCAST | `autocast` |
| IOTA_MULTI_CORE | `multiCore` |
| IOTA_JSON_LD_CONTEXT | `jsonLdContext` |
22 changes: 21 additions & 1 deletion lib/commonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ function processEnvironmentVariables() {
'IOTA_APPEND_MODE',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHANGES_NEXT_RELEASE entry should be provided for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed b41a18a

'IOTA_POLLING_EXPIRATION',
'IOTA_POLLING_DAEMON_FREQ',
'IOTA_MULTI_CORE'
'IOTA_MULTI_CORE',
'IOTA_JSON_LD_CONTEXT'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New env var should be described in documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed b41a18a - Minimal Documentation for now.

],
iotamVariables = [
'IOTA_IOTAM_URL',
Expand Down Expand Up @@ -146,6 +147,9 @@ function processEnvironmentVariables() {
if (process.env.IOTA_CB_NGSI_VERSION) {
config.contextBroker.ngsiVersion = process.env.IOTA_CB_NGSI_VERSION;
}
if (process.env.IOTA_JSON_LD_CONTEXT){
config.contextBroker.jsonLdContext = process.env.IOTA_JSON_LD_CONTEXT;
}

// North Port Configuration (ensuring the configuration sub-object exists before start using it)
if (config.server === undefined) {
Expand Down Expand Up @@ -377,6 +381,21 @@ function checkNgsi2() {
return false;
}

/**
* It checks if the configuration file states the use of NGSI-LD
*
* @return {boolean} Result of the checking
*/
function checkNgsiLD() {
if (config.contextBroker &&
config.contextBroker.ngsiVersion &&
config.contextBroker.ngsiVersion === 'ld') {
return true;
}

return false;
}

function setSecurityService(newSecurityService) {
securityService = newSecurityService;
}
Expand All @@ -394,5 +413,6 @@ exports.getGroupRegistry = getGroupRegistry;
exports.setCommandRegistry = setCommandRegistry;
exports.getCommandRegistry = getCommandRegistry;
exports.checkNgsi2 = checkNgsi2;
exports.checkNgsiLD = checkNgsiLD;
exports.setSecurityService = setSecurityService;
exports.getSecurityService = getSecurityService;
4 changes: 2 additions & 2 deletions lib/plugins/attributeAlias.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function extractAllMappings(typeInformation) {
function applyAlias(mappings) {
return function aliasApplier(attribute) {
if (mappings.direct[attribute.name]) {
if (config.checkNgsi2()) {
if (config.checkNgsi2() || config.checkNgsiLD()) {
/*jshint camelcase: false */
attribute.object_id = attribute.name; // inverse not usefull due to collision
}
Expand All @@ -96,7 +96,7 @@ function applyAlias(mappings) {
*/
function updateAttribute(entity, typeInformation, callback) {
var mappings = extractAllMappings(typeInformation);
if (config.checkNgsi2()) {
if (config.checkNgsi2() || config.checkNgsiLD()) {
var attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
attsArray = attsArray.map(applyAlias(mappings));
entity = utils.createNgsi2Entity(entity.id, entity.type, attsArray, true);
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/bidirectionalData.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function sendSubscriptions(device, attributeList, callback) {

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

if (config.checkNgsi2()) {
if (config.checkNgsi2() || config.checkNgsiLD()) {
async.map(attributeList, sendSingleSubscriptionNgsi2, callback);
} else {
async.map(attributeList, sendSingleSubscriptionNgsi1, callback);
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/expressionParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function expressionApplier(context, typeInformation) {
};

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

Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/expressionPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function update(entity, typeInformation, callback) {
}

try {
if (config.checkNgsi2()) {
if (config.checkNgsi2() || config.checkNgsiLD()) {
var attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
attsArray = processEntityUpdateNgsi2(attsArray);
entity = utils.createNgsi2Entity(entity.id, entity.type, attsArray, true);
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/multiEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ function updateAttributeNgsi2(entity, typeInformation, callback) {
}

function updateAttribute(entity, typeInformation, callback) {
if (config.checkNgsi2()) {
if (config.checkNgsi2() || config.checkNgsiLD()) {
updateAttributeNgsi2(entity, typeInformation, callback);
} else {
updateAttributeNgsi1(entity, typeInformation, callback);
Expand Down
6 changes: 3 additions & 3 deletions lib/plugins/pluginUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function createProcessAttribute(fn, attributeType) {
attribute.value = fn(attribute.value);
}

if (config.checkNgsi2()) {
if (config.checkNgsi2() || config.checkNgsiLD()) {
// This code is backwards compatible to process metadata in the older NGSIv1-style (array)
// as well as supporting the newer NGSIv2-style (object). The redundant Array Check can be
// therefore be removed if/when NGSIv1 support is removed from the library.
Expand Down Expand Up @@ -152,7 +152,7 @@ function createUpdateFilter(fn, attributeType) {
return entity;
}

if (config.checkNgsi2()) {
if (config.checkNgsi2() || config.checkNgsiLD()) {
entity = processEntityUpdateNgsi2(entity);
} else {
entity.contextElements = entity.contextElements.map(processEntityUpdateNgsi1);
Expand Down Expand Up @@ -186,7 +186,7 @@ function createQueryFilter(fn, attributeType) {
return entity;
}

if (config.checkNgsi2()) {
if (config.checkNgsi2() || config.checkNgsiLD()) {
entity = processEntityQueryNgsi2(entity);
} else {
entity.contextResponses = entity.contextResponses.map(processEntityQueryNgsi1);
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/timestampProcessPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function updatePluginNgsi1(entity, entityType, callback) {
* @param {Object} entity NGSI Entity as it would have been sent before the plugin.
*/
function updatePlugin(entity, entityType, callback) {
if (config.checkNgsi2()) {
if (config.checkNgsi2() || config.checkNgsiLD()) {
updatePluginNgsi2(entity, entityType, callback);
} else {
updatePluginNgsi1(entity, entityType, callback);
Expand Down
6 changes: 4 additions & 2 deletions lib/services/common/genericMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function handleError(error, req, res, next) {
function traceRequest(req, res, next) {
logger.debug(context, 'Request for path [%s] from [%s]', req.path, req.get('host'));

if (req.is('json')) {
if (req.is('json') || req.is('application/ld+json')) {
logger.debug(context, 'Body:\n\n%s\n\n', JSON.stringify(req.body, null, 4));
}

Expand Down Expand Up @@ -100,6 +100,8 @@ function getLogLevel(req, res, next) {
function ensureType(req, res, next) {
if (req.is('json')) {
next();
} else if (req.is('application/ld+json')) {
next();
} else {
next(new errors.UnsupportedContentType(req.headers['content-type']));
}
Expand All @@ -113,7 +115,7 @@ function ensureType(req, res, next) {
*/
function validateJson(template) {
return function validate(req, res, next) {
if (req.is('json')) {
if (req.is('json') || req.is('application/ld+json')) {
var errorList = revalidator.validate(req.body, template);

if (errorList.valid) {
Expand Down
Loading