Skip to content

Commit 09048b9

Browse files
authored
Merge pull request telefonicaid#839 from jason-fox/feature/add-v2-metadata
Add NGSIv2 metadata support to attributeAlias plugin
2 parents a22bb62 + 7ba9d12 commit 09048b9

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

CHANGES_NEXT_RELEASE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Refresh Documentation
22
Add NGSIv2 metadata support to device provisioned attributes
33
Fix: Error message when sending measures with unknown/undefined attribute
4-
Add Null check within executeWithSecurity() to avoid crash (#829)
4+
Add Null check within executeWithSecurity() to avoid crash (#829)
5+
Add NGSIv2 metadata support to attributeAlias plugin.

lib/plugins/attributeAlias.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ var config = require('../commonConfig'),
3737

3838
function extractSingleMapping(previous, current) {
3939
/* jshint camelcase: false */
40-
4140
previous.direct[current.object_id] = current.name;
4241
previous.types[current.object_id] = current.type;
42+
previous.metadata[current.object_id] = current.metadata;
4343
previous.inverse[current.name] = current.object_id; // collision using multientity
4444
return previous;
4545
}
@@ -51,7 +51,7 @@ function extractSingleMapping(previous, current) {
5151
* @return {{direct: {}, inverse: {}}} Object containing the direct and reverse name mappings.
5252
*/
5353
function extractAllMappings(typeInformation) {
54-
var mappings = { direct: {}, inverse: {}, types: {}};
54+
var mappings = { direct: {}, inverse: {}, types: {}, metadata: {}};
5555

5656
if (typeInformation.active) {
5757
mappings = typeInformation.active.reduce(extractSingleMapping, mappings);
@@ -64,7 +64,6 @@ function extractAllMappings(typeInformation) {
6464
if (typeInformation.commands) {
6565
mappings = typeInformation.commands.reduce(extractSingleMapping, mappings);
6666
}
67-
6867
return mappings;
6968
}
7069

@@ -81,10 +80,10 @@ function applyAlias(mappings) {
8180
/*jshint camelcase: false */
8281
attribute.object_id = attribute.name; // inverse not usefull due to collision
8382
}
83+
attribute.metadata = mappings.metadata[attribute.name];
8484
attribute.type = mappings.types[attribute.name];
8585
attribute.name = mappings.direct[attribute.name];
8686
}
87-
8887
return attribute;
8988
};
9089
}
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
{
22
"temperature": {
3-
"type": "centigrades",
4-
"value": "52"
3+
"type":"Number",
4+
"value":52,
5+
"metadata": {
6+
"type":"Property",
7+
"value":"CEL"
8+
}
59
},
610
"pressure": {
7-
"type": "Hgmm",
8-
"value": "20071103T131805"
11+
"type":"Number",
12+
"value":20071103,
13+
"metadata": {
14+
"type":"Property",
15+
"value":"Hgmm"
16+
}
917
}
1018
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"luminance": {
3-
"type": "lumens",
4-
"value": "9"
3+
"type": "Number",
4+
"value": 9,
5+
"metadata": {
6+
"type":"Property",
7+
"value":"CAL"
8+
}
59
}
610
}

test/unit/ngsiv2/plugins/alias-plugin_test.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,25 @@ var iotAgentLib = require('../../../../lib/fiware-iotagent-lib'),
5050
{
5151
object_id: 't',
5252
name: 'temperature',
53-
type: 'centigrades'
53+
type: 'Number',
54+
metadata: { type: 'Property', value:'CEL'}
55+
5456
}
5557
],
5658
active: [
5759
{
5860
object_id: 'p',
5961
name: 'pressure',
60-
type: 'Hgmm'
62+
type: 'Number',
63+
metadata: { type: 'Property', value:'Hgmm'}
64+
6165
},
6266
{
6367
object_id: 'l',
6468
name: 'luminance',
65-
type: 'lumens'
69+
type: 'Number',
70+
metadata: { type: 'Property', value:'CAL'}
71+
6672
},
6773
{
6874
object_id: 'ut',

0 commit comments

Comments
 (0)