Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix using limit=0 and details=on to get only the count of elements (prelanding) #4104

Merged
merged 34 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
da0256c
Fix issue #1492
Anjali-NEC Nov 9, 2021
28d9007
Updated
Anjali-NEC Nov 10, 2021
aade17a
Merge branch 'master' into issue1492
Anjali-NEC Nov 11, 2021
9dd6330
Updated
Anjali-NEC Nov 11, 2021
bd8fd20
Merge branch 'issue1492' of https://github.com/Anjali-NEC/fiware-orio…
Anjali-NEC Nov 11, 2021
f4d0cbd
Added test file
Anjali-NEC Nov 11, 2021
8879a39
Updated as per comment
Anjali-NEC Nov 12, 2021
8877986
Merge branch 'master' into issue1492
Anjali-NEC Nov 18, 2021
cf68c96
Updated code as per comment
Anjali-NEC Nov 18, 2021
a5e89be
Merge branch 'issue1492' of https://github.com/Anjali-NEC/fiware-orio…
Anjali-NEC Nov 18, 2021
7d6160f
Update getEntities.cpp
Anjali-NEC Nov 18, 2021
397baaf
Merge remote-tracking branch 'upstream/master' into issue1492
Anjali-NEC Nov 30, 2021
64cf793
Updated code and test case
Anjali-NEC Nov 30, 2021
38b7bf4
Merge branch 'issue1492' of https://github.com/Anjali-NEC/fiware-orio…
Anjali-NEC Nov 30, 2021
8a03332
Updated code
Anjali-NEC Nov 30, 2021
18c7f89
Merge branch 'master' into issue1492
Anjali-NEC Jan 24, 2022
67ea727
Updated as per comment
Anjali-NEC Jan 24, 2022
6fe85e9
Merge branch 'issue1492' of https://github.com/Anjali-NEC/fiware-orio…
Anjali-NEC Jan 24, 2022
4caae7d
Merge branch 'master' into issue1492
Anjali-NEC Mar 4, 2022
9a54cb8
Merge remote-tracking branch 'upstream/master' into issue1492
invalid-email-address Mar 4, 2022
397ae9e
Modify code as per comment
invalid-email-address Mar 4, 2022
d978465
Merge branch 'issue1492' of https://github.com/Anjali-NEC/fiware-orio…
invalid-email-address Mar 4, 2022
ff2b225
Updated code
invalid-email-address Mar 7, 2022
30d7c01
Merge branch 'master' into issue1492
Anjali-NEC Mar 21, 2022
e779cb2
Merge branch 'master' into issue1492
Anjali-NEC Mar 25, 2022
c20bd31
Merge pull request #3994 from Anjali-NEC/issue1492
fgalan Apr 27, 2022
3d95610
Merge branch 'master' into issue1492-prelanding
fgalan Apr 27, 2022
52efc9f
Merge branch 'master' into issue1492-prelanding
fgalan Apr 27, 2022
ae956ec
FIX check spectations
fgalan Apr 27, 2022
71f57e5
Merge branch 'master' into issue1492-prelanding
fgalan Apr 28, 2022
71379a3
FIX whitespacing
fgalan Apr 28, 2022
6d3d83c
FIX simplifications
fgalan Apr 28, 2022
869a8e2
Merge branch 'master' into issue1492-prelanding
fgalan Apr 28, 2022
7ec4cb7
FIX simplification
fgalan Apr 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Fix: allow limit=0 in all paginated operations in the NGSIv2 API (entities, entity types, subscriptions and registrations) (#1492)
- Add: conditions.alterationTypes subscription fuctionality (#1494)
- Add: alterationType built-in atrribute in notifications (#1494)
- Fix: covered notifications in subscriptions (#3693)
Expand Down
3 changes: 2 additions & 1 deletion src/lib/mongoBackend/MongoGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,8 @@ bool entitiesQuery
int errType;
std::string nextErr;

while (cursor.next(&r, &errType, &nextErr))
/* Note limit != 0 will cause skipping the while loop in case request didn't actually ask for any result */
while ((limit != 0) && (cursor.next(&r, &errType, &nextErr)))
{
alarmMgr.dbErrorReset();

Expand Down
3 changes: 2 additions & 1 deletion src/lib/mongoBackend/mongoGetSubscriptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,11 @@ void mongoListSubscriptions
TIME_STAT_MONGO_READ_WAIT_STOP();

/* Process query result */
/* Note limit != 0 will cause skipping the while loop in case request didn't actually ask for any result */
unsigned int docs = 0;

orion::BSONObj r;
while (cursor.next(&r))
while ((limit != 0) && (cursor.next(&r)))
{
docs++;
LM_T(LmtMongo, ("retrieved document [%d]: '%s'", docs, r.toString().c_str()));
Expand Down
4 changes: 3 additions & 1 deletion src/lib/mongoBackend/mongoQueryTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,8 @@ HttpStatusCode mongoEntityTypes
unsigned int docs = 0;
while (cursor.next(&resultItem))
{
if ((docs < offset) || (docs > offset + limit - 1))
// Note limit == 0 has to be checked individually given doc > offset + limit - 1 doesn't work if offset == 0 with unsigned int */
if ((limit == 0) || (docs < offset) || (docs > offset + limit - 1))
{
docs++;
continue;
Expand Down Expand Up @@ -630,6 +631,7 @@ HttpStatusCode mongoEntityTypes

responseP->entityTypeVector.push_back(entityType);
}

orion::releaseMongoConnection(connection);

// Get count if user requested (i.e. if totalTypesP is not NULL)
Expand Down
3 changes: 2 additions & 1 deletion src/lib/mongoBackend/mongoRegistrationGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,10 @@ void mongoRegistrationsGet
TIME_STAT_MONGO_READ_WAIT_STOP();

/* Process query result */
// Note limit != 0 will cause skipping the while loop in case request didn't actually ask for any result */
int docs = 0;
orion::BSONObj r;
while (cursor.next(&r))
while ((limit != 0) && (cursor.next(&r)))
{
ngsiv2::Registration reg;

Expand Down
9 changes: 1 addition & 8 deletions src/lib/rest/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static int uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* ckey, c
{
if ((*cP < '0') || (*cP > '9'))
{
OrionError error(SccBadRequest, std::string("Bad pagination limit: /") + value + "/ [must be a decimal number]");
OrionError error(SccBadRequest, std::string("Bad pagination limit: /") + value + "/ [must be a positive integer number]");
ciP->httpStatusCode = error.code;
ciP->answer = error.smartRender(ciP->apiVersion);
return MHD_YES;
Expand All @@ -175,13 +175,6 @@ static int uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* ckey, c
ciP->answer = error.smartRender(ciP->apiVersion);
return MHD_YES;
}
else if (limit == 0)
{
OrionError error(SccBadRequest, std::string("Bad pagination limit: /") + value + "/ [a value of ZERO is unacceptable]");
ciP->httpStatusCode = error.code;
ciP->answer = error.smartRender(ciP->apiVersion);
return MHD_YES;
}
}
else if (key == URI_PARAM_PAGINATION_DETAILS)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,19 @@ orionCurl --url "$url" --payload "$payload"
echo
echo


# After fixing issue #1492 this has become a not-bad request case, but we keep
# in this file for simplicity (NGSIv1 is a deprecated API)
echo "+++++ 3. URI param 'limit' == 0"
url="/v1/queryContext?limit=000000"
payload='NO PAYLOAD NECESSARY'
payload='{
"entities": [
{
"type": "",
"isPattern": "false",
"id": "EVector"
}
]
}'
orionCurl --url "$url" --payload "$payload"
echo
echo
Expand All @@ -62,15 +71,15 @@ echo
--REGEXPECT--
+++++ 1. bad characters in URI param 'limit'
HTTP/1.1 400 Bad Request
Content-Length: 125
Content-Length: 134
Content-Type: application/json
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Date: REGEX(.*)

{
"orionError": {
"code": "400",
"details": "Bad pagination limit: /abc/ [must be a decimal number]",
"details": "Bad pagination limit: /abc/ [must be a positive integer number]",
"reasonPhrase": "Bad Request"
}
}
Expand All @@ -93,17 +102,16 @@ Date: REGEX(.*)


+++++ 3. URI param 'limit' == 0
HTTP/1.1 400 Bad Request
Content-Length: 135
HTTP/1.1 200 OK
Content-Length: 70
Content-Type: application/json
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Date: REGEX(.*)

{
"orionError": {
"code": "400",
"details": "Bad pagination limit: /000000/ [a value of ZERO is unacceptable]",
"reasonPhrase": "Bad Request"
"errorCode": {
"code": "404",
"reasonPhrase": "No context element found"
}
}

Expand Down
142 changes: 142 additions & 0 deletions test/functionalTest/cases/1492_limit_zero/limit_zero_entities.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Copyright 2021 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--
limit_zero_entities

--SHELL-INIT--
dbInit CB
brokerStart CB

--SHELL--

#
# 01. GET /v2/entities with 'limit' == 0 and options=count and see no entities and fiware-total-count: 0
# 02. POST /v2/entities to create E1 entity
# 03. POST /v2/entities to create E2 entity
# 04. GET /v2/entities with 'limit' == 0 and options=count and see no entities and fiware-total-count: 2
# 05. GET /v2/entities with 'limit' == 0 and see no entities
#

echo "01. GET /v2/entities with 'limit' == 0 and options=count and see no entities and fiware-total-count: 0"
echo "======================================================================================================"
orionCurl --url "/v2/entities?limit=0&options=count"
echo
echo


echo "02. POST /v2/entities to create E1 entity"
echo "========================================="
payload='{
"id": "E1",
"type": "T"
}'
orionCurl --url /v2/entities -X POST --payload "$payload"
echo
echo


echo "03. POST /v2/entities to create E2 entity"
echo "========================================="
payload='{
"id": "E2",
"type": "T"
}'
orionCurl --url /v2/entities -X POST --payload "$payload"
echo
echo


echo "04. GET /v2/entities with 'limit' == 0 and options=count and see no entities and fiware-total-count: 2"
echo "======================================================================================================"
orionCurl --url "/v2/entities?limit=0&options=count"
echo
echo


echo "05. GET /v2/entities with 'limit' == 0 and see no entities"
echo "=========================================================="
orionCurl --url "/v2/entities?limit=0"
echo
echo



--REGEXPECT--
01. GET /v2/entities with 'limit' == 0 and options=count and see no entities and fiware-total-count: 0
======================================================================================================
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json
Fiware-Total-Count: 0
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Date: REGEX(.*)

[]


02. POST /v2/entities to create E1 entity
=========================================
HTTP/1.1 201 Created
Content-Length: 0
Location: /v2/entities/E1?type=T
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Date: REGEX(.*)



03. POST /v2/entities to create E2 entity
=========================================
HTTP/1.1 201 Created
Content-Length: 0
Location: /v2/entities/E2?type=T
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Date: REGEX(.*)



04. GET /v2/entities with 'limit' == 0 and options=count and see no entities and fiware-total-count: 2
======================================================================================================
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json
Fiware-Total-Count: 2
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Date: REGEX(.*)

[]


05. GET /v2/entities with 'limit' == 0 and see no entities
==========================================================
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Date: REGEX(.*)

[]


--TEARDOWN--
brokerStop CB
dbDrop CB
Loading