diff options
author | Shobhit Adlakha <ShobhitAd@users.noreply.github.com> | 2022-03-15 17:21:06 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-15 17:21:06 -0400 |
commit | 25e47c7f34f90f5393958f998c1861efa966d702 (patch) | |
tree | 29f400e59e2357b942dc2154792e73708aedd752 | |
parent | 08b875d51fcb835ff1d157115f2f94d8927d8ddb (diff) | |
download | sdl_core-25e47c7f34f90f5393958f998c1861efa966d702.tar.gz |
Fix/Clear endpoint_properties in policy DB if empty properties recieved in PTU (#3880)8.1-RC1
* Clear endpoint_properties from policy DB if empty endpoint_properties are recieved in a PTU
* Add check to only overwrite endpoint_properties if parameter is defined and empty
* Add is_initialized check for external proprietary
6 files changed, 32 insertions, 0 deletions
diff --git a/src/components/policy/policy_external/include/policy/sql_pt_queries.h b/src/components/policy/policy_external/include/policy/sql_pt_queries.h index aba08dcca1..18c4468703 100644 --- a/src/components/policy/policy_external/include/policy/sql_pt_queries.h +++ b/src/components/policy/policy_external/include/policy/sql_pt_queries.h @@ -99,6 +99,7 @@ extern const std::string kInsertDeviceData; extern const std::string kInsertAppLevel; extern const std::string kDeleteSecondsBetweenRetries; extern const std::string kDeleteEndpoint; +extern const std::string kDeleteEndpointProperties; extern const std::string kDeleteAppLevel; extern const std::string kDeleteMessageString; extern const std::string kDeleteFunctionalGroup; diff --git a/src/components/policy/policy_external/src/sql_pt_queries.cc b/src/components/policy/policy_external/src/sql_pt_queries.cc index 91dd6fb713..8414c2feda 100644 --- a/src/components/policy/policy_external/src/sql_pt_queries.cc +++ b/src/components/policy/policy_external/src/sql_pt_queries.cc @@ -918,6 +918,9 @@ const std::string kDeleteSecondsBetweenRetries = const std::string kDeleteEndpoint = "DELETE FROM `endpoint`"; +const std::string kDeleteEndpointProperties = + "DELETE FROM `endpoint_properties`"; + const std::string kDeleteAppLevel = "DELETE FROM `app_level`"; const std::string kDeleteMessageString = "DELETE FROM `message`"; diff --git a/src/components/policy/policy_external/src/sql_pt_representation.cc b/src/components/policy/policy_external/src/sql_pt_representation.cc index 5bee09773d..0436e82bbb 100644 --- a/src/components/policy/policy_external/src/sql_pt_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_representation.cc @@ -1575,6 +1575,18 @@ bool SQLPTRepresentation::SaveServiceEndpoints( bool SQLPTRepresentation::SaveServiceEndpointProperties( const policy_table::ServiceEndpointProperties& endpoint_properties) { utils::dbms::SQLQuery query(db()); + + if (endpoint_properties.is_initialized() && endpoint_properties.empty()) { + bool delete_query_exec_result = + query.Exec(sql_pt::kDeleteEndpointProperties); + + if (!delete_query_exec_result) { + SDL_LOG_WARN("Failed to delete endpoint properties from DB."); + return false; + } + return true; + } + if (!query.Prepare(sql_pt::kInsertEndpointVersion)) { SDL_LOG_WARN( "Incorrect insert of endpoint property to endpoint_properties."); diff --git a/src/components/policy/policy_regular/include/policy/sql_pt_queries.h b/src/components/policy/policy_regular/include/policy/sql_pt_queries.h index fd7f879abf..492db56204 100644 --- a/src/components/policy/policy_regular/include/policy/sql_pt_queries.h +++ b/src/components/policy/policy_regular/include/policy/sql_pt_queries.h @@ -99,6 +99,7 @@ extern const std::string kInsertDeviceData; extern const std::string kInsertAppLevel; extern const std::string kDeleteSecondsBetweenRetries; extern const std::string kDeleteEndpoint; +extern const std::string kDeleteEndpointProperties; extern const std::string kDeleteAppLevel; extern const std::string kDeleteMessageString; extern const std::string kDeleteFunctionalGroup; diff --git a/src/components/policy/policy_regular/src/sql_pt_queries.cc b/src/components/policy/policy_regular/src/sql_pt_queries.cc index 6e0bfd8c89..c86e934823 100644 --- a/src/components/policy/policy_regular/src/sql_pt_queries.cc +++ b/src/components/policy/policy_regular/src/sql_pt_queries.cc @@ -868,6 +868,9 @@ const std::string kDeleteSecondsBetweenRetries = const std::string kDeleteEndpoint = "DELETE FROM `endpoint`"; +const std::string kDeleteEndpointProperties = + "DELETE FROM `endpoint_properties`"; + const std::string kDeleteAppLevel = "DELETE FROM `app_level`"; const std::string kDeleteMessageString = "DELETE FROM `message`"; diff --git a/src/components/policy/policy_regular/src/sql_pt_representation.cc b/src/components/policy/policy_regular/src/sql_pt_representation.cc index f2254d7752..9dcde34588 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -1539,6 +1539,18 @@ bool SQLPTRepresentation::SaveServiceEndpoints( bool SQLPTRepresentation::SaveServiceEndpointProperties( const policy_table::ServiceEndpointProperties& endpoint_properties) { utils::dbms::SQLQuery query(db()); + + if (endpoint_properties.is_initialized() && endpoint_properties.empty()) { + bool delete_query_exec_result = + query.Exec(sql_pt::kDeleteEndpointProperties); + + if (!delete_query_exec_result) { + SDL_LOG_WARN("Failed to delete endpoint properties from DB."); + return false; + } + return true; + } + if (!query.Prepare(sql_pt::kInsertEndpointVersion)) { SDL_LOG_WARN( "Incorrect insert of endpoint property to endpoint_properties."); |