Commit 3f976675 authored by yangjian's avatar yangjian
Browse files

rm UDR

parent 5774b9e9
cmake_minimum_required (VERSION 3.2)
project(api-server)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pg -g3" )
include(ExternalProject)
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/external)
ExternalProject_Add(PISTACHE
GIT_REPOSITORY https://github.com/oktal/pistache.git
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
)
ExternalProject_Add(NLOHMANN
GIT_REPOSITORY https://github.com/nlohmann/json.git
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
)
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
include_directories(model)
include_directories(api)
include_directories(impl)
file(GLOB SRCS
${CMAKE_CURRENT_SOURCE_DIR}/api/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/impl/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/model/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
)
add_executable(${PROJECT_NAME} ${SRCS} )
add_dependencies(${PROJECT_NAME} PISTACHE NLOHMANN)
target_link_libraries(${PROJECT_NAME} pistache pthread)
# REST API Server for Nudr_DataRepository API OpenAPI file
## Overview
This API Server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
It uses the [Pistache](https://github.com/oktal/pistache) Framework.
## Files organization
The Pistache C++ REST server generator creates three folders:
- `api`: This folder contains the handlers for each method specified in the OpenAPI definition. Every handler extracts
the path and body parameters (if any) from the requests and tries to parse and possibly validate them.
Once this step is completed, the main API class calls the corresponding abstract method that should be implemented
by the developer (a basic implementation is provided under the `impl` folder)
- `impl`: As written above, the implementation folder contains, for each API, the corresponding implementation class,
which extends the main API class and implements the abstract methods.
Every method receives the path and body parameters as constant reference variables and a reference to the response
object, that should be filled with the right response and sent at the end of the method with the command:
response.send(returnCode, responseBody, [mimeType])
- `model`: This folder contains the corresponding class for every object schema found in the OpenAPI specification.
The main folder contains also a file with a main that can be used to start the server.
Of course, is you should customize this file based on your needs
## Installation
First of all, you need to download and install the libraries listed [here](#libraries-required).
Once the libraries are installed, in order to compile and run the server please follow the steps below:
```bash
mkdir build
cd build
cmake ..
make
```
Once compiled run the server:
```bash
cd build
./api-server
```
## Libraries required
- [pistache](http://pistache.io/quickstart)
- [JSON for Modern C++](https://github.com/nlohmann/json/#integration): Please download the `json.hpp` file and
put it under the model/nlohmann folder
## Namespaces
org.openapitools.server.api
org.openapitools.server.model
/**
* Nudr_DataRepository API OpenAPI file
* Unified Data Repository Service. © 2020, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 2.2.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "AMF3GPPAccessRegistrationDocumentApi.h"
#include "Helpers.h"
namespace org {
namespace openapitools {
namespace server {
namespace api {
using namespace org::openapitools::server::helpers;
using namespace org::openapitools::server::model;
AMF3GPPAccessRegistrationDocumentApi::AMF3GPPAccessRegistrationDocumentApi(std::shared_ptr<Pistache::Rest::Router> rtr) {
router = rtr;
}
void AMF3GPPAccessRegistrationDocumentApi::init() {
setupRoutes();
}
void AMF3GPPAccessRegistrationDocumentApi::setupRoutes() {
using namespace Pistache::Rest;
Routes::Patch(*router, base + "/subscription-data/:ueId/context-data/amf-3gpp-access", Routes::bind(&AMF3GPPAccessRegistrationDocumentApi::amf_context3gpp_handler, this));
Routes::Put(*router, base + "/subscription-data/:ueId/context-data/amf-3gpp-access", Routes::bind(&AMF3GPPAccessRegistrationDocumentApi::create_amf_context3gpp_handler, this));
Routes::Get(*router, base + "/subscription-data/:ueId/context-data/amf-3gpp-access", Routes::bind(&AMF3GPPAccessRegistrationDocumentApi::query_amf_context3gpp_handler, this));
// Default handler, called when a route is not found
router->addCustomHandler(Routes::bind(&AMF3GPPAccessRegistrationDocumentApi::amf3_gpp_access_registration_document_api_default_handler, this));
}
void AMF3GPPAccessRegistrationDocumentApi::amf_context3gpp_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the path params
auto ueId = request.param(":ueId").as<std::string>();
// Getting the body param
std::vector<PatchItem> patchItem;
// Getting the query params
auto supportedFeaturesQuery = request.query().get("supported-features");
Pistache::Optional<std::string> supportedFeatures;
if(!supportedFeaturesQuery.isEmpty()){
std::string valueQuery_instance;
if(fromStringValue(supportedFeaturesQuery.get(), valueQuery_instance)){
supportedFeatures = Pistache::Some(valueQuery_instance);
}
}
try {
nlohmann::json::parse(request.body()).get_to(patchItem);
this->amf_context3gpp(ueId, patchItem, supportedFeatures, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void AMF3GPPAccessRegistrationDocumentApi::create_amf_context3gpp_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the path params
auto ueId = request.param(":ueId").as<std::string>();
// Getting the body param
Amf3GppAccessRegistration amf3GppAccessRegistration;
try {
nlohmann::json::parse(request.body()).get_to(amf3GppAccessRegistration);
this->create_amf_context3gpp(ueId, amf3GppAccessRegistration, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void AMF3GPPAccessRegistrationDocumentApi::query_amf_context3gpp_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the path params
auto ueId = request.param(":ueId").as<std::string>();
// Getting the query params
auto fieldsQuery = request.query().get("fields");
Pistache::Optional<std::vector<std::string>> fields;
if(!fieldsQuery.isEmpty()){
std::vector<std::string> valueQuery_instance;
if(fromStringValue(fieldsQuery.get(), valueQuery_instance)){
fields = Pistache::Some(valueQuery_instance);
}
}
auto supportedFeaturesQuery = request.query().get("supported-features");
Pistache::Optional<std::string> supportedFeatures;
if(!supportedFeaturesQuery.isEmpty()){
std::string valueQuery_instance;
if(fromStringValue(supportedFeaturesQuery.get(), valueQuery_instance)){
supportedFeatures = Pistache::Some(valueQuery_instance);
}
}
try {
this->query_amf_context3gpp(ueId, fields, supportedFeatures, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void AMF3GPPAccessRegistrationDocumentApi::amf3_gpp_access_registration_document_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
}
}
}
}
}
/**
* Nudr_DataRepository API OpenAPI file
* Unified Data Repository Service. © 2020, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 2.2.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* AMF3GPPAccessRegistrationDocumentApi.h
*
*
*/
#ifndef AMF3GPPAccessRegistrationDocumentApi_H_
#define AMF3GPPAccessRegistrationDocumentApi_H_
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/http_headers.h>
#include <pistache/optional.h>
#include "Amf3GppAccessRegistration.h"
#include "PatchItem.h"
#include "PatchResult.h"
#include "ProblemDetails.h"
#include <string>
#include <vector>
namespace org {
namespace openapitools {
namespace server {
namespace api {
using namespace org::openapitools::server::model;
class AMF3GPPAccessRegistrationDocumentApi {
public:
AMF3GPPAccessRegistrationDocumentApi(std::shared_ptr<Pistache::Rest::Router>);
virtual ~AMF3GPPAccessRegistrationDocumentApi() {}
void init();
const std::string base = "/nudr-dr/v2";
private:
void setupRoutes();
void amf_context3gpp_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
void create_amf_context3gpp_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
void query_amf_context3gpp_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
void amf3_gpp_access_registration_document_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
std::shared_ptr<Pistache::Rest::Router> router;
/// <summary>
/// To modify the AMF context data of a UE using 3gpp access in the UDR
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="ueId">UE id</param>
/// <param name="patchItem"></param>
/// <param name="supportedFeatures">Features required to be supported by the target NF (optional, default to &quot;&quot;)</param>
virtual void amf_context3gpp(const std::string &ueId, const std::vector<PatchItem> &patchItem, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// To store the AMF context data of a UE using 3gpp access in the UDR
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="ueId">UE id</param>
/// <param name="amf3GppAccessRegistration"> (optional)</param>
virtual void create_amf_context3gpp(const std::string &ueId, const Amf3GppAccessRegistration &amf3GppAccessRegistration, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Retrieves the AMF context data of a UE using 3gpp access
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="ueId">UE id</param>
/// <param name="fields">attributes to be retrieved (optional, default to std::vector&lt;std::string&gt;())</param>
/// <param name="supportedFeatures">Supported Features (optional, default to &quot;&quot;)</param>
virtual void query_amf_context3gpp(const std::string &ueId, const Pistache::Optional<std::vector<std::string>> &fields, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response) = 0;
};
}
}
}
}
#endif /* AMF3GPPAccessRegistrationDocumentApi_H_ */
/**
* Nudr_DataRepository API OpenAPI file
* Unified Data Repository Service. © 2020, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 2.2.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "AMFNon3GPPAccessRegistrationDocumentApi.h"
#include "Helpers.h"
namespace org {
namespace openapitools {
namespace server {
namespace api {
using namespace org::openapitools::server::helpers;
using namespace org::openapitools::server::model;
AMFNon3GPPAccessRegistrationDocumentApi::AMFNon3GPPAccessRegistrationDocumentApi(std::shared_ptr<Pistache::Rest::Router> rtr) {
router = rtr;
}
void AMFNon3GPPAccessRegistrationDocumentApi::init() {
setupRoutes();
}
void AMFNon3GPPAccessRegistrationDocumentApi::setupRoutes() {
using namespace Pistache::Rest;
Routes::Patch(*router, base + "/subscription-data/:ueId/context-data/amf-non-3gpp-access", Routes::bind(&AMFNon3GPPAccessRegistrationDocumentApi::amf_context_non3gpp_handler, this));
Routes::Put(*router, base + "/subscription-data/:ueId/context-data/amf-non-3gpp-access", Routes::bind(&AMFNon3GPPAccessRegistrationDocumentApi::create_amf_context_non3gpp_handler, this));
Routes::Get(*router, base + "/subscription-data/:ueId/context-data/amf-non-3gpp-access", Routes::bind(&AMFNon3GPPAccessRegistrationDocumentApi::query_amf_context_non3gpp_handler, this));
// Default handler, called when a route is not found
router->addCustomHandler(Routes::bind(&AMFNon3GPPAccessRegistrationDocumentApi::amf_non3_gpp_access_registration_document_api_default_handler, this));
}
void AMFNon3GPPAccessRegistrationDocumentApi::amf_context_non3gpp_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the path params
auto ueId = request.param(":ueId").as<std::string>();
// Getting the body param
std::vector<PatchItem> patchItem;
// Getting the query params
auto supportedFeaturesQuery = request.query().get("supported-features");
Pistache::Optional<std::string> supportedFeatures;
if(!supportedFeaturesQuery.isEmpty()){
std::string valueQuery_instance;
if(fromStringValue(supportedFeaturesQuery.get(), valueQuery_instance)){
supportedFeatures = Pistache::Some(valueQuery_instance);
}
}
try {
nlohmann::json::parse(request.body()).get_to(patchItem);
this->amf_context_non3gpp(ueId, patchItem, supportedFeatures, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void AMFNon3GPPAccessRegistrationDocumentApi::create_amf_context_non3gpp_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the path params
auto ueId = request.param(":ueId").as<std::string>();
// Getting the body param
AmfNon3GppAccessRegistration amfNon3GppAccessRegistration;
try {
nlohmann::json::parse(request.body()).get_to(amfNon3GppAccessRegistration);
this->create_amf_context_non3gpp(ueId, amfNon3GppAccessRegistration, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void AMFNon3GPPAccessRegistrationDocumentApi::query_amf_context_non3gpp_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the path params
auto ueId = request.param(":ueId").as<std::string>();
// Getting the query params
auto fieldsQuery = request.query().get("fields");
Pistache::Optional<std::vector<std::string>> fields;
if(!fieldsQuery.isEmpty()){
std::vector<std::string> valueQuery_instance;
if(fromStringValue(fieldsQuery.get(), valueQuery_instance)){
fields = Pistache::Some(valueQuery_instance);
}
}
auto supportedFeaturesQuery = request.query().get("supported-features");
Pistache::Optional<std::string> supportedFeatures;
if(!supportedFeaturesQuery.isEmpty()){
std::string valueQuery_instance;
if(fromStringValue(supportedFeaturesQuery.get(), valueQuery_instance)){
supportedFeatures = Pistache::Some(valueQuery_instance);
}
}
try {
this->query_amf_context_non3gpp(ueId, fields, supportedFeatures, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void AMFNon3GPPAccessRegistrationDocumentApi::amf_non3_gpp_access_registration_document_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
}
}
}
}
}
/**
* Nudr_DataRepository API OpenAPI file
* Unified Data Repository Service. © 2020, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 2.2.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* AMFNon3GPPAccessRegistrationDocumentApi.h
*
*
*/
#ifndef AMFNon3GPPAccessRegistrationDocumentApi_H_
#define AMFNon3GPPAccessRegistrationDocumentApi_H_
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/http_headers.h>
#include <pistache/optional.h>
#include "Amf3GppAccessRegistration.h"
#include "AmfNon3GppAccessRegistration.h"
#include "PatchItem.h"
#include "PatchResult.h"
#include "ProblemDetails.h"
#include <string>
#include <vector>
namespace org {
namespace openapitools {
namespace server {
namespace api {
using namespace org::openapitools::server::model;
class AMFNon3GPPAccessRegistrationDocumentApi {
public:
AMFNon3GPPAccessRegistrationDocumentApi(std::shared_ptr<Pistache::Rest::Router>);
virtual ~AMFNon3GPPAccessRegistrationDocumentApi() {}
void init();
const std::string base = "/nudr-dr/v2";
private:
void setupRoutes();
void amf_context_non3gpp_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
void create_amf_context_non3gpp_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
void query_amf_context_non3gpp_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
void amf_non3_gpp_access_registration_document_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
std::shared_ptr<Pistache::Rest::Router> router;
/// <summary>
/// To modify the AMF context data of a UE using non 3gpp access in the UDR
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="ueId">UE id</param>
/// <param name="patchItem"></param>
/// <param name="supportedFeatures">Features required to be supported by the target NF (optional, default to &quot;&quot;)</param>
virtual void amf_context_non3gpp(const std::string &ueId, const std::vector<PatchItem> &patchItem, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// To store the AMF context data of a UE using non-3gpp access in the UDR
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="ueId">UE id</param>
/// <param name="amfNon3GppAccessRegistration"> (optional)</param>
virtual void create_amf_context_non3gpp(const std::string &ueId, const AmfNon3GppAccessRegistration &amfNon3GppAccessRegistration, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Retrieves the AMF context data of a UE using non-3gpp access
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="ueId">UE id</param>
/// <param name="fields">attributes to be retrieved (optional, default to std::vector&lt;std::string&gt;())</param>
/// <param name="supportedFeatures">Supported Features (optional, default to &quot;&quot;)</param>
virtual void query_amf_context_non3gpp(const std::string &ueId, const Pistache::Optional<std::vector<std::string>> &fields, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response) = 0;
};
}
}
}
}
#endif /* AMFNon3GPPAccessRegistrationDocumentApi_H_ */
/**
* Nudr_DataRepository API OpenAPI file
* Unified Data Repository Service. © 2020, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*