0efab2fa3ec8ea2c94ce734c0268f97ee671d474
[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 <emf-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,
114                                 Api::Tizen::AnyArrayPtr& values, std::string& matchFlag, bool caseSensitive, int depth){
115                         LogDebug("<<< attrName:[" << attrName << "], matchFlag:[" << matchFlag << "]");
116                         LogDebug("values->size():" << values->size());
117
118                         Api::Tizen::FilterType filterType = UNION_FILTER;
119
120                         if(matchFlag.compare("EXIST")==0){
121                                 //TODO implement for EXIST
122                         }else if(values->size() == 1){
123                                 AnyPtr matchValue = values->at(0);
124                                 visitAttributeEach(attrName, matchValue, matchFlag, depth);
125                         }else{
126                                 visitPreComposite(filterType, depth);
127
128                                 AnyArray::iterator iter;
129                                 for(iter=values->begin(); iter!= values->end(); iter++){
130
131                                         if(iter != values->begin()){
132
133                                                 visitInComposite(filterType, depth);
134                                         }
135
136                                         AnyPtr matchValue = *iter;
137                                         visitAttributeEach(attrName, matchValue, matchFlag, depth);
138                                 }
139
140                                 visitPostComposite(filterType, depth);
141                         }
142                         LogDebug(">>>");
143                 }
144
145                 void FolderQueryGenerator::visitAttributeEach(std::string& attrName, Api::Tizen::AnyPtr& value, std::string& matchFlag, int depth){
146                         LogDebug("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
147
148                         if(matchFlag.compare(STRING_MATCH_EXACTLY) == 0){
149                                 LogDebug("STRING_MATCH_EXACTLY");
150                                 getMatchExactlyClause(attrName, value);
151                         }else if(matchFlag.compare(STRING_MATCH_CONTAINS) == 0){
152                                 LogDebug("STRING_MATCH_CONTAINS");
153                                 getMatchContainsClause(attrName, value);
154                         }else if(matchFlag.compare(STRING_MATCH_STARTSWITH) == 0){
155                                 LogDebug("STRING_MATCH_STARTSWITH");
156                                 getMatchStartsWithClause(attrName, value);
157                         }else if(matchFlag.compare(STRING_MATCH_ENDSWITH) == 0){
158                                 LogDebug("STRING_MATCH_ENDSWITH");
159                                 getMatchEndsWithClause(attrName, value);
160                         }else{
161                                 LogDebug("[ERROR]invalid match flag[" << matchFlag << "]");
162                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid match flag:[" + matchFlag + "]");
163                         }
164                         LogDebug(">>>");
165                 }
166
167                 void FolderQueryGenerator::visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth) {
168                         LogDebug("<<< NOT IMPLEMENTED YET");
169                 }
170
171                 //TODO implement visitID
172                 void FolderQueryGenerator::visitID(Api::Tizen::AnyArrayPtr &value, int depth) {
173                         LogDebug("<<< NOT IMPLEMENTED YET");
174                 }
175
176                 int FolderQueryGenerator::getAccountId()
177                 {
178                         return m_accountId;
179                 }
180                 
181                 std::string FolderQueryGenerator::getFolderPath()
182                 {
183                         return m_folderpath;
184                 }
185
186                 bool FolderQueryGenerator::isFolderPathExist()
187                 {
188                         LogError("m_folderPathProcessing : " << m_folderPathProcessing);                        
189                         return m_folderPathProcessing;
190                 }
191
192                 void FolderQueryGenerator::reset(){
193                         m_folderPathProcessing = FALSE;
194                         m_accountId = 0;
195                         m_folderpath.clear();
196                 }
197
198
199                 }
200         }               //namespace Platform
201 }               //namespace WrtPlugins