2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * StorageChangesFolderGenerator.cpp
19 * Created on: 2011. 10. 28.
23 #include "StorageChangesFolderGenerator.h"
24 #include "StorageChangesFolderFilterValidatorFactory.h"
26 #include "IMessagingTypes.h"
28 #include <emf-types.h>
30 #include <dpl/log/log.h>
33 using namespace TizenApis::Api::Tizen;
40 const std::string StorageChangesFolderGenerator::STRING_MATCH_EXCACTLY = "EXACTLY";
41 const std::string StorageChangesFolderGenerator::STRING_MATCH_CONTAINS = "CONTAINS";
42 const std::string StorageChangesFolderGenerator::STRING_MATCH_STARTSWITH = "STARTSWITH";
43 const std::string StorageChangesFolderGenerator::STRING_MATCH_ENDSWITH = "ENDSWITH";
44 // const std::string StorageChangesFolderGenerator::STRING_MATCH_CASESENSITIVE = "CASESENSITIVE";
46 const int StorageChangesFolderGenerator::MESSAGE_TYPE_NOT_INITIALIZED = -1;
48 StorageChangesFolderGenerator::StorageChangesFolderGenerator(Api::Messaging::IMessageFolderPtr folder):m_messageType(MESSAGE_TYPE_NOT_INITIALIZED) {
50 m_id = folder->getId();
51 m_parentid = folder->getParentId();
52 m_accountid = folder->getAccountId();
53 m_contestType = (unsigned short)folder->getContentType();
54 m_name = folder->getName();
55 m_path = folder->getPath();
56 m_type = (unsigned short)folder->getType();
57 m_synchronizable = folder->getSynchronizable();
59 LogDebug("m_type:" << m_type );
63 StorageChangesFolderGenerator::~StorageChangesFolderGenerator() {
67 void StorageChangesFolderGenerator::visitPreComposite(Api::Tizen::FilterType& type, int depth){
69 m_operand.push_back(leftblank);
70 LogDebug("Left_blank");
74 void StorageChangesFolderGenerator::visitInComposite(Api::Tizen::FilterType& type, int depth){
76 if(type == UNION_FILTER ){
77 LogDebug("UNION_FILTER");
78 m_operand.push_back(operandUnion);
79 }else if(type == INTERSECTION_FILTER){
80 LogDebug("INTERSECTION_FILTER");
81 m_operand.push_back(operandIntersection);
83 LogError("[ERROR] invalid Filter type:" << type);
89 void StorageChangesFolderGenerator::visitPostComposite(Api::Tizen::FilterType& type, int depth){
94 LogDebug("m_result size =" << m_result.size());
95 data1 = m_result.back();
97 data2 = m_result.back();
99 LogDebug("m_result size =" << m_result.size());
100 LogDebug("m_operand.back() =" << m_operand.back());
101 LogDebug("m_operand size =" << m_operand.size());
102 if(m_operand.back() == operandUnion)
105 LogDebug("data1 = " << data1);
106 LogDebug("data2 = " << data2);
107 LogDebug("data1 || data2 = " << (data1 || data2));
108 m_operand.pop_back();
109 m_result.push_back(data1 || data2);
110 LogDebug("result" << m_result.back());
111 LogDebug("m_result size =" << m_result.size());
113 else if(m_operand.back() == operandIntersection)
115 LogDebug("Intersection");
116 LogDebug("data1 = " << data1);
117 LogDebug("data2 = " << data2);
118 LogDebug("data1 && data2 = " << (data1 && data2));
119 m_operand.pop_back();
120 m_result.push_back(data1 && data2);
121 LogDebug("result " << m_result.back());
122 LogDebug("m_result size =" << m_result.size());
125 }while(m_operand.back() != leftblank);
126 m_operand.pop_back();
127 LogDebug("elase leftblank from m_operand");
128 LogDebug("m_operand size =" << m_operand.size());
132 bool StorageChangesFolderGenerator::getMatchExactlyClause(std::string& attrName, Api::Tizen::AnyPtr& value)
134 std::string valueString = value->toString();
135 LogDebug("<<< attrName : " << attrName);
136 LogDebug("<<< valueString : " << valueString);
137 LogDebug("<<< attrName.compare(valueString) : " << attrName.compare(valueString));
139 if(attrName.compare(valueString) == 0)
141 LogDebug("<<< getMatchExactlyClause SAME >>>");
145 LogDebug("<<< getMatchExactlyClause DIFF >>>");
150 bool StorageChangesFolderGenerator::getMatchContainsClause(std::string& attrName, Api::Tizen::AnyPtr& value)
152 std::string valueString = value->toString();
153 LogDebug("<<< attrName : " << attrName);
154 LogDebug("<<< valueString : " << valueString);
155 LogDebug("<<< attrName.find(valueString) : " << attrName.find(valueString));
157 if(attrName.find(valueString) != std::string::npos)
159 LogDebug("<<< getMatchContainsClause CONTAINS >>>");
162 LogDebug("<<< getMatchContainsClause NOT CONTAINS >>>");
167 bool StorageChangesFolderGenerator::getMatchStartwithClause(std::string& attrName, Api::Tizen::AnyPtr& value)
169 std::string valueString = value->toString();
170 LogDebug("<<< attrName : " << attrName);
171 LogDebug("<<< valueString : " << valueString);
172 LogDebug("<<< attrName.compare(0,valueString.size(), valueString) : " << attrName.compare(0,valueString.size(), valueString));
175 if(attrName.size()-valueString.size() < 0)
178 if(attrName.compare(0,valueString.size(), valueString) == 0)
180 LogDebug("<<< getMatchStartwithClause START WITH >>>");
184 LogDebug("<<< getMatchStartwithClause NOT START WITH >>>");
189 bool StorageChangesFolderGenerator::getMatchEndwithClause(std::string& attrName, Api::Tizen::AnyPtr& value)
191 std::string valueString = value->toString();
193 LogDebug("<<< attrName : " << attrName);
194 LogDebug("<<< valueString : " << valueString);
195 LogDebug("<<< attrName.compare(attrName.size()-valueString.size(),valueString.size(), valueString) : " << attrName.compare(attrName.size()-valueString.size(),valueString.size(), valueString));
198 if(attrName.size()-valueString.size() < 0)
201 if(attrName.compare(attrName.size()-valueString.size(),valueString.size(), valueString) == 0 )
203 LogDebug("<<< getMatchEndwithClause END WITH >>>");
207 LogDebug("<<< getMatchEndwithClause NOT END WITH >>>");
212 void StorageChangesFolderGenerator::visitAttribute(std::string& attrName,
213 Api::Tizen::AnyArrayPtr& values, std::string& matchFlag, bool caseSensitive, int depth){
214 LogDebug("<<< attrName:[" << attrName << "], matchFlag:[" << matchFlag << "]");
215 LogDebug("values->size():" << values->size());
217 Api::Tizen::FilterType filterType = UNION_FILTER;
219 if(matchFlag.compare("EXIST")==0){
220 //TODO implement for EXIST
221 }else if(values->size() == 1){
222 AnyPtr matchValue = values->at(0);
223 visitAttributeEach(attrName, matchValue, matchFlag, depth);
225 visitPreComposite(filterType, depth);
227 AnyArray::iterator iter;
228 for(iter=values->begin(); iter!= values->end(); iter++){
230 if(iter != values->begin()){
232 visitInComposite(filterType, depth);
235 AnyPtr matchValue = *iter;
236 visitAttributeEach(attrName, matchValue, matchFlag, depth);
239 visitPostComposite(filterType, depth);
244 void StorageChangesFolderGenerator::visitAttributeEach(std::string& attrName, Api::Tizen::AnyPtr& value, std::string& matchFlag, int depth){
245 LogDebug("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
246 std::string valueString;
248 // Check Folder_type and filter_type
249 if(attrName.compare("serviceId")==0){
250 LogDebug("<<< value:[" << value << "]");
251 int nType = atoi(value->toString().c_str());
252 if((int)m_accountid == nType)
254 m_result.push_back(TRUE);
255 LogDebug("<<< accountid is same");
259 m_result.push_back(FALSE);
260 LogDebug("<<< accountid is different");
264 if(attrName.compare("contestType")==0){
265 LogDebug("<<< value:[" << value << "]");
266 std::string convertType = value->toString();
267 int nType = convertMessageType(convertType);
268 if((int)m_contestType == nType)
270 m_result.push_back(TRUE);
271 LogDebug("<<< contestType is same");
275 m_result.push_back(FALSE);
276 LogDebug("<<< contestType is different");
280 if(attrName.compare("type")==0){
281 LogDebug("<<< value:[" << value << "]");
282 std::string convertType = value->toString();
283 int nType = convertFolderType(convertType);
284 if((int)m_type == nType)
286 m_result.push_back(TRUE);
287 LogDebug("<<< type is same");
291 m_result.push_back(FALSE);
292 LogDebug("<<< type is different");
296 if(attrName.compare("synchronizable")==0){
297 LogDebug("<<< value:[" << value << "]");
298 int nType = value->toString().compare("true");
299 if((int)m_synchronizable == nType)
301 m_result.push_back(TRUE);
302 LogDebug("<<< synchronizable is same");
306 m_result.push_back(FALSE);
307 LogDebug("<<< synchronizable is different");
312 if(attrName.compare("name")==0){
313 LogDebug("<<< value:[" << value << "]");
314 LogDebug("<<< value->toString():[" << value->toString() << "]");
315 LogDebug("<<< m_name:[" << m_name << "]");
317 valueString = m_name;
318 if(getMatchFlagResult(value, valueString, matchFlag))
320 m_result.push_back(TRUE);
321 LogDebug("<<< name is same");
325 m_result.push_back(FALSE);
326 LogDebug("<<< name is different");
331 if(attrName.compare("path")==0){
332 LogDebug("<<< value:[" << value << "]");
333 LogDebug("<<< value->toString():[" << value->toString() << "]");
334 LogDebug("<<< m_path:[" << m_path << "]");
336 valueString = m_path;
337 if(getMatchFlagResult(value, valueString, matchFlag))
339 m_result.push_back(TRUE);
340 LogDebug("<<< path is same");
344 m_result.push_back(FALSE);
345 LogDebug("<<< path is different");
353 int StorageChangesFolderGenerator::convertMessageType(std::string& stringType){
354 LogDebug("<<< stringType:[" << stringType << "]");
356 int retMessageType = -1;
358 if(stringType.compare("tizen.sms") ==0){
359 retMessageType = Api::Messaging::SMS;
360 }else if(stringType.compare("tizen.mms") ==0){
361 retMessageType = Api::Messaging::MMS;
362 }else if(stringType.compare("tizen.email") ==0){
363 retMessageType = Api::Messaging::EMAIL;
365 LogError("invalid type:[" << stringType << "]");
369 LogDebug(">>> retMessageType:" << retMessageType);
370 return retMessageType;
373 int StorageChangesFolderGenerator::convertFolderType(std::string& stringType){
374 LogDebug("<<< stringType:[" << stringType << "]");
376 int retMessageType = -1;
378 if(stringType.compare("INBOX") ==0){
379 retMessageType = Api::Messaging::INBOX;
380 }else if(stringType.compare("OUTBOX") ==0){
381 retMessageType = Api::Messaging::OUTBOX;
382 }else if(stringType.compare("DRAFTBOX") ==0){
383 retMessageType = Api::Messaging::DRAFTBOX;
384 }else if(stringType.compare("SENTBOX") ==0){
385 retMessageType = Api::Messaging::SENTBOX;
387 LogError("invalid type:[" << stringType << "]");
391 LogDebug(">>> retMessageType:" << retMessageType);
392 return retMessageType;
396 void StorageChangesFolderGenerator::visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth) {
397 LogDebug("<<< NOT SUPPROTED");
399 m_result.push_back(FALSE);
402 bool StorageChangesFolderGenerator::getMatchFlagResult(Api::Tizen::AnyPtr& value, std::string& valueString, std::string& matchFlag)
404 std::vector<std::string>::iterator iter;
406 if(matchFlag.compare(STRING_MATCH_EXCACTLY) == 0){
407 LogDebug("STRING_MATCH_EXCACTLY");
408 result = result || getMatchExactlyClause(valueString, value);
409 }else if(matchFlag.compare(STRING_MATCH_CONTAINS) == 0){
410 LogDebug("STRING_MATCH_CONTAINS");
411 result = result || getMatchContainsClause(valueString, value);
412 }else if(matchFlag.compare(STRING_MATCH_STARTSWITH) == 0){
413 LogDebug("STRING_MATCH_STARTSWITH");
414 result = result || getMatchStartwithClause(valueString, value);
415 }else if(matchFlag.compare(STRING_MATCH_ENDSWITH) == 0){
416 LogDebug("STRING_MATCH_ENDSWITH");
417 result = result || getMatchEndwithClause(valueString, value);
419 LogDebug("[ERROR]invalid match flag : iter:" << *iter);
424 bool StorageChangesFolderGenerator::getCompareResult()
427 LogDebug("m_result.size() " << m_result.size());
428 result = m_result.back();
430 LogDebug("result = " << result);
434 } //namespace Platform
435 } //namespace WrtPlugins