mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-11-02 11:37:54 +00:00
Finishing DB refactor.
This commit is contained in:
@@ -103,7 +103,7 @@ add_executable(owprov
|
||||
src/SDK_stubs.cpp src/SDK_stubs.h
|
||||
src/ConfigSanityChecker.cpp src/ConfigSanityChecker.h
|
||||
src/TagServer.cpp src/TagServer.h
|
||||
src/RESTAPI/RESTAPI_db_helpers.cpp src/RESTAPI/RESTAPI_db_helpers.h)
|
||||
src/RESTAPI/RESTAPI_db_helpers.h)
|
||||
|
||||
target_link_libraries(owprov PUBLIC
|
||||
${Poco_LIBRARIES} ${MySQL_LIBRARIES}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "StorageService.h"
|
||||
#include "framework/RESTAPI_errors.h"
|
||||
#include "ConfigurationValidator.h"
|
||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
||||
|
||||
namespace OpenWifi{
|
||||
|
||||
@@ -42,17 +43,7 @@ namespace OpenWifi{
|
||||
Answer.set("entries", Inner);
|
||||
return ReturnObject(Answer);
|
||||
} else if(QB_.AdditionalInfo) {
|
||||
Poco::JSON::Object EI;
|
||||
if(!Existing.managementPolicy.empty()) {
|
||||
Poco::JSON::Object PolObj;
|
||||
ProvObjects::ManagementPolicy Policy;
|
||||
if(StorageService()->PolicyDB().GetRecord("id",Existing.managementPolicy,Policy)) {
|
||||
PolObj.set( "name", Policy.info.name);
|
||||
PolObj.set( "description", Policy.info.description);
|
||||
}
|
||||
EI.set("managementPolicy",PolObj);
|
||||
}
|
||||
Answer.set("extendedInfo", EI);
|
||||
AddExtendedInfo(Existing,Answer);
|
||||
}
|
||||
Existing.to_json(Answer);
|
||||
ReturnObject(Answer);
|
||||
|
||||
@@ -6,22 +6,13 @@
|
||||
|
||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||
#include "StorageService.h"
|
||||
#include "framework/RESTAPI_errors.h"
|
||||
#include "RESTAPI_db_helpers.h"
|
||||
|
||||
namespace OpenWifi{
|
||||
void RESTAPI_configurations_list_handler::DoGet() {
|
||||
if(!QB_.Select.empty()) {
|
||||
auto DevUUIDS = Utils::Split(QB_.Select);
|
||||
ProvObjects::DeviceConfigurationVec Configs;
|
||||
for(const auto &i:DevUUIDS) {
|
||||
ProvObjects::DeviceConfiguration E;
|
||||
if(StorageService()->ConfigurationDB().GetRecord("id",i,E)) {
|
||||
Configs.push_back(E);
|
||||
} else {
|
||||
return BadRequest(RESTAPI::Errors::UnknownId + " (" + i + ")");
|
||||
}
|
||||
}
|
||||
return ReturnObject("configurations", Configs);
|
||||
return ReturnRecordList<decltype(StorageService()->ConfigurationDB()),
|
||||
ProvObjects::DeviceConfiguration>("configurations",StorageService()->ConfigurationDB(),*this );
|
||||
} else if(QB_.CountOnly) {
|
||||
Poco::JSON::Object Answer;
|
||||
auto C = StorageService()->ConfigurationDB().Count();
|
||||
@@ -29,31 +20,7 @@ namespace OpenWifi{
|
||||
} else {
|
||||
ProvObjects::DeviceConfigurationVec Configs;
|
||||
StorageService()->ConfigurationDB().GetRecords(QB_.Offset,QB_.Limit,Configs);
|
||||
|
||||
if(QB_.AdditionalInfo) {
|
||||
Poco::JSON::Array ObjArray;
|
||||
for(const auto &i:Configs) {
|
||||
Poco::JSON::Object Obj;
|
||||
i.to_json(Obj);
|
||||
Poco::JSON::Object EI;
|
||||
|
||||
if(!i.managementPolicy.empty()) {
|
||||
Poco::JSON::Object PolObj;
|
||||
ProvObjects::ManagementPolicy Policy;
|
||||
if(StorageService()->PolicyDB().GetRecord("id",i.managementPolicy,Policy)) {
|
||||
PolObj.set( "name", Policy.info.name);
|
||||
PolObj.set( "description", Policy.info.description);
|
||||
}
|
||||
EI.set("managementPolicy",PolObj);
|
||||
}
|
||||
Obj.set("extendedInfo", EI);
|
||||
ObjArray.add(Obj);
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("locations",ObjArray);
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
return ReturnObject("configurations", Configs);
|
||||
return MakeJSONObjectArray("configurations", Configs, *this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ namespace OpenWifi{
|
||||
Answer.set("entries", Inner);
|
||||
return ReturnObject(Answer);
|
||||
} else if(QB_.AdditionalInfo) {
|
||||
AddContactExtendedInfo(Existing, Answer);
|
||||
AddExtendedInfo(Existing, Answer);
|
||||
}
|
||||
|
||||
Existing.to_json(Answer);
|
||||
|
||||
@@ -3,52 +3,24 @@
|
||||
//
|
||||
|
||||
#include "RESTAPI_contact_list_handler.h"
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||
#include "StorageService.h"
|
||||
#include "framework/RESTAPI_errors.h"
|
||||
#include "RESTAPI_db_helpers.h"
|
||||
|
||||
namespace OpenWifi{
|
||||
void RESTAPI_contact_list_handler::DoGet() {
|
||||
if(!QB_.Select.empty()) {
|
||||
auto DevUUIDS = Utils::Split(QB_.Select);
|
||||
Poco::JSON::Array ObjArr;
|
||||
for(const auto &i:DevUUIDS) {
|
||||
ProvObjects::Contact E;
|
||||
Poco::JSON::Object Obj;
|
||||
if(StorageService()->ContactDB().GetRecord("id",i,E)) {
|
||||
E.to_json(Obj);
|
||||
if(QB_.AdditionalInfo)
|
||||
AddContactExtendedInfo(E, Obj);
|
||||
ObjArr.add(Obj);
|
||||
} else {
|
||||
return BadRequest(RESTAPI::Errors::ContactMustExist + " ("+i+")");
|
||||
}
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("contacts", ObjArr);
|
||||
return ReturnObject(Answer);
|
||||
return ReturnRecordList<decltype(StorageService()->ContactDB()),
|
||||
ProvObjects::Contact>("contacts",StorageService()->ContactDB(),*this );
|
||||
} else if(QB_.CountOnly) {
|
||||
Poco::JSON::Object Answer;
|
||||
auto C = StorageService()->ContactDB().Count();
|
||||
ReturnCountOnly(C);
|
||||
return;
|
||||
return ReturnCountOnly(C);
|
||||
} else {
|
||||
ProvObjects::ContactVec Contacts;
|
||||
StorageService()->ContactDB().GetRecords(QB_.Offset,QB_.Limit,Contacts);
|
||||
Poco::JSON::Array ObjArray;
|
||||
for(const auto &i:Contacts) {
|
||||
Poco::JSON::Object Obj;
|
||||
i.to_json(Obj);
|
||||
if(QB_.AdditionalInfo)
|
||||
AddContactExtendedInfo(i, Obj);
|
||||
ObjArray.add(Obj);
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("contacts",ObjArray);
|
||||
return ReturnObject(Answer);
|
||||
return MakeJSONObjectArray("contacts", Contacts, *this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-10-18.
|
||||
//
|
||||
|
||||
#include "RESTAPI_db_helpers.h"
|
||||
#include "StorageService.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
bool AddInventoryExtendedInfo(const ProvObjects::InventoryTag &T, Poco::JSON::Object &O) {
|
||||
Poco::JSON::Object EI;
|
||||
if(!T.entity.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::Entity Entity;
|
||||
if(StorageService()->EntityDB().GetRecord("id",T.entity,Entity)) {
|
||||
EntObj.set( "name", Entity.info.name);
|
||||
EntObj.set( "description", Entity.info.description);
|
||||
}
|
||||
EI.set("entity",EntObj);
|
||||
}
|
||||
if(!T.managementPolicy.empty()) {
|
||||
Poco::JSON::Object PolObj;
|
||||
ProvObjects::ManagementPolicy Policy;
|
||||
if(StorageService()->PolicyDB().GetRecord("id",T.managementPolicy,Policy)) {
|
||||
PolObj.set( "name", Policy.info.name);
|
||||
PolObj.set( "description", Policy.info.description);
|
||||
}
|
||||
EI.set("managementPolicy",PolObj);
|
||||
}
|
||||
if(!T.venue.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::Venue Venue;
|
||||
if(StorageService()->VenueDB().GetRecord("id",T.venue,Venue)) {
|
||||
EntObj.set( "name", Venue.info.name);
|
||||
EntObj.set( "description", Venue.info.description);
|
||||
}
|
||||
EI.set("venue",EntObj);
|
||||
}
|
||||
if(!T.contact.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::Contact Contact;
|
||||
if(StorageService()->ContactDB().GetRecord("id",T.contact,Contact)) {
|
||||
EntObj.set( "name", Contact.info.name);
|
||||
EntObj.set( "description", Contact.info.description);
|
||||
}
|
||||
EI.set("contact",EntObj);
|
||||
}
|
||||
if(!T.location.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::Location Location;
|
||||
if(StorageService()->LocationDB().GetRecord("id",T.location,Location)) {
|
||||
EntObj.set( "name", Location.info.name);
|
||||
EntObj.set( "description", Location.info.description);
|
||||
}
|
||||
EI.set("location",EntObj);
|
||||
}
|
||||
if(!T.deviceConfiguration.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::DeviceConfiguration DevConf;
|
||||
if(StorageService()->ConfigurationDB().GetRecord("id",T.deviceConfiguration,DevConf)) {
|
||||
EntObj.set( "name", DevConf.info.name);
|
||||
EntObj.set( "description", DevConf.info.description);
|
||||
}
|
||||
EI.set("deviceConfiguration",EntObj);
|
||||
}
|
||||
O.set("extendedInfo", EI);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AddLocationExtendedInfo(const ProvObjects::Location & T, Poco::JSON::Object &O) {
|
||||
Poco::JSON::Object EI;
|
||||
if(!T.entity.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::Entity Entity;
|
||||
if(StorageService()->EntityDB().GetRecord("id",T.entity,Entity)) {
|
||||
EntObj.set( "name", Entity.info.name);
|
||||
EntObj.set( "description", Entity.info.description);
|
||||
}
|
||||
EI.set("entity",EntObj);
|
||||
}
|
||||
|
||||
if(!T.managementPolicy.empty()) {
|
||||
Poco::JSON::Object PolObj;
|
||||
ProvObjects::ManagementPolicy Policy;
|
||||
if(StorageService()->PolicyDB().GetRecord("id",T.managementPolicy,Policy)) {
|
||||
PolObj.set( "name", Policy.info.name);
|
||||
PolObj.set( "description", Policy.info.description);
|
||||
}
|
||||
EI.set("managementPolicy",PolObj);
|
||||
}
|
||||
O.set("extendedInfo", EI);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AddContactExtendedInfo(const ProvObjects::Contact & T, Poco::JSON::Object &O) {
|
||||
Poco::JSON::Object EI;
|
||||
if(!T.entity.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::Entity Entity;
|
||||
if(StorageService()->EntityDB().GetRecord("id",T.entity,Entity)) {
|
||||
EntObj.set( "name", Entity.info.name);
|
||||
EntObj.set( "description", Entity.info.description);
|
||||
}
|
||||
EI.set("entity",EntObj);
|
||||
}
|
||||
|
||||
if(!T.managementPolicy.empty()) {
|
||||
Poco::JSON::Object PolObj;
|
||||
ProvObjects::ManagementPolicy Policy;
|
||||
if(StorageService()->PolicyDB().GetRecord("id",T.managementPolicy,Policy)) {
|
||||
PolObj.set( "name", Policy.info.name);
|
||||
PolObj.set( "description", Policy.info.description);
|
||||
}
|
||||
EI.set("managementPolicy",PolObj);
|
||||
}
|
||||
O.set("extendedInfo", EI);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AddEntityExtendedInfo(const ProvObjects::Entity & T, Poco::JSON::Object &O) {
|
||||
Poco::JSON::Object EI;
|
||||
if(!T.managementPolicy.empty()) {
|
||||
Poco::JSON::Object PolObj;
|
||||
ProvObjects::ManagementPolicy Policy;
|
||||
if(StorageService()->PolicyDB().GetRecord("id",T.managementPolicy,Policy)) {
|
||||
PolObj.set( "name", Policy.info.name);
|
||||
PolObj.set( "description", Policy.info.description);
|
||||
}
|
||||
EI.set("managementPolicy",PolObj);
|
||||
}
|
||||
if(!T.deviceConfiguration.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::DeviceConfiguration DevConf;
|
||||
if(StorageService()->ConfigurationDB().GetRecord("id",T.deviceConfiguration,DevConf)) {
|
||||
EntObj.set( "name", DevConf.info.name);
|
||||
EntObj.set( "description", DevConf.info.description);
|
||||
}
|
||||
EI.set("deviceConfiguration",EntObj);
|
||||
}
|
||||
O.set("extendedInfo", EI);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AddVenueExtendedInfo(const ProvObjects::Venue &T, Poco::JSON::Object &O) {
|
||||
Poco::JSON::Object EI;
|
||||
if(!T.entity.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::Entity Entity;
|
||||
if(StorageService()->EntityDB().GetRecord("id",T.entity,Entity)) {
|
||||
EntObj.set( "name", Entity.info.name);
|
||||
EntObj.set( "description", Entity.info.description);
|
||||
}
|
||||
EI.set("entity",EntObj);
|
||||
}
|
||||
if(!T.managementPolicy.empty()) {
|
||||
Poco::JSON::Object PolObj;
|
||||
ProvObjects::ManagementPolicy Policy;
|
||||
if(StorageService()->PolicyDB().GetRecord("id",T.managementPolicy,Policy)) {
|
||||
PolObj.set( "name", Policy.info.name);
|
||||
PolObj.set( "description", Policy.info.description);
|
||||
}
|
||||
EI.set("managementPolicy",PolObj);
|
||||
}
|
||||
if(!T.contact.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::Contact Contact;
|
||||
if(StorageService()->ContactDB().GetRecord("id",T.contact,Contact)) {
|
||||
EntObj.set( "name", Contact.info.name);
|
||||
EntObj.set( "description", Contact.info.description);
|
||||
}
|
||||
EI.set("contact",EntObj);
|
||||
}
|
||||
if(!T.location.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::Location Location;
|
||||
if(StorageService()->LocationDB().GetRecord("id",T.location,Location)) {
|
||||
EntObj.set( "name", Location.info.name);
|
||||
EntObj.set( "description", Location.info.description);
|
||||
}
|
||||
EI.set("location",EntObj);
|
||||
}
|
||||
if(!T.deviceConfiguration.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::DeviceConfiguration DevConf;
|
||||
if(StorageService()->ConfigurationDB().GetRecord("id",T.deviceConfiguration,DevConf)) {
|
||||
EntObj.set( "name", DevConf.info.name);
|
||||
EntObj.set( "description", DevConf.info.description);
|
||||
}
|
||||
EI.set("deviceConfiguration",EntObj);
|
||||
}
|
||||
O.set("extendedInfo", EI);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AddManagementPolicyExtendedInfo(const ProvObjects::ManagementPolicy &T, Poco::JSON::Object &O) {
|
||||
Poco::JSON::Object EI;
|
||||
if(!T.entity.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::Entity Entity;
|
||||
if(StorageService()->EntityDB().GetRecord("id",T.entity,Entity)) {
|
||||
EntObj.set( "name", Entity.info.name);
|
||||
EntObj.set( "description", Entity.info.description);
|
||||
}
|
||||
EI.set("entity",EntObj);
|
||||
}
|
||||
O.set("extendedInfo", EI);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AddManagementRoleExtendedInfo(const ProvObjects::ManagementRole &T, Poco::JSON::Object &O) {
|
||||
Poco::JSON::Object EI;
|
||||
if(!T.entity.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::Entity Entity;
|
||||
if(StorageService()->EntityDB().GetRecord("id",T.entity,Entity)) {
|
||||
EntObj.set( "name", Entity.info.name);
|
||||
EntObj.set( "description", Entity.info.description);
|
||||
}
|
||||
EI.set("entity",EntObj);
|
||||
}
|
||||
if(!T.managementPolicy.empty()) {
|
||||
Poco::JSON::Object PolObj;
|
||||
ProvObjects::ManagementPolicy P;
|
||||
if(StorageService()->PolicyDB().GetRecord("id",T.managementPolicy,P)) {
|
||||
PolObj.set( "name", P.info.name);
|
||||
PolObj.set( "description", P.info.description);
|
||||
}
|
||||
EI.set("managementPolicy",PolObj);
|
||||
}
|
||||
O.set("extendedInfo", EI);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,16 +6,162 @@
|
||||
#define OWPROV_RESTAPI_DB_HELPERS_H
|
||||
|
||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||
#include "StorageService.h"
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
bool AddInventoryExtendedInfo(const ProvObjects::InventoryTag &T, Poco::JSON::Object &O);
|
||||
bool AddLocationExtendedInfo(const ProvObjects::Location & T, Poco::JSON::Object &O);
|
||||
bool AddContactExtendedInfo(const ProvObjects::Contact &T, Poco::JSON::Object &O);
|
||||
bool AddEntityExtendedInfo(const ProvObjects::Entity &T, Poco::JSON::Object &O);
|
||||
bool AddVenueExtendedInfo(const ProvObjects::Venue &T, Poco::JSON::Object &O);
|
||||
bool AddManagementPolicyExtendedInfo(const ProvObjects::ManagementPolicy &T, Poco::JSON::Object &O);
|
||||
bool AddManagementRoleExtendedInfo(const ProvObjects::ManagementRole &T, Poco::JSON::Object &O);
|
||||
|
||||
|
||||
template <typename R, typename Q = decltype(R{}.entity)> void Extend_entity(const R &T, Poco::JSON::Object &EI ) {
|
||||
if constexpr(std::is_same_v<Q,std::string>) {
|
||||
if(!T.entity.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::Entity Entity;
|
||||
if(StorageService()->EntityDB().GetRecord("id",T.entity,Entity)) {
|
||||
EntObj.set( "name", Entity.info.name);
|
||||
EntObj.set( "description", Entity.info.description);
|
||||
}
|
||||
EI.set("entity",EntObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
template <typename... Ts> void Extend_entity(Ts... args) {
|
||||
static_assert( sizeof...(args) == 2);
|
||||
}
|
||||
|
||||
template <typename R, typename Q = decltype(R{}.managementPolicy)> void Extend_managementPolicy(const R &T, Poco::JSON::Object &EI ) {
|
||||
if constexpr(std::is_same_v<Q,std::string>) {
|
||||
if(!T.managementPolicy.empty()) {
|
||||
Poco::JSON::Object PolObj;
|
||||
ProvObjects::ManagementPolicy Policy;
|
||||
if(StorageService()->PolicyDB().GetRecord("id",T.managementPolicy,Policy)) {
|
||||
PolObj.set( "name", Policy.info.name);
|
||||
PolObj.set( "description", Policy.info.description);
|
||||
}
|
||||
EI.set("managementPolicy",PolObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
template <typename... Ts> void Extend_managementPolicy(Ts... args) {
|
||||
static_assert( sizeof...(args) == 2);
|
||||
}
|
||||
|
||||
template <typename R, typename Q = decltype(R{}.venue)> void Extend_venue(const R &T, Poco::JSON::Object &EI ) {
|
||||
if constexpr(std::is_same_v<Q,std::string>) {
|
||||
if(!T.venue.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::Venue Venue;
|
||||
if(StorageService()->VenueDB().GetRecord("id",T.venue,Venue)) {
|
||||
EntObj.set( "name", Venue.info.name);
|
||||
EntObj.set( "description", Venue.info.description);
|
||||
}
|
||||
EI.set("venue",EntObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
template <typename... Ts> void Extend_venue(Ts... args) {
|
||||
static_assert( sizeof...(args) == 2);
|
||||
}
|
||||
|
||||
template <typename R, typename Q = decltype(R{}.contact)> void Extend_contact(const R &T, Poco::JSON::Object &EI ) {
|
||||
if constexpr(std::is_same_v<Q,std::string>) {
|
||||
if(!T.contact.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::Contact Contact;
|
||||
if(StorageService()->ContactDB().GetRecord("id",T.contact,Contact)) {
|
||||
EntObj.set( "name", Contact.info.name);
|
||||
EntObj.set( "description", Contact.info.description);
|
||||
}
|
||||
EI.set("contact",EntObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
template <typename... Ts> void Extend_contact(Ts... args) {
|
||||
static_assert( sizeof...(args) == 2);
|
||||
}
|
||||
|
||||
template <typename R, typename Q = decltype(R{}.location)> void Extend_location(const R &T, Poco::JSON::Object &EI ) {
|
||||
if constexpr(std::is_same_v<Q,std::string>) {
|
||||
if(!T.location.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::Location Location;
|
||||
if(StorageService()->LocationDB().GetRecord("id",T.location,Location)) {
|
||||
EntObj.set( "name", Location.info.name);
|
||||
EntObj.set( "description", Location.info.description);
|
||||
}
|
||||
EI.set("location",EntObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
template <typename... Ts> void Extend_location(Ts... args) {
|
||||
static_assert( sizeof...(args) == 2);
|
||||
}
|
||||
|
||||
template <typename R, typename Q = decltype(R{}.deviceConfiguration)> void Extend_deviceConfiguration(const R &T, Poco::JSON::Object &EI ) {
|
||||
if constexpr(std::is_same_v<Q,std::string>) {
|
||||
if(!T.deviceConfiguration.empty()) {
|
||||
Poco::JSON::Object EntObj;
|
||||
ProvObjects::DeviceConfiguration DevConf;
|
||||
if(StorageService()->ConfigurationDB().GetRecord("id",T.deviceConfiguration,DevConf)) {
|
||||
EntObj.set( "name", DevConf.info.name);
|
||||
EntObj.set( "description", DevConf.info.description);
|
||||
}
|
||||
EI.set("deviceConfiguration",EntObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
template <typename... Ts> void Extend_deviceConfiguration(Ts... args) {
|
||||
static_assert( sizeof...(args) == 2);
|
||||
}
|
||||
|
||||
template <typename R> bool AddExtendedInfo(const R & T, Poco::JSON::Object &O) {
|
||||
Poco::JSON::Object EI;
|
||||
Extend_entity(T,EI);
|
||||
Extend_deviceConfiguration(T,EI);
|
||||
Extend_location(T,EI);
|
||||
Extend_contact(T,EI);
|
||||
Extend_venue(T,EI);
|
||||
Extend_managementPolicy(T,EI);
|
||||
O.set("extendedInfo", EI);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T> void MakeJSONObjectArray(const char * ArrayName, const std::vector<T> & V, RESTAPIHandler & R) {
|
||||
Poco::JSON::Array ObjArray;
|
||||
for(const auto &i:V) {
|
||||
Poco::JSON::Object Obj;
|
||||
i.to_json(Obj);
|
||||
if(R.NeedAdditionalInfo())
|
||||
AddExtendedInfo(i,Obj);
|
||||
ObjArray.add(Obj);
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set(ArrayName,ObjArray);
|
||||
return R.ReturnObject(Answer);
|
||||
}
|
||||
|
||||
template <typename DB, typename Record> void ReturnRecordList(const char *ArrayName,DB & DBInstance, RESTAPIHandler & R) {
|
||||
auto UUIDs = Utils::Split(R.SelectedRecords());
|
||||
Poco::JSON::Array ObjArr;
|
||||
for(const auto &i:UUIDs) {
|
||||
Record E;
|
||||
if(DBInstance.GetRecord("id",i,E)) {
|
||||
Poco::JSON::Object Obj;
|
||||
E.to_json(Obj);
|
||||
if(R.NeedAdditionalInfo())
|
||||
AddExtendedInfo(E,Obj);
|
||||
ObjArr.add(Obj);
|
||||
} else {
|
||||
return R.BadRequest("Unknown UUID:" + i);
|
||||
}
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set(ArrayName, ObjArr);
|
||||
return R.ReturnObject(Answer);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif //OWPROV_RESTAPI_DB_HELPERS_H
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenWifi{
|
||||
Poco::JSON::Object Answer;
|
||||
Existing.to_json(Answer);
|
||||
if(QB_.AdditionalInfo)
|
||||
AddEntityExtendedInfo( Existing, Answer);
|
||||
AddExtendedInfo( Existing, Answer);
|
||||
ReturnObject(Answer);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,17 +16,8 @@ namespace OpenWifi{
|
||||
void RESTAPI_entity_list_handler::DoGet() {
|
||||
std::string Arg;
|
||||
if(!QB_.Select.empty()) {
|
||||
auto EntityUIDs = Utils::Split(QB_.Select);
|
||||
ProvObjects::EntityVec Entities;
|
||||
for(const auto &i:EntityUIDs) {
|
||||
ProvObjects::Entity E;
|
||||
if(StorageService()->EntityDB().GetRecord("id",i,E)) {
|
||||
Entities.push_back(E);
|
||||
} else {
|
||||
return BadRequest(RESTAPI::Errors::UnknownId + " (" + i + ")");
|
||||
}
|
||||
}
|
||||
return ReturnObject("entities", Entities);
|
||||
return ReturnRecordList<decltype(StorageService()->EntityDB()),
|
||||
ProvObjects::Entity>("entities",StorageService()->EntityDB(),*this );
|
||||
} else if(QB_.CountOnly) {
|
||||
auto C = StorageService()->EntityDB().Count();
|
||||
return ReturnCountOnly(C);
|
||||
@@ -37,17 +28,7 @@ namespace OpenWifi{
|
||||
} else {
|
||||
ProvObjects::EntityVec Entities;
|
||||
StorageService()->EntityDB().GetRecords(QB_.Offset, QB_.Limit,Entities);
|
||||
Poco::JSON::Array ObjArray;
|
||||
for(const auto &i:Entities) {
|
||||
Poco::JSON::Object O;
|
||||
i.to_json(O);
|
||||
if(QB_.AdditionalInfo)
|
||||
AddEntityExtendedInfo( i, O);
|
||||
ObjArray.add(O);
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("entities",ObjArray);
|
||||
return ReturnObject(Answer);
|
||||
return MakeJSONObjectArray("entities", Entities, *this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace OpenWifi{
|
||||
RESTAPI_utils::field_to_json(Answer,"warnings", Warnings);
|
||||
return ReturnObject(Answer);
|
||||
} else if(QB_.AdditionalInfo) {
|
||||
AddInventoryExtendedInfo(Existing,Answer);
|
||||
AddExtendedInfo(Existing,Answer);
|
||||
}
|
||||
Existing.to_json(Answer);
|
||||
ReturnObject(Answer);
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace OpenWifi{
|
||||
Poco::JSON::Object O;
|
||||
i.to_json(O);
|
||||
if(QB_.AdditionalInfo)
|
||||
AddInventoryExtendedInfo(i,O);
|
||||
AddExtendedInfo(i,O);
|
||||
Array.add(O);
|
||||
}
|
||||
}
|
||||
@@ -50,24 +50,8 @@ namespace OpenWifi{
|
||||
}
|
||||
|
||||
if(!QB_.Select.empty()) {
|
||||
auto DevUUIDS = Utils::Split(QB_.Select);
|
||||
ProvObjects::InventoryTagVec Tags;
|
||||
Poco::JSON::Array ObjArr;
|
||||
for(const auto &i:DevUUIDS) {
|
||||
ProvObjects::InventoryTag E;
|
||||
if(StorageService()->InventoryDB().GetRecord("id",i,E)) {
|
||||
Poco::JSON::Object O;
|
||||
E.to_json(O);
|
||||
if(QB_.AdditionalInfo)
|
||||
AddInventoryExtendedInfo(E,O);
|
||||
ObjArr.add(O);
|
||||
} else {
|
||||
return BadRequest(RESTAPI::Errors::UnknownId + " (" + i + ")");
|
||||
}
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("taglist",ObjArr);
|
||||
return ReturnObject( Answer);
|
||||
return ReturnRecordList<decltype(StorageService()->InventoryDB()),
|
||||
ProvObjects::InventoryTag>("taglist",StorageService()->InventoryDB(),*this );
|
||||
} else if(HasParameter("entity",UUID)) {
|
||||
if(QB_.CountOnly) {
|
||||
auto C = StorageService()->InventoryDB().Count( StorageService()->InventoryDB().OP("entity",ORM::EQ,UUID));
|
||||
@@ -102,19 +86,7 @@ namespace OpenWifi{
|
||||
} else {
|
||||
ProvObjects::InventoryTagVec Tags;
|
||||
StorageService()->InventoryDB().GetRecords(QB_.Offset,QB_.Limit,Tags,"",OrderBy);
|
||||
Poco::JSON::Array Arr;
|
||||
|
||||
for(const auto &i:Tags) {
|
||||
Poco::JSON::Object O;
|
||||
i.to_json(O);
|
||||
|
||||
if(QB_.AdditionalInfo)
|
||||
AddInventoryExtendedInfo(i,O);
|
||||
Arr.add(O);
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("taglist",Arr);
|
||||
return ReturnObject(Answer);
|
||||
return MakeJSONObjectArray("taglist", Tags, *this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace OpenWifi{
|
||||
Answer.set("entries", Inner);
|
||||
return ReturnObject(Answer);
|
||||
} else if(QB_.AdditionalInfo) {
|
||||
AddLocationExtendedInfo(Existing, Answer);
|
||||
AddExtendedInfo(Existing, Answer);
|
||||
}
|
||||
Existing.to_json(Answer);
|
||||
ReturnObject(Answer);
|
||||
|
||||
@@ -6,30 +6,14 @@
|
||||
|
||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||
#include "StorageService.h"
|
||||
#include "framework/RESTAPI_errors.h"
|
||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
||||
|
||||
namespace OpenWifi{
|
||||
|
||||
void RESTAPI_location_list_handler::DoGet() {
|
||||
if(!QB_.Select.empty()) {
|
||||
auto DevUUIDS = Utils::Split(QB_.Select);
|
||||
Poco::JSON::Array ObjArr;
|
||||
for(const auto &i:DevUUIDS) {
|
||||
ProvObjects::Location E;
|
||||
if(StorageService()->LocationDB().GetRecord("id",i,E)) {
|
||||
Poco::JSON::Object Obj;
|
||||
E.to_json(Obj);
|
||||
if(QB_.AdditionalInfo)
|
||||
AddLocationExtendedInfo(E, Obj);
|
||||
ObjArr.add(Obj);
|
||||
} else {
|
||||
return BadRequest(RESTAPI::Errors::LocationMustExist + " ("+i+")");
|
||||
}
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("locations", ObjArr);
|
||||
return ReturnObject(Answer);
|
||||
return ReturnRecordList<decltype(StorageService()->LocationDB()),
|
||||
ProvObjects::Location>("locations",StorageService()->LocationDB(),*this );
|
||||
} else if(QB_.CountOnly) {
|
||||
Poco::JSON::Object Answer;
|
||||
auto C = StorageService()->LocationDB().Count();
|
||||
@@ -37,18 +21,7 @@ namespace OpenWifi{
|
||||
} else {
|
||||
ProvObjects::LocationVec Locations;
|
||||
StorageService()->LocationDB().GetRecords(QB_.Offset,QB_.Limit,Locations);
|
||||
|
||||
Poco::JSON::Array ObjArray;
|
||||
for(const auto &i:Locations) {
|
||||
Poco::JSON::Object Obj;
|
||||
i.to_json(Obj);
|
||||
if(QB_.AdditionalInfo)
|
||||
AddLocationExtendedInfo(i, Obj);
|
||||
ObjArray.add(Obj);
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("locations",ObjArray);
|
||||
return ReturnObject(Answer);
|
||||
return MakeJSONObjectArray("locations", Locations, *this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ namespace OpenWifi{
|
||||
|
||||
Poco::JSON::Object Answer;
|
||||
if(QB_.AdditionalInfo)
|
||||
AddManagementPolicyExtendedInfo(Existing,Answer);
|
||||
AddExtendedInfo(Existing,Answer);
|
||||
|
||||
Existing.to_json(Answer);
|
||||
ReturnObject(Answer);
|
||||
|
||||
@@ -12,23 +12,8 @@
|
||||
namespace OpenWifi{
|
||||
void RESTAPI_managementPolicy_list_handler::DoGet() {
|
||||
if(!QB_.Select.empty()) {
|
||||
auto DevUUIDS = Utils::Split(QB_.Select);
|
||||
Poco::JSON::Array ObjArr;
|
||||
for(const auto &i:DevUUIDS) {
|
||||
ProvObjects::ManagementPolicy E;
|
||||
if(StorageService()->PolicyDB().GetRecord("id",i,E)) {
|
||||
Poco::JSON::Object Obj;
|
||||
E.to_json(Obj);
|
||||
if(QB_.AdditionalInfo)
|
||||
AddManagementPolicyExtendedInfo(E, Obj);
|
||||
ObjArr.add(Obj);
|
||||
} else {
|
||||
return BadRequest(RESTAPI::Errors::UnknownId + "(" + i + ")");
|
||||
}
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("managementPolicies", ObjArr);
|
||||
return ReturnObject(Answer);
|
||||
return ReturnRecordList<decltype(StorageService()->PolicyDB()),
|
||||
ProvObjects::ManagementPolicy>("managementPolicies",StorageService()->PolicyDB(),*this );
|
||||
} else if(QB_.CountOnly) {
|
||||
Poco::JSON::Object Answer;
|
||||
auto C = StorageService()->ContactDB().Count();
|
||||
@@ -36,7 +21,7 @@ namespace OpenWifi{
|
||||
} else {
|
||||
ProvObjects::ManagementPolicyVec Policies;
|
||||
StorageService()->PolicyDB().GetRecords(QB_.Offset,QB_.Limit,Policies);
|
||||
return ReturnObject("managementPolicies", Policies);
|
||||
return MakeJSONObjectArray("managementPolicies", Policies, *this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||
#include "StorageService.h"
|
||||
#include "Poco/JSON/Parser.h"
|
||||
#include "Daemon.h"
|
||||
#include "Poco/StringTokenizer.h"
|
||||
#include "framework/RESTAPI_errors.h"
|
||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
||||
@@ -44,7 +43,7 @@ namespace OpenWifi{
|
||||
}
|
||||
|
||||
if(QB_.AdditionalInfo)
|
||||
AddManagementRoleExtendedInfo(Existing,Answer);
|
||||
AddExtendedInfo(Existing,Answer);
|
||||
Existing.to_json(Answer);
|
||||
ReturnObject(Answer);
|
||||
}
|
||||
|
||||
@@ -13,23 +13,8 @@
|
||||
namespace OpenWifi{
|
||||
void RESTAPI_managementRole_list_handler::DoGet() {
|
||||
if(!QB_.Select.empty()) {
|
||||
auto DevUUIDS = Utils::Split(QB_.Select);
|
||||
Poco::JSON::Array ObjArr;
|
||||
for(const auto &i:DevUUIDS) {
|
||||
ProvObjects::ManagementRole E;
|
||||
if(StorageService()->RolesDB().GetRecord("id",i,E)) {
|
||||
Poco::JSON::Object Obj;
|
||||
E.to_json(Obj);
|
||||
if(QB_.AdditionalInfo)
|
||||
AddManagementRoleExtendedInfo(E, Obj);
|
||||
ObjArr.add(Obj);
|
||||
} else {
|
||||
return BadRequest(RESTAPI::Errors::UnknownId + " (" + i + ")");
|
||||
}
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("roles", ObjArr);
|
||||
return ReturnObject(Answer);
|
||||
return ReturnRecordList<decltype(StorageService()->RolesDB()),
|
||||
ProvObjects::ManagementRole>("roles",StorageService()->RolesDB(),*this );
|
||||
} else if(QB_.CountOnly) {
|
||||
Poco::JSON::Object Answer;
|
||||
auto C = StorageService()->RolesDB().Count();
|
||||
@@ -37,17 +22,7 @@ namespace OpenWifi{
|
||||
} else {
|
||||
ProvObjects::ManagementRoleVec Roles;
|
||||
StorageService()->RolesDB().GetRecords(QB_.Offset,QB_.Limit,Roles);
|
||||
Poco::JSON::Array ObjArr;
|
||||
for(const auto &i:Roles) {
|
||||
Poco::JSON::Object Obj;
|
||||
i.to_json(Obj);
|
||||
if(QB_.AdditionalInfo)
|
||||
AddManagementRoleExtendedInfo(i, Obj);
|
||||
ObjArr.add(Obj);
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("roles", ObjArr);
|
||||
return ReturnObject(Answer);
|
||||
return MakeJSONObjectArray("roles", Roles, *this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ namespace OpenWifi{
|
||||
|
||||
Poco::JSON::Object Answer;
|
||||
if(QB_.AdditionalInfo)
|
||||
AddVenueExtendedInfo(Existing, Answer);
|
||||
AddExtendedInfo(Existing, Answer);
|
||||
|
||||
Existing.to_json(Answer);
|
||||
ReturnObject(Answer);
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "RESTAPI_venue_list_handler.h"
|
||||
#include "StorageService.h"
|
||||
#include "framework/RESTAPI_errors.h"
|
||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
||||
|
||||
namespace OpenWifi{
|
||||
@@ -12,39 +11,22 @@ namespace OpenWifi{
|
||||
try {
|
||||
std::string Arg;
|
||||
if(!QB_.Select.empty()) {
|
||||
auto UUIDs = Utils::Split(QB_.Select);
|
||||
Poco::JSON::Array ObjArr;
|
||||
for(const auto &i:UUIDs) {
|
||||
ProvObjects::Venue E;
|
||||
if(StorageService()->VenueDB().GetRecord("id",i,E)) {
|
||||
Poco::JSON::Object Obj;
|
||||
E.to_json(Obj);
|
||||
if(QB_.AdditionalInfo)
|
||||
AddVenueExtendedInfo(E,Obj);
|
||||
ObjArr.add(Obj);
|
||||
} else {
|
||||
return BadRequest("Unknown UUID:" + i);
|
||||
}
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("venues", ObjArr);
|
||||
return ReturnObject(Answer);
|
||||
return ReturnRecordList<decltype(StorageService()->VenueDB()),
|
||||
ProvObjects::Venue>("venues",StorageService()->VenueDB(),*this );
|
||||
} else if(HasParameter("entity",Arg)) {
|
||||
ProvObjects::VenueVec Venues;
|
||||
StorageService()->VenueDB().GetRecords(QB_.Offset,QB_.Limit,Venues, StorageService()->VenueDB().OP("entity",ORM::EQ,Arg));
|
||||
if(QB_.CountOnly) {
|
||||
return ReturnCountOnly(Venues.size());
|
||||
} else {
|
||||
return ReturnObject("venues", Venues);
|
||||
}
|
||||
return MakeJSONObjectArray("venues", Venues, *this);
|
||||
} else if(HasParameter("venue",Arg)) {
|
||||
ProvObjects::VenueVec Venues;
|
||||
StorageService()->VenueDB().GetRecords(QB_.Offset,QB_.Limit,Venues,StorageService()->VenueDB().OP("venue",ORM::EQ,Arg));
|
||||
if(QB_.CountOnly) {
|
||||
return ReturnCountOnly(Venues.size());
|
||||
} else {
|
||||
return ReturnObject("venues", Venues);
|
||||
}
|
||||
return MakeJSONObjectArray("venues", Venues, *this);
|
||||
} else if(QB_.CountOnly) {
|
||||
Poco::JSON::Object Answer;
|
||||
auto C = StorageService()->VenueDB().Count();
|
||||
@@ -52,18 +34,7 @@ namespace OpenWifi{
|
||||
} else {
|
||||
ProvObjects::VenueVec Venues;
|
||||
StorageService()->VenueDB().GetRecords(QB_.Offset, QB_.Limit,Venues);
|
||||
|
||||
Poco::JSON::Array ObjArr;
|
||||
for(const auto &i:Venues) {
|
||||
Poco::JSON::Object Obj;
|
||||
i.to_json(Obj);
|
||||
if(QB_.AdditionalInfo)
|
||||
AddVenueExtendedInfo(i, Obj);
|
||||
ObjArr.add(Obj);
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("venues", ObjArr);
|
||||
return ReturnObject(Answer);
|
||||
return MakeJSONObjectArray("venues", Venues, *this);
|
||||
}
|
||||
} catch(const Poco::Exception &E) {
|
||||
Logger_.log(E);
|
||||
|
||||
@@ -1292,10 +1292,14 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
inline bool NeedAdditionalInfo() const { return QB_.AdditionalInfo; }
|
||||
inline const std::string & SelectedRecords() const { return QB_.Select; }
|
||||
|
||||
inline const Poco::JSON::Object::Ptr & ParseStream() {
|
||||
return IncomingParser_.parse(Request->stream()).extract<Poco::JSON::Object::Ptr>();
|
||||
}
|
||||
|
||||
|
||||
inline static bool ParseBindings(const std::string & Request, const std::list<const char *> & EndPoints, BindingMap &bindings) {
|
||||
bindings.clear();
|
||||
std::vector<std::string> PathItems = Utils::Split(Request, '/');
|
||||
|
||||
Reference in New Issue
Block a user