Adding variableBlock support & DB refactor.

This commit is contained in:
stephb9959
2022-03-02 08:23:44 -08:00
parent bea59b7bd7
commit adbd13663e
28 changed files with 503 additions and 386 deletions

2
build
View File

@@ -1 +1 @@
41
43

View File

@@ -166,6 +166,12 @@ components:
type: string
format: uuid
example: each uuid is preceded by ent, or ven to say that the elemenet is entity or venue
entity:
type: string
format: uuid
venue:
type: string
format: uuid
ManagementPolicyList:
type: object
@@ -219,6 +225,36 @@ components:
items:
type: string
format: uuid
managementPolicies:
description: The list of UUID of the venues for this entity
type: array
items:
type: string
format: uuid
variables:
description: The list of UUID of the venues for this entity
type: array
items:
type: string
format: uuid
managementRoles:
description: The list of UUID of the venues for this entity
type: array
items:
type: string
format: uuid
maps:
description: The list of UUID of the venues for this entity
type: array
items:
type: string
format: uuid
configurations:
description: The list of UUID of the venues for this entity
type: array
items:
type: string
format: uuid
rrm:
type: string
enum:
@@ -297,6 +333,36 @@ components:
- inherit
sourceIP:
$ref: '#/components/schemas/StringList'
managementPolicies:
description: The list of UUID of the venues for this entity
type: array
items:
type: string
format: uuid
managementRoles:
description: The list of UUID of the venues for this entity
type: array
items:
type: string
format: uuid
variables:
description: The list of UUID of the venues for this entity
type: array
items:
type: string
format: uuid
maps:
description: The list of UUID of the venues for this entity
type: array
items:
type: string
format: uuid
configurations:
description: The list of UUID of the venues for this entity
type: array
items:
type: string
format: uuid
VenueList:
type: object
@@ -337,6 +403,12 @@ components:
type: string
format: uuid
example: each uuid is preceded by ent, or ven to say that the elemenet is entity or venue
entity:
type: string
format: uuid
venue:
type: string
format: uuid
ManagementRoleList:
type: object
@@ -521,6 +593,15 @@ components:
example: auto or a time string of the format DOW-HH:MM
firmwareRCOnly:
type: boolean
venue:
type: string
format: uuid
entity:
type: string
format: uuid
subscriber:
type: string
format: uuid
DeviceConfigurationList:
type: object
@@ -545,6 +626,9 @@ components:
entity:
type: string
format: uuid
subscriber:
type: string
format: uuid
qrCode:
type: string
geoCode:
@@ -701,6 +785,12 @@ components:
entity:
type: string
format: uuid
venue:
type: string
format: uuid
managementPolicy:
type: string
format: uuid
data:
type: string
visibility:
@@ -778,7 +868,9 @@ components:
- integer
- string
- float
- boolean
- variable
- json
weight:
type: integer
format: int64

View File

