From 5ba351b575d5f831c2058a7a1dca578713ba66c0 Mon Sep 17 00:00:00 2001 From: AKalinich-Luxoft Date: Thu, 15 Jun 2017 14:39:58 +0300 Subject: Fix consumer friendly messages removing from PT In case PTU comes with omitted consumer_friendly_messages param SDL should maintain current consumer_friendly_messages section in Local PT. --- src/components/policy/policy_regular/src/sql_pt_representation.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 e94c853414..18d8975d15 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -1177,9 +1177,11 @@ bool SQLPTRepresentation::SaveConsumerFriendlyMessages( // the policy table. So it won't be changed/updated if (messages.messages.is_initialized()) { utils::dbms::SQLQuery query(db()); - if (!query.Exec(sql_pt::kDeleteMessageString)) { - LOG4CXX_WARN(logger_, "Incorrect delete from message."); - return false; + if (!messages.messages->empty()) { + if (!query.Exec(sql_pt::kDeleteMessageString)) { + LOG4CXX_WARN(logger_, "Incorrect delete from message."); + return false; + } } if (query.Prepare(sql_pt::kUpdateVersion)) { -- cgit v1.2.1 From 045a313b4d99b6141ae99e71ff0e9d1d20520a1c Mon Sep 17 00:00:00 2001 From: AKalinich-Luxoft Date: Thu, 15 Jun 2017 15:55:14 +0300 Subject: Refactoring in SaveConsumerFriendlyMessages function Removed nested if's. --- .../policy_external/src/sql_pt_representation.cc | 68 +++++++++++----------- .../policy_regular/src/sql_pt_representation.cc | 67 +++++++++++---------- 2 files changed, 70 insertions(+), 65 deletions(-) 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 48985fa835..5a3233b67d 100644 --- a/src/components/policy/policy_external/src/sql_pt_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_representation.cc @@ -1264,46 +1264,48 @@ bool SQLPTRepresentation::SaveConsumerFriendlyMessages( // According CRS-2419 If there is no “consumer_friendly_messages” key, // the current local consumer_friendly_messages section shall be maintained in // the policy table. So it won't be changed/updated - if (messages.messages.is_initialized()) { - utils::dbms::SQLQuery query(db()); - if (!messages.messages->empty()) { - if (!query.Exec(sql_pt::kDeleteMessageString)) { - LOG4CXX_WARN(logger_, "Incorrect delete from message."); - return false; - } - } + if (!messages.messages.is_initialized()) { + LOG4CXX_INFO(logger_, "Messages list is empty"); + return true; + } - if (query.Prepare(sql_pt::kUpdateVersion)) { - query.Bind(0, messages.version); - if (!query.Exec()) { - LOG4CXX_WARN(logger_, "Incorrect update into version."); - return false; - } - } else { - LOG4CXX_WARN(logger_, "Incorrect update statement for version."); + utils::dbms::SQLQuery query(db()); + bool delete_query_exec_result = true; + if (!messages.messages->empty()) { + delete_query_exec_result = query.Exec(sql_pt::kDeleteMessageString); + } + + if (!delete_query_exec_result) { + LOG4CXX_WARN(logger_, "Incorrect delete from message."); + return false; + } + + if (!query.Prepare(sql_pt::kUpdateVersion)) { + LOG4CXX_WARN(logger_, "Incorrect update statement for version."); + return false; + } + + query.Bind(0, messages.version); + if (!query.Exec()) { + LOG4CXX_WARN(logger_, "Incorrect update into version."); + return false; + } + + policy_table::Messages::const_iterator it; + for (it = messages.messages->begin(); it != messages.messages->end(); ++it) { + if (!SaveMessageType(it->first)) { return false; } - - 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)) { + const policy_table::Languages& langs = it->second.languages; + policy_table::Languages::const_iterator lang_it; + for (lang_it = langs.begin(); lang_it != langs.end(); ++lang_it) { + if (!SaveLanguage(lang_it->first)) { return false; } - const policy_table::Languages& langs = it->second.languages; - policy_table::Languages::const_iterator lang_it; - for (lang_it = langs.begin(); lang_it != langs.end(); ++lang_it) { - if (!SaveLanguage(lang_it->first)) { - return false; - } - if (!SaveMessageString(it->first, lang_it->first, lang_it->second)) { - return false; - } + if (!SaveMessageString(it->first, lang_it->first, lang_it->second)) { + return false; } } - } else { - LOG4CXX_INFO(logger_, "Messages list is empty"); } return true; 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 18d8975d15..e0c8747c16 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -1175,45 +1175,48 @@ bool SQLPTRepresentation::SaveConsumerFriendlyMessages( // According CRS-2419 If there is no “consumer_friendly_messages” key, // the current local consumer_friendly_messages section shall be maintained in // the policy table. So it won't be changed/updated - if (messages.messages.is_initialized()) { - utils::dbms::SQLQuery query(db()); - if (!messages.messages->empty()) { - if (!query.Exec(sql_pt::kDeleteMessageString)) { - LOG4CXX_WARN(logger_, "Incorrect delete from message."); - return false; - } - } + if (!messages.messages.is_initialized()) { + LOG4CXX_INFO(logger_, "Messages list is empty"); + return true; + } - if (query.Prepare(sql_pt::kUpdateVersion)) { - query.Bind(0, messages.version); - if (!query.Exec()) { - LOG4CXX_WARN(logger_, "Incorrect update into version."); - return false; - } - } else { - LOG4CXX_WARN(logger_, "Incorrect update statement for version."); + utils::dbms::SQLQuery query(db()); + bool delete_query_exec_result = true; + if (!messages.messages->empty()) { + delete_query_exec_result = query.Exec(sql_pt::kDeleteMessageString); + } + + if (!delete_query_exec_result) { + LOG4CXX_WARN(logger_, "Incorrect delete from message."); + return false; + } + + if (!query.Prepare(sql_pt::kUpdateVersion)) { + LOG4CXX_WARN(logger_, "Incorrect update statement for version."); + return false; + } + + query.Bind(0, messages.version); + if (!query.Exec()) { + LOG4CXX_WARN(logger_, "Incorrect update into version."); + return false; + } + + policy_table::Messages::const_iterator it; + for (it = messages.messages->begin(); it != messages.messages->end(); ++it) { + if (!SaveMessageType(it->first)) { return false; } - - policy_table::Messages::const_iterator it; - for (it = messages.messages->begin(); it != messages.messages->end(); - ++it) { - if (!SaveMessageType(it->first)) { + const policy_table::Languages& langs = it->second.languages; + policy_table::Languages::const_iterator lang_it; + for (lang_it = langs.begin(); lang_it != langs.end(); ++lang_it) { + if (!SaveLanguage(lang_it->first)) { return false; } - const policy_table::Languages& langs = it->second.languages; - policy_table::Languages::const_iterator lang_it; - for (lang_it = langs.begin(); lang_it != langs.end(); ++lang_it) { - if (!SaveLanguage(lang_it->first)) { - return false; - } - if (!SaveMessageString(it->first, lang_it->first, lang_it->second)) { - return false; - } + if (!SaveMessageString(it->first, lang_it->first, lang_it->second)) { + return false; } } - } else { - LOG4CXX_INFO(logger_, "Messages list is empty"); } return true; -- cgit v1.2.1 From 36a37e964f03b3c01decee10c80a67b8c5ec1590 Mon Sep 17 00:00:00 2001 From: AKalinich-Luxoft Date: Fri, 16 Jun 2017 15:29:03 +0300 Subject: Fixed logger messages context --- .../policy/policy_external/src/sql_pt_representation.cc | 8 ++++---- src/components/policy/policy_regular/src/sql_pt_representation.cc | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) 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 5a3233b67d..95c07e6aef 100644 --- a/src/components/policy/policy_external/src/sql_pt_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_representation.cc @@ -1265,7 +1265,7 @@ bool SQLPTRepresentation::SaveConsumerFriendlyMessages( // the current local consumer_friendly_messages section shall be maintained in // the policy table. So it won't be changed/updated if (!messages.messages.is_initialized()) { - LOG4CXX_INFO(logger_, "Messages list is empty"); + LOG4CXX_INFO(logger_, "ConsumerFriendlyMessages messages list is empty"); return true; } @@ -1276,18 +1276,18 @@ bool SQLPTRepresentation::SaveConsumerFriendlyMessages( } if (!delete_query_exec_result) { - LOG4CXX_WARN(logger_, "Incorrect delete from message."); + LOG4CXX_WARN(logger_, "Failed to delete messages from DB."); return false; } if (!query.Prepare(sql_pt::kUpdateVersion)) { - LOG4CXX_WARN(logger_, "Incorrect update statement for version."); + LOG4CXX_WARN(logger_, "Invalid update messages version statement."); return false; } query.Bind(0, messages.version); if (!query.Exec()) { - LOG4CXX_WARN(logger_, "Incorrect update into version."); + LOG4CXX_WARN(logger_, "Failed to update messages version number in DB."); return false; } 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 e0c8747c16..a9ecc87053 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -1176,7 +1176,7 @@ bool SQLPTRepresentation::SaveConsumerFriendlyMessages( // the current local consumer_friendly_messages section shall be maintained in // the policy table. So it won't be changed/updated if (!messages.messages.is_initialized()) { - LOG4CXX_INFO(logger_, "Messages list is empty"); + LOG4CXX_INFO(logger_, "ConsumerFriendlyMessages messages list is empty"); return true; } @@ -1187,18 +1187,18 @@ bool SQLPTRepresentation::SaveConsumerFriendlyMessages( } if (!delete_query_exec_result) { - LOG4CXX_WARN(logger_, "Incorrect delete from message."); + LOG4CXX_WARN(logger_, "Failed to delete messages from DB."); return false; } if (!query.Prepare(sql_pt::kUpdateVersion)) { - LOG4CXX_WARN(logger_, "Incorrect update statement for version."); + LOG4CXX_WARN(logger_, "Invalid update messages version statement."); return false; } query.Bind(0, messages.version); if (!query.Exec()) { - LOG4CXX_WARN(logger_, "Incorrect update into version."); + LOG4CXX_WARN(logger_, "Failed to update messages version number in DB."); return false; } -- cgit v1.2.1