Framework update

This commit is contained in:
stephb9959
2022-01-10 22:42:53 -08:00
parent 4c392361a9
commit 8c22f3576b
6 changed files with 67 additions and 42 deletions

View File

@@ -309,6 +309,7 @@ namespace OpenWifi::ProvObjects {
field_to_json( Obj,"deviceConfiguration",deviceConfiguration); field_to_json( Obj,"deviceConfiguration",deviceConfiguration);
field_to_json( Obj,"rrm",rrm); field_to_json( Obj,"rrm",rrm);
field_to_json( Obj,"managementPolicy",managementPolicy); field_to_json( Obj,"managementPolicy",managementPolicy);
field_to_json( Obj,"state",state);
} }
bool InventoryTag::from_json(const Poco::JSON::Object::Ptr &Obj) { bool InventoryTag::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -326,6 +327,7 @@ namespace OpenWifi::ProvObjects {
field_from_json( Obj,"deviceConfiguration",deviceConfiguration); field_from_json( Obj,"deviceConfiguration",deviceConfiguration);
field_from_json( Obj,"rrm",rrm); field_from_json( Obj,"rrm",rrm);
field_from_json( Obj,"managementPolicy",managementPolicy); field_from_json( Obj,"managementPolicy",managementPolicy);
field_from_json( Obj,"state",state);
return true; return true;
} catch(...) { } catch(...) {

View File

@@ -284,6 +284,7 @@ namespace OpenWifi::ProvObjects {
std::string deviceConfiguration; std::string deviceConfiguration;
std::string rrm; std::string rrm;
Types::UUID_t managementPolicy; Types::UUID_t managementPolicy;
std::string state;
void to_json(Poco::JSON::Object &Obj) const; void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj); bool from_json(const Poco::JSON::Object::Ptr &Obj);

View File

@@ -254,6 +254,7 @@ namespace OpenWifi::SecurityObjects {
field_to_json(Obj,"lastPasswords",lastPasswords); field_to_json(Obj,"lastPasswords",lastPasswords);
field_to_json(Obj,"oauthType",oauthType); field_to_json(Obj,"oauthType",oauthType);
field_to_json(Obj,"oauthUserInfo",oauthUserInfo); field_to_json(Obj,"oauthUserInfo",oauthUserInfo);
field_to_json(Obj,"modified",modified);
}; };
bool UserInfo::from_json(const Poco::JSON::Object::Ptr &Obj) { bool UserInfo::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -288,6 +289,7 @@ namespace OpenWifi::SecurityObjects {
field_from_json(Obj,"lastPasswords",lastPasswords); field_from_json(Obj,"lastPasswords",lastPasswords);
field_from_json(Obj,"oauthType",oauthType); field_from_json(Obj,"oauthType",oauthType);
field_from_json(Obj,"oauthUserInfo",oauthUserInfo); field_from_json(Obj,"oauthUserInfo",oauthUserInfo);
field_from_json(Obj,"modified",modified);
return true; return true;
} catch (const Poco::Exception &E) { } catch (const Poco::Exception &E) {
@@ -585,5 +587,12 @@ namespace OpenWifi::SecurityObjects {
return false; return false;
} }
void LoginRecordInfo::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj,"sessionId",sessionId);
field_to_json(Obj,"userId",userId);
field_to_json(Obj,"email",email);
field_to_json(Obj,"login",login);
field_to_json(Obj,"logout",logout);
}
} }

View File

@@ -136,6 +136,7 @@ namespace OpenWifi {
OpenWifi::Types::StringVec lastPasswords; OpenWifi::Types::StringVec lastPasswords;
std::string oauthType; std::string oauthType;
std::string oauthUserInfo; std::string oauthUserInfo;
uint64_t modified;
void to_json(Poco::JSON::Object &Obj) const; void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj); bool from_json(const Poco::JSON::Object::Ptr &Obj);
@@ -292,5 +293,14 @@ namespace OpenWifi {
Poco::Data::LOB<char> avatar; Poco::Data::LOB<char> avatar;
}; };
struct LoginRecordInfo {
std::string sessionId;
std::string userId;
std::string email;
uint64_t login=0;
uint64_t logout=0;
void to_json(Poco::JSON::Object &Obj) const;
};
} }
} }

View File

