diff --git a/src/lib/mongoBackend/MongoGlobal.cpp b/src/lib/mongoBackend/MongoGlobal.cpp index 29decbb9b1..e996aba9e2 100644 --- a/src/lib/mongoBackend/MongoGlobal.cpp +++ b/src/lib/mongoBackend/MongoGlobal.cpp @@ -836,6 +836,11 @@ static std::string sortCriteria(const std::string& sortToken) return ENT_MODIFICATION_DATE; } + if (sortToken == SERVICE_PATH) + { + return std::string("_id.") + ENT_SERVICE_PATH; + } + if (sortToken == ENT_ENTITY_ID) { return std::string("_id.") + ENT_ENTITY_ID; diff --git a/src/lib/rest/StringFilter.cpp b/src/lib/rest/StringFilter.cpp index 52da7d858b..9ac0a26c76 100644 --- a/src/lib/rest/StringFilter.cpp +++ b/src/lib/rest/StringFilter.cpp @@ -1835,6 +1835,10 @@ bool StringFilter::mongoFilterPopulate(std::string* errorStringP) { k = ENT_MODIFICATION_DATE; } + else if (left == SERVICE_PATH) + { + k = std::string("_id.") + ENT_SERVICE_PATH; + } else if (left == itemP->attributeName + "." + ENT_ATTRS_MD "." + NGSI_MD_DATECREATED) { k = std::string(ENT_ATTRS) + "." + itemP->attributeName + "." + ENT_ATTRS_CREATION_DATE; diff --git a/test/functionalTest/cases/2877_return_ServicePath_in_entity_response/servicePath_behave_with_q_and_orderBy.test b/test/functionalTest/cases/2877_return_ServicePath_in_entity_response/servicePath_behave_with_q_and_orderBy.test index c9444977c0..dd55accdfa 100644 --- a/test/functionalTest/cases/2877_return_ServicePath_in_entity_response/servicePath_behave_with_q_and_orderBy.test +++ b/test/functionalTest/cases/2877_return_ServicePath_in_entity_response/servicePath_behave_with_q_and_orderBy.test @@ -36,6 +36,7 @@ brokerStart CB # 04. Create entity E4 with temperature = 40 in servicePath /Barcelona/B # 05. GET entities with q parameter and servicePath /Madrid/A # 06. GET entities with orderBy servicePath +# 07. GET entities with orderBy !servicePath # @@ -113,6 +114,13 @@ echo echo +echo "07. GET entities with orderBy !servicePath" +echo "==========================================" +orionCurl --url /v2/entities?orderBy=!servicePath +echo +echo + + --REGEXPECT-- 01. Create entity E1 with temperature = 35 in servicePath /Madrid/A =================================================================== @@ -160,9 +168,28 @@ HTTP/1.1 200 OK Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 2 +Content-Length: 163 -[] +[ + { + "id": "E1", + "temperature": { + "metadata": {}, + "type": "Integer", + "value": 35 + }, + "type": "T" + }, + { + "id": "E3", + "temperature": { + "metadata": {}, + "type": "Integer", + "value": 30 + }, + "type": "T" + } +] 06. GET entities with orderBy servicePath @@ -174,6 +201,24 @@ Content-Type: application/json Content-Length: 325 [ + { + "id": "E2", + "temperature": { + "metadata": {}, + "type": "Integer", + "value": 25 + }, + "type": "T" + }, + { + "id": "E4", + "temperature": { + "metadata": {}, + "type": "Integer", + "value": 40 + }, + "type": "T" + }, { "id": "E1", "temperature": { @@ -184,11 +229,32 @@ Content-Length: 325 "type": "T" }, { - "id": "E2", + "id": "E3", "temperature": { "metadata": {}, "type": "Integer", - "value": 25 + "value": 30 + }, + "type": "T" + } +] + + +07. GET entities with orderBy !servicePath +========================================== +HTTP/1.1 200 OK +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Content-Type: application/json +Content-Length: 325 + +[ + { + "id": "E1", + "temperature": { + "metadata": {}, + "type": "Integer", + "value": 35 }, "type": "T" }, @@ -209,6 +275,15 @@ Content-Length: 325 "value": 40 }, "type": "T" + }, + { + "id": "E2", + "temperature": { + "metadata": {}, + "type": "Integer", + "value": 25 + }, + "type": "T" } ]