Replaced all references to contacts_db_delete_record by DeleteContactRecord
authorvivek <vivek.ellur@samsung.com>
Fri, 5 Jul 2013 09:21:47 +0000 (14:51 +0530)
committervivek <vivek.ellur@samsung.com>
Wed, 24 Jul 2013 12:08:22 +0000 (17:38 +0530)
Change-Id: I2ea0b5784d01425d6d49b83824be22273ac1abe3
Signed-off-by: vivek <vivek.ellur@samsung.com>
src/FScl_AddressbookImpl.cpp
src/FScl_AddressbookManagerImpl.cpp

index 30f3716..9113253 100644 (file)
@@ -20,6 +20,7 @@
  * This file contains definitions of @e _AddressbookImpl class.
  */
 #include <contacts.h>
+#include <unique_ptr.h>
 #include <FBaseColIListT.h>
 #include <FBaseColArrayListT.h>
 #include <FBaseResult.h>
@@ -48,6 +49,7 @@
 #include "FScl_UserProfileImpl.h"
 #include "FScl_ContactDbConnector.h"
 
+using namespace std;
 using namespace Tizen::App;
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
@@ -329,7 +331,7 @@ _AddressbookImpl::AddCategory(Category& category)
 
        int recordId = 0;
        contacts_record_h recordHandle = null;
-       std::unique_ptr<IListT<int> > pList(null);
+       unique_ptr<IListT<int> > pList(null);
 
        recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
 
@@ -375,7 +377,7 @@ _AddressbookImpl::AddCategory(Category& category)
        pList.reset(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
        if (pList != null && pList->GetCount() > 0)
        {
-               std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
+               unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
 
                while (pEnum->MoveNext() == E_SUCCESS)
                {
@@ -394,28 +396,10 @@ _AddressbookImpl::AddCategory(Category& category)
 result
 _AddressbookImpl::RemoveContact(RecordId contactId)
 {
-       SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
+       SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contactId is invalid", GetErrorMessage(E_INVALID_ARG));
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
-
-       int intValue = 0;
-       int ret = CONTACTS_ERROR_NONE;
-       contacts_record_h recordHandle = null;
-
-       ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
-
-       contacts_record_get_int(recordHandle, _contacts_simple_contact.id, &intValue);
-
-       contacts_record_destroy(recordHandle, true);
-
-       SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-
-       ret = contacts_db_delete_record(_contacts_contact._uri, contactId);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+       result r = _AddressbookUtil::DeleteContactRecord(_contacts_contact._uri, contactId);
+        SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        return E_SUCCESS;
 }
@@ -440,29 +424,15 @@ _AddressbookImpl::RemoveCategory(RecordId categoryId)
 {
        SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId);
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
-
-       int intValue = 0;
-       int ret = CONTACTS_ERROR_NONE;
-       contacts_record_h recordHandle = null;
-
-       ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The category is not found.");
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
-
-       __ContactsRecordHandle categoryHandle(recordHandle);
-
-       contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
-       SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
+       unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
+        SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        bool isReadOnly = false;
-       contacts_record_get_bool(recordHandle, _contacts_group.is_read_only, &isReadOnly);
+       contacts_record_get_bool(pCategoryRecord.get(), _contacts_group.is_read_only, &isReadOnly);
        SysTryReturn(NID_SCL, !isReadOnly, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified category is a default category.", GetErrorMessage(E_INVALID_ARG));
 
-       ret = contacts_db_delete_record(_contacts_group._uri, categoryId);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       //SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed remove a category.");
+       result r = _AddressbookUtil::DeleteContactRecord(_contacts_group._uri, categoryId);
+        SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        return E_SUCCESS;
 }
@@ -1337,9 +1307,8 @@ _AddressbookImpl::SetUserProfile(const UserProfile* pUserProfile)
                {
                        if (pExistingProfile != null)
                        {
-                               ret = contacts_db_delete_record(_contacts_my_profile._uri, existingRecordId);
-                               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-                               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+                               r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId);
+                               SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
                        }
 
                        contacts_record_h newRecordHandle = null;
@@ -1376,9 +1345,8 @@ _AddressbookImpl::SetUserProfile(const UserProfile* pUserProfile)
                        {
                                if (pExistingProfile != null)
                                {
-                                       ret = contacts_db_delete_record(_contacts_my_profile._uri, existingRecordId);
-                                       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-                                       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+                                       r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId);
+                                       SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
                                }
 
                                contacts_record_h newRecordHandle = null;
@@ -1413,9 +1381,8 @@ _AddressbookImpl::SetUserProfile(const UserProfile* pUserProfile)
        {
                if (pExistingProfile != null)
                {
-                       ret = contacts_db_delete_record(_contacts_my_profile._uri, existingRecordId);
-                       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-                       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+                       r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId);
+                       SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
                }
        }
 
index 0c811ac..4bcf99c 100644 (file)
@@ -444,18 +444,8 @@ _AddressbookManagerImpl::RemoveContact(RecordId contactId)
 {
        SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contactId is invalid.", GetErrorMessage(E_INVALID_ARG));
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
-
-       unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_simple_contact._uri, contactId));
-       SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
-
-       int intValue = 0;
-       contacts_record_get_int(pContactRecord.get(), _contacts_simple_contact.id, &intValue);
-       SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-
-       int ret = contacts_db_delete_record(_contacts_contact._uri, contactId);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+       result r = _AddressbookUtil::DeleteContactRecord(_contacts_contact._uri, contactId);
+       SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        return E_SUCCESS;
 }
@@ -463,24 +453,18 @@ _AddressbookManagerImpl::RemoveContact(RecordId contactId)
 result
 _AddressbookManagerImpl::RemoveCategory(RecordId categoryId)
 {
-       SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId);
+       SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified categoryId is invalid", GetErrorMessage(E_INVALID_ARG));
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
         
        unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
        SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       int intValue = 0;
-       contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
-       SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-
        bool isReadOnly = false;
        contacts_record_get_bool(pCategoryRecord.get(), _contacts_group.is_read_only, &isReadOnly);
        SysTryReturn(NID_SCL, !isReadOnly, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified category is a default category.", GetErrorMessage(E_INVALID_ARG));
 
-       int ret = contacts_db_delete_record(_contacts_group._uri, categoryId);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-//     SysTryReturnResult(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OPERATION_FAILED, "Failed to delete a category.(%d)", ret); // temp
+       result r = _AddressbookUtil::DeleteContactRecord(_contacts_group._uri, categoryId);
+       SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        return E_SUCCESS;
 }
@@ -1316,16 +1300,11 @@ _AddressbookManagerImpl::OnRelationChanged(void)
 result
 _AddressbookManagerImpl::RemovePerson(PersonId personId)
 {
-       SysTryReturnResult(NID_SCL, personId > 0, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
+       SysTryReturnResult(NID_SCL, personId > 0, E_INVALID_ARG, "[%s] Invalid argument is used. ", GetErrorMessage(E_INVALID_ARG));
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
-       SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
-
-       int ret = contacts_db_delete_record(_contacts_person._uri, personId);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The person is not found.");
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred. Failed remove a person.", GetErrorMessage(E_SYSTEM));
+       result r = _AddressbookUtil::DeleteContactRecord(_contacts_person._uri, personId);
+       SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        return E_SUCCESS;
 }