• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_postal_data.h"
16 
17 #include "telephony_errors.h"
18 #include "telephony_log_wrapper.h"
19 
20 namespace OHOS {
21 namespace Telephony {
22 namespace {
23 constexpr int32_t ADDR_MAX_DATA_SIZE = 7;
24 } // namespace
25 
BuildValuesBucket(OHOS::DataShare::DataShareValuesBucket & valuesBucket)26 int32_t VCardPostalData::BuildValuesBucket(OHOS::DataShare::DataShareValuesBucket &valuesBucket)
27 {
28     valuesBucket.Put(ContactData::TYPE_ID, TypeId::POSTAL_ADDRESS);
29     valuesBucket.Put(ContactData::POBOX, pobox_);
30     valuesBucket.Put(ContactData::POSTCODE, postCode_);
31     valuesBucket.Put(ContactData::REGION, region_);
32     valuesBucket.Put(ContactData::STREET, street_);
33     valuesBucket.Put(ContactData::COUNTRY, country_);
34     valuesBucket.Put(ContactData::CITY, city_);
35     valuesBucket.Put(ContactData::LABEL_ID, labelId_);
36     valuesBucket.Put(ContactData::LABEL_NAME, labelName_);
37     valuesBucket.Put(ContactData::DETAIL_INFO, postalAddress_);
38     return TELEPHONY_SUCCESS;
39 }
40 
BuildData(std::shared_ptr<DataShare::DataShareResultSet> resultSet)41 int32_t VCardPostalData::BuildData(std::shared_ptr<DataShare::DataShareResultSet> resultSet)
42 {
43     if (resultSet == nullptr) {
44         return TELEPHONY_ERROR;
45     }
46     int32_t index;
47     resultSet->GetColumnIndex(ContactData::POBOX, index);
48     resultSet->GetString(index, pobox_);
49     resultSet->GetColumnIndex(ContactData::POSTCODE, index);
50     resultSet->GetString(index, postCode_);
51     resultSet->GetColumnIndex(ContactData::REGION, index);
52     resultSet->GetString(index, region_);
53     resultSet->GetColumnIndex(ContactData::STREET, index);
54     resultSet->GetString(index, street_);
55     resultSet->GetColumnIndex(ContactData::COUNTRY, index);
56     resultSet->GetString(index, country_);
57     resultSet->GetColumnIndex(ContactData::CITY, index);
58     resultSet->GetString(index, city_);
59     resultSet->GetColumnIndex(ContactData::LABEL_ID, index);
60     resultSet->GetString(index, labelId_);
61     resultSet->GetColumnIndex(ContactData::LABEL_NAME, index);
62     resultSet->GetString(index, labelName_);
63     resultSet->GetColumnIndex(ContactData::DETAIL_INFO, index);
64     resultSet->GetString(index, postalAddress_);
65     return TELEPHONY_SUCCESS;
66 }
67 
InitPostalData(std::vector<std::string> propValueList,int32_t type,std::string label)68 void VCardPostalData::InitPostalData(std::vector<std::string> propValueList, int32_t type, std::string label)
69 {
70     std::vector<std::string> dataArray(ADDR_MAX_DATA_SIZE, "");
71     int32_t size = static_cast<int32_t>(propValueList.size());
72     if (size > ADDR_MAX_DATA_SIZE) {
73         size = ADDR_MAX_DATA_SIZE;
74     }
75     int32_t i = 0;
76     for (std::string addressElement : propValueList) {
77         dataArray[i] = addressElement;
78         if (++i >= size) {
79             break;
80         }
81     }
82     while (i < ADDR_MAX_DATA_SIZE) {
83         dataArray[i++] = "";
84     }
85     pobox_ = dataArray[POBOX_VALUE_INDEX];
86     postalAddress_ = dataArray[POSTAL_ADDRESS_VALUE_INDEX];
87     street_ = dataArray[STREET_VALUE_INDEX];
88     city_ = dataArray[CITY_VALUE_INDEX];
89     region_ = dataArray[REGION_VALUE_INDEX];
90     postCode_ = dataArray[POSTCODE_VALUE_INDEX];
91     country_ = dataArray[COUNTRY_VALUE_INDEX];
92     labelId_ = std::to_string(type);
93     labelName_ = label;
94 }
95 
GetPOBox()96 std::string VCardPostalData::GetPOBox()
97 {
98     return pobox_;
99 }
100 
SetPOBox(const std::string & pobox)101 void VCardPostalData::SetPOBox(const std::string &pobox)
102 {
103     pobox_ = pobox;
104 }
105 
GetPostCode()106 std::string VCardPostalData::GetPostCode()
107 {
108     return postCode_;
109 }
110 
SetPostCode(const std::string & postCode)111 void VCardPostalData::SetPostCode(const std::string &postCode)
112 {
113     postCode_ = postCode;
114 }
115 
GetRegion()116 std::string VCardPostalData::GetRegion()
117 {
118     return region_;
119 }
120 
SetRegion(const std::string & region)121 void VCardPostalData::SetRegion(const std::string &region)
122 {
123     region_ = region;
124 }
125 
GetCountry()126 std::string VCardPostalData::GetCountry()
127 {
128     return country_;
129 }
130 
SetCountry(const std::string & country)131 void VCardPostalData::SetCountry(const std::string &country)
132 {
133     country_ = country;
134 }
135 
GetCity()136 std::string VCardPostalData::GetCity()
137 {
138     return city_;
139 }
140 
SetCity(const std::string & city)141 void VCardPostalData::SetCity(const std::string &city)
142 {
143     city_ = city;
144 }
145 
GetStreet()146 std::string VCardPostalData::GetStreet()
147 {
148     return street_;
149 }
150 
SetStreet(const std::string & street)151 void VCardPostalData::SetStreet(const std::string &street)
152 {
153     street_ = street;
154 }
155 
GetNeighborhood()156 std::string VCardPostalData::GetNeighborhood()
157 {
158     return neighborhood_;
159 }
160 
SetNeighborhood(const std::string & neighborhood)161 void VCardPostalData::SetNeighborhood(const std::string &neighborhood)
162 {
163     neighborhood_ = neighborhood;
164 }
165 
GetPostalAddress()166 std::string VCardPostalData::GetPostalAddress()
167 {
168     return postalAddress_;
169 }
170 
SetPostalAddress(const std::string & postalAddress)171 void VCardPostalData::SetPostalAddress(const std::string &postalAddress)
172 {
173     postalAddress_ = postalAddress;
174 }
175 
GetLabelId()176 std::string VCardPostalData::GetLabelId()
177 {
178     return labelId_;
179 }
180 
SetLabelId(const std::string & labelId)181 void VCardPostalData::SetLabelId(const std::string &labelId)
182 {
183     labelId_ = labelId;
184 }
185 
GetLabelName()186 std::string VCardPostalData::GetLabelName()
187 {
188     return labelName_;
189 }
190 
SetLabelName(const std::string & labelName)191 void VCardPostalData::SetLabelName(const std::string &labelName)
192 {
193     labelName_ = labelName;
194 }
195 
196 } // namespace Telephony
197 } // namespace OHOS
198