forked from ondra/colnod-connector
Working version for sync data from colnod to backend DB
This commit is contained in:
parent
a510938999
commit
ce7317c510
@ -1,6 +1,5 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
|
||||||
#include "data.h"
|
|
||||||
#include "datamanager.h"
|
#include "datamanager.h"
|
||||||
#include "colnodapi.h"
|
#include "colnodapi.h"
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@ INCLUDEPATH += $$PWD
|
|||||||
message($$PWD)
|
message($$PWD)
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/colnodapi.cpp \
|
$$PWD/colnodapi.cpp \
|
||||||
$$PWD/data.cpp \
|
|
||||||
$$PWD/databasemanager.cpp \
|
$$PWD/databasemanager.cpp \
|
||||||
$$PWD/datamanager.cpp \
|
$$PWD/datamanager.cpp \
|
||||||
$$PWD/entity.cpp \
|
$$PWD/entity.cpp \
|
||||||
@ -14,7 +13,6 @@ SOURCES += \
|
|||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/colnodapi.h \
|
$$PWD/colnodapi.h \
|
||||||
$$PWD/data.h \
|
|
||||||
$$PWD/databasemanager.h \
|
$$PWD/databasemanager.h \
|
||||||
$$PWD/datamanager.h \
|
$$PWD/datamanager.h \
|
||||||
$$PWD/entity.h \
|
$$PWD/entity.h \
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
#define COLNODAPI_H
|
#define COLNODAPI_H
|
||||||
|
|
||||||
#include "requestmanager.h"
|
#include "requestmanager.h"
|
||||||
#include "data.h"
|
|
||||||
#include "datamanager.h"
|
#include "datamanager.h"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
#include "data.h"
|
|
||||||
|
|
||||||
Data::Data()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
#ifndef DATA_H
|
|
||||||
#define DATA_H
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
#include "subject.h"
|
|
||||||
#include "token.h"
|
|
||||||
#include <qjsondocument.h>
|
|
||||||
#include <qjsonarray.h>
|
|
||||||
|
|
||||||
class Data : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
Data();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DATA_H
|
|
||||||
@ -17,24 +17,49 @@ DatabaseManager::DatabaseManager(QString host, QString dbName, QString user, QSt
|
|||||||
query = QSqlQuery("query", db);
|
query = QSqlQuery("query", db);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseManager::saveSubject(Subject* subject, QString table)
|
bool DatabaseManager::saveSubject(Subject* subject, QString table)
|
||||||
{
|
{
|
||||||
query.prepare("INSERT INTO subject (id, name) VALUES (:id, :name)");
|
QString id = subject->idToStringWithoutBraces();
|
||||||
query.bindValue(":table", table);
|
if (checkIfExists(id, table))
|
||||||
query.bindValue(":id",subject->getId().toString());
|
return false;
|
||||||
qDebug() << subject->getId().toString() << subject->getName();
|
query.prepare(QString("INSERT INTO %1 (id, name, last_update) "
|
||||||
|
"VALUES (:id, :name, :last_update)").arg(table));
|
||||||
|
query.bindValue(":id", id);
|
||||||
query.bindValue(":name", subject->getName());
|
query.bindValue(":name", subject->getName());
|
||||||
|
query.bindValue(":last_update", QDateTime::fromMSecsSinceEpoch(subject->getLastUpdate()).toString("yyyy-MM-dd hh:mm:ss.zzz"));
|
||||||
query.exec();
|
query.exec();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseManager::saveToken(Token* token, QString table)
|
bool DatabaseManager::saveToken(Token* token, QString table)
|
||||||
{
|
{
|
||||||
query.prepare("INSERT INTO :table (id, name) VALUES (:id, :data, :subject_id)");
|
QString id = token->idToStringWithoutBraces();
|
||||||
query.bindValue(":table", table);
|
if (checkIfExists(id, table))
|
||||||
query.bindValue(":id",token->getId());
|
return false;
|
||||||
|
query.prepare(QString("INSERT INTO %1 (id, last_update, token_data, subject_id) "
|
||||||
|
"VALUES (:id, :last_update, :data, :subject_id)").arg(table));
|
||||||
|
query.bindValue(":id", id);
|
||||||
|
query.bindValue(":last_update", QDateTime::fromMSecsSinceEpoch(token->getLastUpdate()).toString("yyyy-MM-dd hh:mm:ss.zzz"));
|
||||||
query.bindValue(":data", token->getTokenData());
|
query.bindValue(":data", token->getTokenData());
|
||||||
query.bindValue(":subject_id", token->getSubjectId());
|
query.bindValue(":subject_id", token->subjectIdToStringWithoutBraces());
|
||||||
query.exec();
|
query.exec();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DatabaseManager::saveSubjectAttribute(Subject *subject, QString table)
|
||||||
|
{
|
||||||
|
auto attributes = subject->getAtr();
|
||||||
|
for (auto attribute : attributes){
|
||||||
|
query.prepare(QString("INSERT INTO %1 (id, attribute_key, attribute_value, subject_id)"
|
||||||
|
"VALUES (:id, :key, :value, :subject_id)").arg(table));
|
||||||
|
query.bindValue(":id", subject->idToStringWithoutBraces() + " " + attribute.first);
|
||||||
|
query.bindValue(":key", attribute.first);
|
||||||
|
query.bindValue(":value", attribute.second);
|
||||||
|
query.bindValue(":subject_id", subject->idToStringWithoutBraces());
|
||||||
|
query.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DatabaseManager::getTestMessage(int id)
|
QString DatabaseManager::getTestMessage(int id)
|
||||||
@ -43,7 +68,6 @@ QString DatabaseManager::getTestMessage(int id)
|
|||||||
query.bindValue(":id", id);
|
query.bindValue(":id", id);
|
||||||
query.exec();
|
query.exec();
|
||||||
query.next();
|
query.next();
|
||||||
//qDebug() << query.value(0);
|
|
||||||
return query.value(0).toString();
|
return query.value(0).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,9 +76,6 @@ void DatabaseManager::createTestRecord(QString msg)
|
|||||||
query.exec("SELECT MAX(id) FROM test");
|
query.exec("SELECT MAX(id) FROM test");
|
||||||
query.next();
|
query.next();
|
||||||
int id = query.value(0).toInt() + 1;
|
int id = query.value(0).toInt() + 1;
|
||||||
//QString statement = QString("INSERT INTO test (id, message) VALUES (%1, '%2')").arg(id).arg(msg);
|
|
||||||
//query.exec(statement);
|
|
||||||
|
|
||||||
query.prepare("INSERT INTO test (id, message) VALUES (:id, :msg)");
|
query.prepare("INSERT INTO test (id, message) VALUES (:id, :msg)");
|
||||||
query.bindValue(":id", id);
|
query.bindValue(":id", id);
|
||||||
query.bindValue(":msg", msg);
|
query.bindValue(":msg", msg);
|
||||||
@ -63,3 +84,13 @@ void DatabaseManager::createTestRecord(QString msg)
|
|||||||
qDebug() << "U inserted new row, id: " << id << "msg: " << getTestMessage(id);
|
qDebug() << "U inserted new row, id: " << id << "msg: " << getTestMessage(id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool DatabaseManager::checkIfExists(QString id, QString table)
|
||||||
|
{
|
||||||
|
query.prepare(QString("SELECT exists(SELECT 1 FROM %1 WHERE id = :id)").arg(table));
|
||||||
|
query.bindValue(":id", id);
|
||||||
|
query.exec();
|
||||||
|
query.next();
|
||||||
|
return query.value(0).toBool();
|
||||||
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "subject.h"
|
#include "subject.h"
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
|
|
||||||
class DatabaseManager : public QObject
|
class DatabaseManager : public QObject
|
||||||
@ -17,8 +18,9 @@ class DatabaseManager : public QObject
|
|||||||
public:
|
public:
|
||||||
DatabaseManager(QString host, QString dbName, QString user, QString password);
|
DatabaseManager(QString host, QString dbName, QString user, QString password);
|
||||||
|
|
||||||
void saveSubject(Subject* subject, QString table);
|
bool saveSubject(Subject* subject, QString table);
|
||||||
void saveToken(Token* token, QString table);
|
bool saveToken(Token* token, QString table);
|
||||||
|
void saveSubjectAttribute(Subject* subject, QString table);
|
||||||
|
|
||||||
QString getTestMessage(int id);
|
QString getTestMessage(int id);
|
||||||
void createTestRecord(QString msg);
|
void createTestRecord(QString msg);
|
||||||
@ -26,6 +28,11 @@ public:
|
|||||||
|
|
||||||
bool getOpened() {return opened;}
|
bool getOpened() {return opened;}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool checkIfExists(QString id, QString table);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSqlDatabase db;
|
QSqlDatabase db;
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
|
|||||||
@ -32,13 +32,24 @@ void DataManager::localSaveTokens(QString response)
|
|||||||
|
|
||||||
void DataManager::pushDataToDB()
|
void DataManager::pushDataToDB()
|
||||||
{
|
{
|
||||||
|
QSqlDatabase::database().transaction();
|
||||||
|
qDebug() << "In progress...";
|
||||||
|
int counter = 0;
|
||||||
for (auto subject : subjects)
|
for (auto subject : subjects)
|
||||||
{
|
{
|
||||||
db->saveSubject(subject, "subject");
|
if (db->saveSubject(subject, "subject"))
|
||||||
|
counter++;
|
||||||
|
db->saveSubjectAttribute(subject, "subject_attribute");
|
||||||
}
|
}
|
||||||
|
qDebug() << counter << " subjects has been updated";
|
||||||
|
counter = 0;
|
||||||
for (auto token : tokens)
|
for (auto token : tokens)
|
||||||
{
|
{
|
||||||
db->saveToken(token, "Subjects");
|
if (db->saveToken(token, "token"))
|
||||||
|
counter++;
|
||||||
}
|
}
|
||||||
|
QSqlDatabase::database().commit();
|
||||||
|
qDebug() << counter << " tokens has been updated";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,6 @@
|
|||||||
#include "databasemanager.h"
|
#include "databasemanager.h"
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <qjsonarray.h>
|
#include <qjsonarray.h>
|
||||||
#include "data.h"
|
|
||||||
|
|
||||||
|
|
||||||
class DataManager : public QObject
|
class DataManager : public QObject
|
||||||
@ -23,6 +22,8 @@ public:
|
|||||||
void pushDataToDB();
|
void pushDataToDB();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DatabaseManager *db = nullptr;
|
DatabaseManager *db = nullptr;
|
||||||
QList<QPointer<Subject>> subjects;
|
QList<QPointer<Subject>> subjects;
|
||||||
|
|||||||
@ -33,6 +33,11 @@ void Entity::setLastUpdate(uint64_t lastUpdate) {
|
|||||||
this->lastUpdate = lastUpdate;
|
this->lastUpdate = lastUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Entity::idToStringWithoutBraces()
|
||||||
|
{
|
||||||
|
return id.toString().mid(1,36);
|
||||||
|
}
|
||||||
|
|
||||||
void Entity::fromJSON(const QJsonObject &json) {
|
void Entity::fromJSON(const QJsonObject &json) {
|
||||||
id = json.value("id").toString();
|
id = json.value("id").toString();
|
||||||
name = json.value("name").toString();
|
name = json.value("name").toString();
|
||||||
|
|||||||
@ -1,37 +1,39 @@
|
|||||||
#ifndef COLNOD_CONNECTOR_ENTITY_H
|
#ifndef COLNOD_CONNECTOR_ENTITY_H
|
||||||
#define COLNOD_CONNECTOR_ENTITY_H
|
#define COLNOD_CONNECTOR_ENTITY_H
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QUuid>
|
#include <QtCore/QUuid>
|
||||||
#include <QtCore/QJsonObject>
|
#include <QtCore/QJsonObject>
|
||||||
|
|
||||||
|
|
||||||
class Entity : public QObject {
|
class Entity : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
using QObject::QObject;
|
using QObject::QObject;
|
||||||
|
|
||||||
const QUuid &getId() const;
|
const QUuid &getId() const;
|
||||||
void setId(const QUuid &id);
|
void setId(const QUuid &id);
|
||||||
|
|
||||||
const QString &getName() const;
|
const QString &getName() const;
|
||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
|
|
||||||
const QString &getDescription() const;
|
const QString &getDescription() const;
|
||||||
void setDescription(const QString &description);
|
void setDescription(const QString &description);
|
||||||
|
|
||||||
uint64_t getLastUpdate() const;
|
uint64_t getLastUpdate() const;
|
||||||
void setLastUpdate(uint64_t lastUpdate);
|
void setLastUpdate(uint64_t lastUpdate);
|
||||||
|
|
||||||
virtual void fromJSON(const QJsonObject &json);
|
QString idToStringWithoutBraces();
|
||||||
virtual QJsonObject toJSON() const;
|
|
||||||
protected:
|
virtual void fromJSON(const QJsonObject &json);
|
||||||
QUuid id;
|
virtual QJsonObject toJSON() const;
|
||||||
QString name;
|
protected:
|
||||||
QString description;
|
QUuid id;
|
||||||
qint64 lastUpdate;
|
QString name;
|
||||||
};
|
QString description;
|
||||||
|
qint64 lastUpdate;
|
||||||
|
};
|
||||||
|
|
||||||
#endif //COLNOD_CONNECTOR_ENTITY_H
|
|
||||||
|
|
||||||
|
#endif //COLNOD_CONNECTOR_ENTITY_H
|
||||||
|
|||||||
@ -11,10 +11,13 @@ QString Subject::getEmail() const {
|
|||||||
void Subject::fromJSON(const QJsonObject &json) {
|
void Subject::fromJSON(const QJsonObject &json) {
|
||||||
Entity::fromJSON(json);
|
Entity::fromJSON(json);
|
||||||
|
|
||||||
//attributes = json["attributes"]["items"].toObject();
|
|
||||||
|
|
||||||
attributes = json.value("attributes").toObject().value("items").toObject();
|
attributes = json.value("attributes").toObject().value("items").toObject();
|
||||||
|
for (int i = 0; i < attributeTypes->length(); i++)
|
||||||
|
{
|
||||||
|
if (!attributes[attributeTypes[i]].toString().isEmpty()){
|
||||||
|
atr.append(qMakePair(attributeTypes[i], attributes[attributeTypes[i]].toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
const auto &tokenFlagsArray = json.value("tokenFlags").toArray();
|
const auto &tokenFlagsArray = json.value("tokenFlags").toArray();
|
||||||
for(const auto &flag : tokenFlagsArray){
|
for(const auto &flag : tokenFlagsArray){
|
||||||
tokenFlags.insert(flag.toString());
|
tokenFlags.insert(flag.toString());
|
||||||
@ -72,3 +75,11 @@ const QSet<QString> &Subject::getPinFlags() const {
|
|||||||
void Subject::setPinFlags(const QSet<QString> &pinFlags) {
|
void Subject::setPinFlags(const QSet<QString> &pinFlags) {
|
||||||
Subject::pinFlags = 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;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,35 +1,46 @@
|
|||||||
#ifndef COLNOD_CONNECTOR_SUBJECT_H
|
#ifndef COLNOD_CONNECTOR_SUBJECT_H
|
||||||
#define COLNOD_CONNECTOR_SUBJECT_H
|
#define COLNOD_CONNECTOR_SUBJECT_H
|
||||||
|
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
#include "entity.h"
|
#include "entity.h"
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QPointer>
|
||||||
class Subject : public Entity {
|
#include <QPair>
|
||||||
|
|
||||||
public:
|
class Subject : public Entity {
|
||||||
using Entity::Entity;
|
|
||||||
|
public:
|
||||||
QString getEmail() const;
|
using Entity::Entity;
|
||||||
|
|
||||||
const QJsonObject &getAttributes() const;
|
QString getEmail() const;
|
||||||
void setAttributes(const QJsonObject &attributes);
|
|
||||||
const QSet<QString> &getTokenFlags() const;
|
const QJsonObject &getAttributes() const;
|
||||||
void setTokenFlags(const QSet<QString> &tokenFlags);
|
void setAttributes(const QJsonObject &attributes);
|
||||||
const QString &getPin() const;
|
const QSet<QString> &getTokenFlags() const;
|
||||||
void setPin(const QString &pin);
|
void setTokenFlags(const QSet<QString> &tokenFlags);
|
||||||
const QSet<QString> &getPinFlags() const;
|
const QString &getPin() const;
|
||||||
void setPinFlags(const QSet<QString> &pinFlags);
|
void setPin(const QString &pin);
|
||||||
|
const QSet<QString> &getPinFlags() const;
|
||||||
void fromJSON(const QJsonObject &json) override;
|
void setPinFlags(const QSet<QString> &pinFlags);
|
||||||
QJsonObject toJSON() const override;
|
// const QList<QPointer<Attribute>> &getAtr() const;
|
||||||
protected:
|
// void setAtr(const QList<QPointer<Attribute>> &atr);
|
||||||
QJsonObject attributes;
|
|
||||||
QSet<QString> tokenFlags;
|
const QList<QPair<QString, QString>> &getAtr() const;
|
||||||
QString pin;
|
void setAtr(const QList<QPair<QString, QString>> &atr);
|
||||||
QSet<QString> pinFlags;
|
|
||||||
};
|
void fromJSON(const QJsonObject &json) override;
|
||||||
|
QJsonObject toJSON() const override;
|
||||||
|
protected:
|
||||||
#endif //COLNOD_CONNECTOR_SUBJECT_H
|
QJsonObject attributes;
|
||||||
|
QSet<QString> tokenFlags;
|
||||||
|
QString pin;
|
||||||
|
QSet<QString> pinFlags;
|
||||||
|
//QList<QPointer<Attribute>> atr;
|
||||||
|
QList<QPair<QString, QString>> atr;
|
||||||
|
const QString attributeTypes[6] = {"Jmeno", "Prijmeni", "ProfilParking", "Spolecnost", "Profil", "spz"};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //COLNOD_CONNECTOR_SUBJECT_H
|
||||||
|
|||||||
@ -106,3 +106,7 @@ const QUuid &Token::getSubjectId() const {
|
|||||||
void Token::setSubjectId(const QUuid &subjectId) {
|
void Token::setSubjectId(const QUuid &subjectId) {
|
||||||
Token::subjectId = subjectId;
|
Token::subjectId = subjectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Token::subjectIdToStringWithoutBraces(){
|
||||||
|
return subjectId.toString().mid(1,36);
|
||||||
|
}
|
||||||
|
|||||||
@ -1,48 +1,50 @@
|
|||||||
#ifndef COLNOD_CONNECTOR_TOKEN_H
|
#ifndef COLNOD_CONNECTOR_TOKEN_H
|
||||||
#define COLNOD_CONNECTOR_TOKEN_H
|
#define COLNOD_CONNECTOR_TOKEN_H
|
||||||
|
|
||||||
#include "entity.h"
|
#include "entity.h"
|
||||||
|
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
|
|
||||||
class Token : public Entity {
|
class Token : public Entity {
|
||||||
public:
|
public:
|
||||||
// using Entity::Entity;
|
// using Entity::Entity;
|
||||||
|
|
||||||
const QString &getTokenType() const;
|
const QString &getTokenType() const;
|
||||||
void setTokenType(const QString &tokenType);
|
void setTokenType(const QString &tokenType);
|
||||||
int getTokenBits() const;
|
int getTokenBits() const;
|
||||||
void setTokenBits(int tokenBits);
|
void setTokenBits(int tokenBits);
|
||||||
const QString &getTokenData() const;
|
const QString &getTokenData() const;
|
||||||
void setTokenData(const QString &tokenData);
|
void setTokenData(const QString &tokenData);
|
||||||
qint64 getValidFrom() const;
|
qint64 getValidFrom() const;
|
||||||
void setValidFrom(qint64 validFrom);
|
void setValidFrom(qint64 validFrom);
|
||||||
qint64 getValidTo() const;
|
qint64 getValidTo() const;
|
||||||
void setValidTo(qint64 validTo);
|
void setValidTo(qint64 validTo);
|
||||||
int getTimeToLive() const;
|
int getTimeToLive() const;
|
||||||
void setTimeToLive(int timeToLive);
|
void setTimeToLive(int timeToLive);
|
||||||
int getAuthErrors() const;
|
int getAuthErrors() const;
|
||||||
void setAuthErrors(int authErrors);
|
void setAuthErrors(int authErrors);
|
||||||
const QSet<QString> &getFlags() const;
|
const QSet<QString> &getFlags() const;
|
||||||
void setFlags(const QSet<QString> &flags);
|
void setFlags(const QSet<QString> &flags);
|
||||||
const QUuid &getSubjectId() const;
|
const QUuid &getSubjectId() const;
|
||||||
void setSubjectId(const QUuid &subjectId);
|
void setSubjectId(const QUuid &subjectId);
|
||||||
|
|
||||||
|
QString subjectIdToStringWithoutBraces();
|
||||||
void fromJSON(const QJsonObject &json) override;
|
|
||||||
QJsonObject toJSON() const override;
|
|
||||||
protected:
|
void fromJSON(const QJsonObject &json) override;
|
||||||
QString tokenType;
|
QJsonObject toJSON() const override;
|
||||||
int tokenBits;
|
protected:
|
||||||
QString tokenData;
|
QString tokenType;
|
||||||
qint64 validFrom;
|
int tokenBits;
|
||||||
qint64 validTo;
|
QString tokenData;
|
||||||
int timeToLive;
|
qint64 validFrom;
|
||||||
int authErrors;
|
qint64 validTo;
|
||||||
QSet<QString> flags;
|
int timeToLive;
|
||||||
QUuid subjectId;
|
int authErrors;
|
||||||
};
|
QSet<QString> flags;
|
||||||
|
QUuid subjectId;
|
||||||
|
};
|
||||||
#endif //COLNOD_CONNECTOR_TOKEN_H
|
|
||||||
|
|
||||||
|
#endif //COLNOD_CONNECTOR_TOKEN_H
|
||||||
|
|||||||
@ -18,13 +18,14 @@ void UnitTest::loginSuccessfully()
|
|||||||
//POST request w/o datas
|
//POST request w/o datas
|
||||||
void UnitTest::getSubjects()
|
void UnitTest::getSubjects()
|
||||||
{
|
{
|
||||||
|
Response* response = new Response;
|
||||||
RequestManager* testAccess = new RequestManager();
|
RequestManager* testAccess = new RequestManager();
|
||||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||||
testAccess->getSubjects();
|
response = testAccess->getSubjects();
|
||||||
spy.wait();
|
spy.wait();
|
||||||
QVERIFY(spy.isValid());
|
QVERIFY(spy.isValid());
|
||||||
QCOMPARE(spy.count(), 1);
|
QCOMPARE(spy.count(), 1);
|
||||||
QString json = testAccess->getResponse();
|
QString json = response->reply->readAll();
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
||||||
QVERIFY(doc.isObject());
|
QVERIFY(doc.isObject());
|
||||||
QVERIFY2(doc.object().value("items").isArray(), "No parameter 'id' in response");
|
QVERIFY2(doc.object().value("items").isArray(), "No parameter 'id' in response");
|
||||||
@ -35,14 +36,15 @@ void UnitTest::getSubjects()
|
|||||||
|
|
||||||
void UnitTest::getTokens()
|
void UnitTest::getTokens()
|
||||||
{
|
{
|
||||||
|
Response* response = new Response;
|
||||||
RequestManager* testAccess = new RequestManager();
|
RequestManager* testAccess = new RequestManager();
|
||||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||||
testAccess->getTokens();
|
response = testAccess->getTokens();
|
||||||
QCOMPARE(spy.count(), 0);
|
QCOMPARE(spy.count(), 0);
|
||||||
spy.wait();
|
spy.wait();
|
||||||
QVERIFY(spy.isValid());
|
QVERIFY(spy.isValid());
|
||||||
QCOMPARE(spy.count(), 1);
|
QCOMPARE(spy.count(), 1);
|
||||||
QString json = testAccess->getResponse();
|
QString json = response->reply->readAll();
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
||||||
QVERIFY(doc.isObject());
|
QVERIFY(doc.isObject());
|
||||||
QVERIFY2(doc.object().value("items").isArray(), "No parameter 'id' in response");
|
QVERIFY2(doc.object().value("items").isArray(), "No parameter 'id' in response");
|
||||||
@ -52,16 +54,17 @@ void UnitTest::getTokens()
|
|||||||
|
|
||||||
void UnitTest::getTokenSubject()
|
void UnitTest::getTokenSubject()
|
||||||
{
|
{
|
||||||
|
Response* response = new Response;
|
||||||
RequestManager* testAccess = new RequestManager();
|
RequestManager* testAccess = new RequestManager();
|
||||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||||
testAccess->getTokenSubject();
|
response = testAccess->getTokenSubject();
|
||||||
QCOMPARE(spy.count(), 0);
|
QCOMPARE(spy.count(), 0);
|
||||||
spy.wait();
|
spy.wait();
|
||||||
QVERIFY(spy.isValid());
|
QVERIFY(spy.isValid());
|
||||||
QCOMPARE(spy.count(), 1);
|
QCOMPARE(spy.count(), 1);
|
||||||
QString response = testAccess->getResponse();
|
QString json = response->reply->readAll();
|
||||||
qDebug() << response;
|
qDebug() << json;
|
||||||
QVERIFY(!response.isEmpty());
|
QVERIFY(!json.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnitTest::subjectJSONParser()
|
void UnitTest::subjectJSONParser()
|
||||||
@ -79,13 +82,13 @@ void UnitTest::subjectJSONParser()
|
|||||||
QJsonObject obj = doc.object();
|
QJsonObject obj = doc.object();
|
||||||
QJsonArray arr = obj["items"].toArray();
|
QJsonArray arr = obj["items"].toArray();
|
||||||
*/
|
*/
|
||||||
|
Response* response = new Response;
|
||||||
RequestManager* testAccess = new RequestManager();
|
RequestManager* testAccess = new RequestManager();
|
||||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||||
testAccess->getSubjects();
|
response = testAccess->getSubjects();
|
||||||
spy.wait();
|
spy.wait();
|
||||||
QString response = testAccess->getResponse();
|
QString json = response->reply->readAll();
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8());
|
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
||||||
QJsonArray arr = doc.object()["items"].toArray();
|
QJsonArray arr = doc.object()["items"].toArray();
|
||||||
auto testSubject = new Subject();
|
auto testSubject = new Subject();
|
||||||
testSubject->fromJSON(arr[1].toObject());
|
testSubject->fromJSON(arr[1].toObject());
|
||||||
@ -95,12 +98,13 @@ void UnitTest::subjectJSONParser()
|
|||||||
|
|
||||||
void UnitTest::tokenJSONParser()
|
void UnitTest::tokenJSONParser()
|
||||||
{
|
{
|
||||||
|
Response* response = new Response;
|
||||||
RequestManager* testAccess = new RequestManager();
|
RequestManager* testAccess = new RequestManager();
|
||||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||||
testAccess->getTokens();
|
response = testAccess->getTokens();
|
||||||
spy.wait();
|
spy.wait();
|
||||||
QString response = testAccess->getResponse();
|
QString json = response->reply->readAll();
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8());
|
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
||||||
QJsonArray arr = doc.object()["items"].toArray();
|
QJsonArray arr = doc.object()["items"].toArray();
|
||||||
auto testToken = new Token();
|
auto testToken = new Token();
|
||||||
testToken->fromJSON(arr[5].toObject());
|
testToken->fromJSON(arr[5].toObject());
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
#include "databasemanager.h"
|
#include "databasemanager.h"
|
||||||
#include <QSslSocket>
|
#include <QSslSocket>
|
||||||
#include "datamanager.h"
|
#include "datamanager.h"
|
||||||
|
#include "response.h"
|
||||||
|
|
||||||
|
|
||||||
class UnitTest : public QObject
|
class UnitTest : public QObject
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user