forked from ondra/colnod-connector
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;
|
||||
}
|
||||
|
||||
void ColnodAPI::areDataReady(const std::shared_ptr<Data>& data)
|
||||
void ColnodAPI::areDataReady(const std::shared_ptr<Data> &data)
|
||||
{
|
||||
if (++amountData == 4) {
|
||||
|
||||
|
||||
@ -184,7 +184,7 @@ void DatabaseAPI::initNewTokens()
|
||||
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
|
||||
// OK -> token was updated
|
||||
@ -194,8 +194,9 @@ bool DatabaseAPI::uploadTokens(const QHash<QString, std::shared_ptr<Token>> &tok
|
||||
// Get token
|
||||
|
||||
if (exists(token->id(), "colnod_token")) {
|
||||
query = utils->updateTable(token.get(), "colnod_token");
|
||||
qInfo(database).noquote() << Message::massageTemplate("Updating", "token", "database", token->name());
|
||||
query = utils->updateTable(token.get(), "colnod_token", filters);
|
||||
if (filters.contains("last_modified"))
|
||||
qInfo(database).noquote() << Message::massageTemplate("Updating", "token", "database", token->name());
|
||||
}
|
||||
else {
|
||||
// TODO: first check if OK, then message
|
||||
|
||||
@ -38,7 +38,7 @@ public:
|
||||
void initNewTokens();
|
||||
|
||||
// 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 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) << dash;
|
||||
|
||||
if (!database->processData(preparedData->databaseData)) {
|
||||
if (!database->processData(preparedData->colnodData)) {
|
||||
qCritical(syncmanager) << "Not possible to upload data to database";
|
||||
}
|
||||
|
||||
@ -100,21 +100,25 @@ bool SyncManager::startSynchronization()
|
||||
Timestamp time;
|
||||
time.setTimestamp(syncBegin);
|
||||
|
||||
database->reupdateDeleted(preparedData->databaseData->deletedTokens);
|
||||
// download data changes in this sync
|
||||
colnod->getTokensUpdated(time);
|
||||
auto tokensRequest = colnod->getTokensUpdated(time);
|
||||
|
||||
// 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) {
|
||||
qCritical(syncmanager) << "Not possible to get correct data from colnod";
|
||||
QCoreApplication::exit(-1);
|
||||
return;
|
||||
}
|
||||
if (!database->uploadTokens(uploadedData->updatedTokens)) {
|
||||
if (!database->uploadTokens(uploadedData->updatedTokens, {"lastModified"})) {
|
||||
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()) {
|
||||
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";
|
||||
});
|
||||
|
||||
@ -217,7 +222,7 @@ std::unique_ptr<PreparedData> SyncManager::prepareDataNew(const std::shared_ptr<
|
||||
}
|
||||
|
||||
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) << "PREPARING DATA -> FINISHED";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user