2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * This file contains the declaration of custom handler dao class.
19 * @file custom_handler_dao_read_only.cpp
20 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
22 * @brief This file contains the declaration of custom handler dao
25 #include <wrt-commons/custom-handler-dao-ro/custom_handler_dao_read_only.h>
26 #include <wrt-commons/custom-handler-dao-ro/CustomHandlerDatabase.h>
28 #include <orm_generator_custom_handler.h>
30 using namespace DPL::DB::ORM;
31 using namespace DPL::DB::ORM::custom_handler;
33 namespace CustomHandlerDB {
36 CustomHandlerPtr getSingleHandler(std::list<T> row)
38 CustomHandlerPtr handler;
40 // There should be only one
42 ThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
43 "More than one handler registered");
46 handler.reset(new CustomHandler());
47 handler->target = row.front().Get_target();
48 handler->base_url = row.front().Get_base_url();
49 handler->url = row.front().Get_url();
50 handler->title = row.front().Get_title();
51 handler->user_allowed = static_cast<bool>(row.front().Get_user_allowed());
52 handler->user_decision =
53 static_cast<HandlerState>(row.front().Get_user_allowed());
59 CustomHandlerDAOReadOnly::CustomHandlerDAOReadOnly(const DPL::String& pkgName)
64 CustomHandlerDAOReadOnly::~CustomHandlerDAOReadOnly()
67 CustomHandlerPtr CustomHandlerDAOReadOnly::getProtocolHandler(
68 const DPL::String& protocol,
69 const DPL::String& url)
71 LogDebug("Getting protocol handler");
73 CUSTOM_HANDLER_DB_SELECT(select, ProtocolHandlers);
75 select->Where(And(Equals<ProtocolHandlers::app_id>(m_pkgName),
76 And(Equals<ProtocolHandlers::target>(protocol),
77 Equals<ProtocolHandlers::url>(url))));
79 std::list<ProtocolHandlers::Row> list = select->GetRowList();
80 return getSingleHandler(list);
81 } Catch(DPL::DB::SqlConnection::Exception::Base) {
82 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
83 "Failed to get protocol handler");
87 CustomHandlerPtr CustomHandlerDAOReadOnly::getContentHandler(
88 const DPL::String& content,
89 const DPL::String& url)
91 LogDebug("Getting content handler");
93 CUSTOM_HANDLER_DB_SELECT(select, ContentHandlers);
95 select->Where(And(Equals<ContentHandlers::app_id>(m_pkgName),
96 And(Equals<ContentHandlers::target>(content),
97 Equals<ContentHandlers::url>(url))));
99 std::list<ContentHandlers::Row> list = select->GetRowList();
100 return getSingleHandler(list);
101 } Catch(DPL::DB::SqlConnection::Exception::Base) {
102 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
103 "Failed to get content handler");
107 CustomHandlerPtr CustomHandlerDAOReadOnly::getActivProtocolHandler(
108 const DPL::String& protocol)
110 LogDebug("Getting active protocol handler");
112 CUSTOM_HANDLER_DB_SELECT(select, ProtocolHandlers);
114 select->Where(And(Equals<ProtocolHandlers::app_id>(m_pkgName),
115 Equals<ProtocolHandlers::target>(protocol)));
117 std::list<ProtocolHandlers::Row> list = select->GetRowList();
118 CustomHandlerPtr handler;
121 if (it->Get_user_allowed() & Agreed) {
122 handler.reset(new CustomHandler());
123 handler->base_url = it->Get_base_url();
124 handler->target = it->Get_target();
125 handler->title = it->Get_title();
126 handler->url = it->Get_url();
127 handler->user_allowed =
128 static_cast<bool>(it->Get_user_allowed());
129 handler->user_decision =
130 static_cast<HandlerState>(it->Get_user_allowed());
134 } Catch(DPL::DB::SqlConnection::Exception::Base) {
135 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
136 "Failed to get protocol handler");
140 CustomHandlerPtr CustomHandlerDAOReadOnly::getProtocolHandler(
141 const DPL::String& protocol,
142 const DPL::String& url,
143 const DPL::String& baseURL)
145 LogDebug("Check if protocol is registered");
147 CUSTOM_HANDLER_DB_SELECT(select, ProtocolHandlers);
149 select->Where(And(Equals<ProtocolHandlers::app_id>(m_pkgName),
150 And(Equals<ProtocolHandlers::target>(protocol),
151 And(Equals<ProtocolHandlers::url>(url),
152 Equals<ProtocolHandlers::base_url>(baseURL)
158 std::list<ProtocolHandlers::Row> list = select->GetRowList();
159 return getSingleHandler(list);
160 } Catch(DPL::DB::SqlConnection::Exception::Base) {
161 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
162 "Failed to get content handler");
166 CustomHandlerPtr CustomHandlerDAOReadOnly::getActivContentHandler(
167 const DPL::String& content)
169 LogDebug("Getting active content handler");
171 CUSTOM_HANDLER_DB_SELECT(select, ContentHandlers);
173 select->Where(And(Equals<ContentHandlers::app_id>(m_pkgName),
174 Equals<ContentHandlers::target>(content)));
176 std::list<ContentHandlers::Row> list = select->GetRowList();
177 CustomHandlerPtr handler;
180 if (it->Get_user_allowed() & Agreed) {
181 handler.reset(new CustomHandler());
182 handler->base_url = it->Get_base_url();
183 handler->target = it->Get_target();
184 handler->title = it->Get_title();
185 handler->url = it->Get_url();
186 handler->user_allowed =
187 static_cast<bool>(it->Get_user_allowed());
188 handler->user_decision =
189 static_cast<HandlerState>(it->Get_user_allowed());
193 } Catch(DPL::DB::SqlConnection::Exception::Base) {
194 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
195 "Failed to get protocol handler");
199 CustomHandlerPtr CustomHandlerDAOReadOnly::getContentHandler(
200 const DPL::String& content,
201 const DPL::String& url,
202 const DPL::String& baseURL)
204 LogDebug("Check if content is registered");
206 CUSTOM_HANDLER_DB_SELECT(select, ContentHandlers);
208 select->Where(And(Equals<ContentHandlers::app_id>(m_pkgName),
209 And(Equals<ContentHandlers::target>(content),
210 And(Equals<ContentHandlers::url>(url),
211 Equals<ContentHandlers::base_url>(baseURL)))));
213 std::list<ContentHandlers::Row> list = select->GetRowList();
214 return getSingleHandler(list);
215 } Catch(DPL::DB::SqlConnection::Exception::Base) {
216 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
217 "Failed to get content handler");
221 CustomHandlerPtr CustomHandlerDAOReadOnly::getAllowedProtocolHandler(
222 const DPL::String& protocol)
224 LogDebug("Getting allowed protocol handler");
226 CUSTOM_HANDLER_DB_SELECT(select, ProtocolHandlers);
228 select->Where(And(Equals<ProtocolHandlers::app_id>(m_pkgName),
229 And(Equals<ProtocolHandlers::target>(protocol),
230 Equals<ProtocolHandlers::user_allowed>(true))));
232 std::list<ProtocolHandlers::Row> list = select->GetRowList();
233 return getSingleHandler(list);
234 } Catch(DPL::DB::SqlConnection::Exception::Base) {
235 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
236 "Failed to get content handler");
240 CustomHandlerPtr CustomHandlerDAOReadOnly::getAllowedContentHandler(
241 const DPL::String& protocol)
243 LogDebug("Getting allowed content handler");
245 CUSTOM_HANDLER_DB_SELECT(select, ContentHandlers)
247 select->Where(And(Equals<ContentHandlers::app_id>(m_pkgName),
248 And(Equals<ContentHandlers::target>(protocol),
249 Equals<ContentHandlers::user_allowed>(true))));
251 std::list<ContentHandlers::Row> list = select->GetRowList();
252 return getSingleHandler(list);
253 } Catch(DPL::DB::SqlConnection::Exception::Base) {
254 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
255 "Failed to get content handler");
258 } // namespace CustomHandlerDB