Skip to content

Commit 2db114b

Browse files
authored
Merge branch 'master' into revert-945-revert-942-task/default_attribute_value_null_instead_blank
2 parents c399225 + 449cc7b commit 2db114b

File tree

9 files changed

+47
-6
lines changed

9 files changed

+47
-6
lines changed

CHANGES_NEXT_RELEASE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Use null instead of ' ' as default attribute value in entity provisioned (#938)
2+
Add: defaultEntityNameConjunction config (env var IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION) and configuration group API field for default entity_name conjunction (#944)
23
Add basic NGSI-LD support as experimental feature (#842)
34
- Active measures
45
- GeoJSON and DateTime, unitCode and observedAt NGSI-LD support

doc/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ correspondence between the API resource fields and the same fields in the databa
9393
| `expressionLanguage` | `expresionLanguage` | optional boolean value, to set expression language used to compute expressions, possible values are: legacy or jexl. When not set or wrongly set, `legacy` is used as default value. |
9494
| `explicitAttrs` | `explicitAttrs` | optional boolean value, to support selective ignore of measures so that IOTA doesn’t progress. If not specified default is `false`. |
9595
| `ngsiVersion` | `ngsiVersion` | optional string value used in mixed mode to switch between **NGSI-v2** and **NGSI-LD** payloads. Possible values are: `v2` or `ld`. The default is `v2`. When not running in mixed mode, this field is ignored.
96+
| `defaultEntityNameConjunction` | `defaultEntityNameConjunction` | optional string value to set default conjunction string used to compose a default `entity_name` when is not provided at device provisioning time. |
9697

9798
### Service Group Endpoint
9899

doc/installationguide.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ used for the same purpose. For instance:
278278
standard, but the final decision has yet been confirmed), take into account it could change
279279
- **explicitAttrs**: if this flag is activated, only provisioned attributes will be processed to Context Broker. This
280280
flag is overwritten by `explicitAttrs` flag in group or device provision.
281+
- **defaultEntityNameConjunction**: the default conjunction string used to compose a default `entity_name` when is not
282+
provided at device provisioning time; in that case `entity_name` is composed by `type` + `:` + `device_id`.
283+
Default value is `:`. This value is overwritten by `defaultEntityNameConjunction` in group provision.
281284
- **relaxTemplateValidation**: if this flag is activated, `objectId` attributes for incoming devices are not
282285
validated, and may exceptionally include characters (such as semi-colons) which are
283286
[forbidden](https://fiware-orion.readthedocs.io/en/master/user/forbidden_characters/index.html) according to the
@@ -345,6 +348,7 @@ overrides.
345348
| IOTA_FALLBACK_PATH | `fallbackPath` |
346349
| IOTA_DEFAULT_EXPRESSION_LANGUAGE | `defaultExpressionLanguage` |
347350
| IOTA_EXPLICIT_ATTRS | `explicitAttrs` |
351+
| IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION | `defaultEntityNameConjunction` |
348352
| IOTA_RELAX_TEMPLATE_VALIDATION | `relaxTemplateValidation` |
349353

350354
Note:

lib/commonConfig.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ function processEnvironmentVariables() {
155155
'IOTA_MULTI_CORE',
156156
'IOTA_DEFAULT_EXPRESSION_LANGUAGE',
157157
'IOTA_RELAX_TEMPLATE_VALIDATION',
158+
'IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION',
158159
'IOTA_JSON_LD_CONTEXT',
159160
'IOTA_FALLBACK_TENANT',
160161
'IOTA_FALLBACK_PATH'
@@ -462,6 +463,11 @@ function processEnvironmentVariables() {
462463
} else {
463464
config.relaxTemplateValidation = config.relaxTemplateValidation === true;
464465
}
466+
if (process.env.IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION) {
467+
config.defaultEntityNameConjunction = process.env.IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION;
468+
} else {
469+
config.defaultEntityNameConjunction = config.defaultEntityNameConjunction ? config.defaultEntityNameConjunction : ':';
470+
}
465471
}
466472

467473
function setConfig(newConfig) {
@@ -515,6 +521,24 @@ function ngsiVersion() {
515521
return 'unknown';
516522
}
517523

524+
/**
525+
* It checks if the configuration file states the use of NGSIv2
526+
* Returns the supported NGSI format
527+
*
528+
* FIXME: this function was removed in https://github.com/telefonicaid/iotagent-node-lib/pull/947. However
529+
* it is used by IOTAs code (e.g. https://github.com/telefonicaid/iotagent-ul/blob/c59bcb21f7408a6c7cc3b50d1d0c4e38fc7478c3/lib/iotaUtils.js#L327)
530+
* We re-introduce this function to fix CI e2e test but a definitive fix should probably done (in the IOTAs code maybe)
531+
*
532+
* @return {boolean} Result of the checking
533+
*/
534+
/* eslint-disable-next-line no-unused-vars */
535+
function checkNgsi2() {
536+
if (ngsiVersion() === 'v2') {
537+
return true;
538+
}
539+
return false;
540+
}
541+
518542
/**
519543
* It checks if the configuration file states a non-legacy format,
520544
* either v2, LD or mixed.
@@ -555,6 +579,8 @@ exports.getGroupRegistry = getGroupRegistry;
555579
exports.setCommandRegistry = setCommandRegistry;
556580
exports.getCommandRegistry = getCommandRegistry;
557581
exports.ngsiVersion = ngsiVersion;
582+
// FIXME: We re-introduce this function to fix CI e2e test but a definitive fix should probably done (in the IOTAs code maybe)
583+
exports.checkNgsi2 = checkNgsi2;
558584
exports.checkNgsiLD = checkNgsiLD;
559585
exports.isCurrentNgsi = isCurrentNgsi;
560586
exports.setSecurityService = setSecurityService;

lib/model/Group.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const Group = new Schema({
4444
autoprovision: Boolean,
4545
expressionLanguage: String,
4646
explicitAttrs: Boolean,
47+
defaultEntityNameConjunction: String,
4748
ngsiVersion: String
4849
});
4950

lib/services/common/iotManagerService.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function register(callback) {
5757
autoprovision: service.autoprovision,
5858
explicitAttrs: service.explicitAttrs,
5959
expressionLanguage: service.expressionLanguage,
60+
defaultEntityNameConjunction: service.defaultEntityNameConjunction,
6061
ngsiVersion: service.ngsiVersion
6162
};
6263
}

lib/services/devices/deviceService.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,17 @@ function registerDevice(deviceObj, callback) {
262262
}
263263

264264
if (!deviceData.name) {
265-
deviceData.name = deviceData.type + ':' + deviceData.id;
266-
if (config.checkNgsiLD(configuration)) {
267-
deviceData.name = 'urn:ngsi-ld:' + deviceData.type + ':' + deviceData.id;
265+
var conjunction;
266+
if (configuration && configuration.defaultEntityNameConjunction !== undefined) {
267+
conjunction = configuration.defaultEntityNameConjunction;
268+
} else {
269+
conjunction = config.getConfig().defaultEntityNameConjunction;
268270
}
269-
logger.debug(context, 'Device name not found, falling back to deviceType:deviceId [%s]', deviceData.name);
271+
deviceData.name = deviceData.type + conjunction + deviceData.id;
272+
if (config.checkNgsiLD(configuration)) {
273+
deviceData.name = 'urn:ngsi-ld:' + deviceData.type + conjunction + deviceData.id;
274+
}
275+
logger.debug(context, 'Device name not found, falling back to deviceType%sdeviceId [%s]', conjunction, deviceData.name);
270276
}
271277

272278
if (!configuration && config.getConfig().types[deviceData.type]) {

lib/services/groups/groupRegistryMongoDB.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function createGroup(group, callback) {
7878
'autoprovision',
7979
'explicitAttrs',
8080
'expressionLanguage',
81+
'defaultEntityNameConjunction',
8182
'ngsiVersion'
8283
];
8384

@@ -272,6 +273,7 @@ function update(id, body, callback) {
272273
'internalAttributes',
273274
'explicitAttrs',
274275
'expressionLanguage',
276+
'defaultEntityNameConjunction',
275277
'ngsiVersion'
276278
];
277279

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"lint:text": "textlint '*.md' 'doc/*.md'",
3737
"prettier": "prettier --config .prettierrc.json --write '**/**/**/**/*.js' '**/**/**/*.js' '**/**/*.js' '**/*.js' '*.js'",
3838
"prettier:text": "prettier 'README.md' 'doc/*.md' 'doc/**/*.md' --no-config --tab-width 4 --print-width 120 --write --prose-wrap always",
39-
"test": "nyc --reporter=text mocha --recursive 'test/**/*.js' --reporter spec --timeout 5000 --ui bdd --exit",
39+
"test": "nyc --reporter=text mocha --recursive 'test/**/*.js' --reporter spec --timeout 5000 --ui bdd --exit --color true",
4040
"test:coverage": "nyc --reporter=lcov mocha -- --recursive 'test/**/*.js' --reporter spec --timeout 5000 --exit",
4141
"test:coveralls": "npm run test:coverage && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage",
4242
"test:watch": "npm run test -- -w ./lib",
@@ -79,7 +79,6 @@
7979
"textlint": "~11.7.6",
8080
"textlint-filter-rule-comments": "~1.2.2",
8181
"textlint-rule-common-misspellings": "~1.0.1",
82-
"textlint-rule-no-dead-link": "~4.7.0",
8382
"textlint-rule-terminology": "~2.1.4",
8483
"textlint-rule-write-good": "~1.6.2",
8584
"timekeeper": "2.2.0",

0 commit comments

Comments
 (0)