mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-30 02:02:36 +00:00
Adding support for contacts and locations.
This commit is contained in:
BIN
Configuration application.docx
Normal file
BIN
Configuration application.docx
Normal file
Binary file not shown.
@@ -358,7 +358,7 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
example: each uuid is preceded by ent, or ven to say that the elemenet is entity or venue
|
example: each uuid is preceded by ent, or ven to say that the elemenet is entity or venue
|
||||||
owner:
|
entity:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
managementPolicy:
|
managementPolicy:
|
||||||
@@ -421,7 +421,7 @@ components:
|
|||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
owner:
|
entity:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
managementPolicy:
|
managementPolicy:
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
RESTAPI_utils::field_to_json( Obj,"mobiles",mobiles);
|
RESTAPI_utils::field_to_json( Obj,"mobiles",mobiles);
|
||||||
RESTAPI_utils::field_to_json( Obj,"geoCode",geoCode);
|
RESTAPI_utils::field_to_json( Obj,"geoCode",geoCode);
|
||||||
RESTAPI_utils::field_to_json( Obj,"inUse",inUse);
|
RESTAPI_utils::field_to_json( Obj,"inUse",inUse);
|
||||||
RESTAPI_utils::field_to_json( Obj,"owner",owner);
|
RESTAPI_utils::field_to_json( Obj,"entity",entity);
|
||||||
RESTAPI_utils::field_to_json( Obj,"managementPolicy",managementPolicy);
|
RESTAPI_utils::field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +229,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
RESTAPI_utils::field_from_json( Obj,"mobiles",mobiles);
|
RESTAPI_utils::field_from_json( Obj,"mobiles",mobiles);
|
||||||
RESTAPI_utils::field_from_json( Obj,"geoCode",geoCode);
|
RESTAPI_utils::field_from_json( Obj,"geoCode",geoCode);
|
||||||
RESTAPI_utils::field_from_json( Obj,"inUse",inUse);
|
RESTAPI_utils::field_from_json( Obj,"inUse",inUse);
|
||||||
RESTAPI_utils::field_from_json( Obj,"owner",owner);
|
RESTAPI_utils::field_from_json( Obj,"entity",entity);
|
||||||
RESTAPI_utils::field_from_json( Obj,"managementPolicy",managementPolicy);
|
RESTAPI_utils::field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||||
return true;
|
return true;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
@@ -253,7 +253,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
RESTAPI_utils::field_to_json( Obj,"secondaryEmail",secondaryEmail);
|
RESTAPI_utils::field_to_json( Obj,"secondaryEmail",secondaryEmail);
|
||||||
RESTAPI_utils::field_to_json( Obj,"accessPIN",accessPIN);
|
RESTAPI_utils::field_to_json( Obj,"accessPIN",accessPIN);
|
||||||
RESTAPI_utils::field_to_json( Obj,"inUse",inUse);
|
RESTAPI_utils::field_to_json( Obj,"inUse",inUse);
|
||||||
RESTAPI_utils::field_to_json( Obj,"owner",owner);
|
RESTAPI_utils::field_to_json( Obj,"entity",entity);
|
||||||
RESTAPI_utils::field_to_json( Obj,"managementPolicy",managementPolicy);
|
RESTAPI_utils::field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +275,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
RESTAPI_utils::field_from_json( Obj,"secondaryEmail",secondaryEmail);
|
RESTAPI_utils::field_from_json( Obj,"secondaryEmail",secondaryEmail);
|
||||||
RESTAPI_utils::field_from_json( Obj,"accessPIN",accessPIN);
|
RESTAPI_utils::field_from_json( Obj,"accessPIN",accessPIN);
|
||||||
RESTAPI_utils::field_from_json( Obj,"inUse",inUse);
|
RESTAPI_utils::field_from_json( Obj,"inUse",inUse);
|
||||||
RESTAPI_utils::field_from_json( Obj,"owner",owner);
|
RESTAPI_utils::field_from_json( Obj,"entity",entity);
|
||||||
RESTAPI_utils::field_from_json( Obj,"managementPolicy",managementPolicy);
|
RESTAPI_utils::field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||||
return true;
|
return true;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
Types::StringVec mobiles;
|
Types::StringVec mobiles;
|
||||||
std::string geoCode;
|
std::string geoCode;
|
||||||
Types::StringVec inUse;
|
Types::StringVec inUse;
|
||||||
Types::UUID_t owner;
|
Types::UUID_t entity;
|
||||||
Types::UUID_t managementPolicy;
|
Types::UUID_t managementPolicy;
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
void to_json(Poco::JSON::Object &Obj) const;
|
||||||
@@ -226,7 +226,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
std::string secondaryEmail;
|
std::string secondaryEmail;
|
||||||
std::string accessPIN;
|
std::string accessPIN;
|
||||||
Types::StringVec inUse;
|
Types::StringVec inUse;
|
||||||
Types::UUID_t owner;
|
Types::UUID_t entity;
|
||||||
Types::UUID_t managementPolicy;
|
Types::UUID_t managementPolicy;
|
||||||
|
|
||||||
void to_json(Poco::JSON::Object &Obj) const;
|
void to_json(Poco::JSON::Object &Obj) const;
|
||||||
|
|||||||
@@ -91,6 +91,16 @@ namespace OpenWifi{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(NewObject.entity.empty() || !Storage()->EntityDB().Exists("id",NewObject.entity)) {
|
||||||
|
BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!NewObject.managementPolicy.empty() && !Storage()->PolicyDB().Exists("id",NewObject.managementPolicy)) {
|
||||||
|
BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
NewObject.info.id = Daemon()->CreateUUID();
|
NewObject.info.id = Daemon()->CreateUUID();
|
||||||
NewObject.info.created = NewObject.info.modified = std::time(nullptr);
|
NewObject.info.created = NewObject.info.modified = std::time(nullptr);
|
||||||
NewObject.inUse.clear();
|
NewObject.inUse.clear();
|
||||||
@@ -112,9 +122,9 @@ namespace OpenWifi{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Obj = ParseStream();
|
auto RawObject = ParseStream();
|
||||||
ProvObjects::Contact NewObject;
|
ProvObjects::Contact NewObject;
|
||||||
if (!NewObject.from_json(Obj)) {
|
if (!NewObject.from_json(RawObject)) {
|
||||||
BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -124,11 +134,40 @@ namespace OpenWifi{
|
|||||||
Existing.info.notes.insert(Existing.info.notes.begin(),i);
|
Existing.info.notes.insert(Existing.info.notes.begin(),i);
|
||||||
}
|
}
|
||||||
|
|
||||||
AssignIfPresent(Obj,"name",Existing.info.name);
|
std::string MoveEntity, MovePolicy;
|
||||||
AssignIfPresent(Obj,"description",Existing.info.description);
|
bool MovingEntity=false, MovingPolicy=false;
|
||||||
|
if(AssignIfPresent(RawObject,"managementPolicy",MovePolicy)) {
|
||||||
|
if(!MovePolicy.empty() && !Storage()->PolicyDB().Exists("id",MovePolicy)) {
|
||||||
|
BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MovingPolicy = MovePolicy != Existing.managementPolicy;
|
||||||
|
}
|
||||||
|
if(AssignIfPresent(RawObject,"entity",MoveEntity)) {
|
||||||
|
if(MoveEntity.empty() || !Storage()->PolicyDB().Exists("id",MoveEntity)) {
|
||||||
|
BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MovingEntity = MoveEntity != Existing.entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignIfPresent(RawObject,"name",Existing.info.name);
|
||||||
|
AssignIfPresent(RawObject,"description",Existing.info.description);
|
||||||
Existing.info.modified = std::time(nullptr);
|
Existing.info.modified = std::time(nullptr);
|
||||||
|
|
||||||
if(DB_.UpdateRecord("id", UUID, Existing)) {
|
if(DB_.UpdateRecord("id", UUID, Existing)) {
|
||||||
|
if(MovingPolicy) {
|
||||||
|
if(!Existing.managementPolicy.empty())
|
||||||
|
Storage()->PolicyDB().DeleteInUse("id",Existing.managementPolicy,DB_.Prefix(),Existing.info.id);
|
||||||
|
if(!MovePolicy.empty())
|
||||||
|
Storage()->PolicyDB().AddInUse("id", MovePolicy, DB_.Prefix(), Existing.info.id);
|
||||||
|
Existing.managementPolicy = MovePolicy;
|
||||||
|
}
|
||||||
|
if(MovingEntity) {
|
||||||
|
Existing.entity = MoveEntity;
|
||||||
|
}
|
||||||
|
DB_.UpdateRecord("id",UUID,Existing);
|
||||||
|
|
||||||
ProvObjects::Contact NewObjectAdded;
|
ProvObjects::Contact NewObjectAdded;
|
||||||
DB_.GetRecord("id", UUID, NewObjectAdded);
|
DB_.GetRecord("id", UUID, NewObjectAdded);
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ namespace OpenWifi::RESTAPI::Errors {
|
|||||||
static const std::string LocationMustExist{"Location must exist."};
|
static const std::string LocationMustExist{"Location must exist."};
|
||||||
static const std::string OnlyWSSupported{"This endpoint only supports WebSocket."};
|
static const std::string OnlyWSSupported{"This endpoint only supports WebSocket."};
|
||||||
static const std::string DeviceConfigurationUUID{"Unknown DeviceConfiguration UUID."};
|
static const std::string DeviceConfigurationUUID{"Unknown DeviceConfiguration UUID."};
|
||||||
|
static const std::string OwnerMissing{"Missing owning entity UUID."};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,6 +91,16 @@ namespace OpenWifi{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(NewObject.entity.empty() || !Storage()->EntityDB().Exists("id",NewObject.entity)) {
|
||||||
|
BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!NewObject.managementPolicy.empty() && !Storage()->PolicyDB().Exists("id",NewObject.managementPolicy)) {
|
||||||
|
BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
NewObject.info.id = Daemon()->CreateUUID();
|
NewObject.info.id = Daemon()->CreateUUID();
|
||||||
NewObject.info.created = NewObject.info.modified = std::time(nullptr);
|
NewObject.info.created = NewObject.info.modified = std::time(nullptr);
|
||||||
NewObject.inUse.clear();
|
NewObject.inUse.clear();
|
||||||
@@ -112,23 +122,52 @@ namespace OpenWifi{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Obj = ParseStream();
|
auto RawObject = ParseStream();
|
||||||
ProvObjects::Location NewObject;
|
ProvObjects::Location NewObject;
|
||||||
if (!NewObject.from_json(Obj)) {
|
if (!NewObject.from_json(RawObject)) {
|
||||||
BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string MoveEntity, MovePolicy;
|
||||||
|
bool MovingEntity=false, MovingPolicy=false;
|
||||||
|
if(AssignIfPresent(RawObject,"managementPolicy",MovePolicy)) {
|
||||||
|
if(!MovePolicy.empty() && !Storage()->PolicyDB().Exists("id",MovePolicy)) {
|
||||||
|
BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MovingPolicy = MovePolicy != Existing.managementPolicy;
|
||||||
|
}
|
||||||
|
if(AssignIfPresent(RawObject,"entity",MoveEntity)) {
|
||||||
|
if(MoveEntity.empty() || !Storage()->PolicyDB().Exists("id",MoveEntity)) {
|
||||||
|
BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MovingEntity = MoveEntity != Existing.entity;
|
||||||
|
}
|
||||||
|
|
||||||
for(auto &i:NewObject.info.notes) {
|
for(auto &i:NewObject.info.notes) {
|
||||||
i.createdBy = UserInfo_.userinfo.email;
|
i.createdBy = UserInfo_.userinfo.email;
|
||||||
Existing.info.notes.insert(Existing.info.notes.begin(),i);
|
Existing.info.notes.insert(Existing.info.notes.begin(),i);
|
||||||
}
|
}
|
||||||
|
|
||||||
AssignIfPresent(Obj,"name",Existing.info.name);
|
AssignIfPresent(RawObject,"name",Existing.info.name);
|
||||||
AssignIfPresent(Obj,"description",Existing.info.description);
|
AssignIfPresent(RawObject,"description",Existing.info.description);
|
||||||
Existing.info.modified = std::time(nullptr);
|
Existing.info.modified = std::time(nullptr);
|
||||||
|
|
||||||
if(DB_.UpdateRecord("id", UUID, Existing)) {
|
if(DB_.UpdateRecord("id", UUID, Existing)) {
|
||||||
|
if(MovingPolicy) {
|
||||||
|
if(!Existing.managementPolicy.empty())
|
||||||
|
Storage()->PolicyDB().DeleteInUse("id",Existing.managementPolicy,DB_.Prefix(),Existing.info.id);
|
||||||
|
if(!MovePolicy.empty())
|
||||||
|
Storage()->PolicyDB().AddInUse("id", MovePolicy, DB_.Prefix(), Existing.info.id);
|
||||||
|
Existing.managementPolicy = MovePolicy;
|
||||||
|
}
|
||||||
|
if(MovingEntity) {
|
||||||
|
Existing.entity = MoveEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
DB_.UpdateRecord("id",UUID,Existing);
|
||||||
ProvObjects::Location NewObjectAdded;
|
ProvObjects::Location NewObjectAdded;
|
||||||
DB_.GetRecord("id", UUID, NewObjectAdded);
|
DB_.GetRecord("id", UUID, NewObjectAdded);
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace OpenWifi {
|
|||||||
ORM::Field{"inUse",ORM::FieldType::FT_TEXT},
|
ORM::Field{"inUse",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"tags",ORM::FieldType::FT_TEXT},
|
ORM::Field{"tags",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"managementPolicy",ORM::FieldType::FT_TEXT},
|
ORM::Field{"managementPolicy",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"owner",ORM::FieldType::FT_TEXT}
|
ORM::Field{"entity",ORM::FieldType::FT_TEXT}
|
||||||
};
|
};
|
||||||
|
|
||||||
static ORM::IndexVec ContactDB_Indexes{
|
static ORM::IndexVec ContactDB_Indexes{
|
||||||
@@ -75,7 +75,7 @@ template<> void ORM::DB<OpenWifi::ContactDBRecordType, OpenWifi::ProvObjects::Co
|
|||||||
OpenWifi::Types::from_string(In.get<18>(), Out.inUse);
|
OpenWifi::Types::from_string(In.get<18>(), Out.inUse);
|
||||||
Out.info.tags = OpenWifi::RESTAPI_utils::to_taglist(In.get<19>());
|
Out.info.tags = OpenWifi::RESTAPI_utils::to_taglist(In.get<19>());
|
||||||
Out.managementPolicy = In.get<20>();
|
Out.managementPolicy = In.get<20>();
|
||||||
Out.owner = In.get<21>();
|
Out.entity = In.get<21>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> void ORM::DB<OpenWifi::ContactDBRecordType, OpenWifi::ProvObjects::Contact>::Convert(OpenWifi::ProvObjects::Contact &In, OpenWifi::ContactDBRecordType &Out) {
|
template<> void ORM::DB<OpenWifi::ContactDBRecordType, OpenWifi::ProvObjects::Contact>::Convert(OpenWifi::ProvObjects::Contact &In, OpenWifi::ContactDBRecordType &Out) {
|
||||||
@@ -100,5 +100,5 @@ template<> void ORM::DB<OpenWifi::ContactDBRecordType, OpenWifi::ProvObjects::Co
|
|||||||
Out.set<18>(OpenWifi::Types::to_string(In.inUse));
|
Out.set<18>(OpenWifi::Types::to_string(In.inUse));
|
||||||
Out.set<19>(OpenWifi::RESTAPI_utils::to_string(In.info.tags));
|
Out.set<19>(OpenWifi::RESTAPI_utils::to_string(In.info.tags));
|
||||||
Out.set<20>(In.managementPolicy);
|
Out.set<20>(In.managementPolicy);
|
||||||
Out.set<21>(In.owner);
|
Out.set<21>(In.entity);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace OpenWifi {
|
|||||||
ORM::Field{"inUse",ORM::FieldType::FT_TEXT},
|
ORM::Field{"inUse",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"tags",ORM::FieldType::FT_TEXT},
|
ORM::Field{"tags",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"managementPolicy",ORM::FieldType::FT_TEXT},
|
ORM::Field{"managementPolicy",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"owner",ORM::FieldType::FT_TEXT}
|
ORM::Field{"entity",ORM::FieldType::FT_TEXT}
|
||||||
};
|
};
|
||||||
|
|
||||||
static ORM::IndexVec LocationDB_Indexes{
|
static ORM::IndexVec LocationDB_Indexes{
|
||||||
@@ -71,7 +71,7 @@ template<> void ORM::DB<OpenWifi::LocationDBRecordType , OpenWifi::ProvObjects::
|
|||||||
OpenWifi::Types::from_string(In.get<16>(), Out.inUse);
|
OpenWifi::Types::from_string(In.get<16>(), Out.inUse);
|
||||||
Out.info.tags = OpenWifi::RESTAPI_utils::to_taglist(In.get<17>());
|
Out.info.tags = OpenWifi::RESTAPI_utils::to_taglist(In.get<17>());
|
||||||
Out.managementPolicy = In.get<18>();
|
Out.managementPolicy = In.get<18>();
|
||||||
Out.owner = In.get<19>();
|
Out.entity = In.get<19>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> void ORM::DB<OpenWifi::LocationDBRecordType, OpenWifi::ProvObjects::Location>::Convert(OpenWifi::ProvObjects::Location &In, OpenWifi::LocationDBRecordType &Out) {
|
template<> void ORM::DB<OpenWifi::LocationDBRecordType, OpenWifi::ProvObjects::Location>::Convert(OpenWifi::ProvObjects::Location &In, OpenWifi::LocationDBRecordType &Out) {
|
||||||
@@ -94,5 +94,5 @@ template<> void ORM::DB<OpenWifi::LocationDBRecordType, OpenWifi::ProvObjects::L
|
|||||||
Out.set<16>(OpenWifi::Types::to_string(In.inUse));
|
Out.set<16>(OpenWifi::Types::to_string(In.inUse));
|
||||||
Out.set<17>(OpenWifi::RESTAPI_utils::to_string(In.info.tags));
|
Out.set<17>(OpenWifi::RESTAPI_utils::to_string(In.info.tags));
|
||||||
Out.set<18>(In.managementPolicy);
|
Out.set<18>(In.managementPolicy);
|
||||||
Out.set<19>(In.owner);
|
Out.set<19>(In.entity);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user