Update change log and spec for wrt-plugins-tizen_0.4.70
[framework/web/wrt-plugins-tizen.git] / src / Messaging / FolderQueryGenerator.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 "FolderQueryGenerator.h"
19 #include "FolderFilterValidatorFactory.h"
20 #include "ConversationFilterValidatorFactory.h"
21 #include "IMessagingTypes.h"
22 #include "log.h"
23 #include <Commons/Exception.h>
24 #include <email-types.h>
25 #include <Logger.h>
26
27 using namespace std;
28 using namespace DeviceAPI::Tizen;
29
30 namespace DeviceAPI {
31                 namespace Messaging {
32
33                 const std::string FolderQueryGenerator::STRING_MATCH_EXACTLY         = "EXACTLY";
34                 const std::string FolderQueryGenerator::STRING_MATCH_CONTAINS        = "CONTAINS";
35                 const std::string FolderQueryGenerator::STRING_MATCH_STARTSWITH      = "STARTSWITH";
36                 const std::string FolderQueryGenerator::STRING_MATCH_ENDSWITH        = "ENDSWITH";
37                 const std::string FolderQueryGenerator::STRING_MATCH_EXISTS          = "EXISTS";
38
39                 const int FolderQueryGenerator::ACCOUNT_ID_NOT_INITIALIZED = -1;
40
41                 FolderQueryGenerator::FolderQueryGenerator():m_messageType(ACCOUNT_ID_NOT_INITIALIZED) {
42                 }
43
44                 FolderQueryGenerator::~FolderQueryGenerator() {
45                 }
46
47
48                 void FolderQueryGenerator::visitPreComposite(DeviceAPI::Tizen::FilterType& type, int depth){
49                         LoggerD("<<<");
50                 }
51
52                 void FolderQueryGenerator::visitInComposite(DeviceAPI::Tizen::FilterType& type, int depth){
53                         LoggerD("<<<");
54
55                         if(type != INTERSECTION_FILTER){
56                                 LoggerE("[ERROR] >>> invalid Filter type:" << type);
57                                 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "invalid Fiilter Type");
58                                 return;
59                         }
60                 }
61
62                 void FolderQueryGenerator::visitPostComposite(DeviceAPI::Tizen::FilterType& type, int depth){
63                         LoggerD("<<<");
64                 }
65
66                 bool FolderQueryGenerator::getMatchExactlyClause(std::string& attrName, DeviceAPI::Tizen::AnyPtr& value)
67                 {
68                         std::string retClause;
69                         std::string valueString = value->toString();
70
71                         do{
72                                 if(attrName.compare(FolderFilterValidatorFactory::ATTRIBUTE_ACCOUNTID)==0){
73                                         m_accountId = atoi(value->toString().c_str());
74                                         break;
75                                 }else if(attrName.compare(FolderFilterValidatorFactory::ATTRIBUTE_FOLDERPATH)==0){
76                                         m_folderPathProcessing = TRUE;                          
77                                         m_folderpath = value->toString();
78                                         break;
79                                 }
80                         }while(false);
81
82                         return FALSE;
83                 }
84
85                 bool FolderQueryGenerator::getMatchExistClause(std::string& attrName)
86                 {
87                         std::string retClause;
88
89                         do{
90                                 if(attrName.compare(FolderFilterValidatorFactory::ATTRIBUTE_ACCOUNTID)==0){
91                                         return TRUE;
92                                 }
93                                 else
94                                 {
95                                         return FALSE;
96                                 }
97                         }while(false);
98
99                         return FALSE;
100                 }
101
102                 std::string FolderQueryGenerator::getMatchStartsWithClause(std::string& attrName, DeviceAPI::Tizen::AnyPtr& value){
103                         std::string retClause;
104                         LoggerD("<<< NOT IMPLEMENTED YET");
105                         return retClause;
106                 }
107
108                 std::string FolderQueryGenerator::getMatchEndsWithClause(std::string& attrName, DeviceAPI::Tizen::AnyPtr& value){
109                         std::string retClause;
110                         LoggerD("<<< NOT IMPLEMENTED YET");
111                         return retClause;
112                 }
113
114                 std::string FolderQueryGenerator::getMatchContainsClause(std::string& attrName, DeviceAPI::Tizen::AnyPtr& value){
115                         std::string retClause;
116                         LoggerD("<<< NOT IMPLEMENTED YET");
117                         return retClause;
118                 }
119
120                 void FolderQueryGenerator::visitAttribute(std::string& attrName, DeviceAPI::Tizen::MatchFlag& matchFlag,
121                                 DeviceAPI::Tizen::AnyPtr& matchValue, int depth){
122                         LoggerD("<<< attrName:[" << attrName << "], matchFlag:[" << matchFlag << "]");
123
124                         if(matchValue == NULL)
125                                 return;
126
127                         LoggerD("matchValue:" << matchValue->toString());
128
129                         visitAttributeEach(attrName, matchFlag, matchValue, depth);
130
131                         LoggerD(">>>");
132                 }
133
134                 void FolderQueryGenerator::visitAttributeEach(std::string& attrName, DeviceAPI::Tizen::MatchFlag& matchFlag, DeviceAPI::Tizen::AnyPtr& value, int depth){
135                         LoggerD("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
136
137                         if(matchFlag == DeviceAPI::Tizen::MATCH_EXACTLY){
138                                 LoggerD("STRING_MATCH_EXACTLY");
139                                 getMatchExactlyClause(attrName, value);
140                         }else if(matchFlag == DeviceAPI::Tizen::MATCH_CONTAINS){
141                                 LoggerD("STRING_MATCH_CONTAINS");
142                                 getMatchContainsClause(attrName, value);
143                         }else if(matchFlag== DeviceAPI::Tizen::MATCH_STARTSWITH){
144                                 LoggerD("STRING_MATCH_STARTSWITH");
145                                 getMatchStartsWithClause(attrName, value);
146                         }else if(matchFlag == DeviceAPI::Tizen::MATCH_ENDSWITH){
147                                 LoggerD("STRING_MATCH_ENDSWITH");
148                                 getMatchEndsWithClause(attrName, value);
149                         }else if(matchFlag == DeviceAPI::Tizen::MATCH_EXISTS){
150                                 LoggerD("STRING_MATCH_EXISTS");
151                                 getMatchExistClause(attrName);
152                         }else{
153                                 LoggerD("[ERROR]invalid match flag[" << matchFlag << "]");
154                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid match flag:[" << matchFlag << "]");
155                         }
156                         LoggerD(">>>");
157                 }
158
159                 void FolderQueryGenerator::visitAttributeRange(std::string& attrName, DeviceAPI::Tizen::AnyPtr& initialValue, DeviceAPI::Tizen::AnyPtr& endValue, int depth) {
160                         LoggerD("<<< NOT IMPLEMENTED YET");
161                 }
162
163                 int FolderQueryGenerator::getAccountId()
164                 {
165                         return m_accountId;
166                 }
167                 
168                 std::string FolderQueryGenerator::getFolderPath()
169                 {
170                         return m_folderpath;
171                 }
172
173                 bool FolderQueryGenerator::isFolderPathExist()
174                 {
175                         LoggerE("m_folderPathProcessing : " << m_folderPathProcessing);                         
176                         return m_folderPathProcessing;
177                 }
178
179                 void FolderQueryGenerator::reset(){
180                         m_folderPathProcessing = FALSE;
181                         m_accountId = 0;
182                         m_folderpath.clear();
183                 }
184
185
186         }
187 }