Skip to content

Commit

Permalink
FIX speciality EntityChange altType into different subtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
fgalan committed Sep 11, 2024
1 parent 651d740 commit 0b4627c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 16 deletions.
17 changes: 15 additions & 2 deletions src/lib/apiTypesV2/Subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ngsiv2::SubAltType parseAlterationType(const std::string& altType)
{
if (altType == "entityChange")
{
return ngsiv2::SubAltType::EntityChange;
return ngsiv2::SubAltType::EntityChangeBothValueAndMetadata;
}
else if (altType == "entityUpdate")
{
Expand All @@ -64,13 +64,26 @@ ngsiv2::SubAltType parseAlterationType(const std::string& altType)



/* ****************************************************************************
*
* isChangeAltType -
*/
bool isChangeAltType(ngsiv2::SubAltType altType)
{
return (altType == ngsiv2::SubAltType::EntityChangeBothValueAndMetadata) ||
(altType == ngsiv2::SubAltType::EntityChangeOnlyMetadata) ||
(altType == ngsiv2::SubAltType::EntityChangeOnlyValue);
}



/* ****************************************************************************
*
* subAltType2string -
*/
std::string subAltType2string(ngsiv2::SubAltType altType)
{
if (altType == ngsiv2::SubAltType::EntityChange)
if (isChangeAltType(altType))
{
return "entityChange";
}
Expand Down
12 changes: 11 additions & 1 deletion src/lib/apiTypesV2/Subscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ typedef enum NotificationType
*/
typedef enum SubAltType
{
EntityChange,
EntityChangeBothValueAndMetadata, // this is the reference one used by parsing/rendering logic
EntityChangeOnlyValue,
EntityChangeOnlyMetadata,
EntityUpdate,
EntityCreate,
EntityDelete,
Expand Down Expand Up @@ -192,4 +194,12 @@ extern std::string subAltType2string(ngsiv2::SubAltType altType);



/* ****************************************************************************
*
* isChangeAltType -
*/
extern bool isChangeAltType(ngsiv2::SubAltType altType);



#endif // SRC_LIB_APITYPESV2_SUBSCRIPTION_H_
8 changes: 4 additions & 4 deletions src/lib/cache/subCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ static bool matchAltType(CachedSubscription* cSubP, ngsiv2::SubAltType targetAlt
// If subAltTypeV size == 0 default alteration types are update with change and create
if (cSubP->subAltTypeV.size() == 0)
{
if ((targetAltType == ngsiv2::SubAltType::EntityChange) || (targetAltType == ngsiv2::SubAltType::EntityCreate))
if ((isChangeAltType(targetAltType)) || (targetAltType == ngsiv2::SubAltType::EntityCreate))
{
return true;
}
Expand All @@ -417,9 +417,9 @@ static bool matchAltType(CachedSubscription* cSubP, ngsiv2::SubAltType targetAlt
ngsiv2::SubAltType altType = cSubP->subAltTypeV[ix];

// EntityUpdate is special, it is a "sub-type" of EntityChange
if (targetAltType == ngsiv2::SubAltType::EntityChange)
if (isChangeAltType(targetAltType))
{
if ((altType == ngsiv2::SubAltType::EntityUpdate) || (altType == ngsiv2::SubAltType::EntityChange))
if ((altType == ngsiv2::SubAltType::EntityUpdate) || (isChangeAltType(altType)))
{
return true;
}
Expand Down Expand Up @@ -507,7 +507,7 @@ static bool subMatch
return false;
}
}
else if ((targetAltType == ngsiv2::EntityChange) || (targetAltType == ngsiv2::EntityCreate))
else if ((isChangeAltType(targetAltType)) || (targetAltType == ngsiv2::EntityCreate))
{
if (!attributeMatch(cSubP, attrsWithModifiedValue) &&
!(cSubP->notifyOnMetadataChange && attributeMatch(cSubP, attrsWithModifiedMd)))
Expand Down
37 changes: 28 additions & 9 deletions src/lib/mongoBackend/MongoCommonUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ static bool matchAltType(orion::BSONObj sub, ngsiv2::SubAltType targetAltType)
// change and create. Maybe this could be check at MongoDB query stage, but seems be more complex
if (altTypeStrings.size() == 0)
{
if ((targetAltType == ngsiv2::SubAltType::EntityChange) || (targetAltType == ngsiv2::SubAltType::EntityCreate))
if ((isChangeAltType(targetAltType)) || (targetAltType == ngsiv2::SubAltType::EntityCreate))
{
return true;
}
Expand All @@ -1513,9 +1513,9 @@ static bool matchAltType(orion::BSONObj sub, ngsiv2::SubAltType targetAltType)
else
{
// EntityUpdate is special, it is a "sub-type" of EntityChange
if (targetAltType == ngsiv2::SubAltType::EntityChange)
if (isChangeAltType(targetAltType))
{
if ((altType == ngsiv2::SubAltType::EntityUpdate) || (altType == ngsiv2::SubAltType::EntityChange))
if ((altType == ngsiv2::SubAltType::EntityUpdate) || (isChangeAltType(targetAltType)))
{
return true;
}
Expand Down Expand Up @@ -1659,11 +1659,13 @@ static bool addTriggeredSubscriptions_noCache
continue;
}
}
else if ((targetAltType == ngsiv2::EntityChange) || (targetAltType == ngsiv2::EntityCreate))
else if ((isChangeAltType(targetAltType)) || (targetAltType == ngsiv2::EntityCreate))
{
// Skip if: 1) there is no change in the *value* of attributes listed in conditions.attrs and 2) there is no change
// in the *metadata* of the attributes listed in conditions.attrs (the 2) only if notifyOnMetadtaChange is true)
if (!condValueAttrMatch(sub, attrsWithModifiedValue) && !(notifyOnMetadataChange && condValueAttrMatch(sub, attrsWithModifiedMd)))
bool b1 = condValueAttrMatch(sub, attrsWithModifiedValue);
bool b2 = condValueAttrMatch(sub, attrsWithModifiedMd);
if (!b1 && !(notifyOnMetadataChange && b2))
{
continue;
}
Expand Down Expand Up @@ -2766,24 +2768,41 @@ static bool processContextAttributeVector
{
attrsWithModifiedValue.push_back(ca->name);
attrsWithModifiedMd.push_back(ca->name);
targetAltType = ngsiv2::SubAltType::EntityChangeBothValueAndMetadata;
}
else if (changeType == CHANGE_ONLY_VALUE)
{
attrsWithModifiedValue.push_back(ca->name);
if ((targetAltType == ngsiv2::SubAltType::EntityChangeBothValueAndMetadata) || (targetAltType == ngsiv2::SubAltType::EntityChangeOnlyMetadata))
{
targetAltType = ngsiv2::SubAltType::EntityChangeBothValueAndMetadata;
}
else
{
targetAltType = ngsiv2::SubAltType::EntityChangeOnlyValue;
}
}
else if (changeType == CHANGE_ONLY_MD)
{
attrsWithModifiedMd.push_back(ca->name);
if ((targetAltType == ngsiv2::SubAltType::EntityChangeBothValueAndMetadata) || (targetAltType == ngsiv2::SubAltType::EntityChangeOnlyValue))
{
targetAltType = ngsiv2::SubAltType::EntityChangeBothValueAndMetadata;
}
else
{
targetAltType = ngsiv2::SubAltType::EntityChangeOnlyMetadata;
}
}

attributes.push_back(ca->name);
attributes.push_back(ca->name);

/* If actual update then targetAltType changes from EntityUpdate (the value used to initialize
* the variable) to EntityChange */
if (changeType != NO_CHANGE)
/*if (changeType != NO_CHANGE)
{
targetAltType = ngsiv2::SubAltType::EntityChange;
}
}*/
}

/* Add triggered subscriptions */
Expand Down Expand Up @@ -3948,7 +3967,7 @@ static unsigned int updateEntity
* previous addTriggeredSubscriptions() invocations. Before that, we add
* builtin attributes and metadata (both NGSIv1 and NGSIv2 as this is
* for notifications and NGSIv2 builtins can be used in NGSIv1 notifications) */
addBuiltins(notifyCerP, subAltType2string(ngsiv2::SubAltType::EntityChange));
addBuiltins(notifyCerP, subAltType2string(ngsiv2::SubAltType::EntityChangeBothValueAndMetadata));
unsigned int notifSent = processSubscriptions(subsToNotify,
notifyCerP,
tenant,
Expand Down

0 comments on commit 0b4627c

Please sign in to comment.