mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-29 17:52:28 +00:00
Adding locations for venue.
This commit is contained in:
@@ -211,6 +211,49 @@ namespace OpenWifi {
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef std::tuple<std::string,std::string,std::string> triplet_t;
|
||||
|
||||
inline void AddLocationTriplet(const std::string &id, std::vector<triplet_t> & IDs) {
|
||||
ProvObjects::Location L;
|
||||
if(StorageService()->LocationDB().GetRecord("id",id,L)) {
|
||||
IDs.emplace_back(std::make_tuple(L.info.name,L.info.description,L.info.id));
|
||||
}
|
||||
}
|
||||
|
||||
inline void AddLocationTriplet(const std::vector<std::string> &id, std::vector<triplet_t> & IDs) {
|
||||
for(const auto &i:id)
|
||||
AddLocationTriplet(i,IDs);
|
||||
}
|
||||
|
||||
inline void GetLocationsForEntity(const std::string &ID, std::vector<triplet_t> & IDs) {
|
||||
ProvObjects::Entity Existing;
|
||||
if(StorageService()->EntityDB().template GetRecord("id",ID,Existing)) {
|
||||
if(!Existing.locations.empty()) {
|
||||
AddLocationTriplet(Existing.locations,IDs);
|
||||
}
|
||||
if(!Existing.parent.empty()) {
|
||||
GetLocationsForEntity(Existing.parent,IDs);
|
||||
}
|
||||
if(ID==EntityDB::RootUUID())
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
inline void GetLocationsForVenue(const std::string &ID, std::vector<triplet_t> & IDs) {
|
||||
ProvObjects::Venue Existing;
|
||||
if(StorageService()->VenueDB().template GetRecord("id",ID,Existing)) {
|
||||
if(!Existing.location.empty()) {
|
||||
AddLocationTriplet(Existing.location,IDs);
|
||||
}
|
||||
if(!Existing.parent.empty()) {
|
||||
GetLocationsForVenue(Existing.parent,IDs);
|
||||
}
|
||||
if(!Existing.entity.empty()) {
|
||||
GetLocationsForEntity(Existing.entity,IDs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename DB> void ListHandler(const char *BlockName,DB & DBInstance, RESTAPIHandler & R) {
|
||||
auto Entity = R.GetParameter("entity", "");
|
||||
auto Venue = R.GetParameter("venue", "");
|
||||
@@ -218,6 +261,25 @@ namespace OpenWifi {
|
||||
typedef typename DB::RecordVec RecVec;
|
||||
typedef typename DB::RecordName RecType;
|
||||
|
||||
if constexpr(std::is_same_v<RecType,ProvObjects::Venue>) {
|
||||
auto LocationsForVenue = R.GetParameter("locationsForVenue","");
|
||||
if(!LocationsForVenue.empty()) {
|
||||
std::vector<triplet_t> IDs;
|
||||
GetLocationsForVenue(LocationsForVenue,IDs);
|
||||
Poco::JSON::Array A;
|
||||
for(const auto &[name,description,uuid]:IDs) {
|
||||
Poco::JSON::Object O;
|
||||
O.set("name", name);
|
||||
O.set("description",description);
|
||||
O.set("uuid",uuid);
|
||||
A.add(O);
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("locations",A);
|
||||
return R.ReturnObject(Answer);
|
||||
}
|
||||
}
|
||||
|
||||
if(!R.QB_.Select.empty()) {
|
||||
return ReturnRecordList<decltype(DBInstance),
|
||||
RecType>(BlockName, DBInstance, R);
|
||||
|
||||
@@ -238,6 +238,13 @@ namespace OpenWifi{
|
||||
Existing.deviceConfiguration = MoveToConfigurations;
|
||||
}
|
||||
|
||||
std::string ErrorText;
|
||||
auto ObjectsToCreate = CreateObjects(NewObject, *this, ErrorText);
|
||||
|
||||
if(!ErrorText.empty()) {
|
||||
return BadRequest(ErrorText);
|
||||
}
|
||||
|
||||
if(StorageService()->VenueDB().UpdateRecord("id", UUID, Existing)) {
|
||||
MoveUsage(StorageService()->ContactDB(),DB_,MoveFromContacts, MoveToContacts, Existing.info.id);
|
||||
MoveUsage(StorageService()->LocationDB(),DB_,MoveFromLocation, MoveToLocation, Existing.info.id);
|
||||
|
||||
@@ -3076,10 +3076,10 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
inline Poco::Logger & GetLogger(const std::string &Name) {
|
||||
static auto initilized = false;
|
||||
static auto initialized = false;
|
||||
|
||||
if(!initilized) {
|
||||
initilized = true;
|
||||
if(!initialized) {
|
||||
initialized = true;
|
||||
InitializeLoggingSystem();
|
||||
}
|
||||
return Poco::Logger::get(Name);
|
||||
@@ -3237,9 +3237,9 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
auto i=Services_.begin();
|
||||
auto Now = (uint64_t )std::time(nullptr);
|
||||
auto now = OpenWifi::Now();
|
||||
for(;i!=Services_.end();) {
|
||||
if((Now - i->second.LastUpdate)>60) {
|
||||
if((now - i->second.LastUpdate)>60) {
|
||||
i = Services_.erase(i);
|
||||
} else
|
||||
++i;
|
||||
|
||||
Reference in New Issue
Block a user