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 #include "vcard_group_data.h"
16 #include "vcard_rdb_helper.h"
17
18 #include "telephony_errors.h"
19 #include "telephony_log_wrapper.h"
20 #include "telephony_common_utils.h"
21
22 namespace OHOS {
23 namespace Telephony {
24
BuildValuesBucket(OHOS::DataShare::DataShareValuesBucket & valuesBucket)25 int32_t VCardGroupData::BuildValuesBucket(OHOS::DataShare::DataShareValuesBucket &valuesBucket)
26 {
27 valuesBucket.Put(ContactData::TYPE_ID, TypeId::GROUP);
28 valuesBucket.Put(ContactData::DETAIL_INFO, groupId_);
29 return TELEPHONY_SUCCESS;
30 }
31
BuildData(std::shared_ptr<DataShare::DataShareResultSet> resultSet)32 int32_t VCardGroupData::BuildData(std::shared_ptr<DataShare::DataShareResultSet> resultSet)
33 {
34 if (resultSet == nullptr) {
35 return TELEPHONY_ERROR;
36 }
37 int32_t index;
38 std::string groupId;
39 resultSet->GetColumnIndex(ContactData::DETAIL_INFO, index);
40 resultSet->GetString(index, groupId);
41 if (groupId.empty() || !IsValidDecValue(groupId)) {
42 TELEPHONY_LOGE("BuildData groupId is empty or invalid.");
43 return TELEPHONY_ERROR;
44 }
45 groupId_ = std::stoi(groupId);
46 std::vector<std::string> columns;
47 OHOS::DataShare::DataSharePredicates predicates;
48 predicates.EqualTo(Group::GROUP_ID, groupId_);
49 predicates.EqualTo(Group::GROUP_IS_DELETED, 0);
50 std::shared_ptr<DataShare::DataShareResultSet> nameResultSet =
51 VCardRdbHelper::QueryGroupData(columns, predicates);
52 if (nameResultSet == nullptr) {
53 return DB_FAILD;
54 }
55 std::string groupName;
56 if (nameResultSet->GoToFirstRow() == TELEPHONY_ERR_SUCCESS) {
57 int curValueIndex;
58 nameResultSet->GetColumnIndex(Group::GROUP_NAME, curValueIndex);
59 nameResultSet->GetString(curValueIndex, groupName);
60 }
61 nameResultSet->Close();
62 groupName_ = groupName;
63 return TELEPHONY_SUCCESS;
64 }
65
SetGroupName(std::string groupName)66 void VCardGroupData::SetGroupName(std::string groupName)
67 {
68 groupName_ = groupName;
69 }
70
GetGroupName()71 std::string VCardGroupData::GetGroupName()
72 {
73 return groupName_;
74 }
75
SetGroupId(int32_t groupId)76 void VCardGroupData::SetGroupId(int32_t groupId)
77 {
78 groupId_ = groupId;
79 }
80
GetGroupId()81 int32_t VCardGroupData::GetGroupId()
82 {
83 return groupId_;
84 }
85
86 } // namespace Telephony
87 } // namespace OHOS