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 #define CHECK_WIDGET_EXISTENCE(macro_transaction, macro_handle) \
55 if (!WidgetDAO::isWidgetInstalled(macro_handle)) \
57 macro_transaction.Commit(); \
58 LogWarning("Cannot find widget. Handle: " << macro_handle); \
59 ThrowMsg(WidgetDAO::Exception::WidgetNotExist, \
60 "Cannot find widget. Handle: " << macro_handle); \
64 WidgetDAO::WidgetDAO(DbWidgetHandle widgetHandle) :
65 WidgetDAOReadOnly(widgetHandle)
69 WidgetDAO::WidgetDAO(DPL::OptionalString widgetGUID) :
70 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(widgetGUID))
74 WidgetDAO::WidgetDAO(DPL::String pkgName) :
75 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(pkgName))
79 WidgetDAO::~WidgetDAO()
83 void WidgetDAO::removeProperty(
84 const PropertyDAOReadOnly::WidgetPropertyKey &key)
87 PropertyDAO::RemoveProperty(m_widgetHandle, key);
89 Catch(PropertyDAOReadOnly::Exception::ReadOnlyProperty){
90 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
91 "Failure during removing property");
95 void WidgetDAO::setProperty(
96 const PropertyDAOReadOnly::WidgetPropertyKey &key,
97 const PropertyDAOReadOnly::WidgetPropertyValue &value,
101 PropertyDAO::SetProperty(m_widgetHandle, key, value, readOnly);
103 Catch(PropertyDAOReadOnly::Exception::ReadOnlyProperty){
104 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
105 "Failure during setting/updating property");
109 void WidgetDAO::setPkgName(const DPL::OptionalString& pkgName)
111 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
113 using namespace DPL::DB::ORM;
114 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
116 isWidgetInstalled(getHandle());
118 wrt::WidgetInfo::Row row;
119 row.Set_pkgname(pkgName);
121 WRT_DB_UPDATE(update, wrt::WidgetInfo, &WrtDatabase::interface())
123 Equals<wrt::WidgetInfo::app_id>(getHandle()));
127 transaction.Commit();
129 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
132 void WidgetDAO::registerWidget(
133 const DbWidgetHandle& widgetHandle,
134 const WidgetRegisterInfo &widgetRegInfo,
135 const IWacSecurity &wacSecurity)
137 LogDebug("Registering widget");
138 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
140 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
142 //Register into WidgetInfo has to be first
143 //as all other tables depend upon that
144 registerWidgetInfo(widgetHandle, widgetRegInfo, wacSecurity);
146 registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
148 registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
150 registerWidgetIcons(widgetHandle, widgetRegInfo);
152 registerWidgetStartFile(widgetHandle, widgetRegInfo);
154 PropertyDAO::RegisterProperties(widgetHandle, widgetRegInfo);
156 registerWidgetFeatures(widgetHandle, widgetRegInfo);
158 registerWidgetWindowModes(widgetHandle, widgetRegInfo);
160 registerWidgetWarpInfo(widgetHandle, widgetRegInfo);
162 registerWidgetCertificates(widgetHandle, wacSecurity);
164 CertificateChainList list;
165 wacSecurity.getCertificateChainList(list, SIGNATURE_DISTRIBUTOR);
166 registerCertificatesChains(widgetHandle, SIGNATURE_DISTRIBUTOR, list);
169 wacSecurity.getCertificateChainList(list, SIGNATURE_AUTHOR);
170 registerCertificatesChains(widgetHandle, SIGNATURE_AUTHOR, list);
172 registerWidgetSettings(widgetHandle, widgetRegInfo);
174 registerAppService(widgetHandle, widgetRegInfo);
176 registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
178 transaction.Commit();
180 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
183 #define DO_INSERT(row, table) \
185 WRT_DB_INSERT(insert, table, &WrtDatabase::interface()) \
186 insert->Values(row); \
190 void WidgetDAO::registerWidgetExtendedInfo(DbWidgetHandle widgetHandle,
191 const WidgetRegisterInfo ®Info)
193 //Try and transaction not needed
194 using namespace DPL::DB::ORM;
195 using namespace DPL::DB::ORM::wrt;
198 WidgetExtendedInfo::Row row;
199 row.Set_app_id(widgetHandle);
200 // row.Set_share_href (DPL::FromUTF8String(regInfo.shareHref));
201 row.Set_signature_type(regInfo.signatureType);
202 row.Set_factory_widget(regInfo.isFactoryWidget);
203 row.Set_test_widget(regInfo.isTestWidget);
204 row.Set_install_time(regInfo.installedTime);
205 row.Set_splash_img_src(regInfo.configInfo.splashImgSrc);
206 row.Set_background_page(regInfo.configInfo.backgroundPage);
209 DO_INSERT(row, WidgetExtendedInfo)
212 void WidgetDAO::registerWidgetInfo(
213 const DbWidgetHandle& widgetHandle,
214 const WidgetRegisterInfo ®Info,
215 const IWacSecurity &wacSecurity)
217 using namespace DPL::DB::ORM;
218 using namespace DPL::DB::ORM::wrt;
219 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
221 // TODO in wrt_db all Columns in WidgetInfo have DEFAULT VALUE set.
222 // Because of that, "Optional" is not used there
225 row.Set_app_id(widgetHandle);
226 row.Set_widget_type(regInfo.type.appType);
227 row.Set_widget_id(widgetConfigurationInfo.widget_id);
228 row.Set_defaultlocale(widgetConfigurationInfo.defaultlocale);
229 row.Set_widget_version(widgetConfigurationInfo.version);
230 row.Set_widget_width(widgetConfigurationInfo.width);
231 row.Set_widget_height(widgetConfigurationInfo.height);
232 row.Set_author_name(widgetConfigurationInfo.authorName);
233 row.Set_author_email(widgetConfigurationInfo.authorEmail);
234 row.Set_author_href(widgetConfigurationInfo.authorHref);
235 row.Set_base_folder(DPL::FromUTF8String(regInfo.baseFolder));
236 row.Set_webkit_plugins_required(widgetConfigurationInfo.flashNeeded);
237 row.Set_recognized(wacSecurity.isRecognized());
238 row.Set_wac_signed(wacSecurity.isWacSigned());
239 row.Set_distributor_signed(wacSecurity.isDistributorSigned());
241 std::stringstream tmp;
242 tmp << regInfo.minVersion;
243 row.Set_min_version(DPL::FromUTF8String(tmp.str()));
245 row.Set_back_supported(widgetConfigurationInfo.backSupported);
246 row.Set_access_network(widgetConfigurationInfo.accessNetwork);
247 row.Set_pkgname(regInfo.pkgname);
248 row.Set_pkg_type(regInfo.pType.pkgType);
252 DO_INSERT(row, WidgetInfo);
254 Catch(DPL::DB::SqlConnection::Exception::Base)
256 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
257 "Failed to register widget info.");
261 void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
262 const WidgetRegisterInfo ®Info)
264 using namespace DPL::DB::ORM;
265 using namespace DPL::DB::ORM::wrt;
267 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
269 FOREACH(it, widgetConfigurationInfo.localizedDataSet)
271 const DPL::String& locale = it->first;
272 const ConfigParserData::LocalizedData& data = it->second;
274 LocalizedWidgetInfo::Row row;
275 row.Set_app_id(widgetHandle);
276 row.Set_widget_locale(locale);
277 row.Set_widget_name(data.name);
278 row.Set_widget_shortname(data.shortName);
279 row.Set_widget_description(data.description);
280 row.Set_widget_license(data.license);
281 row.Set_widget_license_file(data.licenseFile);
282 row.Set_widget_license_href(data.licenseHref);
284 DO_INSERT(row, LocalizedWidgetInfo)
288 void WidgetDAO::registerWidgetIcons(DbWidgetHandle widgetHandle,
289 const WidgetRegisterInfo ®Info)
291 using namespace DPL::DB::ORM;
292 using namespace DPL::DB::ORM::wrt;
295 FOREACH(i, regInfo.localizationData.icons)
297 wrt::WidgetIcon::icon_id::ColumnType icon_id;
299 wrt::WidgetIcon::Row row;
300 row.Set_app_id(widgetHandle);
301 row.Set_icon_src(i->src);
302 row.Set_icon_width(i->width);
303 row.Set_icon_height(i->height);
305 WRT_DB_INSERT(insert, wrt::WidgetIcon, &WrtDatabase::interface())
307 icon_id = insert->Execute();
310 FOREACH(j, i->availableLocales)
312 WidgetLocalizedIcon::Row row;
313 row.Set_app_id(widgetHandle);
314 row.Set_icon_id(icon_id);
315 row.Set_widget_locale(*j);
316 WRT_DB_SELECT(select, WidgetLocalizedIcon, &WrtDatabase::interface())
317 select->Where(And(Equals<WidgetLocalizedIcon::app_id>(widgetHandle),
318 Equals<WidgetLocalizedIcon::widget_locale>(*j)));
319 WidgetLocalizedIcon::Select::RowList rows = select->GetRowList();
321 bool flag = !rows.empty();
325 // already default icon value of same locale exists
326 WRT_DB_UPDATE(update, WidgetLocalizedIcon, &WrtDatabase::interface())
327 update->Where(And(Equals<WidgetLocalizedIcon::app_id>(widgetHandle),
328 Equals<WidgetLocalizedIcon::widget_locale>(*j)));
332 // any icon value of same locale doesn't exist
333 DO_INSERT(row, WidgetLocalizedIcon)
339 void WidgetDAO::registerWidgetStartFile(DbWidgetHandle widgetHandle,
340 const WidgetRegisterInfo ®Info)
342 using namespace DPL::DB::ORM;
343 using namespace DPL::DB::ORM::wrt;
346 FOREACH(i, regInfo.localizationData.startFiles)
348 WidgetStartFile::start_file_id::ColumnType startFileID;
350 WidgetStartFile::Row row;
351 row.Set_app_id(widgetHandle);
352 row.Set_src(i->path);
354 WRT_DB_INSERT(insert, WidgetStartFile, &WrtDatabase::interface())
356 startFileID = insert->Execute();
359 FOREACH(j, i->propertiesForLocales)
361 WidgetLocalizedStartFile::Row row;
362 row.Set_app_id(widgetHandle);
363 row.Set_start_file_id(startFileID);
364 row.Set_widget_locale(j->first);
365 row.Set_type(j->second.type);
366 row.Set_encoding(j->second.encoding);
368 DO_INSERT(row, WidgetLocalizedStartFile)
373 void WidgetDAO::registerWidgetFeatures(DbWidgetHandle widgetHandle,
374 const WidgetRegisterInfo ®Info)
376 using namespace DPL::DB::ORM;
377 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
380 FOREACH(pWidgetFeature, widgetConfigurationInfo.featuresList)
382 wrt::WidgetFeature::Row widgetFeature;
383 widgetFeature.Set_app_id(widgetHandle);
384 widgetFeature.Set_name(pWidgetFeature->name);
385 widgetFeature.Set_required(pWidgetFeature->required);
386 widgetFeature.Set_rejected(false);
388 wrt::WidgetFeature::widget_feature_id::ColumnType widgetFeatureID;
390 WRT_DB_INSERT(insert, wrt::WidgetFeature, &WrtDatabase::interface())
391 insert->Values(widgetFeature);
392 widgetFeatureID = insert->Execute();
395 // Insert into table FeatureParam
396 wrt::FeatureParam::Row featureParam;
397 featureParam.Set_widget_feature_id(widgetFeatureID);
399 ConfigParserData::ParamsList::const_iterator iter;
401 FOREACH(iter, pWidgetFeature->paramsList)
403 featureParam.Set_name(iter->name);
404 featureParam.Set_value(iter->value);
406 DO_INSERT(featureParam, wrt::FeatureParam)
411 void WidgetDAO::updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature){
412 // This function could be merged with registerWidgetFeature but it requires desing change:
413 // 1. Check "ace step" in installer must be done before "update database step"
415 // ConfigurationParserData shouldn't be called "ParserData" any more.
416 using namespace DPL::DB::ORM;
418 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
419 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
420 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
421 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
423 auto row = select->GetSingleRow();
424 row.Set_rejected(widgetFeature.rejected);
426 WRT_DB_UPDATE(update, wrt::WidgetFeature, &WrtDatabase::interface())
427 update->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
428 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
431 transaction.Commit();
434 void WidgetDAO::registerWidgetWindowModes(DbWidgetHandle widgetHandle,
435 const WidgetRegisterInfo ®Info)
437 using namespace DPL::DB::ORM;
438 using namespace DPL::DB::ORM::wrt;
439 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
442 FOREACH(i, widgetConfigurationInfo.windowModes)
444 wrt::WidgetWindowModes::Row windowMode;
445 windowMode.Set_app_id(widgetHandle);
446 windowMode.Set_window_mode(*i);
448 DO_INSERT(windowMode, wrt::WidgetWindowModes)
452 void WidgetDAO::registerWidgetWarpInfo(DbWidgetHandle widgetHandle,
453 const WidgetRegisterInfo ®Info)
455 using namespace DPL::DB::ORM;
456 using namespace DPL::DB::ORM::wrt;
457 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
460 FOREACH(AccIt, widgetConfigurationInfo.accessInfoSet)
462 WidgetWARPInfo::Row row;
463 row.Set_app_id(widgetHandle);
464 row.Set_iri(AccIt->m_strIRI);
465 row.Set_subdomain_access(static_cast <int>(
466 AccIt->m_bSubDomainAccess));
468 DO_INSERT(row, WidgetWARPInfo)
472 void WidgetDAO::registerWidgetCertificates(DbWidgetHandle widgetHandle,
473 const IWacSecurity &wacSecurity)
475 using namespace DPL::DB::ORM;
476 using namespace DPL::DB::ORM::wrt;
479 FOREACH(it, wacSecurity.getCertificateList())
481 WidgetCertificateFingerprint::Row row;
482 row.Set_app_id(widgetHandle);
483 row.Set_owner(it->owner);
484 row.Set_chainid(it->chainId);
485 row.Set_type(it->type);
486 row.Set_md5_fingerprint(DPL::FromUTF8String(it->strMD5Fingerprint));
487 row.Set_sha1_fingerprint(DPL::FromUTF8String(it->strSHA1Fingerprint));
488 row.Set_common_name(it->strCommonName);
490 DO_INSERT(row, WidgetCertificateFingerprint)
494 void WidgetDAO::registerCertificatesChains(DbWidgetHandle widgetHandle,
495 CertificateSource certificateSource,
496 const CertificateChainList &certificateChainList)
498 using namespace DPL::DB::ORM;
499 using namespace DPL::DB::ORM::wrt;
500 FOREACH(certChain, certificateChainList)
502 WidgetCertificate::Row row;
503 row.Set_app_id(widgetHandle);
504 row.Set_cert_source(certificateSource);
505 row.Set_encoded_chain(DPL::FromASCIIString(*certChain));
507 DO_INSERT(row, WidgetCertificate);
511 void WidgetDAO::registerWidgetSettings(DbWidgetHandle widgetHandle,
512 const WidgetRegisterInfo ®Info)
514 using namespace DPL::DB::ORM;
515 using namespace DPL::DB::ORM::wrt;
517 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
519 FOREACH(pWidgetSetting, widgetConfigurationInfo.settingsList)
521 SettginsList::Row row;
522 row.Set_appId(widgetHandle);
523 row.Set_settingName(pWidgetSetting->m_name);
524 row.Set_settingValue(pWidgetSetting->m_value);
526 DO_INSERT(row, SettginsList)
530 void WidgetDAO::registerAppService(DbWidgetHandle widgetHandle,
531 const WidgetRegisterInfo ®Info)
533 using namespace DPL::DB::ORM;
534 using namespace DPL::DB::ORM::wrt;
535 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
537 FOREACH(ASIt, widgetConfigurationInfo.appServiceList)
539 ApplicationServiceInfo::Row row;
540 row.Set_app_id(widgetHandle);
541 row.Set_src(ASIt->m_src);
542 row.Set_operation(ASIt->m_operation);
543 row.Set_scheme(ASIt->m_scheme);
544 row.Set_mime(ASIt->m_mime);
546 DO_INSERT(row, ApplicationServiceInfo)
550 void WidgetDAO::registerEncryptedResouceInfo(DbWidgetHandle widgetHandle,
551 const WidgetRegisterInfo ®Info)
553 using namespace DPL::DB::ORM;
554 using namespace DPL::DB::ORM::wrt;
556 FOREACH(it, regInfo.encryptedFiles)
558 EncryptedResourceList::Row row;
559 row.Set_app_id(widgetHandle);
560 row.Set_resource(it->fileName);
561 row.Set_size(it->fileSize);
563 DO_INSERT(row, EncryptedResourceList)
567 void WidgetDAO::registerExternalLocations(const ExternalLocationList & externals)
569 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
571 using namespace DPL::DB::ORM;
572 using namespace DPL::DB::ORM::wrt;
573 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
574 LogDebug("Inserting external files for widgetHandle: " << m_widgetHandle);
575 FOREACH(it, externals)
577 WidgetExternalLocations::Row row;
578 row.Set_app_id(m_widgetHandle);
579 row.Set_path(DPL::FromUTF8String(*it));
581 DO_INSERT(row, WidgetExternalLocations)
583 transaction.Commit();
585 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
588 void WidgetDAO::unregisterAllExternalLocations()
590 using namespace DPL::DB::ORM;
591 using namespace DPL::DB::ORM::wrt;
592 LogDebug("Deleting external files for widgetHandle: " << m_widgetHandle);
593 WRT_DB_DELETE(del, WidgetExternalLocations, &WrtDatabase::interface());
594 del->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
600 void WidgetDAO::unregisterWidget(DbWidgetHandle widgetHandle)
602 LogDebug("Unregistering widget from DB. Handle: " << widgetHandle);
603 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
605 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
606 using namespace DPL::DB::ORM;
607 using namespace DPL::DB::ORM::wrt;
609 CHECK_WIDGET_EXISTENCE(transaction, widgetHandle)
611 // Delete from table Widget Info
613 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
614 del->Where(Equals<WidgetInfo::app_id>(widgetHandle));
618 // Deleting in other tables is done via "delete cascade" in SQL
620 transaction.Commit();
622 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
625 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
626 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END
627 #undef CHECK_WIDGET_EXISTENCE