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