Update change log and spec for wrt-plugins-tizen_0.4.50
[framework/web/wrt-plugins-tizen.git] / src / Contact / ContactSearchEngine.cpp
index 73d520a..0ff9fa1 100755 (executable)
@@ -285,19 +285,24 @@ void ContactSearchEngine::visitPostComposite(FilterType& type, int depth)
 
 void ContactSearchEngine::visitAttribute(string& attrName, MatchFlag& matchFlag, AnyPtr& matchValue, int depth)
 {
+       if(matchValue == NULL || matchValue->isNullOrUndefined())
+               matchFlag = MATCH_EXISTS;
+
        ContactIdSetPtr idSet = ContactIdSetPtr(new ContactIdSet());
 
        if(attrName == "id")
        {
-               string value = matchValue->getString();
-               idSet->insert(ContactUtility::strToInt(value));
+               if(matchFlag != MATCH_EXISTS){
+                       string value = matchValue->getString();
+                       idSet->insert(ContactUtility::strToInt(value));
 
-               if(depth == 0)
-                       m_filteredContactIds = idSet;
-               else
-               {
-                       ContactIdSetArrayPtr parentIdSets = m_contactIdSetArrayStack.top();
-                       parentIdSets->push_back(idSet);
+                       if(depth == 0)
+                               m_filteredContactIds = idSet;
+                       else
+                       {
+                               ContactIdSetArrayPtr parentIdSets = m_contactIdSetArrayStack.top();
+                               parentIdSets->push_back(idSet);
+                       }
                }
 
                return;
@@ -321,16 +326,24 @@ void ContactSearchEngine::visitAttribute(string& attrName, MatchFlag& matchFlag,
 
        if(properties.type == ContactSvcPrimitiveType_Boolean)
        {
-               bool value = matchValue->getBool();
+               bool value = true;
+               if(matchFlag != MATCH_EXISTS)
+                       value = matchValue->getBool();
+
                queryAttributeBool(properties, idSet, value);
        }
        else if(properties.type == ContactSvcPrimitiveType_String)
        {
                string value;
-               if(attrName == "photoURI" || attrName == "ringtoneURI" || attrName == "organizations.logoURI")
-                       value = ContactUtility::convertUriToPath(matchValue->getString());
-               else
-                       value = matchValue->getString();
+
+               if(matchFlag != MATCH_EXISTS)
+               {
+                       if(attrName == "photoURI" || attrName == "ringtoneURI" || attrName == "organizations.logoURI")
+                               value = ContactUtility::convertUriToPath(matchValue->getString());
+                       else
+                               value = matchValue->getString();
+               }else
+                       value = "";
 
                contacts_match_str_flag_e flag = CONTACTS_MATCH_EXISTS;
 
@@ -353,15 +366,18 @@ void ContactSearchEngine::visitAttribute(string& attrName, MatchFlag& matchFlag,
        {
                int value;
 
-               if(attrName == "id" || attrName == "personId"){
-                       value = ContactUtility::strToInt(matchValue->getString());
-               }else if(attrName == "lastUpdated"){
-                       time_t tmpTime = mktime(matchValue->getDateTm());
-                       value = (int)tmpTime;
-               }else if(attrName == "birthday" || attrName == "anniversaries.date"){
-                       value = ContactUtility::toDateDbInt(*matchValue->getDateTm());
-               }else{
-                       value = matchValue->getLong();
+               if(matchFlag != MATCH_EXISTS)
+               {
+                       if(attrName == "id" || attrName == "personId"){
+                               value = ContactUtility::strToInt(matchValue->getString());
+                       }else if(attrName == "lastUpdated"){
+                               time_t tmpTime = mktime(matchValue->getDateTm());
+                               value = (int)tmpTime;
+                       }else if(attrName == "birthday" || attrName == "anniversaries.date"){
+                               value = ContactUtility::toDateDbInt(*matchValue->getDateTm());
+                       }else{
+                               value = matchValue->getLong();
+                       }
                }
 
                contacts_match_int_flag_e flag;
@@ -377,7 +393,12 @@ void ContactSearchEngine::visitAttribute(string& attrName, MatchFlag& matchFlag,
                        flag = CONTACTS_MATCH_EQUAL;
                }
 
-               queryAttributeInt(properties, idSet, flag, value);
+               if(attrName == "birthday" || attrName == "anniversaries.date"){
+                       queryAttributeDate(attrName, properties, idSet, flag, value);
+               }else{
+                       queryAttributeInt(properties, idSet, flag, value);
+               }
+
        }
 
        if(depth == 0)
@@ -780,6 +801,48 @@ void ContactSearchEngine::queryAttributeInt(AttributeProperties& attributeProper
        _CONTACTS_SVC_QUERY_FUNC_SUFFIX(query, filter, list, property_contact_id, result);
 }
 
+void ContactSearchEngine::queryAttributeDate(string& attrName, AttributeProperties& attributeProperties, ContactIdSetPtr& result,
+               contacts_match_int_flag_e match, int match_value)
+{
+       const char* view_uri = attributeProperties.viewUri;
+       unsigned int property_contact_id = attributeProperties.propertyContactId;
+       unsigned int property_id = attributeProperties.propertyId;
+
+       int errorCode = 0;
+       contacts_query_h query = NULL;
+       contacts_filter_h filter = NULL;
+       contacts_list_h list = NULL;
+
+       _CONTACTS_SVC_QUERY_FUNC_PREFIX(view_uri, query, filter);
+
+       errorCode = contacts_filter_add_int(filter, property_id, match, match_value);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "contacts_filter_add_int error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+       LoggerD("attrName" << attrName);
+
+       if(attrName == "birthday"){
+               errorCode = contacts_filter_add_operator( filter, CONTACTS_FILTER_OPERATOR_AND);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "contacts_filter_add_int error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+               errorCode = contacts_filter_add_int(filter, _contacts_event.type, CONTACTS_MATCH_EQUAL, CONTACTS_EVENT_TYPE_BIRTH);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "contacts_filter_add_int error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+       }else if(attrName == "anniversaries.date"){
+               errorCode = contacts_filter_add_operator( filter, CONTACTS_FILTER_OPERATOR_AND);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "contacts_filter_add_int error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+               errorCode = contacts_filter_add_int(filter, _contacts_event.type, CONTACTS_MATCH_EQUAL, CONTACTS_EVENT_TYPE_ANNIVERSARY);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "contacts_filter_add_int error : " << errorCode << " (" << __FUNCTION__ << ")");
+       }
+
+       _CONTACTS_SVC_QUERY_FUNC_SUFFIX(query, filter, list, property_contact_id, result);
+}
+
 void ContactSearchEngine::queryAttributeString(AttributeProperties& attributeProperties, ContactIdSetPtr& result,
                contacts_match_str_flag_e match, const char* match_value)
 {