mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-11-01 19:17:47 +00:00
Fixing inventory select bug.
This commit is contained in:
@@ -1558,12 +1558,6 @@ paths:
|
||||
type: string
|
||||
format: uuid
|
||||
required: true
|
||||
- in: query
|
||||
name: claimer
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
required: false
|
||||
requestBody:
|
||||
description: Information used to create the new entity
|
||||
content:
|
||||
@@ -1595,6 +1589,17 @@ paths:
|
||||
schema:
|
||||
type: boolean
|
||||
required: false
|
||||
- in: query
|
||||
name: claimer
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
required: false
|
||||
- in: query
|
||||
name: claimId
|
||||
schema:
|
||||
type: string
|
||||
required: false
|
||||
requestBody:
|
||||
description: Information used to modify the new entity
|
||||
content:
|
||||
|
||||
@@ -154,6 +154,28 @@ namespace OpenWifi {
|
||||
return R.ReturnObject(Answer);
|
||||
}
|
||||
|
||||
// ReturnRecordList<decltype(StorageService()->InventoryDB()),
|
||||
// ProvObjects::InventoryTag>("taglist",StorageService()->InventoryDB(),*this );
|
||||
|
||||
template <typename DB> void ReturnRecordList(const char *ArrayName,DB & DBInstance, RESTAPIHandler & R) {
|
||||
Poco::JSON::Array ObjArr;
|
||||
for(const auto &i:R.SelectedRecords()) {
|
||||
ProvObjects::InventoryTag E;
|
||||
if(DBInstance.GetRecord("serialNumber",i,E)) {
|
||||
Poco::JSON::Object Obj;
|
||||
E.to_json(Obj);
|
||||
if(R.NeedAdditionalInfo())
|
||||
AddExtendedInfo(E,Obj);
|
||||
ObjArr.add(Obj);
|
||||
} else {
|
||||
return R.BadRequest(RESTAPI::Errors::UnknownId + i);
|
||||
}
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set(ArrayName, ObjArr);
|
||||
return R.ReturnObject(Answer);
|
||||
}
|
||||
|
||||
template <typename DB, typename Record> void ReturnRecordList(const char *ArrayName,DB & DBInstance, RESTAPIHandler & R) {
|
||||
Poco::JSON::Array ObjArr;
|
||||
for(const auto &i:R.SelectedRecords()) {
|
||||
|
||||
@@ -216,11 +216,8 @@ namespace OpenWifi{
|
||||
InternalError(RESTAPI::Errors::RecordNotCreated);
|
||||
}
|
||||
|
||||
void RESTAPI_inventory_handler::DoPut() {
|
||||
ProvObjects::InventoryTag Existing;
|
||||
void RESTAPI_inventory_handler::PerformClaim(const std::string &SerialNumber, const std::string &Claimer, const std::string & ClaimId) {
|
||||
|
||||
std::string Claimer;
|
||||
if(HasParameter("claimer",Claimer) && !Claimer.empty()) {
|
||||
if(UserInfo_.userinfo.userRole==SecurityObjects::SUBSCRIBER && Claimer!=UserInfo_.userinfo.id) {
|
||||
return UnAuthorized(RESTAPI::Errors::InsufficientAccessRights, ACCESS_DENIED);
|
||||
}
|
||||
@@ -230,16 +227,29 @@ namespace OpenWifi{
|
||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||
}
|
||||
}
|
||||
|
||||
// if the device exists, check the status to see if we would follow this claim.
|
||||
|
||||
|
||||
}
|
||||
|
||||
void RESTAPI_inventory_handler::DoPut() {
|
||||
|
||||
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER,"");
|
||||
if(SerialNumber.empty() || !DB_.GetRecord(RESTAPI::Protocol::SERIALNUMBER,SerialNumber,Existing)) {
|
||||
if(Claimer.empty())
|
||||
return NotFound();
|
||||
|
||||
// try claiming this device.
|
||||
std::string Claimer;
|
||||
if(HasParameter("claimer",Claimer)) {
|
||||
std::string ClaimId;
|
||||
if(!HasParameter("claimId",ClaimId) || SerialNumber.empty() || Claimer.empty()) {
|
||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||
}
|
||||
return PerformClaim(SerialNumber, Claimer, ClaimId);
|
||||
}
|
||||
|
||||
ProvObjects::InventoryTag Existing;
|
||||
if(SerialNumber.empty() || !DB_.GetRecord(RESTAPI::Protocol::SERIALNUMBER,SerialNumber,Existing)) {
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
auto RawObject = ParseStream();
|
||||
ProvObjects::InventoryTag NewObject;
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace OpenWifi {
|
||||
void DoPost() final;
|
||||
void DoPut() final;
|
||||
void DoDelete() final;
|
||||
void PerformClaim(const std::string &SerialNumber, const std::string & Claimer , const std::string & ClaimId);
|
||||
InventoryDB &DB_;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -50,8 +50,7 @@ namespace OpenWifi{
|
||||
}
|
||||
|
||||
if(!QB_.Select.empty()) {
|
||||
return ReturnRecordList<decltype(StorageService()->InventoryDB()),
|
||||
ProvObjects::InventoryTag>("taglist",StorageService()->InventoryDB(),*this );
|
||||
return ReturnRecordList<decltype(StorageService()->InventoryDB())>("taglist",StorageService()->InventoryDB(),*this );
|
||||
} else if(HasParameter("entity",UUID)) {
|
||||
if(QB_.CountOnly) {
|
||||
auto C = StorageService()->InventoryDB().Count( StorageService()->InventoryDB().OP("entity",ORM::EQ,UUID));
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace OpenWifi::RESTAPI::Errors {
|
||||
static const std::string CouldNotBeDeleted{"Element could not be deleted."};
|
||||
static const std::string NameMustBeSet{"The name property must be set."};
|
||||
static const std::string ConfigBlockInvalid{"Configuration block type invalid."};
|
||||
static const std::string UnknownId{"Unknown management policy."};
|
||||
static const std::string UnknownId{"Unknown UUID."};
|
||||
static const std::string InvalidDeviceTypes{"Unknown or invalid device type(s)."};
|
||||
static const std::string RecordNotCreated{"Record could not be created."};
|
||||
static const std::string RecordNotUpdated{"Record could not be updated."};
|
||||
|
||||
Reference in New Issue
Block a user