mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 12:00:37 +02:00
clanz and error handling
This commit is contained in:
parent
b405d95320
commit
08afae47aa
@ -31,14 +31,14 @@ void ColnodAPI::downloadData(const qint64 &time)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AuthToken token;
|
AuthToken token;
|
||||||
auto responseData = login->responseData();
|
|
||||||
if (responseData.isEmpty()) {
|
if (checkResponse(login->responseData())) {
|
||||||
qCWarning(colnod) << "empty response data when logging in";
|
qCWarning(colnod) << "empty response data when logging in";
|
||||||
emit downloadDataFinished(nullptr);
|
emit downloadDataFinished(nullptr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
token.fromJson(responseData);
|
token.fromJson(login->responseData());
|
||||||
authToken = token.id();
|
authToken = token.id();
|
||||||
if (authToken.isEmpty()) {
|
if (authToken.isEmpty()) {
|
||||||
qCCritical(colnod) << "Token uuid is empty";
|
qCCritical(colnod) << "Token uuid is empty";
|
||||||
@ -52,11 +52,12 @@ void ColnodAPI::downloadData(const qint64 &time)
|
|||||||
if (!checkRequest(request)) {
|
if (!checkRequest(request)) {
|
||||||
qWarning(colnod) << "ERROR during calling" << request->url() << ", request unsuccessful";
|
qWarning(colnod) << "ERROR during calling" << request->url() << ", request unsuccessful";
|
||||||
mValid = false;
|
mValid = false;
|
||||||
emit downloadDataFinished(nullptr); // TODO: think about it, will the other if passed?
|
emit downloadDataFinished(nullptr);
|
||||||
}
|
}
|
||||||
else if (!checkResponse(request->responseData())) {
|
else if (!checkResponse(request->responseData())) {
|
||||||
qWarning(colnod) << "Data from" << request->url() << "are invalid";
|
qWarning(colnod) << "Data from" << request->url() << "are invalid";
|
||||||
mValid = false;
|
mValid = false;
|
||||||
|
emit downloadDataFinished(nullptr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -99,12 +100,6 @@ void ColnodAPI::downloadData(const qint64 &time)
|
|||||||
|
|
||||||
void ColnodAPI::processData(const std::shared_ptr<Data> &data)
|
void ColnodAPI::processData(const std::shared_ptr<Data> &data)
|
||||||
{
|
{
|
||||||
for (const auto &token : data->updatedTokens) {
|
|
||||||
qInfo(colnod).noquote() << Message::massageTemplate("Updating", "token", "colnod", token->name());
|
|
||||||
}
|
|
||||||
for (const auto &id : data->deletedTokens) {
|
|
||||||
qInfo(colnod).noquote() << Message::massageTemplate("Deleting", "token", "colnod", id);
|
|
||||||
}
|
|
||||||
if (!data->updatedTokens.isEmpty() || !data->deletedTokens.isEmpty()) {
|
if (!data->updatedTokens.isEmpty() || !data->deletedTokens.isEmpty()) {
|
||||||
qInfo(colnod) << dash;
|
qInfo(colnod) << dash;
|
||||||
}
|
}
|
||||||
@ -188,15 +183,18 @@ std::shared_ptr<serversdk::Request> ColnodAPI::setTokens(const QHash<QString, st
|
|||||||
connect(request.get(), &serversdk::Request::finished, [=](){
|
connect(request.get(), &serversdk::Request::finished, [=](){
|
||||||
if (!checkRequest(request)) {
|
if (!checkRequest(request)) {
|
||||||
qCritical(colnod) << "ERROR during calling /TokenManager/setTokens, request unsuccessful. EXIT";
|
qCritical(colnod) << "ERROR during calling /TokenManager/setTokens, request unsuccessful. EXIT";
|
||||||
emit error(); // TODO: retyrn nullptr and check here
|
|
||||||
}
|
}
|
||||||
if (checkResponse(request->responseData())) {
|
if (checkResponse(request->responseData())) {
|
||||||
|
|
||||||
|
for (const auto &token : tokens) {
|
||||||
|
qInfo(colnod).noquote() << Message::massageTemplate("Updating", "token", "colnod", token->name());
|
||||||
|
}
|
||||||
emit partOfDataProcessFinished();
|
emit partOfDataProcessFinished();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qWarning(colnod) << "Tokens wasn't updated";
|
qWarning(colnod) << "Tokens wasn't updated";
|
||||||
mValid = false;
|
mValid = false;
|
||||||
emit partOfDataProcessFinished();
|
emit partOfDataProcessFinished(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return request;
|
return request;
|
||||||
@ -210,15 +208,17 @@ std::shared_ptr<serversdk::Request> ColnodAPI::deleteTokens(const QList<QString>
|
|||||||
connect(request.get(), &serversdk::Request::finished, [=](){
|
connect(request.get(), &serversdk::Request::finished, [=](){
|
||||||
if (!checkRequest(request)) {
|
if (!checkRequest(request)) {
|
||||||
qCritical(colnod) << "ERROR during calling /TokenManager/deleteTokens, request unsuccessful. EXIT";
|
qCritical(colnod) << "ERROR during calling /TokenManager/deleteTokens, request unsuccessful. EXIT";
|
||||||
emit error(); // TODO: return nullptr and check it
|
|
||||||
}
|
}
|
||||||
if (checkResponse(request->responseData())) {
|
if (checkResponse(request->responseData())) {
|
||||||
|
for (const auto &id : ids) {
|
||||||
|
qInfo(colnod).noquote() << Message::massageTemplate("Deleting", "token", "colnod", id);
|
||||||
|
}
|
||||||
emit partOfDataProcessFinished();
|
emit partOfDataProcessFinished();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qWarning(colnod) << "Tokens wasn't deleted";
|
qWarning(colnod) << "Tokens wasn't deleted";
|
||||||
mValid = false;
|
mValid = false;
|
||||||
emit partOfDataProcessFinished();
|
emit partOfDataProcessFinished(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return request;
|
return request;
|
||||||
@ -276,10 +276,13 @@ void ColnodAPI::areDataReady(const std::shared_ptr<Data> &data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColnodAPI::isDataProcessFinished()
|
void ColnodAPI::isDataProcessFinished(bool success)
|
||||||
{
|
{
|
||||||
|
if (!success) {
|
||||||
|
mSuccess = false;
|
||||||
|
}
|
||||||
if (++amountProccessesFinished == 2) {
|
if (++amountProccessesFinished == 2) {
|
||||||
emit dataProcessFinished();
|
emit dataProcessFinished(mSuccess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -66,7 +66,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Q_SLOT void areDataReady(const std::shared_ptr<Data>& data);
|
Q_SLOT void areDataReady(const std::shared_ptr<Data>& data);
|
||||||
Q_SLOT void isDataProcessFinished();
|
Q_SLOT void isDataProcessFinished(bool success);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void saveUpdatedTokens(const std::shared_ptr<Data>& data, const QByteArray &responseData);
|
void saveUpdatedTokens(const std::shared_ptr<Data>& data, const QByteArray &responseData);
|
||||||
@ -84,8 +84,8 @@ private:
|
|||||||
signals:
|
signals:
|
||||||
void downloadDataFinished(std::shared_ptr<Data> = std::shared_ptr<Data>());
|
void downloadDataFinished(std::shared_ptr<Data> = std::shared_ptr<Data>());
|
||||||
void partOfDataReady(std::shared_ptr<Data> = std::shared_ptr<Data>());
|
void partOfDataReady(std::shared_ptr<Data> = std::shared_ptr<Data>());
|
||||||
void partOfDataProcessFinished();
|
void partOfDataProcessFinished(bool success = true);
|
||||||
void dataProcessFinished();
|
void dataProcessFinished(bool success = true);
|
||||||
|
|
||||||
void error();
|
void error();
|
||||||
|
|
||||||
@ -97,6 +97,7 @@ private:
|
|||||||
Timestamp mLastSync;
|
Timestamp mLastSync;
|
||||||
bool mDryMode = false;
|
bool mDryMode = false;
|
||||||
bool mValid = true;
|
bool mValid = true;
|
||||||
|
bool mSuccess = true;
|
||||||
|
|
||||||
QString authToken;
|
QString authToken;
|
||||||
qint16 amountData = 0;
|
qint16 amountData = 0;
|
||||||
|
|||||||
@ -44,7 +44,7 @@ struct PreparedData
|
|||||||
public:
|
public:
|
||||||
PreparedData() = default;
|
PreparedData() = default;
|
||||||
PreparedData(const std::shared_ptr<Data> &database, const std::shared_ptr<Data> &colnod)
|
PreparedData(const std::shared_ptr<Data> &database, const std::shared_ptr<Data> &colnod)
|
||||||
:databaseData(std::move(database)), colnodData(std::move(colnod))
|
:databaseData(database), colnodData(colnod)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -46,17 +46,23 @@ std::shared_ptr<Data> DatabaseAPI::downloadData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
return composeData(updatedQuery, deletedQuery);
|
return composeData(updatedQuery, deletedQuery);
|
||||||
// TODO: why emiting signal??
|
|
||||||
// this can return Strucutre
|
|
||||||
//emit downloadDataFinished(composeData(updatedQuery, deletedQuery));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DatabaseAPI::processData(const std::shared_ptr<Data> &data)
|
bool DatabaseAPI::processData(const std::shared_ptr<Data> &data)
|
||||||
{
|
{
|
||||||
uploadTokens(data->updatedTokens);
|
bool res = true;
|
||||||
uploadSubjects(data->updatedSubjects);
|
if (!uploadTokens(data->updatedTokens)) {
|
||||||
deleteItems(data->deletedTokens, "colnod_token");
|
res = false;
|
||||||
deleteItems(data->deletedSubjects, "colnod_subject");
|
}
|
||||||
|
if (uploadSubjects(data->updatedSubjects)) {
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
|
if (deleteItems(data->deletedTokens, "colnod_token")) {
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
|
if (deleteItems(data->deletedSubjects, "colnod_subject")) {
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
if ( !data->updatedTokens.isEmpty() ||
|
if ( !data->updatedTokens.isEmpty() ||
|
||||||
!data->updatedSubjects.isEmpty() ||
|
!data->updatedSubjects.isEmpty() ||
|
||||||
!data->deletedTokens.isEmpty() ||
|
!data->deletedTokens.isEmpty() ||
|
||||||
@ -70,8 +76,7 @@ bool DatabaseAPI::processData(const std::shared_ptr<Data> &data)
|
|||||||
qInfo(database) << tab << tab << data->deletedSubjects.size() << "SUBJECTS DELETED";
|
qInfo(database) << tab << tab << data->deletedSubjects.size() << "SUBJECTS DELETED";
|
||||||
qInfo(database) << dash;
|
qInfo(database) << dash;
|
||||||
|
|
||||||
// TODO: add error handling
|
return res;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -222,6 +227,7 @@ bool DatabaseAPI::deleteItems(const QList<QString> &ids, const QString &tableNam
|
|||||||
query.bindValue(":now", nowString);
|
query.bindValue(":now", nowString);
|
||||||
if (!executeQuery(query)) {
|
if (!executeQuery(query)) {
|
||||||
qWarning(database) << "ERROR during marking token as deleted:" << id;
|
qWarning(database) << "ERROR during marking token as deleted:" << id;
|
||||||
|
mValid = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -235,7 +241,6 @@ std::shared_ptr<Token> DatabaseAPI::getToken(const QString &id)
|
|||||||
query.bindValue(":id", id);
|
query.bindValue(":id", id);
|
||||||
if (!executeQuery(query)) {
|
if (!executeQuery(query)) {
|
||||||
qCritical(database) << "ERROR during accessing existing tokens. EXIT";
|
qCritical(database) << "ERROR during accessing existing tokens. EXIT";
|
||||||
emit error();
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto list = utils->tableFromQuery<Token>(query);
|
auto list = utils->tableFromQuery<Token>(query);
|
||||||
|
|||||||
@ -13,7 +13,6 @@ class SubjectAttribute : public serversdk::DatabaseTable {
|
|||||||
TABLE_PROPERTY(QString, subjectId, setSubjectId, "")
|
TABLE_PROPERTY(QString, subjectId, setSubjectId, "")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Subject : public serversdk::DatabaseTable {
|
class Subject : public serversdk::DatabaseTable {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
TABLE_PROPERTY(QString, id, setId, QString())
|
TABLE_PROPERTY(QString, id, setId, QString())
|
||||||
@ -24,7 +23,6 @@ class Subject : public serversdk::DatabaseTable {
|
|||||||
TABLE_PROPERTY(QDateTime, lastModified, setLastModified, QDateTime())
|
TABLE_PROPERTY(QDateTime, lastModified, setLastModified, QDateTime())
|
||||||
TABLE_PROPERTY(bool, deleted, setDeleted, false)
|
TABLE_PROPERTY(bool, deleted, setDeleted, false)
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Subject() = default;
|
Subject() = default;
|
||||||
explicit Subject(const QString& name);
|
explicit Subject(const QString& name);
|
||||||
@ -32,7 +30,6 @@ public:
|
|||||||
bool fromJson(const QByteArray &data) override;
|
bool fromJson(const QByteArray &data) override;
|
||||||
QList<std::shared_ptr <SubjectAttribute>> getAttributes();
|
QList<std::shared_ptr <SubjectAttribute>> getAttributes();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<std::shared_ptr <SubjectAttribute>> attributes;
|
QList<std::shared_ptr <SubjectAttribute>> attributes;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -60,7 +60,7 @@ bool SyncManager::startSynchronization()
|
|||||||
// NOW I HAVE DATA FROM DATABASE
|
// NOW I HAVE DATA FROM DATABASE
|
||||||
|
|
||||||
colnod->downloadData(mlastSync.timestamp());
|
colnod->downloadData(mlastSync.timestamp());
|
||||||
connect(colnod.get(), &ColnodAPI::downloadDataFinished, [=](std::shared_ptr<Data> colnodData) {
|
connect(colnod.get(), &ColnodAPI::downloadDataFinished, [=](const std::shared_ptr<Data> &colnodData) {
|
||||||
if (!colnodData) {
|
if (!colnodData) {
|
||||||
qCritical(syncmanager) << "Not possible to get correct data from colnod";
|
qCritical(syncmanager) << "Not possible to get correct data from colnod";
|
||||||
QCoreApplication::exit(-1);
|
QCoreApplication::exit(-1);
|
||||||
@ -90,7 +90,7 @@ bool SyncManager::startSynchronization()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// data is processed to other sides
|
// data is processed to other sides
|
||||||
connect(colnod.get(), &ColnodAPI::dataProcessFinished, [&](bool success){
|
connect(colnod.get(), &ColnodAPI::dataProcessFinished, [&,syncBegin](bool success){
|
||||||
if (!success) {
|
if (!success) {
|
||||||
qCritical(syncmanager) << "Not possible to upload data to colnod";
|
qCritical(syncmanager) << "Not possible to upload data to colnod";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,13 +31,6 @@ private:
|
|||||||
private:
|
private:
|
||||||
void initNewToken(const std::shared_ptr<Token>& token);
|
void initNewToken(const std::shared_ptr<Token>& token);
|
||||||
|
|
||||||
void updateLastUpdate(qint64 syncBegin);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void syncFinished();
|
|
||||||
|
|
||||||
void error();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<ColnodAPI> colnod;
|
std::shared_ptr<ColnodAPI> colnod;
|
||||||
std::shared_ptr<DatabaseAPI> database;
|
std::shared_ptr<DatabaseAPI> database;
|
||||||
|
|||||||
@ -45,6 +45,7 @@ QByteArray Token::jsonData(const QSet<QString> &filters) const
|
|||||||
QJsonDocument doc = QJsonDocument::fromVariant(variantMap);
|
QJsonDocument doc = QJsonDocument::fromVariant(variantMap);
|
||||||
return doc.toJson(QJsonDocument::Compact);
|
return doc.toJson(QJsonDocument::Compact);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Token::fromJson(const QByteArray &data)
|
bool Token::fromJson(const QByteArray &data)
|
||||||
{
|
{
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(data);
|
QJsonDocument doc = QJsonDocument::fromJson(data);
|
||||||
@ -81,24 +82,3 @@ QByteArray Token::idsToJSON(const QList<QString> &ids)
|
|||||||
doc.setObject(items);
|
doc.setObject(items);
|
||||||
return doc.toJson();
|
return doc.toJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Token::fromSQLRecord(const QSqlQuery& query)
|
|
||||||
{
|
|
||||||
setId(query.value(0).toString());
|
|
||||||
a_authErrors = query.value(1).toInt();
|
|
||||||
setDescription(query.value(2).toString());
|
|
||||||
setNoValidity(query.value(6).toBool());
|
|
||||||
setEnabled(query.value(3).toBool());
|
|
||||||
QDateTime date = query.value(4).toDateTime();
|
|
||||||
setLastUpdate(date);
|
|
||||||
setName(query.value(5).toString());
|
|
||||||
a_timeToLive = query.value(7).toInt();
|
|
||||||
a_tokenBits = query.value(8).toInt();
|
|
||||||
a_tokenData = query.value(9).toString();
|
|
||||||
a_tokenType = query.value(10).toString();
|
|
||||||
a_subjectId = query.value(11).toString();
|
|
||||||
date = query.value(12).toDateTime();
|
|
||||||
setLastModified(date);
|
|
||||||
setDeleted(query.value(13).toBool());
|
|
||||||
}
|
|
||||||
|
|||||||
@ -65,8 +65,6 @@ public:
|
|||||||
lToken->subjectId() == rToken->subjectId();
|
lToken->subjectId() == rToken->subjectId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void fromSQLRecord(const QSqlQuery& query);
|
|
||||||
|
|
||||||
static QByteArray tokensToColnodJson(const QHash<QString, std::shared_ptr<Token> > &tokens);
|
static QByteArray tokensToColnodJson(const QHash<QString, std::shared_ptr<Token> > &tokens);
|
||||||
static QByteArray idsToJSON(const QList<QString> &ids);
|
static QByteArray idsToJSON(const QList<QString> &ids);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user