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 {
38 CustomHandlerPtr getSingleHandler(std::list<T> row)
40 CustomHandlerPtr handler;
42 // There should be only one
44 ThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
45 "More than one handler registered");
48 handler.reset(new CustomHandler());
49 handler->target = row.front().Get_target();
50 handler->base_url = row.front().Get_base_url();
51 handler->url = row.front().Get_url();
52 handler->title = row.front().Get_title();
53 handler->user_allowed = static_cast<bool>(row.front().Get_user_allowed());
54 handler->user_decision =
55 static_cast<HandlerState>(row.front().Get_user_allowed());
62 CustomHandlerDAOReadOnly::CustomHandlerDAOReadOnly(const DPL::String& pkgName) :
67 CustomHandlerDAOReadOnly::~CustomHandlerDAOReadOnly()
71 CustomHandlerPtr CustomHandlerDAOReadOnly::getProtocolHandler(
72 const DPL::String& protocol,
73 const DPL::String& url)
75 LogDebug("Getting protocol handler");
77 CUSTOM_HANDLER_DB_SELECT(select, ProtocolHandlers);
79 select->Where(And(Equals<ProtocolHandlers::app_id>(m_pkgName),
80 And(Equals<ProtocolHandlers::target>(protocol),
81 Equals<ProtocolHandlers::url>(url))));
83 std::list<ProtocolHandlers::Row> list = select->GetRowList();
84 return getSingleHandler(list);
85 } Catch(DPL::DB::SqlConnection::Exception::Base) {
86 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
87 "Failed to get protocol handler");
91 CustomHandlerPtr CustomHandlerDAOReadOnly::getContentHandler(
92 const DPL::String& content,
93 const DPL::String& url)
95 LogDebug("Getting content handler");
97 CUSTOM_HANDLER_DB_SELECT(select, ContentHandlers);
99 select->Where(And(Equals<ContentHandlers::app_id>(m_pkgName),
100 And(Equals<ContentHandlers::target>(content),
101 Equals<ContentHandlers::url>(url))));
103 std::list<ContentHandlers::Row> list = select->GetRowList();
104 return getSingleHandler(list);
105 } Catch(DPL::DB::SqlConnection::Exception::Base) {
106 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
107 "Failed to get content handler");
111 CustomHandlerPtr CustomHandlerDAOReadOnly::getActivProtocolHandler(
112 const DPL::String& protocol)
114 LogDebug("Getting active protocol handler");
116 CUSTOM_HANDLER_DB_SELECT(select, ProtocolHandlers);
118 select->Where(And(Equals<ProtocolHandlers::app_id>(m_pkgName),
119 Equals<ProtocolHandlers::target>(protocol)));
121 std::list<ProtocolHandlers::Row> list = select->GetRowList();
122 CustomHandlerPtr handler;
125 if (it->Get_user_allowed() & Agreed) {
126 handler.reset(new CustomHandler());
127 handler->base_url = it->Get_base_url();
128 handler->target = it->Get_target();
129 handler->title = it->Get_title();
130 handler->url = it->Get_url();
131 handler->user_allowed =
132 static_cast<bool>(it->Get_user_allowed());
133 handler->user_decision =
134 static_cast<HandlerState>(it->Get_user_allowed());
138 } Catch(DPL::DB::SqlConnection::Exception::Base) {
139 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
140 "Failed to get protocol handler");
144 CustomHandlerPtr CustomHandlerDAOReadOnly::getProtocolHandler(
145 const DPL::String& protocol,
146 const DPL::String& url,
147 const DPL::String& baseURL)
149 LogDebug("Check if protocol is registered");
151 CUSTOM_HANDLER_DB_SELECT(select, ProtocolHandlers);
153 select->Where(And(Equals<ProtocolHandlers::app_id>(m_pkgName),
154 And(Equals<ProtocolHandlers::target>(protocol),
155 And(Equals<ProtocolHandlers::url>(url),
156 Equals<ProtocolHandlers::base_url>(baseURL)
162 std::list<ProtocolHandlers::Row> list = select->GetRowList();
163 return getSingleHandler(list);
164 } Catch(DPL::DB::SqlConnection::Exception::Base) {
165 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
166 "Failed to get content handler");
171 CustomHandlerPtr CustomHandlerDAOReadOnly::getActivContentHandler(
172 const DPL::String& content)
174 LogDebug("Getting active content handler");
176 CUSTOM_HANDLER_DB_SELECT(select, ContentHandlers);
178 select->Where(And(Equals<ContentHandlers::app_id>(m_pkgName),
179 Equals<ContentHandlers::target>(content)));
181 std::list<ContentHandlers::Row> list = select->GetRowList();
182 CustomHandlerPtr handler;
185 if (it->Get_user_allowed() & Agreed) {
186 handler.reset(new CustomHandler());
187 handler->base_url = it->Get_base_url();
188 handler->target = it->Get_target();
189 handler->title = it->Get_title();
190 handler->url = it->Get_url();
191 handler->user_allowed =
192 static_cast<bool>(it->Get_user_allowed());
193 handler->user_decision =
194 static_cast<HandlerState>(it->Get_user_allowed());
198 } Catch(DPL::DB::SqlConnection::Exception::Base) {
199 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
200 "Failed to get protocol handler");
204 CustomHandlerPtr CustomHandlerDAOReadOnly::getContentHandler(
205 const DPL::String& content,
206 const DPL::String& url,
207 const DPL::String& baseURL)
209 LogDebug("Check if content is registered");
211 CUSTOM_HANDLER_DB_SELECT(select, ContentHandlers);
213 select->Where(And(Equals<ContentHandlers::app_id>(m_pkgName),
214 And(Equals<ContentHandlers::target>(content),
215 And(Equals<ContentHandlers::url>(url),
216 Equals<ContentHandlers::base_url>(baseURL)))));
218 std::list<ContentHandlers::Row> list = select->GetRowList();
219 return getSingleHandler(list);
220 } Catch(DPL::DB::SqlConnection::Exception::Base) {
221 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
222 "Failed to get content handler");
226 CustomHandlerPtr CustomHandlerDAOReadOnly::getAllowedProtocolHandler(
227 const DPL::String& protocol)
229 LogDebug("Getting allowed protocol handler");
231 CUSTOM_HANDLER_DB_SELECT(select, ProtocolHandlers);
233 select->Where(And(Equals<ProtocolHandlers::app_id>(m_pkgName),
234 And(Equals<ProtocolHandlers::target>(protocol),
235 Equals<ProtocolHandlers::user_allowed>(true))));
237 std::list<ProtocolHandlers::Row> list = select->GetRowList();
238 return getSingleHandler(list);
239 } Catch(DPL::DB::SqlConnection::Exception::Base) {
240 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
241 "Failed to get content handler");
245 CustomHandlerPtr CustomHandlerDAOReadOnly::getAllowedContentHandler(
246 const DPL::String& protocol)
248 LogDebug("Getting allowed content handler");
250 CUSTOM_HANDLER_DB_SELECT(select, ContentHandlers)
252 select->Where(And(Equals<ContentHandlers::app_id>(m_pkgName),
253 And(Equals<ContentHandlers::target>(protocol),
254 Equals<ContentHandlers::user_allowed>(true))));
256 std::list<ContentHandlers::Row> list = select->GetRowList();
257 return getSingleHandler(list);
258 } Catch(DPL::DB::SqlConnection::Exception::Base) {
259 ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
260 "Failed to get content handler");
264 } // namespace CustomHandlerDB