Skip to content

Commit

Permalink
Merge pull request #393 from telefonicaid/task/add_stripped_event
Browse files Browse the repository at this point in the history
include non flatten attributes into event
  • Loading branch information
fgalan committed Oct 17, 2019
2 parents 875c32d + 469e4e0 commit 9261bda
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Include stripped (non flatten) data into event (#377)
- Add: castType (PERSEO_CAST_TYPE) to enable NGSIv2 type based casting (default is to use JSON native types in values)
- Add authentication config env vars (#349)
- Add full support for pagination in APIs /rules and /vrules (#364)
Expand Down
35 changes: 34 additions & 1 deletion documentation/plain_rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ A rule that will check if the employee has been hired in the last half hour, cou
}
```

## JSON and Array fields
## JSON and Array fields in attributes

Some attributes like JSON and Array based, will generate a pseudo-attribute with the same name as the attribute and a
suffix "\_\_" followed by element name (for the case of JSON) or the ordinal (for the case of arrays), with the parsed
Expand Down Expand Up @@ -1047,3 +1047,36 @@ will send to core the "event"
"myArrayValue__1": "black"
}
```

Additionally all attributes are also included in non flatten format in the event into the `stripped` section:

```json
{
"noticeId": "799635b0-914f-11e6-836b-bf1691c99768",
"noticeTS": 1476368120971,
"id": "John Doe",
"type": "employee",
"isPattern": "false",
"subservice": "/",
"service": "unknownt",
"myJsonValue__color": "blue",
"myArrayValue__0": "green",
"myArrayValue__1": "black",
"stripped": [
{
"myJsonValue": {
"type": "myType1",
"value": {
"color": "blue"
}
}
},
{
"myArrayValue": {
"type": "myType2",
"value": ["green", "black"]
}
}
]
}
```
2 changes: 2 additions & 0 deletions lib/models/notices.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ function processCBNotice(service, subservice, ncr, ix) {
});

n = myutils.flattenMap('', n);
n.stripped = ncr.contextResponses[ix].contextElement.attributes;
} catch (ex) {
// SHOULD BE ex instanceof TypeError. Do not do anything else inside try
localError = new errors.InvalidNotice(JSON.stringify(ncr));
Expand Down Expand Up @@ -306,6 +307,7 @@ function processCBv2Notice(service, subservice, ncr, ix) {
});

n = myutils.flattenMap('', n);
n.stripped = ncr.data[ix];
} catch (ex) {
// Should never reach this catch
var localError = new errors.InvalidV2Notice(ex + ' (' + JSON.stringify(ncr) + ')');
Expand Down

0 comments on commit 9261bda

Please sign in to comment.