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