1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SERVICES_EDM_INCLUDE_ADMIN_POLICIES_STORAGE_RDB_H
17 #define SERVICES_EDM_INCLUDE_ADMIN_POLICIES_STORAGE_RDB_H
18 
19 #include <unordered_map>
20 
21 #include "admin.h"
22 #include "edm_rdb_data_manager.h"
23 #include "json/json.h"
24 
25 namespace OHOS {
26 namespace EDM {
27 class AdminPoliciesStorageRdb {
28 public:
29     AdminPoliciesStorageRdb();
30     static std::shared_ptr<AdminPoliciesStorageRdb> GetInstance();
31     bool InsertAdmin(int32_t userId, const Admin &admin);
32     bool UpdateAdmin(int32_t userId, const Admin &admin);
33     bool DeleteAdmin(int32_t userId, const std::string &packageName);
34     bool UpdateEntInfo(int32_t userId, const std::string &packageName, const EntInfo &entInfo);
35     bool UpdateManagedEvents(int32_t userId, const std::string &packageName,
36         const std::vector<ManagedEvent> &managedEvents);
37     std::unordered_map<int32_t, std::vector<std::shared_ptr<Admin>>> QueryAllAdmin();
38 
39 private:
40     NativeRdb::ValuesBucket CreateInsertValuesBucket(int32_t userId, const Admin &admin);
41     void CreateUpdateValuesBucket(int32_t userId, const Admin &admin, NativeRdb::ValuesBucket &valuesBucket);
42     void SetAdminItems(std::shared_ptr<NativeRdb::ResultSet> resultSet, std::shared_ptr<Admin> item);
43     void ConvertStrToJson(const std::string &str, Json::Value &json);
44     static std::shared_ptr<AdminPoliciesStorageRdb> instance_;
45     static std::mutex mutexLock_;
46 };
47 } // namespace EDM
48 } // namespace OHOS
49 
50 #endif // SERVICES_EDM_INCLUDE_ADMIN_POLICIES_STORAGE_RDB_H