Fixing DB offset/limit computation.

This commit is contained in:
stephb9959
2021-11-17 15:53:38 -08:00
parent e87bdc9440
commit e794647469
12 changed files with 128 additions and 58 deletions

2
build
View File

@@ -1 +1 @@
7
9

View File

@@ -440,11 +440,11 @@ namespace OpenWifi::ProvObjects {
return false;
}
void UserList::to_json(Poco::JSON::Object &Obj) const {
void UuidList::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj, "list", list);
}
bool UserList::from_json(const Poco::JSON::Object::Ptr &Obj) {
bool UuidList::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "list", list);
return true;
@@ -454,14 +454,46 @@ namespace OpenWifi::ProvObjects {
return false;
}
void field_to_json(Poco::JSON::Object &Obj, const char * FieldName, ACLACCESS A) {
switch(A) {
case READ: Obj.set(FieldName,"read"); break;
case MODIFY: Obj.set(FieldName,"modify"); break;
case CREATE: Obj.set(FieldName,"create"); break;
case DELETE: Obj.set(FieldName,"delete"); break;
case NONE:
default:
Obj.set(FieldName,"none");
}
}
void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char * FieldName, ACLACCESS &A) {
if(Obj->has(FieldName)) {
auto V = Obj->getValue<std::string>(FieldName);
if(V=="read")
A = READ;
else if(V=="modify")
A = MODIFY;
else if(V=="create")
A = CREATE;
else if(V=="delete")
A = DELETE;
else if(V=="none")
A = NONE;
else
throw Poco::Exception("invalid JSON");
}
}
void ObjectACL::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj, "users", users);
RESTAPI_utils::field_to_json(Obj, "users", users);
RESTAPI_utils::field_to_json(Obj, "roles", roles);
field_to_json(Obj, "access", access);
}
bool ObjectACL::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "users", users);
RESTAPI_utils::field_from_json(Obj, "users", users);
RESTAPI_utils::field_from_json(Obj, "roles", roles);
field_from_json(Obj, "access", access);
return true;
} catch(...) {
@@ -471,12 +503,12 @@ namespace OpenWifi::ProvObjects {
}
void ObjectACLList::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj, "list", list);
RESTAPI_utils::field_to_json(Obj, "list", list);
}
bool ObjectACLList::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "list", list);
RESTAPI_utils::field_from_json(Obj, "list", list);
return true;
} catch(...) {
@@ -484,23 +516,54 @@ namespace OpenWifi::ProvObjects {
return false;
}
std::string to_string(VISIBILITY A) {
switch(A) {
case PUBLIC: return "public";
case SELECT: return "select";
case PRIVATE:
default:
return "private";
}
}
void field_to_json(Poco::JSON::Object &Obj, const char * FieldName, VISIBILITY A) {
Obj.set(FieldName,to_string(A));
}
VISIBILITY visibility_from_string(const std::string &V) {
if(V=="public")
return PUBLIC;
else if(V=="select")
return SELECT;
else if(V=="private")
return PRIVATE;
throw Poco::Exception("invalid json");
}
void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char * FieldName, VISIBILITY &A) {
if(Obj->has(FieldName)) {
auto V = Obj->getValue<std::string>(FieldName);
A = visibility_from_string(V);
}
}
void Map::to_json(Poco::JSON::Object &Obj) const {
info.to_json(Obj);
field_to_json( Obj,"data",data);
field_to_json( Obj,"entity",entity);
field_to_json( Obj,"creator",creator);
RESTAPI_utils::field_to_json( Obj,"data",data);
RESTAPI_utils::field_to_json( Obj,"entity",entity);
RESTAPI_utils::field_to_json( Obj,"creator",creator);
field_to_json( Obj,"visibility",visibility);
field_to_json( Obj,"access",access);
RESTAPI_utils::field_to_json( Obj,"access",access);
}
bool Map::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
info.from_json(Obj);
field_from_json( Obj,"data",data);
field_from_json( Obj,"entity",entity);
field_from_json( Obj,"creator",creator);
RESTAPI_utils::field_from_json( Obj,"data",data);
RESTAPI_utils::field_from_json( Obj,"entity",entity);
RESTAPI_utils::field_from_json( Obj,"creator",creator);
field_from_json( Obj,"visibility",visibility);
field_from_json( Obj,"access",access);
RESTAPI_utils::field_from_json( Obj,"access",access);
return true;
} catch(...) {
@@ -509,12 +572,12 @@ namespace OpenWifi::ProvObjects {
}
void MapList::to_json(Poco::JSON::Object &Obj) const {
field_to_json( Obj,"list",list);
RESTAPI_utils::field_to_json( Obj,"list",list);
}
bool MapList::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json( Obj,"list",list);
RESTAPI_utils::field_from_json( Obj,"list",list);
return true;
} catch(...) {
@@ -566,4 +629,5 @@ namespace OpenWifi::ProvObjects {
return true;
}
};
}