@@ -67,6 +67,8 @@ namespace OpenWifi{
DB_.DeleteRecord("id", UUID);
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id);
RemoveMembership(StorageService()->VenueDB(),&ProvObjects::Venue::configurations,Existing.venue,Existing.info.id);
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::configurations,Existing.entity,Existing.info.id);
for(const auto &i:Existing.variables)
RemoveMembership(StorageService()->VariablesDB(),&ProvObjects::VariableBlock::configurations,i,Existing.info.id);
@@ -137,35 +139,47 @@ namespace OpenWifi{
return ReturnObject(Answer);
}
ProvObjects::DeviceConfiguration C;
Poco::JSON::Object::Ptr Obj = ParseStream();
if (!C.from_json(Obj)) {
ProvObjects::DeviceConfiguration NewObject;
auto RawObject = ParseStream();
if (!NewObject.from_json(RawObject)) {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
if(!ProvObjects::CreateObjectInfo(Obj,UserInfo_.userinfo,C.info)) {
if(!ProvObjects::CreateObjectInfo(RawObject,UserInfo_.userinfo,NewObject.info)) {
return BadRequest(RESTAPI::Errors::NameMustBeSet);
}
if(!C.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",C.managementPolicy)) {
return BadRequest(RESTAPI::Errors::UnknownId);
if(!NewObject.entity.empty() && !StorageService()->EntityDB().Exists("id",NewObject.entity)) {
return BadRequest(RESTAPI::Errors::EntityMustExist);
}
C.inUse.clear();
if(C.deviceTypes.empty() || !DeviceTypeCache()->AreAcceptableDeviceTypes(C.deviceTypes, true)) {
if(!NewObject.venue.empty() && !StorageService()->VenueDB().Exists("id",NewObject.venue)) {
return BadRequest(RESTAPI::Errors::VenueMustExist);
}
if(!NewObject.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewObject.managementPolicy)) {
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
NewObject.inUse.clear();
if(NewObject.deviceTypes.empty() || !DeviceTypeCache()->AreAcceptableDeviceTypes(NewObject.deviceTypes, true)) {
return BadRequest(RESTAPI::Errors::InvalidDeviceTypes);
}
std::string Error;
if(!ValidateConfigBlock(C,Error)) {
if(!ValidateConfigBlock(NewObject,Error)) {
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid + ", error: " + Error);
}
if(DB_.CreateRecord(C)) {
MoveUsage(StorageService()->PolicyDB(),DB_,"",C.managementPolicy,C.info.id);
DB_.GetRecord("id", C.info.id, C);
if(DB_.CreateRecord(NewObject)) {
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id);
AddMembership(StorageService()->VenueDB(),&ProvObjects::Venue::configurations,NewObject.venue, NewObject.info.id);
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::configurations,NewObject.entity, NewObject.info.id);
ConfigurationDB::RecordName AddedRecord;
DB_.GetRecord("id", NewObject.info.id, AddedRecord);
Poco::JSON::Object Answer;
C.to_json(Answer);
AddedRecord.to_json(Answer);
return ReturnObject(Answer);
}
InternalError(RESTAPI::Errors::RecordNotCreated);
@@ -179,12 +193,12 @@ namespace OpenWifi{
}
ProvObjects::DeviceConfiguration NewConfig;
auto ParsedObj = ParseStream();
if (!NewConfig.from_json(ParsedObj)) {
auto RawObject = ParseStream();
if (!NewConfig.from_json(RawObject)) {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
if(!UpdateObjectInfo(ParsedObj, UserInfo_.userinfo, Existing.info)) {
if(!UpdateObjectInfo(RawObject, UserInfo_.userinfo, Existing.info)) {
return BadRequest(RESTAPI::Errors::NameMustBeSet);
}
@@ -200,20 +214,24 @@ namespace OpenWifi{
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid + ", error: " + Error);
}
if(ParsedObj->has("configuration")) {
if(RawObject->has("configuration")) {
Existing.configuration = NewConfig.configuration;
}
std::string MovePolicy, ExistingPolicy;
if(AssignIfPresent(ParsedObj,"managementPolicy",MovePolicy)) {
if(!MovePolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewConfig.managementPolicy)) {
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
ExistingPolicy = Existing.managementPolicy;
}
std::string FromPolicy, ToPolicy;
if(!CreateMove(RawObject,"managementPolicy",&ConfigurationDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromEntity, ToEntity;
if(!CreateMove(RawObject,"entity",&ConfigurationDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromVenue, ToVenue;
if(!CreateMove(RawObject,"venue",&ConfigurationDB::RecordName::venue, Existing, FromVenue, ToVenue, StorageService()->VenueDB()))
return BadRequest(RESTAPI::Errors::VenueMustExist);
Types::UUIDvec_t FromVariables, ToVariables;
if(ParsedObj->has("variables")) {
if(RawObject->has("variables")) {
for(const auto &i:NewConfig.variables) {
if(!i.empty() && !StorageService()->VariablesDB().Exists("id",i)) {
return BadRequest(RESTAPI::Errors::VariableMustExist);
@@ -228,20 +246,15 @@ namespace OpenWifi{
Existing.variables = ToVariables;
}
if(AssignIfPresent(ParsedObj,"managementPolicy",MovePolicy)) {
if(!MovePolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewConfig.managementPolicy)) {
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
ExistingPolicy = Existing.managementPolicy;
}
AssignIfPresent(ParsedObj, "rrm", Existing.rrm);
AssignIfPresent(ParsedObj, "firmwareUpgrade",Existing.firmwareUpgrade);
AssignIfPresent(ParsedObj, "firmwareRCOnly", Existing.firmwareRCOnly);
AssignIfPresent(RawObject, "rrm", Existing.rrm);
AssignIfPresent(RawObject, "firmwareUpgrade",Existing.firmwareUpgrade);
AssignIfPresent(RawObject, "firmwareRCOnly", Existing.firmwareRCOnly);
if(DB_.UpdateRecord("id",UUID,Existing)) {
MoveUsage(StorageService()->PolicyDB(), DB_, ExistingPolicy, MovePolicy, Existing.info.id);
ManageMembership(StorageService()->VariablesDB(),&ProvObjects::VariableBlock::configurations, FromVariables, ToVariables, Existing.info.id);
ManageMembership(StorageService()->VenueDB(), &ProvObjects::Venue::configurations, FromVenue, ToVenue, Existing.info.id);
ManageMembership(StorageService()->EntityDB(), &ProvObjects::Entity::configurations, FromEntity, ToEntity, Existing.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,FromPolicy,ToPolicy,Existing.info.id);
ProvObjects::DeviceConfiguration D;
DB_.GetRecord("id",UUID,D);

View File

@@ -66,13 +66,11 @@ namespace OpenWifi{
return BadRequest(RESTAPI::Errors::StillInUse);
}
if(DB_.DeleteRecord("id",UUID)) {
if(!Existing.entity.empty())
StorageService()->EntityDB().DeleteLocation("id",Existing.entity,UUID);
DB_.DeleteRecord("id",UUID);
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::contacts,Existing.entity,Existing.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.info.id,"",Existing.info.id);
return OK();
}
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
}
void RESTAPI_contact_handler::DoPost() {
std::string UUID = GetBinding(RESTAPI::Protocol::UUID,"");
@@ -102,10 +100,8 @@ namespace OpenWifi{
NewObject.inUse.clear();
if(DB_.CreateRecord(NewObject)) {
StorageService()->EntityDB().AddContact("id",NewObject.entity,NewObject.info.id);
if(!NewObject.managementPolicy.empty())
StorageService()->PolicyDB().AddInUse("id",NewObject.managementPolicy,DB_.Prefix(),NewObject.info.id);
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::contacts,NewObject.entity,NewObject.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id);
ProvObjects::Contact NewContact;
StorageService()->ContactDB().GetRecord("id", NewObject.info.id, NewContact);
@@ -135,23 +131,13 @@ namespace OpenWifi{
return BadRequest(RESTAPI::Errors::NameMustBeSet);
}
std::string MoveToPolicy, MoveFromPolicy;
if(AssignIfPresent(RawObject,"managementPolicy",MoveToPolicy)) {
if(!MoveToPolicy.empty() && !StorageService()->PolicyDB().Exists("id",MoveToPolicy)) {
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
MoveFromPolicy = Existing.managementPolicy;
Existing.managementPolicy = MoveToPolicy;
}
std::string MoveToEntity,MoveFromEntity;
if(AssignIfPresent(RawObject,"entity",MoveToEntity)) {
if(!MoveToEntity.empty() && !StorageService()->EntityDB().Exists("id",MoveToEntity)) {
std::string FromPolicy, ToPolicy;
if(!CreateMove(RawObject,"managementPolicy",&ContactDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromEntity, ToEntity;
if(!CreateMove(RawObject,"entity",&ContactDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
}
MoveFromEntity = Existing.entity;
Existing.entity = MoveToEntity;
}
AssignIfPresent(RawObject, "title", Existing.title);
AssignIfPresent(RawObject, "salutation", Existing.salutation);
@@ -170,9 +156,8 @@ namespace OpenWifi{
Existing.phones = NewObject.phones;
if(DB_.UpdateRecord("id", UUID, Existing)) {
MoveUsage(StorageService()->PolicyDB(),DB_,MoveFromPolicy,MoveToPolicy,Existing.info.id);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::contacts,MoveFromEntity,MoveToEntity,Existing.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,FromPolicy,ToPolicy,Existing.info.id);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::contacts,FromEntity,ToEntity,Existing.info.id);
ProvObjects::Contact NewObjectAdded;
DB_.GetRecord("id", UUID, NewObjectAdded);

View File

@@ -299,4 +299,14 @@ namespace OpenWifi {
}
}
template <typename Member, typename Rec, typename DB > bool CreateMove(const Poco::JSON::Object::Ptr & RawObj, const char *fieldname, Member T, Rec & Existing, std::string &From, std::string &To, DB & TheDB) {
if(RawObj->has(fieldname)) {
From = Existing.*T;
To = RawObj->get(fieldname).toString();
if(!To.empty() && !TheDB.Exists("id",To))
return false;
Existing.*T=To;
}
return true;
}
}

View File

@@ -42,20 +42,15 @@ namespace OpenWifi{
}
if( !Existing.children.empty() || !Existing.devices.empty() || !Existing.venues.empty() || !Existing.locations.empty()
|| !Existing.contacts.empty()) {
|| !Existing.contacts.empty() || !Existing.configurations.empty()) {
return BadRequest(RESTAPI::Errors::StillInUse);
}
if(!Existing.deviceConfiguration.empty()) {
for(auto &i:Existing.deviceConfiguration)
StorageService()->ConfigurationDB().DeleteInUse("id", i, DB_.Prefix(), Existing.info.id);
}
if(DB_.DeleteRecord("id",UUID)) {
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id);
DB_.DeleteRecord("id",UUID);
DB_.DeleteChild("id",Existing.parent,UUID);
return OK();
}
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
}
void RESTAPI_entity_handler::DoPost() {
@@ -144,27 +139,9 @@ namespace OpenWifi{
return BadRequest(RESTAPI::Errors::NameMustBeSet);
}
std::string NewManagementPolicy;
Types::UUIDvec_t NewConfiguration;
bool MovingConfiguration=false,
MovingManagementPolicy=false;
if(RawObject->has("deviceConfiguration")) {
if(!NewEntity.deviceConfiguration.empty()) {
for(auto &i:NewEntity.deviceConfiguration) {
if(!StorageService()->ConfigurationDB().Exists("id",i)) {
return BadRequest(RESTAPI::Errors::ConfigurationMustExist);
}
}
NewConfiguration = NewEntity.deviceConfiguration;
}
MovingConfiguration = Existing.deviceConfiguration != NewConfiguration;
}
if(AssignIfPresent(RawObject,"managementPolicy",NewManagementPolicy)) {
if(!NewManagementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewManagementPolicy)) {
std::string FromPolicy, ToPolicy;
if(!CreateMove(RawObject,"managementPolicy",&EntityDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
MovingManagementPolicy = Existing.managementPolicy != NewManagementPolicy;
}
if(RawObject->has("sourceIP")) {
if(!NewEntity.sourceIP.empty() && !CIDR::ValidateIpRanges(NewEntity.sourceIP)) {
@@ -181,26 +158,7 @@ namespace OpenWifi{
AssignIfPresent(RawObject, "rrm", Existing.rrm);
if(DB_.UpdateRecord("id",UUID,Existing)) {
if(MovingConfiguration) {
if(!Existing.deviceConfiguration.empty())
for(auto &i:Existing.deviceConfiguration)
StorageService()->ConfigurationDB().DeleteInUse("id",i,DB_.Prefix(),Existing.info.id);
if(!NewConfiguration.empty())
for(auto &i:NewConfiguration)
StorageService()->ConfigurationDB().AddInUse("id",i,DB_.Prefix(),Existing.info.id);
Existing.deviceConfiguration = NewConfiguration;
}
if(MovingManagementPolicy) {
if(!Existing.managementPolicy.empty())
StorageService()->PolicyDB().DeleteInUse("id",Existing.managementPolicy, DB_.Prefix(), Existing.info.id);
if(!NewManagementPolicy.empty())
StorageService()->PolicyDB().AddInUse("id", NewManagementPolicy, DB_.Prefix(), Existing.info.id);
Existing.managementPolicy = NewManagementPolicy;
}
DB_.UpdateRecord("id", Existing.info.id, Existing);
MoveUsage(StorageService()->PolicyDB(),DB_,FromPolicy,ToPolicy,Existing.info.id);
Poco::JSON::Object Answer;
ProvObjects::Entity NewRecord;

View File

@@ -103,17 +103,11 @@ namespace OpenWifi{
return NotFound();
}
if(!Existing.venue.empty())
StorageService()->VenueDB().DeleteDevice("id",Existing.venue,Existing.info.id);
if(!Existing.entity.empty())
StorageService()->EntityDB().DeleteDevice("id",Existing.entity,Existing.info.id);
if(!Existing.location.empty())
StorageService()->LocationDB().DeleteInUse("id",Existing.location,DB_.Prefix(),Existing.info.id);
if(!Existing.contact.empty())
StorageService()->ContactDB().DeleteInUse("id",Existing.contact,DB_.Prefix(),Existing.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id);
RemoveMembership(StorageService()->VenueDB(),&ProvObjects::Venue::configurations,Existing.venue,Existing.info.id);
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::configurations,Existing.entity,Existing.info.id);
MoveUsage(StorageService()->LocationDB(),DB_,Existing.location,"",Existing.info.id);
MoveUsage(StorageService()->ContactDB(),DB_,Existing.contact,"",Existing.info.id);
if(!Existing.deviceConfiguration.empty()) {
ProvObjects::DeviceConfiguration DC;
@@ -126,13 +120,16 @@ namespace OpenWifi{
}
}
if(DB_.DeleteRecord("id", Existing.info.id)) {
DB_.DeleteRecord(RESTAPI::Protocol::ID, Existing.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id);
MoveUsage(StorageService()->LocationDB(),DB_,Existing.location,"",Existing.info.id);
MoveUsage(StorageService()->ContactDB(),DB_,Existing.contact,"",Existing.info.id);
MoveUsage(StorageService()->ConfigurationDB(),DB_,Existing.deviceConfiguration,"",Existing.info.id);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::devices,Existing.entity,"",Existing.info.id);
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::devices,Existing.venue,"",Existing.info.id);
DB_.DeleteRecord("id", Existing.info.id);
SerialNumberCache()->DeleteSerialNumber(SerialNumber);
return OK();
}
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
}
void RESTAPI_inventory_handler::DoPost() {
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER,"");
@@ -219,18 +216,13 @@ namespace OpenWifi{
if(DB_.CreateRecord(NewObject)) {
SerialNumberCache()->AddSerialNumber(SerialNumber,NewObject.deviceType);
if (!NewObject.venue.empty())
StorageService()->VenueDB().AddDevice("id",NewObject.venue,NewObject.info.id);
if (!NewObject.entity.empty())
StorageService()->EntityDB().AddDevice("id",NewObject.entity,NewObject.info.id);
if (!NewObject.location.empty())
StorageService()->LocationDB().AddInUse("id",NewObject.location,DB_.Prefix(),NewObject.info.id);
if (!NewObject.contact.empty())
StorageService()->ContactDB().AddInUse("id",NewObject.contact,DB_.Prefix(),NewObject.info.id);
if (!NewObject.deviceConfiguration.empty())
StorageService()->ConfigurationDB().AddInUse("id",NewObject.deviceConfiguration,DB_.Prefix(),NewObject.info.id);
if (!NewObject.managementPolicy.empty())
StorageService()->PolicyDB().AddInUse("id",NewObject.managementPolicy,DB_.Prefix(),NewObject.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,NewObject.managementPolicy,"",NewObject.info.id);
MoveUsage(StorageService()->LocationDB(),DB_,NewObject.location,"",NewObject.info.id);
MoveUsage(StorageService()->ContactDB(),DB_,NewObject.contact,"",NewObject.info.id);
MoveUsage(StorageService()->ConfigurationDB(),DB_,NewObject.deviceConfiguration,"",NewObject.info.id);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::devices,NewObject.entity,"",NewObject.info.id);
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::devices,NewObject.venue,"",NewObject.info.id);
ProvObjects::InventoryTag NewTag;
DB_.GetRecord("id",NewObject.info.id,NewTag);
@@ -409,61 +401,31 @@ namespace OpenWifi{
return BadRequest(RESTAPI::Errors::NameMustBeSet);
}
std::string NewVenue, NewEntity, NewLocation, NewContact, NewConfiguration, NewPolicy;
bool MovingVenue=false,
MovingEntity=false,
MovingLocation=false,
MovingContact=false,
MovingConfiguration=false,
MovingPolicy=false;
AssignIfPresent(RawObject, "rrm",Existing.rrm);
if(AssignIfPresent(RawObject, "venue",NewVenue)) {
if(!NewVenue.empty() && !StorageService()->VenueDB().Exists("id",NewVenue)) {
return BadRequest(RESTAPI::Errors::VenueMustExist);
}
MovingVenue = Existing.venue != NewVenue;
}
if(AssignIfPresent(RawObject, "entity",NewEntity)) {
if(!NewEntity.empty() && !StorageService()->EntityDB().Exists("id",NewEntity)) {
std::string FromPolicy, ToPolicy;
if(!CreateMove(RawObject,"managementPolicy",&InventoryDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
}
MovingEntity = Existing.entity != NewEntity;
}
if(!NewEntity.empty() && !NewVenue.empty()) {
return BadRequest(RESTAPI::Errors::NotBoth);
}
std::string FromEntity, ToEntity;
if(!CreateMove(RawObject,"entity",&InventoryDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
if(AssignIfPresent(RawObject, "location",NewLocation)) {
if(!NewLocation.empty() && !StorageService()->LocationDB().Exists("id",NewLocation)) {
return BadRequest(RESTAPI::Errors::LocationMustExist);
}
MovingLocation = Existing.location != NewLocation;
}
std::string FromVenue, ToVenue;
if(!CreateMove(RawObject,"venue",&InventoryDB::RecordName::venue, Existing, FromVenue, ToVenue, StorageService()->VenueDB()))
return BadRequest(RESTAPI::Errors::VenueMustExist);
if(AssignIfPresent(RawObject, "contact",NewContact)) {
if(!NewContact.empty() && !StorageService()->ContactDB().Exists("id",NewContact)) {
return BadRequest(RESTAPI::Errors::ContactMustExist);
}
MovingContact = Existing.contact != NewContact;
}
std::string FromLocation, ToLocation;
if(!CreateMove(RawObject,"location",&InventoryDB::RecordName::location, Existing, FromLocation, ToLocation, StorageService()->LocationDB()))
return BadRequest(RESTAPI::Errors::VenueMustExist);
if(AssignIfPresent(RawObject, "deviceConfiguration",NewConfiguration)) {
if(!NewConfiguration.empty() && !StorageService()->ConfigurationDB().Exists("id",NewConfiguration)) {
return BadRequest(RESTAPI::Errors::ConfigurationMustExist);
}
MovingConfiguration = Existing.deviceConfiguration != NewConfiguration;
}
std::string FromContact, ToContact;
if(!CreateMove(RawObject,"contact",&InventoryDB::RecordName::contact, Existing, FromContact, ToContact, StorageService()->ContactDB()))
return BadRequest(RESTAPI::Errors::VenueMustExist);
if(AssignIfPresent(RawObject, "managementPolicy",NewPolicy)) {
if(!NewPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewPolicy)) {
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
MovingPolicy = Existing.managementPolicy != NewPolicy;
}
std::string FromConfiguration, ToConfiguration;
if(!CreateMove(RawObject,"deviceConfiguration",&InventoryDB::RecordName::deviceConfiguration, Existing, FromConfiguration, ToConfiguration, StorageService()->ContactDB()))
return BadRequest(RESTAPI::Errors::VenueMustExist);
std::string NewSubScriber;
if(AssignIfPresent(RawObject, "subscriber", NewSubScriber)) {
@@ -489,79 +451,13 @@ namespace OpenWifi{
Existing.state = NewObject.state;
}
std::string Arg;
bool UnAssign=false;
if(HasParameter("unassign", Arg) && Arg=="true") {
UnAssign=true;
if(!Existing.venue.empty()) {
StorageService()->VenueDB().DeleteDevice("id",Existing.venue,Existing.info.id);
} else if(!Existing.entity.empty()) {
StorageService()->EntityDB().DeleteDevice("id",Existing.entity,Existing.info.id);
}
if(!Existing.location.empty())
StorageService()->LocationDB().DeleteInUse("id",Existing.location,DB_.Prefix(),Existing.info.id);
if(!Existing.contact.empty())
StorageService()->ContactDB().DeleteInUse("id",Existing.contact,DB_.Prefix(),Existing.info.id);
if(!Existing.deviceConfiguration.empty())
StorageService()->ConfigurationDB().DeleteInUse("id",Existing.deviceConfiguration,DB_.Prefix(),Existing.info.id);
if(!Existing.managementPolicy.empty())
StorageService()->PolicyDB().DeleteInUse("id",Existing.managementPolicy,DB_.Prefix(),Existing.info.id);
Existing.venue.clear();
Existing.entity.clear();
Existing.deviceConfiguration.clear();
Existing.contact.clear();
Existing.location.clear();
Existing.managementPolicy.clear();
}
std::cout << "Updating: " << Existing.info.id << " " << Existing.serialNumber << std::endl;
if(StorageService()->InventoryDB().UpdateRecord("id", Existing.info.id, Existing)) {
if(!UnAssign) {
if(MovingEntity) {
if(!Existing.entity.empty())
StorageService()->EntityDB().DeleteDevice("id",Existing.entity,Existing.info.id);
if(!NewEntity.empty())
StorageService()->EntityDB().AddDevice("id", NewEntity, Existing.info.id);
Existing.entity = NewEntity;
}
if(MovingVenue) {
if(!Existing.venue.empty())
StorageService()->VenueDB().DeleteDevice("id",Existing.venue,Existing.info.id);
if(!NewVenue.empty())
StorageService()->VenueDB().AddDevice("id", NewVenue, Existing.info.id);
Existing.venue = NewVenue;
}
if(MovingConfiguration) {
if(!Existing.deviceConfiguration.empty())
StorageService()->ConfigurationDB().DeleteInUse("id",Existing.deviceConfiguration,DB_.Prefix(),Existing.info.id);
if(!NewConfiguration.empty())
StorageService()->ConfigurationDB().AddInUse("id",NewConfiguration,DB_.Prefix(),Existing.info.id);
Existing.deviceConfiguration = NewConfiguration;
}
if(MovingContact) {
if(!Existing.contact.empty())
StorageService()->ContactDB().DeleteInUse("id",Existing.contact,DB_.Prefix(),Existing.info.id);
if(!NewContact.empty())
StorageService()->ContactDB().AddInUse("id",NewContact,DB_.Prefix(),Existing.info.id);
Existing.contact = NewContact;
}
if(MovingLocation) {
if(!Existing.location.empty())
StorageService()->LocationDB().DeleteInUse("id",Existing.location,DB_.Prefix(),Existing.info.id);
if(!NewLocation.empty())
StorageService()->LocationDB().AddInUse("id",NewLocation,DB_.Prefix(),Existing.info.id);
Existing.location = NewLocation;
}
if(MovingPolicy) {
if(!Existing.managementPolicy.empty())
StorageService()->PolicyDB().DeleteInUse("id",Existing.managementPolicy,DB_.Prefix(),Existing.info.id);
if(!NewPolicy.empty())
StorageService()->PolicyDB().AddInUse("id",NewPolicy,DB_.Prefix(),Existing.info.id);
Existing.managementPolicy = NewPolicy;
}
}
DB_.UpdateRecord("id", Existing.info.id, Existing);
MoveUsage(StorageService()->PolicyDB(),DB_,FromPolicy,ToPolicy,Existing.info.id);
MoveUsage(StorageService()->LocationDB(),DB_,FromLocation,ToLocation,Existing.info.id);
MoveUsage(StorageService()->ContactDB(),DB_,FromContact,ToContact,Existing.info.id);
MoveUsage(StorageService()->ConfigurationDB(),DB_,FromConfiguration,ToConfiguration,Existing.info.id);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::devices,FromEntity,ToEntity,Existing.info.id);
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::devices,FromVenue,ToVenue,Existing.info.id);
ProvObjects::InventoryTag NewObjectCreated;
DB_.GetRecord("id", Existing.info.id, NewObjectCreated);

View File

@@ -65,7 +65,8 @@ namespace OpenWifi{
}
DB_.DeleteRecord("id",UUID);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::locations,Existing.entity,"",Existing.info.id);
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::locations,Existing.entity,Existing.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.info.id,"",Existing.info.id);
return OK();
}
@@ -96,11 +97,11 @@ namespace OpenWifi{
NewObject.inUse.clear();
if(DB_.CreateRecord(NewObject)) {
if(!NewObject.managementPolicy.empty())
StorageService()->PolicyDB().AddInUse("id",NewObject.managementPolicy,DB_.Prefix(),NewObject.info.id);
StorageService()->EntityDB().AddLocation("id",NewObject.entity,NewObject.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id);
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::locations,NewObject.entity,NewObject.info.id);
LocationDB::RecordName AddedRecord;
DB_.GetRecord("id", NewObject.info.id,AddedRecord);
Poco::JSON::Object Answer;
NewObject.to_json(Answer);
return ReturnObject(Answer);
@@ -125,23 +126,13 @@ namespace OpenWifi{
return BadRequest( RESTAPI::Errors::NameMustBeSet);
}
std::string MoveFromPolicy,MoveToPolicy;
if(AssignIfPresent(RawObject,"managementPolicy",MoveToPolicy)) {
if(!MoveToPolicy.empty() && !StorageService()->PolicyDB().Exists("id",MoveToPolicy)) {
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
MoveFromPolicy = Existing.managementPolicy;
Existing.managementPolicy = MoveToPolicy;
}
std::string MoveFromEntity,MoveToEntity;
if(AssignIfPresent(RawObject,"entity",MoveToEntity)) {
if(!MoveToEntity.empty() && !StorageService()->EntityDB().Exists("id",MoveToEntity)) {
std::string FromPolicy, ToPolicy;
if(!CreateMove(RawObject,"managementPolicy",&LocationDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromEntity, ToEntity;
if(!CreateMove(RawObject,"entity",&LocationDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
}
MoveFromEntity = Existing.entity;
Existing.entity = MoveToEntity;
}
AssignIfPresent(RawObject, "buildingName", Existing.buildingName);
AssignIfPresent(RawObject, "city", Existing.city);
@@ -160,9 +151,8 @@ namespace OpenWifi{
Existing.type = NewObject.type;
if(DB_.UpdateRecord("id", UUID, Existing)) {
MoveUsage(StorageService()->PolicyDB(), DB_, MoveFromPolicy, MoveToPolicy, Existing.info.id);
ManageMembership(Storage().EntityDB(),&ProvObjects::Entity::locations,MoveFromEntity, MoveToEntity, Existing.info.id);
MoveUsage(StorageService()->PolicyDB(), DB_, FromPolicy, ToPolicy, Existing.info.id);
ManageMembership(Storage().EntityDB(),&ProvObjects::Entity::locations,FromEntity, ToEntity, Existing.info.id);
ProvObjects::Location NewObjectAdded;
DB_.GetRecord("id", UUID, NewObjectAdded);

View File

@@ -65,6 +65,7 @@ namespace OpenWifi{
StorageService()->PolicyDB().DeleteRecord("id", UUID);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementPolicies,Existing.entity,"",Existing.info.id);
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementPolicies,Existing.venue,"",Existing.info.id);
return OK();
}
@@ -74,26 +75,32 @@ namespace OpenWifi{
return BadRequest(RESTAPI::Errors::MissingUUID);
}
ProvObjects::ManagementPolicy NewPolicy;
auto NewObject = ParseStream();
if(!NewPolicy.from_json(NewObject)) {
ProvObjects::ManagementPolicy NewObject;
auto RawObject = ParseStream();
if(!NewObject.from_json(RawObject)) {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
if(!CreateObjectInfo(NewObject, UserInfo_.userinfo, NewPolicy.info)) {
if(!CreateObjectInfo(RawObject, UserInfo_.userinfo, NewObject.info)) {
return BadRequest( RESTAPI::Errors::NameMustBeSet);
}
if(NewPolicy.entity.empty() || !StorageService()->EntityDB().Exists("id", NewPolicy.entity)) {
if(NewObject.entity.empty() || !StorageService()->EntityDB().Exists("id", NewObject.entity)) {
return BadRequest(RESTAPI::Errors::EntityMustExist);
}
NewPolicy.inUse.clear();
if(DB_.CreateRecord(NewPolicy)) {
ProvObjects::ManagementPolicy Policy;
DB_.GetRecord("id",NewPolicy.info.id,Policy);
if(NewObject.venue.empty() || !StorageService()->VenueDB().Exists("id", NewObject.venue)) {
return BadRequest(RESTAPI::Errors::VenueMustExist);
}
NewObject.inUse.clear();
if(DB_.CreateRecord(NewObject)) {
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementPolicies,NewObject.entity,NewObject.info.id);
AddMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementPolicies,NewObject.venue,NewObject.info.id);
PolicyDB::RecordName AddedObject;
DB_.GetRecord("id",NewObject.info.id,AddedObject);
Poco::JSON::Object Answer;
Policy.to_json(Answer);
AddedObject.to_json(Answer);
return ReturnObject(Answer);
}
InternalError(RESTAPI::Errors::RecordNotCreated);
@@ -116,20 +123,21 @@ namespace OpenWifi{
return BadRequest( RESTAPI::Errors::NameMustBeSet);
}
std::string MoveFromEntity,MoveToEntity;
if(AssignIfPresent(RawObject,"entity",MoveToEntity)) {
if(!MoveToEntity.empty() && !StorageService()->EntityDB().Exists("id",MoveToEntity)) {
std::string FromEntity, ToEntity;
if(!CreateMove(RawObject,"entity",&PolicyDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromVenue, ToVenue;
if(!CreateMove(RawObject,"venue",&PolicyDB::RecordName::venue, Existing, FromVenue, ToVenue, StorageService()->VenueDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
}
MoveFromEntity = Existing.entity;
Existing.entity = MoveToEntity;
}
if(!NewPolicy.entries.empty())
Existing.entries = NewPolicy.entries;
if(DB_.UpdateRecord("id", Existing.info.id, Existing)) {
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementPolicies, MoveFromEntity,MoveToEntity,Existing.info.id);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementPolicies, FromEntity,ToEntity,Existing.info.id);
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementPolicies, FromVenue,ToVenue,Existing.info.id);
ProvObjects::ManagementPolicy P;
DB_.GetRecord("id",Existing.info.id,P);
Poco::JSON::Object Answer;

View File

@@ -65,6 +65,7 @@ namespace OpenWifi{
DB_.DeleteRecord("id", Existing.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id);
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementRoles,Existing.entity,Existing.info.id);
RemoveMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementRoles,Existing.venue,Existing.info.id);
return OK();
}
@@ -94,6 +95,7 @@ namespace OpenWifi{
if(DB_.CreateRecord(NewObject)) {
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementRoles,NewObject.entity,NewObject.info.id);
AddMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementRoles,NewObject.venue,NewObject.info.id);
MoveUsage(StorageService()->PolicyDB(), DB_, "", NewObject.managementPolicy, NewObject.info.id);
Poco::JSON::Object Answer;
@@ -122,27 +124,22 @@ namespace OpenWifi{
return BadRequest( RESTAPI::Errors::NameMustBeSet);
}
std::string MoveToPolicy,MoveFromPolicy;
if(AssignIfPresent(RawObject,"managementPolicy",MoveToPolicy)) {
if(!MoveToPolicy.empty() && !StorageService()->PolicyDB().Exists("id",MoveToPolicy)) {
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
MoveFromPolicy = Existing.managementPolicy;
Existing.managementPolicy = MoveToPolicy;
}
std::string MoveToEntity,MoveFromEntity;
if(AssignIfPresent(RawObject,"entity",MoveToEntity)) {
if(!MoveToEntity.empty() && !StorageService()->EntityDB().Exists("id",MoveToEntity)) {
std::string FromPolicy, ToPolicy;
if(!CreateMove(RawObject,"managementPolicy",&ManagementRoleDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromEntity, ToEntity;
if(!CreateMove(RawObject,"entity",&ManagementRoleDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromVenue, ToVenue;
if(!CreateMove(RawObject,"venue",&ManagementRoleDB::RecordName::venue, Existing, FromVenue, ToVenue, StorageService()->VenueDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
}
MoveFromEntity = Existing.entity;
Existing.entity = MoveToEntity;
}
if(DB_.UpdateRecord("id",UUID,Existing)) {
MoveUsage(StorageService()->PolicyDB(),DB_,MoveFromPolicy, MoveToPolicy, Existing.info.id);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementRoles, MoveFromEntity, MoveToEntity, Existing.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_, FromPolicy, ToPolicy, Existing.info.id);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementRoles, FromEntity, ToEntity, Existing.info.id);
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::managementRoles, FromVenue, ToVenue, Existing.info.id);
ProvObjects::ManagementRole NewRecord;

View File

@@ -38,11 +38,12 @@ namespace OpenWifi{
return UnAuthorized("You must be the creator of the map to delete it");
}
if(DB_.DeleteRecord("id", Existing.info.id)) {
DB_.DeleteRecord("id", Existing.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id);
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::maps,Existing.entity,Existing.info.id);
RemoveMembership(StorageService()->VenueDB(),&ProvObjects::Venue::maps,Existing.venue,Existing.info.id);
return OK();
}
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
}
static auto ValidateVisibility(const std::string &V) {
return (V=="private" || V=="public" || V=="select");
@@ -54,20 +55,32 @@ namespace OpenWifi{
return BadRequest(RESTAPI::Errors::MissingUUID);
}
auto Obj = ParseStream();
auto RawObject = ParseStream();
ProvObjects::Map NewObject;
if (!NewObject.from_json(Obj)) {
if (!NewObject.from_json(RawObject)) {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
if(!CreateObjectInfo(Obj, UserInfo_.userinfo, NewObject.info)) {
if(!CreateObjectInfo(RawObject, UserInfo_.userinfo, NewObject.info)) {
return BadRequest( RESTAPI::Errors::NameMustBeSet);
}
if(RawObject->has("entity")) {
if(!NewObject.entity.empty() && !StorageService()->EntityDB().Exists("id",NewObject.entity))
return BadRequest(RESTAPI::Errors::EntityMustExist);
}
if(RawObject->has("managementPolicy")) {
if(!NewObject.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewObject.managementPolicy))
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
NewObject.creator = UserInfo_.userinfo.id;
if(DB_.CreateRecord(NewObject)) {
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::maps,NewObject.entity,NewObject.info.id);
AddMembership(StorageService()->VenueDB(),&ProvObjects::Venue::maps,NewObject.venue,NewObject.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id);
Poco::JSON::Object Answer;
ProvObjects::Map M;
DB_.GetRecord("id", NewObject.info.id,M);
@@ -108,19 +121,28 @@ namespace OpenWifi{
}
}
if(RawObject->has("entity") && !StorageService()->EntityDB().Exists("id",NewObject.entity)) {
std::string FromPolicy, ToPolicy;
if(!CreateMove(RawObject,"managementPolicy",&MapDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
}
AssignIfPresent(RawObject,"entity",Existing.entity);
std::string FromEntity, ToEntity;
if(!CreateMove(RawObject,"entity",&MapDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromVenue, ToVenue;
if(!CreateMove(RawObject,"venue",&MapDB::RecordName::venue, Existing, FromVenue, ToVenue, StorageService()->VenueDB()))
return BadRequest(RESTAPI::Errors::VenueMustExist);
AssignIfPresent(RawObject,"data", Existing.data);
if(RawObject->has("visibility"))
Existing.visibility = NewObject.visibility;
if(DB_.UpdateRecord("id",UUID,Existing)) {
MoveUsage(StorageService()->PolicyDB(),DB_,FromPolicy,ToPolicy,Existing.info.id);
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::maps,FromEntity,ToEntity,Existing.info.id);
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::maps,FromVenue,ToVenue,Existing.info.id);
ProvObjects::Map NewRecord;
DB_.GetRecord("id", UUID, NewRecord);
Poco::JSON::Object Answer;
NewRecord.to_json(Answer);

View File

@@ -39,10 +39,11 @@ namespace OpenWifi {
if(!Existing.configurations.empty()) {
return BadRequest(RESTAPI::Errors::StillInUse);
}
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id);
RemoveMembership(StorageService()->VenueDB(),&ProvObjects::Venue::variables,Existing.venue,Existing.info.id);
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::variables,Existing.entity,Existing.info.id);
DB_.DeleteRecord("id", UUID);
return OK();
}
@@ -53,29 +54,34 @@ namespace OpenWifi {
}
auto RawObj = ParseStream();
VariablesDB::RecordName NewObj;
if(!NewObj.from_json(RawObj)) {
VariablesDB::RecordName NewObject;
if(!NewObject.from_json(RawObj)) {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
if(!NewObj.entity.empty() && !StorageService()->EntityDB().Exists("id",NewObj.entity)) {
if(!NewObject.entity.empty() && !StorageService()->EntityDB().Exists("id",NewObject.entity)) {
return BadRequest(RESTAPI::Errors::EntityMustExist);
}
if(!NewObj.venue.empty() && !StorageService()->VenueDB().Exists("id",NewObj.venue)) {
if(!NewObject.venue.empty() && !StorageService()->VenueDB().Exists("id",NewObject.venue)) {
return BadRequest(RESTAPI::Errors::VenueMustExist);
}
if(!ProvObjects::CreateObjectInfo(RawObj,UserInfo_.userinfo,NewObj.info)) {
if(!NewObject.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewObject.managementPolicy)) {
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
if(!ProvObjects::CreateObjectInfo(RawObj,UserInfo_.userinfo,NewObject.info)) {
return BadRequest((RESTAPI::Errors::MissingOrInvalidParameters));
}
if(DB_.CreateRecord(NewObj)) {
AddMembership(StorageService()->VenueDB(),&ProvObjects::Venue::variables,NewObj.venue, NewObj.info.id);
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::variables,NewObj.entity, NewObj.info.id);
if(DB_.CreateRecord(NewObject)) {
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id);
AddMembership(StorageService()->VenueDB(),&ProvObjects::Venue::variables,NewObject.venue, NewObject.info.id);
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::variables,NewObject.entity, NewObject.info.id);
VariablesDB::RecordName Added;
StorageService()->VariablesDB().GetRecord("id",NewObj.info.id,Added);
DB_.GetRecord("id",NewObject.info.id,Added);
Poco::JSON::Object Answer;
Added.to_json(Answer);
return ReturnObject(Answer);
@@ -94,47 +100,38 @@ namespace OpenWifi {
return NotFound();
}
auto RawObj = ParseStream();
auto RawObject = ParseStream();
VariablesDB::RecordName NewObj;
if(!NewObj.from_json(RawObj)) {
if(!NewObj.from_json(RawObject)) {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
if(!ProvObjects::UpdateObjectInfo(RawObj,UserInfo_.userinfo,Existing.info)) {
if(!ProvObjects::UpdateObjectInfo(RawObject,UserInfo_.userinfo,Existing.info)) {
return BadRequest((RESTAPI::Errors::MissingOrInvalidParameters));
}
if(RawObj->has("variables"))
if(RawObject->has("variables"))
Existing.variables = NewObj.variables;
std::string ExistingEntity, MovingToEntity;
if(RawObj->has("entity")) {
ExistingEntity = Existing.entity;
MovingToEntity = RawObj->get("entity").toString();
if(!MovingToEntity.empty() && !StorageService()->EntityDB().Exists("id",MovingToEntity)) {
std::string FromPolicy, ToPolicy;
if(!CreateMove(RawObject,"managementPolicy",&VariablesDB::RecordName::managementPolicy, Existing, FromPolicy, ToPolicy, StorageService()->PolicyDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
}
Existing.entity = MovingToEntity;
}
std::string ExistingVenue, MovingToVenue;
if(RawObj->has("venue")) {
ExistingVenue = Existing.venue;
MovingToVenue = RawObj->get("venue").toString();
if(!MovingToVenue.empty() && !StorageService()->VenueDB().Exists("id",MovingToVenue)) {
std::string FromEntity, ToEntity;
if(!CreateMove(RawObject,"entity",&VariablesDB::RecordName::entity, Existing, FromEntity, ToEntity, StorageService()->EntityDB()))
return BadRequest(RESTAPI::Errors::EntityMustExist);
std::string FromVenue, ToVenue;
if(!CreateMove(RawObject,"venue",&VariablesDB::RecordName::venue, Existing, FromVenue, ToVenue, StorageService()->VenueDB()))
return BadRequest(RESTAPI::Errors::VenueMustExist);
}
Existing.venue = MovingToVenue;
}
if(DB_.UpdateRecord("id", UUID, Existing)) {
ManageMembership(StorageService()->VenueDB(), &ProvObjects::Venue::variables, ExistingVenue,
MovingToVenue, Existing.info.id);
ManageMembership(StorageService()->EntityDB(), &ProvObjects::Entity::variables, ExistingEntity,
MovingToEntity, Existing.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,FromPolicy,ToPolicy,Existing.info.id);
ManageMembership(StorageService()->VenueDB(), &ProvObjects::Venue::variables, FromVenue, ToVenue, Existing.info.id);
ManageMembership(StorageService()->EntityDB(), &ProvObjects::Entity::variables, FromEntity, ToEntity, Existing.info.id);
VariablesDB::RecordName Added;
StorageService()->VariablesDB().GetRecord("id",NewObj.info.id,Added);
DB_.GetRecord("id",NewObj.info.id,Added);
Poco::JSON::Object Answer;
Added.to_json(Answer);
return ReturnObject(Answer);

View File

@@ -95,6 +95,9 @@ namespace OpenWifi::ProvObjects {
field_to_json( Obj,"sourceIP",sourceIP);
field_to_json( Obj,"variables", variables);
field_to_json( Obj,"managementPolicies", managementPolicies);
field_to_json( Obj,"managementRoles", managementRoles);
field_to_json( Obj,"maps", maps);
field_to_json( Obj,"configurations", configurations);
}
bool Entity::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -112,6 +115,9 @@ namespace OpenWifi::ProvObjects {
field_from_json( Obj,"sourceIP",sourceIP);
field_from_json( Obj,"variables", variables);
field_from_json( Obj,"managementPolicies", managementPolicies);
field_from_json( Obj,"managementRoles", managementRoles);
field_from_json( Obj,"maps", maps);
field_from_json( Obj,"configurations", configurations);
return true;
} catch(...) {
@@ -151,6 +157,10 @@ namespace OpenWifi::ProvObjects {
field_to_json( Obj,"rrm",rrm);
field_to_json( Obj,"sourceIP",sourceIP);
field_to_json( Obj,"variables", variables);
field_to_json( Obj,"managementPolicies", managementPolicies);
field_to_json( Obj,"managementRoles", managementRoles);
field_to_json( Obj,"maps", maps);
field_to_json( Obj,"configurations", configurations);
}
bool Venue::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -170,6 +180,10 @@ namespace OpenWifi::ProvObjects {
field_from_json( Obj,"rrm",rrm);
field_from_json( Obj,"sourceIP",sourceIP);
field_from_json( Obj,"variables", variables);
field_from_json( Obj,"managementPolicies", managementPolicies);
field_from_json( Obj,"managementRoles", managementRoles);
field_from_json( Obj,"maps", maps);
field_from_json( Obj,"configurations", configurations);
return true;
} catch (...) {
@@ -199,6 +213,7 @@ namespace OpenWifi::ProvObjects {
field_to_json( Obj,"managementPolicy",managementPolicy);
field_to_json( Obj,"users",users);
field_to_json( Obj,"entity",entity);
field_to_json( Obj,"venue",venue);
}
bool ManagementRole::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -207,6 +222,7 @@ namespace OpenWifi::ProvObjects {
field_from_json( Obj,"managementPolicy",managementPolicy);
field_from_json( Obj,"users",users);
field_from_json( Obj,"entity",entity);
field_from_json( Obj,"venue",venue);
return true;
} catch(...) {
}
@@ -411,6 +427,9 @@ namespace OpenWifi::ProvObjects {
field_to_json( Obj,"firmwareUpgrade",firmwareUpgrade);
field_to_json( Obj,"firmwareRCOnly",firmwareRCOnly);
field_to_json( Obj,"subscriberOnly",subscriberOnly);
field_to_json( Obj,"entity", entity);
field_to_json( Obj,"venue", venue);
field_to_json( Obj,"subscriber", subscriber);
}
bool DeviceConfiguration::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -425,6 +444,9 @@ namespace OpenWifi::ProvObjects {
field_from_json( Obj,"firmwareUpgrade",firmwareUpgrade);
field_from_json( Obj,"firmwareRCOnly",firmwareRCOnly);
field_from_json( Obj,"subscriberOnly",subscriberOnly);
field_from_json( Obj,"entity", entity);
field_from_json( Obj,"venue", venue);
field_from_json( Obj,"subscriber", subscriber);
return true;
} catch(...) {
@@ -603,6 +625,8 @@ namespace OpenWifi::ProvObjects {
RESTAPI_utils::field_to_json( Obj,"creator",creator);
field_to_json( Obj,"visibility",visibility);
RESTAPI_utils::field_to_json( Obj,"access",access);
RESTAPI_utils::field_to_json( Obj,"managementPolicy", managementPolicy);
RESTAPI_utils::field_to_json( Obj,"venue", venue);
}
bool Map::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -613,6 +637,8 @@ namespace OpenWifi::ProvObjects {
RESTAPI_utils::field_from_json( Obj,"creator",creator);
field_from_json( Obj,"visibility",visibility);
RESTAPI_utils::field_from_json( Obj,"access",access);
RESTAPI_utils::field_from_json( Obj,"managementPolicy", managementPolicy);
RESTAPI_utils::field_from_json( Obj,"venue", venue);
return true;
} catch(...) {
@@ -706,6 +732,7 @@ namespace OpenWifi::ProvObjects {
RESTAPI_utils::field_to_json( Obj,"subscriber", subscriber);
RESTAPI_utils::field_to_json( Obj,"inventory", inventory);
RESTAPI_utils::field_to_json( Obj,"configurations", configurations);
RESTAPI_utils::field_to_json( Obj,"managementPolicy", managementPolicy);
}
bool VariableBlock::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -717,6 +744,7 @@ namespace OpenWifi::ProvObjects {
RESTAPI_utils::field_from_json( Obj,"subscriber", subscriber);
RESTAPI_utils::field_from_json( Obj,"inventory", inventory);
RESTAPI_utils::field_from_json( Obj,"configurations", configurations);
RESTAPI_utils::field_from_json( Obj,"managementPolicy", managementPolicy);
return true;
} catch(...) {
}

View File

@@ -48,6 +48,7 @@ namespace OpenWifi::ProvObjects {
std::vector<ManagementPolicyEntry> entries;
Types::StringVec inUse;
Types::UUID_t entity;
Types::UUID_t venue;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
@@ -69,6 +70,8 @@ namespace OpenWifi::ProvObjects {
Types::UUIDvec_t variables;
Types::UUIDvec_t managementPolicies;
Types::UUIDvec_t managementRoles;
Types::UUIDvec_t maps;
Types::UUIDvec_t configurations;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
@@ -100,6 +103,10 @@ namespace OpenWifi::ProvObjects {
std::string rrm;
Types::StringVec sourceIP;
Types::UUIDvec_t variables;
Types::UUIDvec_t configurations;
Types::UUIDvec_t maps;
Types::UUIDvec_t managementPolicies;
Types::UUIDvec_t managementRoles;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
@@ -121,6 +128,7 @@ namespace OpenWifi::ProvObjects {
Types::UUIDvec_t users;
Types::StringVec inUse;
Types::UUID_t entity;
Types::UUID_t venue;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
@@ -269,6 +277,9 @@ namespace OpenWifi::ProvObjects {
std::string firmwareUpgrade;
bool firmwareRCOnly=false;
bool subscriberOnly=false;
std::string venue;
std::string entity;
std::string subscriber;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
@@ -389,6 +400,8 @@ namespace OpenWifi::ProvObjects {
std::string creator;
VISIBILITY visibility = PRIVATE;
ObjectACLList access;
Types::UUID_t managementPolicy;
std::string venue;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
@@ -451,6 +464,7 @@ namespace OpenWifi::ProvObjects {
std::string subscriber;
std::string inventory;
Types::UUIDvec_t configurations;
Types::UUID_t managementPolicy;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);

View File

@@ -32,7 +32,10 @@ namespace OpenWifi {
ORM::Field{"tags",ORM::FieldType::FT_TEXT},
ORM::Field{"firmwareUpgrade",ORM::FieldType::FT_TEXT},
ORM::Field{"firmwareRCOnly",ORM::FieldType::FT_INT},
ORM::Field{"subscriberOnly",ORM::FieldType::FT_BOOLEAN}
ORM::Field{"subscriberOnly",ORM::FieldType::FT_BOOLEAN},
ORM::Field{"entity",ORM::FieldType::FT_TEXT},
ORM::Field{"venue",ORM::FieldType::FT_TEXT},
ORM::Field{"subscriber",ORM::FieldType::FT_TEXT}
};
static ORM::IndexVec ConfigurationDB_Indexes{
@@ -44,7 +47,10 @@ namespace OpenWifi {
bool ConfigurationDB::Upgrade(uint32_t from, uint32_t &to) {
std::vector<std::string> Statements{
"alter table " + TableName_ + " add column subscriberOnly BOOLEAN;"
"alter table " + TableName_ + " add column subscriberOnly BOOLEAN;",
"alter table " + TableName_ + " add column entity TEXT;",
"alter table " + TableName_ + " add column subscriber TEXT;",
"alter table " + TableName_ + " add column venue TEXT;"
};
RunScript(Statements);
to = 2;
@@ -148,6 +154,9 @@ template<> void ORM::DB< OpenWifi::ConfigurationDBRecordType, OpenWifi::ProvO
Out.firmwareUpgrade = In.get<13>();
Out.firmwareRCOnly = In.get<14>();
Out.subscriberOnly = In.get<15>();
Out.entity = In.get<16>();
Out.venue = In.get<17>();
Out.subscriber = In.get<18>();
}
template<> void ORM::DB< OpenWifi::ConfigurationDBRecordType, OpenWifi::ProvObjects::DeviceConfiguration>::Convert(const OpenWifi::ProvObjects::DeviceConfiguration &In, OpenWifi::ConfigurationDBRecordType &Out) {
@@ -167,4 +176,7 @@ template<> void ORM::DB< OpenWifi::ConfigurationDBRecordType, OpenWifi::ProvO
Out.set<13>(In.firmwareUpgrade);
Out.set<14>(In.firmwareRCOnly);
Out.set<15>(In.subscriberOnly);
Out.set<16>(In.entity);
Out.set<17>(In.venue);
Out.set<18>(In.subscriber);
}

View File

@@ -28,7 +28,10 @@ namespace OpenWifi {
std::string,
std::string,
uint32_t,
bool
bool,
std::string,
std::string,
std::string
> ConfigurationDBRecordType;
class ConfigurationDB : public ORM::DB<ConfigurationDBRecordType, ProvObjects::DeviceConfiguration> {

View File

@@ -37,7 +37,9 @@ namespace OpenWifi {
ORM::Field{"sourceIP",ORM::FieldType::FT_TEXT},
ORM::Field{"variables",ORM::FieldType::FT_TEXT},
ORM::Field{"managementPolicies",ORM::FieldType::FT_TEXT},
ORM::Field{"managementRoles",ORM::FieldType::FT_TEXT}
ORM::Field{"managementRoles",ORM::FieldType::FT_TEXT},
ORM::Field{"maps",ORM::FieldType::FT_TEXT},
ORM::Field{"configurations",ORM::FieldType::FT_TEXT}
};
static ORM::IndexVec EntityDB_Indexes{
@@ -58,6 +60,8 @@ namespace OpenWifi {
std::vector<std::string> Script{
"alter table " + TableName_ + " add column variables text",
"alter table " + TableName_ + " add column managementPolicies text",
"alter table " + TableName_ + " add column maps text",
"alter table " + TableName_ + " add column configurations text",
"alter table " + TableName_ + " add column managementRoles text"
};
@@ -245,6 +249,8 @@ template<> void ORM::DB< OpenWifi::EntityDBRecordType, OpenWifi::ProvObjects:
Out.variables = OpenWifi::RESTAPI_utils::to_object_array(In.get<17>());
Out.managementPolicies = OpenWifi::RESTAPI_utils::to_object_array(In.get<18>());
Out.managementRoles = OpenWifi::RESTAPI_utils::to_object_array(In.get<19>());
Out.maps = OpenWifi::RESTAPI_utils::to_object_array(In.get<20>());
Out.configurations = OpenWifi::RESTAPI_utils::to_object_array(In.get<21>());
}
template<> void ORM::DB< OpenWifi::EntityDBRecordType, OpenWifi::ProvObjects::Entity>::Convert(const OpenWifi::ProvObjects::Entity &In, OpenWifi::EntityDBRecordType &Out) {
@@ -268,4 +274,6 @@ template<> void ORM::DB< OpenWifi::EntityDBRecordType, OpenWifi::ProvObjects:
Out.set<17>(OpenWifi::RESTAPI_utils::to_string(In.variables));
Out.set<18>(OpenWifi::RESTAPI_utils::to_string(In.managementPolicies));
Out.set<19>(OpenWifi::RESTAPI_utils::to_string(In.managementRoles));
Out.set<20>(OpenWifi::RESTAPI_utils::to_string(In.maps));
Out.set<21>(OpenWifi::RESTAPI_utils::to_string(In.configurations));
}

View File

@@ -33,6 +33,8 @@ namespace OpenWifi {
std::string,
std::string,
std::string,
std::string,
std::string,
std::string
> EntityDBRecordType;

View File

@@ -27,6 +27,7 @@ namespace OpenWifi {
ORM::Field{"inUse",ORM::FieldType::FT_TEXT},
ORM::Field{"tags",ORM::FieldType::FT_TEXT},
ORM::Field{"entity",ORM::FieldType::FT_TEXT},
ORM::Field{"venue",ORM::FieldType::FT_TEXT}
};
static ORM::IndexVec RolesDB_Indexes{
@@ -39,6 +40,16 @@ namespace OpenWifi {
ManagementRoleDB::ManagementRoleDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) :
DB(T, "roles", RolesDB_Fields, RolesDB_Indexes, P, L, "rol") {}
bool ManagementRoleDB::Upgrade(uint32_t from, uint32_t &to) {
std::vector<std::string> Statements{
"alter table " + TableName_ + " add column entity text;",
"alter table " + TableName_ + " add column venue text;"
};
RunScript(Statements);
to = 2;
return true;
}
}
template<> void ORM::DB< OpenWifi::ManagementRoleDBRecordType, OpenWifi::ProvObjects::ManagementRole>::Convert(const OpenWifi::ManagementRoleDBRecordType &In, OpenWifi::ProvObjects::ManagementRole &Out) {
@@ -53,6 +64,7 @@ template<> void ORM::DB< OpenWifi::ManagementRoleDBRecordType, OpenWifi::Prov
Out.inUse = OpenWifi::RESTAPI_utils::to_object_array(In.get<8>());
Out.info.tags = OpenWifi::RESTAPI_utils::to_taglist(In.get<9>());
Out.entity = In.get<10>();
Out.venue = In.get<11>();
}
template<> void ORM::DB< OpenWifi::ManagementRoleDBRecordType, OpenWifi::ProvObjects::ManagementRole>::Convert(const OpenWifi::ProvObjects::ManagementRole &In, OpenWifi::ManagementRoleDBRecordType &Out) {
@@ -67,4 +79,5 @@ template<> void ORM::DB< OpenWifi::ManagementRoleDBRecordType, OpenWifi::Prov
Out.set<8>(OpenWifi::RESTAPI_utils::to_string(In.inUse));
Out.set<9>(OpenWifi::RESTAPI_utils::to_string(In.info.tags));
Out.set<10>(In.entity);
Out.set<11>(In.venue);
}

View File

@@ -23,6 +23,7 @@ namespace OpenWifi {
std::string,
std::string,
std::string,
std::string,
std::string
> ManagementRoleDBRecordType;
@@ -30,5 +31,6 @@ namespace OpenWifi {
public:
ManagementRoleDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
private:
bool Upgrade(uint32_t from, uint32_t &to) override;
};
}

View File

@@ -19,7 +19,9 @@ namespace OpenWifi {
ORM::Field{"creator",ORM::FieldType::FT_TEXT},
ORM::Field{"visibility",ORM::FieldType::FT_TEXT},
ORM::Field{"access",ORM::FieldType::FT_TEXT},
ORM::Field{"entity",ORM::FieldType::FT_TEXT}
ORM::Field{"entity",ORM::FieldType::FT_TEXT},
ORM::Field{"managementPolicy",ORM::FieldType::FT_TEXT},
ORM::Field{"venue",ORM::FieldType::FT_TEXT}
};
static ORM::IndexVec MapsDB_Indexes{
@@ -32,6 +34,17 @@ namespace OpenWifi {
MapDB::MapDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) :
DB(T, "maps", MapsDB_Fields, MapsDB_Indexes, P, L, "map") {}
bool MapDB::Upgrade(uint32_t from, uint32_t &to) {
std::vector<std::string> Statements{
"alter table " + TableName_ + " add column managementPolicy text;",
"alter table " + TableName_ + " add column entity text;",
"alter table " + TableName_ + " add column venue text;"
};
RunScript(Statements);
to = 2;
return true;
}
}
template<> void ORM::DB< OpenWifi::MapDBRecordType, OpenWifi::ProvObjects::Map>::Convert(const OpenWifi::MapDBRecordType &In, OpenWifi::ProvObjects::Map &Out) {
@@ -47,6 +60,8 @@ template<> void ORM::DB< OpenWifi::MapDBRecordType, OpenWifi::ProvObjects::Ma
Out.visibility = OpenWifi::ProvObjects::visibility_from_string(In.get<9>());
Out.access = OpenWifi::RESTAPI_utils::to_object<OpenWifi::ProvObjects::ObjectACLList>(In.get<10>());
Out.entity = In.get<11>();
Out.managementPolicy = In.get<12>();
Out.venue = In.get<13>();
}
template<> void ORM::DB< OpenWifi::MapDBRecordType, OpenWifi::ProvObjects::Map>::Convert(const OpenWifi::ProvObjects::Map &In, OpenWifi::MapDBRecordType &Out) {
@@ -62,4 +77,6 @@ template<> void ORM::DB< OpenWifi::MapDBRecordType, OpenWifi::ProvObjects::Ma
Out.set<9>(OpenWifi::ProvObjects::to_string(In.visibility));
Out.set<10>(OpenWifi::RESTAPI_utils::to_string(In.access));
Out.set<11>(In.entity);
Out.set<12>(In.managementPolicy);
Out.set<13>(In.venue);
}

View File

@@ -20,6 +20,8 @@ namespace OpenWifi {
std::string,
std::string,
std::string,
std::string,
std::string,
std::string
> MapDBRecordType;
@@ -27,5 +29,6 @@ namespace OpenWifi {
public:
MapDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
private:
bool Upgrade(uint32_t from, uint32_t &to) override;
};
}

View File

@@ -24,8 +24,8 @@ namespace OpenWifi {
ORM::Field{"entries",ORM::FieldType::FT_TEXT},
ORM::Field{"inUse",ORM::FieldType::FT_TEXT},
ORM::Field{"tags",ORM::FieldType::FT_TEXT},
ORM::Field{"entity",ORM::FieldType::FT_TEXT}
ORM::Field{"entity",ORM::FieldType::FT_TEXT},
ORM::Field{"venue",ORM::FieldType::FT_TEXT}
};
static ORM::IndexVec PolicyDB_Indexes{
@@ -38,6 +38,16 @@ namespace OpenWifi {
PolicyDB::PolicyDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) :
DB(T, "policies", PolicyDB_Fields, PolicyDB_Indexes, P, L, "pol") {}
bool PolicyDB::Upgrade(uint32_t from, uint32_t &to) {
std::vector<std::string> Statements{
"alter table " + TableName_ + " add column entity text;",
"alter table " + TableName_ + " add column venue text;"
};
RunScript(Statements);
to = 2;
return true;
}
}
template<> void ORM::DB< OpenWifi::PolicyDBRecordType, OpenWifi::ProvObjects::ManagementPolicy>::Convert(const OpenWifi::PolicyDBRecordType &In, OpenWifi::ProvObjects::ManagementPolicy &Out) {
@@ -51,6 +61,7 @@ template<> void ORM::DB< OpenWifi::PolicyDBRecordType, OpenWifi::ProvObjects:
Out.inUse = OpenWifi::RESTAPI_utils::to_object_array(In.get<7>());
Out.info.tags = OpenWifi::RESTAPI_utils::to_taglist(In.get<8>());
Out.entity = In.get<9>();
Out.venue = In.get<10>();
}
template<> void ORM::DB< OpenWifi::PolicyDBRecordType, OpenWifi::ProvObjects::ManagementPolicy>::Convert(const OpenWifi::ProvObjects::ManagementPolicy &In, OpenWifi::PolicyDBRecordType &Out) {
@@ -64,4 +75,5 @@ template<> void ORM::DB< OpenWifi::PolicyDBRecordType, OpenWifi::ProvObjects:
Out.set<7>(OpenWifi::RESTAPI_utils::to_string(In.inUse));
Out.set<8>(OpenWifi::RESTAPI_utils::to_string(In.info.tags));
Out.set<9>(In.entity);
Out.set<10>(In.venue);
}

View File

@@ -22,6 +22,7 @@ namespace OpenWifi {
std::string,
std::string,
std::string,
std::string,
std::string
> PolicyDBRecordType;
@@ -29,5 +30,6 @@ namespace OpenWifi {
public:
PolicyDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
private:
bool Upgrade(uint32_t from, uint32_t &to) override;
};
}

View File

@@ -23,7 +23,8 @@ namespace OpenWifi {
ORM::Field{"venue",ORM::FieldType::FT_TEXT},
ORM::Field{"subscriber",ORM::FieldType::FT_BIGINT},
ORM::Field{"inventory",ORM::FieldType::FT_BIGINT},
ORM::Field{"configurations",ORM::FieldType::FT_TEXT}
ORM::Field{"configurations",ORM::FieldType::FT_TEXT},
ORM::Field{"managementPolicy",ORM::FieldType::FT_TEXT}
};
const static ORM::IndexVec VariablesDB_Indexes{
@@ -41,6 +42,14 @@ namespace OpenWifi {
DB(T, "variables", VariablesDB_Fields, VariablesDB_Indexes, P, L, "var") {
}
bool VariablesDB::Upgrade(uint32_t from, uint32_t &to) {
std::vector<std::string> Statements{
"alter table " + TableName_ + " add column managementPolicy BOOLEAN;"
};
RunScript(Statements);
to = 2;
return true;
}
}
template<> void ORM::DB<OpenWifi::VariablesDBRecordType, OpenWifi::ProvObjects::VariableBlock>::Convert(const OpenWifi::VariablesDBRecordType &In, OpenWifi::ProvObjects::VariableBlock &Out) {
@@ -56,6 +65,7 @@ template<> void ORM::DB<OpenWifi::VariablesDBRecordType, OpenWifi::ProvObjects::
Out.subscriber = In.get<9>();
Out.inventory = In.get<10>();
Out.configurations = OpenWifi::RESTAPI_utils::to_object_array(In.get<11>());
Out.managementPolicy = In.get<12>();
}
template<> void ORM::DB<OpenWifi::VariablesDBRecordType, OpenWifi::ProvObjects::VariableBlock>::Convert(const OpenWifi::ProvObjects::VariableBlock &In, OpenWifi::VariablesDBRecordType &Out) {
@@ -71,4 +81,5 @@ template<> void ORM::DB<OpenWifi::VariablesDBRecordType, OpenWifi::ProvObjects::
Out.set<9>(In.subscriber);
Out.set<10>(In.inventory);
Out.set<11>(OpenWifi::RESTAPI_utils::to_string(In.configurations));
Out.set<12>(In.managementPolicy);
}

View File

@@ -20,6 +20,7 @@ namespace OpenWifi {
std::string,
std::string,
std::string,
std::string,
std::string
> VariablesDBRecordType;
@@ -27,5 +28,6 @@ namespace OpenWifi {
public:
explicit VariablesDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) noexcept;
private:
bool Upgrade(uint32_t from, uint32_t &to) override;
};
}

View File

@@ -37,7 +37,11 @@ namespace OpenWifi {
ORM::Field{"tags",ORM::FieldType::FT_TEXT},
ORM::Field{"deviceConfiguration",ORM::FieldType::FT_TEXT},
ORM::Field{"sourceIP",ORM::FieldType::FT_TEXT},
ORM::Field{"variables",ORM::FieldType::FT_TEXT}
ORM::Field{"variables",ORM::FieldType::FT_TEXT},
ORM::Field{"configurations",ORM::FieldType::FT_TEXT},
ORM::Field{"maps",ORM::FieldType::FT_TEXT},
ORM::Field{"managementPolicies",ORM::FieldType::FT_TEXT},
ORM::Field{"managementRoles",ORM::FieldType::FT_TEXT}
};
static ORM::IndexVec VenueDB_Indexes{
@@ -53,7 +57,11 @@ namespace OpenWifi {
bool VenueDB::Upgrade(uint32_t from, uint32_t &to) {
to = Version();
std::vector<std::string> Script{
"alter table " + TableName_ + " add column variables text"
"alter table " + TableName_ + " add column variables text",
"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"
};
for(const auto &i:Script) {
@@ -134,6 +142,10 @@ template<> void ORM::DB< OpenWifi::VenueDBRecordType, OpenWifi::ProvObjects::
Out.deviceConfiguration = OpenWifi::RESTAPI_utils::to_object_array(In.get<17>());
Out.sourceIP = OpenWifi::RESTAPI_utils::to_object_array(In.get<18>());
Out.variables = OpenWifi::RESTAPI_utils::to_object_array(In.get<19>());
Out.configurations = OpenWifi::RESTAPI_utils::to_object_array(In.get<20>());
Out.maps = OpenWifi::RESTAPI_utils::to_object_array(In.get<21>());
Out.managementPolicies = OpenWifi::RESTAPI_utils::to_object_array(In.get<22>());
Out.managementRoles = OpenWifi::RESTAPI_utils::to_object_array(In.get<23>());
}
template<> void ORM::DB< OpenWifi::VenueDBRecordType, OpenWifi::ProvObjects::Venue>::Convert(const OpenWifi::ProvObjects::Venue &In, OpenWifi::VenueDBRecordType &Out) {
@@ -157,4 +169,8 @@ template<> void ORM::DB< OpenWifi::VenueDBRecordType, OpenWifi::ProvObjects::
Out.set<17>(OpenWifi::RESTAPI_utils::to_string(In.deviceConfiguration));
Out.set<18>(OpenWifi::RESTAPI_utils::to_string(In.sourceIP));
Out.set<19>(OpenWifi::RESTAPI_utils::to_string(In.variables));
Out.set<20>(OpenWifi::RESTAPI_utils::to_string(In.configurations));
Out.set<21>(OpenWifi::RESTAPI_utils::to_string(In.maps));
Out.set<22>(OpenWifi::RESTAPI_utils::to_string(In.managementPolicies));
Out.set<23>(OpenWifi::RESTAPI_utils::to_string(In.managementRoles));
}

View File

@@ -32,6 +32,10 @@ namespace OpenWifi {
std::string,
std::string,
std::string,
std::string,
std::string,
std::string,
std::string,
std::string
> VenueDBRecordType;