diff options
Diffstat (limited to 'src/components/policy/src/policy/src/sql_pt_ext_representation.cc')
-rw-r--r-- | src/components/policy/src/policy/src/sql_pt_ext_representation.cc | 101 |
1 files changed, 93 insertions, 8 deletions
diff --git a/src/components/policy/src/policy/src/sql_pt_ext_representation.cc b/src/components/policy/src/policy/src/sql_pt_ext_representation.cc index b6d4d84c0..59764c585 100644 --- a/src/components/policy/src/policy/src/sql_pt_ext_representation.cc +++ b/src/components/policy/src/policy/src/sql_pt_ext_representation.cc @@ -493,7 +493,7 @@ std::vector<UserFriendlyMessage> SQLPTExtRepresentation::GetUserFriendlyMsg( query.Bind(0, *it); query.Bind(1, msg_language); - if (!query.Exec()) { + if (!query.Exec() || !query.Reset()) { LOG4CXX_WARN(logger_, "Incorrect select from friendly messages."); return result; } @@ -562,7 +562,7 @@ bool SQLPTExtRepresentation::GatherConsumerFriendlyMessages( bool SQLPTExtRepresentation::SetMetaInfo(const std::string& ccpu_version, const std::string& wers_country_code, const std::string& language) { - LOG4CXX_TRACE_ENTER(logger_); + LOG4CXX_AUTO_TRACE(logger_); dbms::SQLQuery query(db()); if (!query.Prepare(sql_pt_ext::kUpdateMetaParams)) { LOG4CXX_WARN(logger_, "Incorrect statement for insert to module meta."); @@ -577,7 +577,6 @@ bool SQLPTExtRepresentation::SetMetaInfo(const std::string& ccpu_version, LOG4CXX_WARN(logger_, "Incorrect insert to module meta."); return false; } - LOG4CXX_TRACE_EXIT(logger_); return true; } @@ -691,6 +690,9 @@ bool SQLPTExtRepresentation::SaveSpecificAppPolicy( return true; } + SetIsDefault(app.first, false); + SetIsPredata(app.first, false); + dbms::SQLQuery app_query(db()); if (!app_query.Prepare(sql_pt_ext::kInsertApplication)) { LOG4CXX_WARN(logger_, "Incorrect insert statement into application."); @@ -929,7 +931,29 @@ void SQLPTExtRepresentation::GatherConsentGroup( } bool SQLPTExtRepresentation::SaveDeviceData( - const policy_table::DeviceData& devices) { +const policy_table::DeviceData& devices) { + LOG4CXX_INFO(logger_, "SaveDeviceData"); + dbms::SQLQuery drop_device_query(db()); + const std::string drop_device = "DELETE FROM `device`"; + if (!drop_device_query.Exec(drop_device)) { + LOG4CXX_WARN(logger_, "Could not clear device table."); + return false; + } + + dbms::SQLQuery drop_device_consents_query(db()); + const std::string drop_device_consents = "DELETE FROM `device_consent_group`"; + if (!drop_device_consents_query.Exec(drop_device_consents)) { + LOG4CXX_WARN(logger_, "Could not clear device consents."); + return false; + } + + dbms::SQLQuery drop_user_consents_query(db()); + const std::string drop_user_consents = "DELETE FROM `consent_group`"; + if (!drop_user_consents_query.Exec(drop_user_consents)) { + LOG4CXX_WARN(logger_, "Could not clear user consents."); + return false; + } + dbms::SQLQuery query(db()); if (!query.Prepare(sql_pt_ext::kInsertDeviceData)) { LOG4CXX_WARN(logger_, "Incorrect insert statement for device data."); @@ -989,6 +1013,11 @@ bool SQLPTExtRepresentation::SaveConsentGroup( query.Bind( 3, std::string(policy_table::EnumToJsonString(*(it->second.input)))); + query.Bind(4, std::string(*(it->second.time_stamp))); + LOG4CXX_INFO(logger_, "Device:" << + "time stamp " << std::string(*(it->second.time_stamp)) + << " group " << it_groups->first + << " consent " << it_groups->second); } else { if (!query.Prepare(sql_pt_ext::kInsertConsentGroups)) { LOG4CXX_WARN(logger_, @@ -1002,6 +1031,11 @@ bool SQLPTExtRepresentation::SaveConsentGroup( query.Bind( 4, std::string(policy_table::EnumToJsonString(*(it->second.input)))); + query.Bind(5, std::string(*(it->second.time_stamp))); + LOG4CXX_INFO(logger_, "Device:" << + "time stamp " << std::string(*(it->second.time_stamp)) + << " group " << it_groups->first + << " consent " << it_groups->second); } if (!query.Exec() || !query.Reset()) { @@ -1346,6 +1380,37 @@ bool SQLPTExtRepresentation::SaveMessageString( bool SQLPTExtRepresentation::SaveUsageAndErrorCounts( const policy_table::UsageAndErrorCounts& counts) { + return SaveAppCounters(*counts.app_level) && SaveGlobalCounters(counts); +} + +bool SQLPTExtRepresentation::SaveModuleMeta( + const policy_table::ModuleMeta& meta) { + dbms::SQLQuery query(db()); + + if (!query.Prepare(sql_pt_ext::kSaveModuleMeta)) { + LOG4CXX_WARN(logger_, "Incorrect insert statement for module_meta."); + return false; + } + const int64_t odometer = *(meta.pt_exchanged_at_odometer_x); + + query.Bind(0, *(meta.ccpu_version)); + query.Bind(1, *(meta.language)); + query.Bind(2, *(meta.wers_country_code)); + query.Bind(3, odometer); + query.Bind(4, *(meta.pt_exchanged_x_days_after_epoch)); + query.Bind(5, *(meta.ignition_cycles_since_last_exchange)); + query.Bind(6, *(meta.vin)); + + if (!query.Exec()) { + LOG4CXX_WARN(logger_, "Incorrect update for module_meta."); + return false; + } + + return true; +} + +bool SQLPTExtRepresentation::SaveAppCounters( + const rpc::policy_table_interface_base::AppLevels& app_levels) { dbms::SQLQuery query(db()); if (!query.Exec(sql_pt::kDeleteAppLevel)) { LOG4CXX_WARN(logger_, "Incorrect delete from app level."); @@ -1357,7 +1422,6 @@ bool SQLPTExtRepresentation::SaveUsageAndErrorCounts( } policy_table::AppLevels::const_iterator it; - const policy_table::AppLevels& app_levels = *counts.app_level; for (it = app_levels.begin(); it != app_levels.end(); ++it) { query.Bind(0, it->first); query.Bind(1, it->second.minutes_in_hmi_full); @@ -1374,7 +1438,7 @@ bool SQLPTExtRepresentation::SaveUsageAndErrorCounts( query.Bind(12, it->second.count_of_run_attempts_while_revoked); query.Bind(13, it->second.app_registration_language_gui); query.Bind(14, it->second.app_registration_language_vui); - if (!query.Exec()) { + if (!query.Exec() || !query.Reset()) { LOG4CXX_WARN(logger_, "Incorrect insert into app level."); return false; } @@ -1382,6 +1446,26 @@ bool SQLPTExtRepresentation::SaveUsageAndErrorCounts( return true; } +bool SQLPTExtRepresentation::SaveGlobalCounters( + const rpc::policy_table_interface_base::UsageAndErrorCounts& counts) { + dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt_ext::kUpdateGlobalCounters)) { + LOG4CXX_WARN(logger_, "Incorrect insert statement for global counters."); + return false; + } + + query.Bind(0, *counts.count_of_iap_buffer_full); + query.Bind(1, *counts.count_sync_out_of_memory); + query.Bind(2, *counts.count_of_sync_reboots); + + if (!query.Exec()) { + LOG4CXX_WARN(logger_, "Incorrect insert into global counters."); + return false; + } + + return true; +} + bool SQLPTExtRepresentation::CleanupUnpairedDevices( const DeviceIds& device_ids) const { LOG4CXX_INFO(logger_, "CleanupUnpairedDevices"); @@ -1541,7 +1625,8 @@ bool SQLPTExtRepresentation::SetIsPredata(const std::string& app_id, return true; } -bool SQLPTExtRepresentation::SetUnpairedDevice(const std::string& device_id) const { +bool SQLPTExtRepresentation::SetUnpairedDevice(const std::string& device_id, + bool unpaired) const { LOG4CXX_TRACE(logger_, "Set unpaired device: " << device_id); dbms::SQLQuery query(db()); if (!query.Prepare(sql_pt_ext::kUpdateUnpairedDevice)) { @@ -1549,7 +1634,7 @@ bool SQLPTExtRepresentation::SetUnpairedDevice(const std::string& device_id) con return false; } - query.Bind(0, true); + query.Bind(0, unpaired); query.Bind(1, device_id); if (!query.Exec()) { LOG4CXX_WARN(logger_, "Failed update unpaired device"); |