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 #include "vcard_organization_data.h"
16 
17 #include "telephony_errors.h"
18 
19 namespace OHOS {
20 namespace Telephony {
21 
BuildValuesBucket(OHOS::DataShare::DataShareValuesBucket & valuesBucket)22 int32_t VCardOrganizationData::BuildValuesBucket(OHOS::DataShare::DataShareValuesBucket &valuesBucket)
23 {
24     valuesBucket.Put(ContactData::TYPE_ID, TypeId::ORGANIZATION);
25     if (!company_.empty()) {
26         valuesBucket.Put(ContactData::DETAIL_INFO, company_);
27     }
28     if (!title_.empty()) {
29         valuesBucket.Put(ContactData::POSITION, title_);
30     }
31     return TELEPHONY_SUCCESS;
32 }
33 
BuildData(std::shared_ptr<DataShare::DataShareResultSet> resultSet)34 int32_t VCardOrganizationData::BuildData(std::shared_ptr<DataShare::DataShareResultSet> resultSet)
35 {
36     if (resultSet == nullptr) {
37         return TELEPHONY_ERROR;
38     }
39     int32_t index;
40     resultSet->GetColumnIndex(ContactData::DETAIL_INFO, index);
41     resultSet->GetString(index, company_);
42     resultSet->GetColumnIndex(ContactData::POSITION, index);
43     resultSet->GetString(index, title_);
44     return TELEPHONY_SUCCESS;
45 }
46 
InitOrganizationData(std::string & organization,std::string & departmentName,std::string & company,std::string & title,std::string & phoneticName,int32_t type)47 void VCardOrganizationData::InitOrganizationData(std::string &organization, std::string &departmentName,
48     std::string &company, std::string &title, std::string &phoneticName, int32_t type)
49 {
50     type_ = type;
51     organization_ = organization;
52     departmentName_ = departmentName;
53     phoneticName_ = phoneticName;
54     company_ = company;
55     title_ = title;
56 }
57 
SetOrganization(const std::string & organization)58 void VCardOrganizationData::SetOrganization(const std::string &organization)
59 {
60     organization_ = organization;
61 }
62 
SetDepartmentName(const std::string & departmentName)63 void VCardOrganizationData::SetDepartmentName(const std::string &departmentName)
64 {
65     departmentName_ = departmentName;
66 }
67 
SetTitle(const std::string & title)68 void VCardOrganizationData::SetTitle(const std::string &title)
69 {
70     title_ = title;
71 }
72 
SetPhoneticName(const std::string & phoneticName)73 void VCardOrganizationData::SetPhoneticName(const std::string &phoneticName)
74 {
75     phoneticName_ = phoneticName;
76 }
77 
SetType(int32_t type)78 void VCardOrganizationData::SetType(int32_t type)
79 {
80     type_ = type;
81 }
82 
GetOrganization()83 std::string VCardOrganizationData::GetOrganization()
84 {
85     return organization_;
86 }
87 
GetDepartmentName()88 std::string VCardOrganizationData::GetDepartmentName()
89 {
90     return departmentName_;
91 }
92 
GetTitle()93 std::string VCardOrganizationData::GetTitle()
94 {
95     return title_;
96 }
97 
GetPhoneticName()98 std::string VCardOrganizationData::GetPhoneticName()
99 {
100     return phoneticName_;
101 }
102 
GetType()103 int32_t VCardOrganizationData::GetType()
104 {
105     return type_;
106 }
107 
SetCompany(const std::string & company)108 void VCardOrganizationData::SetCompany(const std::string &company)
109 {
110     company_ = company;
111 }
112 
GetCompany()113 std::string VCardOrganizationData::GetCompany()
114 {
115     return company_;
116 }
117 
118 } // namespace Telephony
119 } // namespace OHOS
120