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 pkgName) :
60 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(pkgName))
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::setPkgName(const WidgetPkgName& pkgName)
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_pkgname(pkgName);
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 WidgetPkgName & widgetPkgname,
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(widgetPkgname, 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 WidgetPkgName WidgetDAO::registerWidgetGenerateTizenId(
303 const WidgetRegisterInfo &pWidgetRegisterInfo,
304 const IWacSecurity &wacSecurity)
306 WidgetPkgName widgetPkgName = generateTizenId();
307 registerWidget(widgetPkgName, pWidgetRegisterInfo, wacSecurity);
308 return widgetPkgName;
311 void WidgetDAO::registerWidgetInternal(
312 const WidgetPkgName & widgetName,
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(widgetName, 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 WidgetPkgName & 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 WidgetPkgName & widgetName,
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_pkgname(widgetName);
447 std::stringstream tmp;
448 tmp << regInfo.minVersion;
449 row.Set_min_version(DPL::FromUTF8String(tmp.str()));
451 row.Set_back_supported(widgetConfigurationInfo.backSupported);
452 row.Set_access_network(widgetConfigurationInfo.accessNetwork);
453 row.Set_pkg_type(regInfo.packagingType.pkgType);
457 DO_INSERT(row, WidgetInfo);
459 Catch(DPL::DB::SqlConnection::Exception::Base)
461 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
462 "Failed to register widget info.");
467 //get autoincremented value of widgetHandle
468 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
469 select->Where(Equals<WidgetInfo::pkgname>(widgetName));
470 return select->GetSingleValue<WidgetInfo::app_id>();
478 void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
479 const WidgetRegisterInfo ®Info)
481 using namespace DPL::DB::ORM;
482 using namespace DPL::DB::ORM::wrt;
484 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
486 FOREACH(it, widgetConfigurationInfo.localizedDataSet)
488 const DPL::String& locale = it->first;
489 const ConfigParserData::LocalizedData& data = it->second;
491 LocalizedWidgetInfo::Row row;
492 row.Set_app_id(widgetHandle);
493 row.Set_widget_locale(locale);
494 row.Set_widget_name(data.name);
495 row.Set_widget_shortname(data.shortName);
496 row.Set_widget_description(data.description);
497 row.Set_widget_license(data.license);
498 row.Set_widget_license_file(data.licenseFile);
499 row.Set_widget_license_href(data.licenseHref);
501 DO_INSERT(row, LocalizedWidgetInfo)
505 void WidgetDAO::registerWidgetIcons(DbWidgetHandle widgetHandle,
506 const WidgetRegisterInfo ®Info)
508 using namespace DPL::DB::ORM;
509 using namespace DPL::DB::ORM::wrt;
512 FOREACH(i, regInfo.localizationData.icons)
514 wrt::WidgetIcon::icon_id::ColumnType icon_id;
516 wrt::WidgetIcon::Row row;
517 row.Set_app_id(widgetHandle);
518 row.Set_icon_src(i->src);
519 row.Set_icon_width(i->width);
520 row.Set_icon_height(i->height);
522 WRT_DB_INSERT(insert, wrt::WidgetIcon, &WrtDatabase::interface())
524 icon_id = insert->Execute();
527 FOREACH(j, i->availableLocales)
529 WidgetLocalizedIcon::Row row;
530 row.Set_app_id(widgetHandle);
531 row.Set_icon_id(icon_id);
532 row.Set_widget_locale(*j);
533 DO_INSERT(row, WidgetLocalizedIcon)
538 void WidgetDAO::registerWidgetStartFile(DbWidgetHandle widgetHandle,
539 const WidgetRegisterInfo ®Info)
541 using namespace DPL::DB::ORM;
542 using namespace DPL::DB::ORM::wrt;
545 FOREACH(i, regInfo.localizationData.startFiles)
547 WidgetStartFile::start_file_id::ColumnType startFileID;
549 WidgetStartFile::Row row;
550 row.Set_app_id(widgetHandle);
551 row.Set_src(i->path);
553 WRT_DB_INSERT(insert, WidgetStartFile, &WrtDatabase::interface())
555 startFileID = insert->Execute();
558 FOREACH(j, i->propertiesForLocales)
560 WidgetLocalizedStartFile::Row row;
561 row.Set_app_id(widgetHandle);
562 row.Set_start_file_id(startFileID);
563 row.Set_widget_locale(j->first);
564 row.Set_type(j->second.type);
565 row.Set_encoding(j->second.encoding);
567 DO_INSERT(row, WidgetLocalizedStartFile)
572 void WidgetDAO::registerWidgetFeatures(DbWidgetHandle widgetHandle,
573 const WidgetRegisterInfo ®Info)
575 using namespace DPL::DB::ORM;
576 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
579 FOREACH(pWidgetFeature, widgetConfigurationInfo.featuresList)
581 wrt::WidgetFeature::Row widgetFeature;
582 widgetFeature.Set_app_id(widgetHandle);
583 widgetFeature.Set_name(pWidgetFeature->name);
584 widgetFeature.Set_required(pWidgetFeature->required);
585 widgetFeature.Set_rejected(false);
587 wrt::WidgetFeature::widget_feature_id::ColumnType widgetFeatureID;
589 WRT_DB_INSERT(insert, wrt::WidgetFeature, &WrtDatabase::interface())
590 insert->Values(widgetFeature);
591 widgetFeatureID = insert->Execute();
594 // Insert into table FeatureParam
595 wrt::FeatureParam::Row featureParam;
596 featureParam.Set_widget_feature_id(widgetFeatureID);
598 FOREACH(iter, pWidgetFeature->paramsList)
600 featureParam.Set_name(iter->name);
601 featureParam.Set_value(iter->value);
603 DO_INSERT(featureParam, wrt::FeatureParam)
608 void WidgetDAO::registerWidgetPrivilege(DbWidgetHandle widgetHandle,
609 const WidgetRegisterInfo ®Info)
611 using namespace DPL::DB::ORM;
612 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
614 FOREACH(it, widgetConfigurationInfo.privilegeList)
616 wrt::WidgetPrivilege::Row widgetPrivilege;
617 widgetPrivilege.Set_app_id(widgetHandle);
618 widgetPrivilege.Set_name(it->name);
620 DO_INSERT(widgetPrivilege, wrt::WidgetPrivilege)
624 void WidgetDAO::updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature){
625 // This function could be merged with registerWidgetFeature but it requires desing change:
626 // 1. Check "ace step" in installer must be done before "update database step"
628 // ConfigurationParserData shouldn't be called "ParserData" any more.
629 using namespace DPL::DB::ORM;
631 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
632 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
633 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
634 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
636 auto row = select->GetSingleRow();
637 row.Set_rejected(widgetFeature.rejected);
639 WRT_DB_UPDATE(update, wrt::WidgetFeature, &WrtDatabase::interface())
640 update->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
641 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
644 transaction.Commit();
647 void WidgetDAO::registerWidgetWindowModes(DbWidgetHandle widgetHandle,
648 const WidgetRegisterInfo ®Info)
650 using namespace DPL::DB::ORM;
651 using namespace DPL::DB::ORM::wrt;
652 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
655 FOREACH(i, widgetConfigurationInfo.windowModes)
657 wrt::WidgetWindowModes::Row windowMode;
658 windowMode.Set_app_id(widgetHandle);
659 windowMode.Set_window_mode(*i);
661 DO_INSERT(windowMode, wrt::WidgetWindowModes)
665 void WidgetDAO::registerWidgetWarpInfo(DbWidgetHandle widgetHandle,
666 const WidgetRegisterInfo ®Info)
668 using namespace DPL::DB::ORM;
669 using namespace DPL::DB::ORM::wrt;
670 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
673 FOREACH(AccIt, widgetConfigurationInfo.accessInfoSet)
675 WidgetWARPInfo::Row row;
676 row.Set_app_id(widgetHandle);
677 row.Set_iri(AccIt->m_strIRI);
678 row.Set_subdomain_access(static_cast <int>(
679 AccIt->m_bSubDomainAccess));
681 DO_INSERT(row, WidgetWARPInfo)
685 void WidgetDAO::registerWidgetCertificates(DbWidgetHandle widgetHandle,
686 const IWacSecurity &wacSecurity)
688 using namespace DPL::DB::ORM;
689 using namespace DPL::DB::ORM::wrt;
692 FOREACH(it, wacSecurity.getCertificateList())
694 WidgetCertificateFingerprint::Row row;
695 row.Set_app_id(widgetHandle);
696 row.Set_owner(it->owner);
697 row.Set_chainid(it->chainId);
698 row.Set_type(it->type);
699 row.Set_md5_fingerprint(DPL::FromUTF8String(it->strMD5Fingerprint));
700 row.Set_sha1_fingerprint(DPL::FromUTF8String(it->strSHA1Fingerprint));
701 row.Set_common_name(it->strCommonName);
703 DO_INSERT(row, WidgetCertificateFingerprint)
707 void WidgetDAO::registerCertificatesChains(DbWidgetHandle widgetHandle,
708 CertificateSource certificateSource,
709 const CertificateChainList &certificateChainList)
711 using namespace DPL::DB::ORM;
712 using namespace DPL::DB::ORM::wrt;
713 FOREACH(certChain, certificateChainList)
715 WidgetCertificate::Row row;
716 row.Set_app_id(widgetHandle);
717 row.Set_cert_source(certificateSource);
718 row.Set_encoded_chain(DPL::FromASCIIString(*certChain));
720 DO_INSERT(row, WidgetCertificate);
724 void WidgetDAO::registerWidgetSettings(DbWidgetHandle widgetHandle,
725 const WidgetRegisterInfo ®Info)
727 using namespace DPL::DB::ORM;
728 using namespace DPL::DB::ORM::wrt;
730 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
732 FOREACH(pWidgetSetting, widgetConfigurationInfo.settingsList)
734 SettingsList::Row row;
735 row.Set_appId(widgetHandle);
736 row.Set_settingName(pWidgetSetting->m_name);
737 row.Set_settingValue(pWidgetSetting->m_value);
739 DO_INSERT(row, SettingsList)
743 void WidgetDAO::registerAppService(DbWidgetHandle widgetHandle,
744 const WidgetRegisterInfo ®Info)
746 using namespace DPL::DB::ORM;
747 using namespace DPL::DB::ORM::wrt;
748 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
750 FOREACH(ASIt, widgetConfigurationInfo.appServiceList)
752 ApplicationServiceInfo::Row row;
753 row.Set_app_id(widgetHandle);
754 row.Set_src(ASIt->m_src);
755 row.Set_operation(ASIt->m_operation);
756 row.Set_scheme(ASIt->m_scheme);
757 row.Set_mime(ASIt->m_mime);
759 DO_INSERT(row, ApplicationServiceInfo)
763 void WidgetDAO::registerEncryptedResouceInfo(DbWidgetHandle widgetHandle,
764 const WidgetRegisterInfo ®Info)
766 using namespace DPL::DB::ORM;
767 using namespace DPL::DB::ORM::wrt;
769 FOREACH(it, regInfo.encryptedFiles)
771 EncryptedResourceList::Row row;
772 row.Set_app_id(widgetHandle);
773 row.Set_resource(it->fileName);
774 row.Set_size(it->fileSize);
776 DO_INSERT(row, EncryptedResourceList)
780 void WidgetDAO::registerExternalLocations(DbWidgetHandle widgetHandle,
781 const ExternalLocationList & externals)
783 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
785 using namespace DPL::DB::ORM;
786 using namespace DPL::DB::ORM::wrt;
787 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
788 LogDebug("Inserting external files for widgetHandle: " << widgetHandle);
789 FOREACH(it, externals)
791 WidgetExternalLocations::Row row;
792 row.Set_app_id(widgetHandle);
793 row.Set_path(DPL::FromUTF8String(*it));
795 DO_INSERT(row, WidgetExternalLocations)
797 transaction.Commit();
799 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
802 void WidgetDAO::registerWidgetSecuritySettings(DbWidgetHandle widgetHandle)
804 using namespace DPL::DB::ORM;
805 using namespace DPL::DB::ORM::wrt;
806 WidgetSecuritySettings::Row row;
807 row.Set_app_id(widgetHandle);
808 row.Set_security_popup_usage(SETTINGS_TYPE_ON);
809 row.Set_geolocation_usage(SETTINGS_TYPE_ON);
810 row.Set_web_notification_usage(SETTINGS_TYPE_ON);
811 row.Set_web_database_usage(SETTINGS_TYPE_ON);
812 row.Set_file_system_usage(SETTINGS_TYPE_ON);
814 DO_INSERT(row, WidgetSecuritySettings)
817 void WidgetDAO::unregisterAllExternalLocations()
819 using namespace DPL::DB::ORM;
820 using namespace DPL::DB::ORM::wrt;
821 LogDebug("Deleting external files for widgetHandle: " << m_widgetHandle);
822 WRT_DB_DELETE(del, WidgetExternalLocations, &WrtDatabase::interface());
823 del->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
827 void WidgetDAO::unregisterWidget(const WidgetPkgName & pkgName)
829 LogDebug("Unregistering widget from DB. PkgName: " << pkgName);
830 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
832 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
833 unregisterWidgetInternal(pkgName);
834 transaction.Commit();
836 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
839 void WidgetDAO::unregisterWidget(WrtDB::DbWidgetHandle handle)
841 LogDebug("Unregistering widget from DB. Handle: " << handle);
842 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
844 using namespace DPL::DB::ORM;
845 using namespace DPL::DB::ORM::wrt;
846 ScopedTransaction transaction(&WrtDatabase::interface());
848 // Delete from table Widget Info
849 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
850 del->Where(Equals<WidgetInfo::app_id>(handle));
853 transaction.Commit();
855 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
858 void WidgetDAO::unregisterWidgetInternal(
859 const WidgetPkgName & pkgName)
861 using namespace DPL::DB::ORM;
862 using namespace DPL::DB::ORM::wrt;
864 DbWidgetHandle handle = getHandle(pkgName);
866 // Delete from table Widget Info
867 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
868 del->Where(Equals<WidgetInfo::app_id>(handle));
871 // Deleting in other tables is done via "delete cascade" in SQL
876 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
877 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END