View File

@@ -324,16 +324,21 @@ namespace OpenWifi::ProvObjects {
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct UserList {
struct UuidList {
std::vector<std::string> list;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
enum ACLACCESS {
NONE, READ, MODIFY, CREATE, DELETE
};
struct ObjectACL {
UserList users;
std::string access;
UuidList users;
UuidList roles;
ACLACCESS access = NONE;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
@@ -346,12 +351,19 @@ namespace OpenWifi::ProvObjects {
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
enum VISIBILITY {
PUBLIC, PRIVATE, SELECT
};
std::string to_string(VISIBILITY A);
VISIBILITY visibility_from_string(const std::string &V);
struct Map {
ObjectInfo info;
std::string data;
std::string entity;
std::string creator;
std::string visibility;
VISIBILITY visibility = PRIVATE;
ObjectACLList access;
void to_json(Poco::JSON::Object &Obj) const;
@@ -367,7 +379,6 @@ namespace OpenWifi::ProvObjects {
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

@@ -2,8 +2,7 @@
// Created by stephane bourque on 2021-09-14.
//
#ifndef OWPROV_CONFIGURATIONVALIDATOR_H
#define OWPROV_CONFIGURATIONVALIDATOR_H
#pragma once
#include <nlohmann/json-schema.hpp>
#include "framework/MicroService.h"
@@ -43,4 +42,3 @@ namespace OpenWifi {
inline bool ValidateUCentralConfiguration(const std::string &C, std::string &Error) { return ConfigurationValidator::instance()->Validate(C, Error); }
}
#endif //OWPROV_CONFIGURATIONVALIDATOR_H

View File

@@ -2,8 +2,7 @@
// Created by stephane bourque on 2021-10-08.
//
#ifndef OWPROV_COUNTRYCODES_H
#define OWPROV_COUNTRYCODES_H
#pragma once
#include <vector>
#include <string>
@@ -270,4 +269,3 @@ namespace OpenWifi {
}
#endif //OWPROV_COUNTRYCODES_H

View File

@@ -5,8 +5,8 @@
// Created by Stephane Bourque on 2021-03-04.
// Arilia Wireless Inc.
//
#ifndef UCENTRALGW_KAFKA_TOPICS_H
#define UCENTRALGW_KAFKA_TOPICS_H
#pragma once
namespace OpenWifi::KafkaTopics {
static const std::string HEALTHCHECK{"healthcheck"};
@@ -37,4 +37,3 @@ namespace OpenWifi::KafkaTopics {
}
}
#endif // UCENTRALGW_KAFKA_TOPICS_H

View File

@@ -803,6 +803,20 @@ namespace OpenWifi::Utils {
return R;
}
[[nodiscard]] inline std::string IntToSerialNumber(uint64_t S) {
char b[16];
for(int i=0;i<12;++i) {
int B = (S & 0x0f);
if(B<10)
b[11-i] = B+'0';
else
b[11-i] = B - 10 + 'a';
S >>= 4 ;
}
b[12]=0;
return b;
}
[[nodiscard]] inline bool SerialNumberMatch(const std::string &S1, const std::string &S2, int Bits=2) {
auto S1_i = SerialNumberToInt(S1);
@@ -1904,7 +1918,7 @@ namespace OpenWifi {
QB_.SerialNumber = GetParameter(RESTAPI::Protocol::SERIALNUMBER, "");
QB_.StartDate = GetParameter(RESTAPI::Protocol::STARTDATE, 0);
QB_.EndDate = GetParameter(RESTAPI::Protocol::ENDDATE, 0);
QB_.Offset = GetParameter(RESTAPI::Protocol::OFFSET, 1);
QB_.Offset = GetParameter(RESTAPI::Protocol::OFFSET, 0);
QB_.Limit = GetParameter(RESTAPI::Protocol::LIMIT, 100);
QB_.Filter = GetParameter(RESTAPI::Protocol::FILTER, "");
QB_.Select = GetParameter(RESTAPI::Protocol::SELECT, "");
@@ -1916,7 +1930,7 @@ namespace OpenWifi {
QB_.AdditionalInfo = GetBoolParameter(RESTAPI::Protocol::WITHEXTENDEDINFO,false);
if(QB_.Offset<1)
QB_.Offset=1;
QB_.Offset=0;
return true;
}

View File

@@ -2,8 +2,7 @@
// Created by stephane bourque on 2021-09-12.
//
#ifndef OWPROV_RESTAPI_ERRORS_H
#define OWPROV_RESTAPI_ERRORS_H
#pragma once
namespace OpenWifi::RESTAPI::Errors {
static const std::string MissingUUID{"Missing UUID."};
@@ -62,4 +61,3 @@ namespace OpenWifi::RESTAPI::Errors {
static const std::string ExpiredToken{"Token has expired, user must login."};
}
#endif //OWPROV_RESTAPI_ERRORS_H

View File

@@ -6,8 +6,7 @@
// Arilia Wireless Inc.
//
#ifndef UCENTRALGW_RESTAPI_PROTOCOL_H
#define UCENTRALGW_RESTAPI_PROTOCOL_H
#pragma once
namespace OpenWifi::RESTAPI::Protocol {
static const char * CAPABILITIES = "capabilities";
@@ -136,5 +135,3 @@ namespace OpenWifi::RESTAPI::Protocol {
static const char * UI = "UI";
}
#endif // UCENTRALGW_RESTAPI_PROTOCOL_H

View File

@@ -2,8 +2,7 @@
// Created by stephane bourque on 2021-10-06.
//
#ifndef OPENWIFI_STORAGE_H
#define OPENWIFI_STORAGE_H
#pragma once
#include "Poco/Data/Session.h"
#include "Poco/Data/SessionPool.h"
@@ -54,13 +53,13 @@ namespace OpenWifi {
[[nodiscard]] inline std::string ComputeRange(uint64_t From, uint64_t HowMany) {
if(dbType_==sqlite) {
return " LIMIT " + std::to_string(From-1) + ", " + std::to_string(HowMany) + " ";
return " LIMIT " + std::to_string(From) + ", " + std::to_string(HowMany) + " ";
} else if(dbType_==pgsql) {
return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From-1) + " ";
return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From) + " ";
} else if(dbType_==mysql) {
return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From-1) + " ";
return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From) + " ";
}
return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From-1) + " ";
return " LIMIT " + std::to_string(HowMany) + " OFFSET " + std::to_string(From) + " ";
}
inline std::string ConvertParams(const std::string & S) const {
@@ -165,5 +164,3 @@ namespace OpenWifi {
#endif
}
#endif //OPENWIFI_STORAGE_H

View File

@@ -6,8 +6,7 @@
// Arilia Wireless Inc.
//
#ifndef __OPENWIFI_ORM_H__
#define __OPENWIFI_ORM_H__
#pragma once
#include <string>
#include <memory>
@@ -755,4 +754,3 @@ namespace ORM {
};
}
#endif

View File

@@ -5,9 +5,7 @@
// Created by Stephane Bourque on 2021-03-04.
// Arilia Wireless Inc.
//
#ifndef UCENTRALGW_UCENTRALPROTOCOL_H
#define UCENTRALGW_UCENTRALPROTOCOL_H
#pragma once
#include "Poco/String.h"
@@ -130,5 +128,3 @@ namespace OpenWifi::uCentralProtocol {
return ET_UNKNOWN;
};
}
#endif // UCENTRALGW_UCENTRALPROTOCOL_H