• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_CLOUD_SYNC_SERVICE_ALBUM_DATA_CONVERTOR_H
17 #define OHOS_CLOUD_SYNC_SERVICE_ALBUM_DATA_CONVERTOR_H
18 
19 #include <unordered_map>
20 
21 #include <uuid/uuid.h>
22 
23 #include "data_convertor.h"
24 #include "dfs_error.h"
25 #include "gallery_album_const.h"
26 #include "gallery_file_const.h"
27 #include "utils_log.h"
28 
29 namespace OHOS {
30 namespace FileManagement {
31 namespace CloudSync {
32 
33 #define UUID_STR_LENGTH 37
34 
35 class AlbumDataConvertor : public DataConvertor {
36 public:
37 
38     AlbumDataConvertor(OperationType type);
39     ~AlbumDataConvertor() = default;
40 
41     int32_t Convert(DriveKit::DKRecord &record, NativeRdb::ResultSet &resultSet) override;
42     int32_t Convert(DriveKit::DKRecord &record, NativeRdb::ValuesBucket &valueBucket) override;
43     int32_t ExtractBundleName(DriveKit::DKRecordData &data, NativeRdb::ValuesBucket &valueBucket);
44     int32_t ExtractLocalLanguage(DriveKit::DKRecordData &data, NativeRdb::ValuesBucket &valueBucket);
45 
46 private:
47     /* record id */
48     int32_t FillRecordId(DriveKit::DKRecord &record, NativeRdb::ResultSet &resultSet);
49     int32_t HandleRecordId(DriveKit::DKRecord &record, NativeRdb::ResultSet &resultSet);
50 
51     /* basic */
52     int32_t HandleAlbumId(DriveKit::DKRecordData &data, NativeRdb::ResultSet &resultSet);
53     int32_t HandleAlbumName(DriveKit::DKRecordData &data, NativeRdb::ResultSet &resultSet);
54     int32_t HandleType(DriveKit::DKRecordData &data, NativeRdb::ResultSet &resultSet);
55     int32_t HandleAlbumLogicType(DriveKit::DKRecordData &data, NativeRdb::ResultSet &resultSet);
56     int32_t HandlePath(DriveKit::DKRecordData &data, NativeRdb::ResultSet &resultSet);
57     int32_t HandleSourceAlbum(DriveKit::DKRecordData &data, NativeRdb::ResultSet &resultSet);
58     int32_t HandleBundleName(DriveKit::DKRecordFieldMap &map, NativeRdb::ResultSet &resultSet);
59     int32_t HandleLocalLanguage(DriveKit::DKRecordFieldMap &map, NativeRdb::ResultSet &resultSet);
60 
61     /* properties */
62     int32_t HandleProperties(DriveKit::DKRecordData &data, NativeRdb::ResultSet &resultSet);
63     /* properties - general */
64     int32_t HandleGeneral(DriveKit::DKRecordFieldMap &map, NativeRdb::ResultSet &resultSet);
65 
66     /* identifier */
67     static const std::string recordType_;
68     OperationType type_;
69 };
70 
HandleAlbumId(DriveKit::DKRecordData & data,NativeRdb::ResultSet & resultSet)71 inline int32_t AlbumDataConvertor::HandleAlbumId(DriveKit::DKRecordData &data, NativeRdb::ResultSet &resultSet)
72 {
73     std::string val;
74     int32_t ret = GetString(Media::PhotoAlbumColumns::ALBUM_ID, val, resultSet);
75     if (ret != E_OK) {
76         return ret;
77     }
78     data[ALBUM_ID] = DriveKit::DKRecordField(val);
79     return E_OK;
80 }
81 
HandleAlbumName(DriveKit::DKRecordData & data,NativeRdb::ResultSet & resultSet)82 inline int32_t AlbumDataConvertor::HandleAlbumName(DriveKit::DKRecordData &data, NativeRdb::ResultSet &resultSet)
83 {
84     std::string val;
85     int32_t ret = GetString(Media::PhotoAlbumColumns::ALBUM_NAME, val, resultSet);
86     if (ret != E_OK) {
87         return ret;
88     }
89     data[ALBUM_NAME] = DriveKit::DKRecordField(val);
90     return E_OK;
91 }
92 
HandleType(DriveKit::DKRecordData & data,NativeRdb::ResultSet & resultSet)93 inline int32_t AlbumDataConvertor::HandleType(DriveKit::DKRecordData &data, NativeRdb::ResultSet &resultSet)
94 {
95     data[ALBUM_TYPE] = DriveKit::DKRecordField(AlbumType::NORMAL);
96     return E_OK;
97 }
98 
HandleAlbumLogicType(DriveKit::DKRecordData & data,NativeRdb::ResultSet & resultSet)99 inline int32_t AlbumDataConvertor::HandleAlbumLogicType(DriveKit::DKRecordData &data, NativeRdb::ResultSet &resultSet)
100 {
101     data[ALBUM_LOGIC_TYPE] = DriveKit::DKRecordField(LogicType::LOGICAL);
102     return E_OK;
103 }
104 
HandlePath(DriveKit::DKRecordData & data,NativeRdb::ResultSet & resultSet)105 inline int32_t AlbumDataConvertor::HandlePath(DriveKit::DKRecordData &data, NativeRdb::ResultSet &resultSet)
106 {
107     std::string val;
108     int32_t ret = GetString(Media::PhotoAlbumColumns::ALBUM_NAME, val, resultSet);
109     if (ret != E_OK) {
110         return ret;
111     }
112     data[ALBUM_PATH] = DriveKit::DKRecordField(ALBUM_LOCAL_PATH_PREFIX + val);
113     return E_OK;
114 }
115 
HandleBundleName(DriveKit::DKRecordFieldMap & map,NativeRdb::ResultSet & resultSet)116 inline int32_t AlbumDataConvertor::HandleBundleName(DriveKit::DKRecordFieldMap &map, NativeRdb::ResultSet &resultSet)
117 {
118     std::string val;
119     int32_t ret = GetString(TMP_ALBUM_BUNDLE_NAME, val, resultSet);
120     if (ret != E_OK) {
121         return ret;
122     }
123     if (val.empty()) {
124         return E_INVAL_ARG;
125     }
126     map[TMP_ALBUM_BUNDLE_NAME] = DriveKit::DKRecordField(val);
127     return E_OK;
128 }
129 
HandleLocalLanguage(DriveKit::DKRecordFieldMap & map,NativeRdb::ResultSet & resultSet)130 inline int32_t AlbumDataConvertor::HandleLocalLanguage(DriveKit::DKRecordFieldMap &map, NativeRdb::ResultSet &resultSet)
131 {
132     std::string val;
133     int32_t ret = GetString(TMP_ALBUM_LOCAL_LANGUAGE, val, resultSet);
134     if (ret != E_OK) {
135         return ret;
136     }
137     map[TMP_ALBUM_LOCAL_LANGUAGE] = DriveKit::DKRecordField(val);
138     return E_OK;
139 }
140 } // namespace CloudSync
141 } // namespace FileManagement
142 } // namespace OHOS
143 #endif // OHOS_CLOUD_SYNC_SERVICE_ALBUM_DATA_CONVERTOR_H
144