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)
101 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
103 using namespace DPL::DB::ORM;
104 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
106 isWidgetInstalled(getHandle());
108 wrt::WidgetInfo::Row row;
109 row.Set_pkgname(pkgName);
111 WRT_DB_UPDATE(update, wrt::WidgetInfo, &WrtDatabase::interface())
113 Equals<wrt::WidgetInfo::app_id>(getHandle()));
117 transaction.Commit();
119 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
122 void WidgetDAO::setSecurityPopupUsage(const SettingsType value)
124 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
126 using namespace DPL::DB::ORM;
127 using namespace DPL::DB::ORM::wrt;
129 ScopedTransaction transaction(&WrtDatabase::interface());
130 if (!isWidgetInstalled(getHandle())) {
131 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
132 "Cannot find widget. Handle: " << getHandle());
135 WidgetSecuritySettings::Row row;
136 row.Set_security_popup_usage(value);
138 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
139 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
143 transaction.Commit();
145 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set security popup usage")
148 void WidgetDAO::setGeolocationUsage(const SettingsType value)
150 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
152 using namespace DPL::DB::ORM;
153 using namespace DPL::DB::ORM::wrt;
155 ScopedTransaction transaction(&WrtDatabase::interface());
156 if (!isWidgetInstalled(getHandle())) {
157 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
158 "Cannot find widget. Handle: " << getHandle());
161 WidgetSecuritySettings::Row row;
162 row.Set_geolocation_usage(value);
164 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
165 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
169 transaction.Commit();
171 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set geolocation usage")
174 void WidgetDAO::setWebNotificationUsage(const SettingsType value)
176 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
178 using namespace DPL::DB::ORM;
179 using namespace DPL::DB::ORM::wrt;
181 ScopedTransaction transaction(&WrtDatabase::interface());
182 if (!isWidgetInstalled(getHandle())) {
183 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
184 "Cannot find widget. Handle: " << getHandle());
187 WidgetSecuritySettings::Row row;
188 row.Set_web_notification_usage(value);
190 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
191 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
195 transaction.Commit();
197 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web notification usage")
200 void WidgetDAO::setWebDatabaseUsage(const SettingsType value)
202 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
204 using namespace DPL::DB::ORM;
205 using namespace DPL::DB::ORM::wrt;
207 ScopedTransaction transaction(&WrtDatabase::interface());
208 if (!isWidgetInstalled(getHandle())) {
209 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
210 "Cannot find widget. Handle: " << getHandle());
213 WidgetSecuritySettings::Row row;
214 row.Set_web_database_usage(value);
216 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
217 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
221 transaction.Commit();
223 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web database usage")
226 void WidgetDAO::setFileSystemUsage(const SettingsType value)
228 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
230 using namespace DPL::DB::ORM;
231 using namespace DPL::DB::ORM::wrt;
233 ScopedTransaction transaction(&WrtDatabase::interface());
234 if (!isWidgetInstalled(getHandle())) {
235 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
236 "Cannot find widget. Handle: " << getHandle());
239 WidgetSecuritySettings::Row row;
240 row.Set_file_system_usage(value);
242 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
243 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
247 transaction.Commit();
249 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set filesystem usage")
252 void WidgetDAO::registerWidget(
253 const WidgetPkgName & widgetPkgname,
254 const WidgetRegisterInfo &widgetRegInfo,
255 const IWacSecurity &wacSecurity)
257 LogDebug("Registering widget");
258 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
260 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
261 registerWidgetInternal(widgetPkgname, widgetRegInfo, wacSecurity);
262 transaction.Commit();
264 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
267 void WidgetDAO::registerWidget(
268 WrtDB::DbWidgetHandle handle,
269 const WidgetRegisterInfo &widgetRegInfo,
270 const IWacSecurity &wacSecurity)
272 LogDebug("Registering widget");
273 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
275 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
276 registerWidgetInternal(generateTizenId(), widgetRegInfo, wacSecurity, handle);
277 transaction.Commit();
279 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
282 DbWidgetHandle WidgetDAO::registerWidget(
283 const WidgetRegisterInfo &pWidgetRegisterInfo,
284 const IWacSecurity &wacSecurity)
286 //make it more precise due to very fast tests
288 gettimeofday(&tv, NULL);
289 srand(time(NULL) + tv.tv_usec);
290 DbWidgetHandle widgetHandle;
292 widgetHandle = rand();
293 } while (isWidgetInstalled(widgetHandle));
295 registerWidget(widgetHandle, pWidgetRegisterInfo, wacSecurity);
299 WidgetPkgName WidgetDAO::registerWidgetGenerateTizenId(
300 const WidgetRegisterInfo &pWidgetRegisterInfo,
301 const IWacSecurity &wacSecurity)
303 WidgetPkgName widgetPkgName = generateTizenId();
304 registerWidget(widgetPkgName, pWidgetRegisterInfo, wacSecurity);
305 return widgetPkgName;
308 void WidgetDAO::registerWidgetInternal(
309 const WidgetPkgName & widgetName,
310 const WidgetRegisterInfo &widgetRegInfo,
311 const IWacSecurity &wacSecurity,
312 const DPL::Optional<DbWidgetHandle> handle)
314 //Register into WidgetInfo has to be first
315 //as all other tables depend upon that
316 DbWidgetHandle widgetHandle = registerWidgetInfo(widgetName, widgetRegInfo, wacSecurity, handle);
318 registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
320 registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
322 registerWidgetIcons(widgetHandle, widgetRegInfo);
324 registerWidgetStartFile(widgetHandle, widgetRegInfo);
326 PropertyDAO::RegisterProperties(widgetHandle, widgetRegInfo);
328 registerWidgetFeatures(widgetHandle, widgetRegInfo);
330 registerWidgetWindowModes(widgetHandle, widgetRegInfo);
332 registerWidgetWarpInfo(widgetHandle, widgetRegInfo);
334 registerWidgetCertificates(widgetHandle, wacSecurity);
336 CertificateChainList list;
337 wacSecurity.getCertificateChainList(list, SIGNATURE_DISTRIBUTOR);
338 registerCertificatesChains(widgetHandle, SIGNATURE_DISTRIBUTOR, list);
341 wacSecurity.getCertificateChainList(list, SIGNATURE_AUTHOR);
342 registerCertificatesChains(widgetHandle, SIGNATURE_AUTHOR, list);
344 registerWidgetSettings(widgetHandle, widgetRegInfo);
346 registerAppService(widgetHandle, widgetRegInfo);
348 registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
350 registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
352 registerWidgetSecuritySettings(widgetHandle);
355 void WidgetDAO::registerOrUpdateWidget(
356 const WidgetPkgName & widgetName,
357 const WidgetRegisterInfo &widgetRegInfo,
358 const IWacSecurity &wacSecurity)
360 LogDebug("Reregistering widget");
361 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
363 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
365 unregisterWidgetInternal(widgetName);
366 registerWidgetInternal(widgetName, widgetRegInfo, wacSecurity);
367 transaction.Commit();
369 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
372 #define DO_INSERT(row, table) \
374 WRT_DB_INSERT(insert, table, &WrtDatabase::interface()) \
375 insert->Values(row); \
379 void WidgetDAO::registerWidgetExtendedInfo(DbWidgetHandle widgetHandle,
380 const WidgetRegisterInfo ®Info)
382 //Try and transaction not needed
383 using namespace DPL::DB::ORM;
384 using namespace DPL::DB::ORM::wrt;
387 WidgetExtendedInfo::Row row;
388 row.Set_app_id(widgetHandle);
389 // row.Set_share_href (DPL::FromUTF8String(regInfo.shareHref));
390 row.Set_signature_type(regInfo.signatureType);
391 row.Set_test_widget(regInfo.isTestWidget);
392 row.Set_install_time(regInfo.installedTime);
393 row.Set_splash_img_src(regInfo.configInfo.splashImgSrc);
394 row.Set_background_page(regInfo.configInfo.backgroundPage);
395 row.Set_installed_path(regInfo.widgetInstalledPath);
397 DO_INSERT(row, WidgetExtendedInfo)
400 DbWidgetHandle WidgetDAO::registerWidgetInfo(
401 const WidgetPkgName & widgetName,
402 const WidgetRegisterInfo ®Info,
403 const IWacSecurity &wacSecurity,
404 const DPL::Optional<DbWidgetHandle> handle)
406 using namespace DPL::DB::ORM;
407 using namespace DPL::DB::ORM::wrt;
408 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
410 // TODO in wrt_db all Columns in WidgetInfo have DEFAULT VALUE set.
411 // Because of that, "Optional" is not used there
416 row.Set_app_id(*handle);
419 if (regInfo.webAppType == APP_TYPE_UNKNOWN && regInfo.type !=
421 // TODO : regInfo.type is temporary code for security.
422 // This code will be removed.
423 row.Set_widget_type(regInfo.type.appType);
425 row.Set_widget_type(regInfo.webAppType.appType);
427 row.Set_widget_id(widgetConfigurationInfo.widget_id);
428 row.Set_defaultlocale(widgetConfigurationInfo.defaultlocale);
429 row.Set_widget_version(widgetConfigurationInfo.version);
430 row.Set_widget_width(widgetConfigurationInfo.width);
431 row.Set_widget_height(widgetConfigurationInfo.height);
432 row.Set_author_name(widgetConfigurationInfo.authorName);
433 row.Set_author_email(widgetConfigurationInfo.authorEmail);
434 row.Set_author_href(widgetConfigurationInfo.authorHref);
435 row.Set_base_folder(DPL::FromUTF8String(regInfo.baseFolder));
436 row.Set_webkit_plugins_required(widgetConfigurationInfo.flashNeeded);
437 row.Set_recognized(wacSecurity.isRecognized());
438 row.Set_wac_signed(wacSecurity.isWacSigned());
439 row.Set_distributor_signed(wacSecurity.isDistributorSigned());
440 row.Set_pkgname(widgetName);
442 std::stringstream tmp;
443 tmp << regInfo.minVersion;
444 row.Set_min_version(DPL::FromUTF8String(tmp.str()));
446 row.Set_back_supported(widgetConfigurationInfo.backSupported);
447 row.Set_access_network(widgetConfigurationInfo.accessNetwork);
448 row.Set_pkg_type(regInfo.packagingType.pkgType);
452 DO_INSERT(row, WidgetInfo);
454 Catch(DPL::DB::SqlConnection::Exception::Base)
456 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
457 "Failed to register widget info.");
462 //get autoincremented value of widgetHandle
463 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
464 select->Where(Equals<WidgetInfo::pkgname>(widgetName));
465 return select->GetSingleValue<WidgetInfo::app_id>();
473 void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
474 const WidgetRegisterInfo ®Info)
476 using namespace DPL::DB::ORM;
477 using namespace DPL::DB::ORM::wrt;
479 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
481 FOREACH(it, widgetConfigurationInfo.localizedDataSet)
483 const DPL::String& locale = it->first;
484 const ConfigParserData::LocalizedData& data = it->second;
486 LocalizedWidgetInfo::Row row;
487 row.Set_app_id(widgetHandle);
488 row.Set_widget_locale(locale);
489 row.Set_widget_name(data.name);
490 row.Set_widget_shortname(data.shortName);
491 row.Set_widget_description(data.description);
492 row.Set_widget_license(data.license);
493 row.Set_widget_license_file(data.licenseFile);
494 row.Set_widget_license_href(data.licenseHref);
496 DO_INSERT(row, LocalizedWidgetInfo)
500 void WidgetDAO::registerWidgetIcons(DbWidgetHandle widgetHandle,
501 const WidgetRegisterInfo ®Info)
503 using namespace DPL::DB::ORM;
504 using namespace DPL::DB::ORM::wrt;
507 FOREACH(i, regInfo.localizationData.icons)
509 wrt::WidgetIcon::icon_id::ColumnType icon_id;
511 wrt::WidgetIcon::Row row;
512 row.Set_app_id(widgetHandle);
513 row.Set_icon_src(i->src);
514 row.Set_icon_width(i->width);
515 row.Set_icon_height(i->height);
517 WRT_DB_INSERT(insert, wrt::WidgetIcon, &WrtDatabase::interface())
519 icon_id = insert->Execute();
522 FOREACH(j, i->availableLocales)
524 WidgetLocalizedIcon::Row row;
525 row.Set_app_id(widgetHandle);
526 row.Set_icon_id(icon_id);
527 row.Set_widget_locale(*j);
528 WRT_DB_SELECT(select, WidgetLocalizedIcon, &WrtDatabase::interface())
529 select->Where(And(Equals<WidgetLocalizedIcon::app_id>(widgetHandle),
530 Equals<WidgetLocalizedIcon::widget_locale>(*j)));
531 WidgetLocalizedIcon::Select::RowList rows = select->GetRowList();
533 bool flag = !rows.empty();
537 // already default icon value of same locale exists
538 WRT_DB_UPDATE(update, WidgetLocalizedIcon, &WrtDatabase::interface())
539 update->Where(And(Equals<WidgetLocalizedIcon::app_id>(widgetHandle),
540 Equals<WidgetLocalizedIcon::widget_locale>(*j)));
544 // any icon value of same locale doesn't exist
545 DO_INSERT(row, WidgetLocalizedIcon)
551 void WidgetDAO::registerWidgetStartFile(DbWidgetHandle widgetHandle,
552 const WidgetRegisterInfo ®Info)
554 using namespace DPL::DB::ORM;
555 using namespace DPL::DB::ORM::wrt;
558 FOREACH(i, regInfo.localizationData.startFiles)
560 WidgetStartFile::start_file_id::ColumnType startFileID;
562 WidgetStartFile::Row row;
563 row.Set_app_id(widgetHandle);
564 row.Set_src(i->path);
566 WRT_DB_INSERT(insert, WidgetStartFile, &WrtDatabase::interface())
568 startFileID = insert->Execute();
571 FOREACH(j, i->propertiesForLocales)
573 WidgetLocalizedStartFile::Row row;
574 row.Set_app_id(widgetHandle);
575 row.Set_start_file_id(startFileID);
576 row.Set_widget_locale(j->first);
577 row.Set_type(j->second.type);
578 row.Set_encoding(j->second.encoding);
580 DO_INSERT(row, WidgetLocalizedStartFile)
585 void WidgetDAO::registerWidgetFeatures(DbWidgetHandle widgetHandle,
586 const WidgetRegisterInfo ®Info)
588 using namespace DPL::DB::ORM;
589 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
592 FOREACH(pWidgetFeature, widgetConfigurationInfo.featuresList)
594 wrt::WidgetFeature::Row widgetFeature;
595 widgetFeature.Set_app_id(widgetHandle);
596 widgetFeature.Set_name(pWidgetFeature->name);
597 widgetFeature.Set_required(pWidgetFeature->required);
598 widgetFeature.Set_rejected(false);
600 wrt::WidgetFeature::widget_feature_id::ColumnType widgetFeatureID;
602 WRT_DB_INSERT(insert, wrt::WidgetFeature, &WrtDatabase::interface())
603 insert->Values(widgetFeature);
604 widgetFeatureID = insert->Execute();
607 // Insert into table FeatureParam
608 wrt::FeatureParam::Row featureParam;
609 featureParam.Set_widget_feature_id(widgetFeatureID);
611 FOREACH(iter, pWidgetFeature->paramsList)
613 featureParam.Set_name(iter->name);
614 featureParam.Set_value(iter->value);
616 DO_INSERT(featureParam, wrt::FeatureParam)
621 void WidgetDAO::updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature){
622 // This function could be merged with registerWidgetFeature but it requires desing change:
623 // 1. Check "ace step" in installer must be done before "update database step"
625 // ConfigurationParserData shouldn't be called "ParserData" any more.
626 using namespace DPL::DB::ORM;
628 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
629 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
630 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
631 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
633 auto row = select->GetSingleRow();
634 row.Set_rejected(widgetFeature.rejected);
636 WRT_DB_UPDATE(update, wrt::WidgetFeature, &WrtDatabase::interface())
637 update->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
638 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
641 transaction.Commit();
644 void WidgetDAO::registerWidgetWindowModes(DbWidgetHandle widgetHandle,
645 const WidgetRegisterInfo ®Info)
647 using namespace DPL::DB::ORM;
648 using namespace DPL::DB::ORM::wrt;
649 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
652 FOREACH(i, widgetConfigurationInfo.windowModes)
654 wrt::WidgetWindowModes::Row windowMode;
655 windowMode.Set_app_id(widgetHandle);
656 windowMode.Set_window_mode(*i);
658 DO_INSERT(windowMode, wrt::WidgetWindowModes)
662 void WidgetDAO::registerWidgetWarpInfo(DbWidgetHandle widgetHandle,
663 const WidgetRegisterInfo ®Info)
665 using namespace DPL::DB::ORM;
666 using namespace DPL::DB::ORM::wrt;
667 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
670 FOREACH(AccIt, widgetConfigurationInfo.accessInfoSet)
672 WidgetWARPInfo::Row row;
673 row.Set_app_id(widgetHandle);
674 row.Set_iri(AccIt->m_strIRI);
675 row.Set_subdomain_access(static_cast <int>(
676 AccIt->m_bSubDomainAccess));
678 DO_INSERT(row, WidgetWARPInfo)
682 void WidgetDAO::registerWidgetCertificates(DbWidgetHandle widgetHandle,
683 const IWacSecurity &wacSecurity)
685 using namespace DPL::DB::ORM;
686 using namespace DPL::DB::ORM::wrt;
689 FOREACH(it, wacSecurity.getCertificateList())
691 WidgetCertificateFingerprint::Row row;
692 row.Set_app_id(widgetHandle);
693 row.Set_owner(it->owner);
694 row.Set_chainid(it->chainId);
695 row.Set_type(it->type);
696 row.Set_md5_fingerprint(DPL::FromUTF8String(it->strMD5Fingerprint));
697 row.Set_sha1_fingerprint(DPL::FromUTF8String(it->strSHA1Fingerprint));
698 row.Set_common_name(it->strCommonName);
700 DO_INSERT(row, WidgetCertificateFingerprint)
704 void WidgetDAO::registerCertificatesChains(DbWidgetHandle widgetHandle,
705 CertificateSource certificateSource,
706 const CertificateChainList &certificateChainList)
708 using namespace DPL::DB::ORM;
709 using namespace DPL::DB::ORM::wrt;
710 FOREACH(certChain, certificateChainList)
712 WidgetCertificate::Row row;
713 row.Set_app_id(widgetHandle);
714 row.Set_cert_source(certificateSource);
715 row.Set_encoded_chain(DPL::FromASCIIString(*certChain));
717 DO_INSERT(row, WidgetCertificate);
721 void WidgetDAO::registerWidgetSettings(DbWidgetHandle widgetHandle,
722 const WidgetRegisterInfo ®Info)
724 using namespace DPL::DB::ORM;
725 using namespace DPL::DB::ORM::wrt;
727 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
729 FOREACH(pWidgetSetting, widgetConfigurationInfo.settingsList)
731 SettingsList::Row row;
732 row.Set_appId(widgetHandle);
733 row.Set_settingName(pWidgetSetting->m_name);
734 row.Set_settingValue(pWidgetSetting->m_value);
736 DO_INSERT(row, SettingsList)
740 void WidgetDAO::registerAppService(DbWidgetHandle widgetHandle,
741 const WidgetRegisterInfo ®Info)
743 using namespace DPL::DB::ORM;
744 using namespace DPL::DB::ORM::wrt;
745 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
747 FOREACH(ASIt, widgetConfigurationInfo.appServiceList)
749 ApplicationServiceInfo::Row row;
750 row.Set_app_id(widgetHandle);
751 row.Set_src(ASIt->m_src);
752 row.Set_operation(ASIt->m_operation);
753 row.Set_scheme(ASIt->m_scheme);
754 row.Set_mime(ASIt->m_mime);
756 DO_INSERT(row, ApplicationServiceInfo)
760 void WidgetDAO::registerEncryptedResouceInfo(DbWidgetHandle widgetHandle,
761 const WidgetRegisterInfo ®Info)
763 using namespace DPL::DB::ORM;
764 using namespace DPL::DB::ORM::wrt;
766 FOREACH(it, regInfo.encryptedFiles)
768 EncryptedResourceList::Row row;
769 row.Set_app_id(widgetHandle);
770 row.Set_resource(it->fileName);
771 row.Set_size(it->fileSize);
773 DO_INSERT(row, EncryptedResourceList)
777 void WidgetDAO::registerExternalLocations(DbWidgetHandle widgetHandle,
778 const ExternalLocationList & externals)
780 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
782 using namespace DPL::DB::ORM;
783 using namespace DPL::DB::ORM::wrt;
784 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
785 LogDebug("Inserting external files for widgetHandle: " << widgetHandle);
786 FOREACH(it, externals)
788 WidgetExternalLocations::Row row;
789 row.Set_app_id(widgetHandle);
790 row.Set_path(DPL::FromUTF8String(*it));
792 DO_INSERT(row, WidgetExternalLocations)
794 transaction.Commit();
796 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
799 void WidgetDAO::registerWidgetSecuritySettings(DbWidgetHandle widgetHandle)
801 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
803 using namespace DPL::DB::ORM;
804 using namespace DPL::DB::ORM::wrt;
805 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
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)
816 transaction.Commit();
818 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
821 void WidgetDAO::unregisterAllExternalLocations()
823 using namespace DPL::DB::ORM;
824 using namespace DPL::DB::ORM::wrt;
825 LogDebug("Deleting external files for widgetHandle: " << m_widgetHandle);
826 WRT_DB_DELETE(del, WidgetExternalLocations, &WrtDatabase::interface());
827 del->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
831 void WidgetDAO::unregisterWidget(const WidgetPkgName & pkgName)
833 LogDebug("Unregistering widget from DB. PkgName: " << pkgName);
834 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
836 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
837 unregisterWidgetInternal(pkgName);
838 transaction.Commit();
840 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
843 void WidgetDAO::unregisterWidget(WrtDB::DbWidgetHandle handle)
845 LogDebug("Unregistering widget from DB. Handle: " << handle);
846 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
848 using namespace DPL::DB::ORM;
849 using namespace DPL::DB::ORM::wrt;
850 ScopedTransaction transaction(&WrtDatabase::interface());
852 // Delete from table Widget Info
853 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
854 del->Where(Equals<WidgetInfo::app_id>(handle));
857 transaction.Commit();
859 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
862 void WidgetDAO::unregisterWidgetInternal(
863 const WidgetPkgName & pkgName)
865 using namespace DPL::DB::ORM;
866 using namespace DPL::DB::ORM::wrt;
868 DbWidgetHandle handle = getHandle(pkgName);
870 // Delete from table Widget Info
871 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
872 del->Where(Equals<WidgetInfo::app_id>(handle));
875 // Deleting in other tables is done via "delete cascade" in SQL
880 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
881 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END