diff options
author | Andriy Byzhynar (GitHub) <AByzhynar@luxoft.com> | 2018-04-19 17:59:07 +0300 |
---|---|---|
committer | Ira Lytvynenko (GitHub) <ILytvynenko@luxoft.com> | 2018-05-24 13:15:46 +0300 |
commit | 767575366af311bbf33c26bd7ab74040f68890b7 (patch) | |
tree | 7485f6f6c7dc6d5d52ccd01413a07285278fff61 /src/components/policy/policy_regular/src/sql_pt_representation.cc | |
parent | dd8c006ecd1c5c696e696584aff694462a54ac4b (diff) | |
download | sdl_core-767575366af311bbf33c26bd7ab74040f68890b7.tar.gz |
Initial implementation of Expandable Design for Proprietary Data Exchange
Added new parameters to Mobile_API.xml & HMI_API.xml
Added handling of new RequestType and RequestSubTypes to policy component
Edited encoding & line endings in sdl_preloaded_pt.json
Updated notifications triggering
Diffstat (limited to 'src/components/policy/policy_regular/src/sql_pt_representation.cc')
-rw-r--r-- | src/components/policy/policy_regular/src/sql_pt_representation.cc | 118 |
1 files changed, 116 insertions, 2 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 9840a08b26..a57230aeb1 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -744,6 +744,10 @@ bool SQLPTRepresentation::GatherApplicationPoliciesSection( return false; } + if (!GatherRequestSubType(app_id, &*params.RequestSubType)) { + return false; + } + (*policies).apps[app_id] = params; } return true; @@ -837,6 +841,7 @@ bool SQLPTRepresentation::SaveFunctionalGroupings( bool SQLPTRepresentation::SaveRpcs(int64_t group_id, const policy_table::Rpc& rpcs) { + LOG4CXX_AUTO_TRACE(logger_); utils::dbms::SQLQuery query(db()); utils::dbms::SQLQuery query_parameter(db()); if (!query.Prepare(sql_pt::kInsertRpc) || @@ -916,6 +921,11 @@ bool SQLPTRepresentation::SaveApplicationPoliciesSection( return false; } + if (!query_delete.Exec(sql_pt::kDeleteRequestSubType)) { + LOG4CXX_WARN(logger_, "Incorrect delete from request subtype."); + return false; + } + // All predefined apps (e.g. default, pre_DataConsent) should be saved first, // otherwise another app with the predefined permissions can get incorrect // permissions @@ -1006,6 +1016,10 @@ bool SQLPTRepresentation::SaveSpecificAppPolicy( return false; } + if (!SaveRequestSubType(app.first, *app.second.RequestSubType)) { + return false; + } + return true; } @@ -1109,15 +1123,83 @@ bool SQLPTRepresentation::SaveRequestType( } policy_table::RequestTypes::const_iterator it; - for (it = types.begin(); it != types.end(); ++it) { + if (!types.empty()) { + LOG4CXX_WARN(logger_, "Request types not empty."); + for (it = types.begin(); it != types.end(); ++it) { + query.Bind(0, app_id); + query.Bind(1, std::string(policy_table::EnumToJsonString(*it))); + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into request types."); + return false; + } + } + } else if (types.is_initialized()) { + LOG4CXX_WARN(logger_, "Request types empty."); query.Bind(0, app_id); - query.Bind(1, std::string(policy_table::EnumToJsonString(*it))); + query.Bind(1, + std::string(policy_table::EnumToJsonString( + policy_table::RequestType::RT_EMPTY))); if (!query.Exec() || !query.Reset()) { LOG4CXX_WARN(logger_, "Incorrect insert into request types."); return false; } + } else { + utils::dbms::SQLQuery query_omitted(db()); + if (!query_omitted.Prepare(sql_pt::kInsertOmittedRequestType)) { + LOG4CXX_WARN(logger_, "Incorrect insert statement for request types."); + return false; + } + LOG4CXX_WARN(logger_, "Request types omitted."); + query_omitted.Bind(0, app_id); + if (!query_omitted.Exec() || !query_omitted.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into request types."); + return false; + } + } + return true; +} + +bool SQLPTRepresentation::SaveRequestSubType( + const std::string& app_id, + const policy_table::RequestSubTypes& request_subtypes) { + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kInsertRequestSubType)) { + LOG4CXX_WARN(logger_, "Incorrect insert statement for request subtypes."); + return false; } + policy_table::Strings::const_iterator it; + if (!request_subtypes.empty()) { + LOG4CXX_TRACE(logger_, "Request subtypes are not empty."); + for (it = request_subtypes.begin(); it != request_subtypes.end(); ++it) { + query.Bind(0, app_id); + query.Bind(1, *it); + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into request subtypes."); + return false; + } + } + } else if (request_subtypes.is_initialized()) { + LOG4CXX_WARN(logger_, "Request subtypes empty."); + query.Bind(0, app_id); + query.Bind(1, std::string("EMPTY")); + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into request subtypes."); + return false; + } + } else { + utils::dbms::SQLQuery query_omitted(db()); + if (!query_omitted.Prepare(sql_pt::kInsertOmittedRequestSubType)) { + LOG4CXX_WARN(logger_, "Incorrect insert statement for request subtypes."); + return false; + } + LOG4CXX_WARN(logger_, "Request subtypes omitted."); + query_omitted.Bind(0, app_id); + if (!query_omitted.Exec() || !query_omitted.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into request subtypes."); + return false; + } + } return true; } @@ -1529,11 +1611,36 @@ bool SQLPTRepresentation::GatherRequestType( if (!policy_table::EnumFromJsonString(query.GetString(0), &type)) { return false; } + if (policy_table::RequestType::RT_EMPTY == type) { + request_types->mark_initialized(); + continue; + } request_types->push_back(type); } return true; } +bool SQLPTRepresentation::GatherRequestSubType( + const std::string& app_id, + policy_table::RequestSubTypes* request_subtypes) const { + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kSelectRequestSubTypes)) { + LOG4CXX_WARN(logger_, "Incorrect select from request subtypes."); + return false; + } + + query.Bind(0, app_id); + while (query.Next()) { + const std::string request_subtype = query.GetString(0); + if ("EMPTY" == request_subtype) { + request_subtypes->mark_initialized(); + continue; + } + request_subtypes->push_back(request_subtype); + } + return true; +} + bool SQLPTRepresentation::GatherNickName( const std::string& app_id, policy_table::Strings* nicknames) const { utils::dbms::SQLQuery query(db()); @@ -1858,6 +1965,13 @@ bool SQLPTRepresentation::SetDefaultPolicy(const std::string& app_id) { !SaveRequestType(app_id, request_types)) { return false; } + + policy_table::Strings request_subtypes; + if (!GatherRequestSubType(kDefaultId, &request_subtypes) || + !SaveRequestSubType(app_id, request_subtypes)) { + return false; + } + policy_table::AppHMITypes app_types; if (!GatherAppType(kDefaultId, &app_types) || !SaveAppType(app_id, app_types)) { |