mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 19:10:35 +02:00
WIP: error handling
This commit is contained in:
parent
9f9f287721
commit
a3c9a783e7
@ -20,6 +20,10 @@ void ColnodAPI::downloadData()
|
||||
auto login = requestLogin();
|
||||
connect(login.get(), &serversdk::Request::finished, this, [=](){ // TODO: error handling
|
||||
// Get token
|
||||
if (login->status() != 0) {
|
||||
qCritical(colnod) << "Login unsuccessful, Status:" << login->status() << "Error message:" ;
|
||||
}
|
||||
|
||||
AuthToken token;
|
||||
token.fromJson(login->responseData());
|
||||
authToken = token.id();
|
||||
|
||||
@ -15,8 +15,7 @@ class Message
|
||||
public:
|
||||
static QString massageTemplate(QString action, QString item, QString source, QString itemInfo)
|
||||
{
|
||||
return "[" + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") +
|
||||
"] " + action + " " + item + "in " + source + ", " + item + " " + itemInfo + "'";
|
||||
return action + " " + item + " in " + source + ", " + item + ": '" + itemInfo + "'";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -58,8 +58,7 @@ std::shared_ptr<Data> DatabaseAPI::composeData(const QSqlQuery &updatedQuery, QS
|
||||
qInfo(database) << tab << "-> DATABASE DATA:";
|
||||
qInfo(database) << tab << tab << data->updatedTokens.size() << "TOKENS WERE ADDED/UPDATED";
|
||||
qInfo(database) << tab << tab << data->deletedTokens.size() << "TOKENS MARKED FOR DELETION";
|
||||
qInfo(database) << dash ;
|
||||
|
||||
qInfo(database) << dash;
|
||||
|
||||
return data;
|
||||
}
|
||||
@ -126,6 +125,8 @@ void DatabaseAPI::initNewTokens()
|
||||
token->setDescription("mobile");
|
||||
token->setTokenData(token->tokenData().toUpper());
|
||||
tokensToInit.insert(token->id(), token);
|
||||
|
||||
qInfo(database).noquote() << Message::massageTemplate("Inicializing new", "token", "database", token->name());
|
||||
}
|
||||
uploadTokens(tokensToInit);
|
||||
}
|
||||
@ -136,9 +137,11 @@ void DatabaseAPI::uploadTokens(const QHash<QString, std::shared_ptr<Token>> &tok
|
||||
for (const auto &token : tokens) {
|
||||
if (exists(token->id(), "colnod_token")) {
|
||||
query = utils->updateTable(token.get(), "colnod_token");
|
||||
qInfo(database).noquote() << Message::massageTemplate("Updating", "token", "database", token->name());
|
||||
}
|
||||
else {
|
||||
query = utils->insertIntoTable(token.get(), "colnod_token");
|
||||
qInfo(database).noquote() << Message::massageTemplate("Adding", "token", "database", token->name());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -148,19 +151,24 @@ void DatabaseAPI::uploadSubjects(const QHash<QString, std::shared_ptr<Subject>>
|
||||
auto query = mDbMan->createQuery();
|
||||
for (const auto &subject : subjects) {
|
||||
for (const auto &attribute : subject->getAttributes()) {
|
||||
|
||||
if (exists(attribute->id(), "colnod_subject_attribute")) {
|
||||
query = utils->updateTable(attribute.get(), "colnod_subject_attribute");
|
||||
|
||||
}
|
||||
else {
|
||||
query = utils->insertIntoTable(attribute.get(), "colnod_subject_attribute");
|
||||
|
||||
}
|
||||
}
|
||||
// NOTE: about actions
|
||||
if (exists(subject->id(), "colnod_subject")) {
|
||||
query = utils->updateTable(subject.get(), "colnod_subject");
|
||||
qInfo(database).noquote() << Message::massageTemplate("Updating", "subject", "database", subject->name());
|
||||
}
|
||||
else {
|
||||
query = utils->insertIntoTable(subject.get(), "colnod_subject");
|
||||
qInfo(database).noquote() << Message::massageTemplate("Adding", "subject", "database", subject->name());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -170,16 +178,12 @@ void DatabaseAPI::deleteItems(const QList<QString> &ids, const QString &tableNam
|
||||
auto query = mDbMan->createQuery();
|
||||
QString nowString = QDateTime::fromMSecsSinceEpoch(getLastSync()).toString("yyyy-MM-dd hh:mm:ss.zzz");
|
||||
for (const auto &id : ids) {
|
||||
qInfo(database) << Message::massageTemplate("deleting", tableName.mid(tableName.indexOf("_") + 1, tableName.length() - 1), "database", id);
|
||||
qInfo(database).noquote() << "[" <<QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") << "]"
|
||||
<< "deleting" << tableName.mid(tableName.indexOf("_") + 1, tableName.length() - 1)
|
||||
<< ":" << "'" << id << "'";
|
||||
qInfo(database).noquote() << Message::massageTemplate("Deleting", tableName.mid(tableName.indexOf("_") + 1, tableName.length() - 1), "database", id);
|
||||
|
||||
query.prepare(QString("UPDATE %1 SET deleted = true, last_update = :now, last_modified = :now WHERE id = :id").arg(tableName));
|
||||
query.bindValue(":id", id);
|
||||
query.bindValue(":now", nowString);
|
||||
mDbMan->executeQuery(query);
|
||||
qDebug() << query.isActive() << ",is active on update???";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -48,6 +48,7 @@ private:
|
||||
|
||||
signals:
|
||||
void downloadDataFinished(std::shared_ptr<Data> = std::shared_ptr<Data>());
|
||||
void error();
|
||||
|
||||
private:
|
||||
bool mDryMode;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user