mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-11-06 05:28:06 +00:00
Finishing framework refactor.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include "RESTAPI_location_handler.h"
|
||||
#include "framework/RESTAPI_errors.h"
|
||||
|
||||
#include "RESTAPI_ProvObjects.h"
|
||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||
#include "StorageService.h"
|
||||
#include "framework/RESTAPI_protocol.h"
|
||||
#include "Daemon.h"
|
||||
@@ -31,7 +31,7 @@ namespace OpenWifi{
|
||||
Storage::ExpandedListMap M;
|
||||
std::vector<std::string> Errors;
|
||||
Poco::JSON::Object Inner;
|
||||
if(Storage()->ExpandInUse(Existing.inUse,M,Errors)) {
|
||||
if(StorageService()->ExpandInUse(Existing.inUse,M,Errors)) {
|
||||
for(const auto &[type,list]:M) {
|
||||
Poco::JSON::Array ObjList;
|
||||
for(const auto &i:list.entries) {
|
||||
@@ -69,7 +69,7 @@ namespace OpenWifi{
|
||||
|
||||
if(DB_.DeleteRecord("id",UUID)) {
|
||||
if(!Existing.entity.empty())
|
||||
Storage()->EntityDB().DeleteLocation("id",Existing.entity,UUID);
|
||||
StorageService()->EntityDB().DeleteLocation("id",Existing.entity,UUID);
|
||||
|
||||
return OK();
|
||||
}
|
||||
@@ -88,23 +88,23 @@ namespace OpenWifi{
|
||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||
}
|
||||
|
||||
if(NewObject.entity.empty() || !Storage()->EntityDB().Exists("id",NewObject.entity)) {
|
||||
if(NewObject.entity.empty() || !StorageService()->EntityDB().Exists("id",NewObject.entity)) {
|
||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||
}
|
||||
|
||||
if(!NewObject.managementPolicy.empty() && !Storage()->PolicyDB().Exists("id",NewObject.managementPolicy)) {
|
||||
if(!NewObject.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewObject.managementPolicy)) {
|
||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||
}
|
||||
|
||||
NewObject.info.id = Daemon()->CreateUUID();
|
||||
NewObject.info.id = MicroService::instance().CreateUUID();
|
||||
NewObject.info.created = NewObject.info.modified = std::time(nullptr);
|
||||
NewObject.inUse.clear();
|
||||
|
||||
if(DB_.CreateRecord(NewObject)) {
|
||||
if(!NewObject.managementPolicy.empty())
|
||||
Storage()->PolicyDB().AddInUse("id",NewObject.managementPolicy,DB_.Prefix(),NewObject.info.id);
|
||||
StorageService()->PolicyDB().AddInUse("id",NewObject.managementPolicy,DB_.Prefix(),NewObject.info.id);
|
||||
|
||||
Storage()->EntityDB().AddLocation("id",NewObject.entity,NewObject.info.id);
|
||||
StorageService()->EntityDB().AddLocation("id",NewObject.entity,NewObject.info.id);
|
||||
|
||||
Poco::JSON::Object Answer;
|
||||
NewObject.to_json(Answer);
|
||||
@@ -129,7 +129,7 @@ namespace OpenWifi{
|
||||
std::string MoveFromPolicy,MoveToPolicy;
|
||||
bool MovingPolicy=false;
|
||||
if(AssignIfPresent(RawObject,"managementPolicy",MoveToPolicy)) {
|
||||
if(!MoveToPolicy.empty() && !Storage()->PolicyDB().Exists("id",MoveToPolicy)) {
|
||||
if(!MoveToPolicy.empty() && !StorageService()->PolicyDB().Exists("id",MoveToPolicy)) {
|
||||
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||
}
|
||||
MoveFromPolicy = Existing.managementPolicy;
|
||||
@@ -140,7 +140,7 @@ namespace OpenWifi{
|
||||
std::string MoveFromEntity,MoveToEntity;
|
||||
bool MovingEntity=false;
|
||||
if(AssignIfPresent(RawObject,"entity",MoveToEntity)) {
|
||||
if(!MoveToEntity.empty() && !Storage()->EntityDB().Exists("id",MoveToEntity)) {
|
||||
if(!MoveToEntity.empty() && !StorageService()->EntityDB().Exists("id",MoveToEntity)) {
|
||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||
}
|
||||
MoveFromEntity = Existing.entity;
|
||||
@@ -174,15 +174,15 @@ namespace OpenWifi{
|
||||
if(DB_.UpdateRecord("id", UUID, Existing)) {
|
||||
if(MovingPolicy) {
|
||||
if(!MoveFromPolicy.empty())
|
||||
Storage()->PolicyDB().DeleteInUse("id",MoveFromPolicy,DB_.Prefix(),Existing.info.id);
|
||||
StorageService()->PolicyDB().DeleteInUse("id",MoveFromPolicy,DB_.Prefix(),Existing.info.id);
|
||||
if(!MoveToPolicy.empty())
|
||||
Storage()->PolicyDB().AddInUse("id", MoveToPolicy, DB_.Prefix(), Existing.info.id);
|
||||
StorageService()->PolicyDB().AddInUse("id", MoveToPolicy, DB_.Prefix(), Existing.info.id);
|
||||
}
|
||||
if(MovingEntity) {
|
||||
if(!MoveFromEntity.empty())
|
||||
Storage()->EntityDB().DeleteLocation("id",MoveFromEntity,Existing.info.id);
|
||||
StorageService()->EntityDB().DeleteLocation("id",MoveFromEntity,Existing.info.id);
|
||||
if(!MoveToEntity.empty())
|
||||
Storage()->EntityDB().AddLocation("id", MoveToEntity, Existing.info.id);
|
||||
StorageService()->EntityDB().AddLocation("id", MoveToEntity, Existing.info.id);
|
||||
}
|
||||
|
||||
ProvObjects::Location NewObjectAdded;
|
||||
|
||||
Reference in New Issue
Block a user