Kgapi

organization.cpp
1/*
2 * SPDX-FileCopyrightText: 2021 Daniel Vrátil <dvratil@kde.org>
3 * SPDX-FileCopyrightText: 2022 Claudio Cambra <claudio.cambra@kde.org>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-only
6 * SPDX-License-Identifier: LGPL-3.0-only
7 * SPDX-License-Identifier: LicenseRef-KDE-Accepted-LGPL
8 */
9
10#include "organization.h"
11
12#include "fieldmetadata.h"
13#include "peopleservice.h"
14
15#include <QJsonArray>
16#include <QJsonObject>
17#include <QJsonValue>
18#include <QSharedData>
19
20#include <algorithm>
21
22namespace KGAPI2::People
23{
24class Organization::Private : public QSharedData
25{
26public:
27 explicit Private() = default;
28 Private(const Private &) = default;
29 Private(Private &&) noexcept = delete;
30 Private &operator=(const Private &) = delete;
31 Private &operator=(Private &&) noexcept = delete;
32 ~Private() = default;
33
34 bool operator==(const Private &other) const
35 {
36 return location == other.location && title == other.title && type == other.type && metadata == other.metadata && symbol == other.symbol
37 && formattedType == other.formattedType && name == other.name && current == other.current && costCenter == other.costCenter
38 && department == other.department && domain == other.domain && startDate == other.startDate && jobDescription == other.jobDescription
39 && endDate == other.endDate && phoneticName == other.phoneticName && fullTimeEquivalentMillipercent == other.fullTimeEquivalentMillipercent;
40 }
41
42 bool operator!=(const Private &other) const
43 {
44 return !(*this == other);
45 }
46
47 QString location{};
48 QString title{};
49 QString type{};
50 FieldMetadata metadata{};
51 QString symbol{};
52 QString formattedType{};
53 QString name{};
54 bool current{};
55 bool hasSetCurrent{};
56 QString costCenter{};
57 QString department{};
58 QString domain{};
59 QDate startDate{};
60 QString jobDescription{};
61 QDate endDate{};
62 QString phoneticName{};
63 int fullTimeEquivalentMillipercent{};
64 bool hasSetFullTimeEquivalentMillipercent{};
65};
66
68 : d(new Private)
69{
70}
71
73Organization::Organization(Organization &&) noexcept = default;
74Organization &Organization::operator=(const Organization &) = default;
75Organization &Organization::operator=(Organization &&) noexcept = default;
76Organization::~Organization() = default;
77
78bool Organization::operator==(const Organization &other) const
79{
80 return *d == *other.d;
81}
82
83bool Organization::operator!=(const Organization &other) const
84{
85 return !(*this == other);
86}
87
89{
90 return d->location;
91}
92
94{
95 d->location = value;
96}
98{
99 return d->title;
100}
101
103{
104 d->title = value;
105}
107{
108 return d->type;
109}
110
112{
113 d->type = value;
114}
116{
117 return d->metadata;
118}
119
121{
122 d->metadata = value;
123}
125{
126 return d->symbol;
127}
128
130{
131 d->symbol = value;
132}
134{
135 return d->formattedType;
136}
138{
139 return d->name;
140}
141
143{
144 d->name = value;
145}
147{
148 return d->current;
149}
150
152{
153 d->current = value;
154 d->hasSetCurrent = true;
155}
156
157bool Organization::hasSetCurrent() const
158{
159 return d->hasSetCurrent;
160}
161
163{
164 return d->costCenter;
165}
166
168{
169 d->costCenter = value;
170}
172{
173 return d->department;
174}
175
177{
178 d->department = value;
179}
181{
182 return d->domain;
183}
184
186{
187 d->domain = value;
188}
190{
191 return d->startDate;
192}
193
195{
196 d->startDate = value;
197}
199{
200 return d->jobDescription;
201}
202
204{
205 d->jobDescription = value;
206}
208{
209 return d->endDate;
210}
211
213{
214 d->endDate = value;
215}
217{
218 return d->phoneticName;
219}
220
222{
223 d->phoneticName = value;
224}
226{
227 return d->fullTimeEquivalentMillipercent;
228}
229
231{
232 d->fullTimeEquivalentMillipercent = value;
233 d->hasSetFullTimeEquivalentMillipercent = true;
234}
235
236bool Organization::hasSetFullTimeEquivalentMillipercent() const
237{
238 return d->hasSetFullTimeEquivalentMillipercent;
239}
240
241Organization Organization::fromJSON(const QJsonObject &obj)
242{
243 Organization organization;
244
245 if(!obj.isEmpty()) {
246 const auto metadata = obj.value(QStringLiteral("metadata")).toObject();
247 organization.d->metadata = FieldMetadata::fromJSON(metadata);
248 organization.d->type = obj.value(QStringLiteral("type")).toString();
249 organization.d->formattedType = obj.value(QStringLiteral("formattedType")).toString();
250
251 const auto jsonStartDate = obj.value(QStringLiteral("startDate")).toObject();
252 const auto startYear = jsonStartDate.value(QStringLiteral("year")).toInt();
253 const auto startMonth = jsonStartDate.value(QStringLiteral("month")).toInt();
254 const auto startDay = jsonStartDate.value(QStringLiteral("day")).toInt();
255 organization.d->startDate = QDate(startYear, startMonth, startDay);
256
257 const auto jsonEndDate = obj.value(QStringLiteral("endDate")).toObject();
258 const auto endYear = jsonEndDate.value(QStringLiteral("year")).toInt();
259 const auto endMonth = jsonEndDate.value(QStringLiteral("month")).toInt();
260 const auto endDay = jsonEndDate.value(QStringLiteral("day")).toInt();
261 organization.d->endDate = QDate(endYear, endMonth, endDay);
262
263 organization.d->current = obj.value(QStringLiteral("current")).toBool();
264 organization.d->hasSetCurrent = obj.contains(QStringLiteral("current"));
265 organization.d->name = obj.value(QStringLiteral("name")).toString();
266 organization.d->phoneticName = obj.value(QStringLiteral("phoneticName")).toString();
267 organization.d->department = obj.value(QStringLiteral("department")).toString();
268 organization.d->title = obj.value(QStringLiteral("title")).toString();
269 organization.d->jobDescription = obj.value(QStringLiteral("jobDescription")).toString();
270 organization.d->symbol = obj.value(QStringLiteral("symbol")).toString();
271 organization.d->domain = obj.value(QStringLiteral("domain")).toString();
272 organization.d->location = obj.value(QStringLiteral("location")).toString();
273 organization.d->costCenter = obj.value(QStringLiteral("costCenter")).toString();
274 organization.d->fullTimeEquivalentMillipercent = obj.value(QStringLiteral("fullTimeEquivalentMillipercent")).toInt();
275 organization.d->hasSetFullTimeEquivalentMillipercent = obj.contains(QStringLiteral("fullTimeEquivalentMillipercent"));
276 }
277
278 return organization;
279}
280
281QList<Organization> Organization::fromJSONArray(const QJsonArray &data)
282{
283 QList<Organization> organizations;
284
285 for(const auto &organization : data) {
286 if(organization.isObject()) {
287 const auto objectifiedOrganization = organization.toObject();
288 organizations.append(fromJSON(objectifiedOrganization));
289 }
290 }
291
292 return organizations;
293}
294
295QJsonValue Organization::toJSON() const
296{
297 QJsonObject obj;
298
299 PeopleUtils::addValueToJsonObjectIfValid(obj, "location", d->location);
300 PeopleUtils::addValueToJsonObjectIfValid(obj, "title", d->title);
301 PeopleUtils::addValueToJsonObjectIfValid(obj, "type", d->type);
302 // Skip, field metadata is only useful for receiving -> PeopleUtils::addValueToJsonObjectIfValid(obj, "metadata", d->metadata.toJSON());
303 PeopleUtils::addValueToJsonObjectIfValid(obj, "symbol", d->symbol);
304 // Output only -> PeopleUtils::addValueToJsonObjectIfValid(obj, "formattedType", d->formattedType);
305 PeopleUtils::addValueToJsonObjectIfValid(obj, "name", d->name);
306
307 if (d->hasSetCurrent) {
308 PeopleUtils::addValueToJsonObjectIfValid(obj, "current", d->current);
309 }
310
311 PeopleUtils::addValueToJsonObjectIfValid(obj, "costCenter", d->costCenter);
312 PeopleUtils::addValueToJsonObjectIfValid(obj, "department", d->department);
313 PeopleUtils::addValueToJsonObjectIfValid(obj, "domain", d->domain);
314 PeopleUtils::addValueToJsonObjectIfValid(obj, "jobDescription", d->jobDescription);
315 PeopleUtils::addValueToJsonObjectIfValid(obj, "phoneticName", d->phoneticName);
316
317 if(d->hasSetFullTimeEquivalentMillipercent) {
318 PeopleUtils::addValueToJsonObjectIfValid(obj, "fullTimeEquivalentMillipercent", d->fullTimeEquivalentMillipercent);
319 }
320
321 return obj;
322}
323
324} // namespace KGAPI2::People
Metadata about a field.
A person's past or current organization.
QString department() const
The person's department at the organization.
FieldMetadata metadata() const
Metadata about the organization.
void setDomain(const QString &value)
Sets value of the domain property.
void setName(const QString &value)
Sets value of the name property.
bool current() const
True if the organization is the person's current organization; false if the organization is a past or...
void setType(const QString &value)
Sets value of the type property.
void setJobDescription(const QString &value)
Sets value of the jobDescription property.
QString title() const
The person's job title at the organization.
QString domain() const
The domain name associated with the organization; for example, google.com.
void setTitle(const QString &value)
Sets value of the title property.
void setLocation(const QString &value)
Sets value of the location property.
void setCurrent(bool value)
Sets value of the current property.
void setCostCenter(const QString &value)
Sets value of the costCenter property.
QString jobDescription() const
The person's job description at the organization.
QString phoneticName() const
The phonetic name of the organization.
void setSymbol(const QString &value)
Sets value of the symbol property.
void setStartDate(const QDate &value)
Sets value of the startDate property.
QString type() const
The type of the organization.
QDate endDate() const
The end date when the person left the organization.
Organization()
Constructs a new Organization.
QDate startDate() const
The start date when the person joined the organization.
QString formattedType() const
Output only.
QString name() const
The name of the organization.
void setFullTimeEquivalentMillipercent(int value)
Sets value of the fullTimeEquivalentMillipercent property.
void setMetadata(const FieldMetadata &value)
Sets value of the metadata property.
void setEndDate(const QDate &value)
Sets value of the endDate property.
QString location() const
The location of the organization office the person works at.
QString costCenter() const
The person's cost center at the organization.
void setDepartment(const QString &value)
Sets value of the department property.
void setPhoneticName(const QString &value)
Sets value of the phoneticName property.
int fullTimeEquivalentMillipercent() const
The person's full-time equivalent millipercent within the organization (100000 = 100%).
QString symbol() const
The symbol associated with the organization; for example, a stock ticker symbol, abbreviation,...
bool contains(QLatin1StringView key) const const
bool isEmpty() const const
QJsonValue value(QLatin1StringView key) const const
bool toBool(bool defaultValue) const const
int toInt(int defaultValue) const const
QJsonObject toObject() const const
QString toString() const const
void append(QList< T > &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:11:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.