forked from ondra/colnod-connector
Add class for storing data
This commit is contained in:
parent
dcc88a669b
commit
988e01ef1b
@ -2,6 +2,7 @@ INCLUDEPATH += $$PWD
|
|||||||
#SRC_DIR = $$PWD
|
#SRC_DIR = $$PWD
|
||||||
message($$PWD)
|
message($$PWD)
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
$$PWD/data.cpp \
|
||||||
$$PWD/databasemanager.cpp \
|
$$PWD/databasemanager.cpp \
|
||||||
$$PWD/dataprocessor.cpp \
|
$$PWD/dataprocessor.cpp \
|
||||||
$$PWD/entity.cpp \
|
$$PWD/entity.cpp \
|
||||||
@ -10,6 +11,7 @@ SOURCES += \
|
|||||||
$$PWD/token.cpp
|
$$PWD/token.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
$$PWD/data.h \
|
||||||
$$PWD/databasemanager.h \
|
$$PWD/databasemanager.h \
|
||||||
$$PWD/dataprocessor.h \
|
$$PWD/dataprocessor.h \
|
||||||
$$PWD/entity.h \
|
$$PWD/entity.h \
|
||||||
|
|||||||
6
src/colnod/data.cpp
Normal file
6
src/colnod/data.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "data.h"
|
||||||
|
|
||||||
|
Data::Data()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
22
src/colnod/data.h
Normal file
22
src/colnod/data.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef DATA_H
|
||||||
|
#define DATA_H
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "subject.h"
|
||||||
|
#include "token.h"
|
||||||
|
|
||||||
|
class Data : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Data();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<Subject> subjects;
|
||||||
|
QList<Token> tokens;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DATA_H
|
||||||
@ -1,10 +1,11 @@
|
|||||||
#include "dataprocessor.h"
|
#include "dataprocessor.h"
|
||||||
|
|
||||||
DataProcessor::DataProcessor()
|
DataProcessor::DataProcessor(Data *data)
|
||||||
{
|
{
|
||||||
|
|
||||||
db = new DatabaseManager("192.168.1.94", "deloitte", "postgres", "34rjkciea12");
|
db = new DatabaseManager("192.168.1.94", "deloitte", "postgres", "34rjkciea12");
|
||||||
reqMan = new RequestManager;
|
reqMan = new RequestManager(data);
|
||||||
|
dataToProcess = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataProcessor::processSubjects()
|
void DataProcessor::processSubjects()
|
||||||
@ -16,8 +17,6 @@ void DataProcessor::processSubjects()
|
|||||||
prepareSubjectJson(reqMan->getResponse());
|
prepareSubjectJson(reqMan->getResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
QUuid DataProcessor::getSubjectId(const QString &email) const
|
QUuid DataProcessor::getSubjectId(const QString &email) const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
#include "databasemanager.h"
|
#include "databasemanager.h"
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <qjsonarray.h>
|
#include <qjsonarray.h>
|
||||||
|
#include "data.h"
|
||||||
|
|
||||||
|
|
||||||
class DataProcessor : public QObject
|
class DataProcessor : public QObject
|
||||||
@ -16,7 +16,7 @@ class DataProcessor : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DataProcessor();
|
DataProcessor(Data *data);
|
||||||
|
|
||||||
void processSubjects();
|
void processSubjects();
|
||||||
|
|
||||||
@ -31,10 +31,12 @@ private slots:
|
|||||||
void prepareSubjectJson(QString json);
|
void prepareSubjectJson(QString json);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RequestManager *reqMan;
|
RequestManager *reqMan = nullptr;
|
||||||
DatabaseManager *db;
|
DatabaseManager *db = nullptr;
|
||||||
QJsonArray subjectArr;
|
QJsonArray subjectArr;
|
||||||
|
|
||||||
|
Data *dataToProcess = nullptr;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
#include "requestmanager.h"
|
#include "requestmanager.h"
|
||||||
|
|
||||||
RequestManager::RequestManager()
|
RequestManager::RequestManager(Data *data)
|
||||||
{
|
{
|
||||||
manager = new QNetworkAccessManager();
|
manager = new QNetworkAccessManager();
|
||||||
token = "";
|
token = "";
|
||||||
loginStatus = false; //should be false, true for testing request header
|
loginStatus = false; //should be false, true for testing request header
|
||||||
|
this->data = data;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
QFile configFile(QDir::current().filePath("config.json"));
|
QFile configFile(QDir::current().filePath("config.json"));
|
||||||
if (!configFile.open(QIODevice::ReadOnly)) {
|
if (!configFile.open(QIODevice::ReadOnly)) {
|
||||||
@ -32,8 +31,8 @@ void RequestManager::login(QString host, QString username, QString password)
|
|||||||
request.setUrl(host + "/AaaManager/authSession");
|
request.setUrl(host + "/AaaManager/authSession");
|
||||||
request.setRawHeader("Authorization", authHeader.toLocal8Bit());
|
request.setRawHeader("Authorization", authHeader.toLocal8Bit());
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json; charset=UTF-8");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json; charset=UTF-8");
|
||||||
QJsonDocument jsonDocument;
|
|
||||||
|
|
||||||
|
QJsonDocument jsonDocument;
|
||||||
jsonDocument.setObject(reqBody);
|
jsonDocument.setObject(reqBody);
|
||||||
QNetworkReply* reply = manager->post(request, jsonDocument.toJson());
|
QNetworkReply* reply = manager->post(request, jsonDocument.toJson());
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [=]() {
|
QObject::connect(reply, &QNetworkReply::finished, [=]() {
|
||||||
@ -57,44 +56,24 @@ void RequestManager::getRequest(QString endpoint)
|
|||||||
{
|
{
|
||||||
// login(config.object()["host"].toString(), config.object()["username"].toString(), config.object()["password"].toString());
|
// login(config.object()["host"].toString(), config.object()["username"].toString(), config.object()["password"].toString());
|
||||||
login(host, user, password);
|
login(host, user, password);
|
||||||
|
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
QObject::connect(this, &RequestManager::successLogin, &loop, &QEventLoop::quit);
|
QObject::connect(this, &RequestManager::successLogin, &loop, &QEventLoop::quit);
|
||||||
loop.exec();
|
loop.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
//host = config.object()["host"].toString();
|
|
||||||
//
|
|
||||||
|
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setUrl(host + endpoint);
|
request.setUrl(host + endpoint);
|
||||||
qDebug() << "Auth: " << authHeader;
|
qDebug() << "Auth: " << authHeader;
|
||||||
request.setRawHeader("Authorization", authHeader.toLocal8Bit());
|
request.setRawHeader("Authorization", authHeader.toLocal8Bit());
|
||||||
//request.setRawHeader("User-Agent", "curl/7.65.3");
|
|
||||||
//request.setRawHeader("Connection", "Keep-Alive");
|
|
||||||
//request.setRawHeader("Accept", "*/*");
|
|
||||||
//request.setRawHeader("Accept-Encoding", "*");
|
|
||||||
//request.setRawHeader("Accept-Language", "*");
|
|
||||||
|
|
||||||
QNetworkReply* reply = manager->post(request, QByteArray());
|
QNetworkReply* reply = manager->post(request, QByteArray());
|
||||||
|
|
||||||
//
|
|
||||||
//QEventLoop loop;
|
|
||||||
//QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
|
||||||
// loop.exec();
|
|
||||||
//
|
|
||||||
|
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [=]() {
|
QObject::connect(reply, &QNetworkReply::finished, [=]() {
|
||||||
if (reply->error())
|
if (reply->error())
|
||||||
{
|
{
|
||||||
qDebug() << reply->errorString();
|
qDebug() << reply->errorString();
|
||||||
qDebug() << reply->readAll();
|
|
||||||
loginStatus = false;
|
loginStatus = false;
|
||||||
getRequest(endpoint);
|
//getRequest(endpoint);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qDebug() << reply->rawHeaderPairs();
|
|
||||||
qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
|
||||||
jsonResponse = reply->readAll();
|
jsonResponse = reply->readAll();
|
||||||
emit responseReady();
|
emit responseReady();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -24,13 +24,14 @@
|
|||||||
#include "databasemanager.h"
|
#include "databasemanager.h"
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
#include "subject.h"
|
#include "subject.h"
|
||||||
|
#include "data.h"
|
||||||
|
|
||||||
class RequestManager : public QObject
|
class RequestManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RequestManager();
|
RequestManager(Data *data);
|
||||||
void getSubjects();
|
void getSubjects();
|
||||||
void login(QString endpoint, QString username, QString password);
|
void login(QString endpoint, QString username, QString password);
|
||||||
void getRequest(QString endpoint);
|
void getRequest(QString endpoint);
|
||||||
@ -58,7 +59,7 @@ signals:
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager* manager;
|
QNetworkAccessManager* manager = nullptr;
|
||||||
QJsonDocument config;
|
QJsonDocument config;
|
||||||
QString authHeader;
|
QString authHeader;
|
||||||
QString host = "https://192.168.1.3:8443";
|
QString host = "https://192.168.1.3:8443";
|
||||||
@ -69,6 +70,7 @@ private:
|
|||||||
QString token;
|
QString token;
|
||||||
QString jsonResponse;
|
QString jsonResponse;
|
||||||
bool loginStatus;
|
bool loginStatus;
|
||||||
|
Data *data = nullptr;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
void UnitTest::loginSuccessfully()
|
void UnitTest::loginSuccessfully()
|
||||||
{
|
{
|
||||||
RequestManager* testAccess = new RequestManager();
|
Data *data = new Data();
|
||||||
|
RequestManager* testAccess = new RequestManager(data);
|
||||||
QJsonDocument config = testAccess->getConfig();
|
QJsonDocument config = testAccess->getConfig();
|
||||||
QSignalSpy spy(testAccess, SIGNAL(successLogin()));
|
QSignalSpy spy(testAccess, SIGNAL(successLogin()));
|
||||||
testAccess->login(host, email, password);
|
testAccess->login(host, email, password);
|
||||||
@ -18,7 +19,8 @@ void UnitTest::loginSuccessfully()
|
|||||||
//POST request w/o datas
|
//POST request w/o datas
|
||||||
void UnitTest::getSubjects()
|
void UnitTest::getSubjects()
|
||||||
{
|
{
|
||||||
RequestManager* testAccess = new RequestManager();
|
Data *data = new Data();
|
||||||
|
RequestManager* testAccess = new RequestManager(data);
|
||||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||||
testAccess->getRequest("/SubjectManager/getSubjects");
|
testAccess->getRequest("/SubjectManager/getSubjects");
|
||||||
spy.wait();
|
spy.wait();
|
||||||
@ -36,7 +38,8 @@ void UnitTest::getSubjects()
|
|||||||
|
|
||||||
void UnitTest::getTokens()
|
void UnitTest::getTokens()
|
||||||
{
|
{
|
||||||
RequestManager* testAccess = new RequestManager();
|
Data *data = new Data();
|
||||||
|
RequestManager* testAccess = new RequestManager(data);
|
||||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||||
testAccess->getRequest("/TokenManager/getTokens");
|
testAccess->getRequest("/TokenManager/getTokens");
|
||||||
QCOMPARE(spy.count(), 0);
|
QCOMPARE(spy.count(), 0);
|
||||||
@ -48,7 +51,8 @@ void UnitTest::getTokens()
|
|||||||
|
|
||||||
void UnitTest::getTokensOpenManager()
|
void UnitTest::getTokensOpenManager()
|
||||||
{
|
{
|
||||||
RequestManager* testAccess = new RequestManager();
|
Data *data = new Data();
|
||||||
|
RequestManager* testAccess = new RequestManager(data);
|
||||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||||
testAccess->getRequest("/OpenManager/getTokenSubject");
|
testAccess->getRequest("/OpenManager/getTokenSubject");
|
||||||
QCOMPARE(spy.count(), 0);
|
QCOMPARE(spy.count(), 0);
|
||||||
@ -75,11 +79,12 @@ void UnitTest::subjectJSONParser()
|
|||||||
QJsonObject obj = doc.object();
|
QJsonObject obj = doc.object();
|
||||||
QJsonArray arr = obj["items"].toArray();
|
QJsonArray arr = obj["items"].toArray();
|
||||||
*/
|
*/
|
||||||
QVERIFY(true);
|
QVERIFY(true);
|
||||||
return;
|
//return;
|
||||||
|
|
||||||
|
|
||||||
RequestManager* testAccess = new RequestManager();
|
Data *data = new Data();
|
||||||
|
RequestManager* testAccess = new RequestManager(data);
|
||||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||||
testAccess->getRequest("/SubjectManager/getSubjects");
|
testAccess->getRequest("/SubjectManager/getSubjects");
|
||||||
spy.wait();
|
spy.wait();
|
||||||
@ -94,7 +99,8 @@ return;
|
|||||||
|
|
||||||
void UnitTest::tokenJSONParser()
|
void UnitTest::tokenJSONParser()
|
||||||
{
|
{
|
||||||
RequestManager* testAccess = new RequestManager();
|
Data *data = new Data();
|
||||||
|
RequestManager* testAccess = new RequestManager(data);
|
||||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||||
testAccess->getRequest("/TokenManager/getTokens");
|
testAccess->getRequest("/TokenManager/getTokens");
|
||||||
spy.wait();
|
spy.wait();
|
||||||
@ -132,15 +138,6 @@ void UnitTest::debugConnection()
|
|||||||
qDebug() << ssl.errorString();
|
qDebug() << ssl.errorString();
|
||||||
}
|
}
|
||||||
QString tmp = "POST /AaaManager/authSession HTTP/1.1\r\nHost: 192.168.1.3:8443\r\nAuthorization: Basic c3BhY2V0aTpFN0ZFQTA3REJDODJGQjlCQTM0QjJFNDUzRTJFRkU4OUYwNTgzRTcxODc1NDM1MDdFRjExRTg0NzI2MDcxRkU0Mjg0NDUzNzJGMkU0NkI0NTVFQjBDNzk3NDdDNTFFMzYyRjQwM0NFMzk0NzNBMkE4QzJERkEwQ0U1Qzk4MjZDMA==\r\nUser-Agent: curl/7.65.3\r\nAccept: */*\r\nContent-Type: application/json\r\nContent-Length: 164\r\n\r\n{\"password\":\"E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0\",\"username\":\"spaceti\"}";
|
QString tmp = "POST /AaaManager/authSession HTTP/1.1\r\nHost: 192.168.1.3:8443\r\nAuthorization: Basic c3BhY2V0aTpFN0ZFQTA3REJDODJGQjlCQTM0QjJFNDUzRTJFRkU4OUYwNTgzRTcxODc1NDM1MDdFRjExRTg0NzI2MDcxRkU0Mjg0NDUzNzJGMkU0NkI0NTVFQjBDNzk3NDdDNTFFMzYyRjQwM0NFMzk0NzNBMkE4QzJERkEwQ0U1Qzk4MjZDMA==\r\nUser-Agent: curl/7.65.3\r\nAccept: */*\r\nContent-Type: application/json\r\nContent-Length: 164\r\n\r\n{\"password\":\"E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0\",\"username\":\"spaceti\"}";
|
||||||
/*POST /AaaManager/authSession HTTP/1.1
|
|
||||||
Host: localhost:8080
|
|
||||||
Authorization: Basic c3BhY2V0aTpFN0ZFQTA3REJDODJGQjlCQTM0QjJFNDUzRTJFRkU4OUYwNTgzRTcxODc1NDM1MDdFRjExRTg0NzI2MDcxRkU0Mjg0NDUzNzJGMkU0NkI0NTVFQjBDNzk3NDdDNTFFMzYyRjQwM0NFMzk0NzNBMkE4QzJERkEwQ0U1Qzk4MjZDMA==
|
|
||||||
User-Agent: curl/7.65.3
|
|
||||||
Accept:
|
|
||||||
Content-Type: application/json
|
|
||||||
Content-Length: 164
|
|
||||||
|
|
||||||
{"password":"E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0","username":"spaceti"}*/
|
|
||||||
qDebug().noquote() << tmp.toUtf8();
|
qDebug().noquote() << tmp.toUtf8();
|
||||||
ssl.write(tmp.toUtf8());
|
ssl.write(tmp.toUtf8());
|
||||||
QString data;
|
QString data;
|
||||||
@ -153,15 +150,6 @@ void UnitTest::debugConnection()
|
|||||||
QString tkn = data.mid( index + 5, 36);
|
QString tkn = data.mid( index + 5, 36);
|
||||||
tkn = tkn + ":";
|
tkn = tkn + ":";
|
||||||
qDebug() << "parsed token : " <<tkn;
|
qDebug() << "parsed token : " <<tkn;
|
||||||
/*
|
|
||||||
RequestManager* testAccess = new RequestManager();
|
|
||||||
QJsonDocument config = testAccess->getConfig();
|
|
||||||
QSignalSpy spy(testAccess, SIGNAL(successLogin()));
|
|
||||||
testAccess->login(host, email, password);
|
|
||||||
spy.wait();
|
|
||||||
|
|
||||||
QString token = testAccess->getToken();
|
|
||||||
token = token + ":";*/
|
|
||||||
tmp = "POST /SubjectManager/getSubjects HTTP/1.1\r\nHost: 192.168.1.3:8443\r\nAuthorization: Basic " + tkn.toUtf8().toBase64() + "\r\nUser-Agent: curl/7.65.3\r\nAccept: */*\r\n\r\n";
|
tmp = "POST /SubjectManager/getSubjects HTTP/1.1\r\nHost: 192.168.1.3:8443\r\nAuthorization: Basic " + tkn.toUtf8().toBase64() + "\r\nUser-Agent: curl/7.65.3\r\nAccept: */*\r\n\r\n";
|
||||||
QFile file("output1234.txt");
|
QFile file("output1234.txt");
|
||||||
file.open(QIODevice::ReadWrite);
|
file.open(QIODevice::ReadWrite);
|
||||||
@ -171,8 +159,9 @@ void UnitTest::debugConnection()
|
|||||||
qDebug().noquote() << tmp.toUtf8();
|
qDebug().noquote() << tmp.toUtf8();
|
||||||
ssl.write(tmp.toUtf8());
|
ssl.write(tmp.toUtf8());
|
||||||
while (ssl.waitForReadyRead())
|
while (ssl.waitForReadyRead())
|
||||||
|
{
|
||||||
qDebug() << ssl.readAll().data();
|
qDebug() << ssl.readAll().data();
|
||||||
|
}
|
||||||
qDebug() << ssl.errorString();
|
qDebug() << ssl.errorString();
|
||||||
|
|
||||||
QVERIFY(true);
|
QVERIFY(true);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user