mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-11-01 19:17:47 +00:00
Adding removal subscriber
This commit is contained in:
@@ -816,23 +816,6 @@ components:
|
||||
items:
|
||||
$ref: '#/components/schemas/Map'
|
||||
|
||||
ClaimResult:
|
||||
type: object
|
||||
properties:
|
||||
claimer:
|
||||
type: string
|
||||
format: uuid
|
||||
claimId:
|
||||
type: string
|
||||
format: uuid
|
||||
date:
|
||||
type: integer
|
||||
format: int64
|
||||
errorCode:
|
||||
type: integer
|
||||
format: int64
|
||||
reason:
|
||||
type: string
|
||||
|
||||
SignupEntry:
|
||||
type: object
|
||||
@@ -1836,12 +1819,13 @@ paths:
|
||||
schema:
|
||||
type: boolean
|
||||
required: false
|
||||
- in: query
|
||||
name: claimer
|
||||
- in: path
|
||||
name: removeSubscriber
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
required: false
|
||||
required: true
|
||||
|
||||
requestBody:
|
||||
description: Information used to modify the new entity
|
||||
content:
|
||||
@@ -1855,9 +1839,7 @@ paths:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/ClaimResult'
|
||||
- $ref: '#/components/schemas/InventoryTag'
|
||||
$ref: '#/components/schemas/InventoryTag'
|
||||
403:
|
||||
$ref: '#/components/responses/Unauthorized'
|
||||
404:
|
||||
@@ -2000,12 +1982,22 @@ paths:
|
||||
format: uuid
|
||||
required: true
|
||||
- in: query
|
||||
name: locationToCreate
|
||||
name: createObjects
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
objects:
|
||||
type: array
|
||||
items:
|
||||
oneOf:
|
||||
- type: object
|
||||
properties:
|
||||
location:
|
||||
$ref: '#/components/schemas/Location'
|
||||
- type: object
|
||||
properties:
|
||||
contact:
|
||||
$ref: '#/components/schemas/Contact'
|
||||
required: false
|
||||
requestBody:
|
||||
description: Information used to create the new venue
|
||||
|
||||
@@ -309,4 +309,60 @@ namespace OpenWifi {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline std::string FindParentEntity(const ProvObjects::Venue &V) {
|
||||
if(V.parent.empty())
|
||||
return V.entity;
|
||||
ProvObjects::Venue P;
|
||||
if(StorageService()->VenueDB().GetRecord("id",V.parent,P))
|
||||
return FindParentEntity(P);
|
||||
return EntityDB::RootUUID();
|
||||
}
|
||||
|
||||
template <typename Type> std::map<std::string,std::string> CreateObjects(Type & NewObject, RESTAPIHandler & R, std::string &ErrorText) {
|
||||
std::map<std::string,std::string> Result;
|
||||
|
||||
auto createObjects = R.GetParameter("createObjects","");
|
||||
if(!createObjects.empty()) {
|
||||
std::cout << "createObjects: " << createObjects << std::endl;
|
||||
Poco::JSON::Parser P;
|
||||
auto Objects = P.parse(createObjects).extract<Poco::JSON::Object::Ptr>();
|
||||
if(Objects->isArray("objects")) {
|
||||
auto ObjectsArray = Objects->getArray("objects");
|
||||
for(const auto &i:*ObjectsArray) {
|
||||
auto Object = i.extract<Poco::JSON::Object::Ptr>();
|
||||
if (Object->has("location")) {
|
||||
auto LocationDetails = Object->get("location").extract<Poco::JSON::Object::Ptr>();
|
||||
ProvObjects::Location LC;
|
||||
if (LC.from_json(LocationDetails)) {
|
||||
if constexpr(std::is_same_v<Type,ProvObjects::Venue>) {
|
||||
std::cout << "Location decoded: " << LC.info.name << std::endl;
|
||||
std::string ParentEntity = FindParentEntity(NewObject);
|
||||
ProvObjects::CreateObjectInfo(R.UserInfo_.userinfo,LC.info);
|
||||
LC.entity = ParentEntity;
|
||||
if(StorageService()->LocationDB().CreateRecord(LC)) {
|
||||
NewObject.location = LC.info.id;
|
||||
AddMembership(StorageService()->EntityDB(), &ProvObjects::Entity::locations,
|
||||
ParentEntity, LC.info.id);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::cout << "Location not decoded." << std::endl;
|
||||
}
|
||||
} else if (Object->has("contact")) {
|
||||
auto ContactDetails = Object->get("contact").extract<Poco::JSON::Object::Ptr>();
|
||||
ProvObjects::Contact CC;
|
||||
if (CC.from_json(ContactDetails)) {
|
||||
std::cout << "contact decoded: " << CC.info.name << std::endl;
|
||||
} else {
|
||||
std::cout << "contact not decoded." << std::endl;
|
||||
}
|
||||
std::cout << "No contact included." << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace OpenWifi{
|
||||
NewEntity.deviceConfiguration.clear();
|
||||
NewEntity.managementRoles.clear();
|
||||
|
||||
if(DB_.CreateShortCut(NewEntity)) {
|
||||
if(DB_.CreateRecord(NewEntity)) {
|
||||
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewEntity.managementPolicy,NewEntity.info.id);
|
||||
if(UUID==EntityDB::RootUUID()) {
|
||||
DB_.CheckForRoot();
|
||||
|
||||
@@ -239,153 +239,43 @@ namespace OpenWifi{
|
||||
InternalError(RESTAPI::Errors::RecordNotCreated);
|
||||
}
|
||||
|
||||
void RESTAPI_inventory_handler::PerformClaim(const std::string &SerialNumber, const std::string &Claimer, std::string & ClaimId, uint64_t &ErrorCode, Poco::JSON::Object &Answer ) {
|
||||
|
||||
if(UserInfo_.userinfo.userRole==SecurityObjects::SUBSCRIBER && Claimer!=UserInfo_.userinfo.id) {
|
||||
return UnAuthorized(RESTAPI::Errors::InsufficientAccessRights, ACCESS_DENIED);
|
||||
} else if(UserInfo_.userinfo.userRole==SecurityObjects::ROOT && !SDK::Sec::Subscriber::Exists(this, Claimer)) {
|
||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||
} else if(UserInfo_.userinfo.userRole!=SecurityObjects::ROOT && UserInfo_.userinfo.userRole!=SecurityObjects::SUBSCRIBER) {
|
||||
return UnAuthorized(RESTAPI::Errors::InsufficientAccessRights,ACCESS_DENIED);
|
||||
}
|
||||
|
||||
uint64_t Now = std::time(nullptr);
|
||||
|
||||
// if the device exists, check the status to see if we would follow this claim.
|
||||
ProvObjects::InventoryTag ExistingDevice;
|
||||
if(DB_.GetRecord("serialNumber",SerialNumber,ExistingDevice)) {
|
||||
// Device is already in there... so we could have claimed that device before, or someone else uses it
|
||||
// or, it is free and clear: it connected but nobody has ever used it...
|
||||
if(!ExistingDevice.state.empty()) {
|
||||
try {
|
||||
Poco::JSON::Parser P;
|
||||
auto StateDoc = P.parse(ExistingDevice.state).extract<Poco::JSON::Object::Ptr>();
|
||||
if (StateDoc->has("method")) {
|
||||
auto Method = StateDoc->get("method").toString();
|
||||
if(Method=="claiming") {
|
||||
auto RecordedClaimer = StateDoc->get("claimer").toString();
|
||||
auto RecordedClaimId = StateDoc->get("claimId").toString();
|
||||
if(Claimer==RecordedClaimer) {
|
||||
ErrorCode = 3;
|
||||
ClaimId = RecordedClaimId;
|
||||
Answer.set("claimer", Claimer);
|
||||
Answer.set("claimId", RecordedClaimId);
|
||||
Answer.set("errorCode",ErrorCode);
|
||||
Answer.set("date", Now);
|
||||
Answer.set("reason", "Claim already in progress");
|
||||
return;
|
||||
}
|
||||
ErrorCode = 1;
|
||||
ClaimId = RecordedClaimId;
|
||||
Answer.set("claimer", Claimer);
|
||||
Answer.set("claimId", RecordedClaimId);
|
||||
Answer.set("errorCode",ErrorCode);
|
||||
Answer.set("date", Now);
|
||||
Answer.set("reason", "Claimed by another user: "+ RecordedClaimer);
|
||||
return;
|
||||
} else if(Method=="claimed") {
|
||||
// We already own this one...
|
||||
if(Claimer==ExistingDevice.subscriber) {
|
||||
auto RecordedClaimer = StateDoc->get("claimer").toString();
|
||||
auto RecordedClaimId = StateDoc->get("claimId").toString();
|
||||
ErrorCode = 0;
|
||||
ClaimId = RecordedClaimId;
|
||||
Answer.set("claimer", Claimer);
|
||||
Answer.set("claimId", RecordedClaimId);
|
||||
Answer.set("errorCode",ErrorCode);
|
||||
Answer.set("date", Now);
|
||||
Answer.set("reason", "Success");
|
||||
return;
|
||||
} else {
|
||||
// Someone else has claimed this device.
|
||||
ErrorCode = 1;
|
||||
ClaimId = "";
|
||||
Answer.set("claimer", Claimer);
|
||||
Answer.set("claimId", "");
|
||||
Answer.set("errorCode",ErrorCode);
|
||||
Answer.set("date", Now);
|
||||
Answer.set("reason", "Claimed by another user: "+ ExistingDevice.subscriber);
|
||||
return;
|
||||
}
|
||||
} else if(Method=="auto-discovery") {
|
||||
if(StateDoc->has("assignedTo")) {
|
||||
auto AssignedTo = StateDoc->get("assignedTo").toString();
|
||||
ErrorCode = 1;
|
||||
ClaimId = "";
|
||||
Answer.set("claimer", Claimer);
|
||||
Answer.set("claimId", "");
|
||||
Answer.set("errorCode",ErrorCode);
|
||||
Answer.set("date", Now);
|
||||
Answer.set("reason", "Claimed by venue: '" + ExistingDevice.venue + "' or entity: '" + ExistingDevice.entity + "'");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
} else {
|
||||
// Device does not exist, so claim it for now.
|
||||
ProvObjects::InventoryTag NewDevice;
|
||||
NewDevice.info.created = NewDevice.info.modified = Now;
|
||||
NewDevice.info.id = MicroService::instance().CreateUUID();
|
||||
NewDevice.info.name = SerialNumber;
|
||||
NewDevice.info.notes.push_back(SecurityObjects::NoteInfo{ .created=Now,
|
||||
.createdBy=UserInfo_.userinfo.email,
|
||||
.note="Claim started for device"});
|
||||
NewDevice.info.description = "Subscriber device";
|
||||
NewDevice.subscriber = UserInfo_.userinfo.id;
|
||||
NewDevice.deviceType = "unknown";
|
||||
nlohmann::json StateDoc;
|
||||
|
||||
ClaimId = MicroService::instance().CreateUUID();
|
||||
|
||||
StateDoc["method"] = "claiming";
|
||||
StateDoc["date"] = Now;
|
||||
StateDoc["claimer"] = Claimer;
|
||||
StateDoc["claimId"] = ClaimId;
|
||||
NewDevice.state = StateDoc;
|
||||
ErrorCode = 0 ;
|
||||
DB_.CreateRecord(NewDevice);
|
||||
|
||||
Answer.set("claimer", Claimer);
|
||||
Answer.set("claimId", ClaimId);
|
||||
Answer.set("errorCode",0);
|
||||
Answer.set("date", Now);
|
||||
Answer.set("reason", "Success");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#define __DBG__ std::cout << __LINE__ << std::endl;
|
||||
|
||||
void RESTAPI_inventory_handler::DoPut() {
|
||||
|
||||
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER,"");
|
||||
|
||||
if(SerialNumber.empty() || !Utils::ValidSerialNumber(SerialNumber)) {
|
||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||
}
|
||||
|
||||
std::string Claimer;
|
||||
if(HasParameter("claimer",Claimer) && !Claimer.empty()) {
|
||||
uint64_t ErrorCode;
|
||||
Poco::JSON::Object Answer;
|
||||
std::string ClaimId;
|
||||
PerformClaim(SerialNumber, Claimer, ClaimId, ErrorCode, Answer);
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
|
||||
ProvObjects::InventoryTag Existing;
|
||||
if(SerialNumber.empty() || !DB_.GetRecord(RESTAPI::Protocol::SERIALNUMBER,SerialNumber,Existing)) {
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
auto RemoveSubscriber = GetParameter("removeSubscriber","");
|
||||
if(!RemoveSubscriber.empty()) {
|
||||
if(Existing.subscriber == RemoveSubscriber) {
|
||||
ProvObjects::DeviceConfiguration DC;
|
||||
if(StorageService()->ConfigurationDB().GetRecord("id",Existing.deviceConfiguration,DC)) {
|
||||
if(DC.subscriberOnly)
|
||||
StorageService()->ConfigurationDB().DeleteRecord("id",Existing.deviceConfiguration);
|
||||
Existing.deviceConfiguration = "";
|
||||
}
|
||||
Existing.subscriber = "";
|
||||
nlohmann::json state;
|
||||
state["date"] = OpenWifi::Now();
|
||||
state["method"] = "auto-discovery";
|
||||
state["last-operation"] = "returned to inventory";
|
||||
Existing.state = state;
|
||||
StorageService()->InventoryDB().UpdateRecord("id",Existing.info.id,Existing);
|
||||
Poco::JSON::Object Answer;
|
||||
Existing.to_json(Answer);
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
}
|
||||
|
||||
auto RawObject = ParseStream();
|
||||
ProvObjects::InventoryTag NewObject;
|
||||
if(!NewObject.from_json(RawObject)) {
|
||||
|
||||
@@ -41,8 +41,11 @@ namespace OpenWifi{
|
||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
||||
}
|
||||
|
||||
if(!Existing.contact.empty())
|
||||
StorageService()->ContactDB().DeleteInUse("id",Existing.contact,StorageService()->VenueDB().Prefix(),UUID);
|
||||
if(!Existing.contacts.empty()) {
|
||||
for(const auto &i:Existing.contacts)
|
||||
StorageService()->ContactDB().DeleteInUse("id", i, StorageService()->VenueDB().Prefix(),
|
||||
UUID);
|
||||
}
|
||||
if(!Existing.location.empty())
|
||||
StorageService()->LocationDB().DeleteInUse("id",Existing.location,StorageService()->VenueDB().Prefix(),UUID);
|
||||
if(!Existing.managementPolicy.empty())
|
||||
@@ -71,26 +74,6 @@ namespace OpenWifi{
|
||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||
}
|
||||
|
||||
auto LocationToCreate = GetParameter("locationToCreate","");
|
||||
if(!LocationToCreate.empty()) {
|
||||
std::cout << "LocationToCreate: " << LocationToCreate << std::endl;
|
||||
Poco::JSON::Parser P;
|
||||
auto LocationObj = P.parse(LocationToCreate).extract<Poco::JSON::Object::Ptr>();
|
||||
if(LocationObj->has("location")) {
|
||||
auto LocationDetails = LocationObj->get("location").extract<Poco::JSON::Object::Ptr>();
|
||||
ProvObjects::Location LC;
|
||||
if(LC.from_json(LocationDetails)) {
|
||||
std::cout << "Location decoded: " << LC.info.name << std::endl;
|
||||
} else {
|
||||
std::cout << "Location not decoded." << std::endl;
|
||||
}
|
||||
} else {
|
||||
std::cout << "No location included." << std::endl;
|
||||
}
|
||||
} else {
|
||||
std::cout << "NoLocation to create." << std::endl;
|
||||
}
|
||||
|
||||
if (!CreateObjectInfo(Obj, UserInfo_.userinfo, NewObject.info)) {
|
||||
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
||||
}
|
||||
@@ -115,9 +98,13 @@ namespace OpenWifi{
|
||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||
}
|
||||
|
||||
if(!NewObject.contact.empty() && !StorageService()->ContactDB().Exists("id",NewObject.contact)) {
|
||||
if (!NewObject.contacts.empty()) {
|
||||
for(const auto &i:NewObject.contacts) {
|
||||
if(!StorageService()->ContactDB().Exists("id", i)) {
|
||||
return BadRequest(RESTAPI::Errors::ContactMustExist);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!NewObject.location.empty() && !StorageService()->LocationDB().Exists("id",NewObject.location)) {
|
||||
return BadRequest(RESTAPI::Errors::LocationMustExist);
|
||||
@@ -140,9 +127,16 @@ namespace OpenWifi{
|
||||
}
|
||||
|
||||
NewObject.children.clear();
|
||||
if(DB_.CreateShortCut(NewObject)) {
|
||||
|
||||
MoveUsage(StorageService()->ContactDB(),DB_,"", NewObject.contact, NewObject.info.id);
|
||||
std::string ErrorText;
|
||||
auto ObjectsToCreate = CreateObjects(NewObject, *this, ErrorText);
|
||||
|
||||
if(!ErrorText.empty()) {
|
||||
return BadRequest(ErrorText);
|
||||
}
|
||||
|
||||
if(DB_.CreateRecord(NewObject)) {
|
||||
MoveUsage(StorageService()->ContactDB(),DB_,{}, NewObject.contacts, NewObject.info.id);
|
||||
MoveUsage(StorageService()->LocationDB(),DB_,"", NewObject.location, NewObject.info.id);
|
||||
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id);
|
||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::venues,"",NewObject.entity,NewObject.info.id);
|
||||
@@ -211,13 +205,15 @@ namespace OpenWifi{
|
||||
Existing.location = MoveToLocation;
|
||||
}
|
||||
|
||||
std::string MoveFromContact, MoveToContact;
|
||||
if(AssignIfPresent(RawObject,"contact",MoveToContact)) {
|
||||
if(!MoveToContact.empty() && !StorageService()->ContactDB().Exists("id",MoveToContact)) {
|
||||
Types::UUIDvec_t MoveFromContacts, MoveToContacts;
|
||||
if(AssignIfPresent(RawObject,"contacts",MoveToContacts)) {
|
||||
for(const auto &i:NewObject.contacts) {
|
||||
if(!StorageService()->ContactDB().Exists("id", i)) {
|
||||
return BadRequest(RESTAPI::Errors::ContactMustExist);
|
||||
}
|
||||
MoveFromContact = Existing.contact;
|
||||
Existing.contact = MoveToContact;
|
||||
}
|
||||
MoveFromContacts = Existing.contacts;
|
||||
Existing.contacts = MoveToContacts;
|
||||
}
|
||||
|
||||
std::string MoveFromPolicy, MoveToPolicy;
|
||||
@@ -243,7 +239,7 @@ namespace OpenWifi{
|
||||
}
|
||||
|
||||
if(StorageService()->VenueDB().UpdateRecord("id", UUID, Existing)) {
|
||||
MoveUsage(StorageService()->ContactDB(),DB_,MoveFromContact, MoveToContact, Existing.info.id);
|
||||
MoveUsage(StorageService()->ContactDB(),DB_,MoveFromContacts, MoveToContacts, Existing.info.id);
|
||||
MoveUsage(StorageService()->LocationDB(),DB_,MoveFromLocation, MoveToLocation, Existing.info.id);
|
||||
MoveUsage(StorageService()->PolicyDB(),DB_,MoveFromPolicy,MoveToPolicy,Existing.info.id);
|
||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::venues,MoveFromEntity,MoveToEntity,Existing.info.id);
|
||||
|
||||
@@ -152,7 +152,7 @@ namespace OpenWifi::ProvObjects {
|
||||
field_to_json( Obj,"design",design);
|
||||
field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||
field_to_json( Obj,"deviceConfiguration",deviceConfiguration);
|
||||
field_to_json( Obj,"contact",contact);
|
||||
field_to_json( Obj,"contacts",contacts);
|
||||
field_to_json( Obj,"location",location);
|
||||
field_to_json( Obj,"rrm",rrm);
|
||||
field_to_json( Obj,"sourceIP",sourceIP);
|
||||
@@ -175,7 +175,7 @@ namespace OpenWifi::ProvObjects {
|
||||
field_from_json( Obj,"design",design);
|
||||
field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||
field_from_json( Obj,"deviceConfiguration",deviceConfiguration);
|
||||
field_from_json( Obj,"contact",contact);
|
||||
field_from_json( Obj,"contacts",contacts);
|
||||
field_from_json( Obj,"location",location);
|
||||
field_from_json( Obj,"rrm",rrm);
|
||||
field_from_json( Obj,"sourceIP",sourceIP);
|
||||
@@ -816,5 +816,12 @@ namespace OpenWifi::ProvObjects {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CreateObjectInfo(const SecurityObjects::UserInfo &U, ObjectInfo &I) {
|
||||
I.modified = I.created = OpenWifi::Now();
|
||||
I.id = MicroService::CreateUUID();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace OpenWifi::ProvObjects {
|
||||
DiGraph topology;
|
||||
std::string design;
|
||||
Types::UUIDvec_t deviceConfiguration;
|
||||
std::string contact;
|
||||
Types::UUIDvec_t contacts;
|
||||
std::string location;
|
||||
std::string rrm;
|
||||
Types::StringVec sourceIP;
|
||||
@@ -482,4 +482,5 @@ 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);
|
||||
bool CreateObjectInfo(const SecurityObjects::UserInfo &U, ObjectInfo &I);
|
||||
};
|
||||
|
||||
@@ -1858,6 +1858,16 @@ namespace OpenWifi {
|
||||
return Return;
|
||||
}
|
||||
|
||||
static inline bool AssignIfPresent(const Poco::JSON::Object::Ptr &O, const std::string &Field, Types::UUIDvec_t & Value) {
|
||||
if(O->has(Field) && O->isArray(Field)) {
|
||||
auto Arr = O->getArray(Field);
|
||||
for(const auto &i:*Arr)
|
||||
Value.emplace_back(i.toString());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool AssignIfPresent(const Poco::JSON::Object::Ptr &O, const std::string &Field, std::string &Value) {
|
||||
if(O->has(Field)) {
|
||||
Value = O->get(Field).toString();
|
||||
|
||||
@@ -159,7 +159,7 @@ namespace OpenWifi {
|
||||
V.info.id = MicroService::CreateUUID();
|
||||
V.parent = Parent;
|
||||
V.info.created = V.info.modified = std::time(nullptr);
|
||||
StorageService()->VenueDB().CreateShortCut(V);
|
||||
// StorageService()->VenueDB().CreateShortCut(V);
|
||||
ImportVenues( Child, V.info.id );
|
||||
}
|
||||
}
|
||||
@@ -176,7 +176,7 @@ namespace OpenWifi {
|
||||
E.info.name = Name;
|
||||
E.info.id = EntityDB::RootUUID();
|
||||
E.info.created = E.info.modified = std::time(nullptr);
|
||||
StorageService()->EntityDB().CreateShortCut(E);
|
||||
// StorageService()->EntityDB().CreateShortCut(E);
|
||||
}
|
||||
|
||||
auto Children = O->getArray("children");
|
||||
@@ -188,7 +188,7 @@ namespace OpenWifi {
|
||||
E.info.id = MicroService::CreateUUID();
|
||||
E.parent = Parent;
|
||||
E.info.created = E.info.modified = std::time(nullptr);
|
||||
StorageService()->EntityDB().CreateShortCut(E);
|
||||
// StorageService()->EntityDB().CreateShortCut(E);
|
||||
ImportTree( Child, E.info.id );
|
||||
}
|
||||
|
||||
@@ -200,32 +200,11 @@ namespace OpenWifi {
|
||||
V.info.id = MicroService::CreateUUID();
|
||||
V.entity = Parent;
|
||||
V.info.created = V.info.modified = std::time(nullptr);
|
||||
StorageService()->VenueDB().CreateShortCut(V);
|
||||
// StorageService()->VenueDB().CreateShortCut(V);
|
||||
ImportVenues( Child, V.info.id );
|
||||
}
|
||||
}
|
||||
|
||||
bool EntityDB::CreateShortCut( ProvObjects::Entity & E) {
|
||||
if(StorageService()->EntityDB().CreateRecord(E)) {
|
||||
if(E.info.id==EntityDB::RootUUID())
|
||||
StorageService()->EntityDB().CheckForRoot();
|
||||
else {
|
||||
StorageService()->EntityDB().AddChild("id",E.parent,E.info.id);
|
||||
}
|
||||
if(!E.managementPolicy.empty())
|
||||
StorageService()->PolicyDB().AddInUse("id",E.managementPolicy, Prefix(), E.info.id);
|
||||
if(!E.deviceConfiguration.empty()) {
|
||||
for(auto &i:E.deviceConfiguration)
|
||||
StorageService()->ConfigurationDB().AddInUse("id", i, Prefix(), E.info.id);
|
||||
}
|
||||
ProvObjects::Entity NE;
|
||||
StorageService()->EntityDB().GetRecord("id",E.info.id,NE);
|
||||
E = NE;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template<> void ORM::DB< OpenWifi::EntityDBRecordType, OpenWifi::ProvObjects::Entity>::Convert(const OpenWifi::EntityDBRecordType &In, OpenWifi::ProvObjects::Entity &Out) {
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenWifi {
|
||||
ORM::Field{"managementPolicy",ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"topology",ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"design",ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"contact",ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"contacts",ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"location",ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"rrm",ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"tags",ORM::FieldType::FT_TEXT},
|
||||
@@ -61,7 +61,8 @@ namespace OpenWifi {
|
||||
"alter table " + TableName_ + " add column configurations text",
|
||||
"alter table " + TableName_ + " add column maps text",
|
||||
"alter table " + TableName_ + " add column managementRoles text",
|
||||
"alter table " + TableName_ + " add column managementPolicies text"
|
||||
"alter table " + TableName_ + " add column managementPolicies text",
|
||||
"alter table " + TableName_ + " rename column contact to contacts",
|
||||
};
|
||||
|
||||
for(const auto &i:Script) {
|
||||
@@ -75,30 +76,6 @@ namespace OpenWifi {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VenueDB::CreateShortCut(ProvObjects::Venue &V) {
|
||||
if(StorageService()->VenueDB().CreateRecord(V)) {
|
||||
if(!V.parent.empty())
|
||||
StorageService()->VenueDB().AddChild("id", V.parent, V.info.id);
|
||||
if(!V.entity.empty())
|
||||
StorageService()->EntityDB().AddVenue("id", V.entity, V.info.id);
|
||||
if(!V.location.empty())
|
||||
StorageService()->LocationDB().AddInUse("id",V.location, StorageService()->VenueDB().Prefix(), V.info.id);
|
||||
if(!V.contact.empty())
|
||||
StorageService()->ContactDB().AddInUse("id",V.contact, StorageService()->VenueDB().Prefix(), V.info.id);
|
||||
if(!V.managementPolicy.empty())
|
||||
StorageService()->PolicyDB().AddInUse("id",V.managementPolicy, StorageService()->VenueDB().Prefix(), V.info.id);
|
||||
if(!V.deviceConfiguration.empty()) {
|
||||
for(auto &i:V.deviceConfiguration)
|
||||
StorageService()->ConfigurationDB().AddInUse("id", i, StorageService()->ConfigurationDB().Prefix(), V.info.id);
|
||||
}
|
||||
ProvObjects::Venue NV;
|
||||
StorageService()->VenueDB().GetRecord("id",V.info.id,NV);
|
||||
V = NV;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VenueDB::GetByIP(const std::string &IP, std::string & uuid) {
|
||||
try {
|
||||
std::string UUID;
|
||||
@@ -135,7 +112,7 @@ template<> void ORM::DB< OpenWifi::VenueDBRecordType, OpenWifi::ProvObjects::
|
||||
Out.managementPolicy = In.get<10>();
|
||||
Out.topology = OpenWifi::RESTAPI_utils::to_object_array<OpenWifi::ProvObjects::DiGraphEntry>(In.get<11>());
|
||||
Out.design = In.get<12>();
|
||||
Out.contact = In.get<13>();
|
||||
Out.contacts = OpenWifi::RESTAPI_utils::to_object_array(In.get<13>());
|
||||
Out.location = In.get<14>();
|
||||
Out.rrm = In.get<15>();
|
||||
Out.info.tags = OpenWifi::RESTAPI_utils::to_taglist(In.get<16>());
|
||||
@@ -162,7 +139,7 @@ template<> void ORM::DB< OpenWifi::VenueDBRecordType, OpenWifi::ProvObjects::
|
||||
Out.set<10>(In.managementPolicy);
|
||||
Out.set<11>(OpenWifi::RESTAPI_utils::to_string(In.topology));
|
||||
Out.set<12>(In.design);
|
||||
Out.set<13>(In.contact);
|
||||
Out.set<13>(OpenWifi::RESTAPI_utils::to_string(In.contacts));
|
||||
Out.set<14>(In.location);
|
||||
Out.set<15>(In.rrm);
|
||||
Out.set<16>(OpenWifi::RESTAPI_utils::to_string(In.info.tags));
|
||||
|
||||
@@ -42,7 +42,6 @@ namespace OpenWifi {
|
||||
class VenueDB : public ORM::DB<VenueDBRecordType, ProvObjects::Venue> {
|
||||
public:
|
||||
VenueDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
|
||||
bool CreateShortCut(ProvObjects::Venue &V);
|
||||
bool GetByIP(const std::string &IP, std::string & uuid);
|
||||
bool Upgrade(uint32_t from, uint32_t &to) override;
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user