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 WidgetDAO::WidgetDAO(DPL::OptionalString widgetGUID) :
55 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(widgetGUID))
59 WidgetDAO::WidgetDAO(DPL::String tzAppId) :
60 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(tzAppId))
64 WidgetDAO::WidgetDAO(DbWidgetHandle handle) :
65 WidgetDAOReadOnly(handle)
69 WidgetDAO::~WidgetDAO()
73 void WidgetDAO::removeProperty(
74 const PropertyDAOReadOnly::WidgetPropertyKey &key)
77 PropertyDAO::RemoveProperty(m_widgetHandle, key);
79 Catch(PropertyDAOReadOnly::Exception::ReadOnlyProperty){
80 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
81 "Failure during removing property");
85 void WidgetDAO::setProperty(
86 const PropertyDAOReadOnly::WidgetPropertyKey &key,
87 const PropertyDAOReadOnly::WidgetPropertyValue &value,
91 PropertyDAO::SetProperty(m_widgetHandle, key, value, readOnly);
93 Catch(PropertyDAOReadOnly::Exception::ReadOnlyProperty){
94 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
95 "Failure during setting/updating property");
99 void WidgetDAO::setTizenAppId(const DPL::OptionalString& tzAppId)
101 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
103 using namespace DPL::DB::ORM;
104 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
106 if (!isWidgetInstalled(getHandle())) {
107 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
108 "Cannot find widget. Handle: " << getHandle());
111 wrt::WidgetInfo::Row row;
112 row.Set_tizen_appid(*tzAppId);
114 WRT_DB_UPDATE(update, wrt::WidgetInfo, &WrtDatabase::interface())
116 Equals<wrt::WidgetInfo::app_id>(getHandle()));
120 transaction.Commit();
122 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
125 void WidgetDAO::setSecurityPopupUsage(const SettingsType value)
127 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
129 using namespace DPL::DB::ORM;
130 using namespace DPL::DB::ORM::wrt;
132 ScopedTransaction transaction(&WrtDatabase::interface());
133 if (!isWidgetInstalled(getHandle())) {
134 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
135 "Cannot find widget. Handle: " << getHandle());
138 WidgetSecuritySettings::Row row;
139 row.Set_security_popup_usage(value);
141 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
142 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
146 transaction.Commit();
148 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set security popup usage")
151 void WidgetDAO::setGeolocationUsage(const SettingsType value)
153 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
155 using namespace DPL::DB::ORM;
156 using namespace DPL::DB::ORM::wrt;
158 ScopedTransaction transaction(&WrtDatabase::interface());
159 if (!isWidgetInstalled(getHandle())) {
160 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
161 "Cannot find widget. Handle: " << getHandle());
164 WidgetSecuritySettings::Row row;
165 row.Set_geolocation_usage(value);
167 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
168 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
172 transaction.Commit();
174 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set geolocation usage")
177 void WidgetDAO::setWebNotificationUsage(const SettingsType value)
179 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
181 using namespace DPL::DB::ORM;
182 using namespace DPL::DB::ORM::wrt;
184 ScopedTransaction transaction(&WrtDatabase::interface());
185 if (!isWidgetInstalled(getHandle())) {
186 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
187 "Cannot find widget. Handle: " << getHandle());
190 WidgetSecuritySettings::Row row;
191 row.Set_web_notification_usage(value);
193 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
194 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
198 transaction.Commit();
200 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web notification usage")
203 void WidgetDAO::setWebDatabaseUsage(const SettingsType value)
205 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
207 using namespace DPL::DB::ORM;
208 using namespace DPL::DB::ORM::wrt;
210 ScopedTransaction transaction(&WrtDatabase::interface());
211 if (!isWidgetInstalled(getHandle())) {
212 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
213 "Cannot find widget. Handle: " << getHandle());
216 WidgetSecuritySettings::Row row;
217 row.Set_web_database_usage(value);
219 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
220 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
224 transaction.Commit();
226 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web database usage")
229 void WidgetDAO::setFileSystemUsage(const SettingsType value)
231 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
233 using namespace DPL::DB::ORM;
234 using namespace DPL::DB::ORM::wrt;
236 ScopedTransaction transaction(&WrtDatabase::interface());
237 if (!isWidgetInstalled(getHandle())) {
238 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
239 "Cannot find widget. Handle: " << getHandle());
242 WidgetSecuritySettings::Row row;
243 row.Set_file_system_usage(value);
245 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
246 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
250 transaction.Commit();
252 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set filesystem usage")
255 void WidgetDAO::registerWidget(
256 const TizenAppId & tzAppId,
257 const WidgetRegisterInfo &widgetRegInfo,
258 const IWacSecurity &wacSecurity)
260 LogDebug("Registering widget");
261 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
263 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
264 registerWidgetInternal(tzAppId, widgetRegInfo, wacSecurity);
265 transaction.Commit();
267 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
270 void WidgetDAO::registerWidget(
271 WrtDB::DbWidgetHandle handle,
272 const WidgetRegisterInfo &widgetRegInfo,
273 const IWacSecurity &wacSecurity)
275 LogDebug("Registering widget");
276 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
278 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
279 registerWidgetInternal(generateTizenId(), widgetRegInfo, wacSecurity, handle);
280 transaction.Commit();
282 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
285 DbWidgetHandle WidgetDAO::registerWidget(
286 const WidgetRegisterInfo &pWidgetRegisterInfo,
287 const IWacSecurity &wacSecurity)
289 //make it more precise due to very fast tests
291 gettimeofday(&tv, NULL);
292 srand(time(NULL) + tv.tv_usec);
293 DbWidgetHandle widgetHandle;
295 widgetHandle = rand();
296 } while (isWidgetInstalled(widgetHandle));
298 registerWidget(widgetHandle, pWidgetRegisterInfo, wacSecurity);
302 TizenAppId WidgetDAO::registerWidgetGeneratePkgId(
303 const WidgetRegisterInfo &pWidgetRegisterInfo,
304 const IWacSecurity &wacSecurity)
306 TizenAppId tzAppId = generatePkgId();
307 registerWidget(tzAppId, pWidgetRegisterInfo, wacSecurity);
311 void WidgetDAO::registerWidgetInternal(
312 const TizenAppId & tzAppId,
313 const WidgetRegisterInfo &widgetRegInfo,
314 const IWacSecurity &wacSecurity,
315 const DPL::Optional<DbWidgetHandle> handle)
317 //Register into WidgetInfo has to be first
318 //as all other tables depend upon that
319 DbWidgetHandle widgetHandle = registerWidgetInfo(tzAppId, widgetRegInfo, wacSecurity, handle);
321 registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
323 registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
325 registerWidgetIcons(widgetHandle, widgetRegInfo);
327 registerWidgetStartFile(widgetHandle, widgetRegInfo);
329 PropertyDAO::RegisterProperties(widgetHandle, widgetRegInfo);
331 registerWidgetFeatures(widgetHandle, widgetRegInfo);
333 registerWidgetPrivilege(widgetHandle, widgetRegInfo);
335 registerWidgetWindowModes(widgetHandle, widgetRegInfo);
337 registerWidgetWarpInfo(widgetHandle, widgetRegInfo);
339 registerWidgetCertificates(widgetHandle, wacSecurity);
341 CertificateChainList list;
342 wacSecurity.getCertificateChainList(list, SIGNATURE_DISTRIBUTOR);
343 registerCertificatesChains(widgetHandle, SIGNATURE_DISTRIBUTOR, list);
346 wacSecurity.getCertificateChainList(list, SIGNATURE_AUTHOR);
347 registerCertificatesChains(widgetHandle, SIGNATURE_AUTHOR, list);
349 registerWidgetSettings(widgetHandle, widgetRegInfo);
351 registerAppService(widgetHandle, widgetRegInfo);
353 registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
355 registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
357 registerWidgetSecuritySettings(widgetHandle);
360 void WidgetDAO::registerOrUpdateWidget(
361 const TizenAppId & widgetName,
362 const WidgetRegisterInfo &widgetRegInfo,
363 const IWacSecurity &wacSecurity)
365 LogDebug("Reregistering widget");
366 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
368 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
370 unregisterWidgetInternal(widgetName);
371 registerWidgetInternal(widgetName, widgetRegInfo, wacSecurity);
372 transaction.Commit();
374 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
377 #define DO_INSERT(row, table) \
379 WRT_DB_INSERT(insert, table, &WrtDatabase::interface()) \
380 insert->Values(row); \
384 void WidgetDAO::registerWidgetExtendedInfo(DbWidgetHandle widgetHandle,
385 const WidgetRegisterInfo ®Info)
387 //Try and transaction not needed
388 using namespace DPL::DB::ORM;
389 using namespace DPL::DB::ORM::wrt;
392 WidgetExtendedInfo::Row row;
393 row.Set_app_id(widgetHandle);
394 // row.Set_share_href (DPL::FromUTF8String(regInfo.shareHref));
395 row.Set_signature_type(regInfo.signatureType);
396 row.Set_test_widget(regInfo.isTestWidget);
397 row.Set_install_time(regInfo.installedTime);
398 row.Set_splash_img_src(regInfo.configInfo.splashImgSrc);
399 row.Set_background_page(regInfo.configInfo.backgroundPage);
400 row.Set_installed_path(regInfo.widgetInstalledPath);
402 DO_INSERT(row, WidgetExtendedInfo)
405 DbWidgetHandle WidgetDAO::registerWidgetInfo(
406 const TizenAppId & tzAppId,
407 const WidgetRegisterInfo ®Info,
408 const IWacSecurity &wacSecurity,
409 const DPL::Optional<DbWidgetHandle> handle)
411 using namespace DPL::DB::ORM;
412 using namespace DPL::DB::ORM::wrt;
413 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
415 // TODO in wrt_db all Columns in WidgetInfo have DEFAULT VALUE set.
416 // Because of that, "Optional" is not used there
421 row.Set_app_id(*handle);
424 if (regInfo.webAppType == APP_TYPE_UNKNOWN && regInfo.type !=
426 // TODO : regInfo.type is temporary code for security.
427 // This code will be removed.
428 row.Set_widget_type(regInfo.type.appType);
430 row.Set_widget_type(regInfo.webAppType.appType);
432 row.Set_widget_id(widgetConfigurationInfo.widget_id);
433 row.Set_defaultlocale(widgetConfigurationInfo.defaultlocale);
434 row.Set_widget_version(widgetConfigurationInfo.version);
435 row.Set_widget_width(widgetConfigurationInfo.width);
436 row.Set_widget_height(widgetConfigurationInfo.height);
437 row.Set_author_name(widgetConfigurationInfo.authorName);
438 row.Set_author_email(widgetConfigurationInfo.authorEmail);
439 row.Set_author_href(widgetConfigurationInfo.authorHref);
440 row.Set_base_folder(DPL::FromUTF8String(regInfo.baseFolder));
441 row.Set_webkit_plugins_required(widgetConfigurationInfo.flashNeeded);
442 row.Set_recognized(wacSecurity.isRecognized());
443 row.Set_wac_signed(wacSecurity.isWacSigned());
444 row.Set_distributor_signed(wacSecurity.isDistributorSigned());
445 row.Set_tizen_appid(tzAppId);
446 row.Set_tizen_pkgid(regInfo.tzPkgid);
448 std::stringstream tmp;
449 tmp << regInfo.minVersion;
450 row.Set_min_version(DPL::FromUTF8String(tmp.str()));
452 row.Set_back_supported(widgetConfigurationInfo.backSupported);
453 row.Set_access_network(widgetConfigurationInfo.accessNetwork);
454 row.Set_pkg_type(regInfo.packagingType.pkgType);
458 DO_INSERT(row, WidgetInfo);
460 Catch(DPL::DB::SqlConnection::Exception::Base)
462 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
463 "Failed to register widget info.");
468 //get autoincremented value of widgetHandle
469 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
470 select->Where(Equals<WidgetInfo::tizen_appid>(tzAppId));
471 return select->GetSingleValue<WidgetInfo::app_id>();
479 void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
480 const WidgetRegisterInfo ®Info)
482 using namespace DPL::DB::ORM;
483 using namespace DPL::DB::ORM::wrt;
485 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
487 FOREACH(it, widgetConfigurationInfo.localizedDataSet)
489 const DPL::String& locale = it->first;
490 const ConfigParserData::LocalizedData& data = it->second;
492 LocalizedWidgetInfo::Row row;
493 row.Set_app_id(widgetHandle);
494 row.Set_widget_locale(locale);
495 row.Set_widget_name(data.name);
496 row.Set_widget_shortname(data.shortName);
497 row.Set_widget_description(data.description);
498 row.Set_widget_license(data.license);
499 row.Set_widget_license_file(data.licenseFile);
500 row.Set_widget_license_href(data.licenseHref);
502 DO_INSERT(row, LocalizedWidgetInfo)
506 void WidgetDAO::registerWidgetIcons(DbWidgetHandle widgetHandle,
507 const WidgetRegisterInfo ®Info)
509 using namespace DPL::DB::ORM;
510 using namespace DPL::DB::ORM::wrt;
513 FOREACH(i, regInfo.localizationData.icons)
515 wrt::WidgetIcon::icon_id::ColumnType icon_id;
517 wrt::WidgetIcon::Row row;
518 row.Set_app_id(widgetHandle);
519 row.Set_icon_src(i->src);
520 row.Set_icon_width(i->width);
521 row.Set_icon_height(i->height);
523 WRT_DB_INSERT(insert, wrt::WidgetIcon, &WrtDatabase::interface())
525 icon_id = insert->Execute();
528 FOREACH(j, i->availableLocales)
530 WidgetLocalizedIcon::Row row;
531 row.Set_app_id(widgetHandle);
532 row.Set_icon_id(icon_id);
533 row.Set_widget_locale(*j);
534 DO_INSERT(row, WidgetLocalizedIcon)
539 void WidgetDAO::registerWidgetStartFile(DbWidgetHandle widgetHandle,
540 const WidgetRegisterInfo ®Info)
542 using namespace DPL::DB::ORM;
543 using namespace DPL::DB::ORM::wrt;
546 FOREACH(i, regInfo.localizationData.startFiles)
548 WidgetStartFile::start_file_id::ColumnType startFileID;
550 WidgetStartFile::Row row;
551 row.Set_app_id(widgetHandle);
552 row.Set_src(i->path);
554 WRT_DB_INSERT(insert, WidgetStartFile, &WrtDatabase::interface())
556 startFileID = insert->Execute();
559 FOREACH(j, i->propertiesForLocales)
561 WidgetLocalizedStartFile::Row row;
562 row.Set_app_id(widgetHandle);
563 row.Set_start_file_id(startFileID);
564 row.Set_widget_locale(j->first);
565 row.Set_type(j->second.type);
566 row.Set_encoding(j->second.encoding);
568 DO_INSERT(row, WidgetLocalizedStartFile)
573 void WidgetDAO::registerWidgetFeatures(DbWidgetHandle widgetHandle,
574 const WidgetRegisterInfo ®Info)
576 using namespace DPL::DB::ORM;
577 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
580 FOREACH(pWidgetFeature, widgetConfigurationInfo.featuresList)
582 wrt::WidgetFeature::Row widgetFeature;
583 widgetFeature.Set_app_id(widgetHandle);
584 widgetFeature.Set_name(pWidgetFeature->name);
585 widgetFeature.Set_required(pWidgetFeature->required);
586 widgetFeature.Set_rejected(false);
588 wrt::WidgetFeature::widget_feature_id::ColumnType widgetFeatureID;
590 WRT_DB_INSERT(insert, wrt::WidgetFeature, &WrtDatabase::interface())
591 insert->Values(widgetFeature);
592 widgetFeatureID = insert->Execute();
595 // Insert into table FeatureParam
596 wrt::FeatureParam::Row featureParam;
597 featureParam.Set_widget_feature_id(widgetFeatureID);
599 FOREACH(iter, pWidgetFeature->paramsList)
601 featureParam.Set_name(iter->name);
602 featureParam.Set_value(iter->value);
604 DO_INSERT(featureParam, wrt::FeatureParam)
609 void WidgetDAO::registerWidgetPrivilege(DbWidgetHandle widgetHandle,
610 const WidgetRegisterInfo ®Info)
612 using namespace DPL::DB::ORM;
613 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
615 FOREACH(it, widgetConfigurationInfo.privilegeList)
617 wrt::WidgetPrivilege::Row widgetPrivilege;
618 widgetPrivilege.Set_app_id(widgetHandle);
619 widgetPrivilege.Set_name(it->name);
621 DO_INSERT(widgetPrivilege, wrt::WidgetPrivilege)
625 void WidgetDAO::updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature){
626 // This function could be merged with registerWidgetFeature but it requires desing change:
627 // 1. Check "ace step" in installer must be done before "update database step"
629 // ConfigurationParserData shouldn't be called "ParserData" any more.
630 using namespace DPL::DB::ORM;
632 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
633 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
634 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
635 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
637 auto row = select->GetSingleRow();
638 row.Set_rejected(widgetFeature.rejected);
640 WRT_DB_UPDATE(update, wrt::WidgetFeature, &WrtDatabase::interface())
641 update->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
642 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
645 transaction.Commit();
648 void WidgetDAO::registerWidgetWindowModes(DbWidgetHandle widgetHandle,
649 const WidgetRegisterInfo ®Info)
651 using namespace DPL::DB::ORM;
652 using namespace DPL::DB::ORM::wrt;
653 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
656 FOREACH(i, widgetConfigurationInfo.windowModes)
658 wrt::WidgetWindowModes::Row windowMode;
659 windowMode.Set_app_id(widgetHandle);
660 windowMode.Set_window_mode(*i);
662 DO_INSERT(windowMode, wrt::WidgetWindowModes)
666 void WidgetDAO::registerWidgetWarpInfo(DbWidgetHandle widgetHandle,
667 const WidgetRegisterInfo ®Info)
669 using namespace DPL::DB::ORM;
670 using namespace DPL::DB::ORM::wrt;
671 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
674 FOREACH(AccIt, widgetConfigurationInfo.accessInfoSet)
676 WidgetWARPInfo::Row row;
677 row.Set_app_id(widgetHandle);
678 row.Set_iri(AccIt->m_strIRI);
679 row.Set_subdomain_access(static_cast <int>(
680 AccIt->m_bSubDomainAccess));
682 DO_INSERT(row, WidgetWARPInfo)
686 void WidgetDAO::registerWidgetCertificates(DbWidgetHandle widgetHandle,
687 const IWacSecurity &wacSecurity)
689 using namespace DPL::DB::ORM;
690 using namespace DPL::DB::ORM::wrt;
693 FOREACH(it, wacSecurity.getCertificateList())
695 WidgetCertificateFingerprint::Row row;
696 row.Set_app_id(widgetHandle);
697 row.Set_owner(it->owner);
698 row.Set_chainid(it->chainId);
699 row.Set_type(it->type);
700 row.Set_md5_fingerprint(DPL::FromUTF8String(it->strMD5Fingerprint));
701 row.Set_sha1_fingerprint(DPL::FromUTF8String(it->strSHA1Fingerprint));
702 row.Set_common_name(it->strCommonName);
704 DO_INSERT(row, WidgetCertificateFingerprint)
708 void WidgetDAO::registerCertificatesChains(DbWidgetHandle widgetHandle,
709 CertificateSource certificateSource,
710 const CertificateChainList &certificateChainList)
712 using namespace DPL::DB::ORM;
713 using namespace DPL::DB::ORM::wrt;
714 FOREACH(certChain, certificateChainList)
716 WidgetCertificate::Row row;
717 row.Set_app_id(widgetHandle);
718 row.Set_cert_source(certificateSource);
719 row.Set_encoded_chain(DPL::FromASCIIString(*certChain));
721 DO_INSERT(row, WidgetCertificate);
725 void WidgetDAO::registerWidgetSettings(DbWidgetHandle widgetHandle,
726 const WidgetRegisterInfo ®Info)
728 using namespace DPL::DB::ORM;
729 using namespace DPL::DB::ORM::wrt;
731 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
733 FOREACH(pWidgetSetting, widgetConfigurationInfo.settingsList)
735 SettingsList::Row row;
736 row.Set_appId(widgetHandle);
737 row.Set_settingName(pWidgetSetting->m_name);
738 row.Set_settingValue(pWidgetSetting->m_value);
740 DO_INSERT(row, SettingsList)
744 void WidgetDAO::registerAppService(DbWidgetHandle widgetHandle,
745 const WidgetRegisterInfo ®Info)
747 using namespace DPL::DB::ORM;
748 using namespace DPL::DB::ORM::wrt;
749 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
751 FOREACH(ASIt, widgetConfigurationInfo.appServiceList)
753 ApplicationServiceInfo::Row row;
754 row.Set_app_id(widgetHandle);
755 row.Set_src(ASIt->m_src);
756 row.Set_operation(ASIt->m_operation);
757 row.Set_scheme(ASIt->m_scheme);
758 row.Set_mime(ASIt->m_mime);
760 DO_INSERT(row, ApplicationServiceInfo)
764 void WidgetDAO::registerEncryptedResouceInfo(DbWidgetHandle widgetHandle,
765 const WidgetRegisterInfo ®Info)
767 using namespace DPL::DB::ORM;
768 using namespace DPL::DB::ORM::wrt;
770 FOREACH(it, regInfo.encryptedFiles)
772 EncryptedResourceList::Row row;
773 row.Set_app_id(widgetHandle);
774 row.Set_resource(it->fileName);
775 row.Set_size(it->fileSize);
777 DO_INSERT(row, EncryptedResourceList)
781 void WidgetDAO::registerExternalLocations(DbWidgetHandle widgetHandle,
782 const ExternalLocationList & externals)
784 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
786 using namespace DPL::DB::ORM;
787 using namespace DPL::DB::ORM::wrt;
788 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
789 LogDebug("Inserting external files for widgetHandle: " << widgetHandle);
790 FOREACH(it, externals)
792 WidgetExternalLocations::Row row;
793 row.Set_app_id(widgetHandle);
794 row.Set_path(DPL::FromUTF8String(*it));
796 DO_INSERT(row, WidgetExternalLocations)
798 transaction.Commit();
800 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
803 void WidgetDAO::registerWidgetSecuritySettings(DbWidgetHandle widgetHandle)
805 using namespace DPL::DB::ORM;
806 using namespace DPL::DB::ORM::wrt;
807 WidgetSecuritySettings::Row row;
808 row.Set_app_id(widgetHandle);
809 row.Set_security_popup_usage(SETTINGS_TYPE_ON);
810 row.Set_geolocation_usage(SETTINGS_TYPE_ON);
811 row.Set_web_notification_usage(SETTINGS_TYPE_ON);
812 row.Set_web_database_usage(SETTINGS_TYPE_ON);
813 row.Set_file_system_usage(SETTINGS_TYPE_ON);
815 DO_INSERT(row, WidgetSecuritySettings)
818 void WidgetDAO::unregisterAllExternalLocations()
820 using namespace DPL::DB::ORM;
821 using namespace DPL::DB::ORM::wrt;
822 LogDebug("Deleting external files for widgetHandle: " << m_widgetHandle);
823 WRT_DB_DELETE(del, WidgetExternalLocations, &WrtDatabase::interface());
824 del->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
828 void WidgetDAO::unregisterWidget(const TizenAppId & tzAppId)
830 LogDebug("Unregistering widget from DB. tzAppId: " << tzAppId);
831 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
833 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
834 unregisterWidgetInternal(tzAppId);
835 transaction.Commit();
837 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
840 void WidgetDAO::unregisterWidget(WrtDB::DbWidgetHandle handle)
842 LogDebug("Unregistering widget from DB. Handle: " << handle);
843 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
845 using namespace DPL::DB::ORM;
846 using namespace DPL::DB::ORM::wrt;
847 ScopedTransaction transaction(&WrtDatabase::interface());
849 // Delete from table Widget Info
850 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
851 del->Where(Equals<WidgetInfo::app_id>(handle));
854 transaction.Commit();
856 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
859 void WidgetDAO::unregisterWidgetInternal(
860 const TizenAppId & tzAppId)
862 using namespace DPL::DB::ORM;
863 using namespace DPL::DB::ORM::wrt;
865 DbWidgetHandle handle = getHandle(tzAppId);
867 // Delete from table Widget Info
868 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
869 del->Where(Equals<WidgetInfo::app_id>(handle));
872 // Deleting in other tables is done via "delete cascade" in SQL
877 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
878 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END