#include <iomanip>
#include <Commons/Exception.h>
+#include "Contact.h"
#include "ContactSearchEngine.h"
namespace TizenApis {
using namespace WrtDeviceApis::Commons;
using namespace std;
-using TizenApis::Api::Contact::Contact;
-
map<string, int> ContactSearchEngine::attrEnumMap = {
{"id", contact_attribute_e::CONTACT_ID},
{"readOnly", contact_attribute_e::ATTRIBUTE_MAX},
filter->travel(filterQuery);
}
+void ContactSearchEngine::setCondition(string contactId)
+{
+ if(contactId == "")
+ ThrowMsg(InvalidArgumentException, "contactId id empty.");
+
+ query_set_condition(m_contact_query_service, getPlatformAttr("id"), EQUAL, contactId.c_str());
+}
+
void ContactSearchEngine::setSortMode(SortModePtr attr)
{
if(attr)
str = query_get_attribute(m_contact_query_service, ACCOUNT_ID, &err);
if( str )
- contact->getAccount()->setAccountId(str);
+ contact->getAccount()->setAccountServiceId(str);
str = query_get_attribute(m_contact_query_service, CONTACT_IS_FAVORITE, &err);
if( str )
str = query_get_attribute(m_contact_query_service, CONTACT_RINGTONE, &err);
if( str )
- contact->setRingtoneURI(str);
+ contact->setRingtoneURI(std::string("file://") + str);
str = query_get_attribute(m_contact_query_service, CONTACT_NOTE, &err);
if( str )
str = query_get_attribute(m_contact_query_service, CONTACT_PHOTO_URI, &err);
if( str )
- contact->setPhotoURI(str);
+ contact->setPhotoURI(std::string("file://") + str);
str = query_get_attribute(m_contact_query_service, CONTACT_LAST_UPDATED_TIME_STAMP, &err);
if( str )
contact->setLastUpdated(time_stamp);
}
- ContactNamePtr contactName = contact->getName();
-
- str = query_get_attribute(m_contact_query_service, NAME_FIRST, &err);
- if( str )
- contactName->setFirstName(str);
-
- str = query_get_attribute(m_contact_query_service, NAME_LAST, &err);
- if( str )
- contactName->setLastName(str);
-
- str = query_get_attribute(m_contact_query_service, NAME_MIDDLE, &err);
- if( str )
- contactName->setMiddleName(str);
-
- str = query_get_attribute(m_contact_query_service, NAME_DISPLAY, &err);
- if( str )
- contactName->setDisplayName(str);
-
- str = query_get_attribute(m_contact_query_service, NAME_PREFIX, &err);
- if( str )
- contactName->setPrefix(str);
+ char *firstName = query_get_attribute(m_contact_query_service, NAME_FIRST, &err);
+ char *lastName = query_get_attribute(m_contact_query_service, NAME_LAST, &err);
+ char *middleName = query_get_attribute(m_contact_query_service, NAME_MIDDLE, &err);
+ char *displayName = query_get_attribute(m_contact_query_service, NAME_DISPLAY, &err);
+ char *prefix = query_get_attribute(m_contact_query_service, NAME_PREFIX, &err);
+ char *phoneticName = query_get_attribute(m_contact_query_service, NAME_PHONETIC, &err);
- str = query_get_attribute(m_contact_query_service, NAME_PHONETIC, &err);
- if( str )
- contactName->setPhoneticName(str);
+ setName(contact, prefix, firstName, middleName, lastName, phoneticName, displayName);
nameAlreadyChecked = true;
}
}
else if (!nicknameAlreadyChecked && (pattr == NICKNAME_NAME))
{
+ ContactNamePtr contactName(NULL);
+
+ if(!contact->getNameIsSet())
+ contactName = ContactNamePtr(new ContactName());
+ else
+ contactName = contact->getName();
+
do
{
char *nickname = query_get_attribute(m_contact_query_service, NICKNAME_NAME, &err);
if(nickname)
- contact->getName()->addNickname(string(nickname));
+ contactName->addNickname(string(nickname));
} while ( fetch_next_row(m_contact_query_service) == QUERY_SUCCESS );
+ if(!contact->getNameIsSet())
+ contact->setName(contactName);
+
nicknameAlreadyChecked = true;
}
else if (!categoryAlreadyChecked && (pattr == CATEGORY_INFO))
query_set_condition_append(m_contact_query_service, RIGHT_BRACKET);
}
-void ContactSearchEngine::visitAttribute(string& attrName, AnyArrayPtr& matchValues, string& matchFlag, bool caseSensitive, int depth)
+void ContactSearchEngine::visitAttribute(string& attrName, MatchFlag& matchFlag, AnyPtr& matchValue, int depth)
{
+ if(matchValue == NULL)
+ return;
+
contact_attribute_e attr;
attr = getPlatformAttr(attrName);
string matchValueStr;
- if(matchFlag == "EXISTS")
+ if(matchFlag == MATCH_EXISTS)
{
query_set_condition(m_contact_query_service, attr, EXISTS, NULL);
}
- else if(attrName == "id" && (matchFlag == "" || matchFlag == "EXACTLY"))
- {
- visitAttributeID(matchValues);
- }
- else if(matchValues->size() == 1)
+ else
{
condition_e cond;
- if(matchFlag == "EXACTLY")
+ if(matchFlag == MATCH_EXACTLY)
cond = EQUAL;
- else if (matchFlag == "STARTSWITH" || matchFlag == "ENDSWITH")
+ else if (matchFlag == MATCH_STARTSWITH || matchFlag == MATCH_ENDSWITH)
cond = LIKE;
else
cond = EQUAL;
- AnyPtr matchValue = matchValues->at(0);
-
visitAttributeEach(attr, matchValue, cond);
}
- else if(matchValues->size() > 1)
- {
- condition_e cond;
- if(matchFlag == "EXACTLY")
- cond = EQUAL;
- else if (matchFlag == "STARTSWITH" || matchFlag == "ENDSWITH")
- cond = LIKE;
- else
- cond = EQUAL;
-
- query_set_condition_append(m_contact_query_service, LEFT_BRACKET);
-
- AnyArray::iterator iter;
- for(iter = matchValues->begin(); iter != matchValues->end(); iter++)
- {
- AnyPtr matchValue = *iter;
- if(iter != matchValues->begin())
- query_set_condition_append(m_contact_query_service, OR);
-
- visitAttributeEach(attr, matchValue, cond);
- }
-
- query_set_condition_append(m_contact_query_service, RIGHT_BRACKET);
- }
}
void ContactSearchEngine::visitAttributeRange(string& attrName, AnyPtr& initialValue, AnyPtr& endValue, int depth)
{
+ if(initialValue == NULL || endValue == NULL)
+ return;
+
contact_attribute_e attr;
string initialValueStr;
string endValueStr;
- if(initialValue->getType() == PrimitiveType_Time)
+ if(initialValue->isType(PrimitiveType_Time))
{
- tm date = DPL::DynamicPointerCast< Any_T<tm> >(initialValue)->getValue();
+ tm date = initialValue->getDateTm();
initialValueStr = toDateDbStr(date);
}
else
initialValueStr = initialValue->toString();
}
- if(endValue->getType() == PrimitiveType_Time)
+ if(endValue->isType(PrimitiveType_Time))
{
- tm date = DPL::DynamicPointerCast< Any_T<tm> >(endValue)->getValue();
+ tm date = endValue->getDateTm();
endValueStr = toDateDbStr(date);
}
else
void ContactSearchEngine::visitAttributeEach(contact_attribute_e attr, AnyPtr& matchValue, condition_e flag)
{
string valueStr;
- if(matchValue->getType() == PrimitiveType_Time)
+ if(matchValue->isType(PrimitiveType_Time))
{
- tm date = DPL::DynamicPointerCast< Any_T<tm> >(matchValue)->getValue();
+ tm date = matchValue->getDateTm();
valueStr = toDateDbStr(date);
}
else
}
#endif
+void ContactSearchEngine::setName(ContactPtr& contact,
+ char *prefix, char *firstName, char *middleName,
+ char *lastName, char *phoneticName, char *displayName)
+{
+ if(prefix == NULL && firstName == NULL && middleName == NULL
+ && lastName == NULL && phoneticName == NULL && displayName == NULL)
+ return;
+
+ ContactNamePtr contactName(NULL);
+
+ if(!contact->getNameIsSet())
+ contactName = ContactNamePtr(new ContactName);
+ else
+ contactName = contact->getName();
+
+ if( prefix )
+ contactName->setFirstName(prefix);
+
+ if( firstName )
+ contactName->setLastName(firstName);
+
+ if( middleName )
+ contactName->setMiddleName(middleName);
+
+ if( lastName )
+ contactName->setDisplayName(lastName);
+
+ if( phoneticName )
+ contactName->setPrefix(phoneticName);
+
+ if( phoneticName )
+ contactName->setPhoneticName(phoneticName);
+
+ if(!contact->getNameIsSet())
+ contact->setName(contactName);
+}
+
void ContactSearchEngine::setPhoneNumber(ContactPtr& contact, char *number, char *type)
{
if(number == NULL)
tokenize(type,tokens, ",");
for (unsigned int i=0; i<tokens.size(); i++)
- numberType->addType(tokens[i]);
+ {
+ if (tokens[i].compare("WORK") == 0)
+ numberType->addType(CONTACT_PHONE_NUMBER_TYPE_WORK);
+ else if (tokens[i].compare("PREF"))
+ numberType->addType(CONTACT_PHONE_NUMBER_TYPE_PREF);
+ else if (tokens[i].compare("HOME"))
+ numberType->addType(CONTACT_PHONE_NUMBER_TYPE_HOME);
+ else if (tokens[i].compare("VOICE"))
+ numberType->addType(CONTACT_PHONE_NUMBER_TYPE_VOICE);
+ else if (tokens[i].compare("FAX"))
+ numberType->addType(CONTACT_PHONE_NUMBER_TYPE_FAX);
+ else if (tokens[i].compare("MSG"))
+ numberType->addType(CONTACT_PHONE_NUMBER_TYPE_MSG);
+ else if (tokens[i].compare("CELL"))
+ numberType->addType(CONTACT_PHONE_NUMBER_TYPE_CELL);
+ else if (tokens[i].compare("PAGER"))
+ numberType->addType(CONTACT_PHONE_NUMBER_TYPE_PAGER);
+ else if (tokens[i].compare("BBS"))
+ numberType->addType(CONTACT_PHONE_NUMBER_TYPE_BBS);
+ else if (tokens[i].compare("MODEM"))
+ numberType->addType(CONTACT_PHONE_NUMBER_TYPE_MODEM);
+ else if (tokens[i].compare("CAR"))
+ numberType->addType(CONTACT_PHONE_NUMBER_TYPE_CAR);
+ else if (tokens[i].compare("IDSN"))
+ numberType->addType(CONTACT_PHONE_NUMBER_TYPE_ISDN);
+ else if (tokens[i].compare("VIDEO"))
+ numberType->addType(CONTACT_PHONE_NUMBER_TYPE_VIDEO);
+ else if (tokens[i].compare("PCS"))
+ numberType->addType(CONTACT_PHONE_NUMBER_TYPE_PCS);
+ }
}
contact->addPhoneNumber(numberType);
void ContactSearchEngine::setOrganization(ContactPtr& contact,
char* org_name, char* org_dept, char* org_title, char* org_role)
{
+ if(org_name == NULL && org_dept == NULL && org_title == NULL && org_role == NULL)
+ return;
+
ContactOrganizationPtr org = ContactOrganizationPtr(new ContactOrganization());
if(org_name)