Refactoring and adding VariableBlocks.

This commit is contained in:
stephb9959
2022-02-23 22:27:59 -08:00
parent df70ec8f40
commit 73a096b0ad
35 changed files with 518 additions and 90 deletions

View File

@@ -128,7 +128,7 @@ add_executable(owprov
src/WebSocketClientServer.cpp src/WebSocketClientServer.h
src/storage/storage_maps.cpp src/storage/storage_maps.h
src/RESTAPI/RESTAPI_map_handler.cpp src/RESTAPI/RESTAPI_map_handler.h
src/RESTAPI/RESTAPI_map_list_handler.cpp src/RESTAPI/RESTAPI_map_list_handler.h src/storage/storage_signup.cpp src/storage/storage_signup.h src/Signup.cpp src/Signup.h src/DeviceTypeCache.h)
src/RESTAPI/RESTAPI_map_list_handler.cpp src/RESTAPI/RESTAPI_map_list_handler.h src/storage/storage_signup.cpp src/storage/storage_signup.h src/Signup.cpp src/Signup.h src/DeviceTypeCache.h src/storage/storage_variables.cpp src/storage/storage_variables.h src/RESTAPI/RESTAPI_variables_handler.cpp src/RESTAPI/RESTAPI_variables_handler.h src/RESTAPI/RESTAPI_variables_list_handler.cpp src/RESTAPI/RESTAPI_variables_list_handler.h)
target_link_libraries(owprov PUBLIC
${Poco_LIBRARIES} ${MySQL_LIBRARIES}

2
build
View File

@@ -1 +1 @@
29
35

View File

@@ -759,6 +759,68 @@ components:
status:
type: string
Variable:
type: object
properties:
type:
type: string
enum:
- integer
- string
- float
- variable
weight:
type: integer
format: int64
prefix:
type: string
value:
type: string
VariableList:
type: object
properties:
variables:
type: array
items:
$ref: '#/components/schemas/Variable'
VariableBlock:
type: object
properties:
allOf:
$ref: '#/components/schemas/ObjectInfo'
variables:
type: array
items:
$ref: '#/components/schemas/Variable'
entity:
type: string
format: uuid
venue:
type: string
format: uuid
subscriber:
type: string
format: uuid
inventory:
type: string
format: uuid
inUse:
type: array
items:
type: string
format: uuid
VariableBlockList:
type: object
properties:
variableBlocks:
type: array
items:
type:
$ref: '#/components/schemas/VariableBlock'
#########################################################################################
##
## These are endpoints that all services in the OPenWiFI stack must provide

View File

@@ -24,15 +24,14 @@ namespace OpenWifi {
TransactionId,
Internal),
DB_(StorageService()->ConfigurationDB()){}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/configurations/{uuid}"}; };
private:
ConfigurationDB &DB_;
void DoGet();
void DoPost();
void DoPut();
void DoDelete();
private:
bool ValidateConfigBlock(const ProvObjects::DeviceConfiguration &Config, std::string & Error);
ConfigurationDB &DB_;
};
}

View File

