Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIFI-13539 Feat: devices api update to include preprovisioned #347

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions openapi/owgw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,11 @@ paths:
- AP
- SWITCH
required: false
- in: query
description: only devices which are not provisioned
name: includeProvisioned
schema:
type: boolean
responses:
200:
description: List devices
Expand Down
5 changes: 3 additions & 2 deletions src/RESTAPI/RESTAPI_devices_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ namespace OpenWifi {
auto serialOnly = GetBoolParameter(RESTAPI::Protocol::SERIALONLY, false);
auto deviceWithStatus = GetBoolParameter(RESTAPI::Protocol::DEVICEWITHSTATUS, false);
auto completeInfo = GetBoolParameter("completeInfo", false);
auto includeProvisioned = GetBoolParameter("includeProvisioned", true);

if(!platform.empty() && (platform!="ap" && platform!="switch" && platform!="all")) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
Expand Down Expand Up @@ -131,7 +132,7 @@ namespace OpenWifi {
}
} else if (serialOnly) {
std::vector<std::string> SerialNumbers;
StorageService()->GetDeviceSerialNumbers(QB_.Offset, QB_.Limit, SerialNumbers, OrderBy, platform);
StorageService()->GetDeviceSerialNumbers(QB_.Offset, QB_.Limit, SerialNumbers, OrderBy, platform, includeProvisioned);
Poco::JSON::Array Objects;
for (const auto &i : SerialNumbers) {
Objects.add(i);
Expand All @@ -149,7 +150,7 @@ namespace OpenWifi {
RetObj.set("serialNumbers", Objects);
} else {
std::vector<GWObjects::Device> Devices;
StorageService()->GetDevices(QB_.Offset, QB_.Limit, Devices, OrderBy, platform);
StorageService()->GetDevices(QB_.Offset, QB_.Limit, Devices, OrderBy, platform, includeProvisioned);
Poco::JSON::Array Objects;
for (const auto &i : Devices) {
Poco::JSON::Object Obj;
Expand Down
6 changes: 4 additions & 2 deletions src/StorageService.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ namespace OpenWifi {
bool GetDevice(const std::string &SerialNumber, GWObjects::Device &);
bool GetDevices(uint64_t From, uint64_t HowMany, std::vector<GWObjects::Device> &Devices,
const std::string &orderBy = "",
const std::string &platform = "");
const std::string &platform = "",
bool includeProvisioned = true);
// bool GetDevices(uint64_t From, uint64_t HowMany, const std::string & Select,
// std::vector<GWObjects::Device> &Devices, const std::string & orderBy="");
bool DeleteDevice(std::string &SerialNumber);
Expand All @@ -164,7 +165,8 @@ namespace OpenWifi {
bool GetDeviceSerialNumbers(uint64_t From, uint64_t HowMany,
std::vector<std::string> &SerialNumbers,
const std::string &orderBy = "",
const std::string &platform = "");
const std::string &platform = "",
bool includeProvisioned = true);
bool GetDeviceFWUpdatePolicy(std::string &SerialNumber, std::string &Policy);
bool SetDevicePassword(LockedDbSession &Session, std::string &SerialNumber, std::string &Password);
bool UpdateSerialNumberCache();
Expand Down
52 changes: 40 additions & 12 deletions src/storage/storage_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,32 @@ namespace OpenWifi {
bool Storage::GetDeviceSerialNumbers(uint64_t From, uint64_t HowMany,
std::vector<std::string> &SerialNumbers,
const std::string &orderBy,
const std::string &platform) {
const std::string &platform, bool includeProvisioned) {
try {
Poco::Data::Session Sess = Pool_->get();
Poco::Data::Statement Select(Sess);

std::string st;
std::string whereClause = "";
if(!platform.empty()) {
st = "SELECT SerialNumber From Devices WHERE DeviceType='" + platform + "' ";
if (includeProvisioned == false) {

whereClause = fmt::format("WHERE entity='' and venue='' and DeviceType='" + platform + "'");
} else {
whereClause = fmt::format("WHERE DeviceType='" + platform + "'");
}


//st = "SELECT SerialNumber From Devices WHERE DeviceType='" + platform + "' ";
} else {
st = "SELECT SerialNumber From Devices ";
if (includeProvisioned == false) {
whereClause = fmt::format("WHERE entity='' and venue=''");
}
//st = "SELECT SerialNumber From Devices ";
}

st = fmt::format("SELECT SerialNumber From Devices {}", whereClause);

if (orderBy.empty())
st += " ORDER BY SerialNumber ASC ";
else
Expand Down Expand Up @@ -835,25 +850,38 @@ namespace OpenWifi {
}

bool Storage::GetDevices(uint64_t From, uint64_t HowMany,
std::vector<GWObjects::Device> &Devices, const std::string &orderBy, const std::string &platform) {
std::vector<GWObjects::Device> &Devices, const std::string &orderBy, const std::string &platform,
bool includeProvisioned) {
DeviceRecordList Records;
try {
Poco::Data::Session Sess = Pool_->get();
Poco::Data::Statement Select(Sess);

std::string st;
std::string whereClause = "";
if(platform.empty()) {
st =
fmt::format("SELECT {} FROM Devices {} {}", DB_DeviceSelectFields,
orderBy.empty() ? " ORDER BY SerialNumber ASC " : orderBy,
ComputeRange(From, HowMany));

if (includeProvisioned == false) {
whereClause = fmt::format("WHERE entity='' and venue=''");
}

} else {
st =
fmt::format("SELECT {} FROM Devices WHERE DeviceType='{}' {} {}", DB_DeviceSelectFields, platform,
orderBy.empty() ? " ORDER BY SerialNumber ASC " : orderBy,
ComputeRange(From, HowMany));

if (includeProvisioned == false) {
whereClause = fmt::format("WHERE DeviceType='{}' and entity='' and venue=''",platform);
} else {
whereClause = fmt::format("WHERE DeviceType='{}'", platform);
}

}

st =
fmt::format("SELECT {} FROM Devices {} {} {}", DB_DeviceSelectFields, whereClause,
orderBy.empty() ? " ORDER BY SerialNumber ASC " : orderBy,
ComputeRange(From, HowMany));

//Logger().information(fmt::format(" GetDevices st is {} ", st));

Select << ConvertParams(st), Poco::Data::Keywords::into(Records);
Select.execute();

Expand Down
Loading