• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #include "medialibrary_smartalbum_map_operations.h"
17 #include "media_log.h"
18 using namespace std;
19 using namespace OHOS::NativeRdb;
20 
21 namespace OHOS {
22 namespace Media {
InsertAlbumAssetsInfoUtil(const ValuesBucket & valuesBucket,shared_ptr<RdbStore> rdbStore,const MediaLibrarySmartAlbumMapDb & smartAlbumMapDbOprn)23 int32_t InsertAlbumAssetsInfoUtil(const ValuesBucket &valuesBucket,
24                                   shared_ptr<RdbStore> rdbStore,
25                                   const MediaLibrarySmartAlbumMapDb &smartAlbumMapDbOprn)
26 {
27     ValuesBucket values = const_cast<ValuesBucket &>(valuesBucket);
28     int32_t insertResult = const_cast<MediaLibrarySmartAlbumMapDb &>(smartAlbumMapDbOprn)
29     .InsertSmartAlbumMapInfo(values, rdbStore);
30     return insertResult;
31 }
RemoveAlbumAssetsInfoUtil(const ValuesBucket & valuesBucket,shared_ptr<RdbStore> rdbStore,const MediaLibrarySmartAlbumMapDb & smartAlbumMapDbOprn)32 int32_t RemoveAlbumAssetsInfoUtil(const ValuesBucket &valuesBucket,
33                                   shared_ptr<RdbStore> rdbStore,
34                                   const MediaLibrarySmartAlbumMapDb &smartAlbumMapDbOprn)
35 {
36     ValuesBucket values = const_cast<ValuesBucket &>(valuesBucket);
37     ValueObject valueObject;
38     int32_t albumId = 0;
39     int32_t assetId = 0;
40     if (values.GetObject(SMARTALBUMMAP_DB_ALBUM_ID, valueObject)) {
41         valueObject.GetInt(albumId);
42     }
43     if (values.GetObject(SMARTALBUMMAP_DB_ASSET_ID, valueObject)) {
44         valueObject.GetInt(assetId);
45     }
46     MEDIA_ERR_LOG("mediasmartmap albumId = %{public}d", albumId);
47     MEDIA_ERR_LOG("mediasmartmap albumId = %{public}d", assetId);
48     int32_t deleteResult = const_cast<MediaLibrarySmartAlbumMapDb &>(smartAlbumMapDbOprn)
49     .DeleteSmartAlbumMapInfo(albumId, assetId, rdbStore);
50     return deleteResult;
51 }
HandleSmartAlbumMapOperations(const string & oprn,const ValuesBucket & valuesBucket,const shared_ptr<RdbStore> & rdbStore)52 int32_t MediaLibrarySmartAlbumMapOperations::HandleSmartAlbumMapOperations(const string &oprn,
53                                                                            const ValuesBucket &valuesBucket,
54                                                                            const shared_ptr<RdbStore> &rdbStore)
55 {
56     ValuesBucket values = const_cast<ValuesBucket &>(valuesBucket);
57     MediaLibrarySmartAlbumMapDb smartAlbumMapDbOprn;
58     int32_t errCode = DATA_ABILITY_FAIL;
59     if (oprn == MEDIA_SMARTALBUMMAPOPRN_ADDSMARTALBUM) {
60         errCode = InsertAlbumAssetsInfoUtil(values, rdbStore, smartAlbumMapDbOprn);
61     } else if (oprn == MEDIA_SMARTALBUMMAPOPRN_REMOVESMARTALBUM) {
62         errCode = RemoveAlbumAssetsInfoUtil(values, rdbStore, smartAlbumMapDbOprn);
63     }
64     return errCode;
65 }
66 } // namespace Media
67 } // namespace OHOS