mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 16:50:48 +02:00
WIP: colnod api doesnt download data
This commit is contained in:
parent
8cb0f3b01d
commit
3487c6f81c
@ -271,7 +271,7 @@ void ColnodAPI::setUserName(const QString &userName)
|
|||||||
mUserName = userName;
|
mUserName = userName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColnodAPI::areDataReady(const std::shared_ptr<Data>& data)
|
void ColnodAPI::areDataReady(const std::shared_ptr<Data> &data)
|
||||||
{
|
{
|
||||||
if (++amountData == 4) {
|
if (++amountData == 4) {
|
||||||
|
|
||||||
|
|||||||
@ -184,7 +184,7 @@ void DatabaseAPI::initNewTokens()
|
|||||||
uploadTokens(tokensToInit);
|
uploadTokens(tokensToInit);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DatabaseAPI::uploadTokens(const QHash<QString, std::shared_ptr<Token>> &tokens)
|
bool DatabaseAPI::uploadTokens(const QHash<QString, std::shared_ptr<Token>> &tokens, const QSet<QString> &filters)
|
||||||
{
|
{
|
||||||
// TODO: first check if OK, then message
|
// TODO: first check if OK, then message
|
||||||
// OK -> token was updated
|
// OK -> token was updated
|
||||||
@ -194,7 +194,8 @@ bool DatabaseAPI::uploadTokens(const QHash<QString, std::shared_ptr<Token>> &tok
|
|||||||
// Get token
|
// Get token
|
||||||
|
|
||||||
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", filters);
|
||||||
|
if (filters.contains("last_modified"))
|
||||||
qInfo(database).noquote() << Message::massageTemplate("Updating", "token", "database", token->name());
|
qInfo(database).noquote() << Message::massageTemplate("Updating", "token", "database", token->name());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@ -38,7 +38,7 @@ public:
|
|||||||
void initNewTokens();
|
void initNewTokens();
|
||||||
|
|
||||||
// process data
|
// process data
|
||||||
bool uploadTokens(const QHash<QString, std::shared_ptr<Token> > &tokens);
|
bool uploadTokens(const QHash<QString, std::shared_ptr<Token> > &tokens, const QSet<QString> &filters = {});
|
||||||
bool uploadSubjects(const QHash<QString, std::shared_ptr<Subject> > &subjects);
|
bool uploadSubjects(const QHash<QString, std::shared_ptr<Subject> > &subjects);
|
||||||
bool deleteItems(const QList<QString> &ids, const QString &tableName);
|
bool deleteItems(const QList<QString> &ids, const QString &tableName);
|
||||||
|
|
||||||
|
|||||||
@ -87,7 +87,7 @@ bool SyncManager::startSynchronization()
|
|||||||
qInfo(syncmanager) << "Push changes to both Colnod and Database:";
|
qInfo(syncmanager) << "Push changes to both Colnod and Database:";
|
||||||
qInfo(syncmanager) << dash;
|
qInfo(syncmanager) << dash;
|
||||||
|
|
||||||
if (!database->processData(preparedData->databaseData)) {
|
if (!database->processData(preparedData->colnodData)) {
|
||||||
qCritical(syncmanager) << "Not possible to upload data to database";
|
qCritical(syncmanager) << "Not possible to upload data to database";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,21 +100,25 @@ bool SyncManager::startSynchronization()
|
|||||||
Timestamp time;
|
Timestamp time;
|
||||||
time.setTimestamp(syncBegin);
|
time.setTimestamp(syncBegin);
|
||||||
|
|
||||||
database->reupdateDeleted(preparedData->databaseData->deletedTokens);
|
|
||||||
// download data changes in this sync
|
// download data changes in this sync
|
||||||
colnod->getTokensUpdated(time);
|
auto tokensRequest = colnod->getTokensUpdated(time);
|
||||||
|
|
||||||
// updated data are ready
|
// updated data are ready
|
||||||
connect(colnod.get(), &ColnodAPI::partOfDataReady, [=](const std::shared_ptr<Data> &uploadedData){
|
connect(tokensRequest.get(), &serversdk::Request::finished, [=](){
|
||||||
|
auto uploadedData = std::make_shared<Data>();
|
||||||
|
uploadedData->loadTokensFromJson(tokensRequest->responseData());
|
||||||
|
|
||||||
if (!uploadedData) {
|
if (!uploadedData) {
|
||||||
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);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!database->uploadTokens(uploadedData->updatedTokens)) {
|
if (!database->uploadTokens(uploadedData->updatedTokens, {"lastModified"})) {
|
||||||
qCritical(syncmanager) << "Not possible to upload data to database";
|
qCritical(syncmanager) << "Not possible to upload data to database";
|
||||||
|
QCoreApplication::exit(-1);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
database->reupdateDeleted(uploadedData->deletedTokens);
|
database->reupdateDeleted(databaseData->deletedTokens);
|
||||||
|
|
||||||
if (!database->isValid() || !colnod->isValid()) {
|
if (!database->isValid() || !colnod->isValid()) {
|
||||||
qWarning(syncmanager) << "Synchronization was unsuccessful, next run of sync will be with same last sync time, check warnings";
|
qWarning(syncmanager) << "Synchronization was unsuccessful, next run of sync will be with same last sync time, check warnings";
|
||||||
@ -135,7 +139,8 @@ bool SyncManager::startSynchronization()
|
|||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
colnod->processData(preparedData->colnodData);
|
colnod->processData(preparedData->databaseData); // TODO: errors???
|
||||||
|
|
||||||
//qCritical(syncmanager) << "Not possible to upload data to colnod";
|
//qCritical(syncmanager) << "Not possible to upload data to colnod";
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -217,7 +222,7 @@ std::unique_ptr<PreparedData> SyncManager::prepareDataNew(const std::shared_ptr<
|
|||||||
}
|
}
|
||||||
|
|
||||||
qInfo(syncmanager) << tab << "-> DATABASE DATA - CHANGES:";
|
qInfo(syncmanager) << tab << "-> DATABASE DATA - CHANGES:";
|
||||||
qInfo(syncmanager) << tab << tab << databaseData->updatedTokens.size() - preparedColnodData->updatedTokens.size() << "TOKENS WERE ADDED/UPDATED IN COLNOD AFTER";
|
qInfo(syncmanager) << tab << tab << databaseData->updatedTokens.size() - preparedDatabaseData->updatedTokens.size() << "TOKENS WERE ADDED/UPDATED IN COLNOD AFTER";
|
||||||
qInfo(syncmanager) << dash;
|
qInfo(syncmanager) << dash;
|
||||||
|
|
||||||
qInfo(syncmanager) << "PREPARING DATA -> FINISHED";
|
qInfo(syncmanager) << "PREPARING DATA -> FINISHED";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user