forked from ondra/colnod-connector
91 lines
2.2 KiB
C++
91 lines
2.2 KiB
C++
#include <utility>
|
|
|
|
#include "subject.h"
|
|
|
|
#include <QJsonArray>
|
|
|
|
Subject::Subject(QString name)
|
|
{
|
|
setName(std::move(name));
|
|
}
|
|
|
|
QString Subject::getEmail() const {
|
|
return attributes["email"].toString();
|
|
}
|
|
|
|
void Subject::fromJSON(const QJsonObject &json) {
|
|
Entity::fromJSON(json);
|
|
|
|
attributes = json.value("attributes").toObject().value("items").toObject();
|
|
for (const auto & attributeType : attributeTypes)
|
|
{
|
|
if (!attributes[attributeType].toString().isEmpty()){
|
|
atr.append(qMakePair(attributeType, attributes[attributeType].toString()));
|
|
}
|
|
}
|
|
const auto &tokenFlagsArray = json.value("tokenFlags").toArray();
|
|
for(const auto &flag : tokenFlagsArray){
|
|
tokenFlags.insert(flag.toString());
|
|
}
|
|
|
|
pin = json.value("pin").toString();
|
|
|
|
const auto &pinFlagsArray = json.value("pinFlags").toArray();
|
|
for(const auto &flag : pinFlagsArray){
|
|
pinFlags.insert(flag.toString());
|
|
}
|
|
|
|
}
|
|
|
|
QJsonObject Subject::toJSON() const {
|
|
QJsonObject json = Entity::toJSON();
|
|
|
|
QJsonObject items({{"items", attributes}});
|
|
json.value("atributes") = items;
|
|
json.value("tokenFlags") = QJsonArray::fromStringList(tokenFlags.toList());
|
|
json.value("pin") = pin;
|
|
json.value("pinFlags") = QJsonArray::fromStringList(pinFlags.toList());
|
|
|
|
return json;
|
|
}
|
|
|
|
const QJsonObject &Subject::getAttributes() const {
|
|
return attributes;
|
|
}
|
|
|
|
void Subject::setAttributes(const QJsonObject &attributes) {
|
|
Subject::attributes = attributes;
|
|
}
|
|
|
|
const QSet<QString> &Subject::getTokenFlags() const {
|
|
return tokenFlags;
|
|
}
|
|
|
|
void Subject::setTokenFlags(const QSet<QString> &tokenFlags) {
|
|
Subject::tokenFlags = tokenFlags;
|
|
}
|
|
|
|
const QString &Subject::getPin() const {
|
|
return pin;
|
|
}
|
|
|
|
void Subject::setPin(const QString &pin) {
|
|
Subject::pin = pin;
|
|
}
|
|
|
|
const QSet<QString> &Subject::getPinFlags() const {
|
|
return pinFlags;
|
|
}
|
|
|
|
void Subject::setPinFlags(const QSet<QString> &pinFlags) {
|
|
Subject::pinFlags = pinFlags;
|
|
}
|
|
|
|
const QList<QPair<QString, QString>> &Subject::getAtr() const {
|
|
return atr;
|
|
}
|
|
|
|
void Subject::setAtr(const QList<QPair<QString, QString>> &atr) {
|
|
this->atr = atr;
|
|
}
|