1 /*
2 * Copyright (C) 2025 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 #define MLOG_TAG "Media_Client"
16
17 #include "mdk_record_album_data.h"
18
19 #include <string>
20
21 #include "media_log.h"
22
23 namespace OHOS::Media::CloudSync {
MDKRecordAlbumData(const MDKRecord & record)24 MDKRecordAlbumData::MDKRecordAlbumData(const MDKRecord &record)
25 {
26 this->UnMarshalling(record);
27 }
28
UnMarshalling(const MDKRecord & record)29 void MDKRecordAlbumData::UnMarshalling(const MDKRecord &record)
30 {
31 this->record_ = record;
32 this->record_.GetRecordData(this->fields_);
33 if (this->fields_.find(this->KEY_PROPERTIES) != this->fields_.end()) {
34 this->fields_[this->KEY_PROPERTIES].GetRecordMap(this->properties_);
35 }
36 this->record_.SetRecordData(this->fields_);
37 if (this->fields_.find(this->KEY_ATTRIBUTES) != this->fields_.end()) {
38 this->fields_[this->KEY_ATTRIBUTES].GetRecordMap(this->attributes_);
39 }
40 }
Marshalling()41 void MDKRecordAlbumData::Marshalling()
42 {
43 if (this->properties_.size() > 0) {
44 this->fields_[this->KEY_PROPERTIES] = MDKRecordField(this->properties_);
45 }
46 this->record_.SetRecordData(this->fields_);
47 this->record_.SetRecordType(this->VALUE_RECORD_TYPE);
48 }
49
GetDKRecord()50 MDKRecord MDKRecordAlbumData::GetDKRecord()
51 {
52 this->record_.SetRecordData(this->fields_);
53 return this->record_;
54 }
SetDKRecord(MDKRecord & record)55 void MDKRecordAlbumData::SetDKRecord(MDKRecord &record)
56 {
57 this->record_ = record;
58 record.GetRecordData(this->fields_);
59 }
GetBundleName() const60 std::optional<std::string> MDKRecordAlbumData::GetBundleName() const
61 {
62 return this->recordReader_.GetStringValue(this->properties_, this->ALBUM_BUNDLE_NAME);
63 }
SetBundleName(const std::string & bundleName)64 void MDKRecordAlbumData::SetBundleName(const std::string &bundleName)
65 {
66 this->properties_[this->ALBUM_BUNDLE_NAME] = MDKRecordField(bundleName);
67 }
GetAlbumName() const68 std::optional<std::string> MDKRecordAlbumData::GetAlbumName() const
69 {
70 return this->recordReader_.GetStringValue(this->fields_, this->ALBUM_NAME);
71 }
SetAlbumName(const std::string & albumName)72 void MDKRecordAlbumData::SetAlbumName(const std::string &albumName)
73 {
74 this->fields_[this->ALBUM_NAME] = MDKRecordField(albumName);
75 }
GetlPath() const76 std::optional<std::string> MDKRecordAlbumData::GetlPath() const
77 {
78 return this->recordReader_.GetStringValue(this->fields_, this->ALBUM_LOCAL_PATH);
79 }
SetlPath(const std::string & path)80 void MDKRecordAlbumData::SetlPath(const std::string &path)
81 {
82 this->fields_[this->ALBUM_LOCAL_PATH] = MDKRecordField(path);
83 }
GetAlbumType() const84 std::optional<int32_t> MDKRecordAlbumData::GetAlbumType() const
85 {
86 std::optional<std::string> albumTypeStr = this->recordReader_.GetStringValue(this->properties_, this->ALBUM_TYPE);
87 if (albumTypeStr.has_value()) {
88 std::stringstream ss(albumTypeStr.value());
89 int32_t result = 0;
90 if (ss >> result) {
91 return result;
92 }
93 }
94 return 0;
95 }
SetAlbumType(const int32_t & albumType)96 void MDKRecordAlbumData::SetAlbumType(const int32_t &albumType)
97 {
98 this->properties_[this->ALBUM_TYPE] = MDKRecordField(albumType);
99 }
GetAlbumSubType() const100 std::optional<int32_t> MDKRecordAlbumData::GetAlbumSubType() const
101 {
102 std::optional<std::string> albumSubTypeStr =
103 this->recordReader_.GetStringValue(this->properties_, this->ALBUM_SUBTYPE);
104 if (albumSubTypeStr.has_value()) {
105 std::stringstream ss(albumSubTypeStr.value());
106 int32_t result = 0;
107 if (ss >> result) {
108 return result;
109 }
110 }
111 return 0;
112 }
SetAlbumSubType(const int32_t & albumSubType)113 void MDKRecordAlbumData::SetAlbumSubType(const int32_t &albumSubType)
114 {
115 this->properties_[this->ALBUM_SUBTYPE] = MDKRecordField(albumSubType);
116 }
GetDateAdded() const117 std::optional<int64_t> MDKRecordAlbumData::GetDateAdded() const
118 {
119 std::optional<std::string> strOpt = this->recordReader_.GetStringValue(this->properties_, this->ALBUM_DATE_ADDED);
120 if (strOpt.has_value()) {
121 std::stringstream ss(strOpt.value());
122 int64_t result = 0;
123 if (ss >> result) {
124 return result;
125 }
126 }
127 return 0;
128 }
SetDateAdded(const int64_t & dateAdded)129 void MDKRecordAlbumData::SetDateAdded(const int64_t &dateAdded)
130 {
131 this->properties_[this->ALBUM_DATE_ADDED] = MDKRecordField(dateAdded);
132 }
GetDateModified() const133 std::optional<int64_t> MDKRecordAlbumData::GetDateModified() const
134 {
135 std::optional<std::string> strOpt =
136 this->recordReader_.GetStringValue(this->properties_, this->ALBUM_DATE_MODIFIED);
137 if (strOpt.has_value()) {
138 std::stringstream ss(strOpt.value());
139 int64_t result = 0;
140 if (ss >> result) {
141 return result;
142 }
143 }
144 return 0;
145 }
SetDateModified(const int64_t & dateModified)146 void MDKRecordAlbumData::SetDateModified(const int64_t &dateModified)
147 {
148 this->properties_[this->ALBUM_DATE_MODIFIED] = MDKRecordField(dateModified);
149 }
150 // albumId in DKRecord, means cloud_id in album table.
GetCloudId() const151 std::optional<std::string> MDKRecordAlbumData::GetCloudId() const
152 {
153 return this->recordReader_.GetStringValue(this->fields_, this->ALBUM_ID);
154 }
SetCloudId(const std::string & albumId)155 void MDKRecordAlbumData::SetCloudId(const std::string &albumId)
156 {
157 this->fields_[this->ALBUM_ID] = MDKRecordField(albumId);
158 }
GetLogicType() const159 std::optional<int32_t> MDKRecordAlbumData::GetLogicType() const
160 {
161 return this->recordReader_.GetIntValue(this->fields_, this->ALBUM_LOGIC_TYPE);
162 }
163 // locgicType, 0 - Physical, 1 - Logical
SetLogicType(const int32_t & logicType)164 void MDKRecordAlbumData::SetLogicType(const int32_t &logicType)
165 {
166 this->fields_[this->ALBUM_LOGIC_TYPE] = MDKRecordField(logicType);
167 }
IsLogic() const168 std::optional<bool> MDKRecordAlbumData::IsLogic() const
169 {
170 return this->recordReader_.GetBoolValue(this->fields_, this->ALBUM_IS_LOGIC);
171 }
SetIsLogic(const bool & isLogic)172 void MDKRecordAlbumData::SetIsLogic(const bool &isLogic)
173 {
174 this->fields_[this->ALBUM_IS_LOGIC] = MDKRecordField(isLogic);
175 }
GetType() const176 std::optional<std::string> MDKRecordAlbumData::GetType() const
177 {
178 return this->recordReader_.GetStringValue(this->fields_, this->KEY_TYPE);
179 }
180 // type, "directory" or "file"
SetType(const std::string & type)181 void MDKRecordAlbumData::SetType(const std::string &type)
182 {
183 this->fields_[this->KEY_TYPE] = MDKRecordField(type);
184 }
GetLocalLanguage() const185 std::optional<std::string> MDKRecordAlbumData::GetLocalLanguage() const
186 {
187 return this->recordReader_.GetStringValue(this->properties_, this->ALBUM_LOCAL_LANGUAGE);
188 }
SetLocalLanguage(const std::string & localLanguage)189 void MDKRecordAlbumData::SetLocalLanguage(const std::string &localLanguage)
190 {
191 this->properties_[this->ALBUM_LOCAL_LANGUAGE] = MDKRecordField(localLanguage);
192 }
SetNewCreate(const bool & isNewCreate)193 void MDKRecordAlbumData::SetNewCreate(const bool &isNewCreate)
194 {
195 this->record_.SetNewCreate(isNewCreate);
196 }
GetNewCreate() const197 bool MDKRecordAlbumData::GetNewCreate() const
198 {
199 return this->record_.GetNewCreate();
200 }
GetRecordId() const201 std::string MDKRecordAlbumData::GetRecordId() const
202 {
203 return this->record_.GetRecordId();
204 }
SetRecordId(std::string recordId)205 void MDKRecordAlbumData::SetRecordId(std::string recordId)
206 {
207 this->record_.SetRecordId(recordId);
208 }
GetEmptyShow() const209 std::optional<std::string> MDKRecordAlbumData::GetEmptyShow() const
210 {
211 return this->recordReader_.GetStringValue(this->properties_, this->ALBUM_EMPTY_SHOW);
212 }
213 // emptyShow = "1", when recordId = default-album-4, which is hidden album.
SetEmptyShow(const std::string & emptyShow)214 void MDKRecordAlbumData::SetEmptyShow(const std::string &emptyShow)
215 {
216 this->properties_[this->ALBUM_EMPTY_SHOW] = MDKRecordField(emptyShow);
217 }
GetAlbumOrder() const218 std::optional<int32_t> MDKRecordAlbumData::GetAlbumOrder() const
219 {
220 return this->recordReader_.GetIntValue(this->fields_, this->ALBUM_ORDER);
221 }
SetAlbumOrder(const int32_t & albumOrder)222 void MDKRecordAlbumData::SetAlbumOrder(const int32_t &albumOrder)
223 {
224 this->fields_[this->ALBUM_ORDER] = MDKRecordField(albumOrder);
225 }
GetPriority() const226 std::optional<int32_t> MDKRecordAlbumData::GetPriority() const
227 {
228 return this->recordReader_.GetIntValue(this->fields_, this->ALBUM_PRIORITY);
229 }
SetPriority(const int32_t & priority)230 void MDKRecordAlbumData::SetPriority(const int32_t &priority)
231 {
232 this->fields_[this->ALBUM_PRIORITY] = MDKRecordField(priority);
233 }
GetCoverUriSource() const234 std::optional<int32_t> MDKRecordAlbumData::GetCoverUriSource() const
235 {
236 return this->recordReader_.GetIntValue(this->attributes_, this->COVER_URI_SOURCE);
237 }
SetCoverUriSource(const int32_t & coverUriSource)238 void MDKRecordAlbumData::SetCoverUriSource(const int32_t &coverUriSource)
239 {
240 this->attributes_[this->COVER_URI_SOURCE] = MDKRecordField(coverUriSource);
241 }
GetCoverCloudId() const242 std::optional<std::string> MDKRecordAlbumData::GetCoverCloudId() const
243 {
244 return this->recordReader_.GetStringValue(this->attributes_, this->COVER_CLOUD_ID);
245 }
SetCoverCloudId(const std::string & coverCloudId)246 void MDKRecordAlbumData::SetCoverCloudId(const std::string &coverCloudId)
247 {
248 this->attributes_[this->COVER_CLOUD_ID] = MDKRecordField(coverCloudId);
249 }
250 } // namespace OHOS::Media::CloudSync