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 definition of widget dao class.
19 * @file widget_dao.cpp
20 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
21 * @author Bartosz Janiak (b.janiak@samsung.com)
22 * @author Yang Jie (jie2.yang@samsung.com)
23 * @author Koeun Choi(koeun.choi@samsung.com)
24 * @author Pawel Sikorski(p.sikorski@samsung.com)
26 * @brief This file contains the definition of Configuration.
29 #include <dpl/wrt-dao-rw/widget_dao.h>
32 #include <dpl/log/log.h>
33 #include <dpl/foreach.h>
34 #include <dpl/wrt-dao-ro/webruntime_database.h>
35 #include <dpl/wrt-dao-rw/property_dao.h>
36 #include <orm_generator_wrt.h>
37 #include <dpl/wrt-dao-ro/WrtDatabase.h>
41 //TODO in current solution in each getter there exists a check
42 //"IsWidgetInstalled". Maybe it should be verified, if it could be done
43 //differently (check in WidgetDAO constructor)
45 #define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN Try
47 #define SQL_CONNECTION_EXCEPTION_HANDLER_END(message) \
48 Catch(DPL::DB::SqlConnection::Exception::Base) { \
50 ReThrowMsg(WidgetDAO::Exception::DatabaseError, \
54 #define CHECK_WIDGET_EXISTENCE(macro_transaction, macro_handle) \
55 if (!WidgetDAO::isWidgetInstalled(macro_handle)) \
57 macro_transaction.Commit(); \
58 LogWarning("Cannot find widget. Handle: " << macro_handle); \
59 ThrowMsg(WidgetDAO::Exception::WidgetNotExist, \
60 "Cannot find widget. Handle: " << macro_handle); \
64 WidgetDAO::WidgetDAO(DbWidgetHandle widgetHandle) :
65 WidgetDAOReadOnly(widgetHandle)
69 WidgetDAO::WidgetDAO(DPL::OptionalString widgetGUID) :
70 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(widgetGUID))
74 WidgetDAO::~WidgetDAO()
78 void WidgetDAO::removeProperty(
79 const PropertyDAOReadOnly::WidgetPropertyKey &key)
82 PropertyDAO::RemoveProperty(m_widgetHandle, key);
84 Catch(PropertyDAOReadOnly::Exception::ReadOnlyProperty){
85 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
86 "Failure during removing property");
90 void WidgetDAO::setProperty(
91 const PropertyDAOReadOnly::WidgetPropertyKey &key,
92 const PropertyDAOReadOnly::WidgetPropertyValue &value,
96 PropertyDAO::SetProperty(m_widgetHandle, key, value, readOnly);
98 Catch(PropertyDAOReadOnly::Exception::ReadOnlyProperty){
99 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
100 "Failure during setting/updating property");
104 void WidgetDAO::setPkgName(const DPL::OptionalString& pkgName)
106 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
108 using namespace DPL::DB::ORM;
109 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
111 isWidgetInstalled(getHandle());
113 wrt::WidgetInfo::Row row;
114 row.Set_pkgname(pkgName);
116 WRT_DB_UPDATE(update, wrt::WidgetInfo, &WrtDatabase::interface())
118 Equals<wrt::WidgetInfo::app_id>(getHandle()));
122 transaction.Commit();
124 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
127 void WidgetDAO::registerWidget(
128 const DbWidgetHandle& widgetHandle,
129 const WidgetRegisterInfo &widgetRegInfo,
130 const IWacSecurity &wacSecurity)
132 LogDebug("Registering widget");
133 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
135 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
137 //Register into WidgetInfo has to be first
138 //as all other tables depend upon that
139 registerWidgetInfo(widgetHandle, widgetRegInfo, wacSecurity);
141 registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
143 registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
145 registerWidgetIcons(widgetHandle, widgetRegInfo);
147 registerWidgetStartFile(widgetHandle, widgetRegInfo);
149 PropertyDAO::RegisterProperties(widgetHandle, widgetRegInfo);
151 registerWidgetFeatures(widgetHandle, widgetRegInfo);
153 registerWidgetWindowModes(widgetHandle, widgetRegInfo);
155 registerWidgetWarpInfo(widgetHandle, widgetRegInfo);
157 registerWidgetCertificates(widgetHandle, wacSecurity);
159 CertificateChainList list;
160 wacSecurity.getCertificateChainList(list);
161 registerLaunchCertificates(widgetHandle,list);
163 registerWidgetSettings(widgetHandle, widgetRegInfo);
165 registerAppService(widgetHandle, widgetRegInfo);
167 registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
169 transaction.Commit();
171 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
174 #define DO_INSERT(row, table) \
176 WRT_DB_INSERT(insert, table, &WrtDatabase::interface()) \
177 insert->Values(row); \
181 void WidgetDAO::registerWidgetExtendedInfo(DbWidgetHandle widgetHandle,
182 const WidgetRegisterInfo ®Info)
184 //Try and transaction not needed
185 using namespace DPL::DB::ORM;
186 using namespace DPL::DB::ORM::wrt;
189 WidgetExtendedInfo::Row row;
190 row.Set_app_id(widgetHandle);
191 // row.Set_share_href (DPL::FromUTF8String(regInfo.shareHref));
192 row.Set_signature_type(regInfo.signatureType);
193 row.Set_factory_widget(regInfo.isFactoryWidget);
194 row.Set_test_widget(regInfo.isTestWidget);
195 row.Set_install_time(regInfo.installedTime);
196 row.Set_splash_img_src(regInfo.configInfo.splashImgSrc);
199 DO_INSERT(row, WidgetExtendedInfo)
202 void WidgetDAO::registerWidgetInfo(
203 const DbWidgetHandle& widgetHandle,
204 const WidgetRegisterInfo ®Info,
205 const IWacSecurity &wacSecurity)
207 using namespace DPL::DB::ORM;
208 using namespace DPL::DB::ORM::wrt;
209 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
211 // TODO in wrt_db all Columns in WidgetInfo have DEFAULT VALUE set.
212 // Because of that, "Optional" is not used there
215 row.Set_app_id(widgetHandle);
216 row.Set_widget_type(regInfo.type.appType);
217 row.Set_widget_id(widgetConfigurationInfo.widget_id);
218 row.Set_defaultlocale(widgetConfigurationInfo.defaultlocale);
219 row.Set_widget_version(widgetConfigurationInfo.version);
220 row.Set_widget_width(widgetConfigurationInfo.width);
221 row.Set_widget_height(widgetConfigurationInfo.height);
222 row.Set_author_name(widgetConfigurationInfo.authorName);
223 row.Set_author_email(widgetConfigurationInfo.authorEmail);
224 row.Set_author_href(widgetConfigurationInfo.authorHref);
225 row.Set_base_folder(DPL::FromUTF8String(regInfo.baseFolder));
226 row.Set_webkit_plugins_required(widgetConfigurationInfo.flashNeeded);
227 row.Set_recognized(wacSecurity.isRecognized());
228 row.Set_wac_signed(wacSecurity.isWacSigned());
229 row.Set_distributor_signed(wacSecurity.isDistributorSigned());
231 std::stringstream tmp;
232 tmp << regInfo.minVersion;
233 row.Set_min_version(DPL::FromUTF8String(tmp.str()));
235 row.Set_back_supported(widgetConfigurationInfo.backSupported);
236 row.Set_access_network(widgetConfigurationInfo.accessNetwork);
237 row.Set_pkgname(regInfo.pkgname);
238 row.Set_pkg_type(regInfo.pType.pkgType);
242 DO_INSERT(row, WidgetInfo);
244 Catch(DPL::DB::SqlConnection::Exception::Base)
246 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
247 "Failed to register widget info.");
251 void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
252 const WidgetRegisterInfo ®Info)
254 using namespace DPL::DB::ORM;
255 using namespace DPL::DB::ORM::wrt;
257 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
259 FOREACH(it, widgetConfigurationInfo.localizedDataSet)
261 const DPL::String& locale = it->first;
262 const ConfigParserData::LocalizedData& data = it->second;
264 LocalizedWidgetInfo::Row row;
265 row.Set_app_id(widgetHandle);
266 row.Set_widget_locale(locale);
267 row.Set_widget_name(data.name);
268 row.Set_widget_shortname(data.shortName);
269 row.Set_widget_description(data.description);
270 row.Set_widget_license(data.license);
271 row.Set_widget_license_file(data.licenseFile);
272 row.Set_widget_license_href(data.licenseHref);
274 DO_INSERT(row, LocalizedWidgetInfo)
278 void WidgetDAO::registerWidgetIcons(DbWidgetHandle widgetHandle,
279 const WidgetRegisterInfo ®Info)
281 using namespace DPL::DB::ORM;
282 using namespace DPL::DB::ORM::wrt;
285 FOREACH(i, regInfo.localizationData.icons)
287 wrt::WidgetIcon::icon_id::ColumnType icon_id;
289 wrt::WidgetIcon::Row row;
290 row.Set_app_id(widgetHandle);
291 row.Set_icon_src(i->src);
292 row.Set_icon_width(i->width);
293 row.Set_icon_height(i->height);
295 WRT_DB_INSERT(insert, wrt::WidgetIcon, &WrtDatabase::interface())
297 icon_id = insert->Execute();
300 FOREACH(j, i->availableLocales)
302 WidgetLocalizedIcon::Row row;
303 row.Set_app_id(widgetHandle);
304 row.Set_icon_id(icon_id);
305 row.Set_widget_locale(*j);
306 WRT_DB_SELECT(select, WidgetLocalizedIcon, &WrtDatabase::interface())
307 select->Where(And(Equals<WidgetLocalizedIcon::app_id>(widgetHandle),
308 Equals<WidgetLocalizedIcon::widget_locale>(*j)));
309 WidgetLocalizedIcon::Select::RowList rows = select->GetRowList();
311 bool flag = !rows.empty();
315 // already default icon value of same locale exists
316 WRT_DB_UPDATE(update, WidgetLocalizedIcon, &WrtDatabase::interface())
317 update->Where(And(Equals<WidgetLocalizedIcon::app_id>(widgetHandle),
318 Equals<WidgetLocalizedIcon::widget_locale>(*j)));
322 // any icon value of same locale doesn't exist
323 DO_INSERT(row, WidgetLocalizedIcon)
329 void WidgetDAO::registerWidgetStartFile(DbWidgetHandle widgetHandle,
330 const WidgetRegisterInfo ®Info)
332 using namespace DPL::DB::ORM;
333 using namespace DPL::DB::ORM::wrt;
336 FOREACH(i, regInfo.localizationData.startFiles)
338 WidgetStartFile::start_file_id::ColumnType startFileID;
340 WidgetStartFile::Row row;
341 row.Set_app_id(widgetHandle);
342 row.Set_src(i->path);
344 WRT_DB_INSERT(insert, WidgetStartFile, &WrtDatabase::interface())
346 startFileID = insert->Execute();
349 FOREACH(j, i->propertiesForLocales)
351 WidgetLocalizedStartFile::Row row;
352 row.Set_app_id(widgetHandle);
353 row.Set_start_file_id(startFileID);
354 row.Set_widget_locale(j->first);
355 row.Set_type(j->second.type);
356 row.Set_encoding(j->second.encoding);
358 DO_INSERT(row, WidgetLocalizedStartFile)
363 void WidgetDAO::registerWidgetFeatures(DbWidgetHandle widgetHandle,
364 const WidgetRegisterInfo ®Info)
366 using namespace DPL::DB::ORM;
367 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
370 FOREACH(pWidgetFeature, widgetConfigurationInfo.featuresList)
372 wrt::WidgetFeature::Row widgetFeature;
373 widgetFeature.Set_app_id(widgetHandle);
374 widgetFeature.Set_name(pWidgetFeature->name);
375 widgetFeature.Set_required(pWidgetFeature->required);
376 widgetFeature.Set_rejected(false);
378 wrt::WidgetFeature::widget_feature_id::ColumnType widgetFeatureID;
380 WRT_DB_INSERT(insert, wrt::WidgetFeature, &WrtDatabase::interface())
381 insert->Values(widgetFeature);
382 widgetFeatureID = insert->Execute();
385 // Insert into table FeatureParam
386 wrt::FeatureParam::Row featureParam;
387 featureParam.Set_widget_feature_id(widgetFeatureID);
389 ConfigParserData::ParamsList::const_iterator iter;
391 FOREACH(iter, pWidgetFeature->paramsList)
393 featureParam.Set_name(iter->name);
394 featureParam.Set_value(iter->value);
396 DO_INSERT(featureParam, wrt::FeatureParam)
401 void WidgetDAO::updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature){
402 // This function could be merged with registerWidgetFeature but it requires desing change:
403 // 1. Check "ace step" in installer must be done before "update database step"
405 // ConfigurationParserData shouldn't be called "ParserData" any more.
406 using namespace DPL::DB::ORM;
408 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
409 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
410 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
411 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
413 auto row = select->GetSingleRow();
414 row.Set_rejected(widgetFeature.rejected);
416 WRT_DB_UPDATE(update, wrt::WidgetFeature, &WrtDatabase::interface())
417 update->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
418 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
421 transaction.Commit();
424 void WidgetDAO::registerWidgetWindowModes(DbWidgetHandle widgetHandle,
425 const WidgetRegisterInfo ®Info)
427 using namespace DPL::DB::ORM;
428 using namespace DPL::DB::ORM::wrt;
429 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
432 FOREACH(i, widgetConfigurationInfo.windowModes)
434 wrt::WidgetWindowModes::Row windowMode;
435 windowMode.Set_app_id(widgetHandle);
436 windowMode.Set_window_mode(*i);
438 DO_INSERT(windowMode, wrt::WidgetWindowModes)
442 void WidgetDAO::registerWidgetWarpInfo(DbWidgetHandle widgetHandle,
443 const WidgetRegisterInfo ®Info)
445 using namespace DPL::DB::ORM;
446 using namespace DPL::DB::ORM::wrt;
447 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
450 FOREACH(AccIt, widgetConfigurationInfo.accessInfoSet)
452 WidgetWARPInfo::Row row;
453 row.Set_app_id(widgetHandle);
454 row.Set_iri(AccIt->m_strIRI);
455 row.Set_subdomain_access(static_cast <int>(
456 AccIt->m_bSubDomainAccess));
458 DO_INSERT(row, WidgetWARPInfo)
462 void WidgetDAO::registerWidgetCertificates(DbWidgetHandle widgetHandle,
463 const IWacSecurity &wacSecurity)
465 using namespace DPL::DB::ORM;
466 using namespace DPL::DB::ORM::wrt;
469 FOREACH(it, wacSecurity.getCertificateList())
471 WidgetCertificateFingerprint::Row row;
472 row.Set_app_id(widgetHandle);
473 row.Set_owner(it->owner);
474 row.Set_chainid(it->chainId);
475 row.Set_type(it->type);
476 row.Set_md5_fingerprint(DPL::FromUTF8String(it->strMD5Fingerprint));
477 row.Set_sha1_fingerprint(DPL::FromUTF8String(it->strSHA1Fingerprint));
478 row.Set_common_name(it->strCommonName);
480 DO_INSERT(row, WidgetCertificateFingerprint)
484 void WidgetDAO::registerLaunchCertificates(DbWidgetHandle widgetHandle,
485 const CertificateChainList &certificateChainList)
487 using namespace DPL::DB::ORM;
488 using namespace DPL::DB::ORM::wrt;
489 FOREACH(certChain, certificateChainList)
491 WidgetCertificate::Row row;
492 row.Set_app_id(widgetHandle);
493 row.Set_encoded_chain(DPL::FromASCIIString(*certChain));
495 DO_INSERT(row, WidgetCertificate);
499 void WidgetDAO::registerWidgetSettings(DbWidgetHandle widgetHandle,
500 const WidgetRegisterInfo ®Info)
502 using namespace DPL::DB::ORM;
503 using namespace DPL::DB::ORM::wrt;
505 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
507 FOREACH(pWidgetSetting, widgetConfigurationInfo.settingsList)
509 SettginsList::Row row;
510 row.Set_appId(widgetHandle);
511 row.Set_settingName(pWidgetSetting->m_name);
512 row.Set_settingValue(pWidgetSetting->m_value);
514 DO_INSERT(row, SettginsList)
518 void WidgetDAO::registerAppService(DbWidgetHandle widgetHandle,
519 const WidgetRegisterInfo ®Info)
521 using namespace DPL::DB::ORM;
522 using namespace DPL::DB::ORM::wrt;
523 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
525 FOREACH(ASIt, widgetConfigurationInfo.appServiceList)
527 ApplicationServiceInfo::Row row;
528 row.Set_app_id(widgetHandle);
529 row.Set_src(ASIt->m_src);
530 row.Set_operation(ASIt->m_operation);
531 row.Set_scheme(ASIt->m_scheme);
532 row.Set_mime(ASIt->m_mime);
534 DO_INSERT(row, ApplicationServiceInfo)
538 void WidgetDAO::registerEncryptedResouceInfo(DbWidgetHandle widgetHandle,
539 const WidgetRegisterInfo ®Info)
541 using namespace DPL::DB::ORM;
542 using namespace DPL::DB::ORM::wrt;
544 FOREACH(it, regInfo.encryptedFiles)
546 EncryptedResourceList::Row row;
547 row.Set_app_id(widgetHandle);
548 row.Set_resource(it->fileName);
549 row.Set_size(it->fileSize);
551 DO_INSERT(row, EncryptedResourceList)
557 void WidgetDAO::unregisterWidget(DbWidgetHandle widgetHandle)
559 LogDebug("Unregistering widget from DB. Handle: " << widgetHandle);
560 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
562 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
563 using namespace DPL::DB::ORM;
564 using namespace DPL::DB::ORM::wrt;
566 CHECK_WIDGET_EXISTENCE(transaction, widgetHandle)
568 // Delete from table Widget Info
570 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
571 del->Where(Equals<WidgetInfo::app_id>(widgetHandle));
575 // Deleting in other tables is done via "delete cascade" in SQL
577 transaction.Commit();
579 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
582 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
583 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END
584 #undef CHECK_WIDGET_EXISTENCE