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 AND (A.CONV_ID = B.CONV_ID) AND (B.CONV_ID = C.CONV_ID) AND (";
29 const std::string ConversationQueryGenerator::QUERY_PREFIX_MMS = "WHERE B.MMS_CNT > 0 AND (A.CONV_ID = B.CONV_ID) AND (B.CONV_ID = C.CONV_ID) 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 = "C.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, "B.CONV_ID"));
60 if(getMode() == MODE_SMS)
63 std::pair<std::string, std::string>(
64 ConversationFilterValidatorFactory::ATTRIBUTE_TYPE, "B.SMS_CNT"));
68 std::pair<std::string, std::string>(
69 ConversationFilterValidatorFactory::ATTRIBUTE_TYPE, "B.MMS_CNT"));
72 std::pair<std::string, std::string>(
73 ConversationFilterValidatorFactory::ATTRIBUTE_TIMESTAMP, "B.DISPLAY_TIME"));
75 std::pair<std::string, std::string>(
76 ConversationFilterValidatorFactory::ATTRIBUTE_FROM, "A.ADDRESS_VAL"));
78 std::pair<std::string, std::string>(
79 ConversationFilterValidatorFactory::ATTRIBUTE_TO, "A.ADDRESS_VAL"));
81 std::pair<std::string, std::string>(
82 ConversationFilterValidatorFactory::ATTRIBUTE_PREVIEW, "B.MSG_TEXT"));
84 std::pair<std::string, std::string>(
85 ConversationFilterValidatorFactory::ATTRIBUTE_MESSAGE_COUNT, "B.SMS_CNT+B.MMS_CNT"));
87 std::pair<std::string, std::string>(
88 ConversationFilterValidatorFactory::ATTRIBUTE_UNREAD_MESSAGES, "B.UNREAD_CNT"));
93 std::string ConversationQueryGenerator::getMatchExactlyClause(std::string& attrName, DeviceAPI::Tizen::AnyPtr& value){
94 std::string retClause;
95 std::string emfAttributeName = convertToEmfAttrName(attrName);
97 if(getMode() == MODE_SMS || getMode() == MODE_MMS){
98 if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_MESSAGE_COUNT)==0){
99 retClause = emfAttributeName + "=" + value->toString();
101 }else if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_TYPE)==0){
102 retClause = emfAttributeName + " > 0";
103 LoggerD(">retClause>> " << retClause);
105 }else if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_PREVIEW)==0){
106 retClause = emfAttributeName + " LIKE '" + value->toString() + "'";
111 retClause = MessageQueryGenerator::getMatchExactlyClause(attrName, value);
115 std::string ConversationQueryGenerator::getMatchExistsClause(std::string& attrName){
116 std::string retClause;
117 std::string emfAttributeName = convertToEmfAttrName(attrName);
119 if(getMode() == MODE_SMS || getMode() == MODE_MMS){
120 if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_MESSAGE_COUNT)==0){
121 retClause = emfAttributeName + " IS NOT NULL ";
123 }else if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_PREVIEW)==0){
124 retClause = emfAttributeName + " NOT LIKE '' ";
129 retClause = MessageQueryGenerator::getMatchExistsClause(attrName);
134 std::string ConversationQueryGenerator::getQueryPrefix(){
135 if(getMode() == MODE_EMAIL){
136 return ConversationQueryGenerator::QUERY_PREFIX_EMAIL;
137 }else if(getMode() == MODE_SMS){
138 return ConversationQueryGenerator::QUERY_PREFIX_SMS;
139 }else if(getMode() == MODE_MMS){
140 return ConversationQueryGenerator::QUERY_PREFIX_MMS;
142 MsgLoggerE("invalid mode:" << getMode());
143 Throw(WrtDeviceApis::Commons::UnknownException);
147 std::string ConversationQueryGenerator::getQuerySuffix(){
148 if(getMode() == MODE_EMAIL){
149 return ConversationQueryGenerator::QUERY_SUFFIX_EMAIL;
150 }else if(getMode() == MODE_SMS || getMode() == MODE_MMS){
151 return ConversationQueryGenerator::QUERY_SUFFIX_SMS_MMS;
153 MsgLoggerE("invalid mode:" << getMode());
154 Throw(WrtDeviceApis::Commons::UnknownException);
158 std::string ConversationQueryGenerator::getMessageDirectionString(){
159 return ConversationQueryGenerator::STRING_DIRECTION;