2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include "ConversationQueryGenerator.h"
19 #include "ConversationFilterValidatorFactory.h"
21 #include <Commons/Exception.h>
28 const std::string ConversationQueryGenerator::QUERY_PREFIX_SMS = "WHERE (B.SMS_CNT > 0 OR B.MMS_CNT > 0) AND A.CONV_ID = B.CONV_ID AND (B.MAIN_TYPE=1) AND (";
29 const std::string ConversationQueryGenerator::QUERY_PREFIX_MMS = "WHERE (B.SMS_CNT > 0 OR B.MMS_CNT > 0 ) AND A.CONV_ID = B.CONV_ID AND (B.MAIN_TYPE=2) AND (";
30 const std::string ConversationQueryGenerator::QUERY_PREFIX_EMAIL = "WHERE ";
31 const std::string ConversationQueryGenerator::QUERY_SUFFIX_SMS_MMS = ") ";
32 const std::string ConversationQueryGenerator::QUERY_SUFFIX_EMAIL = "";
34 const std::string ConversationQueryGenerator::STRING_DIRECTION = "B.MSG_DIRECTION";
36 ConversationQueryGenerator::ConversationQueryGenerator():MessageQueryGenerator() {
39 ConversationQueryGenerator::ConversationQueryGenerator(const DeviceAPI::Tizen::SortModePtr& sortMode,
40 const long limit, const long offset):MessageQueryGenerator(sortMode, limit, offset){
44 ConversationQueryGenerator::ConversationQueryGenerator(const DeviceAPI::Tizen::SortModePtr& sortMode,
45 const long limit, const long offset, const int type):MessageQueryGenerator(sortMode, limit, offset, type){
50 ConversationQueryGenerator::~ConversationQueryGenerator() {
53 void ConversationQueryGenerator::setSmsMmsAttributeMap(){
58 std::pair<std::string, std::string>(
59 ConversationFilterValidatorFactory::ATTRIBUTE_ID, "A.ADDRESS_ID"));
61 std::pair<std::string, std::string>(
62 ConversationFilterValidatorFactory::ATTRIBUTE_TYPE, "B.MAIN_TYPE"));
64 std::pair<std::string, std::string>(
65 ConversationFilterValidatorFactory::ATTRIBUTE_TIMESTAMP, "B.DISPLAY_TIME"));
67 std::pair<std::string, std::string>(
68 ConversationFilterValidatorFactory::ATTRIBUTE_FROM, "A.ADDRESS_VAL"));
70 std::pair<std::string, std::string>(
71 ConversationFilterValidatorFactory::ATTRIBUTE_TO, "A.ADDRESS_VAL"));
73 std::pair<std::string, std::string>(
74 ConversationFilterValidatorFactory::ATTRIBUTE_PREVIEW, "B.MSG_TEXT"));
76 std::pair<std::string, std::string>(
77 ConversationFilterValidatorFactory::ATTRIBUTE_MESSAGE_COUNT, "B.SMS_CNT+B.MMS_CNT"));
79 std::pair<std::string, std::string>(
80 ConversationFilterValidatorFactory::ATTRIBUTE_UNREAD_MESSAGES, "B.UNREAD_CNT"));
85 std::string ConversationQueryGenerator::getMatchExactlyClause(std::string& attrName, DeviceAPI::Tizen::AnyPtr& value){
86 std::string retClause;
87 std::string emfAttributeName = convertToEmfAttrName(attrName);
89 if(getMode() == MODE_SMS || getMode() == MODE_MMS){
90 if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_MESSAGE_COUNT)==0){
91 retClause = emfAttributeName + "=" + value->toString();
93 }else if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_PREVIEW)==0){
94 retClause = emfAttributeName + " LIKE '" + value->toString() + "'";
99 retClause = MessageQueryGenerator::getMatchExactlyClause(attrName, value);
103 std::string ConversationQueryGenerator::getQueryPrefix(){
104 if(getMode() == MODE_EMAIL){
105 return ConversationQueryGenerator::QUERY_PREFIX_EMAIL;
106 }else if(getMode() == MODE_SMS){
107 return ConversationQueryGenerator::QUERY_PREFIX_SMS;
108 }else if(getMode() == MODE_MMS){
109 return ConversationQueryGenerator::QUERY_PREFIX_MMS;
111 MsgLoggerE("invalid mode:" << getMode());
112 Throw(WrtDeviceApis::Commons::UnknownException);
116 std::string ConversationQueryGenerator::getQuerySuffix(){
117 if(getMode() == MODE_EMAIL){
118 return ConversationQueryGenerator::QUERY_SUFFIX_EMAIL;
119 }else if(getMode() == MODE_SMS || getMode() == MODE_MMS){
120 return ConversationQueryGenerator::QUERY_SUFFIX_SMS_MMS;
122 MsgLoggerE("invalid mode:" << getMode());
123 Throw(WrtDeviceApis::Commons::UnknownException);
127 std::string ConversationQueryGenerator::getMessageDirectionString(){
128 return ConversationQueryGenerator::STRING_DIRECTION;