Update change log and spec for wrt-plugins-tizen_0.4.70
[framework/web/wrt-plugins-tizen.git] / src / Messaging / ConversationQueryGenerator.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 #include "ConversationQueryGenerator.h"
19 #include "ConversationFilterValidatorFactory.h"
20
21 #include <Commons/Exception.h>
22 #include "log.h"
23 #include <Logger.h>
24
25 namespace DeviceAPI {
26                 namespace Messaging {
27
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 = "";
33
34                         const std::string ConversationQueryGenerator::STRING_DIRECTION = "C.MSG_DIRECTION";
35
36                 ConversationQueryGenerator::ConversationQueryGenerator():MessageQueryGenerator() {
37                 }
38
39                 ConversationQueryGenerator::ConversationQueryGenerator(const DeviceAPI::Tizen::SortModePtr& sortMode,
40                                 const long limit, const long offset):MessageQueryGenerator(sortMode, limit, offset){
41
42                 }
43
44                 ConversationQueryGenerator::ConversationQueryGenerator(const DeviceAPI::Tizen::SortModePtr& sortMode,
45                                 const long limit, const long offset, const int type):MessageQueryGenerator(sortMode, limit, offset, type){
46
47                 }
48                 
49
50                 ConversationQueryGenerator::~ConversationQueryGenerator() {
51                 }
52
53                 void ConversationQueryGenerator::setSmsMmsAttributeMap(){
54                         LoggerD("<<<");
55                         attributeMap.clear();
56
57                         attributeMap.insert(
58                                                                                         std::pair<std::string, std::string>(
59                                                                                                         ConversationFilterValidatorFactory::ATTRIBUTE_ID,          "B.CONV_ID"));
60                         if(getMode() == MODE_SMS)
61                         {
62                                 attributeMap.insert(
63                                                                                         std::pair<std::string, std::string>(
64                                                                                                         ConversationFilterValidatorFactory::ATTRIBUTE_TYPE,          "B.SMS_CNT"));
65                         }
66                         else{
67                                 attributeMap.insert(
68                                                                                         std::pair<std::string, std::string>(
69                                                                                                         ConversationFilterValidatorFactory::ATTRIBUTE_TYPE,              "B.MMS_CNT"));                         
70                         }
71                         attributeMap.insert(
72                                                                                         std::pair<std::string, std::string>(
73                                                                                                         ConversationFilterValidatorFactory::ATTRIBUTE_TIMESTAMP,       "B.DISPLAY_TIME"));
74                         attributeMap.insert(
75                                                                                         std::pair<std::string, std::string>(
76                                                                                                         ConversationFilterValidatorFactory::ATTRIBUTE_FROM,            "A.ADDRESS_VAL"));
77                         attributeMap.insert(
78                                                                                         std::pair<std::string, std::string>(
79                                                                                                         ConversationFilterValidatorFactory::ATTRIBUTE_TO,              "A.ADDRESS_VAL"));
80                         attributeMap.insert(
81                                                                                         std::pair<std::string, std::string>(
82                                                                                                         ConversationFilterValidatorFactory::ATTRIBUTE_PREVIEW,            "B.MSG_TEXT"));
83                         attributeMap.insert(
84                                                                                         std::pair<std::string, std::string>(
85                                                                                                         ConversationFilterValidatorFactory::ATTRIBUTE_MESSAGE_COUNT,    "B.SMS_CNT+B.MMS_CNT"));
86                         attributeMap.insert(
87                                                                                         std::pair<std::string, std::string>(
88                                                                                                         ConversationFilterValidatorFactory::ATTRIBUTE_UNREAD_MESSAGES,    "B.UNREAD_CNT"));
89
90                         LoggerD(">>>");
91                 }
92
93                 std::string ConversationQueryGenerator::getMatchExactlyClause(std::string& attrName, DeviceAPI::Tizen::AnyPtr& value){
94                         std::string retClause;
95                         std::string emfAttributeName = convertToEmfAttrName(attrName);
96
97                         if(getMode() == MODE_SMS || getMode() == MODE_MMS){
98                                 if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_MESSAGE_COUNT)==0){
99                                         retClause = emfAttributeName + "=" + value->toString();
100                                         return retClause;
101                                 }else if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_TYPE)==0){
102                                         retClause = emfAttributeName + " > 0";
103                                         LoggerD(">retClause>> " << retClause);
104                                         return retClause;                                       
105                                 }else if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_PREVIEW)==0){
106                                         retClause = emfAttributeName + " LIKE '" + value->toString() + "'";
107                                         return retClause;
108                                 }
109                         }
110
111                         retClause = MessageQueryGenerator::getMatchExactlyClause(attrName, value);
112                         return retClause;
113                 }
114
115                 std::string ConversationQueryGenerator::getMatchExistsClause(std::string& attrName){
116                         std::string retClause;
117                         std::string emfAttributeName = convertToEmfAttrName(attrName);
118
119                         if(getMode() == MODE_SMS || getMode() == MODE_MMS){
120                                 if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_MESSAGE_COUNT)==0){
121                                         retClause = emfAttributeName + " IS NOT NULL ";
122                                         return retClause;
123                                 }else if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_PREVIEW)==0){
124                                         retClause = emfAttributeName + " NOT LIKE '' ";
125                                         return retClause;
126                                 }
127                         }
128
129                         retClause = MessageQueryGenerator::getMatchExistsClause(attrName);
130                         return retClause;
131                 }
132
133
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;
141                         }else{
142                                 MsgLoggerE("invalid mode:" << getMode());
143                                 Throw(WrtDeviceApis::Commons::UnknownException);
144                         }
145                 }
146
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;
152                         }else{
153                                 MsgLoggerE("invalid mode:" << getMode());
154                                 Throw(WrtDeviceApis::Commons::UnknownException);
155                         }
156                 }
157
158                 std::string ConversationQueryGenerator::getMessageDirectionString(){
159                                         return ConversationQueryGenerator::STRING_DIRECTION;
160                                 }
161
162         }
163 }