@@ -11,15 +11,15 @@
namespace OpenWifi{
void RESTAPI_configurations_list_handler::DoGet() {
if(!QB_.Select.empty()) {
return ReturnRecordList<decltype(StorageService()->ConfigurationDB()),
ProvObjects::DeviceConfiguration>("configurations",StorageService()->ConfigurationDB(),*this );
return ReturnRecordList<decltype(DB_),
ProvObjects::DeviceConfiguration>("configurations",DB_,*this );
} else if(QB_.CountOnly) {
Poco::JSON::Object Answer;
auto C = StorageService()->ConfigurationDB().Count();
auto C = DB_.Count();
return ReturnCountOnly(C);
} else {
ProvObjects::DeviceConfigurationVec Configs;
StorageService()->ConfigurationDB().GetRecords(QB_.Offset,QB_.Limit,Configs);
ConfigurationDB::RecordVec Configs;
DB_.GetRecords(QB_.Offset,QB_.Limit,Configs);
return MakeJSONObjectArray("configurations", Configs, *this);
}
}

View File

@@ -5,6 +5,7 @@
#pragma once
#include "framework/MicroService.h"
#include "StorageService.h"
namespace OpenWifi {
@@ -17,10 +18,11 @@ namespace OpenWifi {
Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server,
TransactionId,
Internal) {}
Internal),
DB_(StorageService()->ConfigurationDB()) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/configurations"}; };
private:
ConfigurationDB & DB_;
void DoGet() final;
void DoPost() final {};
void DoPut() final {};

View File

@@ -11,15 +11,15 @@
namespace OpenWifi{
void RESTAPI_contact_list_handler::DoGet() {
if(!QB_.Select.empty()) {
return ReturnRecordList<decltype(StorageService()->ContactDB()),
ProvObjects::Contact>("contacts",StorageService()->ContactDB(),*this );
return ReturnRecordList<decltype(DB_),
ProvObjects::Contact>("contacts",DB_,*this );
} else if(QB_.CountOnly) {
Poco::JSON::Object Answer;
auto C = StorageService()->ContactDB().Count();
auto C = DB_.Count();
return ReturnCountOnly(C);
} else {
ProvObjects::ContactVec Contacts;
StorageService()->ContactDB().GetRecords(QB_.Offset,QB_.Limit,Contacts);
ContactDB::RecordVec Contacts;
DB_.GetRecords(QB_.Offset,QB_.Limit,Contacts);
return MakeJSONObjectArray("contacts", Contacts, *this);
}
}

View File

@@ -6,6 +6,7 @@
#include "framework/MicroService.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
#include "StorageService.h"
namespace OpenWifi {
@@ -18,9 +19,11 @@ namespace OpenWifi {
Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server,
TransactionId,
Internal) {}
Internal),
DB_(StorageService()->ContactDB()) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/contact"}; };
private:
ContactDB & DB_;
void DoGet() final;
void DoPost() final {};
void DoPut() final {};

View File

@@ -15,18 +15,18 @@ namespace OpenWifi{
void RESTAPI_entity_list_handler::DoGet() {
if(!QB_.Select.empty()) {
return ReturnRecordList<decltype(StorageService()->EntityDB()),
ProvObjects::Entity>("entities",StorageService()->EntityDB(),*this );
return ReturnRecordList<decltype(DB_),
ProvObjects::Entity>("entities",DB_,*this );
} else if(QB_.CountOnly) {
auto C = StorageService()->EntityDB().Count();
auto C = DB_.Count();
return ReturnCountOnly(C);
} else if (GetBoolParameter("getTree",false)) {
Poco::JSON::Object FullTree;
StorageService()->EntityDB().BuildTree(FullTree);
DB_.BuildTree(FullTree);
return ReturnObject(FullTree);
} else {
ProvObjects::EntityVec Entities;
StorageService()->EntityDB().GetRecords(QB_.Offset, QB_.Limit,Entities);
EntityDB::RecordVec Entities;
DB_.GetRecords(QB_.Offset, QB_.Limit,Entities);
return MakeJSONObjectArray("entities", Entities, *this);
}
}
@@ -34,7 +34,7 @@ namespace OpenWifi{
void RESTAPI_entity_list_handler::DoPost() {
if (GetBoolParameter("setTree",false)) {
auto FullTree = ParseStream();
StorageService()->EntityDB().ImportTree(FullTree);
DB_.ImportTree(FullTree);
return OK();
}
BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);

View File

@@ -10,6 +10,7 @@
#pragma once
#include "framework/MicroService.h"
#include "StorageService.h"
namespace OpenWifi {
class RESTAPI_entity_list_handler : public RESTAPIHandler {
@@ -22,9 +23,11 @@ namespace OpenWifi {
Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server,
TransactionId,
Internal) {}
Internal),
DB_(StorageService()->EntityDB()) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/entity"}; };
private:
EntityDB &DB_;
void DoGet() final;
void DoPost() final ;
void DoPut() final {};

View File

@@ -27,12 +27,12 @@ namespace OpenWifi {
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/inventory/{serialNumber}"}; };
private:
InventoryDB &DB_;
void DoGet() final;
void DoPost() final;
void DoPut() final;
void DoDelete() final;
void PerformClaim(const std::string &SerialNumber, const std::string & Claimer ,
std::string & ClaimId, uint64_t &ErrorCode, Poco::JSON::Object &Answer);
InventoryDB &DB_;
};
}

View File

@@ -43,45 +43,45 @@ namespace OpenWifi{
std::string OrderBy{" ORDER BY serialNumber ASC "};
if(HasParameter("orderBy",Arg)) {
if(!StorageService()->InventoryDB().PrepareOrderBy(Arg,OrderBy)) {
if(!DB_.PrepareOrderBy(Arg,OrderBy)) {
return BadRequest(RESTAPI::Errors::InvalidLOrderBy);
}
}
if(!QB_.Select.empty()) {
return ReturnRecordList<decltype(StorageService()->InventoryDB())>("taglist",StorageService()->InventoryDB(),*this );
return ReturnRecordList<decltype(DB_)>("taglist",DB_,*this );
} else if(HasParameter("entity",UUID)) {
if(QB_.CountOnly) {
auto C = StorageService()->InventoryDB().Count( StorageService()->InventoryDB().OP("entity",ORM::EQ,UUID));
auto C = DB_.Count( StorageService()->InventoryDB().OP("entity",ORM::EQ,UUID));
return ReturnCountOnly( C);
}
ProvObjects::InventoryTagVec Tags;
StorageService()->InventoryDB().GetRecords(QB_.Offset, QB_.Limit, Tags, StorageService()->InventoryDB().OP("entity",ORM::EQ,UUID), OrderBy);
DB_.GetRecords(QB_.Offset, QB_.Limit, Tags, DB_.OP("entity",ORM::EQ,UUID), OrderBy);
return SendList(Tags, SerialOnly);
} else if(HasParameter("venue",UUID)) {
if(QB_.CountOnly) {
auto C = StorageService()->InventoryDB().Count(StorageService()->InventoryDB().OP("venue",ORM::EQ,UUID));
auto C = DB_.Count(DB_.OP("venue",ORM::EQ,UUID));
return ReturnCountOnly( C);
}
ProvObjects::InventoryTagVec Tags;
StorageService()->InventoryDB().GetRecords(QB_.Offset, QB_.Limit, Tags, StorageService()->InventoryDB().OP("venue",ORM::EQ,UUID), OrderBy);
DB_.GetRecords(QB_.Offset, QB_.Limit, Tags, DB_.OP("venue",ORM::EQ,UUID), OrderBy);
return SendList( Tags, SerialOnly);
} else if(HasParameter("unassigned",Arg) && Arg=="true") {
if(QB_.CountOnly) {
std::string Empty;
auto C = StorageService()->InventoryDB().Count( InventoryDB::OP( StorageService()->InventoryDB().OP("venue",ORM::EQ,Empty),
ORM::AND, StorageService()->InventoryDB().OP("entity",ORM::EQ,Empty) ));
auto C = DB_.Count( InventoryDB::OP( DB_.OP("venue",ORM::EQ,Empty),
ORM::AND, DB_.OP("entity",ORM::EQ,Empty) ));
return ReturnCountOnly(C);
}
ProvObjects::InventoryTagVec Tags;
std::string Empty;
StorageService()->InventoryDB().GetRecords(QB_.Offset, QB_.Limit, Tags, InventoryDB::OP( StorageService()->InventoryDB().OP("venue",ORM::EQ,Empty),
ORM::AND, StorageService()->InventoryDB().OP("entity",ORM::EQ,Empty) ) , OrderBy );
DB_.GetRecords(QB_.Offset, QB_.Limit, Tags, InventoryDB::OP( DB_.OP("venue",ORM::EQ,Empty),
ORM::AND, DB_.OP("entity",ORM::EQ,Empty) ) , OrderBy );
return SendList(Tags, SerialOnly);
} else if (HasParameter("subscriber",Arg) && !Arg.empty()) {
// looking for device(s) for a specific subscriber...
ProvObjects::InventoryTagVec Tags;
StorageService()->InventoryDB().GetRecords(0,100,Tags," subscriber='" + Arg + "'");
DB_.GetRecords(0,100,Tags," subscriber='" + Arg + "'");
if(SerialOnly) {
std::vector<std::string> SerialNumbers;
std::transform(cbegin(Tags), cend(Tags), std::back_inserter(SerialNumbers), [](const auto &T) { return T.serialNumber; });
@@ -90,11 +90,11 @@ namespace OpenWifi{
return MakeJSONObjectArray("taglist", Tags, *this);
}
} else if (QB_.CountOnly) {
auto C = StorageService()->InventoryDB().Count();
auto C = DB_.Count();
return ReturnCountOnly(C);
} else if (GetBoolParameter("rrmOnly",false)) {
Types::UUIDvec_t DeviceList;
StorageService()->InventoryDB().GetRRMDeviceList(DeviceList);
DB_.GetRRMDeviceList(DeviceList);
if(QB_.CountOnly)
return ReturnCountOnly(DeviceList.size());
else {
@@ -102,7 +102,7 @@ namespace OpenWifi{
}
} else {
ProvObjects::InventoryTagVec Tags;
StorageService()->InventoryDB().GetRecords(QB_.Offset,QB_.Limit,Tags,"",OrderBy);
DB_.GetRecords(QB_.Offset,QB_.Limit,Tags,"",OrderBy);
return MakeJSONObjectArray("taglist", Tags, *this);
}
}

View File

@@ -8,8 +8,8 @@
#pragma once
#include "StorageService.h"
#include "framework/MicroService.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
namespace OpenWifi {
@@ -22,9 +22,11 @@ namespace OpenWifi {
Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server,
TransactionId,
Internal) {}
Internal),
DB_(StorageService()->InventoryDB()) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/inventory"}; };
private:
InventoryDB &DB_;
void DoGet() final;
void DoPost() final {};
void DoPut() final {};

View File

@@ -26,11 +26,11 @@ namespace OpenWifi {
DB_(StorageService()->LocationDB()){}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/location/{uuid}"}; };
private:
LocationDB &DB_;
void DoGet() final ;
void DoPost() final ;
void DoPut() final ;
void DoDelete() final ;
private:
LocationDB &DB_;
};
}

View File

@@ -12,15 +12,15 @@ namespace OpenWifi{
void RESTAPI_location_list_handler::DoGet() {
if(!QB_.Select.empty()) {
return ReturnRecordList<decltype(StorageService()->LocationDB()),
ProvObjects::Location>("locations",StorageService()->LocationDB(),*this );
return ReturnRecordList<decltype(DB_),
ProvObjects::Location>("locations",DB_,*this );
} else if(QB_.CountOnly) {
Poco::JSON::Object Answer;
auto C = StorageService()->LocationDB().Count();
auto C = DB_.Count();
return ReturnCountOnly(C);
} else {
ProvObjects::LocationVec Locations;
StorageService()->LocationDB().GetRecords(QB_.Offset,QB_.Limit,Locations);
LocationDB::RecordVec Locations;
DB_.GetRecords(QB_.Offset,QB_.Limit,Locations);
return MakeJSONObjectArray("locations", Locations, *this);
}
}

View File

@@ -5,6 +5,7 @@
#pragma once
#include "framework/MicroService.h"
#include "StorageService.h"
namespace OpenWifi {
@@ -17,9 +18,11 @@ namespace OpenWifi {
Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server,
TransactionId,
Internal) {}
Internal),
DB_(StorageService()->LocationDB()){}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/location"}; };
private:
LocationDB & DB_;
void DoGet() final;
void DoPost() final {};
void DoPut() final {};

View File

@@ -11,15 +11,15 @@
namespace OpenWifi{
void RESTAPI_managementPolicy_list_handler::DoGet() {
if(!QB_.Select.empty()) {
return ReturnRecordList<decltype(StorageService()->PolicyDB()),
ProvObjects::ManagementPolicy>("managementPolicies",StorageService()->PolicyDB(),*this );
return ReturnRecordList<decltype(DB_),
ProvObjects::ManagementPolicy>("managementPolicies",DB_,*this );
} else if(QB_.CountOnly) {
Poco::JSON::Object Answer;
auto C = StorageService()->ContactDB().Count();
auto C = DB_.Count();
return ReturnCountOnly(C);
} else {
ProvObjects::ManagementPolicyVec Policies;
StorageService()->PolicyDB().GetRecords(QB_.Offset,QB_.Limit,Policies);
DB_.GetRecords(QB_.Offset,QB_.Limit,Policies);
return MakeJSONObjectArray("managementPolicies", Policies, *this);
}
}

View File

@@ -3,6 +3,7 @@
//
#include "framework/MicroService.h"
#include "StorageService.h"
namespace OpenWifi {
@@ -15,9 +16,11 @@ namespace OpenWifi {
Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server,
TransactionId,
Internal) {}
Internal),
DB_(StorageService()->PolicyDB()) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/managementPolicy"}; };
private:
PolicyDB &DB_;
void DoGet() final ;
void DoPost() final {};
void DoPut() final {};

View File

@@ -12,15 +12,15 @@
namespace OpenWifi{
void RESTAPI_managementRole_list_handler::DoGet() {
if(!QB_.Select.empty()) {
return ReturnRecordList<decltype(StorageService()->RolesDB()),
ProvObjects::ManagementRole>("roles",StorageService()->RolesDB(),*this );
return ReturnRecordList<decltype(DB_),
ProvObjects::ManagementRole>("roles",DB_,*this );
} else if(QB_.CountOnly) {
Poco::JSON::Object Answer;
auto C = StorageService()->RolesDB().Count();
auto C = DB_.Count();
return ReturnCountOnly(C);
} else {
ProvObjects::ManagementRoleVec Roles;
StorageService()->RolesDB().GetRecords(QB_.Offset,QB_.Limit,Roles);
ManagementRoleDB::RecordVec Roles;
DB_.GetRecords(QB_.Offset,QB_.Limit,Roles);
return MakeJSONObjectArray("roles", Roles, *this);
}
}

View File

@@ -4,6 +4,7 @@
#pragma once
#include "framework/MicroService.h"
#include "StorageService.h"
namespace OpenWifi {
@@ -16,9 +17,12 @@ namespace OpenWifi {
Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server,
TransactionId,
Internal) {}
Internal),
DB_(StorageService()->RolesDB()) {
}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/managementRole"}; };
private:
ManagementRoleDB &DB_;
void DoGet() final;
void DoPost() final {};
void DoPut() final {};

View File

@@ -10,21 +10,21 @@
namespace OpenWifi{
void RESTAPI_map_list_handler::DoGet() {
if(GetBoolParameter("myMaps",false)) {
auto where = StorageService()->MapDB().OP("creator",ORM::EQ,UserInfo_.userinfo.id);
auto where = DB_.OP("creator",ORM::EQ,UserInfo_.userinfo.id);
std::vector<ProvObjects::Map> Maps;
StorageService()->MapDB().GetRecords(QB_.Offset,QB_.Limit,Maps,where);
DB_.GetRecords(QB_.Offset,QB_.Limit,Maps,where);
return MakeJSONObjectArray("list", Maps, *this);
} else if(GetBoolParameter("sharedWithMe",false)) {
} else if(!QB_.Select.empty()) {
return ReturnRecordList<decltype(StorageService()->MapDB()),ProvObjects::Map>("list",StorageService()->MapDB(),*this );
return ReturnRecordList<decltype(DB_),ProvObjects::Map>("list",DB_,*this );
} else if(QB_.CountOnly) {
Poco::JSON::Object Answer;
auto C = StorageService()->MapDB().Count();
auto C = DB_.Count();
return ReturnCountOnly(C);
} else {
std::vector<ProvObjects::Map> Maps;
StorageService()->MapDB().GetRecords(QB_.Offset,QB_.Limit,Maps);
MapDB::RecordVec Maps;
DB_.GetRecords(QB_.Offset,QB_.Limit,Maps);
return MakeJSONObjectArray("list", Maps, *this);
}
}

View File

@@ -4,6 +4,7 @@
#pragma once
#include "framework/MicroService.h"
#include "StorageService.h"
namespace OpenWifi {
@@ -16,9 +17,12 @@ namespace OpenWifi {
Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server,
TransactionId,
Internal) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/map"}; };
Internal),
DB_(StorageService()->MapDB()) {
}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/map"}; };
private:
MapDB &DB_;
void DoGet() final;
void DoPost() final {};
void DoPut() final {};

View File

@@ -22,8 +22,10 @@
#include "RESTAPI/RESTAPI_managementRole_list_handler.h"
#include "RESTAPI/RESTAPI_map_handler.h"
#include "RESTAPI/RESTAPI_map_list_handler.h"
#include "RESTAPI_iptocountry_handler.h"
#include "RESTAPI/RESTAPI_iptocountry_handler.h"
#include "RESTAPI/RESTAPI_signup_handler.h"
#include "RESTAPI/RESTAPI_variables_handler.h"
#include "RESTAPI/RESTAPI_variables_list_handler.h"
namespace OpenWifi {
@@ -50,7 +52,9 @@ namespace OpenWifi {
RESTAPI_map_list_handler,
RESTAPI_webSocketServer,
RESTAPI_iptocountry_handler,
RESTAPI_signup_handler
RESTAPI_signup_handler,
RESTAPI_variables_handler,
RESTAPI_variables_list_handler
>(Path,Bindings,L, S, TransactionId);
}

View File

@@ -0,0 +1,25 @@
//
// Created by stephane bourque on 2022-02-23.
//
#include "RESTAPI_variables_handler.h"
namespace OpenWifi {
void RESTAPI_variables_handler::DoGet() {
}
void RESTAPI_variables_handler::DoDelete() {
}
void RESTAPI_variables_handler::DoPost() {
}
void RESTAPI_variables_handler::DoPut() {
}
}

View File

@@ -0,0 +1,30 @@
//
// Created by stephane bourque on 2022-02-23.
//
#pragma once
#include "framework/MicroService.h"
#include "StorageService.h"
namespace OpenWifi {
class RESTAPI_variables_handler : public RESTAPIHandler {
public:
RESTAPI_variables_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L,
std::vector<std::string>{
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST,
Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE,
Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server,
TransactionId,
Internal),
DB_(StorageService()->VariablesDB()){}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/variables/{uuid}"}; };
private:
VariablesDB & DB_;
void DoGet() final ;
void DoPost() final ;
void DoPut() final ;
void DoDelete() final ;
};
}

View File

@@ -0,0 +1,25 @@
//
// Created by stephane bourque on 2022-02-23.
//
#include "RESTAPI_variables_list_handler.h"
#include "RESTAPI/RESTAPI_db_helpers.h"
namespace OpenWifi {
void RESTAPI_variables_list_handler::DoGet() {
if(!QB_.Select.empty()) {
return ReturnRecordList<decltype(DB_),
ProvObjects::VariableBlock>("variableBlocks",DB_,*this );
} else if(QB_.CountOnly) {
Poco::JSON::Object Answer;
auto C = DB_.Count();
return ReturnCountOnly(C);
} else {
VariablesDB::RecordVec VariableBlocks;
DB_.GetRecords(QB_.Offset,QB_.Limit,VariableBlocks);
return MakeJSONObjectArray("variableBlocks", VariableBlocks, *this);
}
}
}

View File

@@ -0,0 +1,32 @@
//
// Created by stephane bourque on 2022-02-23.
//
#pragma once
#include "framework/MicroService.h"
#include "StorageService.h"
namespace OpenWifi {
class RESTAPI_variables_list_handler : public RESTAPIHandler {
public:
RESTAPI_variables_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L,
std::vector<std::string>{
Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server,
TransactionId,
Internal),
DB_(StorageService()->VariablesDB()) {
}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/variables"}; };
private:
VariablesDB & DB_;
void DoGet() final;
void DoPost() final {};
void DoPut() final {};
void DoDelete() final {};
};
}

View File

@@ -11,29 +11,29 @@ namespace OpenWifi{
try {
std::string Arg;
if(!QB_.Select.empty()) {
return ReturnRecordList<decltype(StorageService()->VenueDB()),
ProvObjects::Venue>("venues",StorageService()->VenueDB(),*this );
return ReturnRecordList<decltype(DB_),
ProvObjects::Venue>("venues",DB_,*this );
} else if(HasParameter("entity",Arg)) {
ProvObjects::VenueVec Venues;
StorageService()->VenueDB().GetRecords(QB_.Offset,QB_.Limit,Venues, StorageService()->VenueDB().OP("entity",ORM::EQ,Arg));
DB_.GetRecords(QB_.Offset,QB_.Limit,Venues, DB_.OP("entity",ORM::EQ,Arg));
if(QB_.CountOnly) {
return ReturnCountOnly(Venues.size());
}
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));
VenueDB::RecordVec Venues;
DB_.GetRecords(QB_.Offset,QB_.Limit,Venues,DB_.OP("venue",ORM::EQ,Arg));
if(QB_.CountOnly) {
return ReturnCountOnly(Venues.size());
}
return MakeJSONObjectArray("venues", Venues, *this);
} else if(QB_.CountOnly) {
Poco::JSON::Object Answer;
auto C = StorageService()->VenueDB().Count();
auto C = DB_.Count();
return ReturnCountOnly(C);
} else {
ProvObjects::VenueVec Venues;
StorageService()->VenueDB().GetRecords(QB_.Offset, QB_.Limit,Venues);
VenueDB::RecordVec Venues;
DB_.GetRecords(QB_.Offset, QB_.Limit,Venues);
return MakeJSONObjectArray("venues", Venues, *this);
}
} catch(const Poco::Exception &E) {

View File

@@ -5,6 +5,7 @@
#pragma once
#include "framework/MicroService.h"
#include "StorageService.h"
namespace OpenWifi {
@@ -17,9 +18,12 @@ namespace OpenWifi {
Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server,
TransactionId,
Internal) {}
Internal), DB_(StorageService()->VenueDB()) {
}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/venue"}; };
private:
VenueDB &DB_;
void DoGet() final;
void DoPost() final {};
void DoPut() final {};

View File

@@ -631,6 +631,80 @@ namespace OpenWifi::ProvObjects {
return false;
}
void Variable::to_json(Poco::JSON::Object &Obj) const {
RESTAPI_utils::field_to_json( Obj,"type", type);
RESTAPI_utils::field_to_json( Obj,"weight", weight);
RESTAPI_utils::field_to_json( Obj,"prefix", prefix);
RESTAPI_utils::field_to_json( Obj,"value", value);
}
bool Variable::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
RESTAPI_utils::field_from_json( Obj,"type", type);
RESTAPI_utils::field_from_json( Obj,"weight", weight);
RESTAPI_utils::field_from_json( Obj,"prefix", prefix);
RESTAPI_utils::field_from_json( Obj,"value", value);
return true;
} catch(...) {
}
return false;
}
void VariableList::to_json(Poco::JSON::Object &Obj) const {
RESTAPI_utils::field_to_json( Obj,"variables", variables);
}
bool VariableList::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
RESTAPI_utils::field_from_json( Obj,"variables", variables);
return true;
} catch(...) {
}
return false;
}
void VariableBlock::to_json(Poco::JSON::Object &Obj) const {
info.to_json(Obj);
RESTAPI_utils::field_to_json( Obj,"variables", variables);
RESTAPI_utils::field_to_json( Obj,"entity", entity);
RESTAPI_utils::field_to_json( Obj,"venue", venue);
RESTAPI_utils::field_to_json( Obj,"subscriber", subscriber);
RESTAPI_utils::field_to_json( Obj,"inventory", inventory);
RESTAPI_utils::field_to_json( Obj,"inUse", inUse);
}
bool VariableBlock::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
info.from_json(Obj);
RESTAPI_utils::field_from_json( Obj,"variables", variables);
RESTAPI_utils::field_from_json( Obj,"entity", entity);
RESTAPI_utils::field_from_json( Obj,"venue", venue);
RESTAPI_utils::field_from_json( Obj,"subscriber", subscriber);
RESTAPI_utils::field_from_json( Obj,"inventory", inventory);
RESTAPI_utils::field_from_json( Obj,"inUse", inUse);
return true;
} catch(...) {
}
return false;
}
void VariableBlockList::to_json(Poco::JSON::Object &Obj) const {
RESTAPI_utils::field_to_json( Obj,"variableBlocks", variableBlocks);
}
bool VariableBlockList::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
RESTAPI_utils::field_from_json( Obj,"variableBlocks", variableBlocks);
return true;
} catch(...) {
}
return false;
}
bool UpdateObjectInfo(const Poco::JSON::Object::Ptr &O, const SecurityObjects::UserInfo &U, ObjectInfo &I) {
uint64_t Now = std::time(nullptr);
if(O->has("name"))

View File

@@ -400,6 +400,43 @@ namespace OpenWifi::ProvObjects {
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct Variable {
std::string type;
uint64_t weight=0;
std::string prefix;
std::string value;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct VariableList {
std::vector<Variable> variables;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct VariableBlock {
ObjectInfo info;
std::vector<Variable> variables;
std::string entity;
std::string venue;
std::string subscriber;
std::string inventory;
std::vector<std::string> inUse;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct VariableBlockList {
std::vector<VariableBlock> variableBlocks;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
bool UpdateObjectInfo(const Poco::JSON::Object::Ptr &O, const SecurityObjects::UserInfo &U, ObjectInfo &I);
bool CreateObjectInfo(const Poco::JSON::Object::Ptr &O, const SecurityObjects::UserInfo &U, ObjectInfo &I);
};

View File

@@ -28,6 +28,7 @@ namespace OpenWifi {
TagsObjectDB_ = std::make_unique<OpenWifi::TagsObjectDB>(dbType_, *Pool_, Logger());
MapDB_ = std::make_unique<OpenWifi::MapDB>(dbType_, *Pool_, Logger());
SignupDB_ = std::make_unique<OpenWifi::SignupDB>(dbType_, *Pool_, Logger());
VariablesDB_ = std::make_unique<OpenWifi::VariablesDB>(dbType_, *Pool_, Logger());
EntityDB_->Create();
PolicyDB_->Create();
@@ -41,6 +42,7 @@ namespace OpenWifi {
TagsObjectDB_->Create();
MapDB_->Create();
SignupDB_->Create();
VariablesDB_->Create();
ExistFunc_[EntityDB_->Prefix()] = [=](const char *F, std::string &V) -> bool { return EntityDB_->Exists(F,V); };
ExistFunc_[PolicyDB_->Prefix()] = [=](const char *F, std::string &V) -> bool { return PolicyDB_->Exists(F,V); };
@@ -54,6 +56,7 @@ namespace OpenWifi {
ExistFunc_[TagsObjectDB_->Prefix()] = [=](const char *F, std::string &V) ->bool { return TagsObjectDB_->Exists(F,V); };
ExistFunc_[MapDB_->Prefix()] = [=](const char *F, std::string &V) ->bool { return MapDB_->Exists(F,V); };
ExistFunc_[SignupDB_->Prefix()] = [=](const char *F, std::string &V) ->bool { return SignupDB_->Exists(F,V); };
ExistFunc_[VariablesDB_->Prefix()] = [=](const char *F, std::string &V) ->bool { return VariablesDB_->Exists(F,V); };
ExpandFunc_[EntityDB_->Prefix()] = [=](const char *F, std::string &V, std::string &Name, std::string & Description) -> bool { return EntityDB_->GetNameAndDescription(F,V, Name, Description); };
ExpandFunc_[PolicyDB_->Prefix()] = [=](const char *F, std::string &V, std::string &Name, std::string & Description) -> bool { return PolicyDB_->GetNameAndDescription(F,V, Name, Description); };
@@ -67,6 +70,7 @@ namespace OpenWifi {
ExpandFunc_[TagsObjectDB_->Prefix()] = [=](const char *F, std::string &V, std::string &Name, std::string & Description) ->bool { return TagsObjectDB_->Exists(F,V);; };
ExpandFunc_[MapDB_->Prefix()] = [=](const char *F, std::string &V, std::string &Name, std::string & Description) ->bool { return MapDB_->Exists(F,V);; };
ExpandFunc_[SignupDB_->Prefix()] = [=](const char *F, std::string &V, std::string &Name, std::string & Description) ->bool { return SignupDB_->Exists(F,V);; };
ExpandFunc_[VariablesDB_->Prefix()] = [=](const char *F, std::string &V, std::string &Name, std::string & Description) ->bool { return VariablesDB_->Exists(F,V);; };
EntityDB_->CheckForRoot();
InventoryDB_->InitializeSerialCache();

View File

@@ -22,6 +22,7 @@
#include "storage/storage_tags.h"
#include "storage/storage_maps.h"
#include "storage/storage_signup.h"
#include "storage/storage_variables.h"
namespace OpenWifi {
@@ -50,6 +51,7 @@ namespace OpenWifi {
OpenWifi::TagsObjectDB & TagsObjectDB() { return *TagsObjectDB_; };
OpenWifi::MapDB & MapDB() { return *MapDB_; };
OpenWifi::SignupDB & SignupDB() { return *SignupDB_; };
OpenWifi::VariablesDB & VariablesDB() { return *VariablesDB_; };
bool Validate(const Poco::URI::QueryParameters &P, std::string &Error);
bool Validate(const Types::StringVec &P, std::string &Error);
@@ -73,6 +75,7 @@ namespace OpenWifi {
std::unique_ptr<OpenWifi::TagsObjectDB> TagsObjectDB_;
std::unique_ptr<OpenWifi::MapDB> MapDB_;
std::unique_ptr<OpenWifi::SignupDB> SignupDB_;
std::unique_ptr<OpenWifi::VariablesDB> VariablesDB_;
typedef std::function<bool(const char *FieldName, std::string &Value)> exist_func;

View File

@@ -0,0 +1,74 @@
//
// Created by stephane bourque on 2022-02-23.
//
#include "storage_variables.h"
#include "framework/OpenWifiTypes.h"
#include "RESTObjects/RESTAPI_SecurityObjects.h"
#include "framework/MicroService.h"
namespace OpenWifi {
const static ORM::FieldVec VariablesDB_Fields{
// object info
ORM::Field{"id",64, true},
ORM::Field{"name",ORM::FieldType::FT_TEXT},
ORM::Field{"description",ORM::FieldType::FT_TEXT},
ORM::Field{"notes",ORM::FieldType::FT_TEXT},
ORM::Field{"created",ORM::FieldType::FT_BIGINT},
ORM::Field{"modified",ORM::FieldType::FT_BIGINT},
ORM::Field{"variables",ORM::FieldType::FT_TEXT},
ORM::Field{"entity",ORM::FieldType::FT_TEXT},
ORM::Field{"venue",ORM::FieldType::FT_TEXT},
ORM::Field{"subscriber",ORM::FieldType::FT_BIGINT},
ORM::Field{"inventory",ORM::FieldType::FT_BIGINT},
ORM::Field{"inUse",ORM::FieldType::FT_TEXT}
};
const static ORM::IndexVec VariablesDB_Indexes{
{ std::string("variables_venue_index"),
ORM::IndexEntryVec{
{std::string("venue"),
ORM::Indextype::ASC} } },
{ std::string("variables_entity_index"),
ORM::IndexEntryVec{
{std::string("entity"),
ORM::Indextype::ASC} } }
};
VariablesDB::VariablesDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) noexcept :
DB(T, "variables", VariablesDB_Fields, VariablesDB_Indexes, P, L, "var") {
}
}
template<> void ORM::DB<OpenWifi::VariablesDBRecordType, OpenWifi::ProvObjects::VariableBlock>::Convert(const OpenWifi::VariablesDBRecordType &In, OpenWifi::ProvObjects::VariableBlock &Out) {
Out.info.id = In.get<0>();
Out.info.name = In.get<1>();
Out.info.description = In.get<2>();
Out.info.notes = OpenWifi::RESTAPI_utils::to_object_array<OpenWifi::SecurityObjects::NoteInfo>(In.get<3>());
Out.info.created = In.get<4>();
Out.info.modified = In.get<5>();
Out.variables = OpenWifi::RESTAPI_utils::to_object_array<OpenWifi::ProvObjects::Variable>(In.get<6>());
Out.entity = In.get<7>();
Out.venue = In.get<8>();
Out.subscriber = In.get<9>();
Out.inventory = In.get<10>();
Out.inUse = OpenWifi::RESTAPI_utils::to_object_array(In.get<11>());
}
template<> void ORM::DB<OpenWifi::VariablesDBRecordType, OpenWifi::ProvObjects::VariableBlock>::Convert(const OpenWifi::ProvObjects::VariableBlock &In, OpenWifi::VariablesDBRecordType &Out) {
Out.set<0>(In.info.id);
Out.set<1>(In.info.name);
Out.set<2>(In.info.description);
Out.set<3>(OpenWifi::RESTAPI_utils::to_string(In.info.notes));
Out.set<4>(In.info.created);
Out.set<5>(In.info.modified);
Out.set<6>(OpenWifi::RESTAPI_utils::to_string(In.variables));
Out.set<7>(In.entity);
Out.set<8>(In.venue);
Out.set<9>(In.subscriber);
Out.set<10>(In.inventory);
Out.set<11>(OpenWifi::RESTAPI_utils::to_string(In.inUse));
}

View File

@@ -0,0 +1,31 @@
//
// Created by stephane bourque on 2022-02-23.
//
#pragma once
#include "framework/orm.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
namespace OpenWifi {
typedef Poco::Tuple<
std::string,
std::string,
std::string,
std::string,
uint64_t,
uint64_t,
std::string,
std::string,
std::string,
std::string,
std::string,
std::string
> VariablesDBRecordType;
class VariablesDB : public ORM::DB<VariablesDBRecordType, ProvObjects::VariableBlock> {
public:
explicit VariablesDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) noexcept;
private:
};
}