[content] Remove Open Service Platform words
[platform/framework/native/content.git] / src / FCntContentSearch.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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  * @file                FCntContentSearch.cpp
18  * @brief               This is the implementation file for the %ContentSearch class.
19  *
20  * This is the implementation file for %ContentSearch class.
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FCntContentSearch.h>
25 #include <FBaseColIList.h>
26 #include <FCnt_ContentSearchImpl.h>
27 #include <FSec_AccessController.h>
28
29 using namespace Tizen::Io;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Security;
33
34 namespace Tizen { namespace Content
35 {
36
37 static const int MAX_QUERY_PATH = 512;
38
39 ContentSearch::ContentSearch(void)
40         : Object()
41         , __pImpl(null)
42 {
43 }
44
45 ContentSearch::~ContentSearch(void)
46 {
47         if (__pImpl != null)
48         {
49                 delete __pImpl;
50                 __pImpl = null;
51         }
52 }
53
54 result
55 ContentSearch::Construct(ContentType type)
56 {
57         result r = E_SUCCESS;
58
59         SysAssertf(__pImpl == null,
60                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
61
62         SysTryReturn(NID_CNT, type != CONTENT_TYPE_UNKNOWN, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Construct failed.");
63
64         _ContentSearchImpl* pContentSearchImpl = new (std::nothrow) _ContentSearchImpl();
65         SysTryReturn(NID_CNT, pContentSearchImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed.");
66
67         r = pContentSearchImpl->Construct(type);
68         SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
69
70         __pImpl = pContentSearchImpl;
71
72         return E_SUCCESS;;
73
74 CATCH:
75         delete pContentSearchImpl;
76         pContentSearchImpl = null;
77
78         return r;
79 }
80
81 IList*
82 ContentSearch::SearchN(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, const String& whereExpr,
83 const String& sortColumn, SortOrder sortOrder) const
84 {
85         ClearLastResult();
86
87         totalPageCount = 0;
88         totalCount = 0;
89
90         // Checks the privilege
91         result r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_READ);
92         SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_PRIVILEGE_DENIED,
93                         "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
94
95         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
96
97         SysTryReturn(NID_CNT, pageNo > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] pageNo <=0 : SearchN failed.");
98         SysTryReturn(NID_CNT, countPerPage > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] countPerPage <=0: SearchN failed.");
99         SysTryReturn(NID_CNT, whereExpr.GetLength() <= MAX_QUERY_PATH, null, E_INVALID_ARG, "[E_INVALID_ARG] Exceeds query max size : SearchN failed.");
100
101
102         return __pImpl->SearchN(pageNo, countPerPage, totalPageCount, totalCount, whereExpr, sortColumn, sortOrder);
103
104 }
105
106 IList*
107 ContentSearch::GetValueListN(const String& column, SortOrder sortOrder)
108 {
109         ClearLastResult();
110
111         // Checks the privilege
112         result r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_READ);
113         SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_PRIVILEGE_DENIED,
114                         "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
115
116         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
117
118         SysTryReturn(NID_CNT, !column.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The column name is invalid.");
119
120         return __pImpl->GetValueListN(column, sortOrder);
121 }
122
123 IList*
124 ContentSearch::GetValueListN(int pageNo, int countPerPage, int& totalPageCount, int& totalCount,
125 const String& column, SortOrder sortOrder) const
126 {
127         ClearLastResult();
128
129         totalPageCount = 0;
130         totalCount = 0;
131
132         // Checks the privilege
133         result r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_READ);
134         SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_PRIVILEGE_DENIED,
135                         "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
136
137         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
138
139         SysTryReturn(NID_CNT, !column.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The column name is invalid: GetValueListN failed.");
140         SysTryReturn(NID_CNT, pageNo > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] pageNo <=0: GetValueListN failed.");
141         SysTryReturn(NID_CNT, countPerPage > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] countPerPage <=0: GetValueListN failed.");
142
143         return __pImpl->GetValueListN(pageNo, countPerPage, totalPageCount, totalCount, column, sortOrder);
144 }
145
146 }}