diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index d48b4e7711..fb3bd61689 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..04a6bd919e 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 */ @@ -2384,6 +2384,7 @@ static void deleteAttrInNotifyCer if (caP->name == targetAttr->name) { caP->skip = true; + caP->actionType = NGSI_MD_ACTIONTYPE_DELETE; } } } 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