Skip to content

Commit

Permalink
Rudimentary support for GET /info/sourceIdentity
Browse files Browse the repository at this point in the history
  • Loading branch information
kzangeli committed Sep 3, 2024
1 parent 10cce03 commit ea9d232
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Support for the URL parameter 'orderBy' (must be an attribute) in GET //ngsi-ld/v1/entities, but only if 'local' is set. (This is not NGSI-LD standard. Yet ...)
- Also supporting sorting on entity id, type, and modifiedAt
- One more URL parameter '?reverse=true' to reverse the sorting order
* Rudimentary support for GET /info/sourceIdentity

## Notes
* Lots of improvements for subordinate subscriptions - still not 100% ready, but a lot better.
2 changes: 2 additions & 0 deletions src/app/orionld/orionldRestServices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include "orionld/serviceRoutines/orionldPutAttribute.h"
#include "orionld/serviceRoutines/orionldGetEntityMap.h"
#include "orionld/serviceRoutines/orionldDeleteEntityMap.h"
#include "orionld/serviceRoutines/orionldGetInfo.h"

#include "orionld/serviceRoutines/orionldGetTemporalEntities.h"
#include "orionld/serviceRoutines/orionldGetTemporalEntity.h"
Expand Down Expand Up @@ -105,6 +106,7 @@ static OrionLdRestServiceSimplified getServiceV[] =
{ "/ngsi-ld/v1/csourceRegistrations", orionldGetRegistrations },
{ "/ngsi-ld/v1/jsonldContexts/*", orionldGetContext },
{ "/ngsi-ld/v1/jsonldContexts", orionldGetContexts },
{ "/ngsi-ld/v1/info/sourceIdentity", orionldGetInfo },
{ "/ngsi-ld/v1/temporal/entities/*", orionldGetTemporalEntity },
{ "/ngsi-ld/v1/temporal/entities", orionldGetTemporalEntities },
{ "/ngsi-ld/ex/v1/version", orionldGetVersion },
Expand Down
1 change: 1 addition & 0 deletions src/lib/orionld/serviceRoutines/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ SET (SOURCES
orionldPatchTemporalAttributeInstance.cpp
orionldPostTemporalAttributes.cpp
orionldDeleteEntities.cpp
orionldGetInfo.cpp
)

# Include directories
Expand Down
71 changes: 71 additions & 0 deletions src/lib/orionld/serviceRoutines/orionldGetInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
*
* 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
*
* Author: Ken Zangelin
*/
extern "C"
{
#include "kjson/KjNode.h" // KjNode
#include "kjson/kjBuilder.h" // kjObject, kjString, kjBoolean, ...
}

#include "logMsg/logMsg.h" // LM_*

#include "orionld/common/orionldState.h" // orionldState
#include "orionld/serviceRoutines/orionldGetInfo.h" // Own Interface



// ----------------------------------------------------------------------------
//
// orionldGetInfo -
//
bool orionldGetInfo(void)
{
static int runNo = 1;
char id[128];

snprintf(id, sizeof(id) - 1, "urn:ngsi-ld:cs:%06d", runNo);
++runNo;

KjNode* infoP = kjObject(orionldState.kjsonP, NULL);
KjNode* idP = kjString(orionldState.kjsonP, "id", id);
KjNode* typeP = kjString(orionldState.kjsonP, "type", "ContextSourceIdentity");
KjNode* aliasP = kjString(orionldState.kjsonP, "contextSourceAlias", brokerId);

kjChildAdd(infoP, idP);
kjChildAdd(infoP, typeP);
kjChildAdd(infoP, aliasP);

orionldState.responseTree = infoP;

// This request is ALWAYS returned with pretty-print
orionldState.uriParams.prettyPrint = true;
orionldState.kjsonP->spacesPerIndent = 2;
orionldState.kjsonP->nlString = (char*) "\n";
orionldState.kjsonP->stringBeforeColon = (char*) "";
orionldState.kjsonP->stringAfterColon = (char*) " ";

orionldState.noLinkHeader = true; // We don't want the Link header for version requests

return true;
}
37 changes: 37 additions & 0 deletions src/lib/orionld/serviceRoutines/orionldGetInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef SRC_LIB_ORIONLD_SERVICEROUTINES_ORIONLDGETINFO_H_
#define SRC_LIB_ORIONLD_SERVICEROUTINES_ORIONLDGETINFO_H_

/*
*
* Copyright 2022 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
*
* Author: Ken Zangelin
*/



// ----------------------------------------------------------------------------
//
// orionldGetInfo -
//
extern bool orionldGetInfo(void);

#endif // SRC_LIB_ORIONLD_SERVICEROUTINES_ORIONLDGETINFO_H_
1 change: 0 additions & 1 deletion src/lib/orionld/serviceRoutines/orionldGetVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ extern "C"
#include "kjson/kjBuilder.h" // kjObject, kjString, kjBoolean, ...
}


#include "logMsg/logMsg.h" // LM_*

#include "cache/subCache.h" // subCacheItems
Expand Down
60 changes: 60 additions & 0 deletions test/functionalTest/cases/0000_ngsild/ngsild_get_info.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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--
Test of orionld version service, with branch name

--SHELL-INIT--
dbInit CB
orionldStart CB -troe -brokerId urn:B1 -experimental

--SHELL--

#
# 01. GET /ngsi-ld/v1/info/sourceIdentity
#

echo "01. GET /ngsi-ld/info/sourceIdentity"
echo "===================================="
orionCurl --url /ngsi-ld/v1/info/sourceIdentity
echo
echo


--REGEXPECT--
01. GET /ngsi-ld/info/sourceIdentity
====================================
HTTP/1.1 200 OK
Content-Length: 105
Content-Type: application/json
Date: REGEX(.*)

{
"contextSourceAlias": "urn:B1",
"id": "urn:ngsi-ld:cs:000001",
"type": "ContextSourceIdentity"
}


--TEARDOWN--
brokerStop CB
dbDrop CB

0 comments on commit ea9d232

Please sign in to comment.