Skip to content

Commit

Permalink
FIX PartialUpdate detection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
fgalan committed Nov 21, 2023
1 parent 2399c31 commit a14931c
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 30 deletions.
36 changes: 36 additions & 0 deletions src/lib/mongoBackend/MongoCommonUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4457,6 +4457,42 @@ unsigned int processContextElement
responseP->oe.fillOrAppend(SccInvalidModification, details, ", " + eP->id + " - " + attributeNotExistingList, ERROR_UNPROCESSABLE);
}

if (updateCoverageP != NULL)
{
// By default, everyghing gone ok. Next we are going to detect some partial/failure cases
*updateCoverageP = UC_FULL_SUCCESS;

if ((action == ActionTypeUpdate) || (action == ActionTypeDelete))
{
// Full failure if the number of the non-existing attributes are all the ones in the request
if (attributeNotExistingNumber == eP->attributeVector.size())
{
*updateCoverageP = UC_FULL_FAILURE;
}
// Partial failure/success if the number of the non-existing attributes is less than the ones in the request (else branch)
// and at least there was one existing attribute
else if (attributeNotExistingNumber > 0)
{
*updateCoverageP = UC_PARTIAL;
}
}

if (action == ActionTypeAppendStrict)
{
// Full failure if the number of the existing attributes are all the ones in the request
if (attributeAlreadyExistsNumber == eP->attributeVector.size())
{
*updateCoverageP = UC_FULL_FAILURE;
}
// Partial failure/success if the number of the existing attributes is less than the ones in the request (else branch)
// and at least there was one non-existing attribute
else if (attributeAlreadyExistsNumber > 0)
{
*updateCoverageP = UC_PARTIAL;
}
}
}

// Response in responseP
return notifSent;
}
Expand Down
7 changes: 4 additions & 3 deletions src/lib/mongoBackend/MongoCommonUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@
*/
typedef enum UpdateCoverage
{
FULL_SUCCESS = 0,
FULL_FAILURE = 1,
PARTIAL = 2
UC_NONE = 0,
UC_FULL_SUCCESS = 1,
UC_FULL_FAILURE = 2,
UC_PARTIAL = 3
} UpdateCoverage;


Expand Down
35 changes: 24 additions & 11 deletions src/lib/mongoBackend/mongoUpdateContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ HttpStatusCode mongoUpdateContext
else
{
/* Process each ContextElement */
bool atLeastOneSuccess = false;
bool atLeastOneFail = false;
UpdateCoverage updateCoverage = UC_NONE;
for (unsigned int ix = 0; ix < requestP->entityVector.size(); ++ix)
{
UpdateCoverage entityUpdateCoverage;
notifSent += processContextElement(requestP->entityVector[ix],
responseP,
requestP->updateActionType,
Expand All @@ -167,21 +167,34 @@ HttpStatusCode mongoUpdateContext
overrideMetadata,
notifSent,
apiVersion,
ngsiv2Flavour);

if (responseP->oe.code == SccNone)
{
atLeastOneSuccess = true;
}
else
ngsiv2Flavour,
&entityUpdateCoverage);
switch(updateCoverage)
{
atLeastOneFail = true;
case UC_NONE:
updateCoverage = entityUpdateCoverage;
break;
case UC_FULL_SUCCESS:
if (entityUpdateCoverage != UC_FULL_SUCCESS)
{
updateCoverage = UC_PARTIAL;
}
break;
case UC_FULL_FAILURE:
if (entityUpdateCoverage != UC_FULL_FAILURE)
{
updateCoverage = UC_PARTIAL;
}
break;
case UC_PARTIAL:
updateCoverage = UC_PARTIAL;
break;
}
}

// Only the PartialUpdate case (at least one success + at least one fail) needs to be "intercepted" here
// Other cases follow the usual response processing flow (whatever it is :)
if (atLeastOneSuccess && atLeastOneFail)
if (updateCoverage == UC_PARTIAL)
{
responseP->oe.reasonPhrase = ERROR_PARTIAL_UPDATE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Content-Length: 111

{
"description": "one or more of the attributes in the request already exist: E - [ A ]",
"error": "Unprocessable"
"error": "PartialUpdate"
}


Expand Down Expand Up @@ -188,7 +188,7 @@ Content-Length: 111

{
"description": "one or more of the attributes in the request already exist: E - [ B ]",
"error": "Unprocessable"
"error": "PartialUpdate"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ Content-Length: 145

{
"description": "one or more of the attributes in the request already exist: E1 - [ A ], E2 - [ A, B ], E3 - [ A, B, C ]",
"error": "Unprocessable"
"error": "PartialUpdate"
}


Expand Down Expand Up @@ -312,7 +312,7 @@ Content-Length: 136

{
"description": "one or more of the attributes in the request already exist: E1 - [ B ], E2 - [ B ], E3 - [ B ]",
"error": "Unprocessable"
"error": "PartialUpdate"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Content-Length: 113

{
"description": "one or more of the attributes in the request do not exist: E - [ B, C ]",
"error": "Unprocessable"
"error": "PartialUpdate"
}


Expand Down Expand Up @@ -182,7 +182,7 @@ Content-Length: 110

{
"description": "one or more of the attributes in the request do not exist: E - [ B ]",
"error": "Unprocessable"
"error": "PartialUpdate"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ Content-Length: 126

{
"description": "one or more of the attributes in the request do not exist: E1 - [ B, C ], E2 - [ C ]",
"error": "Unprocessable"
"error": "PartialUpdate"
}


Expand Down Expand Up @@ -295,7 +295,7 @@ Content-Length: 135

{
"description": "one or more of the attributes in the request do not exist: E1 - [ B ], E2 - [ B ], E3 - [ B ]",
"error": "Unprocessable"
"error": "PartialUpdate"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ Content-Length: 134

{
"description": "one or more of the attributes in the request do not exist: E1 - [ B, C ], E2 [entity itself]",
"error": "Unprocessable"
"error": "PartialUpdate"
}


Expand Down Expand Up @@ -269,7 +269,7 @@ Content-Length: 143

{
"description": "one or more of the attributes in the request do not exist: E1 - [ B ], E2 [entity itself], E3 - [ B ]",
"error": "Unprocessable"
"error": "PartialUpdate"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Content-Length: 113

{
"description": "one or more of the attributes in the request do not exist: E - [ B, C ]",
"error": "Unprocessable"
"error": "PartialUpdate"
}


Expand Down Expand Up @@ -178,7 +178,7 @@ Content-Length: 110

{
"description": "one or more of the attributes in the request do not exist: E - [ B ]",
"error": "Unprocessable"
"error": "PartialUpdate"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ Content-Length: 126

{
"description": "one or more of the attributes in the request do not exist: E1 - [ B, C ], E2 - [ C ]",
"error": "Unprocessable"
"error": "PartialUpdate"
}


Expand Down Expand Up @@ -297,7 +297,7 @@ Content-Length: 111

{
"description": "one or more of the attributes in the request do not exist: E1 - [ B ]",
"error": "Unprocessable"
"error": "PartialUpdate"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Content-Length: 134

{
"description": "one or more of the attributes in the request do not exist: E1 - [ B, C ], E2 [entity itself]",
"error": "Unprocessable"
"error": "PartialUpdate"
}


Expand Down Expand Up @@ -271,7 +271,7 @@ Content-Length: 131

{
"description": "one or more of the attributes in the request do not exist: E1 - [ B ], E2 [entity itself]",
"error": "Unprocessable"
"error": "PartialUpdate"
}


Expand Down

0 comments on commit a14931c

Please sign in to comment.