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
|
||||
message($$PWD)
|
||||
SOURCES += \
|
||||
$$PWD/data.cpp \
|
||||
$$PWD/databasemanager.cpp \
|
||||
$$PWD/dataprocessor.cpp \
|
||||
$$PWD/entity.cpp \
|
||||
@ -10,6 +11,7 @@ SOURCES += \
|
||||
$$PWD/token.cpp
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/data.h \
|
||||
$$PWD/databasemanager.h \
|
||||
$$PWD/dataprocessor.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"
|
||||
|
||||
DataProcessor::DataProcessor()
|
||||
DataProcessor::DataProcessor(Data *data)
|
||||
{
|
||||
|
||||
db = new DatabaseManager("192.168.1.94", "deloitte", "postgres", "34rjkciea12");
|
||||
reqMan = new RequestManager;
|
||||
reqMan = new RequestManager(data);
|
||||
dataToProcess = data;
|
||||
}
|
||||
|
||||
void DataProcessor::processSubjects()
|
||||
@ -16,8 +17,6 @@ void DataProcessor::processSubjects()
|
||||
prepareSubjectJson(reqMan->getResponse());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
QUuid DataProcessor::getSubjectId(const QString &email) const
|
||||
{
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
#include "databasemanager.h"
|
||||
#include <QJsonDocument>
|
||||
#include <qjsonarray.h>
|
||||
|
||||
#include "data.h"
|
||||
|
||||
|
||||
class DataProcessor : public QObject
|
||||
@ -16,7 +16,7 @@ class DataProcessor : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DataProcessor();
|
||||
DataProcessor(Data *data);
|
||||
|
||||
void processSubjects();
|
||||
|
||||
@ -31,10 +31,12 @@ private slots:
|
||||
void prepareSubjectJson(QString json);
|
||||
|
||||
private:
|
||||
RequestManager *reqMan;
|
||||
DatabaseManager *db;
|
||||
RequestManager *reqMan = nullptr;
|
||||
DatabaseManager *db = nullptr;
|
||||
QJsonArray subjectArr;
|
||||
|
||||
Data *dataToProcess = nullptr;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
#include "requestmanager.h"
|
||||
|
||||
RequestManager::RequestManager()
|
||||
RequestManager::RequestManager(Data *data)
|
||||
{
|
||||
manager = new QNetworkAccessManager();
|
||||
token = "";
|
||||
loginStatus = false; //should be false, true for testing request header
|
||||
|
||||
|
||||
this->data = data;
|
||||
/*
|
||||
QFile configFile(QDir::current().filePath("config.json"));
|
||||
if (!configFile.open(QIODevice::ReadOnly)) {
|
||||
@ -32,8 +31,8 @@ void RequestManager::login(QString host, QString username, QString password)
|
||||
request.setUrl(host + "/AaaManager/authSession");
|
||||
request.setRawHeader("Authorization", authHeader.toLocal8Bit());
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json; charset=UTF-8");
|
||||
QJsonDocument jsonDocument;
|
||||
|
||||
QJsonDocument jsonDocument;
|
||||
jsonDocument.setObject(reqBody);
|
||||
QNetworkReply* reply = manager->post(request, jsonDocument.toJson());
|
||||
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(host, user, password);
|
||||
|
||||
QEventLoop loop;
|
||||
QObject::connect(this, &RequestManager::successLogin, &loop, &QEventLoop::quit);
|
||||
loop.exec();
|
||||
}
|
||||
|
||||
//
|
||||
//host = config.object()["host"].toString();
|
||||
//
|
||||
|
||||
QNetworkRequest request;
|
||||
request.setUrl(host + endpoint);
|
||||
qDebug() << "Auth: " << authHeader;
|
||||
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());
|
||||
|
||||
//
|
||||
//QEventLoop loop;
|
||||
//QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||
// loop.exec();
|
||||
//
|
||||
|
||||
QObject::connect(reply, &QNetworkReply::finished, [=]() {
|
||||
if (reply->error())
|
||||
{
|
||||
qDebug() << reply->errorString();
|
||||
qDebug() << reply->readAll();
|
||||
loginStatus = false;
|
||||
getRequest(endpoint);
|
||||
//getRequest(endpoint);
|
||||
return;
|
||||
}
|
||||
qDebug() << reply->rawHeaderPairs();
|
||||
qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
||||
jsonResponse = reply->readAll();
|
||||
emit responseReady();
|
||||
});
|
||||
|
||||
@ -24,13 +24,14 @@
|
||||
#include "databasemanager.h"
|
||||
#include "token.h"
|
||||
#include "subject.h"
|
||||
#include "data.h"
|
||||
|
||||
class RequestManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RequestManager();
|
||||
RequestManager(Data *data);
|
||||
void getSubjects();
|
||||
void login(QString endpoint, QString username, QString password);
|
||||
void getRequest(QString endpoint);
|
||||
@ -58,7 +59,7 @@ signals:
|
||||
|
||||
|
||||
private:
|
||||
QNetworkAccessManager* manager;
|
||||
QNetworkAccessManager* manager = nullptr;
|
||||
QJsonDocument config;
|
||||
QString authHeader;
|
||||
QString host = "https://192.168.1.3:8443";
|
||||
@ -69,6 +70,7 @@ private:
|
||||
QString token;
|
||||
QString jsonResponse;
|
||||
bool loginStatus;
|
||||
Data *data = nullptr;
|
||||
|
||||
|
||||
};
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
|
||||
void UnitTest::loginSuccessfully()
|
||||
{
|
||||
RequestManager* testAccess = new RequestManager();
|
||||
Data *data = new Data();
|
||||
RequestManager* testAccess = new RequestManager(data);
|
||||
QJsonDocument config = testAccess->getConfig();
|
||||
QSignalSpy spy(testAccess, SIGNAL(successLogin()));
|
||||
testAccess->login(host, email, password);
|
||||
@ -18,7 +19,8 @@ void UnitTest::loginSuccessfully()
|
||||
//POST request w/o datas
|
||||
void UnitTest::getSubjects()
|
||||
{
|
||||
RequestManager* testAccess = new RequestManager();
|
||||
Data *data = new Data();
|
||||
RequestManager* testAccess = new RequestManager(data);
|
||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||
testAccess->getRequest("/SubjectManager/getSubjects");
|
||||
spy.wait();
|
||||
@ -36,7 +38,8 @@ void UnitTest::getSubjects()
|
||||
|
||||
void UnitTest::getTokens()
|
||||
{
|
||||
RequestManager* testAccess = new RequestManager();
|
||||
Data *data = new Data();
|
||||
RequestManager* testAccess = new RequestManager(data);
|
||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||
testAccess->getRequest("/TokenManager/getTokens");
|
||||
QCOMPARE(spy.count(), 0);
|
||||
@ -48,7 +51,8 @@ void UnitTest::getTokens()
|
||||
|
||||
void UnitTest::getTokensOpenManager()
|
||||
{
|
||||
RequestManager* testAccess = new RequestManager();
|
||||
Data *data = new Data();
|
||||
RequestManager* testAccess = new RequestManager(data);
|
||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||
testAccess->getRequest("/OpenManager/getTokenSubject");
|
||||
QCOMPARE(spy.count(), 0);
|
||||
@ -76,10 +80,11 @@ void UnitTest::subjectJSONParser()
|
||||
QJsonArray arr = obj["items"].toArray();
|
||||
*/
|
||||
QVERIFY(true);
|
||||
return;
|
||||
//return;
|
||||
|
||||
|
||||
RequestManager* testAccess = new RequestManager();
|
||||
Data *data = new Data();
|
||||
RequestManager* testAccess = new RequestManager(data);
|
||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||
testAccess->getRequest("/SubjectManager/getSubjects");
|
||||
spy.wait();
|
||||
@ -94,7 +99,8 @@ return;
|
||||
|
||||
void UnitTest::tokenJSONParser()
|
||||
{
|
||||
RequestManager* testAccess = new RequestManager();
|
||||
Data *data = new Data();
|
||||
RequestManager* testAccess = new RequestManager(data);
|
||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||
testAccess->getRequest("/TokenManager/getTokens");
|
||||
spy.wait();
|
||||
@ -132,15 +138,6 @@ void UnitTest::debugConnection()
|
||||
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\"}";
|
||||
/*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();
|
||||
ssl.write(tmp.toUtf8());
|
||||
QString data;
|
||||
@ -153,15 +150,6 @@ void UnitTest::debugConnection()
|
||||
QString tkn = data.mid( index + 5, 36);
|
||||
tkn = 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";
|
||||
QFile file("output1234.txt");
|
||||
file.open(QIODevice::ReadWrite);
|
||||
@ -171,8 +159,9 @@ void UnitTest::debugConnection()
|
||||
qDebug().noquote() << tmp.toUtf8();
|
||||
ssl.write(tmp.toUtf8());
|
||||
while (ssl.waitForReadyRead())
|
||||
{
|
||||
qDebug() << ssl.readAll().data();
|
||||
|
||||
}
|
||||
qDebug() << ssl.errorString();
|
||||
|
||||
QVERIFY(true);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user