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))
56 // TODO THIS WILL BE DELETED
60 WidgetDAO::WidgetDAO(DPL::String pkgName) :
61 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(pkgName))
65 WidgetDAO::WidgetDAO(DbWidgetHandle handle) :
66 WidgetDAOReadOnly(handle)
70 WidgetDAO::~WidgetDAO()
74 void WidgetDAO::removeProperty(
75 const PropertyDAOReadOnly::WidgetPropertyKey &key)
78 PropertyDAO::RemoveProperty(m_widgetHandle, key);
80 Catch(PropertyDAOReadOnly::Exception::ReadOnlyProperty){
81 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
82 "Failure during removing property");
86 void WidgetDAO::setProperty(
87 const PropertyDAOReadOnly::WidgetPropertyKey &key,
88 const PropertyDAOReadOnly::WidgetPropertyValue &value,
92 PropertyDAO::SetProperty(m_widgetHandle, key, value, readOnly);
94 Catch(PropertyDAOReadOnly::Exception::ReadOnlyProperty){
95 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
96 "Failure during setting/updating property");
100 void WidgetDAO::setPkgName(const DPL::OptionalString& pkgName)
102 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
104 using namespace DPL::DB::ORM;
105 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
107 isWidgetInstalled(getHandle());
109 wrt::WidgetInfo::Row row;
110 row.Set_pkgname(pkgName);
112 WRT_DB_UPDATE(update, wrt::WidgetInfo, &WrtDatabase::interface())
114 Equals<wrt::WidgetInfo::app_id>(getHandle()));
118 transaction.Commit();
120 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
123 void WidgetDAO::setPkgName_NOTNULL(const DPL::String& pkgName)
125 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
127 using namespace DPL::DB::ORM;
128 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
130 isWidgetInstalled(getHandle());
132 wrt::WidgetInfo::Row row;
133 row.Set_pkgname(pkgName);
135 WRT_DB_UPDATE(update, wrt::WidgetInfo, &WrtDatabase::interface())
137 Equals<wrt::WidgetInfo::app_id>(getHandle()));
141 transaction.Commit();
143 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
146 void WidgetDAO::setSecurityPopupUsage(const SettingsType value)
148 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
150 using namespace DPL::DB::ORM;
151 using namespace DPL::DB::ORM::wrt;
153 ScopedTransaction transaction(&WrtDatabase::interface());
154 if (!isWidgetInstalled(getHandle())) {
155 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
156 "Cannot find widget. Handle: " << getHandle());
159 WidgetSecuritySettings::Row row;
160 row.Set_security_popup_usage(value);
162 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
163 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
167 transaction.Commit();
169 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set security popup usage")
172 void WidgetDAO::setGeolocationUsage(const SettingsType value)
174 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
176 using namespace DPL::DB::ORM;
177 using namespace DPL::DB::ORM::wrt;
179 ScopedTransaction transaction(&WrtDatabase::interface());
180 if (!isWidgetInstalled(getHandle())) {
181 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
182 "Cannot find widget. Handle: " << getHandle());
185 WidgetSecuritySettings::Row row;
186 row.Set_geolocation_usage(value);
188 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
189 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
193 transaction.Commit();
195 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set geolocation usage")
198 void WidgetDAO::setWebNotificationUsage(const SettingsType value)
200 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
202 using namespace DPL::DB::ORM;
203 using namespace DPL::DB::ORM::wrt;
205 ScopedTransaction transaction(&WrtDatabase::interface());
206 if (!isWidgetInstalled(getHandle())) {
207 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
208 "Cannot find widget. Handle: " << getHandle());
211 WidgetSecuritySettings::Row row;
212 row.Set_web_notification_usage(value);
214 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
215 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
219 transaction.Commit();
221 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web notification usage")
224 void WidgetDAO::setWebDatabaseUsage(const SettingsType value)
226 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
228 using namespace DPL::DB::ORM;
229 using namespace DPL::DB::ORM::wrt;
231 ScopedTransaction transaction(&WrtDatabase::interface());
232 if (!isWidgetInstalled(getHandle())) {
233 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
234 "Cannot find widget. Handle: " << getHandle());
237 WidgetSecuritySettings::Row row;
238 row.Set_web_database_usage(value);
240 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
241 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
245 transaction.Commit();
247 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web database usage")
250 void WidgetDAO::setFileSystemUsage(const SettingsType value)
252 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
254 using namespace DPL::DB::ORM;
255 using namespace DPL::DB::ORM::wrt;
257 ScopedTransaction transaction(&WrtDatabase::interface());
258 if (!isWidgetInstalled(getHandle())) {
259 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
260 "Cannot find widget. Handle: " << getHandle());
263 WidgetSecuritySettings::Row row;
264 row.Set_file_system_usage(value);
266 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
267 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
271 transaction.Commit();
273 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set filesystem usage")
276 void WidgetDAO::registerWidget(
277 const WidgetPkgName & widgetPkgname,
278 const WidgetRegisterInfo &widgetRegInfo,
279 const IWacSecurity &wacSecurity)
281 LogDebug("Registering widget");
282 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
284 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
285 registerWidgetInternal(widgetPkgname, widgetRegInfo, wacSecurity);
286 transaction.Commit();
288 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
291 void WidgetDAO::registerWidget(
292 WrtDB::DbWidgetHandle handle,
293 const WidgetRegisterInfo &widgetRegInfo,
294 const IWacSecurity &wacSecurity)
296 LogDebug("Registering widget");
297 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
299 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
300 registerWidgetInternal(generateTizenId(), widgetRegInfo, wacSecurity, handle);
301 transaction.Commit();
303 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
306 DbWidgetHandle WidgetDAO::registerWidget(
307 const WidgetRegisterInfo &pWidgetRegisterInfo,
308 const IWacSecurity &wacSecurity)
310 //make it more precise due to very fast tests
312 gettimeofday(&tv, NULL);
313 srand(time(NULL) + tv.tv_usec);
314 DbWidgetHandle widgetHandle;
316 widgetHandle = rand();
317 } while (isWidgetInstalled(widgetHandle));
319 registerWidget(widgetHandle, pWidgetRegisterInfo, wacSecurity);
323 WidgetPkgName WidgetDAO::registerWidgetGenerateTizenId(
324 const WidgetRegisterInfo &pWidgetRegisterInfo,
325 const IWacSecurity &wacSecurity)
327 WidgetPkgName widgetPkgName = generateTizenId();
328 registerWidget(widgetPkgName, pWidgetRegisterInfo, wacSecurity);
329 return widgetPkgName;
332 void WidgetDAO::registerWidgetInternal(
333 const WidgetPkgName & widgetName,
334 const WidgetRegisterInfo &widgetRegInfo,
335 const IWacSecurity &wacSecurity,
336 const DPL::Optional<DbWidgetHandle> handle)
338 //Register into WidgetInfo has to be first
339 //as all other tables depend upon that
340 DbWidgetHandle widgetHandle = registerWidgetInfo(widgetName, widgetRegInfo, wacSecurity, handle);
342 registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
344 registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
346 registerWidgetIcons(widgetHandle, widgetRegInfo);
348 registerWidgetStartFile(widgetHandle, widgetRegInfo);
350 PropertyDAO::RegisterProperties(widgetHandle, widgetRegInfo);
352 registerWidgetFeatures(widgetHandle, widgetRegInfo);
354 registerWidgetWindowModes(widgetHandle, widgetRegInfo);
356 registerWidgetWarpInfo(widgetHandle, widgetRegInfo);
358 registerWidgetCertificates(widgetHandle, wacSecurity);
360 CertificateChainList list;
361 wacSecurity.getCertificateChainList(list, SIGNATURE_DISTRIBUTOR);
362 registerCertificatesChains(widgetHandle, SIGNATURE_DISTRIBUTOR, list);
365 wacSecurity.getCertificateChainList(list, SIGNATURE_AUTHOR);
366 registerCertificatesChains(widgetHandle, SIGNATURE_AUTHOR, list);
368 registerWidgetSettings(widgetHandle, widgetRegInfo);
370 registerAppService(widgetHandle, widgetRegInfo);
372 registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
374 registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
376 registerWidgetSecuritySettings(widgetHandle);
379 void WidgetDAO::registerOrUpdateWidget(
380 const WidgetPkgName & widgetName,
381 const WidgetRegisterInfo &widgetRegInfo,
382 const IWacSecurity &wacSecurity)
384 LogDebug("Reregistering widget");
385 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
387 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
389 unregisterWidgetInternal(widgetName);
390 registerWidgetInternal(widgetName, widgetRegInfo, wacSecurity);
391 transaction.Commit();
393 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
396 #define DO_INSERT(row, table) \
398 WRT_DB_INSERT(insert, table, &WrtDatabase::interface()) \
399 insert->Values(row); \
403 void WidgetDAO::registerWidgetExtendedInfo(DbWidgetHandle widgetHandle,
404 const WidgetRegisterInfo ®Info)
406 //Try and transaction not needed
407 using namespace DPL::DB::ORM;
408 using namespace DPL::DB::ORM::wrt;
411 WidgetExtendedInfo::Row row;
412 row.Set_app_id(widgetHandle);
413 // row.Set_share_href (DPL::FromUTF8String(regInfo.shareHref));
414 row.Set_signature_type(regInfo.signatureType);
415 row.Set_test_widget(regInfo.isTestWidget);
416 row.Set_install_time(regInfo.installedTime);
417 row.Set_splash_img_src(regInfo.configInfo.splashImgSrc);
418 row.Set_background_page(regInfo.configInfo.backgroundPage);
419 row.Set_installed_path(regInfo.widgetInstalledPath);
421 DO_INSERT(row, WidgetExtendedInfo)
424 DbWidgetHandle WidgetDAO::registerWidgetInfo(
425 const WidgetPkgName & widgetName,
426 const WidgetRegisterInfo ®Info,
427 const IWacSecurity &wacSecurity,
428 const DPL::Optional<DbWidgetHandle> handle)
430 using namespace DPL::DB::ORM;
431 using namespace DPL::DB::ORM::wrt;
432 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
434 // TODO in wrt_db all Columns in WidgetInfo have DEFAULT VALUE set.
435 // Because of that, "Optional" is not used there
440 row.Set_app_id(*handle);
443 if (regInfo.webAppType == APP_TYPE_UNKNOWN && regInfo.type !=
445 // TODO : regInfo.type is temporary code for security.
446 // This code will be removed.
447 row.Set_widget_type(regInfo.type.appType);
449 row.Set_widget_type(regInfo.webAppType.appType);
451 row.Set_widget_id(widgetConfigurationInfo.widget_id);
452 row.Set_defaultlocale(widgetConfigurationInfo.defaultlocale);
453 row.Set_widget_version(widgetConfigurationInfo.version);
454 row.Set_widget_width(widgetConfigurationInfo.width);
455 row.Set_widget_height(widgetConfigurationInfo.height);
456 row.Set_author_name(widgetConfigurationInfo.authorName);
457 row.Set_author_email(widgetConfigurationInfo.authorEmail);
458 row.Set_author_href(widgetConfigurationInfo.authorHref);
459 row.Set_base_folder(DPL::FromUTF8String(regInfo.baseFolder));
460 row.Set_webkit_plugins_required(widgetConfigurationInfo.flashNeeded);
461 row.Set_recognized(wacSecurity.isRecognized());
462 row.Set_wac_signed(wacSecurity.isWacSigned());
463 row.Set_distributor_signed(wacSecurity.isDistributorSigned());
464 row.Set_pkgname(widgetName);
466 std::stringstream tmp;
467 tmp << regInfo.minVersion;
468 row.Set_min_version(DPL::FromUTF8String(tmp.str()));
470 row.Set_back_supported(widgetConfigurationInfo.backSupported);
471 row.Set_access_network(widgetConfigurationInfo.accessNetwork);
472 row.Set_pkg_type(regInfo.packagingType.pkgType);
476 DO_INSERT(row, WidgetInfo);
478 Catch(DPL::DB::SqlConnection::Exception::Base)
480 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
481 "Failed to register widget info.");
486 //get autoincremented value of widgetHandle
487 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
488 select->Where(Equals<WidgetInfo::pkgname>(widgetName));
489 return select->GetSingleValue<WidgetInfo::app_id>();
497 void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
498 const WidgetRegisterInfo ®Info)
500 using namespace DPL::DB::ORM;
501 using namespace DPL::DB::ORM::wrt;
503 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
505 FOREACH(it, widgetConfigurationInfo.localizedDataSet)
507 const DPL::String& locale = it->first;
508 const ConfigParserData::LocalizedData& data = it->second;
510 LocalizedWidgetInfo::Row row;
511 row.Set_app_id(widgetHandle);
512 row.Set_widget_locale(locale);
513 row.Set_widget_name(data.name);
514 row.Set_widget_shortname(data.shortName);
515 row.Set_widget_description(data.description);
516 row.Set_widget_license(data.license);
517 row.Set_widget_license_file(data.licenseFile);
518 row.Set_widget_license_href(data.licenseHref);
520 DO_INSERT(row, LocalizedWidgetInfo)
524 void WidgetDAO::registerWidgetIcons(DbWidgetHandle widgetHandle,
525 const WidgetRegisterInfo ®Info)
527 using namespace DPL::DB::ORM;
528 using namespace DPL::DB::ORM::wrt;
531 FOREACH(i, regInfo.localizationData.icons)
533 wrt::WidgetIcon::icon_id::ColumnType icon_id;
535 wrt::WidgetIcon::Row row;
536 row.Set_app_id(widgetHandle);
537 row.Set_icon_src(i->src);
538 row.Set_icon_width(i->width);
539 row.Set_icon_height(i->height);
541 WRT_DB_INSERT(insert, wrt::WidgetIcon, &WrtDatabase::interface())
543 icon_id = insert->Execute();
546 FOREACH(j, i->availableLocales)
548 WidgetLocalizedIcon::Row row;
549 row.Set_app_id(widgetHandle);
550 row.Set_icon_id(icon_id);
551 row.Set_widget_locale(*j);
552 WRT_DB_SELECT(select, WidgetLocalizedIcon, &WrtDatabase::interface())
553 select->Where(And(Equals<WidgetLocalizedIcon::app_id>(widgetHandle),
554 Equals<WidgetLocalizedIcon::widget_locale>(*j)));
555 WidgetLocalizedIcon::Select::RowList rows = select->GetRowList();
557 bool flag = !rows.empty();
561 // already default icon value of same locale exists
562 WRT_DB_UPDATE(update, WidgetLocalizedIcon, &WrtDatabase::interface())
563 update->Where(And(Equals<WidgetLocalizedIcon::app_id>(widgetHandle),
564 Equals<WidgetLocalizedIcon::widget_locale>(*j)));
568 // any icon value of same locale doesn't exist
569 DO_INSERT(row, WidgetLocalizedIcon)
575 void WidgetDAO::registerWidgetStartFile(DbWidgetHandle widgetHandle,
576 const WidgetRegisterInfo ®Info)
578 using namespace DPL::DB::ORM;
579 using namespace DPL::DB::ORM::wrt;
582 FOREACH(i, regInfo.localizationData.startFiles)
584 WidgetStartFile::start_file_id::ColumnType startFileID;
586 WidgetStartFile::Row row;
587 row.Set_app_id(widgetHandle);
588 row.Set_src(i->path);
590 WRT_DB_INSERT(insert, WidgetStartFile, &WrtDatabase::interface())
592 startFileID = insert->Execute();
595 FOREACH(j, i->propertiesForLocales)
597 WidgetLocalizedStartFile::Row row;
598 row.Set_app_id(widgetHandle);
599 row.Set_start_file_id(startFileID);
600 row.Set_widget_locale(j->first);
601 row.Set_type(j->second.type);
602 row.Set_encoding(j->second.encoding);
604 DO_INSERT(row, WidgetLocalizedStartFile)
609 void WidgetDAO::registerWidgetFeatures(DbWidgetHandle widgetHandle,
610 const WidgetRegisterInfo ®Info)
612 using namespace DPL::DB::ORM;
613 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
616 FOREACH(pWidgetFeature, widgetConfigurationInfo.featuresList)
618 wrt::WidgetFeature::Row widgetFeature;
619 widgetFeature.Set_app_id(widgetHandle);
620 widgetFeature.Set_name(pWidgetFeature->name);
621 widgetFeature.Set_required(pWidgetFeature->required);
622 widgetFeature.Set_rejected(false);
624 wrt::WidgetFeature::widget_feature_id::ColumnType widgetFeatureID;
626 WRT_DB_INSERT(insert, wrt::WidgetFeature, &WrtDatabase::interface())
627 insert->Values(widgetFeature);
628 widgetFeatureID = insert->Execute();
631 // Insert into table FeatureParam
632 wrt::FeatureParam::Row featureParam;
633 featureParam.Set_widget_feature_id(widgetFeatureID);
635 FOREACH(iter, pWidgetFeature->paramsList)
637 featureParam.Set_name(iter->name);
638 featureParam.Set_value(iter->value);
640 DO_INSERT(featureParam, wrt::FeatureParam)
645 void WidgetDAO::updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature){
646 // This function could be merged with registerWidgetFeature but it requires desing change:
647 // 1. Check "ace step" in installer must be done before "update database step"
649 // ConfigurationParserData shouldn't be called "ParserData" any more.
650 using namespace DPL::DB::ORM;
652 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
653 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
654 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
655 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
657 auto row = select->GetSingleRow();
658 row.Set_rejected(widgetFeature.rejected);
660 WRT_DB_UPDATE(update, wrt::WidgetFeature, &WrtDatabase::interface())
661 update->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
662 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
665 transaction.Commit();
668 void WidgetDAO::registerWidgetWindowModes(DbWidgetHandle widgetHandle,
669 const WidgetRegisterInfo ®Info)
671 using namespace DPL::DB::ORM;
672 using namespace DPL::DB::ORM::wrt;
673 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
676 FOREACH(i, widgetConfigurationInfo.windowModes)
678 wrt::WidgetWindowModes::Row windowMode;
679 windowMode.Set_app_id(widgetHandle);
680 windowMode.Set_window_mode(*i);
682 DO_INSERT(windowMode, wrt::WidgetWindowModes)
686 void WidgetDAO::registerWidgetWarpInfo(DbWidgetHandle widgetHandle,
687 const WidgetRegisterInfo ®Info)
689 using namespace DPL::DB::ORM;
690 using namespace DPL::DB::ORM::wrt;
691 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
694 FOREACH(AccIt, widgetConfigurationInfo.accessInfoSet)
696 WidgetWARPInfo::Row row;
697 row.Set_app_id(widgetHandle);
698 row.Set_iri(AccIt->m_strIRI);
699 row.Set_subdomain_access(static_cast <int>(
700 AccIt->m_bSubDomainAccess));
702 DO_INSERT(row, WidgetWARPInfo)
706 void WidgetDAO::registerWidgetCertificates(DbWidgetHandle widgetHandle,
707 const IWacSecurity &wacSecurity)
709 using namespace DPL::DB::ORM;
710 using namespace DPL::DB::ORM::wrt;
713 FOREACH(it, wacSecurity.getCertificateList())
715 WidgetCertificateFingerprint::Row row;
716 row.Set_app_id(widgetHandle);
717 row.Set_owner(it->owner);
718 row.Set_chainid(it->chainId);
719 row.Set_type(it->type);
720 row.Set_md5_fingerprint(DPL::FromUTF8String(it->strMD5Fingerprint));
721 row.Set_sha1_fingerprint(DPL::FromUTF8String(it->strSHA1Fingerprint));
722 row.Set_common_name(it->strCommonName);
724 DO_INSERT(row, WidgetCertificateFingerprint)
728 void WidgetDAO::registerCertificatesChains(DbWidgetHandle widgetHandle,
729 CertificateSource certificateSource,
730 const CertificateChainList &certificateChainList)
732 using namespace DPL::DB::ORM;
733 using namespace DPL::DB::ORM::wrt;
734 FOREACH(certChain, certificateChainList)
736 WidgetCertificate::Row row;
737 row.Set_app_id(widgetHandle);
738 row.Set_cert_source(certificateSource);
739 row.Set_encoded_chain(DPL::FromASCIIString(*certChain));
741 DO_INSERT(row, WidgetCertificate);
745 void WidgetDAO::registerWidgetSettings(DbWidgetHandle widgetHandle,
746 const WidgetRegisterInfo ®Info)
748 using namespace DPL::DB::ORM;
749 using namespace DPL::DB::ORM::wrt;
751 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
753 FOREACH(pWidgetSetting, widgetConfigurationInfo.settingsList)
755 SettingsList::Row row;
756 row.Set_appId(widgetHandle);
757 row.Set_settingName(pWidgetSetting->m_name);
758 row.Set_settingValue(pWidgetSetting->m_value);
760 DO_INSERT(row, SettingsList)
764 void WidgetDAO::registerAppService(DbWidgetHandle widgetHandle,
765 const WidgetRegisterInfo ®Info)
767 using namespace DPL::DB::ORM;
768 using namespace DPL::DB::ORM::wrt;
769 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
771 FOREACH(ASIt, widgetConfigurationInfo.appServiceList)
773 ApplicationServiceInfo::Row row;
774 row.Set_app_id(widgetHandle);
775 row.Set_src(ASIt->m_src);
776 row.Set_operation(ASIt->m_operation);
777 row.Set_scheme(ASIt->m_scheme);
778 row.Set_mime(ASIt->m_mime);
780 DO_INSERT(row, ApplicationServiceInfo)
784 void WidgetDAO::registerEncryptedResouceInfo(DbWidgetHandle widgetHandle,
785 const WidgetRegisterInfo ®Info)
787 using namespace DPL::DB::ORM;
788 using namespace DPL::DB::ORM::wrt;
790 FOREACH(it, regInfo.encryptedFiles)
792 EncryptedResourceList::Row row;
793 row.Set_app_id(widgetHandle);
794 row.Set_resource(it->fileName);
795 row.Set_size(it->fileSize);
797 DO_INSERT(row, EncryptedResourceList)
801 void WidgetDAO::registerExternalLocations(DbWidgetHandle widgetHandle,
802 const ExternalLocationList & externals)
804 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
806 using namespace DPL::DB::ORM;
807 using namespace DPL::DB::ORM::wrt;
808 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
809 LogDebug("Inserting external files for widgetHandle: " << widgetHandle);
810 FOREACH(it, externals)
812 WidgetExternalLocations::Row row;
813 row.Set_app_id(widgetHandle);
814 row.Set_path(DPL::FromUTF8String(*it));
816 DO_INSERT(row, WidgetExternalLocations)
818 transaction.Commit();
820 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
823 void WidgetDAO::registerWidgetSecuritySettings(DbWidgetHandle widgetHandle)
825 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
827 using namespace DPL::DB::ORM;
828 using namespace DPL::DB::ORM::wrt;
829 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
831 WidgetSecuritySettings::Row row;
832 row.Set_app_id(widgetHandle);
833 row.Set_security_popup_usage(SETTINGS_TYPE_ON);
834 row.Set_geolocation_usage(SETTINGS_TYPE_ON);
835 row.Set_web_notification_usage(SETTINGS_TYPE_ON);
836 row.Set_web_database_usage(SETTINGS_TYPE_ON);
837 row.Set_file_system_usage(SETTINGS_TYPE_ON);
839 DO_INSERT(row, WidgetSecuritySettings)
840 transaction.Commit();
842 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
845 void WidgetDAO::unregisterAllExternalLocations()
847 using namespace DPL::DB::ORM;
848 using namespace DPL::DB::ORM::wrt;
849 LogDebug("Deleting external files for widgetHandle: " << m_widgetHandle);
850 WRT_DB_DELETE(del, WidgetExternalLocations, &WrtDatabase::interface());
851 del->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
855 void WidgetDAO::unregisterWidget(const WidgetPkgName & pkgName)
857 LogDebug("Unregistering widget from DB. PkgName: " << pkgName);
858 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
860 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
861 unregisterWidgetInternal(pkgName);
862 transaction.Commit();
864 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
867 void WidgetDAO::unregisterWidget(WrtDB::DbWidgetHandle handle)
869 LogDebug("Unregistering widget from DB. Handle: " << handle);
870 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
872 using namespace DPL::DB::ORM;
873 using namespace DPL::DB::ORM::wrt;
874 ScopedTransaction transaction(&WrtDatabase::interface());
876 // Delete from table Widget Info
877 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
878 del->Where(Equals<WidgetInfo::app_id>(handle));
881 transaction.Commit();
883 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
886 void WidgetDAO::unregisterWidgetInternal(
887 const WidgetPkgName & pkgName)
889 using namespace DPL::DB::ORM;
890 using namespace DPL::DB::ORM::wrt;
892 DbWidgetHandle handle = getHandle(pkgName);
894 // Delete from table Widget Info
895 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
896 del->Where(Equals<WidgetInfo::app_id>(handle));
899 // Deleting in other tables is done via "delete cascade" in SQL
904 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
905 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END