b7fc3e357e1469b508bce828e14fb24a7ad53a35
[profile/ivi/wrt-plugins-tizen.git] / src / platform / API / Messaging / FolderFilterValidator.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  * FolderFilterValidator.cpp
18  *
19  *  Created on: 2011. 10. 31.
20  *      Author: sangtai
21  */
22
23 #include "FolderFilterValidator.h"
24 #include "FolderFilterValidatorFactory.h"
25
26 #include <dpl/log/log.h>
27 #include "log.h"
28
29 using namespace WrtDeviceApis::Commons;
30 using namespace WrtDeviceApis::CommonsJavaScript;
31 using namespace TizenApis::Api::Tizen;
32
33 namespace TizenApis {
34         namespace Platform {
35                 namespace Messaging {
36
37                 FolderFilterValidator::FolderFilterValidator(PropertyStructArray properties,
38                                 MatchFlagStrArray matchFlag, Api::Tizen::PrimitiveType idType):FilterValidator(properties, matchFlag){
39                         m_isAccountIdSetted = false;
40
41                         initMatchFlagVectors();
42                         initAttributeAndMatchFlagsMap();
43                 }
44
45                 FolderFilterValidator::~FolderFilterValidator(){
46                 }
47
48                 void FolderFilterValidator::initMatchFlagVectors(){
49                         m_accountIdMatchFlagVec.push_back(FolderFilterValidatorFactory::MATCH_EXACTLY);
50                         m_folderPathMatchFlagVec.push_back(FolderFilterValidatorFactory::MATCH_EXACTLY);
51                 }
52
53                 void FolderFilterValidator::initAttributeAndMatchFlagsMap(){
54                         m_attributeAndMatchFlagsMap[FolderFilterValidatorFactory::ATTRIBUTE_ACCOUNTID]      = m_accountIdMatchFlagVec;
55                         m_attributeAndMatchFlagsMap[FolderFilterValidatorFactory::ATTRIBUTE_FOLDERPATH]        = m_folderPathMatchFlagVec;
56                 }
57
58                 bool FolderFilterValidator::validateAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth){
59                         bool retVal = false;
60                         return retVal;
61                 }
62
63                 bool FolderFilterValidator::vectorContains(std::vector<std::string>& vec, std::string& value){
64                         std::vector<std::string>::iterator it;
65                         for(it=vec.begin(); it<vec.end(); it++){
66                                 if((*it).compare(value) == 0){
67                                         return true;
68                                 }
69                         }
70
71                         return false;
72                 }
73
74                 bool FolderFilterValidator::validateAttribute(std::string& attrName, Api::Tizen::AnyArrayPtr& values,
75                                 std::string& matchFlag, bool caseSensitive, int depth){
76                         bool retBool = false;
77
78                         AnyArray::iterator iter;
79                         for(iter=values->begin(); iter!=values->end(); iter++){
80                                 AnyPtr value = *iter;
81                                 if(validateAttributeEach(attrName, value, matchFlag, depth) == false){
82                                         MsgLogWanning(">>>[Warning] attrName:[" << attrName << "] is invalid value:[" << value->toString() << "]");
83                                         return false;
84                                 }
85                         }
86                         LogDebug("## 001 ##");
87                         retBool = FilterValidator::validateAttribute(attrName, values, matchFlag, caseSensitive, depth);
88                         LogDebug("## 002 ##");                  
89                         LogDebug(">>> retBool:" << retBool);
90                         return retBool;
91                 }
92
93                 bool FolderFilterValidator::validateAttributeEach(std::string& attrName, Api::Tizen::AnyPtr& value, std::string& matchFlag, int depth){
94                         LogDebug("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
95
96                         if(attrName.compare(FolderFilterValidatorFactory::ATTRIBUTE_ACCOUNTID)==0){
97                                 LogDebug("<<< m_isAccountIdSetted :[" << m_isAccountIdSetted << "]");
98                                 if(m_isAccountIdSetted == true){
99                                         LogError(">>> [ERROR] duplicated account :[" << attrName << "], value:[" <<
100                                                         value->toString()<< "]");
101                                         return false;
102                                 }else{
103                                         m_isAccountIdSetted = true;
104                                 }
105                         }
106
107                         if(m_attributeAndMatchFlagsMap.count(attrName) == 0)
108                         {
109                                 MsgLogWanning(">>>[Waning] attrName is not supported:[" << attrName << "]");
110                                 return false;                   
111                         }
112
113                         std::vector<std::string> vec = m_attributeAndMatchFlagsMap.find(attrName)->second;
114
115                         if(vectorContains(vec, matchFlag)==false){
116                                 MsgLogWanning(">>>[Waning]MatchFlag check fail unsupported flag:[" << matchFlag << "] for Attribute:[" << attrName << "]");
117                                 return false;
118                         }
119                         return true;
120                 }
121
122         }
123         }
124
125 }