Skip to content

Commit

Permalink
Highly experimental feature for subscriptions: allowing a wildcard as…
Browse files Browse the repository at this point in the history
… value for entity type, to not filter on entity type
  • Loading branch information
kzangeli committed Sep 5, 2023
1 parent a31fc24 commit 6b1ec26
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Fixed issues:
* #280 - Giving errors for expiresAt in the past (for registrations and subscriptions)
* #280 - Fixed a bug in error detection of downloading errors in arrays of contexts, at lower nesting levels
* #280 - Better 501 handling of temporal operations
* #280 - Highly experimental feature for subscriptions: allowing a wildcard as value for entity type, to not filter on entity type
8 changes: 6 additions & 2 deletions src/lib/orionld/notifications/subCacheAlterationMatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,13 @@ static bool entityTypeMatch(CachedSubscription* subP, const char* entityType, in
{
for (int ix = 0; ix < eItems; ++ix)
{
EntityInfo* eiP = subP->entityIdInfos[ix];
EntityInfo* eiP = subP->entityIdInfos[ix];
const char* eType = eiP->entityType.c_str();

if (strcmp(entityType, eType) == 0)
return true;

if (strcmp(entityType, eiP->entityType.c_str()) == 0)
if ((eType[0] == '*') && (eType[1] == 0))
return true;
}

Expand Down
9 changes: 7 additions & 2 deletions src/lib/orionld/payloadCheck/pcheckEntityInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,13 @@ bool pcheckEntityInfo(KjNode* entityInfoP, bool typeMandatory, bool idMandatory,
// Expand, unless already expanded
// If a ':' is found inside the first 10 chars, the value is assumed to be expanded ...
//
if (orionldContextItemAlreadyExpanded(entityItemP->value.s) == false)
entityItemP->value.s = orionldContextItemExpand(orionldState.contextP, entityItemP->value.s, true, NULL); // entity type
// No expansion if the type is '*' - meaning "ALL ENTITY TYPES"
//
if ((entityItemP->value.s[0] != '*') || (entityItemP->value.s[1] != 0))
{
if (orionldContextItemAlreadyExpanded(entityItemP->value.s) == false)
entityItemP->value.s = orionldContextItemExpand(orionldState.contextP, entityItemP->value.s, true, NULL); // entity type
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Copyright 2023 FIWARE Foundation e.V.
#
# This file is part of Orion-LD Context Broker.
#
# Orion-LD 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-LD 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-LD Context Broker. If not, see http://www.gnu.org/licenses/.
#
# For those usages not covered by this license please contact with
# orionld at fiware dot org

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

--NAME--
Subscription with type: "*", and test of notifications

--SHELL-INIT--
dbInit CB
orionldStart CB -experimental
accumulatorStart --pretty-print

--SHELL--

#
# 01. Create a subscription on EVERYTHING
# 02. Create an entity, any
# 03. See the notification in the accumulator
#


echo "01. Create a subscription on EVERYTHING"
echo "======================================="
payload='{
"id": "urn:S1",
"description": "Notify ALL",
"type": "Subscription",
"entities": [
{
"type": "*"
}
],
"notification": {
"endpoint": {
"uri": "http://localhost:'$LISTENER_PORT'/notify"
}
}
}'
orionCurl --url /ngsi-ld/v1/subscriptions --payload "$payload"
echo
echo


echo "02. Create an entity, any"
echo "========================="
payload='{
"id": "urn:ngsi-ld:Blower:bd01",
"type": "BlowerDevice",
"airflow": 127
}'
orionCurl --url /ngsi-ld/v1/entities --payload "$payload"
echo
echo


echo "03. See the notification in the accumulator"
echo "==========================================="
accumulatorDump
echo
echo


--REGEXPECT--
01. Create a subscription on EVERYTHING
=======================================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/subscriptions/urn:S1



02. Create an entity, any
=========================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/entities/urn:ngsi-ld:Blower:bd01



03. See the notification in the accumulator
===========================================
POST http://REGEX(.*)/notify?subscriptionId=urn:S1
Content-Length: 264
User-Agent: REGEX(.*)
Host: REGEX(.*)
Accept: application/json
Content-Type: application/json
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)
Ngsild-Attribute-Format: Normalized

{
"data": [
{
"airflow": {
"type": "Property",
"value": 127
},
"id": "urn:ngsi-ld:Blower:bd01",
"type": "BlowerDevice"
}
],
"id": "urn:ngsi-ld:Notification:REGEX(.*)",
"notifiedAt": "REGEX(.*)",
"subscriptionId": "urn:S1",
"type": "Notification"
}
=======================================


--TEARDOWN--
brokerStop CB
accumulatorStop
dbDrop CB
dbDrop CB openiot

0 comments on commit 6b1ec26

Please sign in to comment.