diff --git a/openapi/owgw.yaml b/openapi/owgw.yaml index 74f6859c..c7a3a2d0 100644 --- a/openapi/owgw.yaml +++ b/openapi/owgw.yaml @@ -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 diff --git a/src/RESTAPI/RESTAPI_devices_handler.cpp b/src/RESTAPI/RESTAPI_devices_handler.cpp index bb880fbc..401986eb 100644 --- a/src/RESTAPI/RESTAPI_devices_handler.cpp +++ b/src/RESTAPI/RESTAPI_devices_handler.cpp @@ -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); @@ -131,7 +132,7 @@ namespace OpenWifi { } } else if (serialOnly) { std::vector 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); @@ -149,7 +150,7 @@ namespace OpenWifi { RetObj.set("serialNumbers", Objects); } else { std::vector 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; diff --git a/src/StorageService.h b/src/StorageService.h index 726790f2..be71645a 100644 --- a/src/StorageService.h +++ b/src/StorageService.h @@ -148,7 +148,8 @@ namespace OpenWifi { bool GetDevice(const std::string &SerialNumber, GWObjects::Device &); bool GetDevices(uint64_t From, uint64_t HowMany, std::vector &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 &Devices, const std::string & orderBy=""); bool DeleteDevice(std::string &SerialNumber); @@ -164,7 +165,8 @@ namespace OpenWifi { bool GetDeviceSerialNumbers(uint64_t From, uint64_t HowMany, std::vector &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(); diff --git a/src/storage/storage_device.cpp b/src/storage/storage_device.cpp index b2f746f7..ebc2c2d6 100644 --- a/src/storage/storage_device.cpp +++ b/src/storage/storage_device.cpp @@ -195,17 +195,32 @@ namespace OpenWifi { bool Storage::GetDeviceSerialNumbers(uint64_t From, uint64_t HowMany, std::vector &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 @@ -835,25 +850,38 @@ namespace OpenWifi { } bool Storage::GetDevices(uint64_t From, uint64_t HowMany, - std::vector &Devices, const std::string &orderBy, const std::string &platform) { + std::vector &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();