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 * FolderQueryGenerator.cpp
19 * Created on: 2011. 10. 28.
23 #include "FolderQueryGenerator.h"
24 #include "API/Messaging/FolderFilterValidatorFactory.h"
25 #include "API/Messaging/ConversationFilterValidatorFactory.h"
27 #include <API/Messaging/IMessagingTypes.h>
28 #include <API/Messaging/log.h>
29 #include <Commons/Exception.h>
31 #include <emf-types.h>
33 #include <dpl/log/log.h>
36 using namespace TizenApis::Api::Tizen;
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";
49 const int FolderQueryGenerator::ACCOUNT_ID_NOT_INITIALIZED = -1;
51 FolderQueryGenerator::FolderQueryGenerator():m_messageType(ACCOUNT_ID_NOT_INITIALIZED) {
54 FolderQueryGenerator::~FolderQueryGenerator() {
58 void FolderQueryGenerator::visitPreComposite(Api::Tizen::FilterType& type, int depth){
62 void FolderQueryGenerator::visitInComposite(Api::Tizen::FilterType& type, int depth){
65 if(type != INTERSECTION_FILTER){
66 LogError("[ERROR] >>> invalid Filter type:" << type);
67 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "invalid Fiilter Type");
72 void FolderQueryGenerator::visitPostComposite(Api::Tizen::FilterType& type, int depth){
76 bool FolderQueryGenerator::getMatchExactlyClause(std::string& attrName, Api::Tizen::AnyPtr& value)
78 std::string retClause;
79 std::string valueString = value->toString();
82 if(attrName.compare(FolderFilterValidatorFactory::ATTRIBUTE_ACCOUNTID)==0){
83 m_accountId = atoi(value->toString().c_str());
85 }else if(attrName.compare(FolderFilterValidatorFactory::ATTRIBUTE_FOLDERPATH)==0){
86 m_folderPathProcessing = TRUE;
87 m_folderpath = value->toString();
95 std::string FolderQueryGenerator::getMatchStartsWithClause(std::string& attrName, TizenApis::Api::Tizen::AnyPtr& value){
96 std::string retClause;
97 LogDebug("<<< NOT IMPLEMENTED YET");
101 std::string FolderQueryGenerator::getMatchEndsWithClause(std::string& attrName, TizenApis::Api::Tizen::AnyPtr& value){
102 std::string retClause;
103 LogDebug("<<< NOT IMPLEMENTED YET");
107 std::string FolderQueryGenerator::getMatchContainsClause(std::string& attrName, TizenApis::Api::Tizen::AnyPtr& value){
108 std::string retClause;
109 LogDebug("<<< NOT IMPLEMENTED YET");
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());
118 Api::Tizen::FilterType filterType = UNION_FILTER;
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);
126 visitPreComposite(filterType, depth);
128 AnyArray::iterator iter;
129 for(iter=values->begin(); iter!= values->end(); iter++){
131 if(iter != values->begin()){
133 visitInComposite(filterType, depth);
136 AnyPtr matchValue = *iter;
137 visitAttributeEach(attrName, matchValue, matchFlag, depth);
140 visitPostComposite(filterType, depth);
145 void FolderQueryGenerator::visitAttributeEach(std::string& attrName, Api::Tizen::AnyPtr& value, std::string& matchFlag, int depth){
146 LogDebug("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
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);
161 LogDebug("[ERROR]invalid match flag[" << matchFlag << "]");
162 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid match flag:[" + matchFlag + "]");
167 void FolderQueryGenerator::visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth) {
168 LogDebug("<<< NOT IMPLEMENTED YET");
171 //TODO implement visitID
172 void FolderQueryGenerator::visitID(Api::Tizen::AnyArrayPtr &value, int depth) {
173 LogDebug("<<< NOT IMPLEMENTED YET");
176 int FolderQueryGenerator::getAccountId()
181 std::string FolderQueryGenerator::getFolderPath()
186 bool FolderQueryGenerator::isFolderPathExist()
188 LogError("m_folderPathProcessing : " << m_folderPathProcessing);
189 return m_folderPathProcessing;
192 void FolderQueryGenerator::reset(){
193 m_folderPathProcessing = FALSE;
195 m_folderpath.clear();
200 } //namespace Platform
201 } //namespace WrtPlugins