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 DPL::OptionalString& pkgName)
103 setPkgName_TEMPORARY_API(*pkgName);
107 void WidgetDAO::setPkgName_TEMPORARY_API(const WidgetPkgName& pkgName)
109 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
111 using namespace DPL::DB::ORM;
112 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
114 if (!isWidgetInstalled(getHandle())) {
115 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
116 "Cannot find widget. Handle: " << getHandle());
119 wrt::WidgetInfo::Row row;
120 row.Set_pkgname(pkgName);
122 WRT_DB_UPDATE(update, wrt::WidgetInfo, &WrtDatabase::interface())
124 Equals<wrt::WidgetInfo::app_id>(getHandle()));
128 transaction.Commit();
130 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
133 void WidgetDAO::setSecurityPopupUsage(const SettingsType value)
135 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
137 using namespace DPL::DB::ORM;
138 using namespace DPL::DB::ORM::wrt;
140 ScopedTransaction transaction(&WrtDatabase::interface());
141 if (!isWidgetInstalled(getHandle())) {
142 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
143 "Cannot find widget. Handle: " << getHandle());
146 WidgetSecuritySettings::Row row;
147 row.Set_security_popup_usage(value);
149 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
150 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
154 transaction.Commit();
156 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set security popup usage")
159 void WidgetDAO::setGeolocationUsage(const SettingsType value)
161 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
163 using namespace DPL::DB::ORM;
164 using namespace DPL::DB::ORM::wrt;
166 ScopedTransaction transaction(&WrtDatabase::interface());
167 if (!isWidgetInstalled(getHandle())) {
168 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
169 "Cannot find widget. Handle: " << getHandle());
172 WidgetSecuritySettings::Row row;
173 row.Set_geolocation_usage(value);
175 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
176 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
180 transaction.Commit();
182 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set geolocation usage")
185 void WidgetDAO::setWebNotificationUsage(const SettingsType value)
187 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
189 using namespace DPL::DB::ORM;
190 using namespace DPL::DB::ORM::wrt;
192 ScopedTransaction transaction(&WrtDatabase::interface());
193 if (!isWidgetInstalled(getHandle())) {
194 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
195 "Cannot find widget. Handle: " << getHandle());
198 WidgetSecuritySettings::Row row;
199 row.Set_web_notification_usage(value);
201 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
202 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
206 transaction.Commit();
208 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web notification usage")
211 void WidgetDAO::setWebDatabaseUsage(const SettingsType value)
213 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
215 using namespace DPL::DB::ORM;
216 using namespace DPL::DB::ORM::wrt;
218 ScopedTransaction transaction(&WrtDatabase::interface());
219 if (!isWidgetInstalled(getHandle())) {
220 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
221 "Cannot find widget. Handle: " << getHandle());
224 WidgetSecuritySettings::Row row;
225 row.Set_web_database_usage(value);
227 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
228 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
232 transaction.Commit();
234 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web database usage")
237 void WidgetDAO::setFileSystemUsage(const SettingsType value)
239 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
241 using namespace DPL::DB::ORM;
242 using namespace DPL::DB::ORM::wrt;
244 ScopedTransaction transaction(&WrtDatabase::interface());
245 if (!isWidgetInstalled(getHandle())) {
246 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
247 "Cannot find widget. Handle: " << getHandle());
250 WidgetSecuritySettings::Row row;
251 row.Set_file_system_usage(value);
253 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
254 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
258 transaction.Commit();
260 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set filesystem usage")
263 void WidgetDAO::registerWidget(
264 const WidgetPkgName & widgetPkgname,
265 const WidgetRegisterInfo &widgetRegInfo,
266 const IWacSecurity &wacSecurity)
268 LogDebug("Registering widget");
269 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
271 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
272 registerWidgetInternal(widgetPkgname, widgetRegInfo, wacSecurity);
273 transaction.Commit();
275 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
278 void WidgetDAO::registerWidget(
279 WrtDB::DbWidgetHandle handle,
280 const WidgetRegisterInfo &widgetRegInfo,
281 const IWacSecurity &wacSecurity)
283 LogDebug("Registering widget");
284 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
286 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
287 registerWidgetInternal(generateTizenId(), widgetRegInfo, wacSecurity, handle);
288 transaction.Commit();
290 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
293 DbWidgetHandle WidgetDAO::registerWidget(
294 const WidgetRegisterInfo &pWidgetRegisterInfo,
295 const IWacSecurity &wacSecurity)
297 //make it more precise due to very fast tests
299 gettimeofday(&tv, NULL);
300 srand(time(NULL) + tv.tv_usec);
301 DbWidgetHandle widgetHandle;
303 widgetHandle = rand();
304 } while (isWidgetInstalled(widgetHandle));
306 registerWidget(widgetHandle, pWidgetRegisterInfo, wacSecurity);
310 WidgetPkgName WidgetDAO::registerWidgetGenerateTizenId(
311 const WidgetRegisterInfo &pWidgetRegisterInfo,
312 const IWacSecurity &wacSecurity)
314 WidgetPkgName widgetPkgName = generateTizenId();
315 registerWidget(widgetPkgName, pWidgetRegisterInfo, wacSecurity);
316 return widgetPkgName;
319 void WidgetDAO::registerWidgetInternal(
320 const WidgetPkgName & widgetName,
321 const WidgetRegisterInfo &widgetRegInfo,
322 const IWacSecurity &wacSecurity,
323 const DPL::Optional<DbWidgetHandle> handle)
325 //Register into WidgetInfo has to be first
326 //as all other tables depend upon that
327 DbWidgetHandle widgetHandle = registerWidgetInfo(widgetName, widgetRegInfo, wacSecurity, handle);
329 registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
331 registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
333 registerWidgetIcons(widgetHandle, widgetRegInfo);
335 registerWidgetStartFile(widgetHandle, widgetRegInfo);
337 PropertyDAO::RegisterProperties(widgetHandle, widgetRegInfo);
339 registerWidgetFeatures(widgetHandle, widgetRegInfo);
341 registerWidgetPrivilege(widgetHandle, widgetRegInfo);
343 registerWidgetWindowModes(widgetHandle, widgetRegInfo);
345 registerWidgetWarpInfo(widgetHandle, widgetRegInfo);
347 registerWidgetCertificates(widgetHandle, wacSecurity);
349 CertificateChainList list;
350 wacSecurity.getCertificateChainList(list, SIGNATURE_DISTRIBUTOR);
351 registerCertificatesChains(widgetHandle, SIGNATURE_DISTRIBUTOR, list);
354 wacSecurity.getCertificateChainList(list, SIGNATURE_AUTHOR);
355 registerCertificatesChains(widgetHandle, SIGNATURE_AUTHOR, list);
357 registerWidgetSettings(widgetHandle, widgetRegInfo);
359 registerAppService(widgetHandle, widgetRegInfo);
361 registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
363 registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
365 registerWidgetSecuritySettings(widgetHandle);
368 void WidgetDAO::registerOrUpdateWidget(
369 const WidgetPkgName & widgetName,
370 const WidgetRegisterInfo &widgetRegInfo,
371 const IWacSecurity &wacSecurity)
373 LogDebug("Reregistering widget");
374 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
376 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
378 unregisterWidgetInternal(widgetName);
379 registerWidgetInternal(widgetName, widgetRegInfo, wacSecurity);
380 transaction.Commit();
382 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
385 #define DO_INSERT(row, table) \
387 WRT_DB_INSERT(insert, table, &WrtDatabase::interface()) \
388 insert->Values(row); \
392 void WidgetDAO::registerWidgetExtendedInfo(DbWidgetHandle widgetHandle,
393 const WidgetRegisterInfo ®Info)
395 //Try and transaction not needed
396 using namespace DPL::DB::ORM;
397 using namespace DPL::DB::ORM::wrt;
400 WidgetExtendedInfo::Row row;
401 row.Set_app_id(widgetHandle);
402 // row.Set_share_href (DPL::FromUTF8String(regInfo.shareHref));
403 row.Set_signature_type(regInfo.signatureType);
404 row.Set_test_widget(regInfo.isTestWidget);
405 row.Set_install_time(regInfo.installedTime);
406 row.Set_splash_img_src(regInfo.configInfo.splashImgSrc);
407 row.Set_background_page(regInfo.configInfo.backgroundPage);
408 row.Set_installed_path(regInfo.widgetInstalledPath);
410 DO_INSERT(row, WidgetExtendedInfo)
413 DbWidgetHandle WidgetDAO::registerWidgetInfo(
414 const WidgetPkgName & widgetName,
415 const WidgetRegisterInfo ®Info,
416 const IWacSecurity &wacSecurity,
417 const DPL::Optional<DbWidgetHandle> handle)
419 using namespace DPL::DB::ORM;
420 using namespace DPL::DB::ORM::wrt;
421 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
423 // TODO in wrt_db all Columns in WidgetInfo have DEFAULT VALUE set.
424 // Because of that, "Optional" is not used there
429 row.Set_app_id(*handle);
432 if (regInfo.webAppType == APP_TYPE_UNKNOWN && regInfo.type !=
434 // TODO : regInfo.type is temporary code for security.
435 // This code will be removed.
436 row.Set_widget_type(regInfo.type.appType);
438 row.Set_widget_type(regInfo.webAppType.appType);
440 row.Set_widget_id(widgetConfigurationInfo.widget_id);
441 row.Set_defaultlocale(widgetConfigurationInfo.defaultlocale);
442 row.Set_widget_version(widgetConfigurationInfo.version);
443 row.Set_widget_width(widgetConfigurationInfo.width);
444 row.Set_widget_height(widgetConfigurationInfo.height);
445 row.Set_author_name(widgetConfigurationInfo.authorName);
446 row.Set_author_email(widgetConfigurationInfo.authorEmail);
447 row.Set_author_href(widgetConfigurationInfo.authorHref);
448 row.Set_base_folder(DPL::FromUTF8String(regInfo.baseFolder));
449 row.Set_webkit_plugins_required(widgetConfigurationInfo.flashNeeded);
450 row.Set_recognized(wacSecurity.isRecognized());
451 row.Set_wac_signed(wacSecurity.isWacSigned());
452 row.Set_distributor_signed(wacSecurity.isDistributorSigned());
453 row.Set_pkgname(widgetName);
455 std::stringstream tmp;
456 tmp << regInfo.minVersion;
457 row.Set_min_version(DPL::FromUTF8String(tmp.str()));
459 row.Set_back_supported(widgetConfigurationInfo.backSupported);
460 row.Set_access_network(widgetConfigurationInfo.accessNetwork);
461 row.Set_pkg_type(regInfo.packagingType.pkgType);
465 DO_INSERT(row, WidgetInfo);
467 Catch(DPL::DB::SqlConnection::Exception::Base)
469 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
470 "Failed to register widget info.");
475 //get autoincremented value of widgetHandle
476 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
477 select->Where(Equals<WidgetInfo::pkgname>(widgetName));
478 return select->GetSingleValue<WidgetInfo::app_id>();
486 void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
487 const WidgetRegisterInfo ®Info)
489 using namespace DPL::DB::ORM;
490 using namespace DPL::DB::ORM::wrt;
492 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
494 FOREACH(it, widgetConfigurationInfo.localizedDataSet)
496 const DPL::String& locale = it->first;
497 const ConfigParserData::LocalizedData& data = it->second;
499 LocalizedWidgetInfo::Row row;
500 row.Set_app_id(widgetHandle);
501 row.Set_widget_locale(locale);
502 row.Set_widget_name(data.name);
503 row.Set_widget_shortname(data.shortName);
504 row.Set_widget_description(data.description);
505 row.Set_widget_license(data.license);
506 row.Set_widget_license_file(data.licenseFile);
507 row.Set_widget_license_href(data.licenseHref);
509 DO_INSERT(row, LocalizedWidgetInfo)
513 void WidgetDAO::registerWidgetIcons(DbWidgetHandle widgetHandle,
514 const WidgetRegisterInfo ®Info)
516 using namespace DPL::DB::ORM;
517 using namespace DPL::DB::ORM::wrt;
520 FOREACH(i, regInfo.localizationData.icons)
522 wrt::WidgetIcon::icon_id::ColumnType icon_id;
524 wrt::WidgetIcon::Row row;
525 row.Set_app_id(widgetHandle);
526 row.Set_icon_src(i->src);
527 row.Set_icon_width(i->width);
528 row.Set_icon_height(i->height);
530 WRT_DB_INSERT(insert, wrt::WidgetIcon, &WrtDatabase::interface())
532 icon_id = insert->Execute();
535 FOREACH(j, i->availableLocales)
537 WidgetLocalizedIcon::Row row;
538 row.Set_app_id(widgetHandle);
539 row.Set_icon_id(icon_id);
540 row.Set_widget_locale(*j);
541 WRT_DB_SELECT(select, WidgetLocalizedIcon, &WrtDatabase::interface())
542 select->Where(And(Equals<WidgetLocalizedIcon::app_id>(widgetHandle),
543 Equals<WidgetLocalizedIcon::widget_locale>(*j)));
544 WidgetLocalizedIcon::Select::RowList rows = select->GetRowList();
546 bool flag = !rows.empty();
550 // already default icon value of same locale exists
551 WRT_DB_UPDATE(update, WidgetLocalizedIcon, &WrtDatabase::interface())
552 update->Where(And(Equals<WidgetLocalizedIcon::app_id>(widgetHandle),
553 Equals<WidgetLocalizedIcon::widget_locale>(*j)));
557 // any icon value of same locale doesn't exist
558 DO_INSERT(row, WidgetLocalizedIcon)
564 void WidgetDAO::registerWidgetStartFile(DbWidgetHandle widgetHandle,
565 const WidgetRegisterInfo ®Info)
567 using namespace DPL::DB::ORM;
568 using namespace DPL::DB::ORM::wrt;
571 FOREACH(i, regInfo.localizationData.startFiles)
573 WidgetStartFile::start_file_id::ColumnType startFileID;
575 WidgetStartFile::Row row;
576 row.Set_app_id(widgetHandle);
577 row.Set_src(i->path);
579 WRT_DB_INSERT(insert, WidgetStartFile, &WrtDatabase::interface())
581 startFileID = insert->Execute();
584 FOREACH(j, i->propertiesForLocales)
586 WidgetLocalizedStartFile::Row row;
587 row.Set_app_id(widgetHandle);
588 row.Set_start_file_id(startFileID);
589 row.Set_widget_locale(j->first);
590 row.Set_type(j->second.type);
591 row.Set_encoding(j->second.encoding);
593 DO_INSERT(row, WidgetLocalizedStartFile)
598 void WidgetDAO::registerWidgetFeatures(DbWidgetHandle widgetHandle,
599 const WidgetRegisterInfo ®Info)
601 using namespace DPL::DB::ORM;
602 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
605 FOREACH(pWidgetFeature, widgetConfigurationInfo.featuresList)
607 wrt::WidgetFeature::Row widgetFeature;
608 widgetFeature.Set_app_id(widgetHandle);
609 widgetFeature.Set_name(pWidgetFeature->name);
610 widgetFeature.Set_required(pWidgetFeature->required);
611 widgetFeature.Set_rejected(false);
613 wrt::WidgetFeature::widget_feature_id::ColumnType widgetFeatureID;
615 WRT_DB_INSERT(insert, wrt::WidgetFeature, &WrtDatabase::interface())
616 insert->Values(widgetFeature);
617 widgetFeatureID = insert->Execute();
620 // Insert into table FeatureParam
621 wrt::FeatureParam::Row featureParam;
622 featureParam.Set_widget_feature_id(widgetFeatureID);
624 FOREACH(iter, pWidgetFeature->paramsList)
626 featureParam.Set_name(iter->name);
627 featureParam.Set_value(iter->value);
629 DO_INSERT(featureParam, wrt::FeatureParam)
634 void WidgetDAO::registerWidgetPrivilege(DbWidgetHandle widgetHandle,
635 const WidgetRegisterInfo ®Info)
637 using namespace DPL::DB::ORM;
638 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
640 FOREACH(it, widgetConfigurationInfo.privilegeList)
642 wrt::WidgetPrivilege::Row widgetPrivilege;
643 widgetPrivilege.Set_app_id(widgetHandle);
644 widgetPrivilege.Set_name(it->name);
646 DO_INSERT(widgetPrivilege, wrt::WidgetPrivilege)
650 void WidgetDAO::updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature){
651 // This function could be merged with registerWidgetFeature but it requires desing change:
652 // 1. Check "ace step" in installer must be done before "update database step"
654 // ConfigurationParserData shouldn't be called "ParserData" any more.
655 using namespace DPL::DB::ORM;
657 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
658 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
659 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
660 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
662 auto row = select->GetSingleRow();
663 row.Set_rejected(widgetFeature.rejected);
665 WRT_DB_UPDATE(update, wrt::WidgetFeature, &WrtDatabase::interface())
666 update->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
667 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
670 transaction.Commit();
673 void WidgetDAO::registerWidgetWindowModes(DbWidgetHandle widgetHandle,
674 const WidgetRegisterInfo ®Info)
676 using namespace DPL::DB::ORM;
677 using namespace DPL::DB::ORM::wrt;
678 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
681 FOREACH(i, widgetConfigurationInfo.windowModes)
683 wrt::WidgetWindowModes::Row windowMode;
684 windowMode.Set_app_id(widgetHandle);
685 windowMode.Set_window_mode(*i);
687 DO_INSERT(windowMode, wrt::WidgetWindowModes)
691 void WidgetDAO::registerWidgetWarpInfo(DbWidgetHandle widgetHandle,
692 const WidgetRegisterInfo ®Info)
694 using namespace DPL::DB::ORM;
695 using namespace DPL::DB::ORM::wrt;
696 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
699 FOREACH(AccIt, widgetConfigurationInfo.accessInfoSet)
701 WidgetWARPInfo::Row row;
702 row.Set_app_id(widgetHandle);
703 row.Set_iri(AccIt->m_strIRI);
704 row.Set_subdomain_access(static_cast <int>(
705 AccIt->m_bSubDomainAccess));
707 DO_INSERT(row, WidgetWARPInfo)
711 void WidgetDAO::registerWidgetCertificates(DbWidgetHandle widgetHandle,
712 const IWacSecurity &wacSecurity)
714 using namespace DPL::DB::ORM;
715 using namespace DPL::DB::ORM::wrt;
718 FOREACH(it, wacSecurity.getCertificateList())
720 WidgetCertificateFingerprint::Row row;
721 row.Set_app_id(widgetHandle);
722 row.Set_owner(it->owner);
723 row.Set_chainid(it->chainId);
724 row.Set_type(it->type);
725 row.Set_md5_fingerprint(DPL::FromUTF8String(it->strMD5Fingerprint));
726 row.Set_sha1_fingerprint(DPL::FromUTF8String(it->strSHA1Fingerprint));
727 row.Set_common_name(it->strCommonName);
729 DO_INSERT(row, WidgetCertificateFingerprint)
733 void WidgetDAO::registerCertificatesChains(DbWidgetHandle widgetHandle,
734 CertificateSource certificateSource,
735 const CertificateChainList &certificateChainList)
737 using namespace DPL::DB::ORM;
738 using namespace DPL::DB::ORM::wrt;
739 FOREACH(certChain, certificateChainList)
741 WidgetCertificate::Row row;
742 row.Set_app_id(widgetHandle);
743 row.Set_cert_source(certificateSource);
744 row.Set_encoded_chain(DPL::FromASCIIString(*certChain));
746 DO_INSERT(row, WidgetCertificate);
750 void WidgetDAO::registerWidgetSettings(DbWidgetHandle widgetHandle,
751 const WidgetRegisterInfo ®Info)
753 using namespace DPL::DB::ORM;
754 using namespace DPL::DB::ORM::wrt;
756 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
758 FOREACH(pWidgetSetting, widgetConfigurationInfo.settingsList)
760 SettingsList::Row row;
761 row.Set_appId(widgetHandle);
762 row.Set_settingName(pWidgetSetting->m_name);
763 row.Set_settingValue(pWidgetSetting->m_value);
765 DO_INSERT(row, SettingsList)
769 void WidgetDAO::registerAppService(DbWidgetHandle widgetHandle,
770 const WidgetRegisterInfo ®Info)
772 using namespace DPL::DB::ORM;
773 using namespace DPL::DB::ORM::wrt;
774 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
776 FOREACH(ASIt, widgetConfigurationInfo.appServiceList)
778 ApplicationServiceInfo::Row row;
779 row.Set_app_id(widgetHandle);
780 row.Set_src(ASIt->m_src);
781 row.Set_operation(ASIt->m_operation);
782 row.Set_scheme(ASIt->m_scheme);
783 row.Set_mime(ASIt->m_mime);
785 DO_INSERT(row, ApplicationServiceInfo)
789 void WidgetDAO::registerEncryptedResouceInfo(DbWidgetHandle widgetHandle,
790 const WidgetRegisterInfo ®Info)
792 using namespace DPL::DB::ORM;
793 using namespace DPL::DB::ORM::wrt;
795 FOREACH(it, regInfo.encryptedFiles)
797 EncryptedResourceList::Row row;
798 row.Set_app_id(widgetHandle);
799 row.Set_resource(it->fileName);
800 row.Set_size(it->fileSize);
802 DO_INSERT(row, EncryptedResourceList)
806 void WidgetDAO::registerExternalLocations(DbWidgetHandle widgetHandle,
807 const ExternalLocationList & externals)
809 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
811 using namespace DPL::DB::ORM;
812 using namespace DPL::DB::ORM::wrt;
813 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
814 LogDebug("Inserting external files for widgetHandle: " << widgetHandle);
815 FOREACH(it, externals)
817 WidgetExternalLocations::Row row;
818 row.Set_app_id(widgetHandle);
819 row.Set_path(DPL::FromUTF8String(*it));
821 DO_INSERT(row, WidgetExternalLocations)
823 transaction.Commit();
825 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
828 void WidgetDAO::registerWidgetSecuritySettings(DbWidgetHandle widgetHandle)
830 using namespace DPL::DB::ORM;
831 using namespace DPL::DB::ORM::wrt;
832 WidgetSecuritySettings::Row row;
833 row.Set_app_id(widgetHandle);
834 row.Set_security_popup_usage(SETTINGS_TYPE_ON);
835 row.Set_geolocation_usage(SETTINGS_TYPE_ON);
836 row.Set_web_notification_usage(SETTINGS_TYPE_ON);
837 row.Set_web_database_usage(SETTINGS_TYPE_ON);
838 row.Set_file_system_usage(SETTINGS_TYPE_ON);
840 DO_INSERT(row, WidgetSecuritySettings)
843 void WidgetDAO::unregisterAllExternalLocations()
845 using namespace DPL::DB::ORM;
846 using namespace DPL::DB::ORM::wrt;
847 LogDebug("Deleting external files for widgetHandle: " << m_widgetHandle);
848 WRT_DB_DELETE(del, WidgetExternalLocations, &WrtDatabase::interface());
849 del->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
853 void WidgetDAO::unregisterWidget(const WidgetPkgName & pkgName)
855 LogDebug("Unregistering widget from DB. PkgName: " << pkgName);
856 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
858 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
859 unregisterWidgetInternal(pkgName);
860 transaction.Commit();
862 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
865 void WidgetDAO::unregisterWidget(WrtDB::DbWidgetHandle handle)
867 LogDebug("Unregistering widget from DB. Handle: " << handle);
868 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
870 using namespace DPL::DB::ORM;
871 using namespace DPL::DB::ORM::wrt;
872 ScopedTransaction transaction(&WrtDatabase::interface());
874 // Delete from table Widget Info
875 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
876 del->Where(Equals<WidgetInfo::app_id>(handle));
879 transaction.Commit();
881 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
884 void WidgetDAO::unregisterWidgetInternal(
885 const WidgetPkgName & pkgName)
887 using namespace DPL::DB::ORM;
888 using namespace DPL::DB::ORM::wrt;
890 DbWidgetHandle handle = getHandle(pkgName);
892 // Delete from table Widget Info
893 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
894 del->Where(Equals<WidgetInfo::app_id>(handle));
897 // Deleting in other tables is done via "delete cascade" in SQL
902 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
903 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END