From 3efed0a5377c644b7d62dfe78f39713f527781c8 Mon Sep 17 00:00:00 2001 From: Anjali-NEC Date: Fri, 5 Aug 2022 16:22:50 +0000 Subject: [PATCH 1/4] Fix issue #2591 --- CHANGES_NEXT_RELEASE | 1 + src/lib/mongoBackend/MongoCommonUpdate.cpp | 12 +- .../actionType_metadata_delete_support.test | 188 ++++++++++++++++++ 3 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 test/functionalTest/cases/2591_actionType_metadata_delete_support/actionType_metadata_delete_support.test diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 821fe17459..fc67cc1a2b 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,3 +1,4 @@ +- Fix: actionType metadata: delete support (#2591) - Add: json field in httpCustom and mqttCustom subscriptions (#2560) - Add: ${service}, ${servicePath} and ${authToken} macros in custom notifications (#4159) - Fix: conditions.alterationTypes not working properly when conditions.attributes is used in entityUpdate case (#1494, reopened) diff --git a/src/lib/mongoBackend/MongoCommonUpdate.cpp b/src/lib/mongoBackend/MongoCommonUpdate.cpp index a3a2203e35..fe80c98dd7 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.cpp +++ b/src/lib/mongoBackend/MongoCommonUpdate.cpp @@ -1832,7 +1832,7 @@ static bool processOnChangeConditionForUpdateContext { for (unsigned int jx = 0; jx < attrL.size(); jx++) { - if (caP->name == attrL[jx] && !caP->skip) + if (caP->name == attrL[jx]) { /* Note we use cloneCompound=true in the ContextAttribute constructor. This is due to * cer.entity destructor does release() on the attrs vector */ @@ -2375,7 +2375,10 @@ static void updateAttrInNotifyCer static void deleteAttrInNotifyCer ( ContextElementResponse* notifyCerP, - ContextAttribute* targetAttr + ContextAttribute* targetAttr, + bool useDefaultType, + const std::string& actionType, + const bool& overrideMetadata ) { for (unsigned int ix = 0; ix < notifyCerP->entity.attributeVector.size(); ix++) @@ -2384,6 +2387,7 @@ static void deleteAttrInNotifyCer if (caP->name == targetAttr->name) { caP->skip = true; + caP->actionType = NGSI_MD_ACTIONTYPE_DELETE; } } } @@ -2561,12 +2565,13 @@ static bool deleteContextAttributeItem bool* entityModified, orion::BSONDate* dateExpiration, ApiVersion apiVersion, + const bool& overrideMetadata, OrionError* oe ) { if (deleteAttribute(attrs, toUnset, attrNamesRemove, targetAttr)) { - deleteAttrInNotifyCer(notifyCerP, targetAttr); + deleteAttrInNotifyCer(notifyCerP, targetAttr, apiVersion == V2, NGSI_MD_ACTIONTYPE_DELETE, overrideMetadata); *entityModified = true; /* Check aspects related with location */ @@ -2745,6 +2750,7 @@ static bool processContextAttributeVector &entityModified, dateExpiration, apiVersion, + overrideMetadata, oe)) { return false; diff --git a/test/functionalTest/cases/2591_actionType_metadata_delete_support/actionType_metadata_delete_support.test b/test/functionalTest/cases/2591_actionType_metadata_delete_support/actionType_metadata_delete_support.test new file mode 100644 index 0000000000..9d51b214a7 --- /dev/null +++ b/test/functionalTest/cases/2591_actionType_metadata_delete_support/actionType_metadata_delete_support.test @@ -0,0 +1,188 @@ +# Copyright 2022 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-- +actionType_metadata_delete_support + +--SHELL-INIT-- +dbInit CB +brokerStart CB +accumulatorStart --pretty-print + +--SHELL-- + +# +# 01. Create entity E1 with attributes A:1, B:2, C:3 +# 02. Subscribe to E.* for A, B and C; triggered by B, C +# 03. Delete attribute B +# 04. Dump and reset: see notification with actionType=delete for B +# + + +echo "01. Create entity E1 with attributes A:1, B:2, C:3" +echo "==================================================" +payload='{ + "type": "T", + "id": "E1", + "A": { + "type": "Number", + "value": 1 + }, + "B": { + "type": "Number", + "value": 2 + }, + "C": { + "type": "Number", + "value": 3 + } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + + +echo "02. Subscribe to E.* for A, B and C; triggered by B, C" +echo "======================================================" +payload='{ + "subject": { + "entities": [ + { + "idPattern": "E.*", + "type": "T" + } + ], + "condition": { + "attrs": [ "B", "C" ] + } + }, + "notification": { + "http": { + "url": "http://localhost:'$LISTENER_PORT'/notify" + }, + "attrs": [ "A", "B", "C" ], + "metadata": [ "previousValue", "actionType" ] + } +}' +orionCurl --url /v2/subscriptions --payload "$payload" +echo +echo + +SUB_ID=$(echo "$_responseHeaders" | grep Location | awk -F/ '{ print $4 }' | tr -d "\r\n") + + + +echo "03. Delete attribute B" +echo "======================" +orionCurl --url /v2/entities/E1/attrs/B -X DELETE +echo +echo + + + +echo "04. Dump and reset: see notification with actionType=delete for B" +echo "=================================================================" +accumulatorDump +accumulatorReset +echo +echo + + + +--REGEXPECT-- +01. Create entity E1 with attributes A:1, B:2, C:3 +================================================== +HTTP/1.1 201 Created +Content-Length: 0 +Location: /v2/entities/E1?type=T +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + + + +02. Subscribe to E.* for A, B and C; triggered by B, C +====================================================== +HTTP/1.1 201 Created +Content-Length: 0 +Location: /v2/subscriptions/REGEX([0-9a-f]{24}) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + + + +03. Delete attribute B +====================== +HTTP/1.1 204 No Content +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + + + +04. Dump and reset: see notification with actionType=delete for B +================================================================= +POST http://localhost:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: 260 +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": 1 + }, + "B": { + "metadata": { + "actionType": { + "type": "Text", + "value": "delete" + } + }, + "type": "Number", + "value": 2 + }, + "C": { + "metadata": {}, + "type": "Number", + "value": 3 + }, + "id": "E1", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= + + +--TEARDOWN-- +brokerStop CB +accumulatorStop $LISTENER_PORT +dbDrop CB From c5392556585a013d6aea61c8df8cec0cb1779ba4 Mon Sep 17 00:00:00 2001 From: Anjali-NEC Date: Mon, 8 Aug 2022 11:07:58 +0000 Subject: [PATCH 2/4] Updated src/lib/mongoBackend/MongoCommonUpdate.cpp --- src/lib/mongoBackend/MongoCommonUpdate.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lib/mongoBackend/MongoCommonUpdate.cpp b/src/lib/mongoBackend/MongoCommonUpdate.cpp index fe80c98dd7..cc9f7a522e 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.cpp +++ b/src/lib/mongoBackend/MongoCommonUpdate.cpp @@ -2376,9 +2376,7 @@ static void deleteAttrInNotifyCer ( ContextElementResponse* notifyCerP, ContextAttribute* targetAttr, - bool useDefaultType, - const std::string& actionType, - const bool& overrideMetadata + const std::string& actionType ) { for (unsigned int ix = 0; ix < notifyCerP->entity.attributeVector.size(); ix++) @@ -2571,7 +2569,7 @@ static bool deleteContextAttributeItem { if (deleteAttribute(attrs, toUnset, attrNamesRemove, targetAttr)) { - deleteAttrInNotifyCer(notifyCerP, targetAttr, apiVersion == V2, NGSI_MD_ACTIONTYPE_DELETE, overrideMetadata); + deleteAttrInNotifyCer(notifyCerP, targetAttr, NGSI_MD_ACTIONTYPE_DELETE); *entityModified = true; /* Check aspects related with location */ From 8d8174d4a1d7a62451f3d480c9032b9f21569831 Mon Sep 17 00:00:00 2001 From: Anjali Pathak Date: Mon, 15 Aug 2022 23:43:59 +0530 Subject: [PATCH 3/4] Update MongoCommonUpdate.cpp --- src/lib/mongoBackend/MongoCommonUpdate.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/mongoBackend/MongoCommonUpdate.cpp b/src/lib/mongoBackend/MongoCommonUpdate.cpp index cc9f7a522e..b383e6a978 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.cpp +++ b/src/lib/mongoBackend/MongoCommonUpdate.cpp @@ -2375,8 +2375,7 @@ static void updateAttrInNotifyCer static void deleteAttrInNotifyCer ( ContextElementResponse* notifyCerP, - ContextAttribute* targetAttr, - const std::string& actionType + ContextAttribute* targetAttr ) { for (unsigned int ix = 0; ix < notifyCerP->entity.attributeVector.size(); ix++) @@ -2569,7 +2568,7 @@ static bool deleteContextAttributeItem { if (deleteAttribute(attrs, toUnset, attrNamesRemove, targetAttr)) { - deleteAttrInNotifyCer(notifyCerP, targetAttr, NGSI_MD_ACTIONTYPE_DELETE); + deleteAttrInNotifyCer(notifyCerP, targetAttr); *entityModified = true; /* Check aspects related with location */ From 7a65459e06212144bc3932eca95122f14ce9f3f9 Mon Sep 17 00:00:00 2001 From: Anjali Pathak Date: Sat, 20 Aug 2022 21:25:56 +0530 Subject: [PATCH 4/4] Update MongoCommonUpdate.cpp --- src/lib/mongoBackend/MongoCommonUpdate.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib/mongoBackend/MongoCommonUpdate.cpp b/src/lib/mongoBackend/MongoCommonUpdate.cpp index b383e6a978..04a6bd919e 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.cpp +++ b/src/lib/mongoBackend/MongoCommonUpdate.cpp @@ -2562,7 +2562,6 @@ static bool deleteContextAttributeItem bool* entityModified, orion::BSONDate* dateExpiration, ApiVersion apiVersion, - const bool& overrideMetadata, OrionError* oe ) { @@ -2747,7 +2746,6 @@ static bool processContextAttributeVector &entityModified, dateExpiration, apiVersion, - overrideMetadata, oe)) { return false;