diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 6fd7bd35e7..587f939752 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,5 +1,5 @@ ## Fixed Issues: - #0000: nada + #1698: Not fixed, but making it almost usable. Real fix coming soon. Needs a complete rewrite. ## New Features: * Support for ... diff --git a/src/lib/orionld/db/dbEntityTypesGet.cpp b/src/lib/orionld/db/dbEntityTypesGet.cpp index 7078e53597..303879613a 100644 --- a/src/lib/orionld/db/dbEntityTypesGet.cpp +++ b/src/lib/orionld/db/dbEntityTypesGet.cpp @@ -337,6 +337,19 @@ KjNode* dbEntityTypesGet(OrionldProblemDetails* pdP, bool details) } } + // + // See issue #1698 + // I'd really need to rewrite the whole function. + // As cfreyth correctly comments, the pagination limit/offet are about entities (as mongocEntitiesGet is used) + // and NOT entity types. + // + // As a quick and dirty fix: + // * Allow limit/offset + // * Set default limit to 1000 (unless set to anything else by the user) + // + if (orionldState.uriParams.limit == 20) + orionldState.uriParams.limit = 1000; // Default limit of 20 is changed to 1000 + // // GET local types - i.e. from the "entities" collection // diff --git a/src/lib/orionld/service/orionldServiceInit.cpp b/src/lib/orionld/service/orionldServiceInit.cpp index 2929d7430d..5c899979c6 100644 --- a/src/lib/orionld/service/orionldServiceInit.cpp +++ b/src/lib/orionld/service/orionldServiceInit.cpp @@ -444,6 +444,8 @@ static void restServicePrepare(OrionLdRestService* serviceP, OrionLdRestServiceS } else if (serviceP->serviceRoutine == orionldGetEntityTypes) { + serviceP->uriParams |= ORIONLD_URIPARAM_LIMIT; + serviceP->uriParams |= ORIONLD_URIPARAM_OFFSET; serviceP->uriParams |= ORIONLD_URIPARAM_DETAILS; } else if (serviceP->serviceRoutine == orionldGetEntityType) diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_issue_1698.test b/test/functionalTest/cases/0000_ngsild/ngsild_issue_1698.test new file mode 100644 index 0000000000..4f28a29ab6 --- /dev/null +++ b/test/functionalTest/cases/0000_ngsild/ngsild_issue_1698.test @@ -0,0 +1,261 @@ +# Copyright 2024 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-- +Entity pagination + +--SHELL-INIT-- +dbInit CB +orionldStart CB -experimental + +--SHELL-- + +# +# 01. Create 100 entities of types T001-T100 +# 02. GET the first 10 types +# 03. GET the next 10 types +# 04. GET all (1000 is the pagination limit for entities in GET /types) +# + +echo "01. Create 100 entities of types T001-T100" +echo "==========================================" +typeset -i eNo +eNo=1 + +while [ $eNo -le 100 ] +do + eId=$(printf "urn:E%03d" $eNo) + eType=$(printf "T%03d" $eNo) + eNo=$eNo+1 + + payload='{ + "id": "'$eId'", + "type": "'$eType'", + "A1": { + "type": "Property", + "value": "E'$eNo':A1" + } + }' + orionCurl --url /ngsi-ld/v1/entities --payload "$payload" | grep 'Location:' +done | wc +echo +echo + + +echo "02. GET the first 10 types" +echo "==========================" +orionCurl --url /ngsi-ld/v1/types?limit=10 +echo +echo + + +echo "03. GET the next 10 types" +echo "=========================" +orionCurl --url "/ngsi-ld/v1/types?limit=10&offset=10" +echo +echo + + +echo "04. GET all (1000 is the pagination limit for entities in GET /types)" +echo "=====================================================================" +orionCurl --url /ngsi-ld/v1/types +echo +echo + + +--REGEXPECT-- +01. Create 100 entities of types T001-T100 +========================================== + 100 200 4000 + + +02. GET the first 10 types +========================== +HTTP/1.1 200 OK +Content-Length: 179 +Content-Type: application/json +Date: REGEX(.*) +Link: