Update change log and spec for wrt-plugins-tizen_0.2.73
[profile/ivi/wrt-plugins-tizen.git] / src / platform / Tizen / Messaging / MessageQueryGenerator.h
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. 
15 */
16 /*
17  * MessageQueryGenerator.h
18  *
19  *  Created on: 2011. 10. 28.
20  *      Author: sangtai
21  */
22
23 #ifndef MESSAGEQUERYGENERATOR_H_
24 #define MESSAGEQUERYGENERATOR_H_
25
26 #include <API/Filter/IFilterVisitor.h>
27 #include <API/Filter/SortMode.h>
28
29 #include <map>
30
31 namespace TizenApis {
32         namespace Platform {
33                 namespace Messaging {
34
35                 class MessageQueryGenerator: public TizenApis::Api::Tizen::IFilterVisitor{
36
37                         public:
38                                 enum QueryGeneratorMode{
39                                         MODE_EMAIL,
40                                         MODE_SMS,
41                                         MODE_MMS
42                                 };
43
44                         protected:
45                                 std::map<std::string, std::string> attributeMap;
46
47                         private:
48                                 QueryGeneratorMode m_mode;
49                                 std::string m_query;
50                                 std::string m_orderLimit;                               
51                                 std::vector<std::string> m_queryVector;
52
53                                 int m_messageType;
54                                 int m_serviceType;
55
56                                 std::vector<std::string> typeVector;
57
58                                 Api::Tizen::SortModePtr m_sortMode;
59                                 long m_limit;
60                                 long m_offset;
61
62                                 int m_typeProcessing;
63                                 std::string m_currentType;
64
65                                 static const std::string STRING_MATCH_EXACTLY;
66                                 static const std::string STRING_MATCH_CONTAINS;
67                                 static const std::string STRING_MATCH_STARTSWITH;
68                                 static const std::string STRING_MATCH_ENDSWITH;
69                                 static const std::string STRING_MATCH_CASESENSITIVE;
70                                 static const std::string STRING_WHERE;
71                                 static const std::string STRING_SUFFIX;
72                                 static const std::string STRING_DIRECTION;
73
74                                 static const int MESSAGE_TYPE_NOT_INITIALIZED;
75
76                         public:
77                                 MessageQueryGenerator();
78                                 MessageQueryGenerator(const Api::Tizen::SortModePtr& sortMode, const long limit, const long offset);
79                                 MessageQueryGenerator(const Api::Tizen::SortModePtr& sortMode, const long limit, const long offset, const int type);                            
80                                 virtual ~MessageQueryGenerator();
81
82                                 void visitPreComposite(Api::Tizen::FilterType& type, int depth);
83                                 void visitInComposite(Api::Tizen::FilterType& type, int depth);
84                                 void visitPostComposite(Api::Tizen::FilterType& type, int depth);
85                                 void visitAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
86                                                 Api::Tizen::AnyPtr& matchValue, int depth);
87                                 void visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth);
88
89                                 std::string getQuery();
90                                 std::string getOrderLimit();                            
91
92 //                              bool containMailType();
93 //                              bool containType(int type);
94                                 int getMessageType(){
95                                         return m_messageType;
96                                 };
97
98                                 void setMode(QueryGeneratorMode mode ){
99                                         m_mode = mode;
100                                 }
101
102                                 QueryGeneratorMode getMode(){
103                                         return m_mode;
104                                 }
105
106                                 int getServiceType(){
107                                         return m_serviceType;
108                                 }                               
109
110                                 void reset(QueryGeneratorMode mode);
111
112                         protected:
113                                 virtual void setEmailAttributeMap();
114                                 virtual void setSmsMmsAttributeMap();
115                                 virtual std::string getMatchExactlyClause(std::string& attrName, Api::Tizen::AnyPtr& value);
116                                 virtual std::string getQueryPrefix();
117                                 virtual std::string getQuerySuffix();
118                                 virtual std::string getMessageDirectionString();
119
120                                 std::string convertToEmfAttrName(std::string attrName);
121
122                                 void visitAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth);
123                                 std::string convertMessageTypeToString(std::string& stringType);                                
124
125                         private:
126                                 std::string getMatchStartsWithClause(std::string& attrName, Api::Tizen::AnyPtr& value);
127                                 std::string getMatchEndsWithClause(std::string& attrName, Api::Tizen::AnyPtr& value);
128                                 std::string getMatchContainsClause(std::string& attrName, Api::Tizen::AnyPtr& value);
129
130                                 std::string createTimeString(std::string& timeString);
131                                 std::string createFolderType(std::string& value);
132                                 std::string createPriorityTypeForEmail(std::string& value);
133                                 std::string createPriorityTypeForSmsMms(std::string& value);
134                                 std::string createDateTimeTypeForEmail(Api::Tizen::AnyPtr& value);
135
136                                 std::string createDateTimeTypeForSmsMms(Api::Tizen::AnyPtr& value);
137                                 std::string createDateTimeTypeForSmsMms(std::string& timeString);                               
138
139                                 std::string convertToTimeFormat(const std::string& timeString);
140                                 std::string convertBooleanStringToIntegerString(std::string& booleanString);
141                                 std::string toDateDbStr(const std::tm &date) const;
142
143                                 void initAttributeMap();
144                                 std::string getQueryFromVector();
145
146                                 int convertMessageType(std::string& stringType);
147                 };
148
149                 typedef DPL::SharedPtr<MessageQueryGenerator> MessageQueryGeneratorPtr;
150         }               // namespace Platform
151 } // namespace WrtPlugins
152 }
153 #endif /* MESSAGEQUERYGENERATOR_H_ */