mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-11-02 03:27:51 +00:00
Adding tree import.
This commit is contained in:
@@ -151,17 +151,15 @@ namespace OpenWifi{
|
||||
E.contacts.clear();
|
||||
E.locations.clear();
|
||||
|
||||
if(Storage()->EntityDB().CreateRecord(E)) {
|
||||
if(Storage()->EntityDB().CreateShortCut(E)) {
|
||||
if(UUID==EntityDB::RootUUID())
|
||||
Storage()->EntityDB().CheckForRoot();
|
||||
else {
|
||||
Storage()->EntityDB().AddChild("id",E.parent,E.info.id);
|
||||
}
|
||||
|
||||
ProvObjects::Entity AddedRecord;
|
||||
Storage()->EntityDB().GetRecord("id",E.info.id,AddedRecord);
|
||||
Poco::JSON::Object Answer;
|
||||
AddedRecord.to_json(Answer);
|
||||
E.to_json(Answer);
|
||||
ReturnObject(Request, Answer, Response);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -161,22 +161,9 @@ namespace OpenWifi{
|
||||
for(auto &i:V.info.notes)
|
||||
i.createdBy = UserInfo_.userinfo.email;
|
||||
|
||||
if(Storage()->VenueDB().CreateRecord(V)) {
|
||||
if(!V.parent.empty())
|
||||
Storage()->VenueDB().AddChild("id", V.parent, V.info.id);
|
||||
if(!V.entity.empty())
|
||||
Storage()->EntityDB().AddVenue("id", V.entity, V.info.id);
|
||||
if(!V.location.empty())
|
||||
Storage()->LocationDB().AddInUse("id",V.location, Storage()->VenueDB().Prefix(), V.info.id);
|
||||
if(!V.contact.empty())
|
||||
Storage()->ContactDB().AddInUse("id",V.contact, Storage()->VenueDB().Prefix(), V.info.id);
|
||||
if(!V.managementPolicy.empty())
|
||||
Storage()->PolicyDB().AddInUse("id",V.managementPolicy, Storage()->VenueDB().Prefix(), V.info.id);
|
||||
|
||||
ProvObjects::Venue AddedRecord;
|
||||
Storage()->VenueDB().GetRecord("id",V.info.id,AddedRecord);
|
||||
if(Storage()->VenueDB().CreateShortCut(V)) {
|
||||
Poco::JSON::Object Answer;
|
||||
AddedRecord.to_json(Answer);
|
||||
V.to_json(Answer);
|
||||
ReturnObject(Request, Answer, Response);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,8 @@ namespace OpenWifi {
|
||||
V.info.name = Name;
|
||||
V.info.id = Daemon()->CreateUUID();
|
||||
V.parent = Parent;
|
||||
Storage()->VenueDB().CreateRecord(V);
|
||||
V.info.created = V.info.modified = std::time(nullptr);
|
||||
Storage()->VenueDB().CreateShortCut(V);
|
||||
ImportVenues( Child, V.info.id );
|
||||
}
|
||||
}
|
||||
@@ -129,7 +130,8 @@ namespace OpenWifi {
|
||||
ProvObjects::Entity E;
|
||||
E.info.name = Name;
|
||||
E.info.id = EntityDB::RootUUID();
|
||||
Storage()->EntityDB().CreateRecord(E);
|
||||
E.info.created = E.info.modified = std::time(nullptr);
|
||||
Storage()->EntityDB().CreateShortCut(E);
|
||||
}
|
||||
|
||||
Children = O->getArray("children");
|
||||
@@ -140,7 +142,8 @@ namespace OpenWifi {
|
||||
E.info.name = Name;
|
||||
E.info.id = Daemon()->CreateUUID();
|
||||
E.parent = Parent;
|
||||
Storage()->EntityDB().CreateRecord(E);
|
||||
E.info.created = E.info.modified = std::time(nullptr);
|
||||
Storage()->EntityDB().CreateShortCut(E);
|
||||
ImportTree( Child, E.info.id );
|
||||
}
|
||||
|
||||
@@ -151,10 +154,25 @@ namespace OpenWifi {
|
||||
V.info.name = Name;
|
||||
V.info.id = Daemon()->CreateUUID();
|
||||
V.parent = Parent;
|
||||
Storage()->VenueDB().CreateRecord(V);
|
||||
V.info.created = V.info.modified = std::time(nullptr);
|
||||
Storage()->VenueDB().CreateShortCut(V);
|
||||
ImportVenues( Child, V.info.id );
|
||||
}
|
||||
}
|
||||
|
||||
bool EntityDB::CreateShortCut( ProvObjects::Entity & E) {
|
||||
if(Storage()->EntityDB().CreateRecord(E)) {
|
||||
if(E.info.id==EntityDB::RootUUID())
|
||||
Storage()->EntityDB().CheckForRoot();
|
||||
else {
|
||||
Storage()->EntityDB().AddChild("id",E.parent,E.info.id);
|
||||
}
|
||||
Storage()->EntityDB().GetRecord("id",E.info.id,E);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template<> void ORM::DB< OpenWifi::EntityDBRecordType, OpenWifi::ProvObjects::Entity>::Convert(OpenWifi::EntityDBRecordType &In, OpenWifi::ProvObjects::Entity &Out) {
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace OpenWifi {
|
||||
void AddVenues(Poco::JSON::Object &Tree, const std::string & Venue );
|
||||
void ImportTree(const Poco::JSON::Object::Ptr &Ptr, const std::string & Node = RootUUID_ );
|
||||
void ImportVenues(const Poco::JSON::Object::Ptr &Ptr, const std::string & Node = RootUUID_ );
|
||||
bool CreateShortCut( ProvObjects::Entity & E);
|
||||
private:
|
||||
bool RootExists_=false;
|
||||
};
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "RESTAPI_utils.h"
|
||||
#include "RESTAPI_SecurityObjects.h"
|
||||
|
||||
#include "StorageService.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
static ORM::FieldVec VenueDB_Fields{
|
||||
@@ -43,6 +45,25 @@ namespace OpenWifi {
|
||||
VenueDB::VenueDB( ORM::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) :
|
||||
DB(T, "venues", VenueDB_Fields, VenueDB_Indexes, P, L, "ven") {}
|
||||
|
||||
bool VenueDB::CreateShortCut(ProvObjects::Venue &V) {
|
||||
if(CreateRecord(V)) {
|
||||
if(!V.parent.empty())
|
||||
Storage()->VenueDB().AddChild("id", V.parent, V.info.id);
|
||||
if(!V.entity.empty())
|
||||
Storage()->EntityDB().AddVenue("id", V.entity, V.info.id);
|
||||
if(!V.location.empty())
|
||||
Storage()->LocationDB().AddInUse("id",V.location, Storage()->VenueDB().Prefix(), V.info.id);
|
||||
if(!V.contact.empty())
|
||||
Storage()->ContactDB().AddInUse("id",V.contact, Storage()->VenueDB().Prefix(), V.info.id);
|
||||
if(!V.managementPolicy.empty())
|
||||
Storage()->PolicyDB().AddInUse("id",V.managementPolicy, Storage()->VenueDB().Prefix(), V.info.id);
|
||||
|
||||
Storage()->VenueDB().GetRecord("id",V.info.id,V);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template<> void ORM::DB< OpenWifi::VenueDBRecordType, OpenWifi::ProvObjects::Venue>::Convert(OpenWifi::VenueDBRecordType &In, OpenWifi::ProvObjects::Venue &Out) {
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace OpenWifi {
|
||||
class VenueDB : public ORM::DB<VenueDBRecordType, ProvObjects::Venue> {
|
||||
public:
|
||||
VenueDB( ORM::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
|
||||
bool CreateShortCut(ProvObjects::Venue &V);
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type" : "entity",
|
||||
"name" : "root",
|
||||
"name" : "world",
|
||||
"children" : [{
|
||||
"type" : "entity",
|
||||
"name" : "root" ,
|
||||
|
||||
Reference in New Issue
Block a user