@@ -59,5 +59,6 @@ namespace OpenWifi::RESTAPI::Errors {
static const std::string MissingAuthenticationInformation{"Missing authentication information."}; static const std::string MissingAuthenticationInformation{"Missing authentication information."};
static const std::string InsufficientAccessRights{"Insufficient access rights to complete the operation."}; static const std::string InsufficientAccessRights{"Insufficient access rights to complete the operation."};
static const std::string ExpiredToken{"Token has expired, user must login."}; static const std::string ExpiredToken{"Token has expired, user must login."};
static const std::string SubscriberMustExist{"Subscriber must exist."};
} }

View File

@@ -171,6 +171,9 @@ namespace ORM {
template <typename RecordTuple, typename RecordType> class DB { template <typename RecordTuple, typename RecordType> class DB {
public: public:
typedef const char * field_name_t;
DB( OpenWifi::DBType dbtype, DB( OpenWifi::DBType dbtype,
const char *TableName, const char *TableName,
const FieldVec & Fields, const FieldVec & Fields,
@@ -258,27 +261,27 @@ namespace ORM {
[[nodiscard]] const std::string & SelectList() const { return SelectList_; }; [[nodiscard]] const std::string & SelectList() const { return SelectList_; };
[[nodiscard]] const std::string & UpdateFields() const { return UpdateFields_; }; [[nodiscard]] const std::string & UpdateFields() const { return UpdateFields_; };
inline std::string OP(const char *F, SqlComparison O , bool V) { inline std::string OP(field_name_t F, SqlComparison O , bool V) {
assert( FieldNames_.find(F) != FieldNames_.end() ); assert( FieldNames_.find(F) != FieldNames_.end() );
return std::string{"("} + F + SQLCOMPS[O] + (V ? "true" : "false") + ")" ; return std::string{"("} + F + SQLCOMPS[O] + (V ? "true" : "false") + ")" ;
} }
inline std::string OP(const char *F, SqlComparison O , int V) { inline std::string OP(field_name_t F, SqlComparison O , int V) {
assert( FieldNames_.find(F) != FieldNames_.end() ); assert( FieldNames_.find(F) != FieldNames_.end() );
return std::string{"("} + F + SQLCOMPS[O] + std::to_string(V) + ")" ; return std::string{"("} + F + SQLCOMPS[O] + std::to_string(V) + ")" ;
} }
inline std::string OP(const char *F, SqlComparison O , uint64_t V) { inline std::string OP(field_name_t F, SqlComparison O , uint64_t V) {
assert( FieldNames_.find(F) != FieldNames_.end() ); assert( FieldNames_.find(F) != FieldNames_.end() );
return std::string{"("} + F + SQLCOMPS[O] + std::to_string(V) + ")" ; return std::string{"("} + F + SQLCOMPS[O] + std::to_string(V) + ")" ;
} }
std::string OP(const char *F, SqlComparison O , const std::string & V) { std::string OP(field_name_t F, SqlComparison O , const std::string & V) {
assert( FieldNames_.find(F) != FieldNames_.end() ); assert( FieldNames_.find(F) != FieldNames_.end() );
return std::string{"("} + F + SQLCOMPS[O] + "'" + Escape(V) + "')" ; return std::string{"("} + F + SQLCOMPS[O] + "'" + Escape(V) + "')" ;
} }
std::string OP(const char *F, SqlComparison O , const char * V) { std::string OP(field_name_t F, SqlComparison O , const char * V) {
assert( FieldNames_.find(F) != FieldNames_.end() ); assert( FieldNames_.find(F) != FieldNames_.end() );
return std::string{"("} + F + SQLCOMPS[O] + "'" + Escape(V) + "')" ; return std::string{"("} + F + SQLCOMPS[O] + "'" + Escape(V) + "')" ;
} }
@@ -299,9 +302,12 @@ namespace ORM {
return std::string{"("} + P1 + BOPS[BOP] + OP(true, P2, More...); return std::string{"("} + P1 + BOPS[BOP] + OP(true, P2, More...);
} }
inline bool Create() { bool Upgrade() {
std::string S; uint32_t To;
return Upgrade(0, To);
}
inline bool Create() {
switch(Type_) { switch(Type_) {
case OpenWifi::DBType::mysql: { case OpenWifi::DBType::mysql: {
try { try {
@@ -309,12 +315,10 @@ namespace ORM {
std::string Statement = IndexCreation_.empty() ? "create table if not exists " + TableName_ +" ( " + CreateFields_ + " )" : std::string Statement = IndexCreation_.empty() ? "create table if not exists " + TableName_ +" ( " + CreateFields_ + " )" :
"create table if not exists " + TableName_ +" ( " + CreateFields_ + " ), " + IndexCreation_[0] + " )"; "create table if not exists " + TableName_ +" ( " + CreateFields_ + " ), " + IndexCreation_[0] + " )";
Session << Statement , Poco::Data::Keywords::now; Session << Statement , Poco::Data::Keywords::now;
return true;
} catch (const Poco::Exception &E) { } catch (const Poco::Exception &E) {
Logger_.error("Failure to create MySQL DB resources."); Logger_.error("Failure to create MySQL DB resources.");
Logger_.log(E); Logger_.log(E);
} }
return false;
} }
break; break;
@@ -326,7 +330,6 @@ namespace ORM {
for(const auto &i:IndexCreation_) { for(const auto &i:IndexCreation_) {
Session << i , Poco::Data::Keywords::now; Session << i , Poco::Data::Keywords::now;
} }
return true;
} catch (const Poco::Exception &E) { } catch (const Poco::Exception &E) {
Logger_.error("Failure to create SQLITE DB resources."); Logger_.error("Failure to create SQLITE DB resources.");
Logger_.log(E); Logger_.log(E);
@@ -342,7 +345,6 @@ namespace ORM {
for(const auto &i:IndexCreation_) { for(const auto &i:IndexCreation_) {
Session << i , Poco::Data::Keywords::now; Session << i , Poco::Data::Keywords::now;
} }
return true;
} catch (const Poco::Exception &E) { } catch (const Poco::Exception &E) {
Logger_.error("Failure to create POSTGRESQL DB resources."); Logger_.error("Failure to create POSTGRESQL DB resources.");
Logger_.log(E); Logger_.log(E);
@@ -350,7 +352,7 @@ namespace ORM {
} }
break; break;
} }
return false; return Upgrade();
} }
[[nodiscard]] std::string ConvertParams(const std::string & S) const { [[nodiscard]] std::string ConvertParams(const std::string & S) const {
@@ -400,7 +402,7 @@ namespace ORM {
return false; return false;
} }
template<typename T> bool GetRecord( const char * FieldName, const T & Value, RecordType & R) { template<typename T> bool GetRecord(field_name_t FieldName, const T & Value, RecordType & R) {
try { try {
assert( FieldNames_.find(FieldName) != FieldNames_.end() ); assert( FieldNames_.find(FieldName) != FieldNames_.end() );
@@ -438,7 +440,7 @@ namespace ORM {
typedef std::vector<std::string> StringVec; typedef std::vector<std::string> StringVec;
template < typename T, template < typename T,
typename T0, typename T1> bool GR(const char *FieldName, T & R,T0 &V0, T1 &V1) { typename T0, typename T1> bool GR(field_name_t FieldName, T & R,T0 &V0, T1 &V1) {
try { try {
assert( FieldNames_.find(FieldName) != FieldNames_.end() ); assert( FieldNames_.find(FieldName) != FieldNames_.end() );
@@ -495,7 +497,7 @@ namespace ORM {
return false; return false;
} }
template <typename T> bool UpdateRecord( const char *FieldName, const T & Value, const RecordType & R) { template <typename T> bool UpdateRecord(field_name_t FieldName, const T & Value, const RecordType & R) {
try { try {
assert( FieldNames_.find(FieldName) != FieldNames_.end() ); assert( FieldNames_.find(FieldName) != FieldNames_.end() );
@@ -522,7 +524,7 @@ namespace ORM {
return false; return false;
} }
template <typename T> bool ReplaceRecord( const char *FieldName, const T & Value, RecordType & R) { template <typename T> bool ReplaceRecord(field_name_t FieldName, const T & Value, RecordType & R) {
try { try {
if(Exists(FieldName, Value)) { if(Exists(FieldName, Value)) {
return UpdateRecord(FieldName,Value,R); return UpdateRecord(FieldName,Value,R);
@@ -534,7 +536,7 @@ namespace ORM {
return false; return false;
} }
template <typename T> bool GetNameAndDescription(const char *FieldName, const T & Value, std::string & Name, std::string & Description ) { template <typename T> bool GetNameAndDescription(field_name_t FieldName, const T & Value, std::string & Name, std::string & Description ) {
try { try {
assert( FieldNames_.find(FieldName) != FieldNames_.end() ); assert( FieldNames_.find(FieldName) != FieldNames_.end() );
Poco::Data::Session Session = Pool_.get(); Poco::Data::Session Session = Pool_.get();
@@ -561,7 +563,7 @@ namespace ORM {
return false; return false;
} }
template <typename T> bool DeleteRecord( const char *FieldName, const T & Value) { template <typename T> bool DeleteRecord(field_name_t FieldName, const T & Value) {
try { try {
assert( FieldNames_.find(FieldName) != FieldNames_.end() ); assert( FieldNames_.find(FieldName) != FieldNames_.end() );
@@ -599,7 +601,7 @@ namespace ORM {
return false; return false;
} }
bool Exists(const char *FieldName, const std::string & Value) { bool Exists(field_name_t FieldName, const std::string & Value) {
try { try {
assert( FieldNames_.find(FieldName) != FieldNames_.end() ); assert( FieldNames_.find(FieldName) != FieldNames_.end() );
@@ -616,7 +618,7 @@ namespace ORM {
bool Iterate( std::function<bool(const RecordType &R)> F) { bool Iterate( std::function<bool(const RecordType &R)> F) {
try { try {
uint64_t Offset=1; uint64_t Offset=0;
uint64_t Batch=50; uint64_t Batch=50;
bool Done=false; bool Done=false;
while(!Done) { while(!Done) {
@@ -691,7 +693,7 @@ namespace ORM {
return 0; return 0;
} }
template <typename X> bool ManipulateVectorMember( X T, const char *FieldName, std::string & ParentUUID, std::string & ChildUUID, bool Add) { template <typename X> bool ManipulateVectorMember( X T, field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID, bool Add) {
try { try {
assert( FieldNames_.find(FieldName) != FieldNames_.end() ); assert( FieldNames_.find(FieldName) != FieldNames_.end() );
@@ -751,89 +753,89 @@ namespace ORM {
return true; return true;
} }
inline bool AddChild( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) { inline bool AddChild(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::children, FieldName, ParentUUID, ChildUUID, true); return ManipulateVectorMember(&RecordType::children, FieldName, ParentUUID, ChildUUID, true);
} }
inline bool DeleteChild( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) { inline bool DeleteChild(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::children, FieldName, ParentUUID, ChildUUID, false); return ManipulateVectorMember(&RecordType::children, FieldName, ParentUUID, ChildUUID, false);
} }
inline bool AddLocation( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) { inline bool AddLocation(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::locations, FieldName, ParentUUID, ChildUUID, true); return ManipulateVectorMember(&RecordType::locations, FieldName, ParentUUID, ChildUUID, true);
} }
inline bool DeleteLocation( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) { inline bool DeleteLocation(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::locations, FieldName, ParentUUID, ChildUUID, false); return ManipulateVectorMember(&RecordType::locations, FieldName, ParentUUID, ChildUUID, false);
} }
inline bool AddContact( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) { inline bool AddContact(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::contacts, FieldName, ParentUUID, ChildUUID, true); return ManipulateVectorMember(&RecordType::contacts, FieldName, ParentUUID, ChildUUID, true);
} }
inline bool DeleteContact( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) { inline bool DeleteContact(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::contacts, FieldName, ParentUUID, ChildUUID, false); return ManipulateVectorMember(&RecordType::contacts, FieldName, ParentUUID, ChildUUID, false);
} }
inline bool AddVenue( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) { inline bool AddVenue(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::venues, FieldName, ParentUUID, ChildUUID, true); return ManipulateVectorMember(&RecordType::venues, FieldName, ParentUUID, ChildUUID, true);
} }
inline bool DeleteVenue( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) { inline bool DeleteVenue(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::venues, FieldName, ParentUUID, ChildUUID, false); return ManipulateVectorMember(&RecordType::venues, FieldName, ParentUUID, ChildUUID, false);
} }
inline bool AddDevice( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) { inline bool AddDevice(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::devices, FieldName, ParentUUID, ChildUUID, true); return ManipulateVectorMember(&RecordType::devices, FieldName, ParentUUID, ChildUUID, true);
} }
inline bool DeleteDevice( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) { inline bool DeleteDevice(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::devices, FieldName, ParentUUID, ChildUUID, false); return ManipulateVectorMember(&RecordType::devices, FieldName, ParentUUID, ChildUUID, false);
} }
inline bool AddEntity( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) { inline bool AddEntity(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::entities, FieldName, ParentUUID, ChildUUID, true); return ManipulateVectorMember(&RecordType::entities, FieldName, ParentUUID, ChildUUID, true);
} }
inline bool DeleteEntity( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) { inline bool DeleteEntity(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::entities, FieldName, ParentUUID, ChildUUID, false); return ManipulateVectorMember(&RecordType::entities, FieldName, ParentUUID, ChildUUID, false);
} }
inline bool AddUser( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) { inline bool AddUser(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::users, FieldName, ParentUUID, ChildUUID, true); return ManipulateVectorMember(&RecordType::users, FieldName, ParentUUID, ChildUUID, true);
} }
inline bool DelUser( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) { inline bool DelUser(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::users, FieldName, ParentUUID, ChildUUID, false); return ManipulateVectorMember(&RecordType::users, FieldName, ParentUUID, ChildUUID, false);
} }
inline bool AddInUse(const char *FieldName, std::string & ParentUUID, const std::string & Prefix, const std::string & ChildUUID) { inline bool AddInUse(field_name_t FieldName, std::string & ParentUUID, const std::string & Prefix, const std::string & ChildUUID) {
std::string FakeUUID{ Prefix + ":" + ChildUUID}; std::string FakeUUID{ Prefix + ":" + ChildUUID};
return ManipulateVectorMember(&RecordType::inUse,FieldName, ParentUUID, FakeUUID, true); return ManipulateVectorMember(&RecordType::inUse,FieldName, ParentUUID, FakeUUID, true);
} }
inline bool DeleteInUse(const char *FieldName, std::string & ParentUUID, const std::string & Prefix, const std::string & ChildUUID) { inline bool DeleteInUse(field_name_t FieldName, std::string & ParentUUID, const std::string & Prefix, const std::string & ChildUUID) {
std::string FakeUUID{ Prefix + ":" + ChildUUID}; std::string FakeUUID{ Prefix + ":" + ChildUUID};
return ManipulateVectorMember(&RecordType::inUse,FieldName, ParentUUID, FakeUUID, false); return ManipulateVectorMember(&RecordType::inUse,FieldName, ParentUUID, FakeUUID, false);
} }
inline bool DeleteContact(const char *FieldName, std::string & ParentUUID, const std::string & ChildUUID) { inline bool DeleteContact(field_name_t FieldName, std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::contacts,FieldName, ParentUUID, ChildUUID, false); return ManipulateVectorMember(&RecordType::contacts,FieldName, ParentUUID, ChildUUID, false);
} }
inline bool AddContact(const char *FieldName, std::string & ParentUUID, const std::string & ChildUUID) { inline bool AddContact(field_name_t FieldName, std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::contacts,FieldName, ParentUUID, ChildUUID, true); return ManipulateVectorMember(&RecordType::contacts,FieldName, ParentUUID, ChildUUID, true);
} }
inline bool DeleteLocation(const char *FieldName, std::string & ParentUUID, const std::string & ChildUUID) { inline bool DeleteLocation(field_name_t FieldName, std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::locations,FieldName, ParentUUID, ChildUUID, false); return ManipulateVectorMember(&RecordType::locations,FieldName, ParentUUID, ChildUUID, false);
} }
inline bool AddLocation(const char *FieldName, std::string & ParentUUID, const std::string & ChildUUID) { inline bool AddLocation(field_name_t FieldName, std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::locations,FieldName, ParentUUID, ChildUUID, true); return ManipulateVectorMember(&RecordType::locations,FieldName, ParentUUID, ChildUUID, true);
} }
inline bool GetInUse(const char *FieldName, std::string & UUID, std::vector<std::string> & UUIDs ) { inline bool GetInUse(field_name_t FieldName, const std::string & UUID, std::vector<std::string> & UUIDs ) {
RecordType R; RecordType R;
if(GetRecord(FieldName,UUID,R)) { if(GetRecord(FieldName,UUID,R)) {
UUIDs = R.inUse; UUIDs = R.inUse;