Pkgname (tizen id) - not null
[framework/web/wrt-commons.git] / modules / widget_dao / dao / widget_dao.cpp
index cdb99da..9327806 100644 (file)
@@ -53,6 +53,7 @@ namespace WrtDB {
 
 WidgetDAO::WidgetDAO(DPL::OptionalString widgetGUID) :
     WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(widgetGUID))
+// TODO THIS WILL BE DELETED
 {
 }
 
@@ -119,6 +120,159 @@ void WidgetDAO::setPkgName(const DPL::OptionalString& pkgName)
     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
 }
 
+void WidgetDAO::setPkgName_NOTNULL(const DPL::String& pkgName)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        using namespace DPL::DB::ORM;
+        wrt::ScopedTransaction transaction(&WrtDatabase::interface());
+
+        isWidgetInstalled(getHandle());
+
+        wrt::WidgetInfo::Row row;
+        row.Set_pkgname(pkgName);
+
+        WRT_DB_UPDATE(update, wrt::WidgetInfo, &WrtDatabase::interface())
+        update->Where(
+            Equals<wrt::WidgetInfo::app_id>(getHandle()));
+
+        update->Values(row);
+        update->Execute();
+        transaction.Commit();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
+}
+
+void WidgetDAO::setSecurityPopupUsage(const SettingsType value)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        using namespace DPL::DB::ORM;
+        using namespace DPL::DB::ORM::wrt;
+
+        ScopedTransaction transaction(&WrtDatabase::interface());
+        if (!isWidgetInstalled(getHandle())) {
+            ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
+                "Cannot find widget. Handle: " << getHandle());
+        }
+
+        WidgetSecuritySettings::Row row;
+        row.Set_security_popup_usage(value);
+
+        WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
+        update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
+        update->Values(row);
+        update->Execute();
+
+        transaction.Commit();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set security popup usage")
+}
+
+void WidgetDAO::setGeolocationUsage(const SettingsType value)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        using namespace DPL::DB::ORM;
+        using namespace DPL::DB::ORM::wrt;
+
+        ScopedTransaction transaction(&WrtDatabase::interface());
+        if (!isWidgetInstalled(getHandle())) {
+            ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
+                "Cannot find widget. Handle: " << getHandle());
+        }
+
+        WidgetSecuritySettings::Row row;
+        row.Set_geolocation_usage(value);
+
+        WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
+        update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
+        update->Values(row);
+        update->Execute();
+
+        transaction.Commit();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set geolocation usage")
+}
+
+void WidgetDAO::setWebNotificationUsage(const SettingsType value)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        using namespace DPL::DB::ORM;
+        using namespace DPL::DB::ORM::wrt;
+
+        ScopedTransaction transaction(&WrtDatabase::interface());
+        if (!isWidgetInstalled(getHandle())) {
+            ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
+                "Cannot find widget. Handle: " << getHandle());
+        }
+
+        WidgetSecuritySettings::Row row;
+        row.Set_web_notification_usage(value);
+
+        WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
+        update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
+        update->Values(row);
+        update->Execute();
+
+        transaction.Commit();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web notification usage")
+}
+
+void WidgetDAO::setWebDatabaseUsage(const SettingsType value)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        using namespace DPL::DB::ORM;
+        using namespace DPL::DB::ORM::wrt;
+
+        ScopedTransaction transaction(&WrtDatabase::interface());
+        if (!isWidgetInstalled(getHandle())) {
+            ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
+                "Cannot find widget. Handle: " << getHandle());
+        }
+
+        WidgetSecuritySettings::Row row;
+        row.Set_web_database_usage(value);
+
+        WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
+        update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
+        update->Values(row);
+        update->Execute();
+
+        transaction.Commit();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web database usage")
+}
+
+void WidgetDAO::setFileSystemUsage(const SettingsType value)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        using namespace DPL::DB::ORM;
+        using namespace DPL::DB::ORM::wrt;
+
+        ScopedTransaction transaction(&WrtDatabase::interface());
+        if (!isWidgetInstalled(getHandle())) {
+            ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
+                "Cannot find widget. Handle: " << getHandle());
+        }
+
+        WidgetSecuritySettings::Row row;
+        row.Set_file_system_usage(value);
+
+        WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
+        update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
+        update->Values(row);
+        update->Execute();
+
+        transaction.Commit();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set filesystem usage")
+}
+
 void WidgetDAO::registerWidget(
         const WidgetPkgName & widgetPkgname,
         const WidgetRegisterInfo &widgetRegInfo,
@@ -128,25 +282,22 @@ void WidgetDAO::registerWidget(
     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
     {
         DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
-        DbWidgetHandle widgetHandle = registerWidgetInternal(widgetPkgname, widgetRegInfo, wacSecurity);
-        registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
-        //TODO: remove construction from handle and move that call to registerWidgetInternal
-        // in new version external fiels should be register together with other informations
+        registerWidgetInternal(widgetPkgname, widgetRegInfo, wacSecurity);
         transaction.Commit();
     }
     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
 }
 
 void WidgetDAO::registerWidget(
-            WrtDB::DbWidgetHandle handle,
-            const WidgetRegisterInfo & widgetRegInfo,
-            const IWacSecurity &wacSecurity)
+        WrtDB::DbWidgetHandle handle,
+        const WidgetRegisterInfo &widgetRegInfo,
+        const IWacSecurity &wacSecurity)
 {
     LogDebug("Registering widget");
     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
     {
         DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
-        registerWidgetInternal(L"", widgetRegInfo, wacSecurity, handle);
+        registerWidgetInternal(generateTizenId(), widgetRegInfo, wacSecurity, handle);
         transaction.Commit();
     }
     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
@@ -169,7 +320,16 @@ DbWidgetHandle WidgetDAO::registerWidget(
     return widgetHandle;
 }
 
-DbWidgetHandle WidgetDAO::registerWidgetInternal(
+WidgetPkgName WidgetDAO::registerWidgetGenerateTizenId(
+            const WidgetRegisterInfo &pWidgetRegisterInfo,
+            const IWacSecurity &wacSecurity)
+{
+    WidgetPkgName widgetPkgName = generateTizenId();
+    registerWidget(widgetPkgName, pWidgetRegisterInfo, wacSecurity);
+    return widgetPkgName;
+}
+
+void WidgetDAO::registerWidgetInternal(
         const WidgetPkgName & widgetName,
         const WidgetRegisterInfo &widgetRegInfo,
         const IWacSecurity &wacSecurity,
@@ -211,7 +371,9 @@ DbWidgetHandle WidgetDAO::registerWidgetInternal(
 
     registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
 
-    return widgetHandle;
+    registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
+
+    registerWidgetSecuritySettings(widgetHandle);
 }
 
 void WidgetDAO::registerOrUpdateWidget(
@@ -225,10 +387,7 @@ void WidgetDAO::registerOrUpdateWidget(
         DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
 
         unregisterWidgetInternal(widgetName);
-        DbWidgetHandle widgetHandle = registerWidgetInternal(widgetName, widgetRegInfo, wacSecurity);
-        registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
-        //TODO: remove construction from handle and move that call to registerWidgetInternal
-        // in new version external fiels should be register together with other informations
+        registerWidgetInternal(widgetName, widgetRegInfo, wacSecurity);
         transaction.Commit();
     }
     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
@@ -257,7 +416,7 @@ void WidgetDAO::registerWidgetExtendedInfo(DbWidgetHandle widgetHandle,
     row.Set_install_time(regInfo.installedTime);
     row.Set_splash_img_src(regInfo.configInfo.splashImgSrc);
     row.Set_background_page(regInfo.configInfo.backgroundPage);
-
+    row.Set_installed_path(regInfo.widgetInstalledPath);
 
     DO_INSERT(row, WidgetExtendedInfo)
 }
@@ -310,7 +469,6 @@ DbWidgetHandle WidgetDAO::registerWidgetInfo(
     }
     row.Set_back_supported(widgetConfigurationInfo.backSupported);
     row.Set_access_network(widgetConfigurationInfo.accessNetwork);
-    row.Set_pkgname(regInfo.pkgname);
     row.Set_pkg_type(regInfo.packagingType.pkgType);
 
     Try
@@ -640,11 +798,6 @@ void WidgetDAO::registerEncryptedResouceInfo(DbWidgetHandle widgetHandle,
     }
 }
 
-void WidgetDAO::registerExternalLocations(const ExternalLocationList & externals)
-{
-    registerExternalLocations(m_widgetHandle, externals);
-}
-
 void WidgetDAO::registerExternalLocations(DbWidgetHandle widgetHandle,
                                           const ExternalLocationList & externals)
 {
@@ -667,6 +820,28 @@ void WidgetDAO::registerExternalLocations(DbWidgetHandle widgetHandle,
     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
 }
 
+void WidgetDAO::registerWidgetSecuritySettings(DbWidgetHandle widgetHandle)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        using namespace DPL::DB::ORM;
+        using namespace DPL::DB::ORM::wrt;
+        DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
+
+        WidgetSecuritySettings::Row row;
+        row.Set_app_id(widgetHandle);
+        row.Set_security_popup_usage(SETTINGS_TYPE_ON);
+        row.Set_geolocation_usage(SETTINGS_TYPE_ON);
+        row.Set_web_notification_usage(SETTINGS_TYPE_ON);
+        row.Set_web_database_usage(SETTINGS_TYPE_ON);
+        row.Set_file_system_usage(SETTINGS_TYPE_ON);
+
+        DO_INSERT(row, WidgetSecuritySettings)
+        transaction.Commit();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
+}
+
 void WidgetDAO::unregisterAllExternalLocations()
 {
     using namespace DPL::DB::ORM;