Adding locale to inventory

This commit is contained in:
stephb9959
2022-02-24 11:13:39 -08:00
parent 73a096b0ad
commit 72dd336b08
9 changed files with 33 additions and 7 deletions

2
build
View File

@@ -1 +1 @@
35
37

View File

@@ -573,6 +573,10 @@ components:
- venue
- entity
- subscriber
locale:
type: string
minLength: 2
maxLength: 2
InventoryTagList:
type: object

View File

@@ -55,8 +55,12 @@ namespace OpenWifi {
DeviceType = PingMessage->get(uCentralProtocol::COMPATIBLE).toString();
}
}
std::string Locale;
if(PayloadObj->has("locale"))
Locale = PayloadObj->get("locale").toString();
if (!SerialNumber.empty()) {
StorageService()->InventoryDB().CreateFromConnection(SerialNumber, ConnectedIP, DeviceType);
StorageService()->InventoryDB().CreateFromConnection(SerialNumber, ConnectedIP, DeviceType, Locale);
}
}
} catch (const Poco::Exception &E) {

View File

@@ -48,6 +48,7 @@ namespace OpenWifi::GWObjects {
field_to_json(Obj,"subscriber", subscriber);
field_to_json(Obj,"entity", entity);
field_to_json(Obj,"modified", modified);
field_to_json(Obj,"locale", locale);
}
void Device::to_json_with_status(Poco::JSON::Object &Obj) const {
@@ -86,6 +87,7 @@ namespace OpenWifi::GWObjects {
field_from_json(Obj,"compatible",Compatible);
field_from_json(Obj,"subscriber", subscriber);
field_from_json(Obj,"entity", entity);
field_from_json(Obj,"locale", locale);
return true;
} catch (const Poco::Exception &E) {
}
@@ -200,6 +202,7 @@ namespace OpenWifi::GWObjects {
field_to_json(Obj,"websocketPackets", websocketPackets);
field_to_json(Obj,"kafkaClients", kafkaClients);
field_to_json(Obj,"kafkaPackets", kafkaPackets);
field_to_json(Obj,"locale", locale);
switch(VerifiedCertificate) {
case NO_CERTIFICATE:

View File

@@ -37,6 +37,7 @@ namespace OpenWifi::GWObjects {
uint64_t webSocketClients=0;
uint64_t kafkaPackets=0;
uint64_t websocketPackets=0;
std::string locale;
void to_json(Poco::JSON::Object &Obj) const;
};
@@ -62,6 +63,7 @@ namespace OpenWifi::GWObjects {
std::string subscriber;
std::string entity;
uint64_t modified=0;
std::string locale;
void to_json(Poco::JSON::Object &Obj) const;
void to_json_with_status(Poco::JSON::Object &Obj) const;

View File

@@ -311,6 +311,7 @@ namespace OpenWifi::ProvObjects {
field_to_json( Obj,"managementPolicy",managementPolicy);
field_to_json( Obj,"state",state);
field_to_json( Obj,"devClass",devClass);
field_to_json( Obj,"locale",locale);
}
bool InventoryTag::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -330,6 +331,8 @@ namespace OpenWifi::ProvObjects {
field_from_json( Obj,"managementPolicy",managementPolicy);
field_from_json( Obj,"state",state);
field_from_json( Obj,"devClass",devClass);
field_from_json( Obj,"locale",locale);
return true;
} catch(...) {

View File

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

View File

@@ -41,7 +41,8 @@ namespace OpenWifi {
ORM::Field{"tags",ORM::FieldType::FT_TEXT},
ORM::Field{"managementPolicy",ORM::FieldType::FT_TEXT},
ORM::Field{"state",ORM::FieldType::FT_TEXT},
ORM::Field{"devClass",ORM::FieldType::FT_TEXT}
ORM::Field{"devClass",ORM::FieldType::FT_TEXT},
ORM::Field{"locale",ORM::FieldType::FT_TEXT}
};
static ORM::IndexVec InventoryDB_Indexes{
@@ -57,8 +58,12 @@ namespace OpenWifi {
bool InventoryDB::Upgrade(uint32_t from, uint32_t &to) {
to = Version();
std::vector<std::string> Script{ "alter table " + TableName_ + " add column state text" ,
"alter table " + TableName_ + " add column devClass text" };
std::vector<std::string> Script{
"alter table " + TableName_ + " add column state text" ,
"alter table " + TableName_ + " add column locale varchar(16)" ,
"alter table " + TableName_ + " add column devClass text"
};
for(const auto &i:Script) {
try {
auto Session = Pool_.get();
@@ -77,7 +82,8 @@ namespace OpenWifi {
bool InventoryDB::CreateFromConnection( const std::string &SerialNumber,
const std::string &ConnectionInfo,
const std::string &DeviceType) {
const std::string &DeviceType,
const std::string &Locale) {
ProvObjects::InventoryTag ExistingDevice;
if(!GetRecord("serialNumber",SerialNumber,ExistingDevice)) {
@@ -95,6 +101,7 @@ namespace OpenWifi {
NewDevice.info.notes.push_back(SecurityObjects::NoteInfo{.created=Now,.createdBy="*system",.note="Auto discovered"});
NewDevice.serialNumber = SerialNumber;
NewDevice.deviceType = DeviceType;
NewDevice.locale = Locale;
nlohmann::json StateDoc;
StateDoc["method"] = "auto-discovery";
StateDoc["date"] = std::time(nullptr);

View File

@@ -33,13 +33,15 @@ namespace OpenWifi {
std::string,
std::string,
std::string,
std::string,
std::string
> InventoryDBRecordType;
class InventoryDB : public ORM::DB<InventoryDBRecordType, ProvObjects::InventoryTag> {
public:
InventoryDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
bool CreateFromConnection(const std::string & SerialNumber, const std::string & ConnectionInfo, const std::string & DeviceType);
bool CreateFromConnection(const std::string & SerialNumber, const std::string & ConnectionInfo,
const std::string & DeviceType, const std::string &Locale );
bool FindFirmwareOptions(std::string & SerialNumber, ProvObjects::FIRMWARE_UPGRADE_RULES & Rules);
static bool FindFirmwareOptionsForEntity(const std::string & EntityUUID, ProvObjects::FIRMWARE_UPGRADE_RULES & Rules);
static bool FindFirmwareOptionsForVenue(const std::string & VenueUUID, ProvObjects::FIRMWARE_UPGRADE_RULES & Rules);