Beta merge 2
[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_MMS
41                                 };
42
43                         protected:
44                                 std::map<std::string, std::string> attributeMap;
45
46                         private:
47                                 QueryGeneratorMode m_mode;
48                                 std::string m_query;
49                                 std::vector<std::string> m_queryVector;
50
51                                 int m_messageType;
52
53                                 std::vector<std::string> typeVector;
54
55                                 Api::Tizen::SortModePtr m_sortMode;
56                                 long m_limit;
57                                 long m_offset;
58
59                                 int m_typeProcessing;
60                                 std::string m_currentType;
61
62                                 static const std::string STRING_MATCH_EXCACTLY;
63                                 static const std::string STRING_MATCH_CONTAINS;
64                                 static const std::string STRING_MATCH_STARTSWITH;
65                                 static const std::string STRING_MATCH_ENDSWITH;
66                                 static const std::string STRING_MATCH_CASESENSITIVE;
67                                 static const std::string STRING_WHERE;
68                                 static const std::string STRING_SUFFIX;
69                                 static const std::string STRING_DIRECTION;
70
71                                 static const int MESSAGE_TYPE_NOT_INITIALIZED;
72
73                         public:
74                                 MessageQueryGenerator();
75                                 MessageQueryGenerator(const Api::Tizen::SortModePtr& sortMode, const long limit, const long offset);
76                                 virtual ~MessageQueryGenerator();
77
78                                 void visitPreComposite(Api::Tizen::FilterType& type, int depth);
79                                 void visitInComposite(Api::Tizen::FilterType& type, int depth);
80                                 void visitPostComposite(Api::Tizen::FilterType& type, int depth);
81                                 void visitAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
82                                                 Api::Tizen::AnyArrayPtr& values, int depth);
83                                 void visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth);
84
85                                 std::string getQuery();
86
87 //                              bool containMailType();
88 //                              bool containType(int type);
89                                 int getMessageType(){
90                                         return m_messageType;
91                                 };
92
93                                 void setMode(QueryGeneratorMode mode ){
94                                         m_mode = mode;
95                                 }
96
97                                 QueryGeneratorMode getMode(){
98                                         return m_mode;
99                                 }
100
101                                 void reset(QueryGeneratorMode mode);
102
103                         protected:
104                                 virtual void setEmailAttributeMap();
105                                 virtual void setSmsMmsAttributeMap();
106                                 virtual std::string getMatchExactlyClause(std::string& attrName, Api::Tizen::AnyPtr& value);
107                                 virtual std::string getQueryPrefix();
108                                 virtual std::string getQuerySuffix();
109                                 virtual std::string getMessageDirectionString();
110
111                                 std::string convertToEmfAttrName(std::string attrName);
112
113                                 void visitAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth);
114
115                         private:
116                                 std::string getMatchStartsWithClause(std::string& attrName, Api::Tizen::AnyPtr& value);
117                                 std::string getMatchEndsWithClause(std::string& attrName, Api::Tizen::AnyPtr& value);
118                                 std::string getMatchContainsClause(std::string& attrName, Api::Tizen::AnyPtr& value);
119
120                                 std::string createTimeString(std::string& timeString);
121                                 std::string createFolderType(std::string& value);
122                                 std::string createPriorityTypeForEmail(std::string& value);
123                                 std::string createPriorityTypeForSmsMms(std::string& value);
124                                 std::string createDateTimeTypeForEmail(Api::Tizen::AnyPtr& value);
125
126                                 std::string createDateTimeTypeForSmsMms(Api::Tizen::AnyPtr& value);
127
128                                 std::string convertToTimeFormat(const std::string& timeString);
129                                 std::string convertBooleanStringToIntegerString(std::string& booleanString);
130
131                                 void initAttributeMap();
132                                 std::string getQueryFromVector();
133
134                                 int convertMessageType(std::string& stringType);
135                 };
136
137                 typedef DPL::SharedPtr<MessageQueryGenerator> MessageQueryGeneratorPtr;
138         }               // namespace Platform
139 } // namespace WrtPlugins
140 }
141 #endif /* MESSAGEQUERYGENERATOR_H_ */