2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "StorageChangesFolderGenerator.h"
19 #include "StorageChangesFolderFilterValidatorFactory.h"
20 #include "IMessagingTypes.h"
21 #include <email-types.h>
25 using namespace DeviceAPI::Tizen;
31 const int StorageChangesFolderGenerator::MESSAGE_TYPE_NOT_INITIALIZED = -1;
33 StorageChangesFolderGenerator::StorageChangesFolderGenerator(IMessageFolderPtr folder):m_messageType(MESSAGE_TYPE_NOT_INITIALIZED) {
35 m_id = folder->getId();
36 m_parentid = folder->getParentId();
37 m_accountid = folder->getAccountId();
38 m_contestType = (unsigned short)folder->getContentType();
39 m_name = folder->getName();
40 m_path = folder->getPath();
41 m_type = (unsigned short)folder->getType();
42 m_synchronizable = folder->getSynchronizable();
44 LoggerD("m_type:" << m_type );
48 StorageChangesFolderGenerator::~StorageChangesFolderGenerator() {
52 void StorageChangesFolderGenerator::visitPreComposite(DeviceAPI::Tizen::FilterType& type, int depth){
54 m_operand.push_back(leftblank);
55 LoggerD("Left_blank");
59 void StorageChangesFolderGenerator::visitInComposite(DeviceAPI::Tizen::FilterType& type, int depth){
61 if(type == UNION_FILTER ){
62 LoggerD("UNION_FILTER");
63 m_operand.push_back(operandUnion);
64 }else if(type == INTERSECTION_FILTER){
65 LoggerD("INTERSECTION_FILTER");
66 m_operand.push_back(operandIntersection);
68 LoggerE("[ERROR] invalid Filter type:" << type);
74 void StorageChangesFolderGenerator::visitPostComposite(DeviceAPI::Tizen::FilterType& type, int depth){
79 LoggerD("m_result size =" << m_result.size());
80 data1 = m_result.back();
82 data2 = m_result.back();
84 LoggerD("m_result size =" << m_result.size());
85 LoggerD("m_operand.back() =" << m_operand.back());
86 LoggerD("m_operand size =" << m_operand.size());
87 if(m_operand.back() == operandUnion)
90 LoggerD("data1 = " << data1);
91 LoggerD("data2 = " << data2);
92 LoggerD("data1 || data2 = " << (data1 || data2));
94 m_result.push_back(data1 || data2);
95 LoggerD("result" << m_result.back());
96 LoggerD("m_result size =" << m_result.size());
98 else if(m_operand.back() == operandIntersection)
100 LoggerD("Intersection");
101 LoggerD("data1 = " << data1);
102 LoggerD("data2 = " << data2);
103 LoggerD("data1 && data2 = " << (data1 && data2));
104 m_operand.pop_back();
105 m_result.push_back(data1 && data2);
106 LoggerD("result " << m_result.back());
107 LoggerD("m_result size =" << m_result.size());
110 }while(m_operand.back() != leftblank);
111 m_operand.pop_back();
112 LoggerD("elase leftblank from m_operand");
113 LoggerD("m_operand size =" << m_operand.size());
117 bool StorageChangesFolderGenerator::getMatchExactlyClause(std::string& attrName, DeviceAPI::Tizen::AnyPtr& value)
119 std::string valueString = value->toString();
120 LoggerD("<<< attrName : " << attrName);
121 LoggerD("<<< valueString : " << valueString);
122 LoggerD("<<< attrName.compare(valueString) : " << attrName.compare(valueString));
124 if(attrName.compare(valueString) == 0)
126 LoggerD("<<< getMatchExactlyClause SAME >>>");
130 LoggerD("<<< getMatchExactlyClause DIFF >>>");
135 bool StorageChangesFolderGenerator::getMatchFullstringClause(std::string& attrName, DeviceAPI::Tizen::AnyPtr& value)
137 std::string tempString1;
138 std::string tempString2;
140 std::string valueString = value->toString();
141 LoggerD("<<< attrName : " << attrName);
142 LoggerD("<<< valueString : " << valueString);
144 tempString1.assign(attrName);
145 tempString2.assign(valueString);
147 StrLowChange(tempString1);
148 StrLowChange(tempString2);
150 LoggerD("<<< attrName : " << tempString1);
151 LoggerD("<<< valueString : " << tempString2);
153 if(tempString1.compare(tempString2) == 0)
155 LoggerD("<<< getMatchFullstringClause SAME >>>");
159 LoggerD("<<< getMatchFullstringClause DIFF >>>");
164 bool StorageChangesFolderGenerator::getMatchContainsClause(std::string& attrName, DeviceAPI::Tizen::AnyPtr& value)
166 std::string tempString1;
167 std::string tempString2;
169 std::string valueString = value->toString();
170 LoggerD("<<< attrName : " << attrName);
171 LoggerD("<<< valueString : " << valueString);
173 tempString1.assign(attrName);
174 tempString2.assign(valueString);
176 StrLowChange(tempString1);
177 StrLowChange(tempString2);
179 LoggerD("<<< attrName : " << tempString1);
180 LoggerD("<<< valueString : " << tempString2);
182 if(tempString1.find(tempString2) != std::string::npos)
184 LoggerD("<<< getMatchContainsClause CONTAINS >>>");
187 LoggerD("<<< getMatchContainsClause NOT CONTAINS >>>");
192 bool StorageChangesFolderGenerator::getMatchStartwithClause(std::string& attrName, DeviceAPI::Tizen::AnyPtr& value)
194 std::string tempString1;
195 std::string tempString2;
197 std::string valueString = value->toString();
198 LoggerD("<<< attrName : " << attrName);
199 LoggerD("<<< valueString : " << valueString);
201 tempString1.assign(attrName);
202 tempString2.assign(valueString);
204 StrLowChange(tempString1);
205 StrLowChange(tempString2);
207 LoggerD("<<< attrName : " << tempString1);
208 LoggerD("<<< valueString : " << tempString2);
210 if(tempString1.size() < tempString2.size())
213 if(tempString1.compare(0,tempString2.size(), tempString2) == 0)
215 LoggerD("<<< getMatchStartwithClause START WITH >>>");
219 LoggerD("<<< getMatchStartwithClause NOT START WITH >>>");
224 bool StorageChangesFolderGenerator::getMatchEndwithClause(std::string& attrName, DeviceAPI::Tizen::AnyPtr& value)
226 std::string tempString1;
227 std::string tempString2;
229 std::string valueString = value->toString();
230 LoggerD("<<< attrName : " << attrName);
231 LoggerD("<<< valueString : " << valueString);
233 tempString1.assign(attrName);
234 tempString2.assign(valueString);
236 StrLowChange(tempString1);
237 StrLowChange(tempString2);
239 LoggerD("<<< attrName : " << tempString1);
240 LoggerD("<<< valueString : " << tempString2);
242 if(tempString1.size() < tempString2.size())
245 if(tempString1.compare(tempString1.size()-tempString2.size(),tempString2.size(), tempString2) == 0 )
247 LoggerD("<<< getMatchEndwithClause END WITH >>>");
251 LoggerD("<<< getMatchEndwithClause NOT END WITH >>>");
257 bool StorageChangesFolderGenerator::getMatchExistClause(std::string& attrName)
259 LoggerD("<<< attrName : " << attrName);
260 if(attrName.size()> 0)
266 void StorageChangesFolderGenerator::visitAttribute(std::string& attrName,
267 DeviceAPI::Tizen::MatchFlag& matchFlag, DeviceAPI::Tizen::AnyPtr& matchValue, int depth){
268 LoggerD("<<< attrName:[" << attrName << "], matchFlag:[" << matchFlag << "]");
270 if(matchFlag != DeviceAPI::Tizen::MATCH_EXISTS){
271 if(matchValue == NULL) {
276 LoggerD("matchValue:" << matchValue->toString());
278 visitAttributeEach(attrName, matchFlag, matchValue, depth);
281 void StorageChangesFolderGenerator::visitAttributeEach(std::string& attrName, DeviceAPI::Tizen::MatchFlag& matchFlag, DeviceAPI::Tizen::AnyPtr& value, int depth){
282 LoggerD("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
283 std::string valueString;
285 // Check Folder_type and filter_type
286 if(attrName.compare( StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_ACCOUNT_ID)==0){
287 LoggerD("<<< value:[" << value << "]");
288 int nType = atoi(value->toString().c_str());
289 if((int)m_accountid == nType)
291 m_result.push_back(TRUE);
292 LoggerD("<<< accountid is same");
296 m_result.push_back(FALSE);
297 LoggerD("<<< accountid is different");
301 if(attrName.compare(StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_CONTENT_TYPE)==0){
302 LoggerD("<<< value:[" << value << "]");
303 std::string convertType = value->toString();
304 int nType = convertMessageType(convertType);
305 if((int)m_contestType == nType)
307 m_result.push_back(TRUE);
308 LoggerD("<<< contestType is same");
312 m_result.push_back(FALSE);
313 LoggerD("<<< contestType is different");
317 if(attrName.compare(StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_TYPE )==0){
318 LoggerD("<<< value:[" << value << "]");
319 std::string convertType = value->toString();
320 int nType = convertFolderType(convertType);
321 if((int)m_type == nType)
323 m_result.push_back(TRUE);
324 LoggerD("<<< type is same");
328 m_result.push_back(FALSE);
329 LoggerD("<<< type is different");
333 if(attrName.compare(StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_SYNCHRONIZABLE)==0){
334 LoggerD("<<< value:[" << value << "]");
335 std::string lowerString;
336 lowerString.assign(value->toString());
337 StrLowChange(lowerString);
338 int nType = lowerString.compare("true");
339 if((int)m_synchronizable != nType)
341 m_result.push_back(TRUE);
342 LoggerD("<<< synchronizable is same");
346 m_result.push_back(FALSE);
347 LoggerD("<<< synchronizable is different");
352 if(attrName.compare(StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_NAME)==0){
353 LoggerD("<<< value:[" << value << "]");
354 LoggerD("<<< value->toString():[" << value->toString() << "]");
355 LoggerD("<<< m_name:[" << m_name << "]");
357 valueString = m_name;
358 if(getMatchFlagResult(value, valueString, matchFlag))
360 m_result.push_back(TRUE);
361 LoggerD("<<< name is same");
365 m_result.push_back(FALSE);
366 LoggerD("<<< name is different");
371 if(attrName.compare(StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_PATH)==0){
372 LoggerD("<<< value:[" << value << "]");
373 LoggerD("<<< value->toString():[" << value->toString() << "]");
374 LoggerD("<<< m_path:[" << m_path << "]");
376 valueString = m_path;
377 if(getMatchFlagResult(value, valueString, matchFlag))
379 m_result.push_back(TRUE);
380 LoggerD("<<< path is same");
384 m_result.push_back(FALSE);
385 LoggerD("<<< path is different");
393 int StorageChangesFolderGenerator::convertMessageType(std::string& stringType){
394 LoggerD("<<< stringType:[" << stringType << "]");
396 int retMessageType = -1;
398 if(stringType.compare("messaging.sms") ==0){
399 retMessageType = SMS;
400 }else if(stringType.compare("messaging.mms") ==0){
401 retMessageType = MMS;
402 }else if(stringType.compare("messaging.email") ==0){
403 retMessageType = EMAIL;
405 LoggerE("invalid type:[" << stringType << "]");
409 LoggerD(">>> retMessageType:" << retMessageType);
410 return retMessageType;
413 int StorageChangesFolderGenerator::convertFolderType(std::string& stringType){
414 LoggerD("<<< stringType:[" << stringType << "]");
416 int retMessageType = -1;
418 if(stringType.compare("INBOX") ==0){
419 retMessageType = INBOX;
420 }else if(stringType.compare("OUTBOX") ==0){
421 retMessageType = OUTBOX;
422 }else if(stringType.compare("DRAFTBOX") ==0){
423 retMessageType = DRAFTBOX;
424 }else if(stringType.compare("SENTBOX") ==0){
425 retMessageType = SENTBOX;
427 LoggerE("invalid type:[" << stringType << "]");
431 LoggerD(">>> retMessageType:" << retMessageType);
432 return retMessageType;
436 void StorageChangesFolderGenerator::visitAttributeRange(std::string& attrName, DeviceAPI::Tizen::AnyPtr& initialValue, DeviceAPI::Tizen::AnyPtr& endValue, int depth) {
437 LoggerD("<<< NOT SUPPROTED");
439 m_result.push_back(FALSE);
442 bool StorageChangesFolderGenerator::getMatchFlagResult(DeviceAPI::Tizen::AnyPtr& value, std::string& valueString, DeviceAPI::Tizen::MatchFlag& matchFlag)
444 std::vector<std::string>::iterator iter;
446 if(matchFlag == DeviceAPI::Tizen::MATCH_EXACTLY){
447 LoggerD("STRING_MATCH_EXACTLY");
448 result = result || getMatchExactlyClause(valueString, value);
449 }else if(matchFlag == DeviceAPI::Tizen::MATCH_FULLSTRING){
450 LoggerD("STRING_MATCH_FULLSTRING");
451 result = result || getMatchFullstringClause(valueString, value);
452 }else if(matchFlag == DeviceAPI::Tizen::MATCH_CONTAINS){
453 LoggerD("STRING_MATCH_CONTAINS");
454 result = result || getMatchContainsClause(valueString, value);
455 }else if(matchFlag == DeviceAPI::Tizen::MATCH_STARTSWITH){
456 LoggerD("STRING_MATCH_STARTSWITH");
457 result = result || getMatchStartwithClause(valueString, value);
458 }else if(matchFlag == DeviceAPI::Tizen::MATCH_ENDSWITH){
459 LoggerD("STRING_MATCH_ENDSWITH");
460 result = result || getMatchEndwithClause(valueString, value);
461 }else if(matchFlag == DeviceAPI::Tizen::MATCH_EXISTS){
462 LoggerD("STRING_MATCH_EXIST");
463 result = result || getMatchExistClause(valueString);
465 LoggerD("[ERROR]invalid match flag : iter:" << *iter);
470 bool StorageChangesFolderGenerator::getCompareResult()
473 LoggerD("m_result.size() " << m_result.size());
474 result = m_result.back();
476 LoggerD("result = " << result);
481 void StorageChangesFolderGenerator::StrLowChange(std::string& tempString)
483 std::transform(tempString.begin(), tempString.end(), tempString.begin(), ::tolower);