mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-11-02 11:37:54 +00:00
Fixing SerialNumber cache
This commit is contained in:
@@ -553,6 +553,13 @@ components:
|
|||||||
format: uuid
|
format: uuid
|
||||||
state:
|
state:
|
||||||
type: string
|
type: string
|
||||||
|
devClass:
|
||||||
|
type: string
|
||||||
|
enum:4
|
||||||
|
- any
|
||||||
|
- venue
|
||||||
|
- entity
|
||||||
|
- subscriber
|
||||||
|
|
||||||
InventoryTagList:
|
InventoryTagList:
|
||||||
type: object
|
type: object
|
||||||
@@ -1622,6 +1629,7 @@ paths:
|
|||||||
|
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
|
description: success
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
@@ -1867,7 +1875,7 @@ paths:
|
|||||||
- in: query
|
- in: query
|
||||||
description: Return only maps shared with Me
|
description: Return only maps shared with Me
|
||||||
name: sharedWithMe
|
name: sharedWithMe
|
||||||
scmema:
|
schema:
|
||||||
type: boolean
|
type: boolean
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,9 @@ namespace OpenWifi{
|
|||||||
auto Results = Response->get("results").extract<Poco::JSON::Object::Ptr>();
|
auto Results = Response->get("results").extract<Poco::JSON::Object::Ptr>();
|
||||||
auto Status = Results->get("status").extract<Poco::JSON::Object::Ptr>();
|
auto Status = Results->get("status").extract<Poco::JSON::Object::Ptr>();
|
||||||
auto Rejected = Status->getArray("rejected");
|
auto Rejected = Status->getArray("rejected");
|
||||||
for(const auto &i:*Rejected)
|
std::transform(Rejected->begin(),Rejected->end(),std::back_inserter(Warnings), [](auto i) -> auto { return i.toString(); });
|
||||||
Warnings.push_back(i.toString());
|
// for(const auto &i:*Rejected)
|
||||||
|
// Warnings.push_back(i.toString());
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
}
|
}
|
||||||
@@ -136,6 +137,11 @@ namespace OpenWifi{
|
|||||||
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
|
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool ValidDevClass(const std::string &D) {
|
||||||
|
const static std::vector<std::string> Classes{ "any", "entity", "subscriber" , "venue" };
|
||||||
|
return std::find(cbegin(Classes), cend(Classes), D)!=cend(Classes);
|
||||||
|
}
|
||||||
|
|
||||||
void RESTAPI_inventory_handler::DoPost() {
|
void RESTAPI_inventory_handler::DoPost() {
|
||||||
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER,"");
|
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER,"");
|
||||||
if(SerialNumber.empty()) {
|
if(SerialNumber.empty()) {
|
||||||
@@ -156,6 +162,10 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!ValidDevClass(NewObject.devClass)) {
|
||||||
|
return BadRequest(RESTAPI::Errors::InvalidDeviceClass);
|
||||||
|
}
|
||||||
|
|
||||||
if(!ProvObjects::CreateObjectInfo(Obj, UserInfo_.userinfo, NewObject.info)) {
|
if(!ProvObjects::CreateObjectInfo(Obj, UserInfo_.userinfo, NewObject.info)) {
|
||||||
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
||||||
}
|
}
|
||||||
@@ -192,6 +202,25 @@ namespace OpenWifi{
|
|||||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!NewObject.venue.empty()) {
|
||||||
|
nlohmann::json state;
|
||||||
|
state["method"] = "assignedTo";
|
||||||
|
state["venue"] = NewObject.venue;
|
||||||
|
state["date"] = std::time(nullptr);
|
||||||
|
NewObject.state = to_string(state);
|
||||||
|
} else if (!NewObject.entity.empty()) {
|
||||||
|
nlohmann::json state;
|
||||||
|
state["method"] = "assignedTo";
|
||||||
|
state["entity"] = NewObject.entity;
|
||||||
|
state["date"] = std::time(nullptr);
|
||||||
|
NewObject.state = to_string(state);
|
||||||
|
} else {
|
||||||
|
nlohmann::json state;
|
||||||
|
state["method"] = "created";
|
||||||
|
state["date"] = std::time(nullptr);
|
||||||
|
NewObject.state = to_string(state);
|
||||||
|
}
|
||||||
|
|
||||||
if(DB_.CreateRecord(NewObject)) {
|
if(DB_.CreateRecord(NewObject)) {
|
||||||
SerialNumberCache()->AddSerialNumber(SerialNumber,NewObject.deviceType);
|
SerialNumberCache()->AddSerialNumber(SerialNumber,NewObject.deviceType);
|
||||||
if (!NewObject.venue.empty())
|
if (!NewObject.venue.empty())
|
||||||
|
|||||||
@@ -297,19 +297,20 @@ namespace OpenWifi::ProvObjects {
|
|||||||
|
|
||||||
void InventoryTag::to_json(Poco::JSON::Object &Obj) const {
|
void InventoryTag::to_json(Poco::JSON::Object &Obj) const {
|
||||||
info.to_json(Obj);
|
info.to_json(Obj);
|
||||||
field_to_json(Obj, "serialNumber", serialNumber);
|
field_to_json( Obj, "serialNumber", serialNumber);
|
||||||
field_to_json(Obj, "venue", venue);
|
field_to_json( Obj, "venue", venue);
|
||||||
field_to_json(Obj, "entity", entity);
|
field_to_json( Obj, "entity", entity);
|
||||||
field_to_json(Obj, "subscriber", subscriber);
|
field_to_json( Obj, "subscriber", subscriber);
|
||||||
field_to_json(Obj, "deviceType", deviceType);
|
field_to_json( Obj, "deviceType", deviceType);
|
||||||
field_to_json(Obj, "qrCode", qrCode);
|
field_to_json( Obj, "qrCode", qrCode);
|
||||||
field_to_json(Obj, "geoCode", geoCode);
|
field_to_json( Obj, "geoCode", geoCode);
|
||||||
field_to_json(Obj, "location", location);
|
field_to_json( Obj, "location", location);
|
||||||
field_to_json(Obj, "contact", contact);
|
field_to_json( Obj, "contact", contact);
|
||||||
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);
|
field_to_json( Obj,"state",state);
|
||||||
|
field_to_json( Obj,"devClass",devClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InventoryTag::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
bool InventoryTag::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||||
@@ -320,7 +321,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
field_from_json( Obj,"entity",entity);
|
field_from_json( Obj,"entity",entity);
|
||||||
field_from_json( Obj,"subscriber",subscriber);
|
field_from_json( Obj,"subscriber",subscriber);
|
||||||
field_from_json( Obj,"deviceType",deviceType);
|
field_from_json( Obj,"deviceType",deviceType);
|
||||||
field_from_json(Obj, "qrCode", qrCode);
|
field_from_json( Obj, "qrCode", qrCode);
|
||||||
field_from_json( Obj,"geoCode",geoCode);
|
field_from_json( Obj,"geoCode",geoCode);
|
||||||
field_from_json( Obj,"location",location);
|
field_from_json( Obj,"location",location);
|
||||||
field_from_json( Obj,"contact",contact);
|
field_from_json( Obj,"contact",contact);
|
||||||
@@ -328,6 +329,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
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);
|
field_from_json( Obj,"state",state);
|
||||||
|
field_from_json( Obj,"devClass",devClass);
|
||||||
return true;
|
return true;
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
|
|
||||||
|
|||||||
@@ -285,6 +285,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
std::string rrm;
|
std::string rrm;
|
||||||
Types::UUID_t managementPolicy;
|
Types::UUID_t managementPolicy;
|
||||||
std::string state;
|
std::string state;
|
||||||
|
std::string devClass;
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@@ -63,5 +63,6 @@ namespace OpenWifi::RESTAPI::Errors {
|
|||||||
static const std::string AuthenticatorVerificationIncomplete{"Authenticator validation is not complete."};
|
static const std::string AuthenticatorVerificationIncomplete{"Authenticator validation is not complete."};
|
||||||
static const std::string SMSCouldNotBeSentRetry{"SMS could not be sent to validate device, try later or change the phone number."};
|
static const std::string SMSCouldNotBeSentRetry{"SMS could not be sent to validate device, try later or change the phone number."};
|
||||||
static const std::string SMSCouldNotValidate{"Code and number could not be validated"};
|
static const std::string SMSCouldNotValidate{"Code and number could not be validated"};
|
||||||
|
static const std::string InvalidDeviceClass{"Invalid device class. Must be: any, venue, entity, or subscriber"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -430,7 +430,6 @@ namespace ORM {
|
|||||||
Cache_->UpdateCache(R);
|
Cache_->UpdateCache(R);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
} catch (const Poco::Exception &E) {
|
} catch (const Poco::Exception &E) {
|
||||||
Logger_.log(E);
|
Logger_.log(E);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ namespace OpenWifi {
|
|||||||
ORM::Field{"rrm",ORM::FieldType::FT_TEXT},
|
ORM::Field{"rrm",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"tags",ORM::FieldType::FT_TEXT},
|
ORM::Field{"tags",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"managementPolicy",ORM::FieldType::FT_TEXT},
|
ORM::Field{"managementPolicy",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"state",ORM::FieldType::FT_TEXT}
|
ORM::Field{"state",ORM::FieldType::FT_TEXT},
|
||||||
|
ORM::Field{"devClass",ORM::FieldType::FT_TEXT}
|
||||||
};
|
};
|
||||||
|
|
||||||
static ORM::IndexVec InventoryDB_Indexes{
|
static ORM::IndexVec InventoryDB_Indexes{
|
||||||
@@ -59,6 +60,7 @@ namespace OpenWifi {
|
|||||||
try {
|
try {
|
||||||
auto Session = Pool_.get();
|
auto Session = Pool_.get();
|
||||||
Session << "alter table " + TableName_ + " add column state text" , Poco::Data::Keywords::now;
|
Session << "alter table " + TableName_ + " add column state text" , Poco::Data::Keywords::now;
|
||||||
|
Session << "alter table " + TableName_ + " add column devClass text" , Poco::Data::Keywords::now;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -71,10 +73,10 @@ namespace OpenWifi {
|
|||||||
bool InventoryDB::CreateFromConnection( const std::string &SerialNumber,
|
bool InventoryDB::CreateFromConnection( const std::string &SerialNumber,
|
||||||
const std::string &ConnectionInfo,
|
const std::string &ConnectionInfo,
|
||||||
const std::string &DeviceType) {
|
const std::string &DeviceType) {
|
||||||
std::string SNum{SerialNumber};
|
|
||||||
ProvObjects::InventoryTag ExistingDevice;
|
ProvObjects::InventoryTag ExistingDevice;
|
||||||
|
|
||||||
if(!GetRecord("serialNumber",SNum,ExistingDevice)) {
|
if(!GetRecord("serialNumber",SerialNumber,ExistingDevice)) {
|
||||||
ProvObjects::InventoryTag NewDevice;
|
ProvObjects::InventoryTag NewDevice;
|
||||||
uint64_t Now = std::time(nullptr);
|
uint64_t Now = std::time(nullptr);
|
||||||
|
|
||||||
@@ -130,7 +132,7 @@ namespace OpenWifi {
|
|||||||
} else {
|
} else {
|
||||||
// Device already exists, do we need to modify anything?
|
// Device already exists, do we need to modify anything?
|
||||||
bool modified=false;
|
bool modified=false;
|
||||||
if(ExistingDevice.deviceType.empty() || ExistingDevice.state=="unknown") {
|
if(ExistingDevice.deviceType != DeviceType) {
|
||||||
ExistingDevice.deviceType = DeviceType;
|
ExistingDevice.deviceType = DeviceType;
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
@@ -155,7 +157,7 @@ namespace OpenWifi {
|
|||||||
}
|
}
|
||||||
if(modified) {
|
if(modified) {
|
||||||
ExistingDevice.info.modified = std::time(nullptr);
|
ExistingDevice.info.modified = std::time(nullptr);
|
||||||
StorageService()->InventoryDB().UpdateRecord("serialNumber", SNum, ExistingDevice);
|
StorageService()->InventoryDB().UpdateRecord("serialNumber", SerialNumber, ExistingDevice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -364,6 +366,7 @@ template<> void ORM::DB< OpenWifi::InventoryDBRecordType, OpenWifi::ProvObjec
|
|||||||
Out.info.tags = OpenWifi::RESTAPI_utils::to_taglist(In.get<17>());
|
Out.info.tags = OpenWifi::RESTAPI_utils::to_taglist(In.get<17>());
|
||||||
Out.managementPolicy = In.get<18>();
|
Out.managementPolicy = In.get<18>();
|
||||||
Out.state = In.get<19>();
|
Out.state = In.get<19>();
|
||||||
|
Out.devClass = In.get<20>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> void ORM::DB< OpenWifi::InventoryDBRecordType, OpenWifi::ProvObjects::InventoryTag>::Convert(const OpenWifi::ProvObjects::InventoryTag &In, OpenWifi::InventoryDBRecordType &Out) {
|
template<> void ORM::DB< OpenWifi::InventoryDBRecordType, OpenWifi::ProvObjects::InventoryTag>::Convert(const OpenWifi::ProvObjects::InventoryTag &In, OpenWifi::InventoryDBRecordType &Out) {
|
||||||
@@ -387,4 +390,5 @@ template<> void ORM::DB< OpenWifi::InventoryDBRecordType, OpenWifi::ProvObjec
|
|||||||
Out.set<17>(OpenWifi::RESTAPI_utils::to_string(In.info.tags));
|
Out.set<17>(OpenWifi::RESTAPI_utils::to_string(In.info.tags));
|
||||||
Out.set<18>(In.managementPolicy);
|
Out.set<18>(In.managementPolicy);
|
||||||
Out.set<19>(In.state);
|
Out.set<19>(In.state);
|
||||||
|
Out.set<20>(In.devClass);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ namespace OpenWifi {
|
|||||||
std::string,
|
std::string,
|
||||||
std::string,
|
std::string,
|
||||||
std::string,
|
std::string,
|
||||||
|
std::string,
|
||||||
std::string
|
std::string
|
||||||
> InventoryDBRecordType;
|
> InventoryDBRecordType;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user