Skip to content

Commit

Permalink
https://telecominfraproject.atlassian.net/browse/WIFI-13110
Browse files Browse the repository at this point in the history
Signed-off-by: stephb9959 <[email protected]>
  • Loading branch information
stephb9959 committed Nov 15, 2023
1 parent 1757440 commit 0c5e0d6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
53
55
8 changes: 6 additions & 2 deletions openapi/owgw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1712,8 +1712,12 @@ paths:
type: integer
format: int64
required: false


- in: query
description: Filter the results
name: simulatedDevices
schema:
type: boolean
required: false
responses:
200:
$ref: '#/components/responses/Success'
Expand Down
7 changes: 7 additions & 0 deletions src/RESTAPI/RESTAPI_devices_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ namespace OpenWifi {
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
}

if(GetBoolParameter("simulatedDevices",false)) {
if(StorageService()->DeleteSimulatedDevice("")) {
return OK();
}
return NotFound();
}

if(!QB_.Select.empty() && !Utils::ValidSerialNumbers(QB_.Select)) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
Expand Down
2 changes: 2 additions & 0 deletions src/StorageService.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ namespace OpenWifi {
bool UpdateBlackListDevice(std::string &SerialNumber, GWObjects::BlackListedDevice &Device);
uint64_t GetBlackListDeviceCount();

bool DeleteSimulatedDevice(const std::string &SerialNumber);

bool RemoveHealthChecksRecordsOlderThan(uint64_t Date);
bool RemoveDeviceLogsRecordsOlderThan(uint64_t Date);
bool RemoveStatisticsRecordsOlderThan(uint64_t Date);
Expand Down
30 changes: 30 additions & 0 deletions src/storage/storage_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,36 @@ namespace OpenWifi {
return FoundCountry;
}

bool Storage::DeleteSimulatedDevice([[maybe_unused]] const std::string &SerialNumber) {

std::vector<std::string> Statements =
{
"delete from commandlist using devices where commandlist.serialnumber=devices.serialnumber and devices.simulated=true;",
"delete from healthchecks using devices where healthchecks.serialnumber=devices.serialnumber and devices.simulated=true;",
"delete from statistics using devices where statistics.serialnumber=devices.serialnumber and devices.simulated=true;",
"delete from devicelogs using devices where devicelogs.serialnumber=devices.serialnumber and devices.simulated=true;",
"delete from capabilities using devices where capabilities.serialnumber=devices.serialnumber and devices.simulated=true;",
"delete from devices where devices.simulated=true;"
};
try {
Poco::Data::Session Sess = Pool_->get();
Poco::Data::Statement Command(Sess);

for (const auto &i : Statements) {
try {
Command << i, Poco::Data::Keywords::now;
} catch (const Poco::Exception &E) {
Logger().log(E);
}
Command.reset(Sess);
}
return true;
} catch (const Poco::Exception &E) {
Logger().log(E);
}
return true;
}

#define __DBGLOG__ std::cout << __LINE__ << std::endl;

bool Storage::CreateDefaultDevice(std::string &SerialNumber, const Config::Capabilities &Caps,
Expand Down

0 comments on commit 0c5e0d6

Please sign in to comment.