mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-29 17:52:28 +00:00
Refactoring
This commit is contained in:
@@ -65,10 +65,12 @@ namespace OpenWifi{
|
||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
||||
}
|
||||
|
||||
if(DB_.DeleteRecord("id", UUID)) {
|
||||
return OK();
|
||||
}
|
||||
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
|
||||
DB_.DeleteRecord("id", UUID);
|
||||
MoveUsage(StorageService()->PolicyDB(),DB_,Existing.managementPolicy,"",Existing.info.id);
|
||||
for(const auto &i:Existing.variables)
|
||||
RemoveMembership(StorageService()->VariablesDB(),&ProvObjects::VariableBlock::configurations,i,Existing.info.id);
|
||||
|
||||
return OK();
|
||||
}
|
||||
|
||||
bool RESTAPI_configurations_handler::ValidateConfigBlock(const ProvObjects::DeviceConfiguration &Config, std::string & Error) {
|
||||
@@ -160,10 +162,8 @@ namespace OpenWifi{
|
||||
}
|
||||
|
||||
if(DB_.CreateRecord(C)) {
|
||||
MoveUsage(StorageService()->PolicyDB(),DB_,"",C.managementPolicy,C.info.id);
|
||||
DB_.GetRecord("id", C.info.id, C);
|
||||
if(!C.managementPolicy.empty())
|
||||
StorageService()->PolicyDB().AddInUse("id",C.managementPolicy,DB_.Prefix(), C.info.id);
|
||||
|
||||
Poco::JSON::Object Answer;
|
||||
C.to_json(Answer);
|
||||
return ReturnObject(Answer);
|
||||
@@ -192,6 +192,9 @@ namespace OpenWifi{
|
||||
return BadRequest(RESTAPI::Errors::InvalidDeviceTypes);
|
||||
}
|
||||
|
||||
if(!NewConfig.deviceTypes.empty())
|
||||
Existing.deviceTypes = NewConfig.deviceTypes;
|
||||
|
||||
std::string Error;
|
||||
if(!ValidateConfigBlock( NewConfig,Error)) {
|
||||
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid + ", error: " + Error);
|
||||
@@ -201,34 +204,44 @@ namespace OpenWifi{
|
||||
Existing.configuration = NewConfig.configuration;
|
||||
}
|
||||
|
||||
std::string MovePolicy;
|
||||
bool MovingPolicy=false;
|
||||
std::string MovePolicy, ExistingPolicy;
|
||||
if(AssignIfPresent(ParsedObj,"managementPolicy",MovePolicy)) {
|
||||
if(!MovePolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewConfig.managementPolicy)) {
|
||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||
}
|
||||
MovingPolicy = NewConfig.managementPolicy != Existing.managementPolicy;
|
||||
ExistingPolicy = Existing.managementPolicy;
|
||||
}
|
||||
|
||||
if(!NewConfig.deviceTypes.empty())
|
||||
Existing.deviceTypes = NewConfig.deviceTypes;
|
||||
Types::UUIDvec_t FromVariables, ToVariables;
|
||||
if(ParsedObj->has("variables")) {
|
||||
for(const auto &i:NewConfig.variables) {
|
||||
if(!i.empty() && !StorageService()->VariablesDB().Exists("id",i)) {
|
||||
return BadRequest(RESTAPI::Errors::VariableMustExist);
|
||||
}
|
||||
}
|
||||
for(const auto &i:Existing.variables)
|
||||
FromVariables.emplace_back(i);
|
||||
for(const auto &i:NewConfig.variables)
|
||||
ToVariables.emplace_back(i);
|
||||
FromVariables = Existing.variables;
|
||||
ToVariables = NewConfig.variables;
|
||||
Existing.variables = ToVariables;
|
||||
}
|
||||
|
||||
AssignIfPresent(ParsedObj, "rrm", Existing.rrm);
|
||||
AssignIfPresent(ParsedObj,"firmwareUpgrade",Existing.firmwareUpgrade);
|
||||
AssignIfPresent(ParsedObj,"firmwareRCOnly", Existing.firmwareRCOnly);
|
||||
if(AssignIfPresent(ParsedObj,"managementPolicy",MovePolicy)) {
|
||||
if(!MovePolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewConfig.managementPolicy)) {
|
||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||
}
|
||||
ExistingPolicy = Existing.managementPolicy;
|
||||
}
|
||||
|
||||
if(!NewConfig.variables.empty())
|
||||
Existing.variables = NewConfig.variables;
|
||||
AssignIfPresent(ParsedObj, "rrm", Existing.rrm);
|
||||
AssignIfPresent(ParsedObj, "firmwareUpgrade",Existing.firmwareUpgrade);
|
||||
AssignIfPresent(ParsedObj, "firmwareRCOnly", Existing.firmwareRCOnly);
|
||||
|
||||
if(DB_.UpdateRecord("id",UUID,Existing)) {
|
||||
if(MovingPolicy) {
|
||||
if(!Existing.managementPolicy.empty())
|
||||
StorageService()->PolicyDB().DeleteInUse("id",Existing.managementPolicy,DB_.Prefix(),Existing.info.id);
|
||||
if(!MovePolicy.empty())
|
||||
StorageService()->PolicyDB().AddInUse("id",MovePolicy,DB_.Prefix(),Existing.info.id);
|
||||
Existing.managementPolicy = MovePolicy;
|
||||
}
|
||||
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);
|
||||
|
||||
ProvObjects::DeviceConfiguration D;
|
||||
DB_.GetRecord("id",UUID,D);
|
||||
|
||||
@@ -136,23 +136,21 @@ namespace OpenWifi{
|
||||
}
|
||||
|
||||
std::string MoveToPolicy, MoveFromPolicy;
|
||||
bool MovingPolicy=false;
|
||||
if(AssignIfPresent(RawObject,"managementPolicy",MoveToPolicy)) {
|
||||
if(!MoveToPolicy.empty() && !StorageService()->PolicyDB().Exists("id",MoveToPolicy)) {
|
||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||
}
|
||||
MoveFromPolicy = Existing.managementPolicy;
|
||||
MovingPolicy = MoveToPolicy != Existing.managementPolicy;
|
||||
Existing.managementPolicy = MoveToPolicy;
|
||||
}
|
||||
|
||||
std::string MoveToEntity,MoveFromEntity;
|
||||
bool MovingEntity=false;
|
||||
if(AssignIfPresent(RawObject,"entity",MoveToEntity)) {
|
||||
if(!MoveToEntity.empty() && !StorageService()->EntityDB().Exists("id",MoveToEntity)) {
|
||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||
}
|
||||
MoveFromEntity = Existing.entity;
|
||||
MovingEntity = MoveToEntity != Existing.entity ;
|
||||
Existing.entity = MoveToEntity;
|
||||
}
|
||||
|
||||
AssignIfPresent(RawObject, "title", Existing.title);
|
||||
@@ -171,26 +169,10 @@ namespace OpenWifi{
|
||||
if(RawObject->has("phones"))
|
||||
Existing.phones = NewObject.phones;
|
||||
|
||||
Existing.entity = MoveToEntity;
|
||||
Existing.managementPolicy = MoveToPolicy;
|
||||
|
||||
if(DB_.UpdateRecord("id", UUID, Existing)) {
|
||||
|
||||
if(MovingPolicy) {
|
||||
if(!MoveFromPolicy.empty())
|
||||
StorageService()->PolicyDB().DeleteInUse("id",MoveFromPolicy,DB_.Prefix(),Existing.info.id);
|
||||
if(!MoveToPolicy.empty())
|
||||
StorageService()->PolicyDB().AddInUse("id", MoveToPolicy, DB_.Prefix(), Existing.info.id);
|
||||
}
|
||||
|
||||
if(MovingEntity) {
|
||||
if(!MoveFromEntity.empty()) {
|
||||
StorageService()->EntityDB().DeleteContact("id", MoveFromEntity, Existing.info.id);
|
||||
}
|
||||
if(!MoveToEntity.empty()) {
|
||||
StorageService()->EntityDB().AddContact("id", MoveToEntity, Existing.info.id);
|
||||
}
|
||||
}
|
||||
MoveUsage(StorageService()->PolicyDB(),DB_,MoveFromPolicy,MoveToPolicy,Existing.info.id);
|
||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::contacts,MoveFromEntity,MoveToEntity,Existing.info.id);
|
||||
|
||||
ProvObjects::Contact NewObjectAdded;
|
||||
DB_.GetRecord("id", UUID, NewObjectAdded);
|
||||
|
||||
@@ -244,4 +244,59 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename DBUsage, typename ObjectDB> void MoveUsage(DBUsage &DB_InUse, ObjectDB & DB, const std::string & From, const std::string & To, const std::string &Id) {
|
||||
if(From!=To) {
|
||||
if(!From.empty())
|
||||
DB_InUse.DeleteInUse("id",From,DB.Prefix(),Id);
|
||||
if(!To.empty())
|
||||
DB_InUse.AddInUse("id",To,DB.Prefix(),Id);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename DBUsage, typename ObjectDB> void MoveUsage(DBUsage &DB_InUse, ObjectDB & DB, const Types::UUIDvec_t & From, const Types::UUIDvec_t & To, const std::string &Id) {
|
||||
if(From!=To) {
|
||||
if(!From.empty()) {
|
||||
for(const auto &i:From)
|
||||
DB_InUse.DeleteInUse("id", i, DB.Prefix(), Id);
|
||||
}
|
||||
if(!To.empty()) {
|
||||
for(const auto &i:To)
|
||||
DB_InUse.AddInUse("id", i, DB.Prefix(), Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename DB> void MoveChild(DB &TheDB, const std::string & Parent, const std::string & Child, const std::string &Id) {
|
||||
if(Parent!=Child) {
|
||||
if(!Parent.empty())
|
||||
TheDB.InUse.DeleteInUse("id",Parent,Id);
|
||||
if(!Child.empty())
|
||||
TheDB.AddInUse("id",Child,Id);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename DB, typename Member> void RemoveMembership( DB & TheDB, Member T, const std::string & Obj, const std::string &Id) {
|
||||
if(!Obj.empty())
|
||||
TheDB.ManipulateVectorMember(T, "id", Obj, Id, false);
|
||||
}
|
||||
|
||||
template <typename DB, typename Member> void AddMembership( DB & TheDB, Member T, const std::string & Obj, const std::string &Id) {
|
||||
if(!Obj.empty())
|
||||
TheDB.ManipulateVectorMember(T, "id", Obj, Id, true);
|
||||
}
|
||||
|
||||
template <typename DB, typename Member> void ManageMembership( DB & TheDB, Member T, const std::string & From, const std::string & To, const std::string &Id) {
|
||||
RemoveMembership(TheDB,T,From,Id);
|
||||
AddMembership(TheDB,T,To,Id);
|
||||
}
|
||||
|
||||
template <typename DB, typename Member> void ManageMembership( DB & TheDB, Member T, const Types::UUIDvec_t & From, const Types::UUIDvec_t & To, const std::string &Id) {
|
||||
if(From!=To) {
|
||||
for (const auto &i: From)
|
||||
RemoveMembership(TheDB, T, i, Id);
|
||||
for (const auto &i: To)
|
||||
AddMembership(TheDB, T, i, Id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -88,13 +88,6 @@ namespace OpenWifi{
|
||||
return BadRequest(RESTAPI::Errors::ParentUUIDMustExist);
|
||||
}
|
||||
|
||||
if(!NewEntity.deviceConfiguration.empty()) {
|
||||
for(auto &i:NewEntity.deviceConfiguration)
|
||||
if(!StorageService()->ConfigurationDB().Exists("id",i)) {
|
||||
return BadRequest(RESTAPI::Errors::ConfigurationMustExist);
|
||||
}
|
||||
}
|
||||
|
||||
if(!NewEntity.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id", NewEntity.managementPolicy)){
|
||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||
}
|
||||
@@ -107,8 +100,11 @@ namespace OpenWifi{
|
||||
NewEntity.children.clear();
|
||||
NewEntity.contacts.clear();
|
||||
NewEntity.locations.clear();
|
||||
NewEntity.deviceConfiguration.clear();
|
||||
NewEntity.managementRoles.clear();
|
||||
|
||||
if(DB_.CreateShortCut(NewEntity)) {
|
||||
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewEntity.managementPolicy,NewEntity.info.id);
|
||||
if(UUID==EntityDB::RootUUID()) {
|
||||
DB_.CheckForRoot();
|
||||
} else {
|
||||
@@ -185,23 +181,6 @@ namespace OpenWifi{
|
||||
AssignIfPresent(RawObject, "rrm", Existing.rrm);
|
||||
|
||||
if(DB_.UpdateRecord("id",UUID,Existing)) {
|
||||
for(const auto &i:*Request) {
|
||||
std::string Child{i.second};
|
||||
auto UUID_parts = Utils::Split(Child,':');
|
||||
if(i.first=="add" && UUID_parts[0] == "con") {
|
||||
DB_.AddContact("id", UUID, UUID_parts[1]);
|
||||
StorageService()->ContactDB().AddInUse("id",UUID_parts[1],DB_.Prefix(), UUID);
|
||||
} else if (i.first == "del" && UUID_parts[0] == "con") {
|
||||
DB_.DeleteContact("id", UUID, UUID_parts[1]);
|
||||
StorageService()->ContactDB().DeleteInUse("id",UUID_parts[1],DB_.Prefix(),UUID);
|
||||
} else if (i.first == "add" && UUID_parts[0] == "loc") {
|
||||
DB_.AddLocation("id", UUID, UUID_parts[1]);
|
||||
StorageService()->LocationDB().AddInUse("id",UUID_parts[1],DB_.Prefix(),UUID);
|
||||
} else if (i.first == "del" && UUID_parts[0] == "loc") {
|
||||
DB_.DeleteLocation("id", UUID, UUID_parts[1]);
|
||||
StorageService()->LocationDB().DeleteInUse("id",UUID_parts[1],DB_.Prefix(),UUID);
|
||||
}
|
||||
}
|
||||
|
||||
if(MovingConfiguration) {
|
||||
if(!Existing.deviceConfiguration.empty())
|
||||
|
||||
@@ -64,13 +64,9 @@ namespace OpenWifi{
|
||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
||||
}
|
||||
|
||||
if(DB_.DeleteRecord("id",UUID)) {
|
||||
if(!Existing.entity.empty())
|
||||
StorageService()->EntityDB().DeleteLocation("id",Existing.entity,UUID);
|
||||
|
||||
return OK();
|
||||
}
|
||||
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
|
||||
DB_.DeleteRecord("id",UUID);
|
||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::locations,Existing.entity,"",Existing.info.id);
|
||||
return OK();
|
||||
}
|
||||
|
||||
void RESTAPI_location_handler::DoPost() {
|
||||
@@ -130,24 +126,20 @@ namespace OpenWifi{
|
||||
}
|
||||
|
||||
std::string MoveFromPolicy,MoveToPolicy;
|
||||
bool MovingPolicy=false;
|
||||
if(AssignIfPresent(RawObject,"managementPolicy",MoveToPolicy)) {
|
||||
if(!MoveToPolicy.empty() && !StorageService()->PolicyDB().Exists("id",MoveToPolicy)) {
|
||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||
}
|
||||
MoveFromPolicy = Existing.managementPolicy;
|
||||
MovingPolicy = MoveToPolicy != MoveFromPolicy;
|
||||
Existing.managementPolicy = MoveToPolicy;
|
||||
}
|
||||
|
||||
std::string MoveFromEntity,MoveToEntity;
|
||||
bool MovingEntity=false;
|
||||
if(AssignIfPresent(RawObject,"entity",MoveToEntity)) {
|
||||
if(!MoveToEntity.empty() && !StorageService()->EntityDB().Exists("id",MoveToEntity)) {
|
||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||
}
|
||||
MoveFromEntity = Existing.entity;
|
||||
MovingEntity = MoveToEntity != Existing.entity;
|
||||
Existing.entity = MoveToEntity;
|
||||
}
|
||||
|
||||
@@ -168,22 +160,12 @@ namespace OpenWifi{
|
||||
Existing.type = NewObject.type;
|
||||
|
||||
if(DB_.UpdateRecord("id", UUID, Existing)) {
|
||||
if(MovingPolicy) {
|
||||
if(!MoveFromPolicy.empty())
|
||||
StorageService()->PolicyDB().DeleteInUse("id",MoveFromPolicy,DB_.Prefix(),Existing.info.id);
|
||||
if(!MoveToPolicy.empty())
|
||||
StorageService()->PolicyDB().AddInUse("id", MoveToPolicy, DB_.Prefix(), Existing.info.id);
|
||||
}
|
||||
if(MovingEntity) {
|
||||
if(!MoveFromEntity.empty())
|
||||
StorageService()->EntityDB().DeleteLocation("id",MoveFromEntity,Existing.info.id);
|
||||
if(!MoveToEntity.empty())
|
||||
StorageService()->EntityDB().AddLocation("id", MoveToEntity, Existing.info.id);
|
||||
}
|
||||
|
||||
MoveUsage(StorageService()->PolicyDB(), DB_, MoveFromPolicy, MoveToPolicy, Existing.info.id);
|
||||
ManageMembership(Storage().EntityDB(),&ProvObjects::Entity::locations,MoveFromEntity, MoveToEntity, Existing.info.id);
|
||||
|
||||
ProvObjects::Location NewObjectAdded;
|
||||
DB_.GetRecord("id", UUID, NewObjectAdded);
|
||||
|
||||
Poco::JSON::Object Answer;
|
||||
NewObjectAdded.to_json(Answer);
|
||||
return ReturnObject(Answer);
|
||||
|
||||
@@ -63,11 +63,9 @@ namespace OpenWifi{
|
||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
||||
}
|
||||
|
||||
if(StorageService()->PolicyDB().DeleteRecord("id", UUID)) {
|
||||
return OK();
|
||||
}
|
||||
|
||||
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
|
||||
StorageService()->PolicyDB().DeleteRecord("id", UUID);
|
||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementPolicies,Existing.entity,"",Existing.info.id);
|
||||
return OK();
|
||||
}
|
||||
|
||||
void RESTAPI_managementPolicy_handler::DoPost() {
|
||||
@@ -86,8 +84,11 @@ namespace OpenWifi{
|
||||
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
||||
}
|
||||
|
||||
NewPolicy.inUse.clear();
|
||||
if(NewPolicy.entity.empty() || !StorageService()->EntityDB().Exists("id", NewPolicy.entity)) {
|
||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||
}
|
||||
|
||||
NewPolicy.inUse.clear();
|
||||
if(DB_.CreateRecord(NewPolicy)) {
|
||||
ProvObjects::ManagementPolicy Policy;
|
||||
DB_.GetRecord("id",NewPolicy.info.id,Policy);
|
||||
@@ -106,20 +107,30 @@ namespace OpenWifi{
|
||||
}
|
||||
|
||||
ProvObjects::ManagementPolicy NewPolicy;
|
||||
auto NewObject = ParseStream();
|
||||
if(!NewPolicy.from_json(NewObject)) {
|
||||
auto RawObject = ParseStream();
|
||||
if(!NewPolicy.from_json(RawObject)) {
|
||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||
}
|
||||
|
||||
if(!UpdateObjectInfo(NewObject, UserInfo_.userinfo, Existing.info)) {
|
||||
if(!UpdateObjectInfo(RawObject, UserInfo_.userinfo, Existing.info)) {
|
||||
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
||||
}
|
||||
|
||||
std::string MoveFromEntity,MoveToEntity;
|
||||
if(AssignIfPresent(RawObject,"entity",MoveToEntity)) {
|
||||
if(!MoveToEntity.empty() && !StorageService()->EntityDB().Exists("id",MoveToEntity)) {
|
||||
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)) {
|
||||
ProvObjects::ManagementPolicy P;
|
||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementPolicies, MoveFromEntity,MoveToEntity,Existing.info.id);
|
||||
ProvObjects::ManagementPolicy P;
|
||||
DB_.GetRecord("id",Existing.info.id,P);
|
||||
Poco::JSON::Object Answer;
|
||||
P.to_json(Answer);
|
||||
|
||||
@@ -62,13 +62,10 @@ namespace OpenWifi{
|
||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
||||
}
|
||||
|
||||
if(!Existing.managementPolicy.empty())
|
||||
StorageService()->PolicyDB().DeleteInUse("id",Existing.managementPolicy,DB_.Prefix(),Existing.info.id);
|
||||
|
||||
if(StorageService()->RolesDB().DeleteRecord("id", Existing.info.id)) {
|
||||
return OK();
|
||||
}
|
||||
InternalError(RESTAPI::Errors::CouldNotBeDeleted);
|
||||
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);
|
||||
return OK();
|
||||
}
|
||||
|
||||
void RESTAPI_managementRole_handler::DoPost() {
|
||||
@@ -77,23 +74,28 @@ namespace OpenWifi{
|
||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
||||
}
|
||||
|
||||
auto Obj = ParseStream();
|
||||
auto RawObj = ParseStream();
|
||||
ProvObjects::ManagementRole NewObject;
|
||||
if (!NewObject.from_json(Obj)) {
|
||||
if (!NewObject.from_json(RawObj)) {
|
||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||
}
|
||||
|
||||
if(!CreateObjectInfo(Obj, UserInfo_.userinfo, NewObject.info)) {
|
||||
if(!CreateObjectInfo(RawObj, UserInfo_.userinfo, NewObject.info)) {
|
||||
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
||||
}
|
||||
|
||||
if(NewObject.entity.empty() || !StorageService()->EntityDB().Exists("id",NewObject.entity)) {
|
||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||
}
|
||||
|
||||
if(!NewObject.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewObject.managementPolicy)) {
|
||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||
}
|
||||
|
||||
if(DB_.CreateRecord(NewObject)) {
|
||||
if(!NewObject.managementPolicy.empty())
|
||||
StorageService()->PolicyDB().AddInUse("id", NewObject.managementPolicy, DB_.Prefix(), NewObject.info.id);
|
||||
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementRoles,NewObject.entity,NewObject.info.id);
|
||||
MoveUsage(StorageService()->PolicyDB(), DB_, "", NewObject.managementPolicy, NewObject.info.id);
|
||||
|
||||
Poco::JSON::Object Answer;
|
||||
ProvObjects::ManagementRole Role;
|
||||
DB_.GetRecord("id", NewObject.info.id,Role);
|
||||
@@ -120,20 +122,27 @@ namespace OpenWifi{
|
||||
return BadRequest( RESTAPI::Errors::NameMustBeSet);
|
||||
}
|
||||
|
||||
std::string NewPolicy,OldPolicy = Existing.managementPolicy;
|
||||
AssignIfPresent(RawObject, "managementPolicy", NewPolicy);
|
||||
if(!NewPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewPolicy)) {
|
||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||
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;
|
||||
}
|
||||
|
||||
if(!NewPolicy.empty())
|
||||
Existing.managementPolicy = NewPolicy;
|
||||
std::string MoveToEntity,MoveFromEntity;
|
||||
if(AssignIfPresent(RawObject,"entity",MoveToEntity)) {
|
||||
if(!MoveToEntity.empty() && !StorageService()->EntityDB().Exists("id",MoveToEntity)) {
|
||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||
}
|
||||
MoveFromEntity = Existing.entity;
|
||||
Existing.entity = MoveToEntity;
|
||||
}
|
||||
|
||||
if(DB_.UpdateRecord("id",UUID,Existing)) {
|
||||
if(!OldPolicy.empty())
|
||||
StorageService()->PolicyDB().DeleteInUse("id",OldPolicy,DB_.Prefix(),UUID);
|
||||
if(!NewPolicy.empty())
|
||||
StorageService()->PolicyDB().AddInUse("id",NewPolicy,DB_.Prefix(),UUID);
|
||||
MoveUsage(StorageService()->PolicyDB(),DB_,MoveFromPolicy, MoveToPolicy, Existing.info.id);
|
||||
ManageMembership(StorageService()->EntityDB(),&ProvObjects::Entity::managementRoles, MoveFromEntity, MoveToEntity, Existing.info.id);
|
||||
|
||||
ProvObjects::ManagementRole NewRecord;
|
||||
|
||||
|
||||
@@ -3,23 +3,143 @@
|
||||
//
|
||||
|
||||
#include "RESTAPI_variables_handler.h"
|
||||
#include "RESTAPI_db_helpers.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
void RESTAPI_variables_handler::DoGet() {
|
||||
auto UUID = GetBinding("uuid","");
|
||||
if(UUID.empty()) {
|
||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
||||
}
|
||||
|
||||
VariablesDB::RecordName Existing;
|
||||
if(!DB_.GetRecord("id",UUID,Existing)) {
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
Poco::JSON::Object Answer;
|
||||
if(QB_.AdditionalInfo)
|
||||
AddExtendedInfo(Existing, Answer);
|
||||
Existing.to_json(Answer);
|
||||
ReturnObject(Answer);
|
||||
}
|
||||
|
||||
void RESTAPI_variables_handler::DoDelete() {
|
||||
auto UUID = GetBinding("uuid","");
|
||||
if(UUID.empty()) {
|
||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
||||
}
|
||||
|
||||
VariablesDB::RecordName Existing;
|
||||
if(!DB_.GetRecord("id",UUID,Existing)) {
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
if(!Existing.configurations.empty()) {
|
||||
return BadRequest(RESTAPI::Errors::StillInUse);
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
void RESTAPI_variables_handler::DoPost() {
|
||||
auto UUID = GetBinding("uuid","");
|
||||
if(UUID.empty()) {
|
||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
||||
}
|
||||
|
||||
auto RawObj = ParseStream();
|
||||
VariablesDB::RecordName NewObj;
|
||||
if(!NewObj.from_json(RawObj)) {
|
||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||
}
|
||||
|
||||
if(!NewObj.entity.empty() && !StorageService()->EntityDB().Exists("id",NewObj.entity)) {
|
||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||
}
|
||||
|
||||
if(!NewObj.venue.empty() && !StorageService()->VenueDB().Exists("id",NewObj.venue)) {
|
||||
return BadRequest(RESTAPI::Errors::VenueMustExist);
|
||||
}
|
||||
|
||||
if(!ProvObjects::CreateObjectInfo(RawObj,UserInfo_.userinfo,NewObj.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);
|
||||
|
||||
VariablesDB::RecordName Added;
|
||||
StorageService()->VariablesDB().GetRecord("id",NewObj.info.id,Added);
|
||||
Poco::JSON::Object Answer;
|
||||
Added.to_json(Answer);
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
return BadRequest(RESTAPI::Errors::RecordNotCreated);
|
||||
}
|
||||
|
||||
void RESTAPI_variables_handler::DoPut() {
|
||||
auto UUID = GetBinding("uuid","");
|
||||
if(UUID.empty()) {
|
||||
return BadRequest(RESTAPI::Errors::MissingUUID);
|
||||
}
|
||||
|
||||
VariablesDB::RecordName Existing;
|
||||
if(!StorageService()->VariablesDB().GetRecord("id",UUID,Existing)) {
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
auto RawObj = ParseStream();
|
||||
VariablesDB::RecordName NewObj;
|
||||
if(!NewObj.from_json(RawObj)) {
|
||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||
}
|
||||
|
||||
if(!ProvObjects::UpdateObjectInfo(RawObj,UserInfo_.userinfo,Existing.info)) {
|
||||
return BadRequest((RESTAPI::Errors::MissingOrInvalidParameters));
|
||||
}
|
||||
|
||||
if(RawObj->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)) {
|
||||
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)) {
|
||||
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);
|
||||
|
||||
VariablesDB::RecordName Added;
|
||||
StorageService()->VariablesDB().GetRecord("id",NewObj.info.id,Added);
|
||||
Poco::JSON::Object Answer;
|
||||
Added.to_json(Answer);
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
return BadRequest(RESTAPI::Errors::RecordNotCreated);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -120,8 +120,15 @@ namespace OpenWifi{
|
||||
}
|
||||
|
||||
NewObject.children.clear();
|
||||
|
||||
if(DB_.CreateShortCut(NewObject)) {
|
||||
|
||||
MoveUsage(StorageService()->ContactDB(),DB_,"", NewObject.contact, 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);
|
||||
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::children,"",NewObject.parent,NewObject.info.id);
|
||||
MoveUsage(StorageService()->ConfigurationDB(),DB_,{},NewObject.deviceConfiguration,NewObject.info.id);
|
||||
|
||||
ProvObjects::Venue NewRecord;
|
||||
DB_.GetRecord("id",NewObject.info.id,NewRecord);
|
||||
Poco::JSON::Object Answer;
|
||||
@@ -157,114 +164,72 @@ namespace OpenWifi{
|
||||
Existing.sourceIP = NewObject.sourceIP;
|
||||
}
|
||||
|
||||
std::string MoveEntity;
|
||||
bool MovingEntity=false;
|
||||
if(AssignIfPresent(RawObject, "entity", MoveEntity)) {
|
||||
if(!MoveEntity.empty() && !StorageService()->EntityDB().Exists("id",MoveEntity)) {
|
||||
std::string MoveFromEntity,MoveToEntity;
|
||||
if(AssignIfPresent(RawObject, "entity", MoveToEntity)) {
|
||||
if(!MoveToEntity.empty() && !StorageService()->EntityDB().Exists("id",MoveToEntity)) {
|
||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||
}
|
||||
MovingEntity = MoveEntity != Existing.entity;
|
||||
MoveFromEntity = Existing.entity;
|
||||
Existing.entity = MoveToEntity;
|
||||
}
|
||||
|
||||
std::string MoveVenue;
|
||||
bool MovingVenue=false;
|
||||
if(AssignIfPresent(RawObject, "venue", MoveVenue)) {
|
||||
if(!MoveVenue.empty() && !StorageService()->VenueDB().Exists("id",MoveVenue)) {
|
||||
std::string MoveToVenue,MoveFromVenue;
|
||||
if(AssignIfPresent(RawObject, "venue", MoveToVenue)) {
|
||||
if(!MoveToVenue.empty() && !StorageService()->VenueDB().Exists("id",MoveToVenue)) {
|
||||
return BadRequest(RESTAPI::Errors::VenueMustExist);
|
||||
}
|
||||
MovingVenue = MoveVenue != Existing.parent;
|
||||
MoveFromVenue = Existing.parent;
|
||||
Existing.parent = MoveToVenue;
|
||||
}
|
||||
|
||||
std::string MoveLocation;
|
||||
bool MovingLocation=false;
|
||||
if(AssignIfPresent(RawObject,"location",MoveLocation)) {
|
||||
if(!MoveLocation.empty() && !StorageService()->LocationDB().Exists("id",MoveLocation)) {
|
||||
std::string MoveFromLocation, MoveToLocation;
|
||||
if(AssignIfPresent(RawObject,"location",MoveToLocation)) {
|
||||
if(!MoveToLocation.empty() && !StorageService()->LocationDB().Exists("id",MoveToLocation)) {
|
||||
return BadRequest(RESTAPI::Errors::LocationMustExist);
|
||||
}
|
||||
MovingLocation = MoveLocation!=Existing.location;
|
||||
MoveFromLocation = Existing.location;
|
||||
Existing.location = MoveToLocation;
|
||||
}
|
||||
|
||||
std::string MoveContact;
|
||||
bool MovingContact=false;
|
||||
if(AssignIfPresent(RawObject,"contact",MoveContact)) {
|
||||
if(!MoveContact.empty() && !StorageService()->ContactDB().Exists("id",MoveContact)) {
|
||||
std::string MoveFromContact, MoveToContact;
|
||||
if(AssignIfPresent(RawObject,"contact",MoveToContact)) {
|
||||
if(!MoveToContact.empty() && !StorageService()->ContactDB().Exists("id",MoveToContact)) {
|
||||
return BadRequest(RESTAPI::Errors::ContactMustExist);
|
||||
}
|
||||
MovingContact = MoveContact!=Existing.contact;
|
||||
MoveFromContact = Existing.contact;
|
||||
Existing.contact = MoveToContact;
|
||||
}
|
||||
|
||||
std::string MovePolicy;
|
||||
bool MovingPolicy=false;
|
||||
if(AssignIfPresent(RawObject,"managementPolicy",MovePolicy)) {
|
||||
if(!MovePolicy.empty() && !StorageService()->PolicyDB().Exists("id",MovePolicy)) {
|
||||
std::string MoveFromPolicy, MoveToPolicy;
|
||||
if(AssignIfPresent(RawObject,"managementPolicy",MoveToPolicy)) {
|
||||
if(!MoveToPolicy.empty() && !StorageService()->PolicyDB().Exists("id",MoveToPolicy)) {
|
||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||
}
|
||||
MovingPolicy = MovePolicy != Existing.managementPolicy;
|
||||
MoveFromPolicy = Existing.managementPolicy;
|
||||
Existing.managementPolicy = MoveToPolicy;
|
||||
}
|
||||
|
||||
Types::UUIDvec_t MoveConfiguration;
|
||||
bool MovingConfiguration=false;
|
||||
Types::UUIDvec_t MoveToConfigurations, MoveFromConfigurations;
|
||||
if(RawObject->has("deviceConfiguration")){
|
||||
if(!NewObject.deviceConfiguration.empty()){
|
||||
for(auto &i:NewObject.deviceConfiguration) {
|
||||
if(!StorageService()->ConfigurationDB().Exists("id",i)) {
|
||||
return BadRequest(RESTAPI::Errors::ConfigurationMustExist);
|
||||
}
|
||||
MoveToConfigurations = NewObject.deviceConfiguration;
|
||||
for(auto &i:MoveToConfigurations) {
|
||||
if(!StorageService()->ConfigurationDB().Exists("id",i)) {
|
||||
return BadRequest(RESTAPI::Errors::ConfigurationMustExist);
|
||||
}
|
||||
MoveConfiguration = NewObject.deviceConfiguration;
|
||||
}
|
||||
MovingConfiguration = MoveConfiguration != Existing.deviceConfiguration;
|
||||
}
|
||||
MoveToConfigurations = NewObject.deviceConfiguration;
|
||||
MoveFromConfigurations = Existing.deviceConfiguration;
|
||||
Existing.deviceConfiguration = MoveToConfigurations;
|
||||
}
|
||||
|
||||
if(StorageService()->VenueDB().UpdateRecord("id", UUID, Existing)) {
|
||||
if(MovingContact) {
|
||||
if(!Existing.contact.empty())
|
||||
StorageService()->ContactDB().DeleteInUse("id",Existing.contact,DB_.Prefix(),Existing.info.id);
|
||||
if(!MoveContact.empty())
|
||||
StorageService()->ContactDB().AddInUse("id", MoveContact, DB_.Prefix(), Existing.info.id);
|
||||
Existing.contact = MoveContact;
|
||||
}
|
||||
if(MovingEntity) {
|
||||
if(!Existing.entity.empty())
|
||||
StorageService()->EntityDB().DeleteVenue("id", Existing.entity, Existing.info.id);
|
||||
if(!MoveEntity.empty())
|
||||
StorageService()->EntityDB().AddVenue("id",MoveEntity,Existing.info.id);
|
||||
Existing.entity = MoveEntity;
|
||||
}
|
||||
if(MovingVenue) {
|
||||
if(!Existing.parent.empty())
|
||||
DB_.DeleteChild("id",Existing.parent,Existing.info.id);
|
||||
if(!MoveVenue.empty())
|
||||
DB_.AddChild("id", MoveVenue, Existing.info.id);
|
||||
Existing.parent = MoveVenue;
|
||||
}
|
||||
if(MovingLocation) {
|
||||
if(!Existing.location.empty())
|
||||
StorageService()->LocationDB().DeleteInUse("id", Existing.location, DB_.Prefix(), Existing.info.id);
|
||||
if(!MoveLocation.empty())
|
||||
StorageService()->LocationDB().AddInUse("id", MoveLocation, DB_.Prefix(), Existing.info.id);
|
||||
Existing.location = MoveLocation;
|
||||
}
|
||||
if(MovingPolicy) {
|
||||
if(!Existing.managementPolicy.empty())
|
||||
StorageService()->PolicyDB().DeleteInUse("id", Existing.managementPolicy, DB_.Prefix(), Existing.info.id);
|
||||
if(!MovePolicy.empty())
|
||||
StorageService()->PolicyDB().AddInUse("id", MovePolicy, DB_.Prefix(), Existing.info.id);
|
||||
Existing.managementPolicy = MovePolicy;
|
||||
}
|
||||
if(MovingConfiguration) {
|
||||
if(!Existing.deviceConfiguration.empty()) {
|
||||
for(auto &i:Existing.deviceConfiguration)
|
||||
StorageService()->ConfigurationDB().DeleteInUse("id", i, DB_.Prefix(), Existing.info.id);
|
||||
}
|
||||
if(!MoveConfiguration.empty()) {
|
||||
for(auto &i:MoveConfiguration)
|
||||
StorageService()->ConfigurationDB().AddInUse("id", i, DB_.Prefix(), Existing.info.id);
|
||||
}
|
||||
Existing.deviceConfiguration = MoveConfiguration;
|
||||
}
|
||||
MoveUsage(StorageService()->ContactDB(),DB_,MoveFromContact, MoveToContact, 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);
|
||||
ManageMembership(StorageService()->VenueDB(),&ProvObjects::Venue::children,MoveFromVenue,MoveToVenue,Existing.info.id);
|
||||
MoveUsage(StorageService()->ConfigurationDB(),DB_,MoveFromConfigurations,MoveToConfigurations,Existing.info.id);
|
||||
|
||||
DB_.UpdateRecord("id",Existing.info.id, Existing);
|
||||
ProvObjects::Venue AddedRecord;
|
||||
DB_.GetRecord("id",UUID,AddedRecord);
|
||||
Poco::JSON::Object Answer;
|
||||
|
||||
@@ -93,6 +93,8 @@ namespace OpenWifi::ProvObjects {
|
||||
field_to_json( Obj,"devices",devices);
|
||||
field_to_json( Obj,"rrm",rrm);
|
||||
field_to_json( Obj,"sourceIP",sourceIP);
|
||||
field_to_json( Obj,"variables", variables);
|
||||
field_to_json( Obj,"managementPolicies", managementPolicies);
|
||||
}
|
||||
|
||||
bool Entity::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
@@ -108,6 +110,8 @@ namespace OpenWifi::ProvObjects {
|
||||
field_from_json( Obj,"devices",devices);
|
||||
field_from_json( Obj,"rrm",rrm);
|
||||
field_from_json( Obj,"sourceIP",sourceIP);
|
||||
field_from_json( Obj,"variables", variables);
|
||||
field_from_json( Obj,"managementPolicies", managementPolicies);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
@@ -146,6 +150,7 @@ namespace OpenWifi::ProvObjects {
|
||||
field_to_json( Obj,"location",location);
|
||||
field_to_json( Obj,"rrm",rrm);
|
||||
field_to_json( Obj,"sourceIP",sourceIP);
|
||||
field_to_json( Obj,"variables", variables);
|
||||
}
|
||||
|
||||
bool Venue::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
@@ -164,6 +169,7 @@ namespace OpenWifi::ProvObjects {
|
||||
field_from_json( Obj,"location",location);
|
||||
field_from_json( Obj,"rrm",rrm);
|
||||
field_from_json( Obj,"sourceIP",sourceIP);
|
||||
field_from_json( Obj,"variables", variables);
|
||||
return true;
|
||||
} catch (...) {
|
||||
|
||||
@@ -699,7 +705,7 @@ namespace OpenWifi::ProvObjects {
|
||||
RESTAPI_utils::field_to_json( Obj,"venue", venue);
|
||||
RESTAPI_utils::field_to_json( Obj,"subscriber", subscriber);
|
||||
RESTAPI_utils::field_to_json( Obj,"inventory", inventory);
|
||||
RESTAPI_utils::field_to_json( Obj,"inUse", inUse);
|
||||
RESTAPI_utils::field_to_json( Obj,"configurations", configurations);
|
||||
}
|
||||
|
||||
bool VariableBlock::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
@@ -710,7 +716,7 @@ namespace OpenWifi::ProvObjects {
|
||||
RESTAPI_utils::field_from_json( Obj,"venue", venue);
|
||||
RESTAPI_utils::field_from_json( Obj,"subscriber", subscriber);
|
||||
RESTAPI_utils::field_from_json( Obj,"inventory", inventory);
|
||||
RESTAPI_utils::field_from_json( Obj,"inUse", inUse);
|
||||
RESTAPI_utils::field_from_json( Obj,"configurations", configurations);
|
||||
return true;
|
||||
} catch(...) {
|
||||
}
|
||||
@@ -754,7 +760,7 @@ namespace OpenWifi::ProvObjects {
|
||||
}
|
||||
|
||||
bool CreateObjectInfo(const Poco::JSON::Object::Ptr &O, const SecurityObjects::UserInfo &U, ObjectInfo &I) {
|
||||
uint64_t Now = std::time(nullptr);
|
||||
uint64_t Now = OpenWifi::Now();
|
||||
if(O->has("name"))
|
||||
I.name = O->get("name").toString();
|
||||
|
||||
|
||||
@@ -66,6 +66,9 @@ namespace OpenWifi::ProvObjects {
|
||||
Types::UUIDvec_t devices;
|
||||
std::string rrm;
|
||||
Types::StringVec sourceIP;
|
||||
Types::UUIDvec_t variables;
|
||||
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);
|
||||
@@ -96,6 +99,7 @@ namespace OpenWifi::ProvObjects {
|
||||
std::string location;
|
||||
std::string rrm;
|
||||
Types::StringVec sourceIP;
|
||||
Types::UUIDvec_t variables;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
@@ -260,7 +264,7 @@ namespace OpenWifi::ProvObjects {
|
||||
Types::StringVec deviceTypes;
|
||||
DeviceConfigurationElementVec configuration;
|
||||
Types::StringVec inUse;
|
||||
Types::StringPairVec variables;
|
||||
Types::UUIDvec_t variables;
|
||||
std::string rrm;
|
||||
std::string firmwareUpgrade;
|
||||
bool firmwareRCOnly=false;
|
||||
@@ -446,7 +450,7 @@ namespace OpenWifi::ProvObjects {
|
||||
std::string venue;
|
||||
std::string subscriber;
|
||||
std::string inventory;
|
||||
std::vector<std::string> inUse;
|
||||
Types::UUIDvec_t configurations;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
|
||||
@@ -810,32 +810,32 @@ namespace ORM {
|
||||
return ManipulateVectorMember(&RecordType::users, FieldName, ParentUUID, ChildUUID, false);
|
||||
}
|
||||
|
||||
inline bool AddInUse(field_name_t FieldName, std::string & ParentUUID, const std::string & Prefix, const std::string & ChildUUID) {
|
||||
inline bool AddConfiguration(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
|
||||
return ManipulateVectorMember(&RecordType::deviceConfiguration, FieldName, ParentUUID, ChildUUID, true);
|
||||
}
|
||||
|
||||
inline bool DelConfiguration(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
|
||||
return ManipulateVectorMember(&RecordType::deviceConfiguration, FieldName, ParentUUID, ChildUUID, false);
|
||||
}
|
||||
|
||||
inline bool AddVariable(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
|
||||
return ManipulateVectorMember(&RecordType::variables, FieldName, ParentUUID, ChildUUID, true);
|
||||
}
|
||||
|
||||
inline bool DelVariable(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
|
||||
return ManipulateVectorMember(&RecordType::variables, FieldName, ParentUUID, ChildUUID, false);
|
||||
}
|
||||
|
||||
inline bool AddInUse(field_name_t FieldName, const std::string & ParentUUID, const std::string & Prefix, const std::string & ChildUUID) {
|
||||
std::string FakeUUID{ Prefix + ":" + ChildUUID};
|
||||
return ManipulateVectorMember(&RecordType::inUse,FieldName, ParentUUID, FakeUUID, true);
|
||||
}
|
||||
|
||||
inline bool DeleteInUse(field_name_t FieldName, std::string & ParentUUID, const std::string & Prefix, const std::string & ChildUUID) {
|
||||
inline bool DeleteInUse(field_name_t FieldName, const std::string & ParentUUID, const std::string & Prefix, const std::string & ChildUUID) {
|
||||
std::string FakeUUID{ Prefix + ":" + ChildUUID};
|
||||
return ManipulateVectorMember(&RecordType::inUse,FieldName, ParentUUID, FakeUUID, false);
|
||||
}
|
||||
|
||||
inline bool DeleteContact(field_name_t FieldName, std::string & ParentUUID, const std::string & ChildUUID) {
|
||||
return ManipulateVectorMember(&RecordType::contacts,FieldName, ParentUUID, ChildUUID, false);
|
||||
}
|
||||
|
||||
inline bool AddContact(field_name_t FieldName, std::string & ParentUUID, const std::string & ChildUUID) {
|
||||
return ManipulateVectorMember(&RecordType::contacts,FieldName, ParentUUID, ChildUUID, true);
|
||||
}
|
||||
|
||||
inline bool DeleteLocation(field_name_t FieldName, std::string & ParentUUID, const std::string & ChildUUID) {
|
||||
return ManipulateVectorMember(&RecordType::locations,FieldName, ParentUUID, ChildUUID, false);
|
||||
}
|
||||
|
||||
inline bool AddLocation(field_name_t FieldName, std::string & ParentUUID, const std::string & ChildUUID) {
|
||||
return ManipulateVectorMember(&RecordType::locations,FieldName, ParentUUID, ChildUUID, true);
|
||||
}
|
||||
|
||||
inline bool GetInUse(field_name_t FieldName, const std::string & UUID, std::vector<std::string> & UUIDs ) {
|
||||
RecordType R;
|
||||
if(GetRecord(FieldName,UUID,R)) {
|
||||
|
||||
@@ -71,6 +71,7 @@ namespace OpenWifi::RESTAPI::Errors {
|
||||
static const std::string SerialNumberNotTheProperClass{"Device is not available to subscribers. It ahs been assigned to another class of devices."};
|
||||
static const std::string UserAlreadyExists{"Username already exists."};
|
||||
static const std::string NotImplemented{"Function not implemented."};
|
||||
static const std::string VariableMustExist{"Specified variable does not exist."};
|
||||
}
|
||||
|
||||
namespace OpenWifi::RESTAPI::Protocol {
|
||||
|
||||
@@ -142,7 +142,7 @@ template<> void ORM::DB< OpenWifi::ConfigurationDBRecordType, OpenWifi::ProvO
|
||||
Out.deviceTypes = OpenWifi::RESTAPI_utils::to_object_array(In.get<7>());
|
||||
Out.configuration = OpenWifi::RESTAPI_utils::to_object_array<OpenWifi::ProvObjects::DeviceConfigurationElement>(In.get<8>());
|
||||
Out.inUse = OpenWifi::RESTAPI_utils::to_object_array(In.get<9>());
|
||||
Out.variables = OpenWifi::RESTAPI_utils::to_stringpair_array(In.get<10>());
|
||||
Out.variables = OpenWifi::RESTAPI_utils::to_object_array(In.get<10>());
|
||||
Out.rrm = In.get<11>();
|
||||
Out.info.tags = OpenWifi::RESTAPI_utils::to_taglist(In.get<12>());
|
||||
Out.firmwareUpgrade = In.get<13>();
|
||||
|
||||
@@ -34,7 +34,10 @@ namespace OpenWifi {
|
||||
ORM::Field{"devices",ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"rrm",ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"tags",ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"sourceIP",ORM::FieldType::FT_TEXT}
|
||||
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}
|
||||
};
|
||||
|
||||
static ORM::IndexVec EntityDB_Indexes{
|
||||
@@ -50,6 +53,25 @@ namespace OpenWifi {
|
||||
CheckForRoot();
|
||||
}
|
||||
|
||||
bool EntityDB::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 managementPolicies text",
|
||||
"alter table " + TableName_ + " add column managementRoles text"
|
||||
};
|
||||
|
||||
for(const auto &i:Script) {
|
||||
try {
|
||||
auto Session = Pool_.get();
|
||||
Session << i , Poco::Data::Keywords::now;
|
||||
} catch (...) {
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EntityDB::GetByIP(const std::string &IP, std::string & uuid) {
|
||||
try {
|
||||
std::string UUID;
|
||||
@@ -220,6 +242,9 @@ template<> void ORM::DB< OpenWifi::EntityDBRecordType, OpenWifi::ProvObjects:
|
||||
Out.rrm = In.get<14>();
|
||||
Out.info.tags = OpenWifi::RESTAPI_utils::to_taglist(In.get<15>());
|
||||
Out.sourceIP = OpenWifi::RESTAPI_utils::to_object_array(In.get<16>());
|
||||
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>());
|
||||
}
|
||||
|
||||
template<> void ORM::DB< OpenWifi::EntityDBRecordType, OpenWifi::ProvObjects::Entity>::Convert(const OpenWifi::ProvObjects::Entity &In, OpenWifi::EntityDBRecordType &Out) {
|
||||
@@ -240,4 +265,7 @@ template<> void ORM::DB< OpenWifi::EntityDBRecordType, OpenWifi::ProvObjects:
|
||||
Out.set<14>(In.rrm);
|
||||
Out.set<15>(OpenWifi::RESTAPI_utils::to_string(In.info.tags));
|
||||
Out.set<16>(OpenWifi::RESTAPI_utils::to_string(In.sourceIP));
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -30,6 +30,9 @@ namespace OpenWifi {
|
||||
std::string,
|
||||
std::string,
|
||||
std::string,
|
||||
std::string,
|
||||
std::string,
|
||||
std::string,
|
||||
std::string
|
||||
> EntityDBRecordType;
|
||||
|
||||
@@ -47,6 +50,7 @@ namespace OpenWifi {
|
||||
void ImportVenues(const Poco::JSON::Object::Ptr &Ptr, const std::string & Node = RootUUID_ );
|
||||
bool CreateShortCut( ProvObjects::Entity & E);
|
||||
bool GetByIP(const std::string &IP, std::string & uuid);
|
||||
bool Upgrade(uint32_t from, uint32_t &to) override;
|
||||
private:
|
||||
bool RootExists_=false;
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ 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{"inUse",ORM::FieldType::FT_TEXT}
|
||||
ORM::Field{"configurations",ORM::FieldType::FT_TEXT}
|
||||
};
|
||||
|
||||
const static ORM::IndexVec VariablesDB_Indexes{
|
||||
@@ -55,7 +55,7 @@ template<> void ORM::DB<OpenWifi::VariablesDBRecordType, OpenWifi::ProvObjects::
|
||||
Out.venue = In.get<8>();
|
||||
Out.subscriber = In.get<9>();
|
||||
Out.inventory = In.get<10>();
|
||||
Out.inUse = OpenWifi::RESTAPI_utils::to_object_array(In.get<11>());
|
||||
Out.configurations = OpenWifi::RESTAPI_utils::to_object_array(In.get<11>());
|
||||
}
|
||||
|
||||
template<> void ORM::DB<OpenWifi::VariablesDBRecordType, OpenWifi::ProvObjects::VariableBlock>::Convert(const OpenWifi::ProvObjects::VariableBlock &In, OpenWifi::VariablesDBRecordType &Out) {
|
||||
@@ -70,5 +70,5 @@ template<> void ORM::DB<OpenWifi::VariablesDBRecordType, OpenWifi::ProvObjects::
|
||||
Out.set<8>(In.venue);
|
||||
Out.set<9>(In.subscriber);
|
||||
Out.set<10>(In.inventory);
|
||||
Out.set<11>(OpenWifi::RESTAPI_utils::to_string(In.inUse));
|
||||
Out.set<11>(OpenWifi::RESTAPI_utils::to_string(In.configurations));
|
||||
}
|
||||
|
||||
@@ -36,7 +36,8 @@ namespace OpenWifi {
|
||||
ORM::Field{"rrm",ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"tags",ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"deviceConfiguration",ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"sourceIP",ORM::FieldType::FT_TEXT}
|
||||
ORM::Field{"sourceIP",ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"variables",ORM::FieldType::FT_TEXT}
|
||||
};
|
||||
|
||||
static ORM::IndexVec VenueDB_Indexes{
|
||||
@@ -49,6 +50,23 @@ namespace OpenWifi {
|
||||
VenueDB::VenueDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) :
|
||||
DB(T, "venues", VenueDB_Fields, VenueDB_Indexes, P, L, "ven") {}
|
||||
|
||||
bool VenueDB::Upgrade(uint32_t from, uint32_t &to) {
|
||||
to = Version();
|
||||
std::vector<std::string> Script{
|
||||
"alter table " + TableName_ + " add column variables text"
|
||||
};
|
||||
|
||||
for(const auto &i:Script) {
|
||||
try {
|
||||
auto Session = Pool_.get();
|
||||
Session << i , Poco::Data::Keywords::now;
|
||||
} catch (...) {
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VenueDB::CreateShortCut(ProvObjects::Venue &V) {
|
||||
if(StorageService()->VenueDB().CreateRecord(V)) {
|
||||
if(!V.parent.empty())
|
||||
@@ -115,7 +133,7 @@ template<> void ORM::DB< OpenWifi::VenueDBRecordType, OpenWifi::ProvObjects::
|
||||
Out.info.tags = OpenWifi::RESTAPI_utils::to_taglist(In.get<16>());
|
||||
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>());
|
||||
}
|
||||
|
||||
template<> void ORM::DB< OpenWifi::VenueDBRecordType, OpenWifi::ProvObjects::Venue>::Convert(const OpenWifi::ProvObjects::Venue &In, OpenWifi::VenueDBRecordType &Out) {
|
||||
@@ -138,4 +156,5 @@ template<> void ORM::DB< OpenWifi::VenueDBRecordType, OpenWifi::ProvObjects::
|
||||
Out.set<16>(OpenWifi::RESTAPI_utils::to_string(In.info.tags));
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace OpenWifi {
|
||||
std::string,
|
||||
std::string,
|
||||
std::string,
|
||||
std::string,
|
||||
std::string
|
||||
> VenueDBRecordType;
|
||||
|
||||
@@ -39,6 +40,7 @@ namespace OpenWifi {
|
||||
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