1 /*
2  * Copyright (C) 2024 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 FRAMEWORKS_INNERKITSIMPL_MEDIA_LIBRARY_TAB_OLD_PHOTOS_CLIENT_H
17 #define FRAMEWORKS_INNERKITSIMPL_MEDIA_LIBRARY_TAB_OLD_PHOTOS_CLIENT_H
18 
19 #include <string>
20 #include <vector>
21 #include <unordered_map>
22 
23 #include "datashare_result_set.h"
24 #include "file_uri.h"
25 #include "datashare_predicates.h"
26 #include "media_library_manager.h"
27 
28 namespace OHOS::Media {
29 class TabOldPhotosClient {
30 private:
31     struct TabOldPhotosClientObj {
32         int32_t fileId;
33         std::string data;
34         std::string displayName;
35         int32_t oldFileId;
36         std::string oldData;
37     };
38 
39     struct RequestUriObj {
40         int32_t type;
41         int32_t oldFileId;
42         std::string oldData;
43         std::string requestUri;
44     };
45 
46 public:
TabOldPhotosClient(MediaLibraryManager & mediaLibraryManager)47     TabOldPhotosClient(MediaLibraryManager &mediaLibraryManager) : mediaLibraryManager_(mediaLibraryManager) {};
48     std::unordered_map<std::string, std::string> GetUrisByOldUris(std::vector<std::string>& uris);
49 
50 private:
51     int BuildPredicates(const std::vector<std::string> &queryTabOldPhotosUris,
52         DataShare::DataSharePredicates &predicates);
53     std::vector<TabOldPhotosClientObj> Parse(std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
54     std::vector<RequestUriObj> Parse(std::vector<std::string> &queryTabOldPhotosUris);
55     std::string BuildRequestUri(const TabOldPhotosClientObj &dataObj);
56     std::pair<std::string, std::string> Build(
57         const RequestUriObj &requestUriObj, const std::vector<TabOldPhotosClientObj> &dataMapping);
58     std::unordered_map<std::string, std::string> Parse(
59         const std::vector<TabOldPhotosClientObj> &dataMapping, std::vector<RequestUriObj> &uriList);
60     std::unordered_map<std::string, std::string> GetResultMap(
61         std::shared_ptr<DataShare::DataShareResultSet> &resultSet, std::vector<std::string> &queryTabOldPhotosUris);
62     std::shared_ptr<DataShare::DataShareResultSet> GetResultSetFromTabOldPhotos(
63         Uri &uri, const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns, int &errCode);
64 
65 private:
66     const int32_t URI_MAX_SIZE = 100;
67     const std::string COLUMN_FILE_ID = "file_id";
68     const std::string COLUMN_DATA = "data";
69     const std::string COLUMN_OLD_FILE_ID = "old_file_id";
70     const std::string COLUMN_OLD_DATA = "old_data";
71     const std::string COLUMN_DISPLAY_NAME = "display_name";
72     enum { URI_TYPE_DEFAULT, URI_TYPE_ID_LINK, URI_TYPE_PATH, URI_TYPE_ID };
73     MediaLibraryManager &mediaLibraryManager_;
74 };
75 } // namespace OHOS::Media
76 
77 #endif // FRAMEWORKS_INNERKITSIMPL_MEDIA_LIBRARY_TAB_OLD_PHOTOS_CLIENT_H