diff options
author | Aleksandr Galiuzov (GutHub) <AGaliuzov@luxoft.com> | 2016-07-08 13:04:14 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-08 13:04:14 +0300 |
commit | eb9091afef3b9bce637248ecc35ffabd0a846567 (patch) | |
tree | 58ab5bf5279ceb050ff7c3178279a31e06ae6634 | |
parent | d738f0de8d66c43d549f57e865f13f235fb711d8 (diff) | |
parent | 038d42b6cbfb1e2342a585ddd375e78de1e2f0b2 (diff) | |
download | sdl_core-eb9091afef3b9bce637248ecc35ffabd0a846567.tar.gz |
Merge pull request #675 from dev-gh/fix/Fix_policy_data_saving
Fixes saving of certain policy data
-rw-r--r-- | src/components/policy/include/policy/sql_pt_queries.h | 1 | ||||
-rw-r--r-- | src/components/policy/src/cache_manager.cc | 10 | ||||
-rw-r--r-- | src/components/policy/src/policy_manager_impl.cc | 7 | ||||
-rw-r--r-- | src/components/policy/src/sql_pt_queries.cc | 22 | ||||
-rw-r--r-- | src/components/policy/src/sql_pt_representation.cc | 53 | ||||
-rw-r--r-- | src/components/policy/test/sql_pt_representation_test.cc | 43 |
6 files changed, 100 insertions, 36 deletions
diff --git a/src/components/policy/include/policy/sql_pt_queries.h b/src/components/policy/include/policy/sql_pt_queries.h index 01c1d81082..cf3028b0a0 100644 --- a/src/components/policy/include/policy/sql_pt_queries.h +++ b/src/components/policy/include/policy/sql_pt_queries.h @@ -60,6 +60,7 @@ extern const std::string kSelectFunctionalGroups; extern const std::string kSelectAllRpcs; extern const std::string kSelectUserMsgsVersion; extern const std::string kSelectAppPolicies; +extern const std::string kCollectFriendlyMsg; extern const std::string kSelectAppGroups; extern const std::string kSelectNicknames; extern const std::string kSelectAppTypes; diff --git a/src/components/policy/src/cache_manager.cc b/src/components/policy/src/cache_manager.cc index e1474a2abd..ff5df6538f 100644 --- a/src/components/policy/src/cache_manager.cc +++ b/src/components/policy/src/cache_manager.cc @@ -311,6 +311,16 @@ bool CacheManager::AddDevice(const std::string& device_id, sync_primitives::AutoLock auto_lock(cache_lock_); CACHE_MANAGER_CHECK(false); + policy_table::DeviceParams& params = + (*(pt_->policy_table.device_data))[device_id]; + + // Open SDL stored just device id in policy + UNUSED(params); + + // We have to set preloaded flag as false in policy table on adding new + // information (SDLAQ-CRS-2365). It can happens only after device addition. + *pt_->policy_table.module_config.preloaded_pt = false; + Backup(); return true; } diff --git a/src/components/policy/src/policy_manager_impl.cc b/src/components/policy/src/policy_manager_impl.cc index 7e628ee3ef..4e3f892b45 100644 --- a/src/components/policy/src/policy_manager_impl.cc +++ b/src/components/policy/src/policy_manager_impl.cc @@ -452,8 +452,11 @@ bool PolicyManagerImpl::GetInitialAppData(const std::string& application_id, void PolicyManagerImpl::AddDevice(const std::string& device_id, const std::string& connection_type) { - LOG4CXX_INFO(logger_, "SetDeviceInfo"); - LOG4CXX_DEBUG(logger_, "Device :" << device_id); + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, "Device: " << device_id); + if (!cache_->AddDevice(device_id, connection_type)) { + LOG4CXX_WARN(logger_, "Can't add device."); + } } void PolicyManagerImpl::SetDeviceInfo(const std::string& device_id, diff --git a/src/components/policy/src/sql_pt_queries.cc b/src/components/policy/src/sql_pt_queries.cc index ff4386c3c2..df4bc74cc2 100644 --- a/src/components/policy/src/sql_pt_queries.cc +++ b/src/components/policy/src/sql_pt_queries.cc @@ -514,8 +514,8 @@ const std::string kInsertLanguage = "INSERT OR IGNORE INTO `language` (`code`) VALUES (?)"; const std::string kInsertMessageString = - "INSERT INTO `message` (`tts`, `label`, `line1`, `line2`, `language_code`, " - " `message_type_name`, `textBody`) VALUES (?, ?, ?, ?, ?, ?, ?)"; + "INSERT INTO `message` (`language_code`, `message_type_name`) " + "VALUES (?, ?)"; const std::string kUpdateModuleConfig = "UPDATE `module_config` SET `preloaded_pt` = ?, " @@ -540,16 +540,8 @@ const std::string kInsertDeviceData = "INSERT OR IGNORE INTO `device` (`id`) VALUES (?)"; const std::string kInsertAppLevel = - "INSERT INTO `app_level` (`application_id`, `minutes_in_hmi_full`," - "`minutes_in_hmi_limited` ,`minutes_in_hmi_background`," - "`minutes_in_hmi_none`,`count_of_user_selections`," - "`count_of_rejections_sync_out_of_memory`," - "`count_of_rejections_nickname_mismatch`," - "`count_of_rejections_duplicate_name`,`count_of_rejected_rpcs_calls`," - "`count_of_rpcs_sent_in_hmi_none`,`count_of_removals_for_bad_behavior`," - "`count_of_run_attempts_while_revoked`,`app_registration_language_gui`," - "`app_registration_language_vui`, `count_of_tls_errors`) " - "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + "INSERT INTO `app_level` (`application_id`, `count_of_tls_errors`) " + "VALUES(?,?)"; const std::string kDeleteSecondsBetweenRetries = "DELETE FROM `seconds_between_retry`"; @@ -582,7 +574,9 @@ const std::string kSelectNotificationsPerMin = const std::string kSelectNotificationsPerPriority = "SELECT `value` FROM notifications_by_priority WHERE `priority_value` = ? "; -const std::string kSelectAppLevels = "SELECT `application_id` FROM `app_level`"; +const std::string kSelectAppLevels = + "SELECT `application_id`, `count_of_tls_errors` " + "FROM `app_level`"; const std::string kSelectDeviceData = "SELECT * FROM `device`"; @@ -601,6 +595,8 @@ const std::string kSelectAppPolicies = "SELECT `id`, `priority_value`, `memory_kb`, " " `heart_beat_timeout_ms`, `certificate` FROM `application`"; +const std::string kCollectFriendlyMsg = "SELECT * FROM `message`"; + const std::string kSelectAppGroups = "SELECT `f`.`name` FROM `app_group` AS `a`" " LEFT JOIN `functional_group` AS `f` " diff --git a/src/components/policy/src/sql_pt_representation.cc b/src/components/policy/src/sql_pt_representation.cc index 8cdb3c9448..b94e9306d3 100644 --- a/src/components/policy/src/sql_pt_representation.cc +++ b/src/components/policy/src/sql_pt_representation.cc @@ -560,13 +560,16 @@ bool SQLPTRepresentation::GatherUsageAndErrorCounts( LOG4CXX_INFO(logger_, "Gather Usage and Error Counts."); utils::dbms::SQLQuery query(db()); if (query.Prepare(sql_pt::kSelectAppLevels)) { - policy_table::AppLevel app_level_empty; - app_level_empty.mark_initialized(); + policy_table::AppLevel app_level; + app_level.mark_initialized(); while (query.Next()) { - (*counts->app_level)[query.GetString(0)] = app_level_empty; + app_level.count_of_tls_errors = query.GetInteger(1); + const std::string app_id = query.GetString(0); + (*counts->app_level)[app_id] = app_level; } + return true; } - return true; + return false; } void SQLPTRepresentation::GatherDeviceData( @@ -576,10 +579,11 @@ void SQLPTRepresentation::GatherDeviceData( utils::dbms::SQLQuery query(db()); if (query.Prepare(sql_pt::kSelectDeviceData)) { - policy_table::DeviceParams device_data_empty; - device_data_empty.mark_initialized(); + policy_table::DeviceParams device_data; + device_data.mark_initialized(); while (query.Next()) { - (*data)[query.GetString(0)] = device_data_empty; + const std::string device_id = query.GetString(0); + (*data)[device_id] = device_data; } } } @@ -635,7 +639,22 @@ bool SQLPTRepresentation::GatherConsumerFriendlyMessages( LOG4CXX_WARN(logger_, "Incorrect select from consumer_friendly_messages"); return false; } + messages->version = query.GetString(0); + + if (query.Prepare(sql_pt::kCollectFriendlyMsg)) { + while (query.Next()) { + + UserFriendlyMessage msg; + msg.message_code = query.GetString(7); + std::string language = query.GetString(6); + + (*messages->messages)[msg.message_code].languages[language]; + } + } else { + LOG4CXX_WARN(logger_, "Incorrect statement for select friendly messages."); + } + return true; } @@ -1171,7 +1190,6 @@ bool SQLPTRepresentation::SaveConsumerFriendlyMessages( } policy_table::Messages::const_iterator it; - // TODO(IKozyrenko): Check logic if optional container is missing for (it = messages.messages->begin(); it != messages.messages->end(); ++it) { if (!SaveMessageType(it->first)) { @@ -1231,7 +1249,19 @@ bool SQLPTRepresentation::SaveMessageString( const std::string& type, const std::string& lang, const policy_table::MessageString& strings) { - // Section is empty for SDL specific + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kInsertMessageString)) { + LOG4CXX_WARN(logger_, "Incorrect insert statement for message."); + return false; + } + + query.Bind(0, lang); + query.Bind(1, type); + + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into message."); + return false; + } return true; } @@ -1293,7 +1323,7 @@ bool SQLPTRepresentation::SaveDeviceData( policy_table::DeviceData::const_iterator it; for (it = devices.begin(); it != devices.end(); ++it) { query.Bind(0, it->first); - if (!query.Exec()) { + if (!query.Exec() || !query.Reset()) { LOG4CXX_WARN(logger_, "Incorrect insert into device data."); return false; } @@ -1320,7 +1350,8 @@ bool SQLPTRepresentation::SaveUsageAndErrorCounts( const_cast<policy_table::AppLevels&>(*counts.app_level).mark_initialized(); for (it = app_levels.begin(); it != app_levels.end(); ++it) { query.Bind(0, it->first); - if (!query.Exec()) { + query.Bind(1, it->second.count_of_tls_errors); + if (!query.Exec() || !query.Reset()) { LOG4CXX_WARN(logger_, "Incorrect insert into app level."); return false; } diff --git a/src/components/policy/test/sql_pt_representation_test.cc b/src/components/policy/test/sql_pt_representation_test.cc index c2874122b0..9a69556d58 100644 --- a/src/components/policy/test/sql_pt_representation_test.cc +++ b/src/components/policy/test/sql_pt_representation_test.cc @@ -210,6 +210,8 @@ class SQLPTRepresentationTest : public SQLPTRepresentation, policy_table["functional_groupings"] = Json::Value(Json::objectValue); policy_table["consumer_friendly_messages"] = Json::Value(Json::objectValue); policy_table["app_policies"] = Json::Value(Json::objectValue); + policy_table["usage_and_error_counts"] = Json::Value(Json::objectValue); + policy_table["device_data"] = Json::Value(Json::objectValue); // 'module_config' section start Json::Value& module_config = policy_table["module_config"]; @@ -268,18 +270,13 @@ class SQLPTRepresentationTest : public SQLPTRepresentation, Json::Value& consumer_friendly_messages = policy_table["consumer_friendly_messages"]; - consumer_friendly_messages["version"] = Json::Value("1.2"); + consumer_friendly_messages["version"] = Json::Value("some_msg_version"); consumer_friendly_messages["messages"] = Json::Value(Json::objectValue); - consumer_friendly_messages["messages"]["MSG1"] = + consumer_friendly_messages["messages"]["MSG_CODE"] = Json::Value(Json::objectValue); - Json::Value& msg1 = consumer_friendly_messages["messages"]["MSG1"]; + Json::Value& msg1 = consumer_friendly_messages["messages"]["MSG_CODE"]; msg1["languages"] = Json::Value(Json::objectValue); msg1["languages"]["en-us"] = Json::Value(Json::objectValue); - msg1["languages"]["en-us"]["tts"] = Json::Value("TTS message"); - msg1["languages"]["en-us"]["label"] = Json::Value("LABEL message"); - msg1["languages"]["en-us"]["line1"] = Json::Value("LINE1 message"); - msg1["languages"]["en-us"]["line2"] = Json::Value("LINE2 message"); - msg1["languages"]["en-us"]["textBody"] = Json::Value("TEXTBODY message"); // 'functional_groupings' section end // 'app_policies' section start @@ -325,6 +322,19 @@ class SQLPTRepresentationTest : public SQLPTRepresentation, app_policies["device"]["keep_context"] = Json::Value(true); app_policies["device"]["steal_focus"] = Json::Value(true); // 'app_policies' section end + + Json::Value& usage_and_error_counts = + policy_table["usage_and_error_counts"]; + usage_and_error_counts["app_level"] = Json::Value(Json::objectValue); + usage_and_error_counts["app_level"]["some_app_id"] = + Json::Value(Json::objectValue); + usage_and_error_counts["app_level"]["some_app_id"]["count_of_tls_errors"] = + Json::Value(5); + + Json::Value& device_data = policy_table["device_data"]; + device_data["device_id_hash_1"] = Json::Value(Json::objectValue); + device_data["device_id_hash_2"] = Json::Value(Json::objectValue); + device_data["device_id_hash_3"] = Json::Value(Json::objectValue); } ::testing::AssertionResult IsValid(const policy_table::Table& table) { @@ -1533,12 +1543,15 @@ TEST_F(SQLPTRepresentationTest, Save_SetPolicyTableThenSave_ExpectSavedToPT) { policy_table::ConsumerFriendlyMessages messages; GatherConsumerFriendlyMessages(&messages); EXPECT_EQ("0", static_cast<std::string>(messages.version)); + policy_table::DeviceData devices; GatherDeviceData(&devices); EXPECT_EQ(0u, devices.size()); + policy_table::UsageAndErrorCounts counts; GatherUsageAndErrorCounts(&counts); - EXPECT_EQ(0u, counts.app_level->size()); + EXPECT_TRUE(0u == counts.app_level->size()); + // ASSERT_TRUE(IsValid(update)); // Act ASSERT_TRUE(reps->Save(update)); @@ -1638,8 +1651,18 @@ TEST_F(SQLPTRepresentationTest, Save_SetPolicyTableThenSave_ExpectSavedToPT) { EXPECT_EQ("default", url_list.begin()->first); policy_table::URL& url = url_list.begin()->second; EXPECT_EQ("http://ford.com/cloud/default", static_cast<std::string>(url[0])); + GatherConsumerFriendlyMessages(&messages); - EXPECT_EQ("1.2", static_cast<std::string>(messages.version)); + EXPECT_EQ("some_msg_version", static_cast<std::string>(messages.version)); + EXPECT_TRUE(0u != messages.messages->size()); + EXPECT_TRUE(0u != (*messages.messages)["MSG_CODE"].languages.size()); + + GatherUsageAndErrorCounts(&counts); + EXPECT_FALSE(0u == counts.app_level->size()); + EXPECT_EQ(5u, (*counts.app_level)["some_app_id"].count_of_tls_errors); + + GatherDeviceData(&devices); + EXPECT_EQ(3u, devices.size()); } } // namespace policy |