[Contact] Refactoring API structures
authorKisub Song <kisubs.song@samsung.com>
Wed, 22 Aug 2012 13:52:36 +0000 (22:52 +0900)
committerKisub Song <kisubs.song@samsung.com>
Thu, 23 Aug 2012 10:01:35 +0000 (19:01 +0900)
 * Implementation changed
   * Supporting multiple address books with ContactSvcWrapper
 * Refactoring
   * ContactWrapper -> ContactObjectP2AConverter and ContactObjectA2PConverter
     * These handles data more carefully
   * Added ContactsSvcWrapper manages address book objects
   * Added ContactListenerManager manages contact change listener
   * Added ContactUtility contains utility functions
 * UnitTC
   * modified getCategories check rule.

53 files changed:
src/platform/API/Contact/ContactAddress.cpp
src/platform/API/Contact/ContactAddress.h
src/platform/API/Contact/ContactAnniversary.cpp
src/platform/API/Contact/ContactAnniversary.h
src/platform/API/Contact/ContactEmailAddress.cpp
src/platform/API/Contact/ContactEmailAddress.h
src/platform/API/Contact/ContactName.cpp
src/platform/API/Contact/ContactName.h
src/platform/API/Contact/ContactOrganization.cpp
src/platform/API/Contact/ContactOrganization.h
src/platform/API/Contact/ContactPhoneNumber.cpp
src/platform/API/Contact/ContactPhoneNumber.h
src/platform/API/Contact/ContactRef.cpp
src/platform/API/Contact/ContactRef.h
src/platform/API/Contact/ContactTypes.h
src/platform/API/Contact/ContactWebSite.cpp
src/platform/API/Contact/ContactWebSite.h
src/platform/API/Contact/IAddressBook.cpp
src/platform/API/Contact/IAddressBook.h
src/platform/API/Contact/IContact.cpp
src/platform/API/Contact/IContact.h
src/platform/Tizen/Contact/AddressBook.cpp
src/platform/Tizen/Contact/AddressBook.h
src/platform/Tizen/Contact/AddressBookStorage.cpp [deleted file]
src/platform/Tizen/Contact/Contact.cpp
src/platform/Tizen/Contact/ContactDownloadManager.cpp [moved from src/platform/Tizen/Contact/DownloadManager.cpp with 86% similarity]
src/platform/Tizen/Contact/ContactDownloadManager.h [moved from src/platform/Tizen/Contact/DownloadManager.h with 78% similarity]
src/platform/Tizen/Contact/ContactListenerManager.cpp [new file with mode: 0644]
src/platform/Tizen/Contact/ContactListenerManager.h [new file with mode: 0644]
src/platform/Tizen/Contact/ContactManager.cpp
src/platform/Tizen/Contact/ContactManager.h
src/platform/Tizen/Contact/ContactObjectA2PConverter.cpp [new file with mode: 0644]
src/platform/Tizen/Contact/ContactObjectA2PConverter.h [new file with mode: 0644]
src/platform/Tizen/Contact/ContactObjectP2AConverter.cpp [new file with mode: 0644]
src/platform/Tizen/Contact/ContactObjectP2AConverter.h [new file with mode: 0644]
src/platform/Tizen/Contact/ContactSearchEngine.cpp
src/platform/Tizen/Contact/ContactSearchEngine.h
src/platform/Tizen/Contact/ContactUtility.cpp [new file with mode: 0644]
src/platform/Tizen/Contact/ContactUtility.h [new file with mode: 0644]
src/platform/Tizen/Contact/ContactWrapper.cpp [deleted file]
src/platform/Tizen/Contact/ContactWrapper.h [deleted file]
src/platform/Tizen/Contact/ContactsSvcWrapper.cpp [new file with mode: 0755]
src/platform/Tizen/Contact/ContactsSvcWrapper.h [moved from src/platform/Tizen/Contact/AddressBookStorage.h with 83% similarity]
src/platform/Tizen/Contact/config.cmake
src/standards/Tizen/Contact/JSAddressBook.cpp
src/standards/Tizen/Contact/JSContact.cpp
src/standards/Tizen/Contact/JSContactAddress.cpp
src/standards/Tizen/Contact/JSContactAnniversary.cpp
src/standards/Tizen/Contact/JSContactManager.cpp
src/standards/Tizen/Contact/JSContactManager.h
src/standards/Tizen/Contact/JSContactName.cpp
src/standards/Tizen/Contact/JSContactOrganization.cpp
src/standards/Tizen/Contact/JSContactWebSite.cpp

index b5c13af..53bc87a 100755 (executable)
@@ -54,6 +54,12 @@ void ContactAddress::setCountry(const std::string &value)
        m_countryIsSet = true;
 }
 
+void ContactAddress::unsetCountry()
+{
+       m_country = "";
+       m_countryIsSet = false;
+}
+
 bool ContactAddress::getCountryIsSet() const
 {
        return m_countryIsSet;
@@ -70,6 +76,12 @@ void ContactAddress::setRegion(const std::string &value)
        m_regionIsSet = true;
 }
 
+void ContactAddress::unsetRegion()
+{
+       m_region = "";
+       m_regionIsSet = false;
+}
+
 bool ContactAddress::getRegionIsSet() const
 {
        return m_regionIsSet;
@@ -86,6 +98,12 @@ void ContactAddress::setCity(const std::string &value)
        m_cityIsSet = true;
 }
 
+void ContactAddress::unsetCity()
+{
+       m_city = "";
+       m_cityIsSet = false;
+}
+
 bool ContactAddress::getCityIsSet() const
 {
        return m_cityIsSet;
@@ -102,6 +120,12 @@ void ContactAddress::setStreetAddress(const std::string &value)
        m_streetAddressIsSet = true;
 }
 
+void ContactAddress::unsetStreetAddress()
+{
+       m_streetAddress = "";
+       m_streetAddressIsSet = false;
+}
+
 bool ContactAddress::getStreetAddressIsSet() const
 {
        return m_streetAddressIsSet;
@@ -118,6 +142,12 @@ void ContactAddress::setAdditionalInformation(const std::string &value)
        m_additionalInformationIsSet = true;
 }
 
+void ContactAddress::unsetAdditionalInformation()
+{
+       m_additionalInformation = "";
+       m_additionalInformationIsSet = false;
+}
+
 bool ContactAddress::getAdditionalInformationIsSet() const
 {
        return m_additionalInformationIsSet;
@@ -134,6 +164,12 @@ void ContactAddress::setPostalCode(const std::string &value)
        m_postalCodeIsSet = true;
 }
 
+void ContactAddress::unsetPostalCode()
+{
+       m_postalCode = "";
+       m_postalCodeIsSet = false;
+}
+
 bool ContactAddress::getPostalCodeIsSet() const
 {
        return m_postalCodeIsSet;
@@ -232,19 +268,24 @@ std::string ContactAddress::getAsSingleString() const
 void ContactAddress::clear()
 {
        m_country = "";
-       m_region = "";
-       m_city = "";
-       m_streetAddress = "";
-       m_additionalInformation = "";
-       m_postalCode = "";
-       m_types = ContactAddressTypeArrayPtr(new ContactAddressTypeArray());
-
        m_countryIsSet = false;
+
+       m_region = "";
        m_regionIsSet = false;
+
+       m_city = "";
        m_cityIsSet = false;
+
+       m_streetAddress = "";
        m_streetAddressIsSet = false;
+
+       m_additionalInformation = "";
        m_additionalInformationIsSet = false;
+
+       m_postalCode = "";
        m_postalCodeIsSet = false;
+
+       m_types = ContactAddressTypeArrayPtr(new ContactAddressTypeArray());
 }
 
 ContactAddressPtr ContactAddress::clone() const
@@ -252,11 +293,23 @@ ContactAddressPtr ContactAddress::clone() const
        ContactAddressPtr result(new ContactAddress());
 
        result->m_country = m_country;
+       result->m_countryIsSet = m_countryIsSet;
+
        result->m_region = m_region;
+       result->m_regionIsSet = m_regionIsSet;
+
        result->m_city = m_city;
+       result->m_cityIsSet = m_cityIsSet;
+
        result->m_streetAddress = m_streetAddress;
+       result->m_streetAddressIsSet = m_streetAddressIsSet;
+
        result->m_additionalInformation = m_additionalInformation;
+       result->m_additionalInformationIsSet = m_additionalInformationIsSet;
+
        result->m_postalCode = m_postalCode;
+       result->m_postalCodeIsSet = m_postalCodeIsSet;
+
        result->m_types = ContactAddressTypeArrayPtr(new ContactAddressTypeArray());
        ContactAddressTypeArray::iterator typeIter;
        for(typeIter = m_types->begin(); typeIter != m_types->end(); typeIter++)
@@ -265,13 +318,6 @@ ContactAddressPtr ContactAddress::clone() const
                result->m_types->push_back(addressType);
        }
 
-       result->m_countryIsSet = m_countryIsSet;
-       result->m_regionIsSet = m_regionIsSet;
-       result->m_cityIsSet = m_cityIsSet;
-       result->m_streetAddressIsSet = m_streetAddressIsSet;
-       result->m_additionalInformationIsSet = m_additionalInformationIsSet;
-       result->m_postalCodeIsSet = m_postalCodeIsSet;
-
        return result;
 }
 
index f1f99b5..bb57ade 100755 (executable)
@@ -51,26 +51,32 @@ public:
 
        std::string getCountry() const;
        void setCountry(const std::string &value);
+       void unsetCountry();
        bool getCountryIsSet() const;
 
        std::string getRegion() const;
        void setRegion(const std::string &value);
+       void unsetRegion();
        bool getRegionIsSet() const;
 
        std::string getCity() const;
        void setCity(const std::string &value);
+       void unsetCity();
        bool getCityIsSet() const;
 
        std::string getStreetAddress() const;
        void setStreetAddress(const std::string &value);
+       void unsetStreetAddress();
        bool getStreetAddressIsSet() const;
 
        std::string getAdditionalInformation() const;
        void setAdditionalInformation(const std::string &value);
+       void unsetAdditionalInformation();
        bool getAdditionalInformationIsSet() const;
 
        std::string getPostalCode() const;
        void setPostalCode(const std::string &value);
+       void unsetPostalCode();
        bool getPostalCodeIsSet() const;
 
        ContactAddressTypeArrayPtr getTypes() const;
@@ -90,20 +96,25 @@ public:
        ContactAddressPtr clone() const;
 
 private:
-       std::string m_country;
-       std::string m_region;
-       std::string m_city;
-       std::string m_streetAddress;
-       std::string m_additionalInformation;
-       std::string m_postalCode;
-       ContactAddressTypeArrayPtr m_types;
+       std::string     m_country;
+       bool            m_countryIsSet;
+
+       std::string     m_region;
+       bool            m_regionIsSet;
+
+       std::string     m_city;
+       bool            m_cityIsSet;
+
+       std::string     m_streetAddress;
+       bool            m_streetAddressIsSet;
 
-       bool m_countryIsSet;
-       bool m_regionIsSet;
-       bool m_cityIsSet;
-       bool m_streetAddressIsSet;
-       bool m_additionalInformationIsSet;
-       bool m_postalCodeIsSet;
+       std::string     m_additionalInformation;
+       bool            m_additionalInformationIsSet;
+
+       std::string     m_postalCode;
+       bool            m_postalCodeIsSet;
+
+       ContactAddressTypeArrayPtr m_types;
 };
 
 } // Contact
index 24b4920..21c042c 100755 (executable)
@@ -31,6 +31,7 @@ ContactAnniversary::ContactAnniversary() :
                m_dateIsSet(false),
                m_labelIsSet(false)
 {
+       m_date = {0, };
 }
 
 ContactAnniversary::~ContactAnniversary()
@@ -48,6 +49,12 @@ void ContactAnniversary::setDate(const std::tm &value)
        m_dateIsSet = true;
 }
 
+void ContactAnniversary::unsetDate()
+{
+       m_date = {0, };
+       m_dateIsSet = false;
+}
+
 bool ContactAnniversary::getDateIsSet() const
 {
        return m_dateIsSet;
@@ -64,6 +71,12 @@ void ContactAnniversary::setLabel(const std::string &value)
        m_labelIsSet = true;
 }
 
+void ContactAnniversary::unsetLabel()
+{
+       m_label = "";
+       m_labelIsSet = false;
+}
+
 bool ContactAnniversary::getLabelIsSet() const
 {
        return m_labelIsSet;
@@ -72,9 +85,9 @@ bool ContactAnniversary::getLabelIsSet() const
 void ContactAnniversary::clear()
 {
        m_date = {0, };
-       m_label = "";
-
        m_dateIsSet = false;
+
+       m_label = "";
        m_labelIsSet = false;
 }
 
@@ -83,9 +96,9 @@ ContactAnniversaryPtr ContactAnniversary::clone() const
        ContactAnniversaryPtr result(new ContactAnniversary());
 
        result->m_date = m_date;
-       result->m_label = m_label;
-
        result->m_dateIsSet = m_dateIsSet;
+
+       result->m_label = m_label;
        result->m_labelIsSet = m_labelIsSet;
 
        return result;
index c3c4524..98830af 100755 (executable)
@@ -48,21 +48,23 @@ public:
 
        std::tm getDate() const;
        void setDate(const std::tm &value);
+       void unsetDate();
        bool getDateIsSet() const;
 
        std::string getLabel() const;
        void setLabel(const std::string &value);
+       void unsetLabel();
        bool getLabelIsSet() const;
 
        void clear();
        ContactAnniversaryPtr clone() const;
 
 private:
-       std::tm m_date;
-       std::string m_label;
+       std::tm         m_date;
+       bool            m_dateIsSet;
 
-       bool m_dateIsSet;
-       bool m_labelIsSet;
+       std::string     m_label;
+       bool            m_labelIsSet;
 };
 
 } // Contact
index 03ff7fa..25f636d 100755 (executable)
@@ -44,8 +44,14 @@ std::string ContactEmailAddress::getEmail() const
 
 void ContactEmailAddress::setEmail(const std::string &value)
 {
-       m_emailIsSet = true;
        m_email = value;
+       m_emailIsSet = true;
+}
+
+void ContactEmailAddress::unsetEmail()
+{
+       m_email = "";
+       m_emailIsSet = false;
 }
 
 bool ContactEmailAddress::getEmailIsSet() const
@@ -81,9 +87,9 @@ int ContactEmailAddress::getTypesNum() const
 void ContactEmailAddress::clear()
 {
        m_email = "";
-       m_types = ContactEmailAddressTypeArrayPtr(new ContactEmailAddressTypeArray());
-
        m_emailIsSet = false;
+
+       m_types = ContactEmailAddressTypeArrayPtr(new ContactEmailAddressTypeArray());
 }
 
 ContactEmailAddressPtr ContactEmailAddress::clone() const
@@ -91,13 +97,13 @@ ContactEmailAddressPtr ContactEmailAddress::clone() const
        ContactEmailAddressPtr result(new ContactEmailAddress());
 
        result->m_email = m_email;
+       result->m_emailIsSet = m_emailIsSet;
+
        result->m_types = ContactEmailAddressTypeArrayPtr(new ContactEmailAddressTypeArray());
        ContactEmailAddressTypeArray::iterator typeIter;
        for(typeIter = m_types->begin(); typeIter != m_types->end(); typeIter++)
                result->m_types->push_back(*typeIter);
 
-       result->m_emailIsSet = m_emailIsSet;
-
        return result;
 }
 
index 9ee3b9e..3295f78 100755 (executable)
@@ -51,6 +51,7 @@ public:
 
        std::string getEmail() const;
        void setEmail(const std::string &value);
+       void unsetEmail();
        bool getEmailIsSet() const;
 
        ContactEmailAddressTypeArrayPtr getTypes() const;
@@ -63,10 +64,10 @@ public:
        ContactEmailAddressPtr clone() const;
 
 private:
-       std::string m_email;
-       ContactEmailAddressTypeArrayPtr m_types;
+       std::string     m_email;
+       bool            m_emailIsSet;
 
-       bool m_emailIsSet;
+       ContactEmailAddressTypeArrayPtr m_types;
 };
 
 } // Contact
index da81d2b..eec42fb 100755 (executable)
@@ -54,6 +54,12 @@ void ContactName::setPrefix(const std::string &value)
        m_prefixIsSet = true;
 }
 
+void ContactName::unsetPrefix()
+{
+       m_prefix = "";
+       m_prefixIsSet = false;
+}
+
 bool ContactName::getPrefixIsSet() const
 {
        return m_prefixIsSet;
@@ -70,6 +76,12 @@ void ContactName::setFirstName(const std::string &value)
        m_firstNameIsSet = true;
 }
 
+void ContactName::unsetFirstName()
+{
+       m_firstName = "";
+       m_firstNameIsSet = false;
+}
+
 bool ContactName::getFirstNameIsSet() const
 {
        return m_firstNameIsSet;
@@ -86,6 +98,12 @@ void ContactName::setMiddleName(const std::string &value)
        m_middleNameIsSet = true;
 }
 
+void ContactName::unsetMiddleName()
+{
+       m_middleName = "";
+       m_middleNameIsSet = false;
+}
+
 bool ContactName::getMiddleNameIsSet() const
 {
        return m_middleNameIsSet;
@@ -102,6 +120,12 @@ void ContactName::setLastName(const std::string &value)
        m_lastNameIsSet = true;
 }
 
+void ContactName::unsetLastName()
+{
+       m_lastName = "";
+       m_lastNameIsSet = false;
+}
+
 bool ContactName::getLastNameIsSet() const
 {
        return m_lastNameIsSet;
@@ -114,7 +138,10 @@ StringArrayPtr ContactName::getNicknames() const
 
 void ContactName::setNicknames(const StringArrayPtr &value)
 {
-       m_nicknames = value;
+       if(value == NULL)
+               m_nicknames = StringArrayPtr(new StringArray());
+       else
+               m_nicknames = value;
 }
 
 void ContactName::addNickname(const std::string &value)
@@ -122,6 +149,11 @@ void ContactName::addNickname(const std::string &value)
        m_nicknames->push_back(value);
 }
 
+void ContactName::clearNicknames()
+{
+       m_nicknames->clear();
+}
+
 int ContactName::getNicknamesNum() const
 {
        return m_nicknames->size();
@@ -138,6 +170,12 @@ void ContactName::setPhoneticFirstName(const std::string &value)
        m_phoneticFirstNameIsSet = true;
 }
 
+void ContactName::unsetPhoneticFirstName()
+{
+       m_phoneticFirstName = "";
+       m_phoneticFirstNameIsSet = false;
+}
+
 bool ContactName::getPhoneticFirstNameIsSet() const
 {
        return m_phoneticFirstNameIsSet;
@@ -154,6 +192,12 @@ void ContactName::setPhoneticLastName(const std::string &value)
        m_phoneticLastNameIsSet = true;
 }
 
+void ContactName::unsetPhoneticLastName()
+{
+       m_phoneticLastName = "";
+       m_phoneticLastNameIsSet = false;
+}
+
 bool ContactName::getPhoneticLastNameIsSet() const
 {
        return m_phoneticLastNameIsSet;
@@ -170,6 +214,12 @@ void ContactName::setDisplayName(const std::string &value)
        m_displayNameIsSet = true;
 }
 
+void ContactName::unsetDisplayName()
+{
+       m_displayName = "";
+       m_displayNameIsSet = false;
+}
+
 bool ContactName::getDisplayNameIsSet() const
 {
        return m_displayNameIsSet;
@@ -178,20 +228,26 @@ bool ContactName::getDisplayNameIsSet() const
 void ContactName::clear()
 {
        m_prefix = "";
+       m_prefixIsSet = false;
+
        m_firstName = "";
+       m_firstNameIsSet = false;
+
        m_middleName = "";
+       m_middleNameIsSet = false;
+
        m_lastName = "";
+       m_lastNameIsSet = false;
+
        m_nicknames = StringArrayPtr(new StringArray());
-       m_phoneticFirstName = "";
-       m_phoneticLastName = "";
-       m_displayName = "";
 
-       m_prefixIsSet = false;
-       m_firstNameIsSet = false;
-       m_middleNameIsSet = false;
-       m_lastNameIsSet = false;
+       m_phoneticFirstName = "";
        m_phoneticFirstNameIsSet = false;
+
+       m_phoneticLastName = "";
        m_phoneticLastNameIsSet = false;
+
+       m_displayName = "";
        m_displayNameIsSet = false;
 }
 
@@ -200,9 +256,17 @@ ContactNamePtr ContactName::clone() const
        ContactNamePtr result(new ContactName());
 
        result->m_prefix = m_prefix;
+       result->m_prefixIsSet = m_prefixIsSet;
+
        result->m_firstName = m_firstName;
+       result->m_firstNameIsSet = m_firstNameIsSet;
+
        result->m_middleName = m_middleName;
+       result->m_middleNameIsSet = m_middleNameIsSet;
+
        result->m_lastName = m_lastName;
+       result->m_lastNameIsSet = m_lastNameIsSet;
+
        result->m_nicknames = StringArrayPtr(new StringArray());
        StringArray::iterator nicknameIter;
        for(nicknameIter = m_nicknames->begin(); nicknameIter != m_nicknames->end(); nicknameIter++)
@@ -212,15 +276,12 @@ ContactNamePtr ContactName::clone() const
        }
 
        result->m_phoneticFirstName = m_phoneticFirstName;
-       result->m_phoneticLastName = m_phoneticLastName;
-       result->m_displayName = m_displayName;
-
-       result->m_prefixIsSet = m_prefixIsSet;
-       result->m_firstNameIsSet = m_firstNameIsSet;
-       result->m_middleNameIsSet = m_middleNameIsSet;
-       result->m_lastNameIsSet = m_lastNameIsSet;
        result->m_phoneticFirstNameIsSet = m_phoneticFirstNameIsSet;
+
+       result->m_phoneticLastName = m_phoneticLastName;
        result->m_phoneticLastNameIsSet = m_phoneticLastNameIsSet;
+
+       result->m_displayName = m_displayName;
        result->m_displayNameIsSet = m_displayNameIsSet;
 
        return result;
index 4e56ae3..77f6387 100755 (executable)
@@ -47,57 +47,71 @@ public:
 
        std::string getPrefix() const;
        void setPrefix(const std::string &value);
+       void unsetPrefix();
        bool getPrefixIsSet() const;
 
        std::string getFirstName() const;
        void setFirstName(const std::string &value);
+       void unsetFirstName();
        bool getFirstNameIsSet() const;
 
        std::string getMiddleName() const;
        void setMiddleName(const std::string &value);
+       void unsetMiddleName();
        bool getMiddleNameIsSet() const;
 
        std::string getLastName() const;
        void setLastName(const std::string &value);
+       void unsetLastName();
        bool getLastNameIsSet() const;
 
        StringArrayPtr getNicknames() const;
        void setNicknames(const StringArrayPtr &value);
        void addNickname(const std::string& value);
+       void clearNicknames();
        int  getNicknamesNum() const;
 
        std::string getPhoneticFirstName() const;
        void setPhoneticFirstName(const std::string &value);
+       void unsetPhoneticFirstName();
        bool getPhoneticFirstNameIsSet() const;
 
        std::string getPhoneticLastName() const;
        void setPhoneticLastName(const std::string &value);
+       void unsetPhoneticLastName();
        bool getPhoneticLastNameIsSet() const;
 
        std::string getDisplayName() const;
        void setDisplayName(const std::string &value);
+       void unsetDisplayName();
        bool getDisplayNameIsSet() const;
 
        void clear();
        ContactNamePtr clone() const;
 
 private:
-       std::string                 m_prefix;
-       std::string                 m_firstName;
-       std::string                 m_middleName;
-       std::string                 m_lastName;
-       StringArrayPtr              m_nicknames;
-       std::string                 m_phoneticFirstName;
-       std::string                 m_phoneticLastName;
-       std::string                 m_displayName;
-
-       bool m_prefixIsSet;
-       bool m_firstNameIsSet;
-       bool m_middleNameIsSet;
-       bool m_lastNameIsSet;
-       bool m_phoneticFirstNameIsSet;
-       bool m_phoneticLastNameIsSet;
-       bool m_displayNameIsSet;
+       std::string     m_prefix;
+       bool            m_prefixIsSet;
+
+       std::string     m_firstName;
+       bool            m_firstNameIsSet;
+
+       std::string     m_middleName;
+       bool            m_middleNameIsSet;
+
+       std::string     m_lastName;
+       bool            m_lastNameIsSet;
+
+       StringArrayPtr  m_nicknames;
+
+       std::string     m_phoneticFirstName;
+       bool            m_phoneticFirstNameIsSet;
+
+       std::string     m_phoneticLastName;
+       bool            m_phoneticLastNameIsSet;
+
+       std::string     m_displayName;
+       bool            m_displayNameIsSet;
 };
 
 } // Contact
index 5d5528c..8b5dac9 100755 (executable)
@@ -51,6 +51,12 @@ void ContactOrganization::setName(const std::string &value)
        m_nameIsSet = true;
 }
 
+void ContactOrganization::unsetName()
+{
+       m_name = "";
+       m_nameIsSet = false;
+}
+
 bool ContactOrganization::getNameIsSet() const
 {
        return m_nameIsSet;
@@ -67,6 +73,12 @@ void ContactOrganization::setDepartment(const std::string &value)
        m_departmentIsSet = true;
 }
 
+void ContactOrganization::unsetDepartment()
+{
+       m_department = "";
+       m_departmentIsSet = false;
+}
+
 bool ContactOrganization::getDepartmentIsSet() const
 {
        return m_departmentIsSet;
@@ -83,6 +95,12 @@ void ContactOrganization::setTitle(const std::string &value)
        m_titleIsSet = true;
 }
 
+void ContactOrganization::unsetTitle()
+{
+       m_title = "";
+       m_titleIsSet = false;
+}
+
 bool ContactOrganization::getTitleIsSet() const
 {
        return m_titleIsSet;
@@ -99,6 +117,12 @@ void ContactOrganization::setRole(const std::string &value)
        m_roleIsSet = true;
 }
 
+void ContactOrganization::unsetRole()
+{
+       m_role = "";
+       m_roleIsSet = false;
+}
+
 bool ContactOrganization::getRoleIsSet() const
 {
        return m_roleIsSet;
@@ -115,6 +139,12 @@ void ContactOrganization::setLogoURI(const std::string &value)
        m_logoURIIsSet = true;
 }
 
+void ContactOrganization::unsetLogoURI()
+{
+       m_logoURI = "";
+       m_logoURIIsSet = false;
+}
+
 bool ContactOrganization::getLogoURIIsSet() const
 {
        return m_logoURIIsSet;
@@ -123,15 +153,18 @@ bool ContactOrganization::getLogoURIIsSet() const
 void ContactOrganization::clear()
 {
        m_name = "";
-       m_department = "";
-       m_title = "";
-       m_role = "";
-       m_logoURI = "";
-
        m_nameIsSet = false;
+
+       m_department = "";
        m_departmentIsSet = false;
+
+       m_title = "";
        m_titleIsSet = false;
+
+       m_role = "";
        m_roleIsSet = false;
+
+       m_logoURI = "";
        m_logoURIIsSet = false;
 }
 
@@ -140,15 +173,18 @@ ContactOrganizationPtr ContactOrganization::clone() const
        ContactOrganizationPtr result(new ContactOrganization());
 
        result->m_name = m_name;
-       result->m_department = m_department;
-       result->m_title = m_title;
-       result->m_role = m_role;
-       result->m_logoURI = m_logoURI;
-
        result->m_nameIsSet = m_nameIsSet;
+
+       result->m_department = m_department;
        result->m_departmentIsSet = m_departmentIsSet;
+
+       result->m_title = m_title;
        result->m_titleIsSet = m_titleIsSet;
+
+       result->m_role = m_role;
        result->m_roleIsSet = m_roleIsSet;
+
+       result->m_logoURI = m_logoURI;
        result->m_logoURIIsSet = m_logoURIIsSet;
 
        return result;
index 2cd1949..49c8e71 100755 (executable)
@@ -46,39 +46,47 @@ public:
 
        std::string getName() const;
        void setName(const std::string &value);
+       void unsetName();
        bool getNameIsSet() const;
 
        std::string getDepartment() const;
        void setDepartment(const std::string &value);
+       void unsetDepartment();
        bool getDepartmentIsSet() const;
 
        std::string getTitle() const;
        void setTitle(const std::string &value);
+       void unsetTitle();
        bool getTitleIsSet() const;
 
        std::string getRole() const;
        void setRole(const std::string &value);
+       void unsetRole();
        bool getRoleIsSet() const;
 
        std::string getLogoURI() const;
        void setLogoURI(const std::string &value);
+       void unsetLogoURI();
        bool getLogoURIIsSet() const;
 
        void clear();
        ContactOrganizationPtr clone() const;
 
 private:
-       std::string m_name;
-       std::string m_department;
-       std::string m_title;
-       std::string m_role;
-       std::string m_logoURI;
-
-       bool m_nameIsSet;
-       bool m_departmentIsSet;
-       bool m_titleIsSet;
-       bool m_roleIsSet;
-       bool m_logoURIIsSet;
+       std::string     m_name;
+       bool            m_nameIsSet;
+
+       std::string     m_department;
+       bool            m_departmentIsSet;
+
+       std::string     m_title;
+       bool            m_titleIsSet;
+
+       std::string     m_role;
+       bool            m_roleIsSet;
+
+       std::string     m_logoURI;
+       bool            m_logoURIIsSet;
 };
 
 } // Contact
index 658eebd..51c6ce9 100755 (executable)
@@ -46,8 +46,14 @@ std::string ContactPhoneNumber::getNumber() const
 
 void ContactPhoneNumber::setNumber(const std::string &value)
 {
-       m_numberIsSet = true;
        m_number = value;
+       m_numberIsSet = true;
+}
+
+void ContactPhoneNumber::unsetNumber()
+{
+       m_number = "";
+       m_numberIsSet = false;
 }
 
 bool ContactPhoneNumber::getNumberIsSet() const
@@ -83,9 +89,9 @@ int ContactPhoneNumber::getTypesNum() const
 void ContactPhoneNumber::clear()
 {
        m_number = "";
-       m_types = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
-
        m_numberIsSet = false;
+
+       m_types = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
 }
 
 ContactPhoneNumberPtr ContactPhoneNumber::clone() const
@@ -93,6 +99,8 @@ ContactPhoneNumberPtr ContactPhoneNumber::clone() const
        ContactPhoneNumberPtr result(new ContactPhoneNumber());
 
        result->m_number = m_number;
+       result->m_numberIsSet = m_numberIsSet;
+
        result->m_types = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
        ContactPhoneNumberTypeArray::iterator typeIter;
        for(typeIter = m_types->begin(); typeIter != m_types->end(); typeIter++)
@@ -101,8 +109,6 @@ ContactPhoneNumberPtr ContactPhoneNumber::clone() const
                result->m_types->push_back(type);
        }
 
-       result->m_numberIsSet = m_numberIsSet;
-
        return result;
 }
 
index 4f36254..93de741 100755 (executable)
@@ -52,6 +52,7 @@ public:
 
        std::string getNumber() const;
        void setNumber(const std::string &value);
+       void unsetNumber();
        bool getNumberIsSet() const;
 
        ContactPhoneNumberTypeArrayPtr getTypes() const;
@@ -64,10 +65,10 @@ public:
        ContactPhoneNumberPtr clone() const;
 
 private:
-       std::string m_number;
-       ContactPhoneNumberTypeArrayPtr m_types;
+       std::string     m_number;
+       bool            m_numberIsSet;
 
-       bool m_numberIsSet;
+       ContactPhoneNumberTypeArrayPtr m_types;
 };
 
 } // Contact
index 81342b6..19536f9 100755 (executable)
@@ -88,9 +88,9 @@ void ContactRef::setContactId(const int value)
 void ContactRef::clear()
 {
        m_addressBookId = "";
-       m_contactId = "";
-
        m_addressBookIdIsSet = false;
+
+       m_contactId = "";
        m_contactIdIsSet = false;
 }
 
@@ -99,9 +99,9 @@ ContactRefPtr ContactRef::clone()
        ContactRefPtr result(new ContactRef());
 
        result->m_addressBookId = m_addressBookId;
-       result->m_contactId = m_contactId;
-
        result->m_addressBookIdIsSet = m_addressBookIdIsSet;
+
+       result->m_contactId = m_contactId;
        result->m_contactIdIsSet = m_contactIdIsSet;
 
        return result;
index 73bcbcc..c8a544b 100755 (executable)
@@ -60,11 +60,11 @@ public:
        virtual ContactRefPtr clone();
 
 protected:
-       std::string                 m_addressBookId;
-       std::string                 m_contactId;
+       std::string     m_addressBookId;
+       bool            m_addressBookIdIsSet;
 
-       bool m_addressBookIdIsSet;
-       bool m_contactIdIsSet;
+       std::string     m_contactId;
+       bool            m_contactIdIsSet;
 };
 
 } // Contact
index 79c3de6..c7c8ab8 100755 (executable)
@@ -75,13 +75,6 @@ enum ContactWebSiteType
        WEBSITE_TYPE_BLOG
 };
 
-enum ContactAddressBookType
-{
-       //SIM_ADDRESS_BOOK = 0x0000,
-       DEVICE_ADDRESS_BOOK = 0x000F,
-       PHONE_ADDRESS_BOOK = 0x00FF
-};
-
 enum ContactVCardFormat
 {
        VCARD_21_FORMAT,
index 30670db..b09b420 100755 (executable)
@@ -48,6 +48,12 @@ void ContactWebSite::setUrl(const std::string &value)
        m_urlIsSet = true;
 }
 
+void ContactWebSite::unsetUrl()
+{
+       m_url = "";
+       m_urlIsSet = false;
+}
+
 bool ContactWebSite::getUrlIsSet() const
 {
        return m_urlIsSet;
@@ -64,6 +70,12 @@ void ContactWebSite::setType(const ContactWebSiteType value)
        m_typeIsSet = true;
 }
 
+void ContactWebSite::unsetType()
+{
+       m_type = WEBSITE_TYPE_HOMEPAGE;
+       m_typeIsSet = false;
+}
+
 bool ContactWebSite::getTypeIsSet() const
 {
        return m_typeIsSet;
@@ -72,9 +84,9 @@ bool ContactWebSite::getTypeIsSet() const
 void ContactWebSite::clear()
 {
        m_url = "";
-       m_type = WEBSITE_TYPE_HOMEPAGE;
-
        m_urlIsSet = false;
+
+       m_type = WEBSITE_TYPE_HOMEPAGE;
        m_typeIsSet = false;
 }
 
@@ -83,9 +95,9 @@ ContactWebSitePtr ContactWebSite::clone() const
        ContactWebSitePtr result(new ContactWebSite());
 
        result->m_url = m_url;
-       result->m_type = m_type;
-
        result->m_urlIsSet = m_urlIsSet;
+
+       result->m_type = m_type;
        result->m_typeIsSet = m_typeIsSet;
 
        return result;
index 4b81cea..1066b1b 100755 (executable)
@@ -47,10 +47,12 @@ public:
 
        std::string getUrl() const;
        void setUrl(const std::string &value);
+       void unsetUrl();
        bool getUrlIsSet() const;
 
        ContactWebSiteType getType() const;
        void setType(const ContactWebSiteType value);
+       void unsetType();
        bool getTypeIsSet() const;
 
        void clear();
@@ -58,10 +60,10 @@ public:
 
 private:
        std::string         m_url;
-       ContactWebSiteType          m_type;
+       bool            m_urlIsSet;
 
-       bool m_urlIsSet;
-       bool m_typeIsSet;
+       ContactWebSiteType          m_type;
+       bool            m_typeIsSet;
 };
 
 } // Contact
index 8f820ad..80d88ae 100755 (executable)
@@ -30,7 +30,7 @@ namespace Contact {
 
 using namespace WrtDeviceApis::Commons;
 
-IAddressBook::IAddressBook(AddressBookType type) :
+IAddressBook::IAddressBook() :
        //initialize all receivers to work on CONTACT_THREAD thread
        EventRequestReceiver< EventAddressBookGet >(ThreadEnum::CONTACT_THREAD),
        EventRequestReceiver< EventAddressBookAdd >(ThreadEnum::CONTACT_THREAD),
@@ -42,8 +42,7 @@ IAddressBook::IAddressBook(AddressBookType type) :
        EventRequestReceiver< EventAddressBookFind >(ThreadEnum::CONTACT_THREAD),
        EventRequestReceiver< EventAddressBookGetCategories >(ThreadEnum::CONTACT_THREAD),
        EventRequestReceiver< EventAddressBookAddChangeListener >(ThreadEnum::CONTACT_THREAD),
-       EventRequestReceiver< EventAddressBookRemoveChangeListener >(ThreadEnum::CONTACT_THREAD),
-       m_bookType(type)
+       EventRequestReceiver< EventAddressBookRemoveChangeListener >(ThreadEnum::CONTACT_THREAD)
 {
        //Nothing to do
        LogDebug("entered");
@@ -55,12 +54,6 @@ IAddressBook::~IAddressBook()
 //     LogDebug("entered");
 }
 
-IAddressBook::AddressBookType IAddressBook::getType() const
-{
-       //return address book type: sim or device
-       return m_bookType;
-}
-
 void IAddressBook::get(const EventAddressBookGetPtr &event)
 {
        //post event to PLATFORM implementation
index e6350f0..bfe330f 100755 (executable)
@@ -67,13 +67,7 @@ class IAddressBook :
        public IContactEventPrivateData
 {
 public:
-       typedef enum
-       {
-           SIMBook,
-           PhoneBook
-       } AddressBookType;
-
-       explicit IAddressBook(AddressBookType type);
+       explicit IAddressBook();
        virtual ~IAddressBook();
 
        virtual void get(const EventAddressBookGetPtr &event);
@@ -88,17 +82,16 @@ public:
        virtual void addChangeListener(const EventAddressBookAddChangeListenerPtr &event);
        virtual void removeChangeListener(const EventAddressBookRemoveChangeListenerPtr &event);
 
-       virtual AddressBookType    getType() const;
        virtual std::string getId() const = 0;
        virtual void        setId(const std::string &value) = 0;
        virtual std::string getName() const = 0;
        virtual void        setName(const std::string &value) = 0;
+       virtual std::string getAccountId() const = 0;
+       virtual void        setAccountId(const std::string &value) = 0;
        virtual bool        getReadOnly() const = 0;
        virtual void        setReadOnly(const bool &value) = 0;
 
 protected:
-       AddressBookType m_bookType;
-
        virtual void    OnRequestReceived(const EventAddressBookGetPtr &event) = 0;
        virtual void    OnRequestReceived(const EventAddressBookAddPtr &event) = 0;
        virtual void    OnRequestReceived(const EventAddressBookAddBatchPtr &event) = 0;
index 1f6dfdb..cbac552 100755 (executable)
@@ -30,26 +30,24 @@ namespace Api {
 namespace Contact {
 
 IContact::IContact() :
-               m_isFavorite(false),
                m_idIsSet(false),
                m_addressBookIdIsSet(false),
-               m_accountIdIsSet(false),
                m_lastUpdatedIsSet(false),
-               m_nameIsSet(false),
                m_photoURIIsSet(false),
                m_birthdayIsSet(false),
-               m_organizationIsSet(false),
                m_noteIsSet(false),
                m_ringtoneURIIsSet(false)
 {
-       m_name = ContactNamePtr(new ContactName());
+       m_lastUpdated = {0, };
+       m_name = ContactNamePtr(NULL);
        m_addresses = ContactAddressArrayPtr(new ContactAddressArray());
        m_phoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray());
        m_emails = ContactEmailAddressArrayPtr(new ContactEmailAddressArray());
        m_birthday = {0, };
        m_anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray());
-       m_organization = ContactOrganizationPtr(new ContactOrganization());
+       m_organization = ContactOrganizationPtr(NULL);
        m_urls = ContactWebSiteArrayPtr(new ContactWebSiteArray());
+       m_isFavorite = false;
        m_categories = StringArrayPtr(new StringArray());
 }
 
@@ -68,11 +66,6 @@ void IContact::setId(const std::string value)
        m_idIsSet = true;
 }
 
-bool IContact::getIdIsSet() const
-{
-       return m_idIsSet;
-}
-
 void IContact::setId(const int value)
 {
        std::stringstream oss;
@@ -81,6 +74,17 @@ void IContact::setId(const int value)
        m_idIsSet = true;
 }
 
+void IContact::unsetId()
+{
+       m_id = "";
+       m_idIsSet = false;
+}
+
+bool IContact::getIdIsSet() const
+{
+       return m_idIsSet;
+}
+
 std::string IContact::getAddressBookId() const
 {
        return m_addressBookId;
@@ -92,11 +96,6 @@ void IContact::setAddressBookId(const std::string value)
        m_addressBookIdIsSet = true;
 }
 
-bool IContact::getAddressBookIdIsSet() const
-{
-       return m_addressBookIdIsSet;
-}
-
 void IContact::setAddressBookId(const int value)
 {
        std::stringstream oss;
@@ -105,28 +104,15 @@ void IContact::setAddressBookId(const int value)
        m_addressBookIdIsSet = true;
 }
 
-std::string IContact::getAccountId() const
-{
-       return m_accountId;
-}
-
-void IContact::setAccountId(const std::string value)
+void IContact::unsetAddressBookId()
 {
-       m_accountId = value;
-       m_accountIdIsSet = true;
-}
-
-bool IContact::getAccountIdIsSet() const
-{
-       return m_accountIdIsSet;
+       m_addressBookId = "";
+       m_addressBookIdIsSet = false;
 }
 
-void IContact::setAccountId(const int value)
+bool IContact::getAddressBookIdIsSet() const
 {
-       std::stringstream oss;
-       oss << value;
-       m_accountId = oss.str();
-       m_accountIdIsSet = true;
+       return m_addressBookIdIsSet;
 }
 
 std::tm IContact::getLastUpdated() const
@@ -140,6 +126,12 @@ void IContact::setLastUpdated(const std::tm &value)
        m_lastUpdatedIsSet = true;
 }
 
+void IContact::unsetLastUpdated()
+{
+       m_lastUpdated = {0, };
+       m_lastUpdatedIsSet = false;
+}
+
 bool IContact::getLastUpdatedIsSet() const
 {
        return m_lastUpdatedIsSet;
@@ -153,12 +145,11 @@ ContactNamePtr IContact::getName() const
 void IContact::setName(const ContactNamePtr &value)
 {
        m_name = value;
-       m_nameIsSet = true;
 }
 
-bool IContact::getNameIsSet() const
+void IContact::unsetName()
 {
-       return m_nameIsSet;
+       m_name = ContactNamePtr(NULL);
 }
 
 ContactAddressArrayPtr IContact::getAddresses() const
@@ -168,7 +159,10 @@ ContactAddressArrayPtr IContact::getAddresses() const
 
 void IContact::setAddresses(const ContactAddressArrayPtr &value)
 {
-       m_addresses = value;
+       if(value == NULL)
+               m_addresses = ContactAddressArrayPtr(new ContactAddressArray());
+       else
+               m_addresses = value;
 }
 
 void IContact::addAddress(const ContactAddressPtr &value)
@@ -176,6 +170,11 @@ void IContact::addAddress(const ContactAddressPtr &value)
        m_addresses->push_back(value);
 }
 
+void IContact::clearAddresses()
+{
+       m_addresses->clear();
+}
+
 int IContact::getAddressesNum() const
 {
        return m_addresses->size();
@@ -192,6 +191,12 @@ void IContact::setPhotoURI(const std::string &value)
        m_photoURIIsSet = true;
 }
 
+void IContact::unsetPhotoURI()
+{
+       m_photoURI = "";
+       m_photoURIIsSet = false;
+}
+
 bool IContact::getPhotoURIIsSet() const
 {
        return m_photoURIIsSet;
@@ -204,7 +209,10 @@ ContactPhoneNumberArrayPtr IContact::getPhoneNumbers() const
 
 void IContact::setPhoneNumbers(const ContactPhoneNumberArrayPtr &value)
 {
-       m_phoneNumbers = value;
+       if(value == NULL)
+               m_phoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray());
+       else
+               m_phoneNumbers = value;
 }
 
 void IContact::addPhoneNumber(const ContactPhoneNumberPtr &value)
@@ -212,6 +220,11 @@ void IContact::addPhoneNumber(const ContactPhoneNumberPtr &value)
        m_phoneNumbers->push_back(value);
 }
 
+void IContact::clearPhoneNumbers()
+{
+       m_phoneNumbers->clear();
+}
+
 int IContact::getPhoneNumbersNum() const
 {
        return m_phoneNumbers->size();
@@ -222,14 +235,22 @@ ContactEmailAddressArrayPtr IContact::getEmails() const
        return m_emails;
 }
 
+void IContact::setEmails(const ContactEmailAddressArrayPtr &value)
+{
+       if(value == NULL)
+               m_emails = ContactEmailAddressArrayPtr(new ContactEmailAddressArray());
+       else
+               m_emails = value;
+}
+
 void IContact::addEmail(const ContactEmailAddressPtr& value)
 {
        m_emails->push_back(value);
 }
 
-void IContact::setEmails(const ContactEmailAddressArrayPtr &value)
+void IContact::clearEmails()
 {
-       m_emails = value;
+       m_emails->clear();
 }
 
 int IContact::getEmailsNum() const
@@ -248,6 +269,12 @@ void IContact::setBirthday(const std::tm &value)
        m_birthdayIsSet = true;
 }
 
+void IContact::unsetBirthday()
+{
+       m_birthday = {0, };
+       m_birthdayIsSet = false;
+}
+
 bool IContact::getBirthdayIsSet() const
 {
        return m_birthdayIsSet;
@@ -260,7 +287,10 @@ ContactAnniversaryArrayPtr IContact::getAnniversaries() const
 
 void IContact::setAnniversaries(const ContactAnniversaryArrayPtr &value)
 {
-       m_anniversaries = value;
+       if(value == NULL)
+               m_anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray());
+       else
+               m_anniversaries = value;
 }
 
 void IContact::addAnniversary(const ContactAnniversaryPtr &value)
@@ -268,6 +298,11 @@ void IContact::addAnniversary(const ContactAnniversaryPtr &value)
        m_anniversaries->push_back(value);
 }
 
+void IContact::clearAnniversaries()
+{
+       m_anniversaries->clear();
+}
+
 int IContact::getAnniversariesNum() const
 {
        return m_anniversaries->size();
@@ -281,12 +316,11 @@ ContactOrganizationPtr IContact::getOrganization() const
 void IContact::setOrganization(const ContactOrganizationPtr &value)
 {
        m_organization = value;
-       m_organizationIsSet = true;
 }
 
-bool IContact::getOrganizationIsSet() const
+void IContact::unsetOrganization()
 {
-       return m_organizationIsSet;
+       m_organization = ContactOrganizationPtr(NULL);
 }
 
 std::string IContact::getNote() const
@@ -300,6 +334,12 @@ void IContact::setNote(const std::string &value)
        m_noteIsSet = true;
 }
 
+void IContact::unsetNote()
+{
+       m_note = "";
+       m_noteIsSet = false;
+}
+
 bool IContact::getNoteIsSet() const
 {
        return m_noteIsSet;
@@ -312,7 +352,10 @@ ContactWebSiteArrayPtr IContact::getUrls() const
 
 void IContact::setUrls(const ContactWebSiteArrayPtr &value)
 {
-       m_urls = value;
+       if(value == NULL)
+               m_urls = ContactWebSiteArrayPtr(new ContactWebSiteArray());
+       else
+               m_urls = value;
 }
 
 void IContact::addUrl(const ContactWebSitePtr &value)
@@ -320,6 +363,11 @@ void IContact::addUrl(const ContactWebSitePtr &value)
        m_urls->push_back(value);
 }
 
+void IContact::clearUrls()
+{
+       m_urls->clear();
+}
+
 int IContact::getUrlsNum() const
 {
        return m_urls->size();
@@ -340,17 +388,23 @@ std::string IContact::getRingtoneURI() const
        return m_ringtoneURI;
 }
 
-bool IContact::getRingtoneURIIsSet() const
-{
-       return m_ringtoneURIIsSet;
-}
-
 void IContact::setRingtoneURI(const std::string &value)
 {
        m_ringtoneURI = value;
        m_ringtoneURIIsSet = true;
 }
 
+void IContact::unsetRingtoneURI()
+{
+       m_ringtoneURI = "";
+       m_ringtoneURIIsSet = false;
+}
+
+bool IContact::getRingtoneURIIsSet() const
+{
+       return m_ringtoneURIIsSet;
+}
+
 StringArrayPtr IContact::getCategories() const
 {
        return m_categories;
@@ -358,7 +412,10 @@ StringArrayPtr IContact::getCategories() const
 
 void IContact::setCategories(const StringArrayPtr &value)
 {
-       m_categories = value;
+       if(value == NULL)
+               m_categories = StringArrayPtr(new StringArray());
+       else
+               m_categories = value;
 }
 
 void IContact::addCategory(const std::string &value)
@@ -366,6 +423,11 @@ void IContact::addCategory(const std::string &value)
        m_categories->push_back(value);
 }
 
+void IContact::clearCategories()
+{
+       m_categories->clear();
+}
+
 int IContact::getCategoriesNum() const
 {
        return m_categories->size();
@@ -374,17 +436,27 @@ int IContact::getCategoriesNum() const
 void IContact::copy(const ContactPtr &contact)
 {
        m_id = contact->m_id;
+       m_idIsSet = contact->m_idIsSet;
+
        m_addressBookId = contact->m_addressBookId;
-       m_accountId = contact->m_accountId;
+       m_addressBookIdIsSet = contact->m_addressBookIdIsSet;
+
        m_lastUpdated = contact->m_lastUpdated;
+       m_lastUpdatedIsSet = contact->m_lastUpdatedIsSet;
+
+       if(contact->m_name == NULL)
+               m_name = ContactNamePtr(NULL);
+       else
+               m_name = contact->m_name->clone();
 
-       m_name = contact->m_name->clone();
        m_addresses = ContactAddressArrayPtr(new ContactAddressArray());
        ContactAddressArray::iterator contactAddressIter;
        for(contactAddressIter = contact->m_addresses->begin(); contactAddressIter != contact->m_addresses->end(); contactAddressIter++)
                m_addresses->push_back((*contactAddressIter)->clone());
 
        m_photoURI = contact->m_photoURI;
+       m_photoURIIsSet = contact->m_photoURIIsSet;
+
        m_phoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray());
        ContactPhoneNumberArray::iterator contactPhoneNumberIter;
        for(contactPhoneNumberIter = contact->m_phoneNumbers->begin(); contactPhoneNumberIter != contact->m_phoneNumbers->end(); contactPhoneNumberIter++)
@@ -396,13 +468,20 @@ void IContact::copy(const ContactPtr &contact)
                m_emails->push_back((*contactEmailAddressIter)->clone());
 
        m_birthday = contact->m_birthday;
+       m_birthdayIsSet = contact->m_birthdayIsSet;
+
        m_anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray());
        ContactAnniversaryArray::iterator contactAnniversaryIter;
        for(contactAnniversaryIter = contact->m_anniversaries->begin(); contactAnniversaryIter != contact->m_anniversaries->end(); contactAnniversaryIter++)
                m_anniversaries->push_back((*contactAnniversaryIter)->clone());
 
-       m_organization = contact->m_organization->clone();
+       if(contact->m_organization == NULL)
+               m_organization = ContactOrganizationPtr(NULL);
+       else
+               m_organization = contact->m_organization->clone();
+
        m_note = contact->m_note;
+       m_noteIsSet = contact->m_noteIsSet;
 
        m_urls = ContactWebSiteArrayPtr(new ContactWebSiteArray());
        ContactWebSiteArray::iterator contactWebSiteIter;
@@ -410,7 +489,10 @@ void IContact::copy(const ContactPtr &contact)
                m_urls->push_back((*contactWebSiteIter)->clone());
 
        m_isFavorite = contact->m_isFavorite;
+
        m_ringtoneURI = contact->m_ringtoneURI;
+       m_ringtoneURIIsSet = contact->m_ringtoneURIIsSet;
+
        m_categories = StringArrayPtr(new StringArray());
        StringArray::iterator categoryIter;
        for(categoryIter = contact->m_categories->begin(); categoryIter != contact->m_categories->end(); categoryIter++)
@@ -418,67 +500,65 @@ void IContact::copy(const ContactPtr &contact)
                std::string category = *categoryIter;
                m_categories->push_back(category);
        }
-
-       m_idIsSet = contact->m_idIsSet;
-       m_addressBookIdIsSet = contact->m_addressBookIdIsSet;
-       m_accountIdIsSet = contact->m_accountIdIsSet;
-       m_lastUpdatedIsSet = contact->m_lastUpdatedIsSet;
-       m_nameIsSet = contact->m_nameIsSet;
-       m_photoURIIsSet = contact->m_photoURIIsSet;
-       m_birthdayIsSet = contact->m_birthdayIsSet;
-       m_organizationIsSet = contact->m_organizationIsSet;
-       m_noteIsSet = contact->m_noteIsSet;
-       m_ringtoneURIIsSet = contact->m_ringtoneURIIsSet;
 }
 
 void IContact::clear()
 {
        m_id = "";
+       m_idIsSet = false;
+
        m_addressBookId = "";
-       m_accountId = "";
+       m_addressBookIdIsSet = false;
+
        m_lastUpdated = {0, };
-       m_name = ContactNamePtr(new ContactName());
+       m_lastUpdatedIsSet = false;
+
+       m_name = ContactNamePtr(NULL);
+
        m_addresses = ContactAddressArrayPtr(new ContactAddressArray());
+
        m_photoURI = "";
+       m_photoURIIsSet = false;
+
        m_phoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray());
+
        m_emails = ContactEmailAddressArrayPtr(new ContactEmailAddressArray());
+
        m_birthday = {0, };
+       m_birthdayIsSet = false;
+
        m_anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray());
-       m_organization = ContactOrganizationPtr(new ContactOrganization());
+
+       m_organization = ContactOrganizationPtr(NULL);
+
        m_note = "";
+       m_noteIsSet = false;
+
        m_urls = ContactWebSiteArrayPtr(new ContactWebSiteArray());
+
        m_isFavorite = false;
-       m_ringtoneURI = "";
-       m_categories = StringArrayPtr(new StringArray());
 
-       m_idIsSet = false;
-       m_addressBookIdIsSet = false;
-       m_accountIdIsSet = false;
-       m_lastUpdatedIsSet = false;
-       m_nameIsSet = false;
-       m_photoURIIsSet = false;
-       m_birthdayIsSet = false;
-       m_organizationIsSet = false;
-       m_noteIsSet = false;
+       m_ringtoneURI = "";
        m_ringtoneURIIsSet = false;
+
+       m_categories = StringArrayPtr(new StringArray());
 }
 
 ContactPtr IContact::clone() const
 {
        ContactPtr result = ContactFactory::getInstance().createContact();
 
-       result->m_id = "";
-       result->m_addressBookId = "";
-       result->m_accountId = "";
-       result->m_lastUpdated = {0, };
+       if(m_name != NULL)
+               result->m_name = m_name->clone();
 
-       result->m_name = m_name->clone();
        result->m_addresses = ContactAddressArrayPtr(new ContactAddressArray());
        ContactAddressArray::iterator contactAddressIter;
        for(contactAddressIter = m_addresses->begin(); contactAddressIter != m_addresses->end(); contactAddressIter++)
                result->m_addresses->push_back((*contactAddressIter)->clone());
 
        result->m_photoURI = m_photoURI;
+       result->m_photoURIIsSet = m_photoURIIsSet;
+
        result->m_phoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray());
        ContactPhoneNumberArray::iterator contactPhoneNumberIter;
        for(contactPhoneNumberIter = m_phoneNumbers->begin(); contactPhoneNumberIter != m_phoneNumbers->end(); contactPhoneNumberIter++)
@@ -490,13 +570,18 @@ ContactPtr IContact::clone() const
                result->m_emails->push_back((*contactEmailAddressIter)->clone());
 
        result->m_birthday = m_birthday;
+       result->m_birthdayIsSet = m_birthdayIsSet;
+
        result->m_anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray());
        ContactAnniversaryArray::iterator contactAnniversaryIter;
        for(contactAnniversaryIter = m_anniversaries->begin(); contactAnniversaryIter != m_anniversaries->end(); contactAnniversaryIter++)
                result->m_anniversaries->push_back((*contactAnniversaryIter)->clone());
 
-       result->m_organization = m_organization->clone();
+       if(m_organization != NULL)
+               result->m_organization = m_organization->clone();
+
        result->m_note = m_note;
+       result->m_noteIsSet = m_noteIsSet;
 
        result->m_urls = ContactWebSiteArrayPtr(new ContactWebSiteArray());
        ContactWebSiteArray::iterator contactWebSiteIter;
@@ -504,7 +589,10 @@ ContactPtr IContact::clone() const
                result->m_urls->push_back((*contactWebSiteIter)->clone());
 
        result->m_isFavorite = m_isFavorite;
+
        result->m_ringtoneURI = m_ringtoneURI;
+       result->m_ringtoneURIIsSet = m_ringtoneURIIsSet;
+
        result->m_categories = StringArrayPtr(new StringArray());
        StringArray::iterator categoryIter;
        for(categoryIter = m_categories->begin(); categoryIter != m_categories->end(); categoryIter++)
@@ -513,17 +601,6 @@ ContactPtr IContact::clone() const
                result->m_categories->push_back(category);
        }
 
-       result->m_idIsSet = false;
-       result->m_addressBookIdIsSet = false;
-       result->m_accountIdIsSet = false;
-       result->m_lastUpdatedIsSet = false;
-       result->m_nameIsSet = m_nameIsSet;
-       result->m_photoURIIsSet = m_photoURIIsSet;
-       result->m_birthdayIsSet = m_birthdayIsSet;
-       result->m_organizationIsSet = m_organizationIsSet;
-       result->m_noteIsSet = m_noteIsSet;
-       result->m_ringtoneURIIsSet = m_ringtoneURIIsSet;
-
        return result;
 }
 
index 47a9b32..b65f727 100755 (executable)
@@ -63,65 +63,71 @@ public:
        std::string getId() const;
        void setId(const std::string value);
        void setId(const int value);
+       void unsetId();
        bool getIdIsSet() const;
 
        std::string getAddressBookId() const;
        void setAddressBookId(const std::string value);
        void setAddressBookId(const int value);
+       void unsetAddressBookId();
        bool getAddressBookIdIsSet() const;
 
-       std::string getAccountId() const;
-       void setAccountId(const std::string value);
-       void setAccountId(const int value);
-       bool getAccountIdIsSet() const;
-
        std::tm getLastUpdated() const;
        void setLastUpdated(const std::tm &value);
+       void unsetLastUpdated();
        bool getLastUpdatedIsSet() const;
 
        ContactNamePtr getName() const;
        void setName(const ContactNamePtr &value);
-       bool getNameIsSet() const;
+       void unsetName();
 
        ContactAddressArrayPtr getAddresses() const;
        void setAddresses(const ContactAddressArrayPtr &value);
        void addAddress(const ContactAddressPtr &value);
+       void clearAddresses();
        int  getAddressesNum() const;
 
        std::string getPhotoURI() const;
        void setPhotoURI(const std::string &value);
+       void unsetPhotoURI();
        bool getPhotoURIIsSet() const;
 
        ContactPhoneNumberArrayPtr getPhoneNumbers() const;
        void setPhoneNumbers(const ContactPhoneNumberArrayPtr &value);
        void addPhoneNumber(const ContactPhoneNumberPtr &value);
+       void clearPhoneNumbers();
        int  getPhoneNumbersNum() const;
 
        ContactEmailAddressArrayPtr getEmails() const;
        void setEmails(const ContactEmailAddressArrayPtr &value);
        void addEmail(const ContactEmailAddressPtr& value);
+       void clearEmails();
        int  getEmailsNum() const;
 
        std::tm getBirthday() const;
        void setBirthday(const std::tm &value);
+       void unsetBirthday();
        bool getBirthdayIsSet() const;
 
        ContactAnniversaryArrayPtr getAnniversaries() const;
        void setAnniversaries(const ContactAnniversaryArrayPtr &value);
        void addAnniversary(const ContactAnniversaryPtr &value);
+       void clearAnniversaries();
        int  getAnniversariesNum() const;
 
        ContactOrganizationPtr getOrganization() const;
        void setOrganization(const ContactOrganizationPtr &value);
-       bool getOrganizationIsSet() const;
+       void unsetOrganization();
 
        std::string getNote() const;
        void setNote(const std::string &value);
+       void unsetNote();
        bool getNoteIsSet() const;
 
        ContactWebSiteArrayPtr getUrls() const;
        void setUrls(const ContactWebSiteArrayPtr &value);
        void addUrl(const ContactWebSitePtr &value);
+       void clearUrls();
        int  getUrlsNum() const;
 
        bool getIsFavorite() const;
@@ -129,11 +135,13 @@ public:
 
        std::string getRingtoneURI() const;
        void setRingtoneURI(const std::string &value);
+       void unsetRingtoneURI();
        bool getRingtoneURIIsSet() const;
 
        StringArrayPtr getCategories() const;
        void setCategories(const StringArrayPtr &value);
        void addCategory(const std::string &value);
+       void clearCategories();
        int  getCategoriesNum() const;
 
        virtual void copy(const ContactPtr &contact);
@@ -142,33 +150,44 @@ public:
 
 protected:
        std::string                 m_id;
+       bool                        m_idIsSet;
+
        std::string                 m_addressBookId;
-       std::string                 m_accountId;
+       bool                        m_addressBookIdIsSet;
+
        std::tm                     m_lastUpdated;
+       bool                        m_lastUpdatedIsSet;
+
        ContactNamePtr              m_name;
+
        ContactAddressArrayPtr      m_addresses;
+
        std::string                 m_photoURI;
+       bool                        m_photoURIIsSet;
+
        ContactPhoneNumberArrayPtr  m_phoneNumbers;
+
        ContactEmailAddressArrayPtr m_emails;
+
        std::tm                     m_birthday;
+       bool                        m_birthdayIsSet;
+
        ContactAnniversaryArrayPtr  m_anniversaries;
+
        ContactOrganizationPtr      m_organization;
+
        std::string                 m_note;
+       bool                        m_noteIsSet;
+
        ContactWebSiteArrayPtr      m_urls;
+
        bool                        m_isFavorite;
+
        std::string                 m_ringtoneURI;
+       bool                        m_ringtoneURIIsSet;
+
        StringArrayPtr              m_categories;
 
-       bool m_idIsSet;
-       bool m_addressBookIdIsSet;
-       bool m_accountIdIsSet;
-       bool m_lastUpdatedIsSet;
-       bool m_nameIsSet;
-       bool m_photoURIIsSet;
-       bool m_birthdayIsSet;
-       bool m_organizationIsSet;
-       bool m_noteIsSet;
-       bool m_ringtoneURIIsSet;
 };
 
 } // Contact
index f87958e..86dc699 100755 (executable)
 #include <API/Contact/IContact.h>
 #include "AddressBook.h"
 #include "Contact.h"
-#include "ContactWrapper.h"
+#include "ContactObjectA2PConverter.h"
+#include "ContactObjectP2AConverter.h"
 #include "ContactSearchEngine.h"
 #include "ContactFilterValidator.h"
-#include "DownloadManager.h"
+#include "ContactDownloadManager.h"
+#include "ContactUtility.h"
 
 namespace TizenApis {
 namespace Platform {
@@ -49,29 +51,68 @@ using namespace TizenApis::Api::Tizen;
 using namespace WrtDeviceApis::Commons;
 using namespace std;
 
-AddressBook::AddressBook(IAddressBook::AddressBookType changeType) :
-               IAddressBook(changeType),
-               m_name("TEST_ADDRESS_BOOK"),
-               m_watchIdAcc(0)
+AddressBook::AddressBook() :
+               IAddressBook(),
+               m_name("TEST_ADDRESS_BOOK")
 {
     LogDebug("entered");
 }
 
 AddressBook::~AddressBook()
 {
+       if(m_addressBookEmitters.size() != 0)
+       {
+               ContactListenerManagerSingleton::Instance().unregisterAppListChangedCallbacks(this);
+       }
+}
+
+std::string AddressBook::getId() const
+{
+       std::stringstream oss;
+       oss << m_id;
+       return oss.str();
+}
+
+void AddressBook::setId(const std::string &value)
+{
+       std::stringstream oss(value);
+       oss >> m_id;
+}
+
+std::string AddressBook::getAccountId() const
+{
+       std::stringstream oss;
+       oss << m_accountId;
+       return oss.str();
+}
+
+void AddressBook::setAccountId(const std::string &value)
+{
+       std::stringstream oss(value);
+       oss >> m_accountId;
 }
 
 void AddressBook::OnRequestReceived(const EventAddressBookGetPtr &event)
 {
        LogDebug("entered");
 
+       CTSstruct *ctsStruct = NULL;
        Try     {
                if(!event->getIdIsSet())
                        ThrowMsg(InvalidArgumentException, "Invalid contact id");
 
                string contactId = event->getId();
 
-               ContactPtr contact = internalGetById(contactId);
+               int contactIdInt = ContactUtility::strToInt(contactId);
+
+               int errorCode = contacts_svc_get_contact(contactIdInt, &ctsStruct);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       ThrowMsg(NotFoundException, "No contact (id:" << contactIdInt << ")");
+               }
+               ContactObjectP2AConverterPtr contactObjConverter(
+                               new ContactObjectP2AConverter(ctsStruct, false));
+               ContactPtr contact = contactObjConverter->getAbstractContact();
 
                event->setContact(contact);
                event->setResult(true);
@@ -82,7 +123,7 @@ void AddressBook::OnRequestReceived(const EventAddressBookGetPtr &event)
                event->setResult(false);
 
        } Catch (PlatformException) {
-               LogError("Error during deleting contact : " << _rethrown_exception.GetMessage());
+               LogError("Error during getting contact : " << _rethrown_exception.GetMessage());
                event->setExceptionCode(ExceptionCodes::PlatformException);
                event->setResult(false);
 
@@ -96,6 +137,9 @@ void AddressBook::OnRequestReceived(const EventAddressBookGetPtr &event)
                event->setExceptionCode(ExceptionCodes::UnknownException);
                event->setResult(false);
        }
+
+       if(ctsStruct != NULL)
+               contacts_svc_struct_free(ctsStruct);
 }
 
 void AddressBook::OnRequestReceived(const EventAddressBookAddPtr &event)
@@ -119,6 +163,8 @@ void AddressBook::OnRequestReceived(const EventAddressBookAddPtr &event)
                return;
        }
 
+       CTSstruct *ctsStruct = NULL;
+
        Try
        {
                internalAddContact(contact);
@@ -126,26 +172,34 @@ void AddressBook::OnRequestReceived(const EventAddressBookAddPtr &event)
                string id = contact->getId();
                if(id != "")
                {
-                       ContactPtr insertedContact = internalGetById(id);
+                       int idInt = ContactUtility::strToInt(id);
+                       int errorCode = contacts_svc_get_contact(idInt, &ctsStruct);
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               ThrowMsg(PlatformException, "No contact just inserted  (id:" << id << ")");
+                       }
+                       ContactObjectP2AConverterPtr contactObjConverter(
+                                       new ContactObjectP2AConverter(ctsStruct, false));
+                       ContactPtr insertedContact = contactObjConverter->getAbstractContact();
                        contact->copy(insertedContact);
                }
+
+               event->setResult(true);
+               event->setExceptionCode(ExceptionCodes::None);
        }
        Catch (PlatformException) {
                LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
                event->setResult(false);
                event->setExceptionCode(ExceptionCodes::PlatformException);
-               return;
        }
        Catch (Exception) {
                LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
                event->setResult(false);
                event->setExceptionCode(ExceptionCodes::UnknownException);
-               return;
        }
-       //m_latestVersion = get_contact_version();
 
-       event->setResult(true);
-       event->setExceptionCode(ExceptionCodes::None);
+       if(ctsStruct != NULL)
+               contacts_svc_struct_free(ctsStruct);
 }
 
 void AddressBook::OnRequestReceived(const EventAddressBookAddBatchPtr &event)
@@ -168,6 +222,8 @@ void AddressBook::OnRequestReceived(const EventAddressBookAddBatchPtr &event)
                return;
        }
 
+       CTSstruct *ctsStruct = NULL;
+
        Try
        {
                int ret = contacts_svc_begin_trans();
@@ -195,10 +251,21 @@ void AddressBook::OnRequestReceived(const EventAddressBookAddBatchPtr &event)
                        string id = contact->getId();
                        if(id != "")
                        {
-                               ContactPtr insertedContact = internalGetById(id);
+                               int idInt = ContactUtility::strToInt(id);
+                               int errorCode = contacts_svc_get_contact(idInt, &ctsStruct);
+                               if(errorCode != CTS_SUCCESS)
+                               {
+                                       ThrowMsg(PlatformException, "No contact just inserted  (id:" << id << ")");
+                               }
+                               ContactObjectP2AConverterPtr contactObjConverter(
+                                               new ContactObjectP2AConverter(ctsStruct, false));
+                               ContactPtr insertedContact = contactObjConverter->getAbstractContact();
                                contact->copy(insertedContact);
                        }
                }
+
+               event->setResult(true);
+               event->setExceptionCode(ExceptionCodes::None);
        }
        Catch (NotFoundException)
        {
@@ -206,26 +273,22 @@ void AddressBook::OnRequestReceived(const EventAddressBookAddBatchPtr &event)
                LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
                event->setResult(false);
                event->setExceptionCode(ExceptionCodes::NotFoundException);
-               return;
        }
        Catch (PlatformException) {
                contacts_svc_end_trans(false);
                LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
                event->setResult(false);
                event->setExceptionCode(ExceptionCodes::PlatformException);
-               return;
        }
        Catch (Exception) {
                contacts_svc_end_trans(false);
                LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
                event->setResult(false);
                event->setExceptionCode(ExceptionCodes::PlatformException);
-               return;
        }
-       //m_latestVersion = get_contact_version();
 
-       event->setResult(true);
-       event->setExceptionCode(ExceptionCodes::None);
+       if(ctsStruct != NULL)
+               contacts_svc_struct_free(ctsStruct);
 }
 
 void AddressBook::OnRequestReceived(const EventAddressBookUpdatePtr &event)
@@ -607,22 +670,18 @@ void AddressBook::OnRequestReceived(const EventAddressBookAddChangeListenerPtr &
                if(emitter == NULL)
                        ThrowMsg(InvalidArgumentException, "Invalid arguments.");
 
-               DPL::Mutex::ScopedLock lock(&m_addressBookEmittersMutex);
+               //DPL::Mutex::ScopedLock lock(&m_addressBookEmittersMutex);
 
                if(m_addressBookEmitters.size() == 0)
                {
                        LogDebug("Watch registered initially");
 
-                       m_latestVersion = get_contact_version();
-                       contacts_svc_subscribe_change(CTS_SUBSCRIBE_CONTACT_CHANGE,
-                                       contactsSvcContactChangedCallback, reinterpret_cast<void *>(this));
-                       contacts_svc_subscribe_change(CTS_SUBSCRIBE_ADDRESSBOOK_CHANGE,
-                                       refresh_addressbook_list, reinterpret_cast<void *>(this));
+                       ContactListenerManagerSingleton::Instance().registerAppListChangedCallbacks(this, m_id);
                }
 
                m_addressBookEmitters.attach(emitter);
 
-               long id = ++m_watchIdAcc;
+               long id = ContactListenerManagerSingleton::Instance().getWatchIdAndInc();
                m_watchIdMap[id] = emitter->getId();
 
            event->setId(id);
@@ -662,7 +721,7 @@ void AddressBook::OnRequestReceived(const EventAddressBookRemoveChangeListenerPt
                if(m_watchIdMap.find(id) == m_watchIdMap.end())
                        ThrowMsg(NotFoundException, "No watchId : " << id);
 
-               DPL::Mutex::ScopedLock lock(&m_addressBookEmittersMutex);
+               //DPL::Mutex::ScopedLock lock(&m_addressBookEmittersMutex);
                bool success = m_addressBookEmitters.detach(m_watchIdMap[id]);
                if(!success)
                        ThrowMsg(NotFoundException, "No watchId : " << id);
@@ -673,11 +732,7 @@ void AddressBook::OnRequestReceived(const EventAddressBookRemoveChangeListenerPt
                {
                        LogDebug("No watcher is registered. unsubscribing from contact service.");
 
-                       m_latestVersion = 0;
-                       contacts_svc_unsubscribe_change(CTS_SUBSCRIBE_CONTACT_CHANGE,
-                                       contactsSvcContactChangedCallback);
-                       contacts_svc_unsubscribe_change(CTS_SUBSCRIBE_ADDRESSBOOK_CHANGE,
-                                       refresh_addressbook_list);
+                       ContactListenerManagerSingleton::Instance().unregisterAppListChangedCallbacks(this);
                }
 
                event->setResult(true);
@@ -704,6 +759,32 @@ void AddressBook::OnRequestReceived(const EventAddressBookRemoveChangeListenerPt
        }
 }
 
+void AddressBook::onContactEventAdded(TizenApis::Api::Contact::ContactArrayPtr &contacts)
+{
+       EventInfoAddressBookChangeAddedPtr contactsAdded(new EventInfoAddressBookChangeAdded());
+       contactsAdded->setContacts(contacts);
+       EventInfoAddressBookChangePtr event = DPL::StaticPointerCast<EventInfoAddressBookChange>(contactsAdded);
+       EventAddressBookChangeListenerPtr listener(new EventAddressBookChangeListener(event));
+       m_addressBookEmitters.emit(listener);
+}
+
+void AddressBook::onContactEventUpdated(TizenApis::Api::Contact::ContactArrayPtr &contacts)
+{
+       EventInfoAddressBookChangeUpdatedPtr contactsUpdated(new EventInfoAddressBookChangeUpdated());
+       contactsUpdated->setContacts(contacts);
+       EventInfoAddressBookChangePtr event = DPL::StaticPointerCast<EventInfoAddressBookChange>(contactsUpdated);
+       EventAddressBookChangeListenerPtr listener(new EventAddressBookChangeListener(event));
+       m_addressBookEmitters.emit(listener);
+}
+
+void AddressBook::onContactEventRemoved(TizenApis::Api::Contact::StringArrayPtr &contactIds)
+{
+       EventInfoAddressBookChangeRemovedPtr contactsRemoved(new EventInfoAddressBookChangeRemoved());
+       contactsRemoved->setContactIds(contactIds);
+       EventInfoAddressBookChangePtr event = DPL::StaticPointerCast<EventInfoAddressBookChange>(contactsRemoved);
+       EventAddressBookChangeListenerPtr listener(new EventAddressBookChangeListener(event));
+       m_addressBookEmitters.emit(listener);
+}
 
 void AddressBook::internalAddContact(const ContactPtr &newContact)
 {
@@ -714,25 +795,35 @@ void AddressBook::internalAddContact(const ContactPtr &newContact)
        //translate provided path to real filesystem path
        if (newContact->getPhotoURIIsSet())
        {
-               string realPath = DownloadManager::getInstance()->getRealPath(newContact->getPhotoURI());
+               string realPath = ContactDownloadManager::getInstance()->getRealPath(newContact->getPhotoURI());
                if(realPath.length() <= MAXPATHLEN)
                        newContact->setPhotoURI(realPath);
        }
 
+       if (newContact->getRingtoneURIIsSet())
+       {
+               string realPath = ContactDownloadManager::getInstance()->getRealPath(newContact->getRingtoneURI());
+               if(realPath.length() <= MAXPATHLEN)
+                       newContact->setRingtoneURI(realPath);
+       }
+
        DPL::SharedPtr<TizenApis::Platform::Contact::Contact> newContactT =
                        DPL::StaticPointerCast<TizenApis::Platform::Contact::Contact>(newContact);
 
-       ContactWrapperPtr contactWrapper(new ContactWrapper(m_bookType));
+       ContactObjectA2PConverterPtr contactObjConverter(NULL);
 
        CTSstruct* contact = newContactT->getCTSStruct();
        if(contact == NULL)
        {
-               contactWrapper->setAbstractContact(newContact, false);
-               contact = contactWrapper->getPlatformContact();
+               contactObjConverter = ContactObjectA2PConverterPtr(
+                               new ContactObjectA2PConverter(newContact, false) );
+               contact = contactObjConverter->getPlatformContact();
        }
        else
        {
-               contactWrapper->convertAbstractToPlatform(newContact, contact, false);
+               contactObjConverter = ContactObjectA2PConverterPtr(
+                               new ContactObjectA2PConverter(newContact, false, contact) );
+               contact = contactObjConverter->getPlatformContact();
        }
 
        if (!contact)
@@ -753,22 +844,8 @@ void AddressBook::internalAddContact(const ContactPtr &newContact)
        }
        else
        {
-               query_error error_code = QUERY_SUCCESS;
-               int addressBookId = 0;
-               int accountId = 0;
-
-               string accountIdStr = newContact->getAccountId();
-               try {
-                       istringstream iss(accountIdStr);
-                       iss >> accountId;
-               } catch (...) {
-                       LogDebug("accountId changeType is wrong. (id:" << accountIdStr << ")");
-                       accountId = 0;
-               }
-
-               addressBookId = find_addressbook_id(accountId, &error_code);
-               if(error_code != QUERY_SUCCESS)
-                       addressBookId = 0;
+               string addressBookIdStr = newContact->getAddressBookId();
+               int addressBookId = ContactUtility::strToInt(addressBookIdStr);
 
                int id = contacts_svc_insert_contact(addressBookId, contact);
                if (id < 0) {
@@ -795,158 +872,6 @@ void AddressBook::internalDeleteContactById(int id)
                ThrowMsg(PlatformException, "Error during executing contacts_svc_delete_contact()");
 }
 
-ContactPtr AddressBook::internalGetById(const std::string &contactId)
-{
-       if(contactId == "")
-               ThrowMsg(InvalidArgumentException, "contactId argument is wrong");
-
-       ContactSearchEnginePtr searchEngine(new ContactSearchEngine(ContactSearchEngine::CONTACT_QUERY));
-
-       searchEngine->setCondition(contactId);
-       searchEngine->setAttributeOfInterest();
-       searchEngine->setSortMode();
-
-       ContactArrayPtr contacts = searchEngine->getContactSearchResult();
-
-       if(contacts->size() == 0)
-               ThrowMsg(NotFoundException, "No contact with ID:" << contactId);
-
-       return contacts->at(0);
-}
-
-void AddressBook::contactsSvcContactChangedCallback(void *data)
-{
-       AddressBook *addressBook = static_cast<AddressBook *>(data);
-       addressBook->contactsSvcContactChangedCallback();
-}
-
-void AddressBook::contactsSvcContactChangedCallback()
-{
-       LogDebug("entered");
-       if(m_addressBookEmitters.size() == 0)
-               return;
-
-       CTSiter *iter;
-       int changeId = 0;
-       int changeType = 0;
-       int changeVersion = 0;
-
-       bool contactInserted = false;
-       bool contactUpdated = false;
-       bool contactDeleted = false;
-
-       int *addressBookIds = NULL;
-       int addressBookIdCount = 0;
-
-       addressBookIds = get_all_addressbook_id(&addressBookIdCount);
-
-       EventInfoAddressBookChangeAddedPtr contactsAdded(new EventInfoAddressBookChangeAdded());
-       EventInfoAddressBookChangeUpdatedPtr contactsUpdated(new EventInfoAddressBookChangeUpdated());
-       EventInfoAddressBookChangeRemovedPtr contactsRemoved(new EventInfoAddressBookChangeRemoved());
-
-       ContactArrayPtr addedContacts(new ContactArray());
-       ContactArrayPtr updatedContacts(new ContactArray());
-       StringArrayPtr removedContactIds(new StringArray());
-
-       for(int i = 0; i < addressBookIdCount; i++)
-       {
-               int ret = contacts_svc_get_updated_contacts(addressBookIds[i], m_latestVersion, &iter);
-               if(ret == CTS_SUCCESS)
-               {
-                       while (contacts_svc_iter_next(iter) == CTS_SUCCESS)
-                       {
-                               CTSstruct *contact= NULL;
-                               CTSvalue *row_info = NULL;
-                               row_info = contacts_svc_iter_get_info(iter);
-
-                               changeId = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_ID_INT);
-                               changeType = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_TYPE_INT);
-                               changeVersion = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_VER_INT);
-
-                               if(changeType == CTS_OPERATION_INSERTED)
-                               {
-                                       contactInserted = true;
-                                       contacts_svc_get_contact(changeId, &contact);
-
-                                       ContactWrapperPtr contactWrapper(new ContactWrapper(m_bookType));
-                                       contactWrapper->setPlatformContact(contact, false);
-                                       ContactPtr absContact = contactWrapper->getAbstractContact();
-                                       if(absContact != NULL)
-                                               addedContacts->push_back(absContact);
-
-                                       if(contact != NULL)
-                                       {
-                                               contacts_svc_struct_free(contact);
-                                               contact = NULL;
-                                       }
-                               }
-
-                               if(changeType == CTS_OPERATION_UPDATED)
-                               {
-                                       contactUpdated = true;
-                                       contacts_svc_get_contact(changeId, &contact);
-
-                                       ContactWrapperPtr contactWrapper(new ContactWrapper(m_bookType));
-                                       contactWrapper->setPlatformContact(contact, false);
-                                       ContactPtr absContact = contactWrapper->getAbstractContact();
-                                       if(absContact != NULL)
-                                               updatedContacts->push_back(absContact);
-
-                                       if(contact != NULL)
-                                       {
-                                               contacts_svc_struct_free(contact);
-                                               contact = NULL;
-                                       }
-                               }
-
-                               if(changeType == CTS_OPERATION_DELETED)
-                               {
-                                       contactDeleted = true;
-
-                                       std::stringstream oss;
-                                       oss << changeId;
-                                       removedContactIds->push_back(oss.str());
-                               }
-
-                               contacts_svc_value_free(row_info);
-                       }
-                       contacts_svc_iter_remove(iter);
-               }
-       }
-
-       m_latestVersion = get_contact_version();
-
-       if(addressBookIds)
-               free(addressBookIds);
-
-       if(contactInserted)
-       {
-               DPL::Mutex::ScopedLock lock(&m_addressBookEmittersMutex);
-               contactsAdded->setContacts(addedContacts);
-               EventInfoAddressBookChangePtr event = DPL::StaticPointerCast<EventInfoAddressBookChange>(contactsAdded);
-               EventAddressBookChangeListenerPtr listener(new EventAddressBookChangeListener(event));
-               m_addressBookEmitters.emit(listener);
-       }
-
-       if(contactUpdated)
-       {
-               DPL::Mutex::ScopedLock lock(&m_addressBookEmittersMutex);
-               contactsUpdated->setContacts(updatedContacts);
-               EventInfoAddressBookChangePtr event = DPL::StaticPointerCast<EventInfoAddressBookChange>(contactsUpdated);
-               EventAddressBookChangeListenerPtr listener(new EventAddressBookChangeListener(event));
-               m_addressBookEmitters.emit(listener);
-       }
-
-       if(contactDeleted)
-       {
-               DPL::Mutex::ScopedLock lock(&m_addressBookEmittersMutex);
-               contactsRemoved->setContactIds(removedContactIds);
-               EventInfoAddressBookChangePtr event = DPL::StaticPointerCast<EventInfoAddressBookChange>(contactsRemoved);
-               EventAddressBookChangeListenerPtr listener(new EventAddressBookChangeListener(event));
-               m_addressBookEmitters.emit(listener);
-       }
-}
-
 } // Contact
 } // Platform
 } // TizenApis
index e3a535b..846d596 100755 (executable)
 #include <API/Contact/IAddressBook.h>
 #include <API/Contact/IContact.h>
 
+#include "ContactListenerManager.h"
+
 namespace TizenApis {
 namespace Platform {
 namespace Contact {
 
-class AddressBook : public TizenApis::Api::Contact::IAddressBook
+class AddressBook : public TizenApis::Api::Contact::IAddressBook, public IContactEventCallbacks
 {
 private:
-       std::string             m_id;
-       std::string             m_name;
-       bool                    m_readOnly;
+       int             m_id;
+       std::string     m_name;
+       bool            m_readOnly;
+       int             m_accountId;
 
 public:
-       explicit AddressBook(TizenApis::Api::Contact::IAddressBook::AddressBookType type);
+       explicit AddressBook();
        virtual ~AddressBook();
 
-       virtual std::string getId() const { return m_id; }
-       virtual void        setId(const std::string &value) { m_id = value; }
+       virtual std::string getId() const;
+       virtual void        setId(const std::string &value);
+       void                setId(const int &value) { m_id = value; }
        virtual std::string getName() const { return m_name; }
        virtual void            setName(const std::string &value) { m_name = value; }
        virtual bool        getReadOnly() const { return m_readOnly; }
        virtual void        setReadOnly(const bool &value) { m_readOnly = value; }
+       virtual std::string getAccountId() const;
+       virtual void        setAccountId(const std::string &value);
+       void                setAccountId(const int &value) { m_accountId = value; }
 
 protected:
        virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookGetPtr &event);
@@ -67,10 +74,12 @@ protected:
        virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookAddChangeListenerPtr &event);
        virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookRemoveChangeListenerPtr &event);
 
-private:
-       int m_latestVersion;
+       virtual void onContactEventAdded(TizenApis::Api::Contact::ContactArrayPtr &contacts);
+       virtual void onContactEventUpdated(TizenApis::Api::Contact::ContactArrayPtr &contacts);
+       virtual void onContactEventRemoved(TizenApis::Api::Contact::StringArrayPtr &contactIds);
 
-       TizenApis::Api::Contact::ContactPtr internalGetById(const std::string &contactId);
+private:
+       //int m_latestVersion;
 
        void internalAddContact(const TizenApis::Api::Contact::ContactPtr &newContact);
        void internalDeleteContactById(int id);
@@ -78,17 +87,11 @@ private:
 
        typedef WrtDeviceApis::Commons::Emitters<TizenApis::Api::Contact::EventAddressBookChangeListenerEmitter> AddressBookChangedEmitter;
        AddressBookChangedEmitter       m_addressBookEmitters;
-       DPL::Mutex      m_addressBookEmittersMutex;
+       //DPL::Mutex    m_addressBookEmittersMutex;
 
        typedef std::map<long, TizenApis::Api::Contact::EventAddressBookChangeListenerEmitter::IdType> WatchIdMap;
        WatchIdMap m_watchIdMap;
-       long m_watchIdAcc;
-
-public:
-       static void contactsSvcContactChangedCallback(void *data);
-
-private:
-       void contactsSvcContactChangedCallback();
+       //long m_watchIdAcc;
 };
 
 } // Contact
diff --git a/src/platform/Tizen/Contact/AddressBookStorage.cpp b/src/platform/Tizen/Contact/AddressBookStorage.cpp
deleted file mode 100755 (executable)
index 263bc1b..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * @file        AddressBookStorage.cpp
- * @author      Kisub Song (kisubs.song@samsung.com)
- * @version     0.1
- * @brief
- */
-
-#include <sstream>
-#include <dpl/exception.h>
-#include "AddressBookStorage.h"
-
-namespace TizenApis {
-namespace Platform {
-namespace Contact {
-
-using namespace WrtDeviceApis::Commons;
-using namespace TizenApis::Api::Contact;
-//using namespace TizenApis::Api::Tizen;
-
-AddressBookStorage::AddressBookStorage() :
-       m_addressBooks(new AddressBookArray()),
-       m_defaultAddressBookIndex(-1)
-{
-}
-
-AddressBookStorage::~AddressBookStorage()
-{
-}
-
-void AddressBookStorage::insert(AddressBookPtr addressBook, bool setAsDefault)
-{
-       int index;
-       std::string id;
-
-       std::stringstream ss;
-
-       index = m_addressBooks->size();
-
-       // just use index as id (very simple)
-       ss << index;
-       id = ss.str();
-       m_idMap[id] = index;
-
-       addressBook->setId(id);
-
-       m_addressBooks->push_back(addressBook);
-
-       if(m_defaultAddressBookIndex == -1 || setAsDefault)
-               m_defaultAddressBookIndex = index;
-}
-
-AddressBookPtr AddressBookStorage::getAddressBook(const std::string &id)
-{
-       if(m_idMap.find(id) == m_idMap.end())
-               ThrowMsg(NotFoundException, "No AddressBook id:" << id);
-
-       int index = m_idMap[id];
-
-       if(static_cast<int>(m_addressBooks->size()) <= index)
-               ThrowMsg(NotFoundException, "No AddressBook id:" << id);
-
-       return m_addressBooks->at(index);
-}
-
-AddressBookPtr AddressBookStorage::getDefaultAddressBook() const
-{
-       if(m_defaultAddressBookIndex == -1 || m_addressBooks->size() == 0)
-               ThrowMsg(PlatformException, "Invalid request");
-
-       return m_addressBooks->at(m_defaultAddressBookIndex);
-}
-
-AddressBookArrayPtr AddressBookStorage::getAddressBooks() const
-{
-       AddressBookArrayPtr newArray(new AddressBookArray());
-
-       for(AddressBookArray::iterator i = m_addressBooks->begin(); i != m_addressBooks->end(); i++)
-               newArray->push_back(*i);
-
-       return newArray;
-}
-
-} // Contact
-} // Platform
-} // TizenApis
index c3a1753..6edc3fc 100755 (executable)
  * @brief
  */
 
+#include "Contact.h"
+
 #include <pcrecpp.h>
 #include <dpl/log/log.h>
 #include <dpl/exception.h>
 #include <Commons/Exception.h>
 #include <Commons/Regex.h>
-#include "ContactWrapper.h"
-#include "Contact.h"
+#include "ContactObjectA2PConverter.h"
+#include "ContactObjectP2AConverter.h"
 
 namespace TizenApis {
 namespace Platform {
@@ -61,14 +63,17 @@ string Contact::convertToString(const string &format)
        if(format != "VCARD_30")
                ThrowMsg(UnsupportedException, "Only support vCard 3.0.");
 
-       ContactWrapperPtr contactWrapper(new ContactWrapper(TizenApis::Api::Contact::IAddressBook::PhoneBook));
+       ContactPtr thisObj = SharedFromThis();
+       ContactObjectA2PConverterPtr contactObjConverter(NULL);
+
+       CTSstruct *platformContact = NULL;
        Try {
-               ContactPtr thisObj = SharedFromThis();
-               contactWrapper->setAbstractContact(thisObj, true);
-       } Catch (PlatformException) {
+               contactObjConverter = ContactObjectA2PConverterPtr(new ContactObjectA2PConverter(thisObj, true) );
+               platformContact = contactObjConverter->getPlatformContact();
+       } Catch (Exception) {
                ThrowMsg(PlatformException, "Fail to extract contact to platform object.");
        }
-       int ret = contacts_svc_get_vcard_from_contact(contactWrapper->getPlatformContact(), &vcard_stream);
+       int ret = contacts_svc_get_vcard_from_contact(platformContact, &vcard_stream);
        if(ret != CTS_SUCCESS)
                ThrowMsg(PlatformException, "Fail to convert to vCard.");
 
@@ -94,11 +99,12 @@ void Contact::setContactFromString(const std::string &vObjectStr, const std::str
        else if(CTS_SUCCESS != ret)
                ThrowMsg(PlatformException, "Fail to convert contact from vCard.");
 
-       ContactWrapperPtr contactWrapper(new ContactWrapper(TizenApis::Api::Contact::IAddressBook::PhoneBook));
+       ContactObjectP2AConverterPtr contactObjConverter(NULL);
        Try {
                ContactPtr thisObj = SharedFromThis();
-               contactWrapper->convertPlatformToAbstract(cts, thisObj, true);
-       } Catch (PlatformException) {
+               contactObjConverter = ContactObjectP2AConverterPtr(new ContactObjectP2AConverter(cts, true, thisObj) );
+               contactObjConverter->getAbstractContact();
+       } Catch (Exception) {
                ThrowMsg(PlatformException, "Fail to extract contact from platform object.");
        }
 
  */
 
 /**
- * @file        DownloadManager.cpp
+ * @file        ContactDownloadManager.cpp
  * @author      Kisub Song (kisubs.song@samsung.com)
  * @version     0.1
  * @brief
  */
 
+#include "ContactDownloadManager.h"
+
 #include <ctime>
 #include <cstdlib>
 #include <cstddef>
 #include <fstream>
-#include <sstream>
 #include <pcrecpp.h>
 #include <dpl/log/log.h>
 #include <dpl/exception.h>
 #include <Commons/Exception.h>
 #include <Commons/Regex.h>
-#include "DownloadManager.h"
 
 namespace TizenApis {
 namespace Platform {
@@ -39,15 +39,15 @@ namespace Contact {
 
 using namespace WrtDeviceApis::Commons;
 
-DownloadManager::DownloadManager()
+ContactDownloadManager::ContactDownloadManager()
 {
 }
 
-DownloadManager::~DownloadManager()
+ContactDownloadManager::~ContactDownloadManager()
 {
 }
 
-string DownloadManager::downloadImage(const string &imgUrl) const
+string ContactDownloadManager::downloadImage(const string &imgUrl) const
 {
        LogDebug("URL : " << imgUrl);
 
@@ -111,7 +111,7 @@ string DownloadManager::downloadImage(const string &imgUrl) const
        return result;
 }
 
-string DownloadManager::getRealPath(const string &path) const
+string ContactDownloadManager::getRealPath(const string &path) const
 {
        LogDebug("Path : " << path);
 
@@ -141,7 +141,7 @@ string DownloadManager::getRealPath(const string &path) const
        return result;
 }
 
-void DownloadManager::urlDownloadStoppedCB(url_download_h download, url_download_error_e error, void *user_data)
+void ContactDownloadManager::urlDownloadStoppedCB(url_download_h download, url_download_error_e error, void *user_data)
 {
        if (download == NULL)
        {
@@ -159,7 +159,7 @@ void DownloadManager::urlDownloadStoppedCB(url_download_h download, url_download
        }
 }
 
-void DownloadManager::urlDownloadCompletedCB(url_download_h download, const char *installed_path, void *user_data)
+void ContactDownloadManager::urlDownloadCompletedCB(url_download_h download, const char *installed_path, void *user_data)
 {
        if(download == NULL)
        {
@@ -184,9 +184,9 @@ void DownloadManager::urlDownloadCompletedCB(url_download_h download, const char
        }
 }
 
-DownloadManagerPtr DownloadManager::getInstance()
+ContactDownloadManagerPtr ContactDownloadManager::getInstance()
 {
-       static DownloadManagerPtr downloadManager(new DownloadManager());
+       static ContactDownloadManagerPtr downloadManager(new ContactDownloadManager());
 
        return downloadManager;
 }
similarity index 78%
rename from src/platform/Tizen/Contact/DownloadManager.h
rename to src/platform/Tizen/Contact/ContactDownloadManager.h
index 0089a2c..d23d936 100755 (executable)
  */
 
 /**
- * @file        DownloadManager.h
+ * @file        ContactDownloadManager.h
  * @author      Kisub Song (kisubs.song@samsung.com)
  * @version     0.1
  * @brief
  */
 
-#ifndef _PLATFORM_CONTACT_DOWNLOAD_MANAGER_H_
-#define _PLATFORM_CONTACT_DOWNLOAD_MANAGER_H_
+#ifndef TIZENAPIS_PLATFORM_CONTACT_CONTACT_DOWNLOAD_MANAGER_H_
+#define TIZENAPIS_PLATFORM_CONTACT_CONTACT_DOWNLOAD_MANAGER_H_
 
 #include <url_download.h>
 #include <string>
 #include <vector>
 #include <dpl/shared_ptr.h>
+#include <dpl/waitable_event.h>
 
 namespace TizenApis {
 namespace Platform {
 namespace Contact {
 
-class DownloadManager;
-typedef DPL::SharedPtr<DownloadManager> DownloadManagerPtr;
+class ContactDownloadManager;
+typedef DPL::SharedPtr<ContactDownloadManager> ContactDownloadManagerPtr;
 
-class DownloadManager
+class ContactDownloadManager
 {
 private:
        class DownImageInfo
@@ -72,10 +73,10 @@ private:
        };
 
 private:
-       DownloadManager();
+       ContactDownloadManager();
 
 public:
-       virtual ~DownloadManager();
+       virtual ~ContactDownloadManager();
 
 private:
        static void urlDownloadStoppedCB(url_download_h download,
@@ -87,11 +88,11 @@ public:
        std::string downloadImage(const std::string &imgUrl) const;
        std::string getRealPath(const std::string &path) const;
 
-       static DownloadManagerPtr getInstance();
+       static ContactDownloadManagerPtr getInstance();
 };
 
 } // Contact
 } // Platform
 } // TizenApis
 
-#endif // _PLATFORM_CONTACT_DOWNLOAD_MANAGER_H_
+#endif // TIZENAPIS_PLATFORM_CONTACT_CONTACT_DOWNLOAD_MANAGER_H_
diff --git a/src/platform/Tizen/Contact/ContactListenerManager.cpp b/src/platform/Tizen/Contact/ContactListenerManager.cpp
new file mode 100644 (file)
index 0000000..b2bab60
--- /dev/null
@@ -0,0 +1,332 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        ContactListenerManager.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       
+ */
+
+#include "ContactListenerManager.h"
+
+#include <contacts-svc.h>
+
+#include <dpl/log/log.h>
+#include <dpl/singleton_impl.h>
+#include <Commons/Exception.h>
+#include <Commons/Regex.h>
+
+#include "ContactUtility.h"
+#include "ContactObjectP2AConverter.h"
+#include "query-svc/query-service.h"
+
+IMPLEMENT_SINGLETON(TizenApis::Platform::Contact::ContactListenerManager)
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace std;
+using namespace WrtDeviceApis::Commons;
+using namespace TizenApis::Api::Contact;
+
+ContactListenerManager::ContactListenerManager() :
+               m_callbackRegistered(false),
+               m_latestVersion(0),
+               m_watchIdAcc(0)
+{
+}
+
+ContactListenerManager::~ContactListenerManager()
+{
+       if(m_callbackRegistered)
+       {
+               unregisterContactSvcChangedCallbacks();
+       }
+}
+
+void ContactListenerManager::registerAppListChangedCallbacks(IContactEventCallbacks *callbacks, int addressBookId)
+{
+       if(callbacks == NULL)
+       {
+               LogWarning("Parameter is NULL.");
+               return;
+       }
+
+       if(getContactEventCallbacks(addressBookId) != NULL)
+               ThrowMsg(PlatformException, "Already registered address book (id:" << addressBookId << ")");
+
+       if(!m_callbackRegistered)
+       {
+               registerContactSvcChangedCallbacks();
+       }
+
+       m_callbacks[addressBookId] = callbacks;
+}
+
+void ContactListenerManager::unregisterAppListChangedCallbacks(IContactEventCallbacks *callbacks)
+{
+       if(callbacks == NULL)
+       {
+               LogWarning("Parameter is NULL.");
+               return;
+       }
+
+       if(m_callbacks.size() == 0)
+       {
+               LogWarning("No callbacks are registered.");
+               return;
+       }
+
+       ContactEventCallbacksMap::iterator iter = m_callbacks.begin();
+       for(; iter != m_callbacks.end(); iter++)
+       {
+               if(iter->second == callbacks)
+                       break;
+       }
+
+       if(iter == m_callbacks.end())
+       {
+               LogWarning("Callbacks " << callbacks << " are not registered.");
+               return;
+       }
+
+       m_callbacks.erase(iter);
+
+       if(m_callbacks.size() == 0)
+       {
+               unregisterContactSvcChangedCallbacks();
+       }
+}
+
+void ContactListenerManager::unregisterAppListChangedCallbacks(int addressBookId)
+{
+       if(m_callbacks.size() == 0)
+       {
+               LogWarning("No callbacks are registered.");
+               return;
+       }
+
+       ContactEventCallbacksMap::iterator iter = m_callbacks.find(addressBookId);
+       if(iter == m_callbacks.end())
+       {
+               LogWarning("Callbacks for addressbook " << addressBookId << " are not registered.");
+               return;
+       }
+
+       m_callbacks.erase(iter);
+
+       if(m_callbacks.size() == 0)
+       {
+               unregisterContactSvcChangedCallbacks();
+       }
+}
+
+long ContactListenerManager::getWatchIdAndInc()
+{
+       return ++m_watchIdAcc;
+}
+
+void ContactListenerManager::contactsSvcEventCallback(void *data)
+{
+       if(data == NULL)
+       {
+               LogWarning("contacts-service listener passed NULL user_data");
+               return;
+       }
+
+       ContactListenerManager *contactListenerMgr = static_cast<ContactListenerManager *>(data);
+       contactListenerMgr->contactsSvcEventCallback();
+}
+
+void ContactListenerManager::contactsSvcEventCallback()
+{
+       LogDebug("entered");
+       if(!m_callbackRegistered)
+               return;
+
+       int errorCode = 0;
+
+       ContactEventCallbacksMap::iterator callbacksIter = m_callbacks.begin();
+       for(; callbacksIter != m_callbacks.end(); callbacksIter++)
+       {
+               int addressBookId = callbacksIter->first;
+               IContactEventCallbacks *callbacks = callbacksIter->second;
+
+               CTSiter *iter = NULL;
+
+               errorCode = contacts_svc_get_updated_contacts(addressBookId, m_latestVersion, &iter);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       LogDebug("No updated contacts for addressbook : " << addressBookId);
+                       continue;
+               }
+
+               int changeId = 0;
+               int changeType = 0;
+               int changeVersion = 0;
+
+               bool existingAddedContacts = false;
+               bool existingUpdatedContacts = false;
+               bool existingRemovedContacts = false;
+
+               ContactArrayPtr addedContacts(new ContactArray());
+               ContactArrayPtr updatedContacts(new ContactArray());
+               StringArrayPtr removedContactIds(new StringArray());
+
+               while (contacts_svc_iter_next(iter) == CTS_SUCCESS)
+               {
+                       CTSstruct *contact= NULL;
+                       CTSvalue *row_info = NULL;
+                       row_info = contacts_svc_iter_get_info(iter);
+
+                       changeId = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_ID_INT);
+                       changeType = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_TYPE_INT);
+                       changeVersion = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_VER_INT);
+
+                       if(changeType == CTS_OPERATION_INSERTED)
+                       {
+                               existingAddedContacts = true;
+                               contacts_svc_get_contact(changeId, &contact);
+
+                               ContactObjectP2AConverterPtr contactObjConverter(
+                                               new ContactObjectP2AConverter(contact, false) );
+                               ContactPtr absContact = contactObjConverter->getAbstractContact();
+                               if(absContact != NULL)
+                                       addedContacts->push_back(absContact);
+
+                               if(contact != NULL)
+                               {
+                                       contacts_svc_struct_free(contact);
+                                       contact = NULL;
+                               }
+                       }
+
+                       if(changeType == CTS_OPERATION_UPDATED)
+                       {
+                               existingUpdatedContacts = true;
+                               contacts_svc_get_contact(changeId, &contact);
+
+                               ContactObjectP2AConverterPtr contactObjConverter(
+                                               new ContactObjectP2AConverter(contact, false) );
+                               ContactPtr absContact = contactObjConverter->getAbstractContact();
+                               if(absContact != NULL)
+                                       updatedContacts->push_back(absContact);
+
+                               if(contact != NULL)
+                               {
+                                       contacts_svc_struct_free(contact);
+                                       contact = NULL;
+                               }
+                       }
+
+                       if(changeType == CTS_OPERATION_DELETED)
+                       {
+                               existingRemovedContacts = true;
+
+                               removedContactIds->push_back(ContactUtility::intToStr(changeId));
+                       }
+
+                       contacts_svc_value_free(row_info);
+               }
+               contacts_svc_iter_remove(iter);
+
+               if(existingAddedContacts)
+                       callbacks->onContactEventAdded(addedContacts);
+
+               if(existingUpdatedContacts)
+                       callbacks->onContactEventUpdated(updatedContacts);
+
+               if(existingRemovedContacts)
+                       callbacks->onContactEventRemoved(removedContactIds);
+       }
+
+       m_latestVersion = get_contact_version();
+}
+
+void ContactListenerManager::registerContactSvcChangedCallbacks()
+{
+       int errorCode = 0;
+
+       if(m_callbackRegistered)
+       {
+               LogWarning("Callback already registered.");
+               return;
+       }
+
+       m_latestVersion = get_contact_version();
+
+       errorCode = contacts_svc_subscribe_change(CTS_SUBSCRIBE_CONTACT_CHANGE,
+                       contactsSvcEventCallback, reinterpret_cast<void *>(this));
+       if(errorCode != CTS_SUCCESS)
+       {
+               LogWarning("contacts_svc_subscribe_change(CTS_SUBSCRIBE_CONTACT_CHANGE) returns Error (error");
+               ThrowMsg(InvalidArgumentException, "Error while registering listener to contacts-service");
+       }
+
+       errorCode = contacts_svc_subscribe_change(CTS_SUBSCRIBE_ADDRESSBOOK_CHANGE,
+                       refresh_addressbook_list, reinterpret_cast<void *>(this));
+       if(errorCode != CTS_SUCCESS)
+       {
+               LogWarning("contacts_svc_subscribe_change(CTS_SUBSCRIBE_ADDRESSBOOK_CHANGE) returns Error (error");
+               ThrowMsg(InvalidArgumentException, "Error while registering listener to contacts-service");
+       }
+
+       m_callbackRegistered = true;
+}
+
+void ContactListenerManager::unregisterContactSvcChangedCallbacks()
+{
+       int errorCode = 0;
+
+       if(!m_callbackRegistered)
+       {
+               LogWarning("Callback already unregistered.");
+               return;
+       }
+
+       m_latestVersion = 0;
+
+       errorCode = contacts_svc_unsubscribe_change(CTS_SUBSCRIBE_CONTACT_CHANGE,
+                       contactsSvcEventCallback);
+       if(errorCode != CTS_SUCCESS)
+       {
+               LogWarning("contacts_svc_unsubscribe_change(CTS_SUBSCRIBE_CONTACT_CHANGE) returns Error (error");
+               ThrowMsg(InvalidArgumentException, "Error while unregistering listener to contacts-service");
+       }
+
+       errorCode = contacts_svc_unsubscribe_change(CTS_SUBSCRIBE_ADDRESSBOOK_CHANGE,
+                       refresh_addressbook_list);
+       if(errorCode != CTS_SUCCESS)
+       {
+               LogWarning("contacts_svc_unsubscribe_change(CTS_SUBSCRIBE_ADDRESSBOOK_CHANGE) returns Error (error");
+               ThrowMsg(InvalidArgumentException, "Error while unregistering listener to contacts-service");
+       }
+
+       m_callbackRegistered = false;
+}
+
+IContactEventCallbacks* ContactListenerManager::getContactEventCallbacks(int id)
+{
+       if(m_callbacks.find(id) == m_callbacks.end())
+               return NULL;
+
+       return m_callbacks[id];
+}
+
+} // Application
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/ContactListenerManager.h b/src/platform/Tizen/Contact/ContactListenerManager.h
new file mode 100644 (file)
index 0000000..ab03eb1
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        ContactListenerManager.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       
+ */
+
+#ifndef TIZENAPIS_PLATFORM_CONTACT_CONTACT_LISTENER_MANAGER_H_
+#define TIZENAPIS_PLATFORM_CONTACT_CONTACT_LISTENER_MANAGER_H_
+
+#include <string>
+#include <map>
+#include <set>
+#include <dpl/shared_ptr.h>
+#include <dpl/singleton.h>
+
+#include <API/Contact/IContact.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class IContactEventCallbacks
+{
+public:
+    friend class ContactListenerManager;
+
+    IContactEventCallbacks() {}
+       ~IContactEventCallbacks() {}
+
+protected:
+       virtual void onContactEventAdded(TizenApis::Api::Contact::ContactArrayPtr &contacts) = 0;
+       virtual void onContactEventUpdated(TizenApis::Api::Contact::ContactArrayPtr &contacts) = 0;
+       virtual void onContactEventRemoved(TizenApis::Api::Contact::StringArrayPtr &contactIds) = 0;
+};
+
+class ContactListenerManager
+{
+public:
+       ContactListenerManager();
+       virtual ~ContactListenerManager();
+
+       // Can throw InvalidArgumentException or PlatformException
+       void registerAppListChangedCallbacks(IContactEventCallbacks *callbacks, int addressBookId);
+
+       // No throws
+       void unregisterAppListChangedCallbacks(IContactEventCallbacks *callbacks);
+       void unregisterAppListChangedCallbacks(int addressBookId);
+
+       long getWatchIdAndInc();
+
+private:
+       static void contactsSvcEventCallback(void *data);
+       void contactsSvcEventCallback();
+
+       void registerContactSvcChangedCallbacks();
+       void unregisterContactSvcChangedCallbacks();
+
+       IContactEventCallbacks* getContactEventCallbacks(int id);
+
+       typedef std::map<int, IContactEventCallbacks *> ContactEventCallbacksMap;
+       ContactEventCallbacksMap m_callbacks;
+
+       bool m_callbackRegistered;
+
+       int m_latestVersion;
+
+       long m_watchIdAcc;
+
+public:
+       friend class DPL::Singleton<ContactListenerManager>;
+};
+
+typedef DPL::Singleton<ContactListenerManager> ContactListenerManagerSingleton;
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // TIZENAPIS_PLATFORM_CONTACT_CONTACT_LISTENER_MANAGER_H_
index 1167a3b..0107d69 100755 (executable)
  * @brief
  */
 
+#include "ContactManager.h"
+
 #include <dpl/log/log.h>
 #include <contacts-svc.h>
 #include <API/Contact/ContactFactory.h>
 #include <API/Contact/IAddressBook.h>
 #include <API/Contact/IContact.h>
-#include "ContactManager.h"
-#include "AddressBook.h"
-#include "DownloadManager.h"
 
-#define DEVICE_ADDRESSBOOK     "DEVICE AddressBook"
-#define SIM_ADDRESSBOOK                "SIM AddressBook"
+#include "AddressBook.h"
+#include "ContactDownloadManager.h"
 
 namespace TizenApis {
 namespace Platform {
@@ -41,85 +40,25 @@ using namespace WrtDeviceApis::Commons;
 using namespace TizenApis::Api::Contact;
 using namespace TizenApis::Api::Tizen;
 
-//initialize static variables
-int ContactManager::m_instanceCount = 0;
-bool ContactManager::m_opened = false;
-
 ContactManager::ContactManager()
-       : m_addressBookStorage(new AddressBookStorage())
 {
-       // Currently only supports PhoneBook
-       AddressBookPtr addressBook(new AddressBook(IAddressBook::PhoneBook));
-       addressBook->setName(DEVICE_ADDRESSBOOK);
-       addressBook->setReadOnly(false);
-
-       m_addressBookStorage->insert(addressBook, true);
-
-       //protect for pararel execution
-       DPL::Mutex::ScopedLock mx(&m_constructorMutex);
-       if (m_instanceCount == 0)
-       {
-               //when it is first instance then open connection to database
-               if (contacts_svc_connect() == CTS_SUCCESS)
-               {
-                       //contacts database is opened properly
-                       LogDebug("contacts database is opened properly");
-                       m_opened = true;
-               }
-               else
-               {
-                       //error during opening contacts database
-                       LogError("error during opening contacts database");
-               }
-       }
-
-       //increase counter of instances
-       m_instanceCount++;
+       ContactsSvcWrapperSingleton::Instance().init();
 
        //initialize download manager
-       DownloadManagerPtr downloadManager = DownloadManager::getInstance();
+       ContactDownloadManagerPtr downloadManager = ContactDownloadManager::getInstance();
 }
 
 ContactManager::~ContactManager()
 {
-//     LogDebug("entered");
-       //protect for pararel execution
-       DPL::Mutex::ScopedLock mx(&m_constructorMutex);
-       //decrease counter of instances
-       m_instanceCount--;
-       if (m_instanceCount == 0)
-       {
-               //when it is last instance then clse connection to database
-               if (contacts_svc_disconnect() != CTS_SUCCESS)
-               {
-                       //error during closing contacts database
-                       LogError("error during closing contacts database");
-               }
-               m_opened = false;
-       }
 }
 
 AddressBookPtr ContactManager::getDefaultAddressBook()
 {
-       if(!m_opened)
-       {
-               //when database is not opened then set result as failed
-               LogError("Contact DB is not opened.");
-               ThrowMsg(PlatformException, "Contact DB is not opened.");
-       }
-
-       return m_addressBookStorage->getDefaultAddressBook();
+       return ContactsSvcWrapperSingleton::Instance().getDefaultAddressBook();
 }
 
 AddressBookPtr ContactManager::getAddressBook(const std::string &addressBookId)
 {
-       if(!m_opened)
-       {
-               //when database is not opened then set result as failed
-               LogError("Contact DB is not opened.");
-               ThrowMsg(PlatformException, "Contact DB is not opened.");
-       }
-
        if(addressBookId == "")
        {
                //when database is not opened then set result as failed
@@ -127,34 +66,39 @@ AddressBookPtr ContactManager::getAddressBook(const std::string &addressBookId)
                ThrowMsg(InvalidArgumentException, "Wrong address book id.");
        }
 
-       AddressBookPtr addressBook;
-
-       Try {
-               addressBook = m_addressBookStorage->getAddressBook(addressBookId);
+       AddressBookPtr addressBook(NULL);
 
-       } Catch(Exception) {
+       Try
+       {
+               addressBook = ContactsSvcWrapperSingleton::Instance().getAddressBook(addressBookId);
+       }
+       Catch(PlatformException)
+       {
+               //when database is not opened then set result as failed
+               LogError("Contact DB not opened : " << _rethrown_exception.GetMessage());
+               ThrowMsg(PlatformException, "Not opend DB");
+       }
+       Catch(NotFoundException)
+       {
                //when database is not opened then set result as failed
                LogError("Not found : " << _rethrown_exception.GetMessage());
                ThrowMsg(NotFoundException, "No address book");
        }
+       Catch (Exception)
+       {
+               //when database is not opened then set result as failed
+               LogError("Unknown exception : " << _rethrown_exception.GetMessage());
+               ThrowMsg(UnknownException, "Unknown exception.");
+       }
 
        return addressBook;
 }
 
 void ContactManager::OnRequestReceived(const EventContactManagerGetAddressBooksPtr &event)
 {
-       if(!m_opened)
-       {
-               //when database is not opened then set result as failed
-               LogError("Contact DB is not opened.");
-               event->setResult(false);
-               event->setExceptionCode(ExceptionCodes::PlatformException);
-               return;
-       }
-
        Try
        {
-               AddressBookArrayPtr addressBookArray = m_addressBookStorage->getAddressBooks();
+               AddressBookArrayPtr addressBookArray = ContactsSvcWrapperSingleton::Instance().getAddressBooks();
 
                if(addressBookArray->size() == 0)
                        ThrowMsg(NotFoundException, "No address book");
@@ -163,7 +107,15 @@ void ContactManager::OnRequestReceived(const EventContactManagerGetAddressBooksP
                event->setResult(true);
                event->setExceptionCode(ExceptionCodes::None);
        }
-       Catch (UnknownException)
+       Catch (PlatformException)
+       {
+               //when database is not opened then set result as failed
+               LogError("Contact DB is not opened.");
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+       Catch (Exception)
        {
                LogError("Unknown exception : " << _rethrown_exception.GetMessage());
                event->setResult(false);
index e0eb9b0..0eb3115 100755 (executable)
@@ -27,7 +27,7 @@
 #include <dpl/mutex.h>
 #include <API/Contact/IContactManager.h>
 #include "AddressBook.h"
-#include "AddressBookStorage.h"
+#include "ContactsSvcWrapper.h"
 
 namespace TizenApis {
 namespace Platform {
@@ -44,12 +44,6 @@ public:
 
 protected:
        virtual void OnRequestReceived(const TizenApis::Api::Contact::EventContactManagerGetAddressBooksPtr &event);
-
-private:
-       static int m_instanceCount;
-       static bool m_opened;
-       DPL::Mutex m_constructorMutex;
-       AddressBookStoragePtr m_addressBookStorage;
 };
 
 } // Contact
diff --git a/src/platform/Tizen/Contact/ContactObjectA2PConverter.cpp b/src/platform/Tizen/Contact/ContactObjectA2PConverter.cpp
new file mode 100644 (file)
index 0000000..b7b187a
--- /dev/null
@@ -0,0 +1,1808 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        ContactObjectA2PConverter.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Converter (TizenApis::Api::Contact::ContactPtr -> CTSstruct*)
+ */
+
+#include "ContactObjectA2PConverter.h"
+
+#include <Commons/Exception.h>
+#include "ContactUtility.h"
+#include "query-svc/query-service.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+static const char *EMPTY_STRING = "";
+
+ContactObjectA2PConverter::ContactObjectA2PConverter(const ContactPtr &abstractContact,
+               bool forScratch) :
+               m_abstractContact(abstractContact),
+               m_platformContact(NULL),
+               m_forScratch(forScratch),
+               m_convertFinished(false),
+               m_platformContactOwnership(false)
+{
+}
+
+ContactObjectA2PConverter::ContactObjectA2PConverter(const ContactPtr &abstractContact,
+               bool forScratch,
+               CTSstruct* platformContact) :
+               m_abstractContact(abstractContact),
+               m_platformContact(platformContact),
+               m_forScratch(forScratch),
+               m_convertFinished(false),
+               m_platformContactOwnership(false)
+{
+}
+
+ContactObjectA2PConverter::~ContactObjectA2PConverter()
+{
+       if(m_platformContactOwnership && m_platformContact != NULL)
+       {
+               contacts_svc_struct_free(m_platformContact);
+               m_platformContact = NULL;
+               m_platformContactOwnership = false;
+       }
+}
+
+CTSstruct* ContactObjectA2PConverter::getPlatformContact()
+{
+       LogDebug("enter");
+
+       if(m_abstractContact == NULL)
+       {
+               LogError("Abstract contact object did not set");
+               ThrowMsg(InvalidArgumentException, "Abstract contact object did not set");
+       }
+
+       if(m_platformContact == NULL)
+       {
+               if(m_abstractContact->getIdIsSet() && (m_forScratch == false))
+               {
+                       int id = ContactUtility::strToInt(m_abstractContact->getId());
+                       LogDebug("Load platform object id : " << id);
+                       contacts_svc_get_contact(id, &m_platformContact);
+               }
+               else
+               {
+                       LogDebug("New platform object has been created");
+                       m_platformContact = contacts_svc_struct_new(CTS_STRUCT_CONTACT);
+               }
+
+               m_platformContactOwnership = true;
+       }
+
+       LogDebug("for scratch : " << m_forScratch);
+
+       Try
+       {
+               if(m_convertFinished == false)
+                       convertToPlatformObject();
+       }
+       Catch(Exception)
+       {
+               LogError("Error while converting - " << _rethrown_exception.GetMessage());
+               ThrowMsg(PlatformException, "Fail to convert abstract object to platform object.");
+       }
+
+       return m_platformContact;
+}
+
+void ContactObjectA2PConverter::convertToPlatformObject()
+{
+       importBaseInfoValue();
+       importNameValue();
+       importCompanyValue();
+//     importNoteValue();
+       importNumberList();
+       importEmailList();
+       importGrouprelList();
+       importEventList();
+       importPostalList();
+       importWebAddrList();
+       importNicknameList();
+
+       m_convertFinished = true;
+}
+
+void ContactObjectA2PConverter::importBaseInfoValue()
+{
+       int errorCode = 0;
+       CTSvalue *ctsValue = NULL;
+
+       errorCode = contacts_svc_struct_get_value(m_platformContact, CTS_CF_BASE_INFO_VALUE, &ctsValue);
+       if(errorCode != CTS_SUCCESS || ctsValue == NULL)
+       {
+               ctsValue = contacts_svc_value_new(CTS_VALUE_CONTACT_BASE_INFO);
+               if(ctsValue == NULL)
+                       ThrowMsg(UnknownException, "creating base info value (ctsValue:NULL)");
+
+               importBaseInfoValueToNewValue(ctsValue);
+       }
+       else
+       {
+               importBaseInfoValueToExistingValue(ctsValue);
+       }
+
+       contacts_svc_struct_store_value(m_platformContact, CTS_CF_BASE_INFO_VALUE, ctsValue);
+       contacts_svc_value_free(ctsValue);
+}
+
+void ContactObjectA2PConverter::importBaseInfoValueToExistingValue(CTSvalue *ctsValue)
+{
+       int errorCode = 0;
+
+       const char *newValueStr = NULL;
+       const char *oldValueStr = NULL;
+       string abstractValueStr;
+
+       // Contact.photoURI
+       oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_BASE_VAL_IMG_PATH_STR);
+       abstractValueStr = ContactUtility::convertUriToPath(m_abstractContact->getPhotoURI());
+       if(oldValueStr != NULL &&
+                       (!m_abstractContact->getPhotoURIIsSet() || m_abstractContact->getPhotoURI().empty()))
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_svc_value_set_str(ctsValue, CTS_BASE_VAL_IMG_PATH_STR, newValueStr);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       contacts_svc_value_free(ctsValue);
+                       ThrowMsg(PlatformException, "importing photoURI E (err:" <<
+                                       errorCode << ", str:" << abstractValueStr << ")");
+               }
+       }
+
+       // Contact.ringtoneURI
+       newValueStr = NULL;
+       oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_BASE_VAL_RINGTONE_PATH_STR);
+       abstractValueStr = ContactUtility::convertUriToPath(m_abstractContact->getRingtoneURI());
+       if(oldValueStr != NULL &&
+                       (!m_abstractContact->getRingtoneURIIsSet() || m_abstractContact->getRingtoneURI().empty()))
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_svc_value_set_str(ctsValue, CTS_BASE_VAL_RINGTONE_PATH_STR, newValueStr);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       contacts_svc_value_free(ctsValue);
+                       ThrowMsg(PlatformException, "importing ringtoneURI E (err:" <<
+                                       errorCode << ", str:" << abstractValueStr << ")");
+               }
+       }
+
+       // Contact.note
+       newValueStr = NULL;
+       oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_BASE_VAL_NOTE_STR);
+       abstractValueStr = m_abstractContact->getNote();
+       if(oldValueStr != NULL && (!m_abstractContact->getNoteIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_svc_value_set_str(ctsValue, CTS_BASE_VAL_NOTE_STR, newValueStr);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       contacts_svc_value_free(ctsValue);
+                       ThrowMsg(PlatformException, "importing note E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+}
+
+void ContactObjectA2PConverter::importBaseInfoValueToNewValue(CTSvalue *ctsValue)
+{
+       int errorCode = 0;
+
+       // Contact.photoURI
+       if(m_abstractContact->getPhotoURIIsSet())
+       {
+               string photoURI = ContactUtility::convertUriToPath(m_abstractContact->getPhotoURI());
+               if(!photoURI.empty())
+               {
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_BASE_VAL_IMG_PATH_STR, photoURI.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               contacts_svc_value_free(ctsValue);
+                               ThrowMsg(PlatformException, "importing photoURI N (err: " <<
+                                               errorCode << ", str:" << photoURI << ")");
+                       }
+               }
+       }
+
+       // Contact.ringtoneURI
+       if(m_abstractContact->getRingtoneURIIsSet())
+       {
+               string ringtoneURI = ContactUtility::convertUriToPath(m_abstractContact->getRingtoneURI());
+               if(!ringtoneURI.empty())
+               {
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_BASE_VAL_RINGTONE_PATH_STR, ringtoneURI.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               contacts_svc_value_free(ctsValue);
+                               ThrowMsg(PlatformException, "importing ringtoneURI N (err:" <<
+                                               errorCode << ", str:" << ringtoneURI << ")");
+                       }
+               }
+       }
+
+       // Contact.note
+       if(m_abstractContact->getNoteIsSet())
+       {
+               string note = m_abstractContact->getNote();
+               if(note != EMPTY_STRING)
+               {
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_BASE_VAL_NOTE_STR, note.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               contacts_svc_value_free(ctsValue);
+                               ThrowMsg(PlatformException, "importing note N (err:" <<
+                                               errorCode << ", str:" << note << ")");
+                       }
+               }
+       }
+}
+
+void ContactObjectA2PConverter::importNameValue()
+{
+       int errorCode = 0;
+       CTSvalue *ctsValue = NULL;
+
+       ContactNamePtr contactName = m_abstractContact->getName();
+       if(contactName == NULL ||
+                       (( !contactName->getFirstNameIsSet() || contactName->getFirstName().empty() )
+                       && ( !contactName->getLastNameIsSet() || contactName->getLastName().empty() )
+                       && ( !contactName->getMiddleNameIsSet() || contactName->getMiddleName().empty() )
+//                     && ( !contactName->getPhoneticFirstNameIsSet() || contactName->getPhoneticFirstName().empty() )
+//                     && ( !contactName->getPhoneticLastNameIsSet() || contactName->getPhoneticLastName().empty() )
+                       && ( !contactName->getPrefixIsSet() || contactName->getPrefix().empty() )
+                       && ( !contactName->getDisplayNameIsSet() || contactName->getDisplayName().empty() ) ) )
+       {
+               ctsValue = contacts_svc_value_new(CTS_VALUE_NAME);
+               if(ctsValue == NULL)
+                       ThrowMsg(UnknownException, "creating name value A (ctsValue:NULL)");
+               contacts_svc_struct_store_value(m_platformContact, CTS_CF_NAME_VALUE, ctsValue);
+               return;
+       }
+
+       errorCode = contacts_svc_struct_get_value(m_platformContact, CTS_CF_NAME_VALUE, &ctsValue);
+       if(errorCode != CTS_SUCCESS || ctsValue == NULL)
+       {
+               ctsValue = contacts_svc_value_new(CTS_VALUE_NAME);
+               if(ctsValue == NULL)
+                       ThrowMsg(UnknownException, "creating name value B (ctsValue:NULL)");
+
+               importNameValueToNewValue(ctsValue, contactName);
+       }
+       else
+       {
+               importNameValueToExistingValue(ctsValue, contactName);
+       }
+
+       contacts_svc_struct_store_value(m_platformContact, CTS_CF_NAME_VALUE, ctsValue);
+       contacts_svc_value_free(ctsValue);
+}
+
+void ContactObjectA2PConverter::importNameValueToExistingValue(CTSvalue *ctsValue, ContactNamePtr &contactName)
+{
+       int errorCode = 0;
+
+       const char *newValueStr = NULL;
+       const char *oldValueStr = NULL;
+       string abstractValueStr;
+
+       // ContactName.firstName
+       oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_FIRST_STR);
+       abstractValueStr = contactName->getFirstName();
+       if(oldValueStr != NULL && (!contactName->getFirstNameIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_FIRST_STR, newValueStr);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       contacts_svc_value_free(ctsValue);
+                       ThrowMsg(PlatformException, "importing firstName E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+
+       // ContactName.lastName
+       newValueStr = NULL;
+       oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_LAST_STR);
+       abstractValueStr = contactName->getLastName();
+       if(oldValueStr != NULL && (!contactName->getLastNameIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_LAST_STR, newValueStr);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       contacts_svc_value_free(ctsValue);
+                       ThrowMsg(PlatformException, "importing lastName E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+
+       // ContactName.middleName
+       newValueStr = NULL;
+       oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_ADDITION_STR);
+       abstractValueStr = contactName->getMiddleName();
+       if(oldValueStr != NULL && (!contactName->getMiddleNameIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_ADDITION_STR, newValueStr);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       contacts_svc_value_free(ctsValue);
+                       ThrowMsg(PlatformException, "importing middleName E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+
+       // ContactName.prefix
+       newValueStr = NULL;
+       oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_PREFIX_STR);
+       abstractValueStr = contactName->getPrefix();
+       if(oldValueStr != NULL && (!contactName->getPrefixIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_PREFIX_STR, newValueStr);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       contacts_svc_value_free(ctsValue);
+                       ThrowMsg(PlatformException, "importing prefix E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+
+//     // ContactName.phoneticFirstName
+//     newValueStr = NULL;
+//     oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_PHONETIC_FIRST_STR);
+//     abstractValueStr = contactName->getPhoneticFirstName();
+//     if(oldValueStr != NULL && (!contactName->getPhoneticFirstNameIsSet() || abstractValueStr.empty()) )
+//     {
+//             newValueStr = EMPTY_STRING;
+//     }
+//     else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+//     {
+//             newValueStr = abstractValueStr.c_str();
+//     }
+//
+//     if(newValueStr != NULL)
+//     {
+//             errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_PHONETIC_FIRST_STR, newValueStr);
+//             if(errorCode != CTS_SUCCESS)
+//             {
+//                     contacts_svc_value_free(ctsValue);
+//                     ThrowMsg(PlatformException, "importing phoneticFirstName E (err:" <<
+//                                     errorCode << ", str:" << newValueStr << ")");
+//             }
+//     }
+//
+//     // ContactName.phoneticLastName
+//     newValueStr = NULL;
+//     oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_PHONETIC_LAST_STR);
+//     abstractValueStr = contactName->getPhoneticLastName();
+//     if(oldValueStr != NULL && (!contactName->getPhoneticLastNameIsSet() || abstractValueStr.empty()) )
+//     {
+//             newValueStr = EMPTY_STRING;
+//     }
+//     else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+//     {
+//             newValueStr = abstractValueStr.c_str();
+//     }
+//
+//     if(newValueStr != NULL)
+//     {
+//             errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_PHONETIC_LAST_STR, newValueStr);
+//             if(errorCode != CTS_SUCCESS)
+//             {
+//                     contacts_svc_value_free(ctsValue);
+//                     ThrowMsg(PlatformException, "importing phoneticLastName E (err:" <<
+//                                     errorCode << ", str:" << newValueStr << ")");
+//             }
+//     }
+
+       // ContactName.displayName
+       newValueStr = NULL;
+       oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_DISPLAY_STR);
+       abstractValueStr = contactName->getDisplayName();
+       if(oldValueStr != NULL && (!contactName->getDisplayNameIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_DISPLAY_STR, newValueStr);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       contacts_svc_value_free(ctsValue);
+                       ThrowMsg(PlatformException, "importing displayName E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+}
+
+void ContactObjectA2PConverter::importNameValueToNewValue(CTSvalue *ctsValue, ContactNamePtr &contactName)
+{
+       int errorCode = 0;
+
+       // ContactName.firstName
+       if(contactName->getFirstNameIsSet())
+       {
+               string firstName = contactName->getFirstName();
+               if(firstName != EMPTY_STRING)
+               {
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_FIRST_STR, firstName.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               contacts_svc_value_free(ctsValue);
+                               ThrowMsg(PlatformException, "importing firstName N (err:" <<
+                                               errorCode << ", str:" << firstName << ")");
+                       }
+               }
+       }
+
+       // ContactName.lastName
+       if(contactName->getLastNameIsSet())
+       {
+               string lastName = contactName->getLastName();
+               if(lastName != EMPTY_STRING)
+               {
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_LAST_STR, lastName.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               contacts_svc_value_free(ctsValue);
+                               ThrowMsg(PlatformException, "importing lastName N (err:" <<
+                                               errorCode << ", str:" << lastName << ")");
+                       }
+               }
+       }
+
+       // ContactName.middleName
+       if(contactName->getMiddleNameIsSet())
+       {
+               string middleName = contactName->getMiddleName();
+               if(middleName != EMPTY_STRING)
+               {
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_ADDITION_STR, middleName.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               contacts_svc_value_free(ctsValue);
+                               ThrowMsg(PlatformException, "importing middleName N (err:" <<
+                                               errorCode << ", str:" << middleName << ")");
+                       }
+               }
+       }
+
+       // ContactName.prefix
+       if(contactName->getPrefixIsSet())
+       {
+               string prefix = contactName->getPrefix();
+               if(prefix != EMPTY_STRING)
+               {
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_PREFIX_STR, prefix.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               contacts_svc_value_free(ctsValue);
+                               ThrowMsg(PlatformException, "importing prefix N (err:" <<
+                                               errorCode << ", str:" << prefix << ")");
+                       }
+               }
+       }
+
+//     // ContactName.phoneticFirstName
+//     if(contactName->getPhoneticFirstNameIsSet())
+//     {
+//             string phoneticFirstName = contactName->getPhoneticFirstName();
+//             if(phoneticFirstName != EMPTY_STRING)
+//             {
+//                     errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_PHONETIC_FIRST_STR, phoneticFirstName.c_str());
+//                     if(errorCode != CTS_SUCCESS)
+//                     {
+//                             contacts_svc_value_free(ctsValue);
+//                             ThrowMsg(PlatformException, "importing phoneticFirstName N (err:" <<
+//                                             errorCode << ", str:" << phoneticFirstName << ")");
+//                     }
+//             }
+//     }
+//
+//     // ContactName.phoneticLastName
+//     if(contactName->getPhoneticLastNameIsSet())
+//     {
+//             string phoneticLastName = contactName->getPhoneticLastName();
+//             if(phoneticLastName != EMPTY_STRING)
+//             {
+//                     errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_PHONETIC_LAST_STR, phoneticLastName.c_str());
+//                     if(errorCode != CTS_SUCCESS)
+//                     {
+//                             contacts_svc_value_free(ctsValue);
+//                             ThrowMsg(PlatformException, "importing phoneticLastName N (err:" <<
+//                                             errorCode << ", str:" << phoneticLastName << ")");
+//                     }
+//             }
+//     }
+
+       // ContactName.displayName
+       if(contactName->getDisplayNameIsSet())
+       {
+               string displayName = contactName->getDisplayName();
+               if(displayName != EMPTY_STRING)
+               {
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_DISPLAY_STR, displayName.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               contacts_svc_value_free(ctsValue);
+                               ThrowMsg(PlatformException, "importing displayName N (err:" <<
+                                               errorCode << ", str:" << displayName << ")");
+                       }
+               }
+       }
+}
+
+void ContactObjectA2PConverter::importCompanyValue()
+{
+       int errorCode = 0;
+       CTSvalue *ctsValue = NULL;
+
+       ContactOrganizationPtr contactOrganization = m_abstractContact->getOrganization();
+       if(contactOrganization == NULL ||
+                       ( (!contactOrganization->getNameIsSet() || contactOrganization->getName().empty() )
+                       && (!contactOrganization->getDepartmentIsSet() || contactOrganization->getDepartment().empty() )
+                       && (!contactOrganization->getTitleIsSet() || contactOrganization->getTitle().empty() )
+                       && (!contactOrganization->getRoleIsSet() || contactOrganization->getRole().empty() ) ) )
+       {
+               ctsValue = contacts_svc_value_new(CTS_VALUE_COMPANY);
+               if(ctsValue == NULL)
+                       ThrowMsg(UnknownException, "creating company value A");
+               contacts_svc_struct_store_value(m_platformContact, CTS_CF_COMPANY_VALUE, ctsValue);
+               return;
+       }
+
+       errorCode = contacts_svc_struct_get_value(m_platformContact, CTS_CF_COMPANY_VALUE, &ctsValue);
+       if(errorCode != CTS_SUCCESS || ctsValue == NULL)
+       {
+               ctsValue = contacts_svc_value_new(CTS_VALUE_COMPANY);
+               if(ctsValue == NULL)
+                       ThrowMsg(UnknownException, "creating company value B");
+
+               importCompanyValueToNewValue(ctsValue, contactOrganization);
+       }
+       else
+       {
+               importCompanyValueToExistingValue(ctsValue, contactOrganization);
+       }
+
+
+       contacts_svc_struct_store_value(m_platformContact, CTS_CF_COMPANY_VALUE, ctsValue);
+       contacts_svc_value_free(ctsValue);
+}
+
+void ContactObjectA2PConverter::importCompanyValueToExistingValue(CTSvalue *ctsValue, ContactOrganizationPtr &contactOrganization)
+{
+       int errorCode = 0;
+
+       const char *newValueStr = NULL;
+       const char *oldValueStr = NULL;
+       string abstractValueStr;
+
+       // ContactOrganization.name
+       oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_COMPANY_VAL_NAME_STR);
+       abstractValueStr = contactOrganization->getName();
+       if(oldValueStr != NULL && (!contactOrganization->getNameIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_svc_value_set_str(ctsValue, CTS_COMPANY_VAL_NAME_STR, newValueStr);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       contacts_svc_value_free(ctsValue);
+                       ThrowMsg(PlatformException, "importing company name E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+
+       // ContactOrganization.department
+       newValueStr = NULL;
+       oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_COMPANY_VAL_DEPARTMENT_STR);
+       abstractValueStr = contactOrganization->getDepartment();
+       if(oldValueStr != NULL && (!contactOrganization->getDepartmentIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_svc_value_set_str(ctsValue, CTS_COMPANY_VAL_DEPARTMENT_STR, newValueStr);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       contacts_svc_value_free(ctsValue);
+                       ThrowMsg(PlatformException, "importing department E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+
+       // ContactOrganization.title
+       newValueStr = NULL;
+       oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_COMPANY_VAL_JOB_TITLE_STR);
+       abstractValueStr = contactOrganization->getTitle();
+       if(oldValueStr != NULL && (!contactOrganization->getTitleIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_svc_value_set_str(ctsValue, CTS_COMPANY_VAL_JOB_TITLE_STR, newValueStr);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       contacts_svc_value_free(ctsValue);
+                       ThrowMsg(PlatformException, "importing jobTitle E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+
+       // ContactOrganization.role
+       newValueStr = NULL;
+       oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_COMPANY_VAL_ROLE_STR);
+       abstractValueStr = contactOrganization->getRole();
+       if(oldValueStr != NULL && (!contactOrganization->getRoleIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_svc_value_set_str(ctsValue, CTS_COMPANY_VAL_ROLE_STR, newValueStr);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       contacts_svc_value_free(ctsValue);
+                       ThrowMsg(PlatformException, "importing role E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+}
+
+void ContactObjectA2PConverter::importCompanyValueToNewValue(CTSvalue *ctsValue, ContactOrganizationPtr &contactOrganization)
+{
+       int errorCode = 0;
+
+       // ContactOrganization.name
+       if(contactOrganization->getNameIsSet())
+       {
+               string name = contactOrganization->getName();
+               if(!name.empty())
+               {
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_COMPANY_VAL_NAME_STR, name.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               contacts_svc_value_free(ctsValue);
+                               ThrowMsg(PlatformException, "importing company name N (err:" <<
+                                               errorCode << ", str:" << name << ")");
+                       }
+               }
+       }
+
+       // ContactOrganization.department
+       if(contactOrganization->getDepartmentIsSet())
+       {
+               string department = contactOrganization->getDepartment();
+               if(!department.empty())
+               {
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_COMPANY_VAL_DEPARTMENT_STR, department.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               contacts_svc_value_free(ctsValue);
+                               ThrowMsg(PlatformException, "importing department N (err:" <<
+                                               errorCode << ", str:" << department << ")");
+                       }
+               }
+       }
+
+       // ContactOrganization.title
+       if(contactOrganization->getTitleIsSet())
+       {
+               string title = contactOrganization->getTitle();
+               if(!title.empty())
+               {
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_COMPANY_VAL_JOB_TITLE_STR, title.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               contacts_svc_value_free(ctsValue);
+                               ThrowMsg(PlatformException, "importing title N (err:" <<
+                                               errorCode << ", str:" << title << ")");
+                       }
+               }
+       }
+
+       // ContactOrganization.role
+       if(contactOrganization->getRoleIsSet())
+       {
+               string role = contactOrganization->getRole();
+               if(!role.empty())
+               {
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_COMPANY_VAL_ROLE_STR, role.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               contacts_svc_value_free(ctsValue);
+                               ThrowMsg(PlatformException, "importing role N (err:" <<
+                                               errorCode << ", str:" << role << ")");
+                       }
+               }
+       }
+}
+
+//void ContactObjectA2PConverter::importNoteValue()
+//{
+//     int errorCode = 0;
+//     CTSvalue *ctsValue = NULL;
+//
+//     errorCode = contacts_svc_struct_get_value(m_platformContact, CTS_CF_NOTE_VALUE, &ctsValue);
+//     if(errorCode != CTS_SUCCESS || ctsValue == NULL)
+//     {
+//             ctsValue = contacts_svc_value_new(CTS_VALUE_NOTE);
+//             if(ctsValue == NULL)
+//                     ThrowMsg(UnknownException, "creating note value (ctsValue:NULL)");
+//
+//             importNoteValueToNewValue(ctsValue);
+//     }
+//     else
+//     {
+//             importNoteValueToExistingValue(ctsValue);
+//     }
+//
+//     contacts_svc_struct_store_value(m_platformContact, CTS_CF_NOTE_VALUE, ctsValue);
+//     contacts_svc_value_free(ctsValue);
+//}
+//
+//void ContactObjectA2PConverter::importNoteValueToExistingValue(CTSvalue *ctsValue)
+//{
+//     int errorCode = 0;
+//
+//     const char *newValueStr = NULL;
+//     const char *oldValueStr = NULL;
+//
+//     // note
+//     oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_NOTE_VAL_NOTE_STR);
+//     string note = m_abstractContact->getNote();
+//     if(oldValueStr != NULL && (!m_abstractContact->getNoteIsSet() || note.empty()) )
+//     {
+//             newValueStr = EMPTY_STRING;
+//     }
+//     else if(oldValueStr == NULL || note != oldValueStr)
+//     {
+//             newValueStr = note.c_str();
+//     }
+//
+//     if(newValueStr != NULL)
+//     {
+//             errorCode = contacts_svc_value_set_str(ctsValue, CTS_NOTE_VAL_NOTE_STR, newValueStr);
+//             if(errorCode != CTS_SUCCESS)
+//             {
+//                     contacts_svc_value_free(ctsValue);
+//                     ThrowMsg(PlatformException, "importing note E (err:" <<
+//                                     errorCode << ", str:" << newValueStr << ")");
+//             }
+//     }
+//}
+//
+//void ContactObjectA2PConverter::importNoteValueToNewValue(CTSvalue *ctsValue)
+//{
+//     int errorCode = 0;
+//
+//     if(m_abstractContact->getNoteIsSet())
+//     {
+//             string note = m_abstractContact->getNote();
+//             if(!note.empty())
+//             {
+//                     errorCode = contacts_svc_value_set_str(ctsValue, CTS_NOTE_VAL_NOTE_STR, note.c_str());
+//                     if(errorCode != CTS_SUCCESS)
+//                     {
+//                             contacts_svc_value_free(ctsValue);
+//                             ThrowMsg(PlatformException, "importing note N (err:" <<
+//                                             errorCode << ", str:" << note << ")");
+//                     }
+//             }
+//     }
+//}
+
+void ContactObjectA2PConverter::importNumberList()
+{
+       int errorCode = 0;
+
+       GSList *gsList = NULL;
+       GSList *gsListIter = NULL;
+
+       errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_NUMBER_LIST, &gsList);
+       if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+       {
+               ThrowMsg(PlatformException, "getting number list (err:" <<
+                               errorCode << ", gsList:" << gsList << ")");
+       }
+
+       gsListIter = gsList;
+       for(; gsListIter; gsListIter = g_slist_next(gsListIter))
+       {
+               CTSvalue* ctsValue = static_cast<CTSvalue*>(gsListIter->data);
+               errorCode = contacts_svc_value_set_bool(ctsValue, CTS_NUM_VAL_DELETE_BOOL, true);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       ThrowMsg(PlatformException, "clearing number list (err:" << errorCode << ")");
+               }
+       }
+
+       ContactPhoneNumberArrayPtr phoneNumbers = m_abstractContact->getPhoneNumbers();
+       if(phoneNumbers->size() == 0)
+               return;
+
+       ContactPhoneNumberArray::iterator phoneNumbersIter = phoneNumbers->begin();
+       for(; phoneNumbersIter != phoneNumbers->end(); phoneNumbersIter++)
+       {
+               ContactPhoneNumberPtr phoneNumber = *phoneNumbersIter;
+               ContactPhoneNumberTypeArrayPtr types = phoneNumber->getTypes();
+
+               if(!phoneNumber->getNumberIsSet() || phoneNumber->getNumber().empty())
+               {
+                       LogDebug("Number was not set.");
+                       continue;
+               }
+
+               string number = phoneNumber->getNumber();
+
+               int ctsIntType = 0;
+               bool ctsBoolDefault = false;
+               char *ctsStrCustomType = NULL;
+
+               ContactPhoneNumberTypeArray::iterator typesIter = types->begin();
+               for(; typesIter != types->end(); typesIter++)
+               {
+                       ContactPhoneNumberType type = *typesIter;
+                       if(type == CONTACT_PHONE_NUMBER_TYPE_HOME)
+                               ctsIntType = ctsIntType | CTS_NUM_TYPE_HOME;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_WORK)
+                               ctsIntType = ctsIntType | CTS_NUM_TYPE_WORK;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_VOICE)
+                               ctsIntType = ctsIntType | CTS_NUM_TYPE_VOICE;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_FAX)
+                               ctsIntType = ctsIntType | CTS_NUM_TYPE_FAX;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_MSG)
+                               ctsIntType = ctsIntType | CTS_NUM_TYPE_MSG;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_CELL)
+                               ctsIntType = ctsIntType | CTS_NUM_TYPE_CELL;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_PAGER)
+                               ctsIntType = ctsIntType | CTS_NUM_TYPE_PAGER;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_BBS)
+                               ctsIntType = ctsIntType | CTS_NUM_TYPE_BBS;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_MODEM)
+                               ctsIntType = ctsIntType | CTS_NUM_TYPE_MODEM;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_CAR)
+                               ctsIntType = ctsIntType | CTS_NUM_TYPE_CAR;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_ISDN)
+                               ctsIntType = ctsIntType | CTS_NUM_TYPE_ISDN;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_VIDEO)
+                               ctsIntType = ctsIntType | CTS_NUM_TYPE_VIDEO;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_PCS)
+                               ctsIntType = ctsIntType | CTS_NUM_TYPE_PCS;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_PREF)
+                               ctsBoolDefault = true;
+                       else
+                       {
+                               // TODO Will be added after type changed to string
+                               // ctsIntType = ctsIntType | CTS_NUM_TYPE_CUSTOM;
+                               // ctsStrCustomType = ...;
+                       }
+               }
+
+               CTSvalue *ctsValue = contacts_svc_value_new(CTS_VALUE_NUMBER);
+               if(ctsValue == NULL)
+               {
+                       LogWarning("Fail to create CTSvalue with contacts_svc_value_new(CTS_VALUE_NUMBER)");
+                       continue;
+               }
+
+               errorCode = contacts_svc_value_set_str(ctsValue, CTS_NUM_VAL_NUMBER_STR, number.c_str());
+               if(errorCode != CTS_SUCCESS)
+               {
+                       LogWarning("Fail to set number value to ctsValue str : " << number);
+                       contacts_svc_value_free(ctsValue);
+                       continue;
+               }
+
+               errorCode = contacts_svc_value_set_bool(ctsValue, CTS_NUM_VAL_DEFAULT_BOOL, ctsBoolDefault);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       LogWarning("Fail to set favorite value to ctsValue default : " << ctsBoolDefault);
+                       contacts_svc_value_free(ctsValue);
+                       continue;
+               }
+
+               errorCode = contacts_svc_value_set_int(ctsValue, CTS_NUM_VAL_TYPE_INT, ctsIntType);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       LogWarning("Fail to set default value to ctsValue type : " << ctsIntType);
+                       contacts_svc_value_free(ctsValue);
+                       continue;
+               }
+
+//             if(ctsStrCustomType != NULL)
+//             {
+//                     errorCode = contacts_svc_value_set_str(ctsValue, CTS_NUM_VAL_LABEL_STR, ctsStrCustomType);
+//                     if(errorCode != CTS_SUCCESS)
+//                     {
+//                             LogWarning("Fail to set custom value to ctsValue type : " << ctsStrCustomType);
+//                             contacts_svc_value_free(ctsValue);
+//                             continue;
+//                     }
+//             }
+
+               gsList = g_slist_append(gsList, ctsValue);
+       }
+
+       contacts_svc_struct_store_list(m_platformContact, CTS_CF_NUMBER_LIST, gsList);
+
+       for (; gsList; gsList = g_slist_next(gsList))
+               contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
+
+       g_slist_free(gsList);
+}
+
+void ContactObjectA2PConverter::importEmailList()
+{
+       int errorCode = 0;
+
+       GSList *gsList = NULL;
+       GSList *gsListIter = NULL;
+
+       errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_EMAIL_LIST, &gsList);
+       if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+       {
+               ThrowMsg(PlatformException, "getting email list (err:" <<
+                               errorCode << ", gsList:" << gsList << ")");
+       }
+
+       gsListIter = gsList;
+       for(; gsListIter; gsListIter = g_slist_next(gsListIter))
+       {
+               CTSvalue* ctsValue = static_cast<CTSvalue*>(gsListIter->data);
+               errorCode = contacts_svc_value_set_bool(ctsValue, CTS_EMAIL_VAL_DELETE_BOOL, true);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       ThrowMsg(PlatformException, "clearing email list (err:" << errorCode << ")");
+               }
+       }
+
+       ContactEmailAddressArrayPtr emails = m_abstractContact->getEmails();
+       if(emails->size() == 0)
+               return;
+
+       ContactEmailAddressArray::iterator emailsIter = emails->begin();
+       for(; emailsIter != emails->end(); emailsIter++)
+       {
+               ContactEmailAddressPtr email = *emailsIter;
+               ContactEmailAddressTypeArrayPtr types = email->getTypes();
+
+               if(!email->getEmailIsSet() || email->getEmail().empty())
+               {
+                       LogDebug("email address was not set.");
+                       continue;
+               }
+
+               string emailAddress = email->getEmail();
+
+               int ctsIntType = 0;
+               bool ctsBoolDefault = false;
+               char *ctsStrCustomType = NULL;
+
+               ContactEmailAddressTypeArray::iterator typesIter = types->begin();
+               for(; typesIter != types->end(); typesIter++)
+               {
+                       ContactEmailAddressType type = *typesIter;
+                       if(type == CONTACT_EMAIL_TYPE_HOME)
+                               ctsIntType = ctsIntType | CTS_EMAIL_TYPE_HOME;
+                       else if(type == CONTACT_EMAIL_TYPE_WORK)
+                               ctsIntType = ctsIntType | CTS_EMAIL_TYPE_WORK;
+                       else if(type == CONTACT_EMAIL_TYPE_PREF)
+                               ctsBoolDefault = true;
+                       else
+                       {
+                               // TODO Will be added after type changed to string
+                               // ctsIntType = ctsIntType | CTS_EMAIL_TYPE_CUSTOM;
+                               // ctsStrCustomType = ...;
+                       }
+               }
+
+               CTSvalue *ctsValue = contacts_svc_value_new(CTS_VALUE_EMAIL);
+               if(ctsValue == NULL)
+               {
+                       LogWarning("Fail to create CTSvalue with contacts_svc_value_new(CTS_VALUE_EMAIL)");
+                       continue;
+               }
+
+               errorCode = contacts_svc_value_set_str(ctsValue, CTS_EMAIL_VAL_ADDR_STR, emailAddress.c_str());
+               if(errorCode != CTS_SUCCESS)
+               {
+                       LogWarning("Fail to set email value to ctsValue str : " << emailAddress);
+                       contacts_svc_value_free(ctsValue);
+                       continue;
+               }
+
+               errorCode = contacts_svc_value_set_bool(ctsValue, CTS_EMAIL_VAL_DEFAULT_BOOL, ctsBoolDefault);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       LogWarning("Fail to set favorite value to ctsValue default : " << ctsBoolDefault);
+                       contacts_svc_value_free(ctsValue);
+                       continue;
+               }
+
+               errorCode = contacts_svc_value_set_int(ctsValue, CTS_EMAIL_VAL_TYPE_INT, ctsIntType);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       LogWarning("Fail to set default value to ctsValue type : " << ctsIntType);
+                       contacts_svc_value_free(ctsValue);
+                       continue;
+               }
+
+//             if(ctsStrCustomType != NULL)
+//             {
+//                     errorCode = contacts_svc_value_set_str(ctsValue, CTS_EMAIL_VAL_LABEL_STR, ctsStrCustomType);
+//                     if(errorCode != CTS_SUCCESS)
+//                     {
+//                             LogWarning("Fail to set custom value to ctsValue type : " << ctsStrCustomType);
+//                             contacts_svc_value_free(ctsValue);
+//                             continue;
+//                     }
+//             }
+
+               gsList = g_slist_append(gsList, ctsValue);
+       }
+
+       contacts_svc_struct_store_list(m_platformContact, CTS_CF_EMAIL_LIST, gsList);
+
+       for (; gsList; gsList = g_slist_next(gsList))
+               contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
+       g_slist_free(gsList);
+}
+
+void ContactObjectA2PConverter::importGrouprelList()
+{
+       int errorCode = 0;
+
+       GSList *gsList = NULL;
+       GSList *gsListIter = NULL;
+
+       errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_GROUPREL_LIST, &gsList);
+       if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+       {
+               ThrowMsg(PlatformException, "getting grouprel list (err:" <<
+                               errorCode << ", gsList:" << gsList << ")");
+       }
+
+       gsListIter = gsList;
+       for(; gsListIter; gsListIter = g_slist_next(gsListIter))
+       {
+               CTSvalue* ctsValue = static_cast<CTSvalue*>(gsListIter->data);
+               errorCode = contacts_svc_value_set_bool(ctsValue, CTS_GROUPREL_VAL_DELETE_BOOL, true);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       ThrowMsg(PlatformException, "clearing grouprel list (err:" << errorCode << ")");
+               }
+       }
+
+       if(m_abstractContact->getCategoriesNum() == 0)
+               return;
+
+       CTSiter* ctsIterGroup = NULL;
+       GSList *gsListGroups = NULL;
+
+       int addressBookId = ContactUtility::strToInt(m_abstractContact->getAddressBookId());
+
+       StringArrayPtr categories = m_abstractContact->getCategories();
+
+       StringArray::iterator categoriesIter = categories->begin();
+       for(; categoriesIter != categories->end(); categoriesIter++)
+       {
+               string category = *categoriesIter;
+
+               errorCode = contacts_svc_get_list(CTS_LIST_ALL_GROUP, &ctsIterGroup);
+               if (errorCode == CTS_SUCCESS)
+               {
+                       while (contacts_svc_iter_next(ctsIterGroup) == CTS_SUCCESS)
+                       {
+                               CTSvalue *ctsValueFoundGroup = contacts_svc_iter_get_info(ctsIterGroup);
+                               if (ctsValueFoundGroup)
+                               {
+                                       group_info_t* groupInfo = g_new0(group_info_t, 1);
+
+                                       groupInfo->group_name = g_strdup(contacts_svc_value_get_str(ctsValueFoundGroup, CTS_LIST_GROUP_NAME_STR));
+                                       groupInfo->addressbook_id = contacts_svc_value_get_int(ctsValueFoundGroup, CTS_GROUP_VAL_ADDRESSBOOK_ID_INT);
+                                       groupInfo->group_id = contacts_svc_value_get_int(ctsValueFoundGroup, CTS_GROUP_VAL_ID_INT);
+                                       gsListGroups = g_slist_append(gsListGroups, groupInfo);
+                               }
+                       }
+               }
+
+               CTSvalue *group = contacts_svc_value_new(CTS_VALUE_GROUP_RELATION);
+               if(group == NULL)
+               {
+                       LogWarning("Fail to create CTSvalue with contacts_svc_value_new(CTS_VALUE_GROUP_RELATION)");
+                       continue;
+               }
+
+               int groupId = -1;
+
+               bool isNewGroup = true;
+               GSList* gsListGroupsIter = gsListGroups;
+               for(; gsListGroupsIter; gsListGroupsIter=g_slist_next(gsListGroupsIter))
+               {
+                       group_info_t* groupInfo = (group_info_t*)gsListGroupsIter->data;
+
+                       if ((groupInfo->group_name != NULL) &&
+                                       (category == groupInfo->group_name) &&
+                                       (groupInfo->addressbook_id == addressBookId))
+                       {
+                               isNewGroup = false;
+                               groupId = groupInfo->group_id;
+                       }
+
+                       if (groupInfo->group_name)
+                               free(groupInfo->group_name);
+                       free(groupInfo);
+               }
+
+               g_slist_free(gsListGroups);
+               gsListGroups = NULL;
+
+               if (isNewGroup)
+               {
+                       CTSvalue *ctsValueNewGroup;
+                       ctsValueNewGroup = contacts_svc_value_new(CTS_VALUE_GROUP);
+
+                       contacts_svc_value_set_str(ctsValueNewGroup, CTS_GROUP_VAL_NAME_STR, (const char*)(category.c_str()));
+                       contacts_svc_value_set_int(ctsValueNewGroup, CTS_GROUP_VAL_ADDRESSBOOK_ID_INT, addressBookId);
+                       groupId = contacts_svc_insert_group(addressBookId, ctsValueNewGroup);
+                       if (groupId < 0)
+                       {
+                               ThrowMsg(PlatformException, "contacts_svc_insert_group (groupId:" << groupId << ")");
+                       }
+
+                       contacts_svc_value_free(ctsValueNewGroup);
+               }
+
+               if (groupId == -1)
+               {
+                       for (; gsList; gsList = g_slist_next(gsList))
+                               contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
+                       g_slist_free(gsList);
+
+                       ThrowMsg(PlatformException, "groupId is not properly set");
+               }
+
+               errorCode = contacts_svc_value_set_int(group, CTS_GROUPREL_VAL_ID_INT, groupId);
+               if (errorCode != CTS_SUCCESS)
+               {
+                       for (; gsList; gsList = g_slist_next(gsList))
+                               contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
+                       g_slist_free(gsList);
+
+                       ThrowMsg(PlatformException, "Fail to set group type value to ctsValue group (err:" << errorCode << ")");
+               }
+
+               gsList = g_slist_append(gsList, group);
+       }
+
+       contacts_svc_struct_store_list(m_platformContact, CTS_CF_GROUPREL_LIST, gsList);
+
+       for (; gsList; gsList = g_slist_next(gsList))
+               contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
+       g_slist_free(gsList);
+}
+
+void ContactObjectA2PConverter::importEventList()
+{
+       int errorCode = 0;
+
+       GSList *gsList = NULL;
+       GSList *gsListIter = NULL;
+
+       errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_EVENT_LIST, &gsList);
+       if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+       {
+               ThrowMsg(PlatformException, "getting event list (err:" <<
+                               errorCode << ", gsList:" << gsList << ")");
+       }
+
+       gsListIter = gsList;
+       for(; gsListIter; gsListIter = g_slist_next(gsListIter))
+       {
+               CTSvalue* ctsValue = static_cast<CTSvalue*>(gsListIter->data);
+               errorCode = contacts_svc_value_set_bool(ctsValue, CTS_EVENT_VAL_DELETE_BOOL, true);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       ThrowMsg(PlatformException, "clearing event list (err:" << errorCode << ")");
+               }
+       }
+
+       if(!m_abstractContact->getBirthdayIsSet() && m_abstractContact->getAnniversariesNum() == 0)
+               return;
+
+       gsList = importEventListBirthday(gsList);
+
+       gsList = importEventListAnniversary(gsList);
+
+       contacts_svc_struct_store_list(m_platformContact, CTS_CF_EVENT_LIST, gsList);
+
+       for (; gsList; gsList = g_slist_next(gsList))
+               contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
+       g_slist_free(gsList);
+}
+
+GSList * ContactObjectA2PConverter::importEventListBirthday(GSList *gsList)
+{
+       int errorCode = 0;
+
+       if(!m_abstractContact->getBirthdayIsSet())
+               return gsList;
+
+       tm birthdayTm = m_abstractContact->getBirthday();
+
+       if (birthdayTm.tm_year == 0 && birthdayTm.tm_mon == 0 && birthdayTm.tm_mday == 0)
+               return gsList;
+
+       int birthday = ( ( birthdayTm.tm_year + 1900) * 10000 ) +
+                       ( ( birthdayTm.tm_mon + 1 ) * 100 ) +
+                       birthdayTm.tm_mday;
+
+       CTSvalue *ctsValue = NULL;
+       ctsValue = contacts_svc_value_new(CTS_VALUE_EVENT);
+       if(ctsValue == NULL)
+       {
+               LogWarning("Fail to create CTSvalue with contacts_svc_value_new(CTS_VALUE_EVENT)");
+               return gsList;
+       }
+
+       errorCode = contacts_svc_value_set_int(ctsValue, CTS_EVENT_VAL_TYPE_INT, CTS_EVENT_TYPE_BIRTH);
+       if(errorCode != CTS_SUCCESS)
+       {
+               LogWarning("Fail to set event type value to ctsValue value : birthday");
+               contacts_svc_value_free(ctsValue);
+               return gsList;
+       }
+
+       errorCode = contacts_svc_value_set_int(ctsValue, CTS_EVENT_VAL_DATE_INT, birthday);
+       if(errorCode != CTS_SUCCESS)
+       {
+               LogWarning("Fail to set birthday value to ctsValue type : " << birthday);
+               contacts_svc_value_free(ctsValue);
+               return gsList;
+       }
+
+       gsList = g_slist_append(gsList, ctsValue);
+
+       return gsList;
+}
+
+GSList * ContactObjectA2PConverter::importEventListAnniversary(GSList *gsList)
+{
+       int errorCode = 0;
+
+       if(m_abstractContact->getAnniversariesNum() == 0)
+               return gsList;
+
+       ContactAnniversaryArrayPtr anniversaries = m_abstractContact->getAnniversaries();
+
+       ContactAnniversaryArray::iterator anniversariesIter = anniversaries->begin();
+       for(; anniversariesIter != anniversaries->end(); anniversariesIter++)
+       {
+               ContactAnniversaryPtr anniversary = *anniversariesIter;
+
+               if(!anniversary->getDateIsSet())
+                       continue;
+
+               tm dateTm = anniversary->getDate();
+
+               if (dateTm.tm_year == 0 && dateTm.tm_mon == 0 && dateTm.tm_mday == 0)
+                       continue;
+
+               int date = ( ( dateTm.tm_year + 1900) * 10000 ) +
+                               ( ( dateTm.tm_mon + 1 ) * 100 ) +
+                               dateTm.tm_mday;
+
+               CTSvalue *ctsValue = NULL;
+               ctsValue = contacts_svc_value_new(CTS_VALUE_EVENT);
+               if(ctsValue == NULL)
+               {
+                       LogWarning("Fail to create CTSvalue with contacts_svc_value_new(CTS_VALUE_EVENT)");
+                       continue;
+               }
+
+               errorCode = contacts_svc_value_set_int(ctsValue, CTS_EVENT_VAL_TYPE_INT, CTS_EVENT_TYPE_ANNIVERSARY);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       LogWarning("Fail to set event type value to ctsValue value : birthday");
+                       contacts_svc_value_free(ctsValue);
+                       continue;
+               }
+
+               errorCode = contacts_svc_value_set_int(ctsValue, CTS_EVENT_VAL_DATE_INT, date);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       LogWarning("Fail to set date value to ctsValue type : " << date);
+                       contacts_svc_value_free(ctsValue);
+                       continue;
+               }
+
+//             if(anniversary->getLabelIsSet())
+//             {
+//                     string label = anniversary->getLabel();
+//                     errorCode = contacts_svc_value_set_str(ctsValue, CTS_EVENT_VAL_LABEL_STR, label.c_str());
+//                     if(errorCode != CTS_SUCCESS)
+//                     {
+//                             LogWarning("Fail to set label value to ctsValue type : " << label);
+//                             contacts_svc_value_free(ctsValue);
+//                             continue;
+//                     }
+//
+//             }
+
+               gsList = g_slist_append(gsList, ctsValue);
+       }
+
+       return gsList;
+}
+
+void ContactObjectA2PConverter::importPostalList()
+{
+       int errorCode = 0;
+
+       GSList *gsList = NULL;
+       GSList *gsListIter = NULL;
+
+       errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_POSTAL_ADDR_LIST, &gsList);
+       if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+       {
+               ThrowMsg(PlatformException, "getting postal list (err:" <<
+                               errorCode << ", gsList:" << gsList << ")");
+       }
+
+       gsListIter = gsList;
+       for(; gsListIter; gsListIter = g_slist_next(gsListIter))
+       {
+               CTSvalue* ctsValue = static_cast<CTSvalue*>(gsListIter->data);
+               errorCode = contacts_svc_value_set_bool(ctsValue, CTS_POSTAL_VAL_DELETE_BOOL, true);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       ThrowMsg(PlatformException, "clearing postal list (err:" << errorCode << ")");
+               }
+       }
+
+       if(m_abstractContact->getAddressesNum() == 0)
+               return;
+
+       ContactAddressArrayPtr addresses = m_abstractContact->getAddresses();
+
+       ContactAddressArray::iterator addressesIter = addresses->begin();
+       for(; addressesIter != addresses->end(); addressesIter++)
+       {
+               ContactAddressPtr address = *addressesIter;
+               ContactAddressTypeArrayPtr types = address->getTypes();
+
+               if(( !address->getCountryIsSet() || address->getCountry().empty() ) &&
+                               ( !address->getRegionIsSet() || address->getRegion().empty() ) &&
+                               ( !address->getCityIsSet() || address->getCity().empty() ) &&
+                               ( !address->getStreetAddressIsSet() || address->getStreetAddress().empty() ) &&
+                               ( !address->getAdditionalInformationIsSet() || address->getAdditionalInformation().empty() ) &&
+                               ( !address->getPostalCodeIsSet() || address->getPostalCode().empty() ) )
+               {
+                       LogDebug("No information for address was not set.");
+                       continue;
+               }
+
+               int ctsIntType = 0;
+               bool ctsBoolDefault = false;
+               char *ctsStrCustomType = NULL;
+
+               ContactAddressTypeArray::iterator typesIter = types->begin();
+               for(; typesIter != types->end(); typesIter++)
+               {
+                       ContactAddressType type = *typesIter;
+                       if(type == CONTACT_ADDRESS_TYPE_HOME)
+                               ctsIntType = ctsIntType | CTS_ADDR_TYPE_HOME;
+                       else if(type == CONTACT_ADDRESS_TYPE_WORK)
+                               ctsIntType = ctsIntType | CTS_ADDR_TYPE_WORK;
+                       else if(type == CONTACT_ADDRESS_TYPE_PREF)
+                               ctsBoolDefault = true;
+                       else
+                       {
+                               // TODO Will be added after type changed to string
+                               // ctsIntType = ctsIntType | CTS_POSTAL_TYPE_CUSTOM;
+                               // ctsStrCustomType = ...;
+                       }
+               }
+
+               CTSvalue *ctsValue = contacts_svc_value_new(CTS_VALUE_POSTAL);
+               if(ctsValue == NULL)
+               {
+                       LogWarning("Fail to create CTSvalue with contacts_svc_value_new(CTS_VALUE_POSTAL)");
+                       continue;
+               }
+
+               if(address->getCountryIsSet())
+               {
+                       string country = address->getCountry();
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_POSTAL_VAL_COUNTRY_STR, country.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               LogWarning("Fail to set country value to ctsValue str : " << country);
+                               contacts_svc_value_free(ctsValue);
+                               continue;
+                       }
+               }
+
+               if(address->getRegionIsSet())
+               {
+                       string region = address->getRegion();
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_POSTAL_VAL_REGION_STR, region.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               LogWarning("Fail to set region value to ctsValue str : " << region);
+                               contacts_svc_value_free(ctsValue);
+                               continue;
+                       }
+               }
+
+               if(address->getCityIsSet())
+               {
+                       string city = address->getCity();
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_POSTAL_VAL_LOCALITY_STR, city.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               LogWarning("Fail to set city value to ctsValue str : " << city);
+                               contacts_svc_value_free(ctsValue);
+                               continue;
+                       }
+               }
+
+               if(address->getStreetAddressIsSet())
+               {
+                       string streetAddress = address->getStreetAddress();
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_POSTAL_VAL_STREET_STR, streetAddress.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               LogWarning("Fail to set street value to ctsValue str : " << streetAddress);
+                               contacts_svc_value_free(ctsValue);
+                               continue;
+                       }
+               }
+
+               if(address->getAdditionalInformationIsSet())
+               {
+                       string additionalInformation = address->getAdditionalInformation();
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_POSTAL_VAL_EXTENDED_STR, additionalInformation.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               LogWarning("Fail to set extended value to ctsValue str : " << additionalInformation);
+                               contacts_svc_value_free(ctsValue);
+                               continue;
+                       }
+               }
+
+               if(address->getPostalCodeIsSet())
+               {
+                       string postalCode = address->getPostalCode();
+                       errorCode = contacts_svc_value_set_str(ctsValue, CTS_POSTAL_VAL_POSTALCODE_STR, postalCode.c_str());
+                       if(errorCode != CTS_SUCCESS)
+                       {
+                               LogWarning("Fail to set postalcode value to ctsValue str : " << postalCode);
+                               contacts_svc_value_free(ctsValue);
+                               continue;
+                       }
+               }
+
+               errorCode = contacts_svc_value_set_bool(ctsValue, CTS_POSTAL_VAL_DEFAULT_BOOL, ctsBoolDefault);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       LogWarning("Fail to set favorite value to ctsValue default : " << ctsBoolDefault);
+                       contacts_svc_value_free(ctsValue);
+                       continue;
+               }
+
+               errorCode = contacts_svc_value_set_int(ctsValue, CTS_POSTAL_VAL_TYPE_INT, ctsIntType);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       LogWarning("Fail to set default value to ctsValue type : " << ctsIntType);
+                       contacts_svc_value_free(ctsValue);
+                       continue;
+               }
+
+//             if(ctsStrCustomType != NULL)
+//             {
+//                     errorCode = contacts_svc_value_set_str(ctsValue, CTS_POSTAL_VAL_LABEL_STR, ctsStrCustomType);
+//                     if(errorCode != CTS_SUCCESS)
+//                     {
+//                             LogWarning("Fail to set custom value to ctsValue type : " << ctsStrCustomType);
+//                             contacts_svc_value_free(ctsValue);
+//                             continue;
+//                     }
+//             }
+
+               gsList = g_slist_append(gsList, ctsValue);
+       }
+
+       contacts_svc_struct_store_list(m_platformContact, CTS_CF_POSTAL_ADDR_LIST, gsList);
+
+       for (; gsList; gsList = g_slist_next(gsList))
+               contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
+       g_slist_free(gsList);
+}
+
+void ContactObjectA2PConverter::importWebAddrList()
+{
+       int errorCode = 0;
+
+       GSList *gsList = NULL;
+       GSList *gsListIter = NULL;
+
+       errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_WEB_ADDR_LIST, &gsList);
+       if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+       {
+               ThrowMsg(PlatformException, "getting web addr list (err:" <<
+                               errorCode << ", gsList:" << gsList << ")");
+       }
+
+       gsListIter = gsList;
+       for(; gsListIter; gsListIter = g_slist_next(gsListIter))
+       {
+               CTSvalue* ctsValue = static_cast<CTSvalue*>(gsListIter->data);
+               errorCode = contacts_svc_value_set_bool(ctsValue, CTS_WEB_VAL_DELETE_BOOL, true);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       ThrowMsg(PlatformException, "clearing web addr list (err:" << errorCode << ")");
+               }
+       }
+
+       ContactWebSiteArrayPtr webSites = m_abstractContact->getUrls();
+       if(webSites->size() == 0)
+               return;
+
+       ContactWebSiteArray::iterator webSiteIter = webSites->begin();
+       for(; webSiteIter != webSites->end(); webSiteIter++)
+       {
+               ContactWebSitePtr webSite = *webSiteIter;
+               ContactWebSiteType type = webSite->getType();
+
+               if(!webSite->getUrlIsSet() || webSite->getUrl().empty())
+               {
+                       LogDebug("url was not set.");
+                       continue;
+               }
+
+               string url = webSite->getUrl();
+
+               int ctsIntType = 0;
+               char *ctsStrCustomType = NULL;
+
+               if(type == WEBSITE_TYPE_HOMEPAGE)
+                       ctsIntType = CTS_WEB_TYPE_HOME;
+               else if(type == WEBSITE_TYPE_BLOG)
+                       ctsIntType = CTS_WEB_TYPE_WORK;
+               else
+               {
+                       // TODO Will be added after type changed to string
+                       // ctsIntType = CTS_WEB_TYPE_CUSTOM;
+                       // ctsStrCustomType = ...;
+               }
+
+               CTSvalue *ctsValue = contacts_svc_value_new(CTS_VALUE_WEB);
+               if(ctsValue == NULL)
+               {
+                       LogWarning("Fail to create CTSvalue with contacts_svc_value_new(CTS_VALUE_WEB)");
+                       continue;
+               }
+
+               errorCode = contacts_svc_value_set_str(ctsValue, CTS_WEB_VAL_ADDR_STR, url.c_str());
+               if(errorCode != CTS_SUCCESS)
+               {
+                       LogWarning("Fail to set url value to ctsValue str : " << url);
+                       contacts_svc_value_free(ctsValue);
+                       continue;
+               }
+
+               errorCode = contacts_svc_value_set_int(ctsValue, CTS_WEB_VAL_TYPE_INT, ctsIntType);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       LogWarning("Fail to set default value to ctsValue type : " << ctsIntType);
+                       contacts_svc_value_free(ctsValue);
+                       continue;
+               }
+
+//             if(ctsStrCustomType != NULL)
+//             {
+//                     errorCode = contacts_svc_value_set_str(ctsValue, CTS_WEB_VAL_LABEL_STR, ctsStrCustomType);
+//                     if(errorCode != CTS_SUCCESS)
+//                     {
+//                             LogWarning("Fail to set custom value to ctsValue type : " << ctsStrCustomType);
+//                             contacts_svc_value_free(ctsValue);
+//                             continue;
+//                     }
+//             }
+
+               gsList = g_slist_append(gsList, ctsValue);
+       }
+
+       contacts_svc_struct_store_list(m_platformContact, CTS_CF_WEB_ADDR_LIST, gsList);
+
+       for (; gsList; gsList = g_slist_next(gsList))
+               contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
+       g_slist_free(gsList);
+}
+
+void ContactObjectA2PConverter::importNicknameList()
+{
+       int errorCode = 0;
+
+       GSList *gsList = NULL;
+       GSList *gsListIter = NULL;
+
+       errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_NICKNAME_LIST, &gsList);
+       if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+       {
+               ThrowMsg(PlatformException, "getting nickname list (err:" <<
+                               errorCode << ", gsList:" << gsList << ")");
+       }
+
+       gsListIter = gsList;
+       for(; gsListIter; gsListIter = g_slist_next(gsListIter))
+       {
+               CTSvalue* ctsValue = static_cast<CTSvalue*>(gsListIter->data);
+               errorCode = contacts_svc_value_set_bool(ctsValue, CTS_NICKNAME_VAL_DELETE_BOOL, true);
+               if(errorCode != CTS_SUCCESS)
+               {
+                       ThrowMsg(PlatformException, "clearing nickname list (err:" << errorCode << ")");
+               }
+       }
+
+       ContactNamePtr contactName = m_abstractContact->getName();
+       if(contactName == NULL)
+               return;
+
+       if(contactName->getNicknamesNum() == 0)
+               return;
+
+       StringArrayPtr nicknames = contactName->getNicknames();
+
+       StringArray::iterator nicknamesIter = nicknames->begin();
+       for(; nicknamesIter != nicknames->end(); nicknamesIter++)
+       {
+               string nickname = *nicknamesIter;
+
+               if(nickname.empty())
+               {
+                       LogDebug("nickname was not set.");
+                       continue;
+               }
+
+               CTSvalue *ctsValue = contacts_svc_value_new(CTS_VALUE_NICKNAME);
+               if(ctsValue == NULL)
+               {
+                       LogWarning("Fail to create CTSvalue with contacts_svc_value_new(CTS_VALUE_NICKNAME)");
+                       continue;
+               }
+
+               errorCode = contacts_svc_value_set_str(ctsValue, CTS_NICKNAME_VAL_NAME_STR, nickname.c_str());
+               if(errorCode != CTS_SUCCESS)
+               {
+                       LogWarning("Fail to set nickname value to ctsValue str : " << nickname);
+                       contacts_svc_value_free(ctsValue);
+                       continue;
+               }
+
+               gsList = g_slist_append(gsList, ctsValue);
+       }
+
+       contacts_svc_struct_store_list(m_platformContact, CTS_CF_NICKNAME_LIST, gsList);
+
+       for (; gsList; gsList = g_slist_next(gsList))
+               contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
+       g_slist_free(gsList);
+}
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/ContactObjectA2PConverter.h b/src/platform/Tizen/Contact/ContactObjectA2PConverter.h
new file mode 100644 (file)
index 0000000..f4ac741
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        ContactObjectA2PConverter.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Converter (TizenApis::Api::Contact::ContactPtr -> CTSstruct*)
+ */
+
+#ifndef _PLATFORM_CONTACT_CONTACT_OBJECT_A2P_CONVERTER_H_
+#define _PLATFORM_CONTACT_CONTACT_OBJECT_A2P_CONVERTER_H_
+
+#include <string>
+#include <contacts-svc.h>
+#include <dpl/shared_ptr.h>
+#include <API/Contact/IContact.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class ContactObjectA2PConverter
+{
+public:
+       ContactObjectA2PConverter(const TizenApis::Api::Contact::ContactPtr &abstractContact,
+                              bool forScratch);
+       ContactObjectA2PConverter(const TizenApis::Api::Contact::ContactPtr &abstractContact,
+                                 bool forScratch,
+                                 CTSstruct* platformContact);
+       virtual ~ContactObjectA2PConverter();
+
+       CTSstruct* getPlatformContact();
+
+protected:
+       void convertToPlatformObject();
+
+       void importBaseInfoValue();
+       void importBaseInfoValueToExistingValue(CTSvalue *ctsValue);
+       void importBaseInfoValueToNewValue(CTSvalue *ctsValue);
+
+       void importNameValue();
+       void importNameValueToExistingValue(CTSvalue *ctsValue,
+                                                   TizenApis::Api::Contact::ContactNamePtr &contactName);
+       void importNameValueToNewValue(CTSvalue *ctsValue,
+                                      TizenApis::Api::Contact::ContactNamePtr &contactName);
+
+       void importCompanyValue();
+       void importCompanyValueToExistingValue(CTSvalue *ctsValue,
+                                              TizenApis::Api::Contact::ContactOrganizationPtr &contactOrganization);
+       void importCompanyValueToNewValue(CTSvalue *ctsValue,
+                                         TizenApis::Api::Contact::ContactOrganizationPtr &contactOrganization);
+
+//     void importNoteValue();
+//     void importNoteValueToExistingValue(CTSvalue *ctsValue);
+//     void importNoteValueToNewValue(CTSvalue *ctsValue);
+
+       void importNumberList();
+
+       void importEmailList();
+
+       void importGrouprelList();
+
+       void importEventList();
+       GSList * importEventListBirthday(GSList *gsList);
+       GSList * importEventListAnniversary(GSList *gsList);
+
+       void importPostalList();
+
+       void importWebAddrList();
+
+       void importNicknameList();
+
+       TizenApis::Api::Contact::ContactPtr m_abstractContact;
+       CTSstruct*                          m_platformContact;
+       bool                                m_forScratch;
+       bool                                m_convertFinished;
+       bool                                m_platformContactOwnership;
+};
+typedef DPL::SharedPtr<ContactObjectA2PConverter> ContactObjectA2PConverterPtr;
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_CONTACT_CONTACT_ABSTRACT_OBJECT_WRAPPER_H_
diff --git a/src/platform/Tizen/Contact/ContactObjectP2AConverter.cpp b/src/platform/Tizen/Contact/ContactObjectP2AConverter.cpp
new file mode 100644 (file)
index 0000000..f43d19a
--- /dev/null
@@ -0,0 +1,842 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        ContactObjectP2AConverter.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Converter (CTSstruct* -> TizenApis::Api::Contact::ContactPtr)
+ */
+
+#include "ContactObjectP2AConverter.h"
+
+#include <vector>
+#include <pcrecpp.h>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include <Commons/Regex.h>
+#include "AddressBook.h"
+#include "Contact.h"
+#include "ContactUtility.h"
+#include "query-svc/query-service.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+ContactObjectP2AConverter::ContactObjectP2AConverter(CTSstruct* platformContact,
+               bool forScratch) :
+               m_platformContact(platformContact),
+               m_abstractContact(ContactPtr(NULL)),
+               m_forScratch(forScratch),
+               m_convertFinished(false)
+{
+}
+
+ContactObjectP2AConverter::ContactObjectP2AConverter(CTSstruct* platformContact,
+               bool forScratch,
+               ContactPtr &abstractContact) :
+               m_platformContact(platformContact),
+               m_abstractContact(abstractContact),
+               m_forScratch(forScratch),
+               m_convertFinished(false)
+{
+}
+
+ContactObjectP2AConverter::~ContactObjectP2AConverter()
+{
+}
+
+ContactPtr ContactObjectP2AConverter::getAbstractContact()
+{
+       LogDebug("enter");
+
+       if(m_platformContact == NULL)
+       {
+               LogError("Platform contact object did not set");
+               ThrowMsg(InvalidArgumentException, "Platform contact object did not set");
+       }
+
+       if(m_abstractContact == NULL)
+       {
+               LogDebug("Abstract contact object did not set, so a new object has been created");
+               m_abstractContact = ContactPtr(new Contact());
+       }
+
+       LogDebug("for scratch : " << m_forScratch);
+
+       Try
+       {
+               if(m_convertFinished == false)
+                       convertToAbstractObject();
+       }
+       Catch(Exception)
+       {
+               LogError("Error while converting - " << _rethrown_exception.GetMessage());
+               ThrowMsg(PlatformException, "Fail to convert platform object to abstract object.");
+       }
+
+       return m_abstractContact;
+}
+
+void ContactObjectP2AConverter::convertToAbstractObject()
+{
+       exportBaseInfoValue();
+       exportNameValue();
+       exportCompanyValue();
+//     exportNoteValue();
+       exportNumberList();
+       exportEmailList();
+       exportGrouprelList();
+       exportEventList();
+       exportPostalList();
+       exportWebAddrList();
+       exportNicknameList();
+
+       m_convertFinished = true;
+}
+
+void ContactObjectP2AConverter::exportBaseInfoValue()
+{
+       int errorCode = 0;
+       CTSvalue *ctsValue = NULL;
+
+       errorCode = contacts_svc_struct_get_value(m_platformContact, CTS_CF_BASE_INFO_VALUE, &ctsValue);
+       if (errorCode != CTS_SUCCESS)
+               ThrowMsg(UnknownException, "getting base info value (err:" << errorCode << ")");
+
+       if(!m_forScratch)
+       {
+               int id = contacts_svc_value_get_int(ctsValue, CTS_BASE_VAL_ID_INT);
+               m_abstractContact->setId(id);
+
+               int addressBookId = contacts_svc_value_get_int(ctsValue, CTS_BASE_VAL_ADDRESSBOOK_ID_INT);
+               m_abstractContact->setAddressBookId(addressBookId);
+
+               time_t changedTime = (time_t)contacts_svc_value_get_int(ctsValue, CTS_BASE_VAL_CHANGED_TIME_INT);
+               struct tm *changedTimeTm = gmtime(&changedTime);
+               m_abstractContact->setLastUpdated(*changedTimeTm);
+       }
+
+       const char *charValue = NULL;
+
+       charValue = contacts_svc_value_get_str(ctsValue, CTS_BASE_VAL_IMG_PATH_STR);
+       if (charValue)
+               m_abstractContact->setPhotoURI(ContactUtility::convertPathToUri(charValue));
+       else
+       {
+               if(m_abstractContact->getPhotoURIIsSet())
+                       m_abstractContact->unsetPhotoURI();
+       }
+
+       charValue = contacts_svc_value_get_str(ctsValue, CTS_BASE_VAL_RINGTONE_PATH_STR);
+       if (charValue)
+               m_abstractContact->setRingtoneURI(ContactUtility::convertPathToUri(charValue));
+       else
+       {
+               if(m_abstractContact->getRingtoneURIIsSet())
+                       m_abstractContact->unsetRingtoneURI();
+       }
+
+       charValue = contacts_svc_value_get_str(ctsValue, CTS_BASE_VAL_NOTE_STR);
+       if (charValue)
+               m_abstractContact->setNote(charValue);
+       else
+       {
+               if(m_abstractContact->getNoteIsSet())
+                       m_abstractContact->unsetNote();
+       }
+}
+
+void ContactObjectP2AConverter::exportNameValue()
+{
+       int errorCode = 0;
+       CTSvalue *ctsValue = NULL;
+
+       errorCode = contacts_svc_struct_get_value(m_platformContact, CTS_CF_NAME_VALUE, &ctsValue);
+       if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+               ThrowMsg(UnknownException, "getting name value (err:" << errorCode << ")");
+
+       if(ctsValue == NULL || errorCode == CTS_ERR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have name value");
+               ContactNamePtr contactName = m_abstractContact->getName();
+               if(contactName != NULL)
+               {
+                       if(contactName->getFirstNameIsSet())
+                               contactName->unsetFirstName();
+
+                       if(contactName->getMiddleNameIsSet())
+                               contactName->unsetMiddleName();
+
+                       if(contactName->getLastNameIsSet())
+                               contactName->unsetLastName();
+
+                       if(contactName->getPrefixIsSet())
+                               contactName->unsetPrefix();
+
+                       if(contactName->getPhoneticFirstNameIsSet())
+                               contactName->unsetPhoneticFirstName();
+
+                       if(contactName->getPhoneticLastNameIsSet())
+                               contactName->unsetPhoneticLastName();
+
+                       if(contactName->getDisplayNameIsSet())
+                               contactName->unsetDisplayName();
+               }
+               return;
+       }
+
+       ContactNamePtr contactName = m_abstractContact->getName();
+       if(contactName == NULL)
+       {
+               contactName = ContactNamePtr(new ContactName());
+               m_abstractContact->setName(contactName);
+       }
+
+       const char *charValue = NULL;
+
+       charValue = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_FIRST_STR);
+       if (charValue)
+               contactName->setFirstName(charValue);
+       else
+       {
+               if(contactName->getFirstNameIsSet())
+                       contactName->unsetFirstName();
+       }
+
+       charValue = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_ADDITION_STR);
+       if (charValue)
+               contactName->setMiddleName(charValue);
+       else
+       {
+               if(contactName->getMiddleNameIsSet())
+                       contactName->unsetMiddleName();
+       }
+
+       charValue = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_LAST_STR);
+       if (charValue)
+               contactName->setLastName(charValue);
+       else
+       {
+               if(contactName->getLastNameIsSet())
+                       contactName->unsetLastName();
+       }
+
+       charValue = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_PREFIX_STR);
+       if (charValue)
+               contactName->setPrefix(charValue);
+       else
+       {
+               if(contactName->getPrefixIsSet())
+                       contactName->unsetPrefix();
+       }
+
+       charValue = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_DISPLAY_STR);
+       if (charValue)
+               contactName->setDisplayName(charValue);
+       else
+       {
+               if(contactName->getDisplayNameIsSet())
+                       contactName->unsetDisplayName();
+       }
+
+//     charValue = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_PHONETIC_NAME_STR);
+//     if (charValue)
+//             contactName->setPhoneticFirstName(charValue);
+//     else
+//     {
+//             if(contactName->getPhoneticFirstNameIsSet())
+//                     contactName->unsetPhoneticFirstName();
+//     }
+//
+//     charValue = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_PHONETIC_LAST_STR);
+//     if (charValue)
+//             contactName->setPhoneticLastName(charValue);
+//     else
+//     {
+//             if(contactName->getPhoneticLastNameIsSet())
+//                     contactName->unsetPhoneticLastName();
+//     }
+}
+
+
+void ContactObjectP2AConverter::exportCompanyValue()
+{
+       int errorCode = 0;
+       CTSvalue *ctsValue = NULL;
+
+       errorCode = contacts_svc_struct_get_value(m_platformContact, CTS_CF_COMPANY_VALUE, &ctsValue);
+       if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+               ThrowMsg(UnknownException, "getting company value (err:" << errorCode << ")");
+
+       if(ctsValue == NULL || errorCode == CTS_ERR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have company value");
+               if(m_abstractContact->getOrganization() != NULL)
+                       m_abstractContact->unsetOrganization();
+
+               return;
+       }
+
+       ContactOrganizationPtr organization = m_abstractContact->getOrganization();
+       if(organization == NULL)
+       {
+               organization = ContactOrganizationPtr(new ContactOrganization());
+               m_abstractContact->setOrganization(organization);
+       }
+
+       const char *charValue = NULL;
+
+       charValue = contacts_svc_value_get_str(ctsValue, CTS_COMPANY_VAL_NAME_STR);
+       if (charValue)
+               organization->setName(charValue);
+       else
+       {
+               if(organization->getNameIsSet())
+                       organization->unsetName();
+       }
+
+       charValue = contacts_svc_value_get_str(ctsValue, CTS_COMPANY_VAL_DEPARTMENT_STR);
+       if (charValue)
+               organization->setDepartment(charValue);
+       else
+       {
+               if(organization->getDepartmentIsSet())
+                       organization->unsetDepartment();
+       }
+
+       charValue = contacts_svc_value_get_str(ctsValue, CTS_COMPANY_VAL_JOB_TITLE_STR);
+       if (charValue)
+               organization->setTitle(charValue);
+       else
+       {
+               if(organization->getTitleIsSet())
+                       organization->unsetTitle();
+       }
+
+       charValue = contacts_svc_value_get_str(ctsValue, CTS_COMPANY_VAL_ROLE_STR);
+       if (charValue)
+               organization->setRole(charValue);
+       else
+       {
+               if(organization->getRoleIsSet())
+                       organization->unsetRole();
+       }
+
+//     charValue = contacts_svc_value_get_str(ctsValue, CTS_COMPANY_VAL_LOGOURI_STR);
+//     if (charValue)
+//             organization->setLogoURI(charValue);
+//     else
+//     {
+//             if(organization->getLogoURIIsSet())
+//                     organization->unsetLogoURI();
+//     }
+       if(organization->getLogoURIIsSet())
+               organization->unsetLogoURI();
+}
+
+//void ContactObjectP2AConverter::exportNoteValue()
+//{
+//     int errorCode = 0;
+//     CTSvalue *ctsValue = NULL;
+//
+//     errorCode = contacts_svc_struct_get_value(m_platformContact, CTS_CF_NOTE_VALUE, &ctsValue);
+//     if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+//             ThrowMsg(UnknownException, "getting note value : (err:" << errorCode << ")");
+//
+//     if(ctsValue == NULL || errorCode == CTS_ERR_NO_DATA)
+//     {
+//             //LogDebug("Platform contact don't have note value");
+//             if(m_abstractContact->getNoteIsSet())
+//                     m_abstractContact->unsetNote();
+//
+//             return;
+//     }
+//
+//     bool boolValue = false;
+//     const char *charValue = NULL;
+//
+//     boolValue = contacts_svc_value_get_bool(ctsValue, CTS_NOTE_VAL_DELETE_BOOL);
+//     charValue = contacts_svc_value_get_str(ctsValue, CTS_COMPANY_VAL_NAME_STR);
+//     if (charValue && boolValue != false)
+//             m_abstractContact->setNote(charValue);
+//     else
+//     {
+//             if(m_abstractContact->getNoteIsSet())
+//                     m_abstractContact->unsetNote();
+//     }
+//}
+
+void ContactObjectP2AConverter::exportNumberList()
+{
+       int errorCode = 0;
+       GSList *numberList = NULL;
+
+       if(m_abstractContact->getPhoneNumbersNum() > 0)
+               m_abstractContact->clearPhoneNumbers();
+
+       errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_NUMBER_LIST, &numberList);
+       if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+               ThrowMsg(UnknownException, "getting number list (err:" << errorCode << ")");
+
+       if(numberList == NULL || errorCode == CTS_ERR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have number list");
+               return;
+       }
+
+       ContactPhoneNumberArrayPtr phoneNumbers = m_abstractContact->getPhoneNumbers();
+
+       for (; numberList; numberList = g_slist_next(numberList))
+       {
+               ContactPhoneNumberPtr phoneNumber(new ContactPhoneNumber());
+
+               const char *charValue = NULL;
+               bool boolValue = false;
+               int intValue = 0;
+
+               boolValue = contacts_svc_value_get_bool(static_cast<CTSvalue*>(numberList->data), CTS_NUM_VAL_DELETE_BOOL);
+               if(boolValue)
+               {
+                       //LogDebug("Platform contact have a phone number to be deleted");
+                       continue;
+               }
+
+               charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(numberList->data), CTS_NUM_VAL_NUMBER_STR);
+               if (charValue)
+               {
+                       phoneNumber->setNumber(charValue);
+                       phoneNumbers->push_back(phoneNumber);
+               }
+               else
+               {
+                       //LogDebug("Platform contact have a empty phone number");
+                       continue;
+               }
+
+               boolValue = contacts_svc_value_get_bool(static_cast<CTSvalue*>(numberList->data), CTS_NUM_VAL_DEFAULT_BOOL);
+               if(boolValue)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_PREF);
+
+               intValue = contacts_svc_value_get_int(static_cast<CTSvalue*>(numberList->data), CTS_NUM_VAL_TYPE_INT);
+               if(intValue & CTS_NUM_TYPE_HOME)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_HOME);
+               if(intValue & CTS_NUM_TYPE_WORK)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_WORK);
+               if(intValue & CTS_NUM_TYPE_VOICE)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_VOICE);
+               if(intValue & CTS_NUM_TYPE_FAX)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_FAX);
+               if(intValue & CTS_NUM_TYPE_MSG)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_MSG);
+               if(intValue & CTS_NUM_TYPE_CELL)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_CELL);
+               if(intValue & CTS_NUM_TYPE_PAGER)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_PAGER);
+               if(intValue & CTS_NUM_TYPE_BBS)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_BBS);
+               if(intValue & CTS_NUM_TYPE_MODEM)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_MODEM);
+               if(intValue & CTS_NUM_TYPE_CAR)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_CAR);
+               if(intValue & CTS_NUM_TYPE_ISDN)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_ISDN);
+               if(intValue & CTS_NUM_TYPE_VIDEO)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_VIDEO);
+               if(intValue & CTS_NUM_TYPE_PCS)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_PCS);
+
+               // TODO Will be added after type changed to string
+//             if(intValue & CTS_NUM_TYPE_CUSTOM)
+//             {
+//                     charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(numberList->data), CTS_NUMBER_VAL_LABEL_STR);
+//                     if (charValue)
+//                             phoneNumber->addType(CUSTOM);
+//             }
+       }
+}
+
+void ContactObjectP2AConverter::exportEmailList()
+{
+       int errorCode = 0;
+       GSList *emailList = NULL;
+
+       if(m_abstractContact->getEmailsNum() > 0)
+               m_abstractContact->clearEmails();
+
+       errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_EMAIL_LIST, &emailList);
+       if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+               ThrowMsg(UnknownException, "getting email list (err:" << errorCode << ")");
+
+       if(emailList == NULL || errorCode == CTS_ERR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have email list");
+               return;
+       }
+
+       ContactEmailAddressArrayPtr emails = m_abstractContact->getEmails();
+
+       for (; emailList; emailList = g_slist_next(emailList))
+       {
+               ContactEmailAddressPtr email(new ContactEmailAddress());
+
+               const char *charValue = NULL;
+               bool boolValue = false;
+               int intValue = 0;
+
+               boolValue = contacts_svc_value_get_bool(static_cast<CTSvalue*>(emailList->data), CTS_EMAIL_VAL_DELETE_BOOL);
+               if(boolValue)
+               {
+                       //LogDebug("Platform contact have a email address to be deleted");
+                       continue;
+               }
+
+               charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(emailList->data), CTS_EMAIL_VAL_ADDR_STR);
+               if (charValue)
+               {
+                       email->setEmail(charValue);
+                       emails->push_back(email);
+               }
+               else
+               {
+                       //LogDebug("Platform contact have a empty email address");
+                       continue;
+               }
+
+               boolValue = contacts_svc_value_get_bool(static_cast<CTSvalue*>(emailList->data), CTS_EMAIL_VAL_DEFAULT_BOOL);
+               if(boolValue)
+                       email->addType(CONTACT_EMAIL_TYPE_PREF);
+
+               intValue = contacts_svc_value_get_int(static_cast<CTSvalue*>(emailList->data), CTS_EMAIL_VAL_TYPE_INT);
+               if(intValue & CTS_EMAIL_TYPE_HOME)
+                       email->addType(CONTACT_EMAIL_TYPE_HOME);
+               if(intValue & CTS_EMAIL_TYPE_WORK)
+                       email->addType(CONTACT_EMAIL_TYPE_WORK);
+
+               // TODO Will be added after type changed to string
+//             if(intValue & CTS_EMAIL_TYPE_CUSTOM)
+//             {
+//                     charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(emailList->data), CTS_EMAIL_VAL_LABEL_STR);
+//                     if (charValue)
+//                             email->addType(CUSTOM);
+//             }
+       }
+}
+
+void ContactObjectP2AConverter::exportGrouprelList()
+{
+       int errorCode = 0;
+       GSList *groupList = NULL;
+
+       if(m_abstractContact->getCategoriesNum() > 0)
+               m_abstractContact->clearCategories();
+
+       errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_GROUPREL_LIST, &groupList);
+       if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+               ThrowMsg(UnknownException, "getting group list (err:" << errorCode << ")");
+
+       if(groupList == NULL || errorCode == CTS_ERR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have group list");
+               return;
+       }
+
+       StringArrayPtr categories = m_abstractContact->getCategories();
+
+       for (; groupList; groupList = g_slist_next(groupList))
+       {
+               const char *charValue = NULL;
+               bool boolValue = false;
+
+               boolValue = contacts_svc_value_get_bool(static_cast<CTSvalue*>(groupList->data), CTS_GROUPREL_VAL_DELETE_BOOL);
+               if(boolValue)
+               {
+                       //LogDebug("Platform contact have a group to be deleted");
+                       continue;
+               }
+
+               charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(groupList->data), CTS_GROUPREL_VAL_NAME_STR);
+               if (charValue)
+                       categories->push_back(charValue);
+       }
+}
+
+void ContactObjectP2AConverter::exportEventList()
+{
+       int errorCode = 0;
+       GSList *eventList = NULL;
+
+       if(m_abstractContact->getAnniversariesNum() > 0)
+               m_abstractContact->clearAnniversaries();
+
+       if(m_abstractContact->getBirthdayIsSet())
+               m_abstractContact->unsetBirthday();
+
+       errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_EVENT_LIST, &eventList);
+       if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+               ThrowMsg(UnknownException, "getting event list (err:" << errorCode << ")");
+
+       if(eventList == NULL || errorCode == CTS_ERR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have group list");
+               return;
+       }
+
+       ContactAnniversaryArrayPtr anniversaries = m_abstractContact->getAnniversaries();
+
+       for (; eventList; eventList = g_slist_next(eventList))
+       {
+               const char *charValue = NULL;
+               bool boolValue = false;
+               int intValueType = 0;
+               int intValueDate = 0;
+
+               boolValue = contacts_svc_value_get_bool(static_cast<CTSvalue*>(eventList->data), CTS_GROUPREL_VAL_DELETE_BOOL);
+               if(boolValue)
+               {
+                       //LogDebug("Platform contact have a event to be deleted");
+                       continue;
+               }
+
+               intValueDate = contacts_svc_value_get_int(static_cast<CTSvalue*>(eventList->data), CTS_EVENT_VAL_DATE_INT);
+
+               struct tm tmDate = {0, };
+
+               tmDate.tm_year = (intValueDate / 10000) - 1900;
+               tmDate.tm_mon = ((intValueDate - ((tmDate.tm_year + 1900) * 10000)) / 100) - 1;
+               tmDate.tm_mday = (intValueDate - ((tmDate.tm_year + 1900) * 10000) - tmDate.tm_mon * 100);
+
+               intValueType = contacts_svc_value_get_int(static_cast<CTSvalue*>(eventList->data), CTS_EVENT_VAL_TYPE_INT);
+               if (intValueType == CTS_EVENT_TYPE_BIRTH)
+               {
+                       m_abstractContact->setBirthday(tmDate);
+               }
+               else if(intValueType == CTS_EVENT_TYPE_ANNIVERSARY)
+               {
+                       ContactAnniversaryPtr anniversary = ContactAnniversaryPtr(new ContactAnniversary());
+
+                       anniversary->setDate(tmDate);
+                       anniversary->setLabel("Anniversary");
+
+                       anniversaries->push_back(anniversary);
+               }
+//             else if(intValueType == CTS_EVENT_TYPE_CUSTOM)
+//             {
+//                     ContactAnniversaryPtr anniversary = ContactAnniversaryPtr(new ContactAnniversary());
+//
+//                     anniversary->setDate(tmDate);
+//
+//                     charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(eventList->data), CTS_EVENT_VAL_LABEL_STR);
+//                     if(charValue)
+//                             anniversary->setLabel(charValue);
+//
+//                     anniversaries->push_back(anniversary);
+//             }
+
+               // TODO Check the difference of CTS_EVENT_TYPE_CUSTOM and CTS_EVENT_TYPE_ANNIVERSARY
+       }
+}
+
+void ContactObjectP2AConverter::exportPostalList()
+{
+       int errorCode = 0;
+       GSList *addressList = NULL;
+
+       if(m_abstractContact->getAddressesNum() > 0)
+               m_abstractContact->clearAddresses();
+
+       errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_POSTAL_ADDR_LIST, &addressList);
+       if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+               ThrowMsg(UnknownException, "getting address list (err:" << errorCode << ")");
+
+       if(addressList == NULL || errorCode == CTS_ERR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have address list");
+               return;
+       }
+
+       ContactAddressArrayPtr addresss = m_abstractContact->getAddresses();
+
+       for (; addressList; addressList = g_slist_next(addressList))
+       {
+               ContactAddressPtr address(new ContactAddress());
+
+               const char *charValue = NULL;
+               bool boolValue = false;
+               int intValue = 0;
+
+               boolValue = contacts_svc_value_get_bool(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_DELETE_BOOL);
+               if(boolValue)
+               {
+                       //LogDebug("Platform contact have a address to be deleted");
+                       continue;
+               }
+
+               addresss->push_back(address);
+
+               charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_POSTALCODE_STR);
+               if (charValue)
+                       address->setPostalCode(charValue);
+
+               charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_REGION_STR);
+               if (charValue)
+                       address->setRegion(charValue);
+
+               charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_LOCALITY_STR);
+               if (charValue)
+                       address->setCity(charValue);
+
+               charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_STREET_STR);
+               if (charValue)
+                       address->setStreetAddress(charValue);
+
+               charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_EXTENDED_STR);
+               if (charValue)
+                       address->setAdditionalInformation(charValue);
+
+               charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_COUNTRY_STR);
+               if (charValue)
+                       address->setCountry(charValue);
+
+               boolValue = contacts_svc_value_get_bool(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_DEFAULT_BOOL);
+               if(boolValue)
+                       address->addType(CONTACT_ADDRESS_TYPE_PREF);
+
+               intValue = contacts_svc_value_get_int(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_TYPE_INT);
+               if(intValue & CTS_ADDR_TYPE_HOME)
+                       address->addType(CONTACT_ADDRESS_TYPE_HOME);
+               if(intValue & CTS_ADDR_TYPE_WORK)
+                       address->addType(CONTACT_ADDRESS_TYPE_WORK);
+
+               // TODO Will be added after type changed to string
+//             if(intValue & CTS_ADDR_TYPE_CUSTOM)
+//             {
+//                     charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_LABEL_STR);
+//                     if (charValue)
+//                             address->addType(CUSTOM);
+//             }
+       }
+}
+
+void ContactObjectP2AConverter::exportWebAddrList()
+{
+       int errorCode = 0;
+       GSList *webAddrList = NULL;
+
+       if(m_abstractContact->getUrlsNum() > 0)
+               m_abstractContact->clearUrls();
+
+       errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_WEB_ADDR_LIST, &webAddrList);
+       if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+               ThrowMsg(UnknownException, "getting address list (err:" << errorCode << ")");
+
+       if(webAddrList == NULL || errorCode == CTS_ERR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have address list");
+               return;
+       }
+
+       ContactWebSiteArrayPtr urls = m_abstractContact->getUrls();
+
+       for (; webAddrList; webAddrList = g_slist_next(webAddrList))
+       {
+               ContactWebSitePtr url(new ContactWebSite());
+
+               const char *charValue = NULL;
+               bool boolValue = false;
+               int intValue = 0;
+
+               boolValue = contacts_svc_value_get_bool(static_cast<CTSvalue*>(webAddrList->data), CTS_WEB_VAL_DELETE_BOOL);
+               if(boolValue)
+               {
+                       //LogDebug("Platform contact have a address to be deleted");
+                       continue;
+               }
+
+               urls->push_back(url);
+
+               charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(webAddrList->data), CTS_WEB_VAL_ADDR_STR);
+               if (charValue)
+                       url->setUrl(charValue);
+
+               intValue = contacts_svc_value_get_int(static_cast<CTSvalue*>(webAddrList->data), CTS_WEB_VAL_TYPE_INT);
+               if(intValue == CTS_WEB_TYPE_HOME)
+                       url->setType(WEBSITE_TYPE_HOMEPAGE);
+               if(intValue & CTS_WEB_TYPE_WORK)
+                       url->setType(WEBSITE_TYPE_BLOG);
+
+               // TODO Will be added after type changed to string
+//             if(intValue & CTS_WEB_TYPE_CUSTOM)
+//             {
+//                     charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(webAddrList->data), CTS_WEB_VAL_LABEL_STR);
+//                     if (charValue)
+//                             url->setType(CUSTOM);
+//             }
+       }
+}
+
+void ContactObjectP2AConverter::exportNicknameList()
+{
+       int errorCode = 0;
+       GSList *nicknameList = NULL;
+
+       ContactNamePtr contactName = m_abstractContact->getName();
+       if(contactName == NULL)
+       {
+               contactName = ContactNamePtr(new ContactName());
+               m_abstractContact->setName(contactName);
+       }
+
+       if(contactName->getNicknamesNum() > 0)
+               contactName->clearNicknames();
+
+       errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_NICKNAME_LIST, &nicknameList);
+       if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
+               ThrowMsg(UnknownException, "getting nickname list (err:" << errorCode << ")");
+
+       if(nicknameList == NULL || errorCode == CTS_ERR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have nickname list");
+               return;
+       }
+
+       StringArrayPtr nicknames = contactName->getNicknames();
+
+       for (; nicknameList; nicknameList = g_slist_next(nicknameList))
+       {
+               const char *charValue = NULL;
+               bool boolValue = false;
+
+               boolValue = contacts_svc_value_get_bool(static_cast<CTSvalue*>(nicknameList->data), CTS_NICKNAME_VAL_DELETE_BOOL);
+               if(boolValue)
+               {
+                       //LogDebug("Platform contact have a nickname to be deleted");
+                       continue;
+               }
+
+               charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(nicknameList->data), CTS_NICKNAME_VAL_NAME_STR);
+               if (charValue)
+                       nicknames->push_back(charValue);
+       }
+}
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/ContactObjectP2AConverter.h b/src/platform/Tizen/Contact/ContactObjectP2AConverter.h
new file mode 100644 (file)
index 0000000..595c754
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        ContactObjectP2AConverter.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Converter (CTSstruct* -> TizenApis::Api::Contact::ContactPtr)
+ */
+
+#ifndef _PLATFORM_CONTACT_CONTACT_OBJECT_P2A_CONVERTER_H_
+#define _PLATFORM_CONTACT_CONTACT_OBJECT_P2A_CONVERTER_H_
+
+#include <string>
+#include <contacts-svc.h>
+#include <dpl/shared_ptr.h>
+#include <API/Contact/IContact.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class ContactObjectP2AConverter
+{
+public:
+       ContactObjectP2AConverter(CTSstruct* platformContact,
+                                 bool forScratch);
+       ContactObjectP2AConverter(CTSstruct* platformContact,
+                                 bool forScratch,
+                                 TizenApis::Api::Contact::ContactPtr &abstractContact);
+       virtual ~ContactObjectP2AConverter();
+
+       TizenApis::Api::Contact::ContactPtr getAbstractContact();
+
+protected:
+       void convertToAbstractObject();
+
+       void exportBaseInfoValue();
+       void exportNameValue();
+       void exportCompanyValue();
+//     void exportNoteValue();
+       void exportNumberList();
+       void exportEmailList();
+       void exportGrouprelList();
+       void exportEventList();
+       void exportPostalList();
+       void exportWebAddrList();
+       void exportNicknameList();
+
+       CTSstruct*                          m_platformContact;
+       TizenApis::Api::Contact::ContactPtr m_abstractContact;
+       bool                                m_forScratch;
+       bool                                m_convertFinished;
+};
+typedef DPL::SharedPtr<ContactObjectP2AConverter> ContactObjectP2AConverterPtr;
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_CONTACT_CONTACT_OBJECT_P2A_CONVERTER_H_
index 97afab9..eb3ed46 100755 (executable)
  * @brief
  */
 
+#include "ContactSearchEngine.h"
+
 #include "query-svc/query-service.h"
 #include "time.h"
 
 #include <algorithm>
-#include <sstream>
 #include <iomanip>
 #include <Commons/Exception.h>
 #include "Contact.h"
-#include "ContactSearchEngine.h"
+#include "ContactUtility.h"
 
 namespace TizenApis {
 namespace Platform {
@@ -204,16 +205,19 @@ ContactArrayPtr ContactSearchEngine::getContactSearchResult()
                                if( str )
                                {
                                        contact->setId(str);
-                                       contact->setAddressBookId(0);
                                }
 
                                str = query_get_attribute(m_contact_query_service, ACCOUNT_ID, &err);
                                if( str )
-                                       contact->setAccountId(str);
+                               {
+                                       int accountId = ContactUtility::strToInt(str);
+                                       int addressBookId = find_addressbook_id(accountId, &err);
+                                       contact->setAddressBookId(addressBookId);
+                               }
 
                                str = query_get_attribute(m_contact_query_service, CONTACT_IS_FAVORITE, &err);
                                if( str )
-                                       contact->setIsFavorite(toBool(str));
+                                       contact->setIsFavorite(ContactUtility::strToBool(str));
 
                                str = query_get_attribute(m_contact_query_service, CONTACT_RINGTONE, &err);
                                if( str )
@@ -232,8 +236,7 @@ ContactArrayPtr ContactSearchEngine::getContactSearchResult()
                                {
                                        struct tm time_stamp;
 
-                                       time_t db_time_stamp;
-                                       stringstream(str) >> db_time_stamp;
+                                       time_t db_time_stamp = ContactUtility::strToInt(str);
 
                                        struct tm* tmp_time = gmtime(&db_time_stamp);
                                        memcpy(&time_stamp, tmp_time, sizeof(struct tm));
@@ -343,22 +346,25 @@ ContactArrayPtr ContactSearchEngine::getContactSearchResult()
                        }
                        else if (!nicknameAlreadyChecked && (pattr == NICKNAME_NAME))
                        {
-                               ContactNamePtr contactName(NULL);
+                               ContactNamePtr contactName = contact->getName();
+                               bool nicknameExists = false;
 
-                               if(!contact->getNameIsSet())
+                               if(contactName == NULL)
                                        contactName = ContactNamePtr(new ContactName());
-                               else
-                                       contactName = contact->getName();
 
                                do
                                {
                                        char *nickname = query_get_attribute(m_contact_query_service, NICKNAME_NAME, &err);
                                        if(nickname)
+                                       {
                                                contactName->addNickname(string(nickname));
+                                               if(nicknameExists == false)
+                                                       nicknameExists = true;
+                                       }
 
                                } while ( fetch_next_row(m_contact_query_service) == QUERY_SUCCESS );
 
-                               if(!contact->getNameIsSet())
+                               if(nicknameExists && contact->getName() == NULL)
                                        contact->setName(contactName);
 
                                nicknameAlreadyChecked = true;
@@ -499,7 +505,7 @@ void ContactSearchEngine::visitAttribute(string& attrName, MatchFlag& matchFlag,
                        query_set_condition_append(m_contact_query_service, LEFT_BRACKET);
 
                        cond = EQUAL;
-                       valueStr = toDateDbStr(matchValue->getDateTm());
+                       valueStr = ContactUtility::toDateDbStr(matchValue->getDateTm());
                        query_set_condition(m_contact_query_service, attr, cond, valueStr.c_str());
 
                        query_set_condition_append(m_contact_query_service, AND);
@@ -568,7 +574,7 @@ void ContactSearchEngine::visitAttributeRange(string& attrName, AnyPtr& initialV
                if(initialValue->isType(PrimitiveType_Time))
                {
                        valueIsDate = true;
-                       initialValueStr = toDateDbStr(initialValue->getDateTm());
+                       initialValueStr = ContactUtility::toDateDbStr(initialValue->getDateTm());
                }
                else
                        initialValueStr = initialValue->toString();
@@ -579,7 +585,7 @@ void ContactSearchEngine::visitAttributeRange(string& attrName, AnyPtr& initialV
                if(endValue->isType(PrimitiveType_Time))
                {
                        valueIsDate = true;
-                       endValueStr = toDateDbStr(endValue->getDateTm());
+                       endValueStr = ContactUtility::toDateDbStr(endValue->getDateTm());
                }
                else
                        endValueStr = endValue->toString();
@@ -652,7 +658,7 @@ void ContactSearchEngine::setPlatformAttrValue(Contact& contact, contact_attribu
                contact.setId(string(val));
                break;
        case CONTACT_IS_FAVORITE:
-               contact.setIsFavorite(toBool(val));
+               contact.setIsFavorite(ContactUtility::strToBool(val));
                break;
        case CONTACT_RINGTONE:
                contact.setRingtoneURI(string(val));
@@ -751,7 +757,7 @@ void ContactSearchEngine::setName(ContactPtr& contact,
 
        ContactNamePtr contactName(NULL);
 
-       if(!contact->getNameIsSet())
+       if(contact->getName() == NULL)
                contactName = ContactNamePtr(new ContactName);
        else
                contactName = contact->getName();
@@ -777,7 +783,7 @@ void ContactSearchEngine::setName(ContactPtr& contact,
        if( displayName )
                contactName->setDisplayName(displayName);
 
-       if(!contact->getNameIsSet())
+       if(contact->getName() == NULL)
                contact->setName(contactName);
 }
 
@@ -921,7 +927,7 @@ void ContactSearchEngine::setEvent(ContactPtr& contact, char *date, char *type)
        if(date == NULL)
                return;
 
-       tm tm_date = toDateTmFromDateDbStr(date);
+       tm tm_date = ContactUtility::toDateTmFromDateDbStr(date);
 
        if(type != NULL)
        {
@@ -985,67 +991,6 @@ void ContactSearchEngine::tokenize(const string& str, vector<string>& tokens, co
        }
 }
 
-bool ContactSearchEngine::toBool(char* val)
-{
-       string boolStr(val);
-
-       if (boolStr == "true" || boolStr == "TRUE")
-               return true;
-
-       return false;
-}
-
-tm ContactSearchEngine::toDateTm(char* arg)
-{
-       // this code originated from Converter
-       struct tm result;
-       char* currentLocale = setlocale(LC_TIME, NULL);
-       if (currentLocale == NULL) {
-               ThrowMsg(ConversionException, "Couldn't get current locale.");
-       }
-       DPL::ScopedFree<char> currentLocaleCopy(strdup(currentLocale));
-       if (setlocale(LC_TIME, "C") == NULL) {
-               ThrowMsg(ConversionException, "Couldn't set POSIX locale.");
-       }
-       if (strptime(arg, "%a %b %d %Y %T", &result) == NULL) {
-               ThrowMsg(ConversionException, "Couldn't convert supplied date.");
-       }
-       if (setlocale(LC_TIME, currentLocaleCopy.Get()) == NULL) {
-               ThrowMsg(ConversionException, "Couldn't set previous locale back.");
-       }
-       return result;
-}
-
-string ContactSearchEngine::toDateDbStr(const tm &date) const
-{
-       stringstream ss;
-       ss << setfill('0') << setiosflags(ios::right) << setw(4) << (date.tm_year + 1900);
-       ss << setfill('0') << setiosflags(ios::right) << setw(2) << (date.tm_mon + 1);
-       ss << setfill('0') << setiosflags(ios::right) << setw(2) << date.tm_mday;
-
-       return ss.str();
-}
-
-tm ContactSearchEngine::toDateTmFromDateDbStr(const char* arg) const
-{
-       tm date;
-       memset(&date, 0, sizeof(tm));
-
-       if(arg == NULL) {
-               ThrowMsg(InvalidArgumentException, "Invalid Date type");
-       }
-
-       int dateDb;
-       stringstream ss(arg);
-       ss >> dateDb;
-
-       date.tm_year = (dateDb / 10000) - 1900;
-       date.tm_mon = ((dateDb - ((date.tm_year + 1900) * 10000)) / 100) - 1;
-       date.tm_mday = (dateDb - ((date.tm_year + 1900) * 10000) - ((date.tm_mon+1) * 100));
-
-       return date;
-}
-
 bool ContactSearchEngine::isStringTypeAttr(std::string& type) const
 {
        vector<string>::iterator result = find(attrStringTypes.begin(), attrStringTypes.end(), type);
index 1a58bde..94b243e 100755 (executable)
@@ -100,9 +100,6 @@ private:
        // utility functions
        void tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = " ");
        bool toBool(char* val);
-       std::tm toDateTm(char* arg);
-       std::string toDateDbStr(const std::tm &date) const;
-       std::tm toDateTmFromDateDbStr(const char* arg) const;
 
        bool isStringTypeAttr(std::string& type) const;
 };
diff --git a/src/platform/Tizen/Contact/ContactUtility.cpp b/src/platform/Tizen/Contact/ContactUtility.cpp
new file mode 100644 (file)
index 0000000..7c76f55
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        ContactUtility.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       
+ */
+
+#include "ContactUtility.h"
+
+#include <time.h>
+#include <string>
+#include <sstream>
+#include <iomanip>
+#include <Commons/Exception.h>
+#include <Commons/Regex.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace std;
+using namespace WrtDeviceApis::Commons;
+
+ContactUtility::ContactUtility()
+{
+}
+
+ContactUtility::~ContactUtility()
+{
+}
+
+bool ContactUtility::strToBool(const char *str)
+{
+       if(str == NULL)
+               return false;
+
+       string boolStr(str);
+
+       if (boolStr == "true" || boolStr == "TRUE")
+               return true;
+
+       return false;
+}
+
+int ContactUtility::strToInt(const char* str)
+{
+       if(str == NULL)
+               return 0;
+
+       int result = 0;
+
+       istringstream iss(str);
+       iss >> result;
+
+       return result;
+}
+
+int ContactUtility::strToInt(const string &str)
+{
+       int result = 0;
+
+       istringstream iss(str);
+       iss >> result;
+
+       return result;
+}
+
+string ContactUtility::intToStr(const int value)
+{
+       stringstream oss;
+       oss << value;
+       return oss.str();
+}
+
+string ContactUtility::toDateDbStr(const tm &date)
+{
+       stringstream ss;
+       ss << setfill('0') << setiosflags(ios::right) << setw(4) << (date.tm_year + 1900);
+       ss << setfill('0') << setiosflags(ios::right) << setw(2) << (date.tm_mon + 1);
+       ss << setfill('0') << setiosflags(ios::right) << setw(2) << date.tm_mday;
+
+       return ss.str();
+}
+
+tm ContactUtility::toDateTmFromDateDbStr(const char* arg)
+{
+       tm date;
+       memset(&date, 0, sizeof(tm));
+
+       if(arg == NULL) {
+               ThrowMsg(InvalidArgumentException, "Invalid Date type");
+       }
+
+       int dateDb;
+       stringstream ss(arg);
+       ss >> dateDb;
+
+       date.tm_year = (dateDb / 10000) - 1900;
+       date.tm_mon = ((dateDb - ((date.tm_year + 1900) * 10000)) / 100) - 1;
+       date.tm_mday = (dateDb - ((date.tm_year + 1900) * 10000) - ((date.tm_mon+1) * 100));
+
+       return date;
+}
+
+string ContactUtility::convertUriToPath(const string str)
+{
+       string result;
+
+       if(validate("^file\\:///[a-zA-Z]{2,3}(/\\S*)?$", str, VALIDATE_MATCH_CASELESS))
+               result = str.substr(string("file://").size());
+       else if(validate("^/[a-zA-Z]{2,3}(/\\S*)?$", str, VALIDATE_MATCH_CASELESS))
+               result = str;
+
+       return result;
+}
+
+string ContactUtility::convertPathToUri(const string str)
+{
+       string result;
+
+       if(validate("^/[a-zA-Z]{2,3}(/\\S*)?$", str, VALIDATE_MATCH_CASELESS))
+               result = "file://" + str;
+       else if(validate("^file\\:///[a-zA-Z]{2,3}(/\\S*)?$", str, VALIDATE_MATCH_CASELESS))
+               result = str;
+
+       return result;
+}
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/ContactUtility.h b/src/platform/Tizen/Contact/ContactUtility.h
new file mode 100644 (file)
index 0000000..417b38b
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        ContactUtility.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       
+ */
+
+#ifndef TIZENAPIS_PLATFORM_CONTACT_CONTACT_UTILITY_H_
+#define TIZENAPIS_PLATFORM_CONTACT_CONTACT_UTILITY_H_
+
+#include <string>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class ContactUtility
+{
+public:
+       ContactUtility();
+       virtual ~ContactUtility();
+
+       static bool strToBool(const char* str);
+
+       static int strToInt(const char* str);
+       static int strToInt(const std::string &str);
+       static std::string intToStr(const int value);
+
+       static std::string toDateDbStr(const tm &date);
+       static tm toDateTmFromDateDbStr(const char* arg);
+
+       static std::string convertUriToPath(const std::string str);
+       static std::string convertPathToUri(const std::string str);
+};
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // TIZENAPIS_PLATFORM_CONTACT_CONTACT_UTILITY_H_
diff --git a/src/platform/Tizen/Contact/ContactWrapper.cpp b/src/platform/Tizen/Contact/ContactWrapper.cpp
deleted file mode 100755 (executable)
index b003418..0000000
+++ /dev/null
@@ -1,2138 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * @file        ContactWrapper.cpp
- * @author      Lukasz Marek(l.marek@samsung.com)
- * @author      Yujie Zeng(yj.zengk@samsung.com)
- * @version     0.1
- * @brief
- */
-
-#include <vector>
-#include <pcrecpp.h>
-#include <dpl/log/log.h>
-#include <Commons/Exception.h>
-#include <Commons/Regex.h>
-#include "ContactWrapper.h"
-#include "AddressBook.h"
-#include "Contact.h"
-#include "query-svc/query-service.h"
-
-#define CONTACT_ATTRIBUTE_PHONETIC_FIRST_NAME "phoneticFirstName"
-#define CONTACT_ATTRIBUTE_PHONETIC_LAST_NAME "phoneticLastName"
-
-namespace TizenApis
-{
-namespace Platform
-{
-namespace Contact
-{
-
-using namespace TizenApis::Api::Contact;
-using namespace WrtDeviceApis::Commons;
-using namespace std;
-
-ContactWrapper::ContactWrapper(IAddressBook::AddressBookType type) :
-               m_abstractContact(NULL),
-               m_platformContact(NULL),
-               m_platformContactOwnership(false)
-{
-       //platform layer seems to not support different storage types yet
-}
-
-ContactWrapper::~ContactWrapper()
-{
-       freePlatformObject();
-}
-
-void ContactWrapper::freePlatformObject()
-{
-       if (m_platformContact && m_platformContactOwnership)
-       {
-               contacts_svc_struct_free(m_platformContact);
-               m_platformContact = NULL;
-               m_platformContactOwnership = false;
-       }
-}
-
-void ContactWrapper::freeAbstractObject()
-{
-       m_abstractContact = ContactPtr(NULL);
-}
-
-ContactPtr ContactWrapper::getAbstractContact() const
-{
-       return m_abstractContact;
-}
-
-void ContactWrapper::setAbstractContact(const ContactPtr &contact, bool isConvertingVCard)
-{
-       m_abstractContact = contact;
-       convertToPlatformObject(isConvertingVCard);
-}
-
-CTSstruct* ContactWrapper::getPlatformContact() const
-{
-       return m_platformContact;
-}
-
-void ContactWrapper::setPlatformContact(CTSstruct* contact, bool isConvertingVCard)
-{
-       freePlatformObject();
-       freeAbstractObject();
-
-       m_platformContact = contact;
-       m_platformContactOwnership = false;
-       convertToAbstractObject(isConvertingVCard);
-}
-
-bool ContactWrapper::convertAbstractToPlatform(const ContactPtr &abstract, CTSstruct* platform, bool isConvertingVCard)
-{
-       freePlatformObject();
-       freeAbstractObject();
-
-       m_abstractContact = abstract;
-       m_platformContact = platform;
-       m_platformContactOwnership = false;
-
-       return convertToPlatformObject(isConvertingVCard);
-}
-
-bool ContactWrapper::convertPlatformToAbstract(CTSstruct* platform, ContactPtr &abstract, bool isConvertingVCard)
-{
-       freeAbstractObject();
-       freePlatformObject();
-
-       m_platformContact = platform;
-       m_platformContactOwnership = false;
-       m_abstractContact = abstract;
-
-       return convertToAbstractObject(isConvertingVCard);
-}
-
-bool ContactWrapper::convertToPlatformObject(bool isConvertingVCard)
-{
-       LogDebug("entered");
-
-       freePlatformObject();
-
-       if (!m_abstractContact)
-       {
-               LogError("abstract object is not set");
-               return false;
-       }
-
-       //if abstrat object has id set then we have to read existing object and update it
-       if (m_abstractContact->getIdIsSet() && (isConvertingVCard == false))
-       {
-               LogDebug("reading existing contact");
-               int id;
-               stringstream(m_abstractContact->getId()) >> id;
-               contacts_svc_get_contact(id, &m_platformContact);
-       }
-       else // if no id is set then create new platform object
-       {
-               LogDebug("creating new contact");
-               m_platformContact = contacts_svc_struct_new(CTS_STRUCT_CONTACT);
-               m_platformContactOwnership = true;
-       }
-
-       if (!m_platformContact)
-       {
-               LogError("contact structure not created properly");
-               return false;
-       }
-
-       Try
-       {
-               if (!convertToPlatformBaseData())
-                       ThrowMsg(UnknownException, "error during converting base data");
-
-               if (!convertToPlatformAddressObject())
-                       ThrowMsg(UnknownException, "error during converting address object");
-
-               if (!convertToPlatformEmailObject())
-                       ThrowMsg(UnknownException, "error during converting email object");
-
-               if (!convertToPlatformPhoneObject())
-                       ThrowMsg(UnknownException, "error during converting phone object");
-
-               if (!convertToPlatformNicknameObject())
-                       ThrowMsg(UnknownException, "error during converting nickname object");
-
-               if (!convertToPlatformPhoneticnameObject())
-                       ThrowMsg(UnknownException, "error during converting Phoneticname object");
-
-               if (!convertToPlatformGroupObject())
-                       ThrowMsg(UnknownException, "error during converting group object");
-
-               if (!convertToPlatformUrlObject())
-                       ThrowMsg(UnknownException, "error during converting url object");
-
-               if (!convertToPlatformOrganizationObject())
-                       ThrowMsg(UnknownException, "error during converting organization object");
-
-               if (!convertToPlatformAnniversaryObject())
-                       ThrowMsg(UnknownException, "error during converting anniversary object");
-
-               if (!convertToPlatformbirthdayObject())
-                       ThrowMsg(UnknownException, "error during converting birthday object");
-       }
-       Catch (Exception)
-       {
-               LogError("Error converting to platform object : " << _rethrown_exception.GetMessage());
-
-               freePlatformObject();
-
-               return false;
-       }
-
-       return true;
-}
-
-bool ContactWrapper::convertToAbstractObject(bool isConvertingVCard)
-{
-       LogDebug("entered");
-
-       if (!m_platformContact)
-               return false;
-
-       CTSvalue *value = NULL;
-       //store id
-       if (CTS_SUCCESS != contacts_svc_struct_get_value(m_platformContact, CTS_CF_BASE_INFO_VALUE, &value))
-               return false;
-
-       if(m_abstractContact == NULL)
-               m_abstractContact = ContactPtr(new Contact());
-
-       if(!isConvertingVCard)
-       {
-               m_abstractContact->setId(contacts_svc_value_get_int(value, CTS_BASE_VAL_ID_INT));
-               //m_abstractContact->setAddressBookId(contacts_svc_value_get_int(value, CTS_BASE_VAL_ADDRESSBOOK_ID_INT));
-               m_abstractContact->setAddressBookId(0);
-       }
-
-       const char *charValue;
-
-       charValue = contacts_svc_value_get_str(value, CTS_BASE_VAL_IMG_PATH_STR);
-       if (charValue)
-               m_abstractContact->setPhotoURI(convertPathToUri(charValue));
-
-       charValue = contacts_svc_value_get_str(value, CTS_BASE_VAL_RINGTONE_PATH_STR);
-       if (charValue)
-               m_abstractContact->setRingtoneURI(convertPathToUri(charValue));
-
-       charValue = contacts_svc_value_get_str(value, CTS_BASE_VAL_NOTE_STR);
-       if (charValue)
-               m_abstractContact->setNote(charValue);
-
-       Try
-       {
-               if (!convertToAbstractBaseData())
-                       ThrowMsg(UnknownException, "error during converting base data");
-
-               if (!convertToAbstractAddressObject())
-                       ThrowMsg(UnknownException, "error during converting address object");
-
-               if (!convertToAbstractEmailObject())
-                       ThrowMsg(UnknownException, "error during converting email object");
-
-               if (!convertToAbstractPhoneObject())
-                       ThrowMsg(UnknownException, "error during converting phone object");
-
-               if (!convertToAbstractNicknameObject())
-                       ThrowMsg(UnknownException, "error during converting nickname object");
-
-               if (!convertToAbstractPhoneticnameObject())
-                       ThrowMsg(UnknownException, "error during converting phoneticName object");
-
-               if (!convertToAbstractGroupObject())
-                       ThrowMsg(UnknownException, "error during converting group object");
-
-               if (!convertToAbstractUrlObject())
-                       ThrowMsg(UnknownException, "error during converting url object");
-
-               if (!convertToAbstractOrganizationObject())
-                       ThrowMsg(UnknownException, "error during converting organization object");
-
-               if (!convertToAbstractAnniversaryObject())
-                       ThrowMsg(UnknownException, "error during converting anniversary object");
-
-               if (!convertToAbstractBirthdayObject())
-                       ThrowMsg(UnknownException, "error during converting birthday object");
-       }
-       Catch (Exception)
-       {
-               LogError("Error converting to abstract object : " << _rethrown_exception.GetMessage());
-               freeAbstractObject();
-
-               return false;
-       }
-
-       return true;
-}
-
-bool ContactWrapper::convertToAbstractBaseData()
-{
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       CTSvalue *value = NULL;
-
-       int errorCode;
-       errorCode = contacts_svc_struct_get_value(m_platformContact, CTS_CF_NAME_VALUE, &value);
-       if (CTS_SUCCESS == errorCode && value != NULL)
-       {
-               const char *charValue = NULL;
-               ContactNamePtr contactName(new ContactName);
-
-               charValue = contacts_svc_value_get_str(value, CTS_NAME_VAL_FIRST_STR);
-               if (charValue)
-                       contactName->setFirstName(charValue);
-
-               charValue = contacts_svc_value_get_str(value, CTS_NAME_VAL_ADDITION_STR);
-               if (charValue)
-                       contactName->setMiddleName(charValue);
-
-               charValue = contacts_svc_value_get_str(value, CTS_NAME_VAL_LAST_STR);
-               if (charValue)
-                       contactName->setLastName(charValue);
-
-               charValue = contacts_svc_value_get_str(value, CTS_NAME_VAL_DISPLAY_STR);
-               if (charValue)
-                       contactName->setDisplayName(charValue);
-
-               charValue = contacts_svc_value_get_str(value, CTS_NAME_VAL_PREFIX_STR);
-               if (charValue)
-                       contactName->setPrefix(charValue);
-
-               //charValue = contacts_svc_value_get_str(value, CTS_NAME_VAL_SUFFIX_STR);
-               //if (charValue)
-               //      contactName->setPhoneticName(charValue);
-
-               m_abstractContact->setName(contactName);
-       }
-       else if (errorCode != CTS_ERR_NO_DATA || value == NULL)
-       {
-               return false;
-       }
-
-//     errorCode = contacts_svc_struct_get_value(m_platformContact, CTS_CF_BASE_INFO_VALUE, &value);
-//     if (CTS_SUCCESS == errorCode && value != NULL)
-//     {
-//             const char *charValue = NULL;
-//
-//             charValue = contacts_svc_value_get_str(value, CTS_BASE_VAL_IMG_PATH_STR);
-//             if (charValue)
-//                     m_abstractContact->setPhotoURI(convertPathToUri(charValue));
-//
-//             charValue = contacts_svc_value_get_str(value, CTS_BASE_VAL_RINGTONE_PATH_STR);
-//             if (charValue)
-//                     m_abstractContact->setRingtoneURI(convertPathToUri(charValue));
-//
-//             bool boolValue = contacts_svc_value_get_bool(value, CTS_BASE_VAL_FAVORITE_BOOL);
-//             if (boolValue)
-//                     m_abstractContact->setIsFavorite(boolValue);
-//
-//             charValue = contacts_svc_value_get_str(value, CTS_BASE_VAL_NOTE_STR);
-//             if (charValue)
-//                     m_abstractContact->addNote(charValue);
-//     }
-//     else if (errorCode != CTS_ERR_NO_DATA || value == NULL)
-//     {
-//             return false;
-//     }
-
-       return true;
-}
-
-bool ContactWrapper::convertToAbstractAddressObject()
-{
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       ContactAddressArrayPtr addresses = ContactAddressArrayPtr(new ContactAddressArray());
-
-       GSList *addressList = NULL;
-       int errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_POSTAL_ADDR_LIST, &addressList);
-       if (CTS_SUCCESS == errorCode)
-       {
-               for (; addressList; addressList = g_slist_next(addressList))
-               {
-                       ContactAddressPtr address(new ContactAddress());
-                       addresses->push_back(address);
-
-                       int type = contacts_svc_value_get_int(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_TYPE_INT);
-                       if(type & CTS_ADDR_TYPE_POSTAL) // TODO to be checked
-                               address->addType(CONTACT_ADDRESS_TYPE_PREF);
-                       if(type & CTS_ADDR_TYPE_HOME)
-                               address->addType(CONTACT_ADDRESS_TYPE_HOME);
-                       if(type & CTS_ADDR_TYPE_WORK)
-                               address->addType(CONTACT_ADDRESS_TYPE_WORK);
-
-                       const char *charValue = NULL;
-
-                       charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_COUNTRY_STR);
-                       if (charValue)
-                               address->setCountry(charValue);
-
-                       charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_REGION_STR);
-                       if (charValue)
-                               address->setRegion(charValue);
-
-                       charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_LOCALITY_STR);
-                       if (charValue)
-                               address->setCity(charValue);
-
-                       charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_STREET_STR);
-                       if (charValue)
-                               address->setStreetAddress(charValue);
-
-                       charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_POSTALCODE_STR);
-                       if (charValue)
-                               address->setPostalCode(charValue);
-
-                       charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(addressList->data), CTS_POSTAL_VAL_EXTENDED_STR);
-                       if (charValue)
-                               address->setAdditionalInformation(charValue);
-
-               }
-       }
-       else if (errorCode != CTS_ERR_NO_DATA)
-       {
-               return false;
-       }
-
-       m_abstractContact->setAddresses(addresses);
-
-       return true;
-}
-
-bool ContactWrapper::convertToAbstractUrlObject()
-{
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       ContactWebSiteArrayPtr urls = ContactWebSiteArrayPtr(new ContactWebSiteArray());
-
-       GSList *urlList = NULL;
-       int errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_WEB_ADDR_LIST, &urlList);
-       if (CTS_SUCCESS == errorCode)
-       {
-               for (; urlList; urlList = g_slist_next(urlList))
-               {
-                       ContactWebSitePtr url(new ContactWebSite());
-                       urls->push_back(url);
-
-                       int type = contacts_svc_value_get_int(static_cast<CTSvalue*>(urlList->data), CTS_WEB_VAL_TYPE_INT);
-                       switch (type)
-                       {
-                       case CTS_WEB_TYPE_NONE:
-                               url->setType(WEBSITE_TYPE_HOMEPAGE);
-                               break;
-                       case CTS_WEB_TYPE_HOME:
-                               url->setType(WEBSITE_TYPE_HOMEPAGE);
-                               break;
-                       case CTS_WEB_TYPE_WORK:
-                               url->setType(WEBSITE_TYPE_BLOG);
-                               break;
-                       default:
-                               LogError("invalid url type");
-                               url->setType(WEBSITE_TYPE_HOMEPAGE);
-                               break;
-                       }
-
-                       const char *charValue = NULL;
-
-                       charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(urlList->data), CTS_WEB_VAL_ADDR_STR);
-                       if (charValue)
-                               url->setUrl(charValue);
-
-               }
-       }
-       else if (errorCode != CTS_ERR_NO_DATA)
-       {
-               return false;
-       }
-
-       m_abstractContact->setUrls(urls);
-
-       return true;
-}
-
-bool ContactWrapper::convertToAbstractOrganizationObject()
-{
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       CTSvalue *value = NULL;
-       int errorCode;
-
-       ContactOrganizationPtr organization(new ContactOrganization());
-
-       errorCode = contacts_svc_struct_get_value(m_platformContact, CTS_CF_COMPANY_VALUE, &value);
-       if (CTS_SUCCESS == errorCode)
-       {
-               const char *charValue = NULL;
-
-               charValue = contacts_svc_value_get_str(value, CTS_COMPANY_VAL_NAME_STR);
-               if (charValue)
-                       organization->setName(charValue);
-
-               charValue = contacts_svc_value_get_str(value, CTS_COMPANY_VAL_DEPARTMENT_STR);
-               if (charValue)
-                       organization->setDepartment(charValue);
-
-               charValue = contacts_svc_value_get_str(value, CTS_COMPANY_VAL_JOB_TITLE_STR);
-               if (charValue)
-                       organization->setTitle(charValue);
-
-               charValue = contacts_svc_value_get_str(value, CTS_COMPANY_VAL_ROLE_STR);
-               if (charValue)
-                       organization->setRole(charValue);
-
-       }
-       else if (errorCode != CTS_ERR_NO_DATA)
-       {
-               return false;
-       }
-
-       m_abstractContact->setOrganization(organization);
-
-       return true;
-}
-
-bool ContactWrapper::convertToAbstractAnniversaryObject()
-{
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       ContactAnniversaryArrayPtr anniversaries(new ContactAnniversaryArray());
-
-       GSList *eventList = NULL;
-       int errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_EVENT_LIST, &eventList);
-       if (CTS_SUCCESS == errorCode)
-       {
-               for (; eventList; eventList = g_slist_next(eventList))
-               {
-                       int type = contacts_svc_value_get_int(static_cast<CTSvalue*>(eventList->data), CTS_EVENT_VAL_TYPE_INT);
-                       int db_date = contacts_svc_value_get_int(static_cast<CTSvalue*>(eventList->data), CTS_EVENT_VAL_DATE_INT);
-
-                       if (type == CTS_EVENT_TYPE_ANNIVERSARY)
-                       {
-                               ContactAnniversaryPtr anniversary = ContactAnniversaryPtr(new ContactAnniversary());
-
-                               tm tm_date;
-
-                               tm_date.tm_year = (db_date / 10000) - 1900;
-                               tm_date.tm_mon = ((db_date - ((tm_date.tm_year + 1900) * 10000)) / 100) - 1;
-                               tm_date.tm_mday = (db_date - ((tm_date.tm_year + 1900) * 10000) - tm_date.tm_mon * 100);
-
-                               anniversary->setDate(tm_date);
-
-                               //if (type)
-                               //      anniv->setLabel(string("ANNIVERSARY"));
-
-                               anniversaries->push_back(anniversary);
-                       }
-               }
-       }
-       else if (errorCode != CTS_ERR_NO_DATA)
-       {
-               return false;
-       }
-
-       m_abstractContact->setAnniversaries(anniversaries);
-
-       return true;
-}
-
-bool ContactWrapper::convertToAbstractBirthdayObject()
-{
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       GSList *eventList = NULL;
-       int errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_EVENT_LIST, &eventList);
-       if (CTS_SUCCESS == errorCode)
-       {
-               for (; eventList; eventList = g_slist_next(eventList))
-               {
-                       int type = contacts_svc_value_get_int(static_cast<CTSvalue*>(eventList->data), CTS_EVENT_VAL_TYPE_INT);
-                       int db_date = contacts_svc_value_get_int(static_cast<CTSvalue*>(eventList->data), CTS_EVENT_VAL_DATE_INT);
-
-                       if (type == CTS_EVENT_TYPE_BIRTH)
-                       {
-                               tm tm_date;
-
-                               tm_date.tm_year = (db_date / 10000) - 1900;
-                               tm_date.tm_mon = ((db_date - ((tm_date.tm_year + 1900) * 10000)) / 100) - 1;
-                               tm_date.tm_mday = (db_date - ((tm_date.tm_year + 1900) * 10000) - tm_date.tm_mon * 100);
-
-                               m_abstractContact->setBirthday(tm_date);
-                               break;
-                       }
-               }
-       }
-       else if (errorCode != CTS_ERR_NO_DATA)
-       {
-               return false;
-       }
-
-       return true;
-}
-
-bool ContactWrapper::convertToAbstractEmailObject()
-{
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       ContactEmailAddressArrayPtr emailAddresses(new ContactEmailAddressArray());
-
-       GSList *emailList = NULL;
-       int errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_EMAIL_LIST, &emailList);
-       if (CTS_SUCCESS == errorCode)
-       {
-               for (; emailList; emailList = g_slist_next(emailList))
-               {
-                       ContactEmailAddressPtr email(new ContactEmailAddress());
-
-                       emailAddresses->push_back(email);
-
-                       int type = contacts_svc_value_get_int(static_cast<CTSvalue*>(emailList->data), CTS_EMAIL_VAL_TYPE_INT);
-
-                       if(type | CTS_EMAIL_TYPE_NONE)
-                               email->addType(CONTACT_EMAIL_TYPE_PREF);
-                       if(type | CTS_EMAIL_TYPE_HOME)
-                               email->addType(CONTACT_EMAIL_TYPE_HOME);
-                       if(type | CTS_EMAIL_TYPE_WORK)
-                               email->addType(CONTACT_EMAIL_TYPE_WORK);
-
-                       const char *charValue = NULL;
-
-                       charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(emailList->data), CTS_EMAIL_VAL_ADDR_STR);
-                       if (charValue)
-                               email->setEmail(charValue);
-               }
-       }
-       else if (errorCode != CTS_ERR_NO_DATA)
-       {
-               return false;
-       }
-
-       m_abstractContact->setEmails(emailAddresses);
-
-       return true;
-}
-
-bool ContactWrapper::convertToAbstractPhoneObject()
-{
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       ContactPhoneNumberArrayPtr phoneNumbers(new ContactPhoneNumberArray());
-
-       GSList *phoneList = NULL;
-       int errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_NUMBER_LIST, &phoneList);
-       if (CTS_SUCCESS == errorCode)
-       {
-               for (; phoneList; phoneList = g_slist_next(phoneList))
-               {
-                       ContactPhoneNumberPtr phoneNumber(new ContactPhoneNumber());
-                       phoneNumbers->push_back(phoneNumber);
-
-                       int type = contacts_svc_value_get_int(static_cast<CTSvalue*>(phoneList->data), CTS_NUM_VAL_TYPE_INT);
-                       if(type & CTS_NUM_TYPE_WORK)
-                               phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_WORK);
-                       if(type & CTS_NUM_TYPE_NONE)
-                               phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_PREF);
-                       if(type & CTS_NUM_TYPE_HOME)
-                               phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_HOME);
-                       if(type & CTS_NUM_TYPE_FAX)
-                               phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_FAX);
-                       if(type & CTS_NUM_TYPE_CELL)
-                               phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_CELL);
-                       if(type & CTS_NUM_TYPE_PAGER)
-                               phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_PAGER);
-                       if(type & CTS_NUM_TYPE_CAR)
-                               phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_CAR);
-                       if(type & CTS_NUM_TYPE_VOICE)
-                               phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_VOICE);
-                       if(type & CTS_NUM_TYPE_MSG)
-                               phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_MSG);
-                       if(type & CTS_NUM_TYPE_BBS)
-                               phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_BBS);
-                       if(type & CTS_NUM_TYPE_ISDN)
-                               phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_ISDN);
-                       if(type & CTS_NUM_TYPE_VIDEO)
-                               phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_VIDEO);
-                       if(type & CTS_NUM_TYPE_PCS)
-                               phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_PCS);
-                       if(type & CTS_NUM_TYPE_WORK)
-                               phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_WORK);
-                       if(type & CTS_NUM_TYPE_WORK)
-                               phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_WORK);
-
-                       const char *charValue = NULL;
-
-                       charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(phoneList->data), CTS_NUM_VAL_NUMBER_STR);
-                       if (charValue)
-                               phoneNumber->setNumber(charValue);
-               }
-       }
-       else if (errorCode != CTS_ERR_NO_DATA)
-       {
-               return false;
-       }
-
-       m_abstractContact->setPhoneNumbers(phoneNumbers);
-
-       return true;
-}
-
-bool ContactWrapper::convertToAbstractNicknameObject()
-{
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       StringArrayPtr nickNames(new StringArray());
-
-       GSList *nicknNameList = NULL;
-       int errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_NICKNAME_LIST, &nicknNameList);
-       if (CTS_SUCCESS == errorCode)
-       {
-               for (; nicknNameList; nicknNameList = g_slist_next(nicknNameList))
-               {
-                       const char *charValue = NULL;
-                       charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(nicknNameList->data), CTS_NICKNAME_VAL_NAME_STR);
-                       if (charValue)
-                               nickNames->push_back(charValue);
-               }
-       }
-       else if (errorCode != CTS_ERR_NO_DATA)
-       {
-               return false;
-       }
-
-       m_abstractContact->getName()->setNicknames(nickNames);
-
-       return true;
-}
-
-bool ContactWrapper::convertToAbstractPhoneticnameObject()
-{
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       int structFieldType = 0;
-       structFieldType = getCustomTypeInContactsSvc(CONTACT_ATTRIBUTE_PHONETIC_FIRST_NAME);
-       if (structFieldType < CTS_SUCCESS)
-       {
-               LogError("Phonetic first name struct type is not found!!");
-               return false;
-       }
-
-       CTSvalue *value = NULL;
-       int errorCode;
-       errorCode = contacts_svc_struct_get_value(m_platformContact, static_cast<cts_struct_field>(structFieldType), &value);
-       if (CTS_SUCCESS == errorCode)
-       {
-               if (value)
-               {
-                       const char *charValue = NULL;
-                       charValue = contacts_svc_value_get_str(value, CTS_EXTEND_VAL_DATA2_STR);
-                       if (charValue)
-                               m_abstractContact->getName()->setPhoneticFirstName(charValue);
-               }
-               else
-               {
-                       return false;
-               }
-       }
-       else if (errorCode != CTS_ERR_NO_DATA)
-       {
-               return false;
-       }
-
-       structFieldType = getCustomTypeInContactsSvc(CONTACT_ATTRIBUTE_PHONETIC_LAST_NAME);
-       if (structFieldType < CTS_SUCCESS)
-       {
-               LogError("Phonetic name struct type is not found!!");
-               return false;
-       }
-
-       value = NULL;
-       errorCode = contacts_svc_struct_get_value(m_platformContact, static_cast<cts_struct_field>(structFieldType), &value);
-       if (CTS_SUCCESS == errorCode)
-       {
-               if (value)
-               {
-                       const char *charValue = NULL;
-                       charValue = contacts_svc_value_get_str(value, CTS_EXTEND_VAL_DATA3_STR);
-                       if (charValue)
-                               m_abstractContact->getName()->setPhoneticLastName(charValue);
-               }
-               else
-               {
-                       return false;
-               }
-       }
-       else if (errorCode != CTS_ERR_NO_DATA)
-       {
-               return false;
-       }
-
-       return true;
-}
-
-bool ContactWrapper::convertToAbstractGroupObject()
-{
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       StringArrayPtr categories(new StringArray());
-
-       GSList *groupList = NULL;
-       int errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_GROUPREL_LIST, &groupList);
-       if (CTS_SUCCESS == errorCode)
-       {
-               for (; groupList; groupList = g_slist_next(groupList))
-               {
-                       const char *charValue = NULL;
-                       charValue = contacts_svc_value_get_str(static_cast<CTSvalue*>(groupList->data), CTS_GROUPREL_VAL_NAME_STR);
-                       if (charValue)
-                               categories->push_back(charValue);
-               }
-       }
-       else if (errorCode != CTS_ERR_NO_DATA)
-       {
-               return false;
-       }
-
-       m_abstractContact->setCategories(categories);
-
-       return true;
-}
-
-bool ContactWrapper::convertToPlatformNicknameObject()
-{
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       StringArrayPtr nicknames = m_abstractContact->getName()->getNicknames();
-
-       bool properlyCreated = true;
-
-       GSList *nicknameList = NULL;
-       if (CTS_SUCCESS == contacts_svc_struct_get_list(m_platformContact, CTS_CF_NICKNAME_LIST, &nicknameList))
-       {
-               GSList *nicknameListSave = nicknameList;
-               for (; nicknameList; nicknameList = g_slist_next(nicknameList))
-               {
-                       CTSvalue* nickname = static_cast<CTSvalue*>(nicknameList->data);
-                       contacts_svc_value_set_bool(nickname, CTS_NICKNAME_VAL_DELETE_BOOL, true);
-               }
-               nicknameList = nicknameListSave;
-       }
-
-       if (nicknames->size() == 0 && nicknameList == NULL)
-               return true;
-
-       //add new items
-       for (size_t i = 0; i < nicknames->size(); ++i)
-       {
-               CTSvalue *nickname = NULL;
-               nickname = contacts_svc_value_new(CTS_VALUE_NICKNAME);
-               if (nickname)
-               {
-                       if (CTS_SUCCESS == contacts_svc_value_set_str(nickname, CTS_NICKNAME_VAL_NAME_STR, nicknames->at(i).c_str()))
-                       {
-                               nicknameList = g_slist_append(nicknameList, nickname);
-                       }
-                       else
-                       {
-                               contacts_svc_value_free(nickname);
-                               properlyCreated = false;
-                               break;
-                       }
-               }
-               else
-               {
-                       properlyCreated = false;
-                       break;
-               }
-       }
-
-       if (properlyCreated)
-       {
-               if (CTS_SUCCESS != contacts_svc_struct_store_list(m_platformContact, CTS_CF_NICKNAME_LIST, nicknameList))
-               {
-                       properlyCreated = false;
-               }
-       }
-
-       return properlyCreated;
-}
-
-bool ContactWrapper::convertToPlatformPhoneticnameObject()
-{
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       int structFieldType = 0;
-       structFieldType = getCustomTypeInContactsSvc(CONTACT_ATTRIBUTE_PHONETIC_FIRST_NAME);
-       if (structFieldType < CTS_SUCCESS)
-       {
-               LogError("Phonetic first name struct type is not found!!");
-               return false;
-       }
-
-       /**
-        *If phonetic name information is not existed, add phonetic name information
-        *If phonetic name information is existed,update phonetic name information
-        */
-       CTSvalue *value = NULL;
-       if (CTS_SUCCESS != contacts_svc_struct_get_value(m_platformContact, static_cast<cts_struct_field>(structFieldType), &value))
-       {
-               value = contacts_svc_value_new(CTS_VALUE_EXTEND);
-               if (!value)
-                       return false;
-
-       }
-
-       if (CTS_SUCCESS != contacts_svc_value_set_str(value, CTS_EXTEND_VAL_DATA2_STR, m_abstractContact->getName()->getPhoneticFirstName().c_str())
-                       || CTS_SUCCESS != contacts_svc_struct_store_value(m_platformContact, static_cast<cts_struct_field>(structFieldType), value))
-       {
-               contacts_svc_value_free(value);
-               return false;
-       }
-
-       structFieldType = getCustomTypeInContactsSvc(CONTACT_ATTRIBUTE_PHONETIC_LAST_NAME);
-       if (structFieldType < CTS_SUCCESS)
-       {
-               LogError("Phonetic last name struct type is not found!!");
-               return false;
-       }
-
-       /**
-        *If phonetic name information is not existed, add phonetic name information
-        *If phonetic name information is existed,update phonetic name information
-        */
-       value = NULL;
-       if (CTS_SUCCESS != contacts_svc_struct_get_value(m_platformContact, static_cast<cts_struct_field>(structFieldType), &value))
-       {
-               value = contacts_svc_value_new(CTS_VALUE_EXTEND);
-               if (!value)
-                       return false;
-
-       }
-
-       if (CTS_SUCCESS != contacts_svc_value_set_str(value, CTS_EXTEND_VAL_DATA3_STR, m_abstractContact->getName()->getPhoneticLastName().c_str())
-                       || CTS_SUCCESS != contacts_svc_struct_store_value(m_platformContact, static_cast<cts_struct_field>(structFieldType), value))
-       {
-               contacts_svc_value_free(value);
-               return false;
-       }
-
-
-       contacts_svc_value_free(value);
-
-//     LogDebug("RETURN TRUE!!!");
-       return true;
-}
-
-bool ContactWrapper::convertToPlatformGroupObject()
-{
-//     LogDebug("entered");
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       StringArrayPtr groups = m_abstractContact->getCategories();
-       CTSvalue *group = NULL;
-       bool properlyCreated = true;
-       GSList *groupList = NULL;
-       //mark existing items to delete them.
-       if (CTS_SUCCESS == contacts_svc_struct_get_list(m_platformContact, CTS_CF_GROUPREL_LIST, &groupList))
-       {
-               GSList *groupListSave = groupList;
-               for (; groupList; groupList = g_slist_next(groupList))
-               {
-//                     LogDebug("clearing group list");
-                       CTSvalue* delgroup = static_cast<CTSvalue*>(groupList->data);
-                       contacts_svc_value_set_bool(delgroup, CTS_GROUPREL_VAL_DELETE_BOOL, true);
-               }
-               groupList = groupListSave;
-       }
-       if (groups->size() == 0 && groupList == NULL
-               )
-               return true;
-
-       //add new items
-       query_error error_code = QUERY_SUCCESS;
-       GSList *groups_list = NULL;
-       int accountId;
-
-       try {
-               string accountIdStr = m_abstractContact->getAccountId();
-               stringstream ss(accountIdStr);
-               ss >> accountId;
-       } catch (...) {
-               LogError("Wrong account id");
-               return false;
-       }
-
-       int addressBookId = find_addressbook_id(accountId, &error_code);
-       if (error_code != QUERY_SUCCESS)
-               addressBookId = 0;
-
-       CTSiter* group_iter;
-       bool is_new_group = true;
-
-       for (size_t i = 0; i < groups->size(); ++i)
-       {
-               if (CTS_SUCCESS == contacts_svc_get_list(CTS_LIST_ALL_GROUP, &group_iter))
-               {
-                       while (CTS_SUCCESS == contacts_svc_iter_next(group_iter))
-                       {
-                               CTSvalue *findgroup = contacts_svc_iter_get_info(group_iter);
-                               if (findgroup)
-                               {
-                                       group_info_t* group_info = g_new0(group_info_t, 1);
-
-                                       group_info->group_name = g_strdup(contacts_svc_value_get_str(findgroup, CTS_LIST_GROUP_NAME_STR));
-                                       group_info->addressbook_id = contacts_svc_value_get_int(findgroup, CTS_GROUP_VAL_ADDRESSBOOK_ID_INT);
-                                       group_info->group_id = contacts_svc_value_get_int(findgroup, CTS_GROUP_VAL_ID_INT);
-                                       groups_list = g_slist_append(groups_list, group_info);
-                               }
-                       }
-               }
-
-               group = contacts_svc_value_new(CTS_VALUE_GROUP_RELATION);
-               if (group)
-               {
-                       int groupId = -1;
-                       //groupId = AddressBook::getGroupId(groups[i]);
-
-                       is_new_group = true;
-                       GSList* tmp_list = groups_list;
-                       while (tmp_list)
-                       {
-                               group_info_t* info = (group_info_t*) tmp_list->data;
-
-                               if ((info->group_name != NULL) && (groups->at(i).compare(info->group_name) == 0)
-                                               && (info->addressbook_id == addressBookId))
-                               {
-                                       is_new_group = false;
-                                       groupId = info->group_id;
-                               }
-                               if (info->group_name)
-                                       free(info->group_name);
-                               free(info);
-                               tmp_list = g_slist_next(tmp_list);
-                       }
-                       g_slist_free(groups_list);
-                       groups_list = NULL;
-
-                       if (is_new_group)
-                       {
-                               CTSvalue *new_group;
-                               new_group = contacts_svc_value_new(CTS_VALUE_GROUP);
-
-                               contacts_svc_value_set_str(new_group, CTS_GROUP_VAL_NAME_STR, (const char*) (groups->at(i).c_str()));
-                               contacts_svc_value_set_int(new_group, CTS_GROUP_VAL_ADDRESSBOOK_ID_INT, addressBookId);
-                               groupId = contacts_svc_insert_group(addressBookId, new_group);
-                               if (groupId < 0)
-                                       return false;
-                               contacts_svc_value_free(new_group);
-                       }
-//                     LogDebug("group id " << groupId);
-                       if (groupId != -1)
-                       {
-                               if (CTS_SUCCESS == contacts_svc_value_set_int(group, CTS_GROUPREL_VAL_ID_INT, groupId))
-                               {
-                                       groupList = g_slist_append(groupList, group);
-                               }
-                               else
-                               {
-                                       contacts_svc_value_free(group);
-                                       properlyCreated = false;
-                                       break;
-                               }
-                       }
-                       else
-                       {
-                               contacts_svc_value_free(group);
-                               properlyCreated = false;
-                               break;
-                       }
-               }
-               else
-               {
-                       properlyCreated = false;
-                       break;
-               }
-       }
-       if (properlyCreated)
-       {
-//             LogDebug("storing group list");
-               if (CTS_SUCCESS != contacts_svc_struct_store_list(m_platformContact, CTS_CF_GROUPREL_LIST, groupList))
-               {
-                       properlyCreated = false;
-               }
-       }
-       for (; groupList; groupList = g_slist_next(groupList))
-       {
-               contacts_svc_value_free(static_cast<CTSvalue*>(groupList->data));
-       }
-       g_slist_free(groupList);
-       return properlyCreated;
-}
-
-bool ContactWrapper::convertToPlatformUrlObject()
-{
-//     LogDebug("entered");
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       int type = 0;
-       ContactWebSiteArrayPtr urls = m_abstractContact->getUrls();
-       CTSvalue *url = NULL;
-       bool properlyCreated = true;
-       GSList *urlList = NULL;
-       //mark existing items to delete them.
-       if (CTS_SUCCESS == contacts_svc_struct_get_list(m_platformContact, CTS_CF_WEB_ADDR_LIST, &urlList))
-       {
-               GSList *urlListSave = urlList;
-               for (; urlList; urlList = g_slist_next(urlList))
-               {
-//                     LogDebug("clearing url list");
-                       CTSvalue* tmp_email = static_cast<CTSvalue*>(urlList->data);
-                       contacts_svc_value_set_bool(tmp_email, CTS_WEB_VAL_DELETE_BOOL, true);
-               }
-               urlList = urlListSave;
-       }
-       if (urls->size() == 0 && urlList == NULL
-               )
-               return true;
-
-       //add new items
-       for (size_t i = 0; i < urls->size(); ++i)
-       {
-               ContactWebSiteType types = urls->at(i)->getType();
-               url = contacts_svc_value_new(CTS_VALUE_WEB);
-               if (url)
-               {
-                       switch (types)
-                       {
-                       case WEBSITE_TYPE_HOMEPAGE:
-                               type = CTS_WEB_TYPE_HOME;
-                               break;
-                       case WEBSITE_TYPE_BLOG:
-                               type = CTS_WEB_TYPE_WORK;
-                               break;
-                       default:
-                               LogError("invalid phone type");
-                               type = CTS_WEB_TYPE_NONE;
-                               break;
-                       }
-                       if (CTS_SUCCESS == contacts_svc_value_set_int(url, CTS_WEB_VAL_TYPE_INT, type)
-                                       && CTS_SUCCESS == contacts_svc_value_set_str(url, CTS_WEB_VAL_ADDR_STR, urls->at(i)->getUrl().c_str()))
-                       {
-                               urlList = g_slist_append(urlList, url);
-                       }
-                       else
-                       {
-                               contacts_svc_value_free(url);
-                               properlyCreated = false;
-                               break;
-                       }
-               }
-               else
-               {
-                       properlyCreated = false;
-                       break;
-               }
-
-               if (!properlyCreated)
-               {
-                       break;
-               }
-       }
-
-       if (properlyCreated)
-       {
-               if (CTS_SUCCESS != contacts_svc_struct_store_list(m_platformContact, CTS_CF_WEB_ADDR_LIST, urlList))
-               {
-                       properlyCreated = false;
-               }
-       }
-       for (; urlList; urlList = g_slist_next(urlList))
-       {
-               contacts_svc_value_free(static_cast<CTSvalue*>(urlList->data));
-       }
-       g_slist_free(urlList);
-       return properlyCreated;
-}
-
-bool ContactWrapper::convertToPlatformOrganizationObject()
-{
-//     LogDebug("entered");
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       ContactOrganizationPtr org = m_abstractContact->getOrganization();
-       bool isNewValue = false;
-       CTSvalue *value = NULL;
-
-       if (CTS_SUCCESS != contacts_svc_struct_get_value(m_platformContact, CTS_CF_COMPANY_VALUE, &value))
-       {
-               value = contacts_svc_value_new(CTS_VALUE_COMPANY);
-               if(!value)
-                       return false;
-
-               isNewValue = true;
-       }
-
-       if (CTS_SUCCESS != contacts_svc_value_set_str(value, CTS_COMPANY_VAL_NAME_STR, org->getName().c_str())
-                       || CTS_SUCCESS != contacts_svc_value_set_str(value, CTS_COMPANY_VAL_DEPARTMENT_STR, org->getDepartment().c_str())
-                       || CTS_SUCCESS != contacts_svc_value_set_str(value, CTS_COMPANY_VAL_JOB_TITLE_STR, org->getTitle().c_str())
-                       || CTS_SUCCESS != contacts_svc_value_set_str(value, CTS_COMPANY_VAL_ROLE_STR, org->getRole().c_str()) )
-       {
-               contacts_svc_value_free(value);
-               return false;
-       }
-
-       if( isNewValue
-                       && org->getName().empty()
-                       && org->getDepartment().empty()
-                       && org->getTitle().empty()
-                       && org->getRole().empty() )
-       {
-               LogDebug("Nothing to store for ContactOrganization");
-       }
-       else
-       {
-               if ( CTS_SUCCESS != contacts_svc_struct_store_value(m_platformContact, CTS_CF_COMPANY_VALUE, value) )
-               {
-                       contacts_svc_value_free(value);
-                       return false;
-               }
-       }
-
-       contacts_svc_value_free(value);
-
-       return true;
-}
-
-bool ContactWrapper::convertToPlatformAnniversaryObject()
-{
-//     LogDebug("entered");
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       ContactAnniversaryArrayPtr anniversaries = m_abstractContact->getAnniversaries();
-       CTSvalue *anniversary = NULL;
-       bool properlyCreated = true;
-       GSList *anniversaryList = NULL;
-
-       //mark existing items to delete them.
-       if (CTS_SUCCESS == contacts_svc_struct_get_list(m_platformContact, CTS_CF_EVENT_LIST, &anniversaryList))
-       {
-               GSList *anniversaryListSave = anniversaryList;
-               for (; anniversaryList; anniversaryList = g_slist_next(anniversaryList))
-               {
-//                     LogDebug("clearing anniversary list");
-                       CTSvalue* tmp_anniversary = static_cast<CTSvalue*>(anniversaryList->data);
-                       contacts_svc_value_set_bool(tmp_anniversary, CTS_EVENT_VAL_DELETE_BOOL, true);
-               }
-               anniversaryList = anniversaryListSave;
-       }
-       if (anniversaries->size() == 0 && anniversaryList == NULL
-               )
-               return true;
-
-       //add new items
-       int date = 0;
-       for (size_t i = 0; i < anniversaries->size(); ++i)
-       {
-               date = 0;
-               std::tm abstract_date = anniversaries->at(i)->getDate();
-
-               date = (abstract_date.tm_year + 1900) * 10000 + (abstract_date.tm_mon+1) * 100  + abstract_date.tm_mday;
-               anniversary = contacts_svc_value_new(CTS_VALUE_EVENT);
-               if (anniversary)
-               {
-                       if (CTS_SUCCESS == contacts_svc_value_set_int(anniversary, CTS_EVENT_VAL_TYPE_INT, CTS_EVENT_TYPE_ANNIVERSARY)
-                                       && CTS_SUCCESS == contacts_svc_value_set_int(anniversary, CTS_EVENT_VAL_DATE_INT, date))
-                       {
-                               anniversaryList = g_slist_append(anniversaryList, anniversary);
-                       }
-                       else
-                       {
-                               contacts_svc_value_free(anniversary);
-                               properlyCreated = false;
-                               break;
-                       }
-               }
-               else
-               {
-                       properlyCreated = false;
-                       break;
-               }
-
-               if (!properlyCreated)
-               {
-                       break;
-               }
-       }
-
-       if (properlyCreated)
-       {
-               if (CTS_SUCCESS != contacts_svc_struct_store_list(m_platformContact, CTS_CF_EVENT_LIST, anniversaryList))
-               {
-                       properlyCreated = false;
-               }
-       }
-       for (; anniversaryList; anniversaryList = g_slist_next(anniversaryList))
-       {
-               contacts_svc_value_free(static_cast<CTSvalue*>(anniversaryList->data));
-       }
-       g_slist_free(anniversaryList);
-       return properlyCreated;
-}
-
-bool ContactWrapper::convertToPlatformbirthdayObject()
-{
-//     LogDebug("entered");
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       tm birth_date = m_abstractContact->getBirthday();
-
-       CTSvalue *birthday = NULL;
-       bool properlyCreated = true;
-       GSList *anniversaryList = NULL;
-
-       //mark existing items to delete them.
-       if (CTS_SUCCESS == contacts_svc_struct_get_list(m_platformContact, CTS_CF_EVENT_LIST, &anniversaryList))
-       {
-               GSList *anniversaryListSave = anniversaryList;
-               for (; anniversaryList; anniversaryList = g_slist_next(anniversaryList))
-               {
-//                     LogDebug("clearing anniversary list");
-                       CTSvalue* tmp_anniversary = static_cast<CTSvalue*>(anniversaryList->data);
-                       int type = contacts_svc_value_get_int(tmp_anniversary, CTS_EVENT_VAL_TYPE_INT);
-                       if (type == CTS_EVENT_TYPE_BIRTH)
-                               contacts_svc_value_set_bool(tmp_anniversary, CTS_EVENT_VAL_DELETE_BOOL, true);
-               }
-               anniversaryList = anniversaryListSave;
-       }
-       if (birth_date.tm_year == 0 && birth_date.tm_mon == 0 && birth_date.tm_mday == 0 && anniversaryList == NULL
-               )
-               return true;
-
-       //add new items
-       int date = 0;
-       date = (birth_date.tm_year + 1900) * 10000 + (birth_date.tm_mon+1) * 100 + birth_date.tm_mday;
-//     for (size_t i = 0; i < anniversaries->size(); ++i) {
-       birthday = contacts_svc_value_new(CTS_VALUE_EVENT);
-       if (birthday)
-       {
-
-               if (CTS_SUCCESS == contacts_svc_value_set_int(birthday, CTS_EVENT_VAL_TYPE_INT, CTS_EVENT_TYPE_BIRTH)
-                               && CTS_SUCCESS == contacts_svc_value_set_int(birthday, CTS_EVENT_VAL_DATE_INT, date))
-               {
-                       anniversaryList = g_slist_append(anniversaryList, birthday);
-               }
-               else
-               {
-                       contacts_svc_value_free(birthday);
-                       properlyCreated = false;
-//                             break;
-               }
-       }
-       else
-       {
-               properlyCreated = false;
-//                     break;
-       }
-
-//             if (!properlyCreated) {
-//                     break;
-//             }
-//     }
-
-       if (properlyCreated)
-       {
-               if (CTS_SUCCESS != contacts_svc_struct_store_list(m_platformContact, CTS_CF_EVENT_LIST, anniversaryList))
-               {
-                       properlyCreated = false;
-               }
-       }
-       for (; anniversaryList; anniversaryList = g_slist_next(anniversaryList))
-       {
-               contacts_svc_value_free(static_cast<CTSvalue*>(anniversaryList->data));
-       }
-       g_slist_free(anniversaryList);
-       return properlyCreated;
-}
-
-bool ContactWrapper::convertToPlatformPhoneObject()
-{
-//     LogDebug("entered");
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       int type = 0;
-       ContactPhoneNumberArrayPtr phoneNumbers = m_abstractContact->getPhoneNumbers();
-       bool properlyCreated = true;
-       CTSvalue *number = NULL;
-       GSList *numberList = NULL;
-       //mark existing items to delete them.
-       if (CTS_SUCCESS == contacts_svc_struct_get_list(m_platformContact, CTS_CF_NUMBER_LIST, &numberList))
-       {
-               GSList *numberListSave = numberList;
-               for (; numberList; numberList = g_slist_next(numberList))
-               {
-//                     LogDebug("clearing phone list");
-                       CTSvalue* number = static_cast<CTSvalue*>(numberList->data);
-                       contacts_svc_value_set_bool(number, CTS_NUM_VAL_DELETE_BOOL, true);
-               }
-               numberList = numberListSave;
-       }
-       if (phoneNumbers->size() == 0 && numberList == NULL )
-               return true;
-
-       //add new items
-       for (size_t i = 0; i < phoneNumbers->size(); ++i)
-       {
-               ContactPhoneNumberTypeArrayPtr types = phoneNumbers->at(i)->getTypes();
-               number = contacts_svc_value_new(CTS_VALUE_NUMBER);
-               type = 0;
-               if (number)
-               {
-                       for (size_t j = 0; j < types->size(); ++j)
-                       {
-                               if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_WORK)
-                                       type = type | CTS_NUM_TYPE_WORK;
-                               else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_PREF)
-                                       type = type | CTS_NUM_TYPE_NONE;
-                               else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_HOME)
-                                       type = type | CTS_NUM_TYPE_HOME;
-                               else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_FAX)
-                                       type = type | CTS_NUM_TYPE_FAX;
-                               else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_CELL)
-                                       type = type | CTS_NUM_TYPE_CELL;
-                               else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_PAGER)
-                                       type = type | CTS_NUM_TYPE_PAGER;
-                               else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_CAR)
-                                       type = type | CTS_NUM_TYPE_CAR;
-                               else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_BBS)
-                                       type = type | CTS_NUM_TYPE_BBS;
-                               else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_MODEM)
-                                       type = type | CTS_NUM_TYPE_MODEM;
-                               else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_ISDN)
-                                       type = type | CTS_NUM_TYPE_ISDN;
-                               else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_VIDEO)
-                                       type = type | CTS_NUM_TYPE_VIDEO;
-                               else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_VOICE)
-                                       type = type | CTS_NUM_TYPE_VOICE;
-                               else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_MSG)
-                                       type = type | CTS_NUM_TYPE_MSG;
-                               else
-                               {
-                                       LogError("invalid phone type");
-                                       type = CTS_NUM_TYPE_NONE;
-                               }
-                       }
-                       if (CTS_SUCCESS == contacts_svc_value_set_str(number, CTS_NUM_VAL_NUMBER_STR, phoneNumbers->at(i)->getNumber().c_str())
-                                       && CTS_SUCCESS == contacts_svc_value_set_bool(number, CTS_NUM_VAL_DEFAULT_BOOL, type == CTS_NUM_TYPE_NONE)
-                                       && CTS_SUCCESS == contacts_svc_value_set_int(number, CTS_NUM_VAL_TYPE_INT, type))
-                       {
-                               numberList = g_slist_append(numberList, number);
-                       }
-                       else
-                       {
-                               contacts_svc_value_free(number);
-                               properlyCreated = false;
-                               break;
-                       }
-               }
-               else
-               {
-                       properlyCreated = false;
-                       break;
-               }
-               if (!properlyCreated)
-               {
-                       break;
-               }
-       }
-       if (properlyCreated)
-       {
-               if (CTS_SUCCESS != contacts_svc_struct_store_list(m_platformContact, CTS_CF_NUMBER_LIST, numberList))
-               {
-                       properlyCreated = false;
-               }
-       }
-       for (; numberList; numberList = g_slist_next(numberList))
-       {
-               contacts_svc_value_free(static_cast<CTSvalue*>(numberList->data));
-       }
-       g_slist_free(numberList);
-       return properlyCreated;
-}
-
-bool ContactWrapper::convertToPlatformEmailObject()
-{
-//     LogDebug("entered");
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       int type = 0;
-       ContactEmailAddressArrayPtr emails = m_abstractContact->getEmails();
-       CTSvalue *email = NULL;
-       bool properlyCreated = true;
-       GSList *emailList = NULL;
-       //mark existing items to delete them.
-       if (CTS_SUCCESS == contacts_svc_struct_get_list(m_platformContact, CTS_CF_EMAIL_LIST, &emailList))
-       {
-               GSList *emailListSave = emailList;
-               for (; emailList; emailList = g_slist_next(emailList))
-               {
-//                     LogDebug("clearing email list");
-                       CTSvalue* email = static_cast<CTSvalue*>(emailList->data);
-                       contacts_svc_value_set_bool(email, CTS_EMAIL_VAL_DELETE_BOOL, true);
-               }
-               emailList = emailListSave;
-       }
-       if (emails->size() == 0 && emailList == NULL)
-               return true;
-
-       //add new items
-       for (size_t i = 0; i < emails->size(); ++i)
-       {
-               ContactEmailAddressTypeArrayPtr types = emails->at(i)->getTypes();
-               email = contacts_svc_value_new(CTS_VALUE_EMAIL);
-               type = 0;
-               if (email)
-               {
-                       for (size_t j = 0; j < types->size(); ++j)
-                       {
-                               switch (types->at(j))
-                               {
-                               case CONTACT_EMAIL_TYPE_HOME:
-                                       type = type | CTS_EMAIL_TYPE_HOME;
-                                       break;
-                               case CONTACT_EMAIL_TYPE_WORK:
-                                       type = type | CTS_EMAIL_TYPE_WORK;
-                                       break;
-                               case CONTACT_EMAIL_TYPE_PREF:
-                                       type = type | CTS_EMAIL_TYPE_NONE;
-                                       break;
-                               default:
-                                       LogError("invalid phone type");
-                                       type = CTS_EMAIL_TYPE_NONE;
-                                       break;
-                               }
-                       }
-                       if (CTS_SUCCESS == contacts_svc_value_set_int(email, CTS_EMAIL_VAL_TYPE_INT, type)
-                                       && CTS_SUCCESS == contacts_svc_value_set_str(email, CTS_EMAIL_VAL_ADDR_STR, emails->at(i)->getEmail().c_str()))
-                       {
-                               emailList = g_slist_append(emailList, email);
-                       }
-                       else
-                       {
-                               contacts_svc_value_free(email);
-                               properlyCreated = false;
-                               break;
-                       }
-               }
-               else
-               {
-                       properlyCreated = false;
-                       break;
-               }
-
-               if (!properlyCreated)
-               {
-                       break;
-               }
-       }
-       if (properlyCreated)
-       {
-               if (CTS_SUCCESS != contacts_svc_struct_store_list(m_platformContact, CTS_CF_EMAIL_LIST, emailList))
-               {
-                       properlyCreated = false;
-               }
-       }
-       for (; emailList; emailList = g_slist_next(emailList))
-       {
-               contacts_svc_value_free(static_cast<CTSvalue*>(emailList->data));
-       }
-       g_slist_free(emailList);
-       return properlyCreated;
-}
-
-bool ContactWrapper::convertToPlatformAddressObject()
-{
-//     LogDebug("entered");
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       int type = 0;
-       ContactAddressArrayPtr addresses = m_abstractContact->getAddresses();
-       bool properlyCreated = true;
-
-       GSList *addressList = NULL;
-       if (CTS_SUCCESS == contacts_svc_struct_get_list(m_platformContact, CTS_CF_POSTAL_ADDR_LIST, &addressList))
-       {
-               GSList *addressListSave = addressList;
-               for (; addressList; addressList = g_slist_next(addressList))
-               {
-//                     LogDebug("clearing address list");
-                       CTSvalue* address = static_cast<CTSvalue*>(addressList->data);
-                       contacts_svc_value_set_bool(address, CTS_POSTAL_VAL_DELETE_BOOL, true);
-               }
-               addressList = addressListSave;
-       }
-       if (addresses->size() == 0 && addressList == NULL)
-               return true;
-
-       //add new items
-       for (size_t i = 0; i < addresses->size(); ++i)
-       {
-               ContactAddressPtr contactAddress = addresses->at(i);
-               ContactAddressTypeArrayPtr types = contactAddress->getTypes();
-
-               CTSvalue *address = NULL;
-               address = contacts_svc_value_new(CTS_VALUE_POSTAL);
-               if (address)
-               {
-                       type = 0;
-                       for (size_t j = 0; j < types->size(); ++j)
-                       {
-                               switch (types->at(j))
-                               {
-                               case CONTACT_ADDRESS_TYPE_PREF:
-                                       type |= CTS_ADDR_TYPE_POSTAL;   // TODO To be checked
-                                       break;
-                               case CONTACT_ADDRESS_TYPE_WORK:
-                                       type |= CTS_ADDR_TYPE_WORK;
-                                       break;
-                               case CONTACT_ADDRESS_TYPE_HOME:
-                                       type |= CTS_ADDR_TYPE_HOME;
-                                       break;
-                               default:
-                                       LogError("invalid address type");
-                                       type |= CTS_EMAIL_TYPE_NONE;
-                                       break;
-                               }
-                       }
-                       if (CTS_SUCCESS == contacts_svc_value_set_int(address, CTS_POSTAL_VAL_TYPE_INT, type)
-                                       && CTS_SUCCESS == contacts_svc_value_set_str(address, CTS_POSTAL_VAL_COUNTRY_STR, contactAddress->getCountry().c_str())
-                                       && CTS_SUCCESS == contacts_svc_value_set_str(address, CTS_POSTAL_VAL_REGION_STR, contactAddress->getRegion().c_str())
-                                       && CTS_SUCCESS == contacts_svc_value_set_str(address, CTS_POSTAL_VAL_LOCALITY_STR, contactAddress->getCity().c_str())
-                                       && CTS_SUCCESS == contacts_svc_value_set_str(address, CTS_POSTAL_VAL_STREET_STR, contactAddress->getStreetAddress().c_str())
-                                       && CTS_SUCCESS == contacts_svc_value_set_str(address, CTS_POSTAL_VAL_POBOX_STR, contactAddress->getAdditionalInformation().c_str())
-                                       && CTS_SUCCESS == contacts_svc_value_set_str(address, CTS_POSTAL_VAL_POSTALCODE_STR, contactAddress->getPostalCode().c_str())
-                                       && CTS_SUCCESS == contacts_svc_value_set_str(address, CTS_POSTAL_VAL_EXTENDED_STR, contactAddress->getAdditionalInformation().c_str()))
-                       {
-                               addressList = g_slist_append(addressList, address);
-                       }
-                       else
-                       {
-                               contacts_svc_value_free(address);
-                               properlyCreated = false;
-                               break;
-                       }
-               }
-               else
-               {
-                       properlyCreated = false;
-                       break;
-               }
-
-               if (!properlyCreated)
-               {
-                       break;
-               }
-       }
-
-       if (properlyCreated)
-       {
-               if (CTS_SUCCESS != contacts_svc_struct_store_list(m_platformContact, CTS_CF_POSTAL_ADDR_LIST, addressList))
-               {
-                       properlyCreated = false;
-               }
-       }
-       for (; addressList; addressList = g_slist_next(addressList))
-       {
-               contacts_svc_value_free(static_cast<CTSvalue*>(addressList->data));
-       }
-
-       g_slist_free(addressList);
-
-       return properlyCreated;
-}
-
-bool ContactWrapper::convertToPlatformBaseData()
-{
-       if (NULL == m_abstractContact)
-       {
-               LogError("you should create empty abstract contact object first");
-               return false;
-       }
-
-       if (NULL == m_platformContact)
-       {
-               LogError("you should provide platform contact object first");
-               return false;
-       }
-
-       /**
-        *If name information is not existed, add name information
-        * If  name information is existed,update name information
-        */
-       ContactNamePtr contactName = m_abstractContact->getName();
-       bool isValueNew = false;
-       CTSvalue *value = NULL;
-
-       if (CTS_SUCCESS != contacts_svc_struct_get_value(m_platformContact, CTS_CF_NAME_VALUE, &value))
-       {
-               value = contacts_svc_value_new(CTS_VALUE_NAME);
-               if (!value)
-                       return false;
-
-               isValueNew = true;
-       }
-
-       if (CTS_SUCCESS != contacts_svc_value_set_str(value, CTS_NAME_VAL_FIRST_STR, contactName->getFirstName().c_str())
-                       || CTS_SUCCESS != contacts_svc_value_set_str(value, CTS_NAME_VAL_LAST_STR, contactName->getLastName().c_str())
-                       || CTS_SUCCESS != contacts_svc_value_set_str(value, CTS_NAME_VAL_ADDITION_STR, contactName->getMiddleName().c_str())
-                       || CTS_SUCCESS != contacts_svc_value_set_str(value, CTS_NAME_VAL_DISPLAY_STR, contactName->getDisplayName().c_str())
-                       // || CTS_SUCCESS != contacts_svc_value_set_str(value, CTS_NAME_VAL_SUFFIX_STR, contactName->getPhoneticName().c_str())
-                       || CTS_SUCCESS != contacts_svc_value_set_str(value, CTS_NAME_VAL_PREFIX_STR, contactName->getPrefix().c_str()) )
-       {
-               contacts_svc_value_free(value);
-               return false;
-       }
-
-       if( isValueNew
-                       && contactName->getFirstName().empty()
-                       && contactName->getLastName().empty()
-                       && contactName->getMiddleName().empty()
-                       && contactName->getDisplayName().empty()
-                       // && contactName->getPhoneticName().empty()
-                       && contactName->getPrefix().empty() )
-       {
-               LogDebug("Nothing to store for ContactName");
-       }
-       else
-       {
-               if(CTS_SUCCESS != contacts_svc_struct_store_value(m_platformContact, CTS_CF_NAME_VALUE, value))
-               {
-                       contacts_svc_value_free(value);
-                       return false;
-               }
-       }
-       contacts_svc_value_free(value);
-
-       /**
-        *If photo and ringtone uri information is not existed, add the information
-        * If photo and ringtone uri is existed,update the information
-        */
-       CTSvalue *baseinfo = NULL;
-       if (CTS_SUCCESS != contacts_svc_struct_get_value(m_platformContact, CTS_CF_BASE_INFO_VALUE, &baseinfo))
-       {
-
-               baseinfo = contacts_svc_value_new(CTS_VALUE_CONTACT_BASE_INFO);
-               if (baseinfo)
-               {
-                       if (m_abstractContact->getPhotoURIIsSet())
-                       {
-                               if (CTS_SUCCESS != contacts_svc_value_set_str(baseinfo, CTS_BASE_VAL_IMG_PATH_STR, convertUriToPath(m_abstractContact->getPhotoURI()).c_str()))
-                               {
-                                       contacts_svc_value_free(baseinfo);
-                                       return false;
-                               }
-                       }
-
-                       if (m_abstractContact->getRingtoneURIIsSet())
-                       {
-                               if (CTS_SUCCESS != contacts_svc_value_set_str(baseinfo, CTS_BASE_VAL_RINGTONE_PATH_STR, convertUriToPath(m_abstractContact->getRingtoneURI()).c_str()))
-                               {
-                                       contacts_svc_value_free(baseinfo);
-                                       return false;
-                               }
-                       }
-
-                       if (CTS_SUCCESS != contacts_svc_value_set_bool(baseinfo, CTS_BASE_VAL_FAVORITE_BOOL, m_abstractContact->getIsFavorite()))
-                       {
-                               contacts_svc_value_free(baseinfo);
-                               return false;
-                       }
-
-                       if(m_abstractContact->getNoteIsSet())
-                       {
-                               if (CTS_SUCCESS != contacts_svc_value_set_str(baseinfo, CTS_BASE_VAL_NOTE_STR, m_abstractContact->getNote().c_str()))
-                               {
-                                       contacts_svc_value_free(baseinfo);
-                                       return false;
-                               }
-                       }
-
-                       contacts_svc_struct_store_value(m_platformContact, CTS_CF_BASE_INFO_VALUE, baseinfo);
-                       contacts_svc_value_free(baseinfo);
-               }
-               else
-               {
-                       return false;
-               }
-       }
-       else
-       {
-               const char * oldimgpath = NULL;
-               oldimgpath = contacts_svc_value_get_str(baseinfo, CTS_BASE_VAL_IMG_PATH_STR);
-
-               string strOldImagePath = "";
-               if (NULL != oldimgpath)
-               {
-                       strOldImagePath = static_cast<string>(oldimgpath);
-               }
-
-               string strNewImagePath = convertUriToPath(m_abstractContact->getPhotoURI());
-               if (strOldImagePath != strNewImagePath)
-               {
-                       if (CTS_SUCCESS != contacts_svc_value_set_str(baseinfo, CTS_BASE_VAL_IMG_PATH_STR, strNewImagePath.c_str()))
-                       {
-                               contacts_svc_value_free(baseinfo);
-                               return false;
-                       }
-               }
-
-               const char * oldringtonepath = NULL;
-               oldringtonepath = contacts_svc_value_get_str(baseinfo, CTS_BASE_VAL_IMG_PATH_STR);
-
-               string strOldRingtonePath = "";
-               if (NULL != oldringtonepath)
-               {
-                       strOldRingtonePath = static_cast<string>(oldringtonepath);
-               }
-
-               string strNewRingtonePath = convertUriToPath(m_abstractContact->getRingtoneURI());
-               if (strOldRingtonePath != strNewRingtonePath)
-               {
-                       if (CTS_SUCCESS != contacts_svc_value_set_str(baseinfo, CTS_BASE_VAL_RINGTONE_PATH_STR, strNewRingtonePath.c_str()))
-                       {
-                               contacts_svc_value_free(baseinfo);
-                               return false;
-                       }
-               }
-
-               if(m_abstractContact->getNoteIsSet())
-               {
-                       if (CTS_SUCCESS != contacts_svc_value_set_str(baseinfo, CTS_BASE_VAL_NOTE_STR, m_abstractContact->getNote().c_str()))
-                       {
-                               contacts_svc_value_free(baseinfo);
-                               return false;
-                       }
-               }
-               else
-               {
-                       if (CTS_SUCCESS != contacts_svc_value_set_str(baseinfo, CTS_BASE_VAL_NOTE_STR, ""))
-                       {
-                               contacts_svc_value_free(baseinfo);
-                               return false;
-                       }
-               }
-
-               contacts_svc_struct_store_value(m_platformContact, CTS_CF_BASE_INFO_VALUE, baseinfo);
-               contacts_svc_value_free(baseinfo);
-       }
-       /*
-        //save company information
-        CTSvalue *company = NULL;
-        company = contacts_svc_value_new(CTS_VALUE_COMPANY);
-        if (company) {
-        if (m_abstractContact->getOrganizations()->size() > 0) {
-        if (CTS_SUCCESS !=
-        contacts_svc_value_set_str(company, CTS_COMPANY_VAL_NAME_STR,
-        m_abstractContact->getOrganizations()->at(0)->getName().c_str())
-        ||
-        CTS_SUCCESS !=
-        contacts_svc_struct_store_value(m_platformContact,
-        CTS_CF_COMPANY_VALUE, company))
-        {
-        contacts_svc_value_free(company);
-        return false;
-        }
-        }
-        contacts_svc_value_free(value);
-        } else {
-        return false;
-        }
-        */
-       return true;
-}
-
-int ContactWrapper::getCustomTypeInContactsSvc(const string &typeName) const
-{
-       int structFieldType = -1;
-       structFieldType = contacts_svc_find_custom_type(CTS_TYPE_CLASS_EXTEND_DATA, const_cast<char*>(typeName.c_str()));
-       if ( CTS_ERR_DB_RECORD_NOT_FOUND == structFieldType)
-       {
-               LogDebug("CTS_ERR_DB_RECORD_NOT_FOUND!!");
-
-               structFieldType = contacts_svc_insert_custom_type( CTS_TYPE_CLASS_EXTEND_DATA, const_cast<char*>(typeName.c_str()));
-               if (CTS_SUCCESS > structFieldType)
-               {
-                       LogDebug("Create fail");
-               }
-       }
-       else if (CTS_SUCCESS > structFieldType)
-       {
-               LogDebug("contacts_svc_find_custom_type is fail");
-       }
-
-       return structFieldType;
-}
-
-void ContactWrapper::printPlatformObject()
-{
-}
-
-void ContactWrapper::printAbstractObject()
-{
-}
-
-string ContactWrapper::convertUriToPath(string str) const
-{
-       string result;
-
-       if(validate("^file\\:///[a-zA-Z]{2,3}(/\\S*)?$", str, VALIDATE_MATCH_CASELESS))
-               result = str.substr(string("file://").size());
-       else if(validate("^/[a-zA-Z]{2,3}(/\\S*)?$", str, VALIDATE_MATCH_CASELESS))
-               result = str;
-
-       return result;
-}
-
-string ContactWrapper::convertPathToUri(string str) const
-{
-       string result;
-
-       if(validate("^/[a-zA-Z]{2,3}(/\\S*)?$", str, VALIDATE_MATCH_CASELESS))
-               result = "file://" + str;
-       else if(validate("^file\\:///[a-zA-Z]{2,3}(/\\S*)?$", str, VALIDATE_MATCH_CASELESS))
-               result = str;
-
-       return result;
-}
-
-} // Contact
-} // Platform
-} // TizenApis
diff --git a/src/platform/Tizen/Contact/ContactWrapper.h b/src/platform/Tizen/Contact/ContactWrapper.h
deleted file mode 100755 (executable)
index 41f4cd0..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * @file        ContactManager.h
- * @author
- * @version     0.1
- * @brief
- */
-
-#ifndef _PLATFORM_CONTACT_CONTACT_WRAPPER_H_
-#define _PLATFORM_CONTACT_CONTACT_WRAPPER_H_
-
-#include <string>
-#include <list>
-#include <contacts-svc.h>
-#include <API/Contact/IContact.h>
-#include <API/Contact/IAddressBook.h>
-
-namespace TizenApis {
-namespace Platform {
-namespace Contact {
-
-class ContactWrapper
-{
-public:
-       explicit ContactWrapper(TizenApis::Api::Contact::IAddressBook::AddressBookType type);
-       virtual ~ContactWrapper();
-
-       TizenApis::Api::Contact::ContactPtr getAbstractContact() const;
-       void setAbstractContact(const TizenApis::Api::Contact::ContactPtr &contact, bool isConvertingVCard);
-
-       CTSstruct* getPlatformContact() const;
-       //WARNING: calling this function will cause to store pointer inside private field
-       //Structure will be freed by this class when is not needed anymore.
-       //User should not modify nor free passed pointer.
-       void setPlatformContact(CTSstruct* contact, bool isConvertingVCard);
-
-       bool convertAbstractToPlatform(const TizenApis::Api::Contact::ContactPtr &abstract, CTSstruct* platform, bool isConvertingVCard);
-       bool convertPlatformToAbstract(CTSstruct* platform, TizenApis::Api::Contact::ContactPtr &abstract, bool isConvertingVCard);
-
-protected:
-       bool convertToPlatformObject(bool isConvertingVCard);
-       bool convertToAbstractObject(bool isConvertingVCard);
-
-       TizenApis::Api::Contact::ContactPtr m_abstractContact;
-       CTSstruct*        m_platformContact;
-       bool m_platformContactOwnership;
-
-private:
-       void freePlatformObject();
-       void freeAbstractObject();
-
-       bool convertToPlatformBaseData();
-       bool convertToPlatformAddressObject();
-       bool convertToPlatformEmailObject();
-       bool convertToPlatformPhoneObject();
-       bool convertToPlatformNicknameObject();
-       bool convertToPlatformPhoneticnameObject();
-       bool convertToPlatformGroupObject();
-       bool convertToPlatformUrlObject();
-       bool convertToPlatformOrganizationObject();
-       bool convertToPlatformAnniversaryObject();
-       bool convertToPlatformbirthdayObject();
-
-       bool convertToAbstractBaseData();
-       bool convertToAbstractAddressObject();
-       bool convertToAbstractEmailObject();
-       bool convertToAbstractPhoneObject();
-       bool convertToAbstractNicknameObject();
-       bool convertToAbstractPhoneticnameObject();
-       bool convertToAbstractGroupObject();
-       bool convertToAbstractUrlObject();
-       bool convertToAbstractOrganizationObject();
-       bool convertToAbstractAnniversaryObject();
-       bool convertToAbstractBirthdayObject();
-
-       int getCustomTypeInContactsSvc(const std::string &typeName) const;
-       //for debug purpose only
-       void printPlatformObject();
-       //for debug purpose only
-       void printAbstractObject();
-
-       std::string convertUriToPath(std::string str) const;
-       std::string convertPathToUri(std::string str) const;
-};
-
-typedef DPL::SharedPtr<ContactWrapper> ContactWrapperPtr;
-
-} // Contact
-} // Platform
-} // TizenApis
-
-#endif // _PLATFORM_CONTACT_CONTACT_WRAPPER_H_
diff --git a/src/platform/Tizen/Contact/ContactsSvcWrapper.cpp b/src/platform/Tizen/Contact/ContactsSvcWrapper.cpp
new file mode 100755 (executable)
index 0000000..f3d64cd
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file        ContactsSvcWrapper.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactsSvcWrapper.h"
+
+#include <contacts-svc.h>
+#include <dpl/exception.h>
+#include <dpl/singleton_impl.h>
+#include "AddressBook.h"
+
+IMPLEMENT_SINGLETON(TizenApis::Platform::Contact::ContactsSvcWrapper)
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace WrtDeviceApis::Commons;
+using namespace TizenApis::Api::Contact;
+
+ContactsSvcWrapper::ContactsSvcWrapper() :
+       m_opened(false),
+       m_addressBooks(new AddressBookArray()),
+       m_defaultAddressBookIndex(-1)
+{
+       //when it is first instance then open connection to database
+       int ret = contacts_svc_connect();
+       if (ret != CTS_SUCCESS)
+       {
+               //error during opening contacts database
+               LogError("Error occurred during opening contacts database. (ret:" << ret << ")");
+               m_opened = false;
+
+               return;
+       }
+
+       //contacts-service has properly connected.
+       LogDebug("Contact db has properly opened.");
+       m_opened = true;
+
+       loadAddressBooks();
+}
+
+ContactsSvcWrapper::~ContactsSvcWrapper()
+{
+       //when it is last instance then clse connection to database
+       int ret = contacts_svc_disconnect();
+       if (ret != CTS_SUCCESS)
+       {
+               //error during closing contacts database
+               LogError("Error occurred during closing contacts database. (ret:" << ret << ")");
+       }
+       m_opened = false;
+}
+
+void ContactsSvcWrapper::init()
+{
+
+}
+
+AddressBookPtr ContactsSvcWrapper::getAddressBook(const std::string &id)
+{
+       if(!m_opened)
+       {
+               //when database is not opened then set result as failed
+               LogError("Contact db is not open.");
+               ThrowMsg(PlatformException, "Contact DB is not open.");
+       }
+
+       if(m_idMap.find(id) == m_idMap.end())
+               ThrowMsg(NotFoundException, "No AddressBook id:" << id);
+
+       int index = m_idMap[id];
+
+       if(static_cast<int>(m_addressBooks->size()) <= index)
+               ThrowMsg(NotFoundException, "No AddressBook id:" << id);
+
+       return m_addressBooks->at(index);
+}
+
+AddressBookPtr ContactsSvcWrapper::getDefaultAddressBook() const
+{
+       if(!m_opened)
+       {
+               //when database is not opened then set result as failed
+               LogError("Contact db is not open.");
+               ThrowMsg(PlatformException, "Contact DB is not open.");
+       }
+
+       if(m_defaultAddressBookIndex == -1 || m_addressBooks->size() == 0)
+               ThrowMsg(PlatformException, "Invalid request");
+
+       return m_addressBooks->at(m_defaultAddressBookIndex);
+}
+
+AddressBookArrayPtr ContactsSvcWrapper::getAddressBooks() const
+{
+       if(!m_opened)
+       {
+               //when database is not opened then set result as failed
+               LogError("Contact db is not open.");
+               ThrowMsg(PlatformException, "Contact DB is not open.");
+       }
+
+       AddressBookArrayPtr newArray(new AddressBookArray());
+
+       for(AddressBookArray::iterator i = m_addressBooks->begin(); i != m_addressBooks->end(); i++)
+               newArray->push_back(*i);
+
+       return newArray;
+}
+
+void ContactsSvcWrapper::loadAddressBooks()
+{
+       LogDebug("Loading AddressBook");
+
+       CTSiter *iter;
+       int ret = contacts_svc_get_list(CTS_LIST_ALL_ADDRESSBOOK, &iter);
+       if (CTS_SUCCESS != ret)
+       {
+               LogError("Fail to get addressbook list (ret:" << ret << ")");
+               return;
+       }
+
+       while (CTS_SUCCESS == contacts_svc_iter_next(iter))
+       {
+               int id, accountId, mode;
+               const char *name;
+               CTSvalue *info;
+
+               info = contacts_svc_iter_get_info(iter);
+               id = contacts_svc_value_get_int(info, CTS_LIST_ADDRESSBOOK_ID_INT);
+               mode = contacts_svc_value_get_int(info, CTS_LIST_ADDRESSBOOK_MODE_INT);
+               name = contacts_svc_value_get_str(info, CTS_LIST_ADDRESSBOOK_NAME_STR);
+               accountId = contacts_svc_value_get_int(info, CTS_LIST_ADDRESSBOOK_ACC_ID_INT);
+               //accountType = contacts_svc_value_get_int(info, CTS_LIST_ADDRESSBOOK_ACC_TYPE_INT);
+               //count = contacts_svc_count_with_int(CTS_GET_COUNT_CONTACTS_IN_ADDRESSBOOK, id);
+
+               LogDebug(" AddressBook [id:" << id << ", name:" << name <<
+                               ", accId:" << accountId << ", mode:" << mode << "]");
+
+               AddressBook *addressBook = new AddressBook();
+               addressBook->setId(id);
+               addressBook->setName(name);
+               addressBook->setAccountId(accountId);
+               addressBook->setReadOnly(mode == CTS_ADDRESSBOOK_MODE_READONLY);
+
+               insert(AddressBookPtr(addressBook), (id==0));
+       }
+
+       if(size() == 0) // No address book has been created
+       {
+               AddressBook *addressBook = new AddressBook();
+               addressBook->setId(0);
+               addressBook->setName("phone");
+               addressBook->setAccountId(0);
+               addressBook->setReadOnly(false);
+
+               insert(AddressBookPtr(addressBook), true);
+               LogDebug(" Inserted default address book");
+       }
+
+       contacts_svc_iter_remove(iter);
+}
+
+int ContactsSvcWrapper::size() const
+{
+       return m_idMap.size();
+}
+
+void ContactsSvcWrapper::insert(AddressBookPtr addressBook, bool setAsDefault)
+{
+       int index;
+       std::string id = addressBook->getId();
+
+       index = m_addressBooks->size();
+
+       m_idMap[id] = index;
+
+       m_addressBooks->push_back(addressBook);
+
+       if(m_defaultAddressBookIndex == -1 || setAsDefault)
+               m_defaultAddressBookIndex = index;
+}
+
+} // Contact
+} // Platform
+} // TizenApis
similarity index 83%
rename from src/platform/Tizen/Contact/AddressBookStorage.h
rename to src/platform/Tizen/Contact/ContactsSvcWrapper.h
index 4e7c91b..6942c8c 100755 (executable)
@@ -15,7 +15,7 @@
  */
 
 /**
- * @file        AddressBookStorage.h
+ * @file        ContactsSvcWrapper.h
  * @author      Kisub Song (kisubs.song@samsung.com)
  * @version     0.1
  * @brief
 #include <string>
 #include <map>
 #include <dpl/shared_ptr.h>
+#include <dpl/singleton.h>
 #include <API/Contact/IAddressBook.h>
 
 namespace TizenApis {
 namespace Platform {
 namespace Contact {
 
-class AddressBookStorage
+class ContactsSvcWrapper
 {
 public:
-       AddressBookStorage();
-       virtual ~AddressBookStorage();
+       ContactsSvcWrapper();
+       virtual ~ContactsSvcWrapper();
+
+       void init();
 
-       void insert(TizenApis::Api::Contact::AddressBookPtr addressBook, bool setAsDefault = false);
        TizenApis::Api::Contact::AddressBookPtr getAddressBook(const std::string &id);
        TizenApis::Api::Contact::AddressBookPtr getDefaultAddressBook() const;
        TizenApis::Api::Contact::AddressBookArrayPtr getAddressBooks() const;
 
 private:
+       void loadAddressBooks();
+       void insert(TizenApis::Api::Contact::AddressBookPtr addressBook, bool setAsDefault = false);
+       int size() const;
+
+private:
+       bool m_opened;
+
        TizenApis::Api::Contact::AddressBookArrayPtr m_addressBooks;
        std::map<std::string, int> m_idMap;
        int m_defaultAddressBookIndex;
 };
-typedef DPL::SharedPtr<AddressBookStorage> AddressBookStoragePtr;
+typedef DPL::Singleton<ContactsSvcWrapper> ContactsSvcWrapperSingleton;
 
 } // Contact
 } // Platform
index 28575b1..5756ca1 100755 (executable)
@@ -22,37 +22,15 @@ set(SRCS_PLATFORM_IMPLEMENTATION_CONTACT
   ${CURRENT_PATH}/ContactManager.cpp
   ${CURRENT_PATH}/AddressBook.cpp
   ${CURRENT_PATH}/Contact.cpp
-  ${CURRENT_PATH}/ContactWrapper.cpp
+  ${CURRENT_PATH}/ContactObjectA2PConverter.cpp
+  ${CURRENT_PATH}/ContactObjectP2AConverter.cpp
   ${CURRENT_PATH}/ContactSearchEngine.cpp
   ${CURRENT_PATH}/ContactFilterValidator.cpp
-  ${CURRENT_PATH}/AddressBookStorage.cpp
-  ${CURRENT_PATH}/DownloadManager.cpp
+  ${CURRENT_PATH}/ContactsSvcWrapper.cpp
+  ${CURRENT_PATH}/ContactListenerManager.cpp
+  ${CURRENT_PATH}/ContactUtility.cpp
+  ${CURRENT_PATH}/ContactDownloadManager.cpp
   ${CURRENT_PATH}/query-svc/query-svc.c
   ${CURRENT_PATH}/query-svc/query-utility.c
-#  ${CURRENT_PATH}/../../API/Filesystem/IManager.cpp
-#  ${CURRENT_PATH}/../../API/Filesystem/IPath.cpp
-#  ${CURRENT_PATH}/../../API/Filesystem/INode.cpp
-#  ${CURRENT_PATH}/../../API/Filesystem/IStream.cpp
-#  ${CURRENT_PATH}/../../API/Filesystem/EventCopy.cpp
-#  ${CURRENT_PATH}/../../API/Filesystem/EventFind.cpp
-#  ${CURRENT_PATH}/../../API/Filesystem/EventResolve.cpp
-#  ${CURRENT_PATH}/../../API/Filesystem/EventMove.cpp
-#  ${CURRENT_PATH}/../../API/Filesystem/EventRemove.cpp
-#  ${CURRENT_PATH}/../../API/Filesystem/EventOpen.cpp
-#  ${CURRENT_PATH}/../../API/Filesystem/EventListNodes.cpp
-#  ${CURRENT_PATH}/../../API/Filesystem/EventReadText.cpp
-#  ${CURRENT_PATH}/../../API/Filesystem/NodeFilter.cpp
-#  ${CURRENT_PATH}/../../API/Filesystem/PathUtils.cpp
-#  ${CURRENT_PATH}/../Filesystem/System.cpp
-#  ${CURRENT_PATH}/../Filesystem/Manager.cpp
-#  ${CURRENT_PATH}/../Filesystem/Utils.cpp
-#  ${CURRENT_PATH}/../Filesystem/Path.cpp
-#  ${CURRENT_PATH}/../Filesystem/Node.cpp
-#  ${CURRENT_PATH}/../Filesystem/Stream.cpp
-#  ${CURRENT_PATH}/../Filesystem/NodeFilterMatcher.cpp
-#  ${CURRENT_PATH}/../Filesystem/Command.cpp
-#  ${CURRENT_PATH}/../Filesystem/MoveCommand.cpp
-#  ${CURRENT_PATH}/../Filesystem/RemoveCommand.cpp
-#  ${CURRENT_PATH}/../Filesystem/CopyCommand.cpp
   PARENT_SCOPE
 )
index e2f1d5c..cd435b6 100755 (executable)
@@ -1305,7 +1305,7 @@ JSValueRef JSAddressBook::removeChangeListener(JSContextRef context,
                {
                case ExceptionCodes::InvalidArgumentException:
                case ExceptionCodes::NotFoundException:
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, "Contact not found");
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, "Watch id not found");
                        break;
                default:
                        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
index 55c01d4..d24b8aa 100755 (executable)
@@ -393,10 +393,11 @@ JSValueRef JSContact::getName(JSContextRef context,
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
                ContactPtr contact = getPrivData(object);
-               if(!contact->getNameIsSet())
+               ContactNamePtr contactName = contact->getName();
+               if(contactName == NULL)
                        return JSValueMakeNull(context);
                else
-                       return converter->toJSValueRef(contact->getName());
+                       return converter->toJSValueRef(contactName);
        }
        Catch(WrtDeviceApis::Commons::Exception)
        {
@@ -417,7 +418,12 @@ bool JSContact::setName(JSContextRef context,
                ContactPtr contact = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contact->setName(converter->toContactName(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contact->unsetName();
+               else
+                       contact->setName(converter->toContactName(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -525,7 +531,12 @@ bool JSContact::setPhotoURI(JSContextRef context,
                ContactPtr contact = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contact->setPhotoURI(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contact->unsetPhotoURI();
+               else
+                       contact->setPhotoURI(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -658,7 +669,12 @@ bool JSContact::setBirthday(JSContextRef context,
                ContactPtr contact = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contact->setBirthday(converter->toDateTm(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contact->unsetBirthday();
+               else
+                       contact->setBirthday(converter->toDateTm(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -724,10 +740,11 @@ JSValueRef JSContact::getOrganization(JSContextRef context,
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
                ContactPtr contact = getPrivData(object);
-               if(!contact->getOrganizationIsSet())
+               ContactOrganizationPtr contactOrganization = contact->getOrganization();
+               if(contactOrganization == NULL)
                        return JSValueMakeNull(context);
                else
-                       return converter->toJSValueRef(contact->getOrganization());
+                       return converter->toJSValueRef(contactOrganization);
        }
        Catch(WrtDeviceApis::Commons::Exception)
        {
@@ -846,7 +863,12 @@ bool JSContact::setNote(JSContextRef context,
                ContactPtr contact = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contact->setNote(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contact->unsetNote();
+               else
+                       contact->setNote(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -978,7 +1000,12 @@ bool JSContact::setRingtoneURI(JSContextRef context,
                ContactPtr contact = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contact->setRingtoneURI(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contact->unsetRingtoneURI();
+               else
+                       contact->setRingtoneURI(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
index 24870c1..17ece2d 100755 (executable)
@@ -267,7 +267,12 @@ bool JSContactAddress::setCountry(JSContextRef context,
                ContactAddressPtr contactAddress = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contactAddress->setCountry(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactAddress->unsetCountry();
+               else
+                       contactAddress->setCountry(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -312,7 +317,12 @@ bool JSContactAddress::setRegion(JSContextRef context,
                ContactAddressPtr contactAddress = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contactAddress->setRegion(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactAddress->unsetRegion();
+               else
+                       contactAddress->setRegion(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -356,7 +366,12 @@ bool JSContactAddress::setCity(JSContextRef context,
                ContactAddressPtr contactAddress = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contactAddress->setCity(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactAddress->unsetCity();
+               else
+                       contactAddress->setCity(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -401,7 +416,12 @@ bool JSContactAddress::setStreetAddress(JSContextRef context,
                ContactAddressPtr contactAddress = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contactAddress->setStreetAddress(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactAddress->unsetStreetAddress();
+               else
+                       contactAddress->setStreetAddress(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -446,7 +466,12 @@ bool JSContactAddress::setAdditionalInformation(JSContextRef context,
                ContactAddressPtr contactAddress = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contactAddress->setAdditionalInformation(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactAddress->unsetAdditionalInformation();
+               else
+                       contactAddress->setAdditionalInformation(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -491,7 +516,12 @@ bool JSContactAddress::setPostalCode(JSContextRef context,
                ContactAddressPtr contactAddress = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contactAddress->setPostalCode(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactAddress->unsetPostalCode();
+               else
+                       contactAddress->setPostalCode(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
index a7c328f..5d4931d 100755 (executable)
@@ -308,11 +308,15 @@ bool JSContactAnniversary::setLabel(JSContextRef context,
 {
        Try
        {
-               // NOTE: Currently not support this field
-               //ContactAnniversaryPtr anniversary = getPrivData(object);
-               //ContactConverterFactory::ConverterType converter =
-               //              ContactConverterFactory::getConverter(context);
-               //anniversary->setLabel(converter->toString(value));
+               ContactAnniversaryPtr anniversary = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       anniversary->unsetLabel();
+               else
+                       anniversary->setLabel(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
index e584236..d19a5c8 100755 (executable)
@@ -39,9 +39,6 @@
 #include "ContactConverter.h"
 #include "JSContactManager.h"
 
-#define TIZEN_CONTACT_MANAGER_DEVICE_ADDRESS_BOOK      "DEVICE_ADDRESS_BOOK"
-#define TIZEN_CONTACT_MANAGER_PHONE_ADDRESS_BOOK       "PHONE_ADDRESS_BOOK"
-
 namespace TizenApis {
 namespace Tizen1_0 {
 namespace Contact {
@@ -78,8 +75,6 @@ const JSClassDefinition* JSContactManager::getClassInfo()
 }
 
 JSStaticValue JSContactManager::m_property[] = {
-       //{ TIZEN_CONTACT_MANAGER_DEVICE_ADDRESS_BOOK, getConstProperty, NULL, kJSPropertyAttributeReadOnly },
-       //{ TIZEN_CONTACT_MANAGER_PHONE_ADDRESS_BOOK, getConstProperty, NULL, kJSPropertyAttributeReadOnly },
        { 0, 0, 0, 0 }
 };
 
@@ -119,27 +114,6 @@ void JSContactManager::Finalize(JSObjectRef object)
        delete priv;
 }
 
-JSValueRef JSContactManager::getConstProperty(JSContextRef context,
-               JSObjectRef object,
-               JSStringRef jsPropertyName,
-               JSValueRef* exception)
-{
-       LogDebug("Entered");
-       BasicConverter converter = BasicConverterFactory::getConverter(context);
-
-       Try {
-               std::string propertyName = converter->toString(jsPropertyName);
-               if (propertyName == TIZEN_CONTACT_MANAGER_DEVICE_ADDRESS_BOOK) {
-                       return converter->toJSValueRef(DEVICE_ADDRESS_BOOK);
-               } else if (propertyName == TIZEN_CONTACT_MANAGER_PHONE_ADDRESS_BOOK) {
-                       return converter->toJSValueRef(PHONE_ADDRESS_BOOK);
-               }
-       } Catch(Exception) {
-               LogError("error during getting property");
-       }
-       return JSValueMakeUndefined(context);
-}
-
 JSValueRef JSContactManager::getAddressBooks(JSContextRef context,
                JSObjectRef object,
                JSObjectRef thisObject,
index 95a34d6..e03f2c9 100755 (executable)
@@ -55,14 +55,6 @@ private:
        static void Finalize(JSObjectRef object);
 
        /**
-        * Getter for const properties
-        */
-       static JSValueRef getConstProperty(JSContextRef context,
-                       JSObjectRef object,
-                       JSStringRef jsPropertyName,
-                       JSValueRef* exception);
-
-       /**
         * Get Address Books.
         */
        static JSValueRef getAddressBooks(JSContextRef context,
index 0e223e0..8cf2c23 100755 (executable)
@@ -277,7 +277,12 @@ bool JSContactName::setPrefix(JSContextRef context,
                ContactNamePtr contactName = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contactName->setPrefix(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactName->unsetPrefix();
+               else
+                       contactName->setPrefix(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -323,7 +328,12 @@ bool JSContactName::setFirstName(JSContextRef context,
                ContactNamePtr contactName = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contactName->setFirstName(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactName->unsetFirstName();
+               else
+                       contactName->setFirstName(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -369,7 +379,12 @@ bool JSContactName::setMiddleName(JSContextRef context,
                ContactNamePtr contactName = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contactName->setMiddleName(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactName->unsetMiddleName();
+               else
+                       contactName->setMiddleName(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -415,7 +430,12 @@ bool JSContactName::setLastName(JSContextRef context,
                ContactNamePtr contactName = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contactName->setLastName(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactName->unsetLastName();
+               else
+                       contactName->setLastName(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -475,23 +495,8 @@ JSValueRef JSContactName::getPhoneticName(JSContextRef context,
                JSStringRef propertyName,
                JSValueRef* exception)
 {
-       // Deprecated field. Supporting for low level compatibility.
-       Try
-       {
-               ContactConverterFactory::ConverterType converter =
-                               ContactConverterFactory::getConverter(context);
-               ContactNamePtr contactName = getPrivData(object);
-               if(!contactName->getPhoneticFirstNameIsSet())
-                       return JSValueMakeNull(context);
-               else
-                       return converter->toJSValueRef(contactName->getPhoneticFirstName());
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("trying to get incorrect value");
-       }
-
-       return JSValueMakeUndefined(context);
+       // NOTE: Deprecated field.
+       return JSValueMakeNull(context);
 }
 
 bool JSContactName::setPhoneticName(JSContextRef context,
@@ -500,22 +505,8 @@ bool JSContactName::setPhoneticName(JSContextRef context,
                JSValueRef value,
                JSValueRef* exception)
 {
-       // Deprecated field. Supporting for low level compatibility.
-       Try
-       {
-               ContactNamePtr contactName = getPrivData(object);
-               ContactConverterFactory::ConverterType converter =
-                               ContactConverterFactory::getConverter(context);
-               contactName->setPhoneticFirstName(converter->toString(value));
-               return true;
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("trying to set incorrect value");
-       }
-
-       JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
-       return false;
+       // NOTE: Deprecated field.
+       return true;
 }
 
 JSValueRef JSContactName::getPhoneticFirstName(JSContextRef context,
@@ -552,7 +543,12 @@ bool JSContactName::setPhoneticFirstName(JSContextRef context,
                ContactNamePtr contactName = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contactName->setPhoneticFirstName(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactName->unsetPhoneticFirstName();
+               else
+                       contactName->setPhoneticFirstName(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -598,7 +594,12 @@ bool JSContactName::setPhoneticLastName(JSContextRef context,
                ContactNamePtr contactName = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               contactName->setPhoneticLastName(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactName->unsetPhoneticLastName();
+               else
+                       contactName->setPhoneticLastName(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
index 822bd1a..f7dc0ab 100755 (executable)
@@ -263,7 +263,12 @@ bool JSContactOrganization::setName(JSContextRef context,
                ContactOrganizationPtr organization = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               organization->setName(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       organization->unsetName();
+               else
+                       organization->setName(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -308,7 +313,12 @@ bool JSContactOrganization::setDepartment(JSContextRef context,
                ContactOrganizationPtr organization = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               organization->setDepartment(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       organization->unsetDepartment();
+               else
+                       organization->setDepartment(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -371,7 +381,12 @@ bool JSContactOrganization::setTitle(JSContextRef context,
                ContactOrganizationPtr organization = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               organization->setTitle(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       organization->unsetTitle();
+               else
+                       organization->setTitle(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -415,7 +430,12 @@ bool JSContactOrganization::setRole(JSContextRef context,
                ContactOrganizationPtr organization = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               organization->setRole(converter->toString(value));
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       organization->unsetRole();
+               else
+                       organization->setRole(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
@@ -457,10 +477,15 @@ bool JSContactOrganization::setLogoURI(JSContextRef context,
        Try
        {
                // NOTE: Currently not support this field
-               //ContactOrganizationPtr organization = getPrivData(object);
-               //ContactConverterFactory::ConverterType converter =
-               //              ContactConverterFactory::getConverter(context);
-               //organization->setLogoURI(converter->toString(value));
+//             ContactOrganizationPtr organization = getPrivData(object);
+//             ContactConverterFactory::ConverterType converter =
+//                             ContactConverterFactory::getConverter(context);
+//             BasicValidator validator =
+//                             BasicValidatorFactory::getValidator(context, exception);
+//             if(validator->isNullOrUndefined(value))
+//                     organization->unsetLogoURI();
+//             else
+//                     organization->setLogoURI(converter->toString(value));
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)
index 45061e1..7263db8 100755 (executable)
@@ -308,8 +308,15 @@ bool JSContactWebSite::setType(JSContextRef context,
                ContactWebSitePtr webSite = getPrivData(object);
                ContactConverterFactory::ConverterType converter =
                                ContactConverterFactory::getConverter(context);
-               ContactWebSiteType type = converter->toContactWebSiteType(converter->toString(value));
-               webSite->setType(type);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       webSite->unsetType();
+               else
+               {
+                       ContactWebSiteType type = converter->toContactWebSiteType(converter->toString(value));
+                       webSite->setType(type);
+               }
                return true;
        }
        Catch(WrtDeviceApis::Commons::Exception)