Skip to content

Commit

Permalink
Merge pull request telefonicaid#4471 from telefonicaid/hardening/only…
Browse files Browse the repository at this point in the history
…changedattrs_with_alterationtype

FIX add test combining onlyChangedAttrs true and alterationType/dateCreated/dateModified
  • Loading branch information
mapedraza authored Jan 16, 2024
2 parents f8e2daa + 3ac33cb commit d05d04a
Show file tree
Hide file tree
Showing 5 changed files with 371 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Add: log deprecation traces for usage of attrsFormat legacy in subscriptions
- Add: deprecatedFeatures counters block in GET /v2/statistics
- Fix: do not show dateExpires built-in attribute in GET /v2/types and GET /v2/types/{type} operations (#4451)
- Fix: builtin attributes alterationType, dateCreated and dateModified included in notifications even when onlyChangedAttrs is true
- Fix: correctly detect JSON attribute and metadata value changes in subscription triggering logic (#4211, #4434, #643)
- Fix: update forwarding was not working when entity type is not included in the request (#4460)
- Fix: DateTime and geo:json types were not supported in custom notifications using ngsi patching (#4435)
Expand Down
9 changes: 8 additions & 1 deletion doc/manuals/orion-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ rendered by Orion to provide extra information. From a representation point of v
are just like regular attributes, with name, value and type.

Builtin attributes are not rendered by default. In order to render a specific attribute, add its
name to the `attrs` parameter in URLs (or payload field in POST /v2/op/query operation) or
name to the `attrs` parameter in URLs (or payload field in `POST /v2/op/query` operation) or
subscription (`attrs` sub-field within `notification`).

The list of builtin attributes is as follows:
Expand All @@ -683,6 +683,13 @@ the subscriptions based in alteration type features (see [Subscription based in
Like regular attributes, they can be used in `q` filters and in `orderBy` (except `alterationType`).
However, they cannot be used in resource URLs.

The following builtin attributes are included in notifications (if added to `attrs` sub-field within `notification`) even
when `onlyChangedAttrs` is set to `true`:

* `alterationType`
* `dateCreated`
* `dateModified`

## Special Metadata Types

Generally speaking, user-defined metadata types are informative; they are processed by Orion
Expand Down
5 changes: 3 additions & 2 deletions src/lib/mongoBackend/MongoGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2296,9 +2296,10 @@ static void getCommonAttributes
{
for (unsigned int avOc = 0; avOc < sVector.size(); ++avOc)
{
if (fVector[cavOc] == sVector[avOc])
// some builtin attributes are always include (even when onlyChangedAttrs is true)
if ((sVector[avOc] == ALTERATION_TYPE) || (sVector[avOc] == DATE_CREATED) || (sVector[avOc] == DATE_MODIFIED) || (fVector[cavOc] == sVector[avOc]))
{
resultVector.push_back(fVector[cavOc]);
resultVector.push_back(sVector[avOc]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Copyright 2019 Telefonica Investigacion y Desarrollo, S.A.U
#
# This file is part of Orion Context Broker.
#
# Orion Context Broker is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Orion Context Broker is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/.
#
# For those usages not covered by this license please contact with
# iot_support at tid dot es

# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh

--NAME--
Notify only attributes that change get with alterationType

--SHELL-INIT--
dbInit CB
brokerStart CB
accumulatorStart --pretty-print


--SHELL--

#
# 01. Create entity E-A,B,C
# 02. Create a subscription with onlyChangedAttrs: true and alterationType
# 03. Update E-A
# 04. Dump notification get E-A/alterationType
#


echo '01. Create entity E-A,B,C'
echo '========================='
payload='{
"id": "E",
"type": "T",
"A": {
"value": 1,
"type": "Number"
},
"B": {
"value": 1,
"type": "Number"
},
"C": {
"value": 1,
"type": "Number"
}
}'
orionCurl --url /v2/entities --payload "$payload"
echo
echo


echo '02. Create a subscription with onlyChangedAttrs: true and alterationType'
echo '========================================================================'
payload='{
"subject": {
"entities": [
{
"id": "E",
"type": "T"
}
]
},
"notification": {
"http": {
"url": "http://localhost:'$LISTENER_PORT'/notify"
},
"attrs": [
"A","B","C", "alterationType"
],
"onlyChangedAttrs": true
}
}'
orionCurl --url /v2/subscriptions --payload "$payload"
echo
echo


echo '03. Update E-A'
echo '=============='
payload='{
"A": {
"value": 2,
"type": "Number"
}
}'
orionCurl --url /v2/entities/E/attrs -X PATCH --payload "$payload"
echo
echo


echo '04. Dump notification get E-A/alterationType'
echo '============================================'
accumulatorDump
echo
echo


--REGEXPECT--
01. Create entity E-A,B,C
=========================
HTTP/1.1 201 Created
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Location: /v2/entities/E?type=T
Content-Length: 0



02. Create a subscription with onlyChangedAttrs: true and alterationType
========================================================================
HTTP/1.1 201 Created
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Location: /v2/subscriptions/REGEX([0-9a-f]{24})
Content-Length: 0



03. Update E-A
==============
HTTP/1.1 204 No Content
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})



04. Dump notification get E-A/alterationType
============================================
POST http://localhost:REGEX(\d+)/notify
Fiware-Servicepath: /
Content-Length: 192
User-Agent: orion/REGEX(\d+\.\d+\.\d+.*)
Ngsiv2-Attrsformat: normalized
Host: localhost:REGEX(\d+)
Accept: application/json
Content-Type: application/json; charset=utf-8
Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1

{
"data": [
{
"A": {
"metadata": {},
"type": "Number",
"value": 2
},
"alterationType": {
"metadata": {},
"type": "Text",
"value": "entityChange"
},
"id": "E",
"type": "T"
}
],
"subscriptionId": "REGEX([0-9a-f]{24})"
}
=======================================


--TEARDOWN--
brokerStop CB
dbDrop CB
accumulatorStop
Loading

0 comments on commit d05d04a

Please sign in to comment.