Skip to content
Merged
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