forked from ondra/colnod-connector
Compare commits
24 Commits
bug/downlo
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 8654918f95 | |||
|
|
9784c31174 | ||
|
|
c1a8c80cfa | ||
|
|
96b32c222c | ||
|
|
3c68cd64f2 | ||
|
|
91da3090c9 | ||
|
|
ce2a4cbaf7 | ||
|
|
111b93549a | ||
|
|
691ad920db | ||
|
|
d49db3f6b0 | ||
|
|
2bc1301fcd | ||
|
|
82d93fd115 | ||
|
|
d7b9c15dd6 | ||
|
|
18032ef1fc | ||
|
|
d91ff9f38f | ||
|
|
7dd5afe599 | ||
|
|
2dbd72bf34 | ||
|
|
7188e98e6d | ||
|
|
21da53fc33 | ||
|
|
30735dc953 | ||
|
|
9d7e05635e | ||
|
|
08afae47aa | ||
|
|
b405d95320 | ||
|
|
fe0954edf1 |
2
.gitmodules
vendored
2
.gitmodules
vendored
@ -1,3 +1,3 @@
|
||||
[submodule "server-sdk"]
|
||||
path = server-sdk
|
||||
url = ../../common/server-sdk
|
||||
url = git@gitea.thegolem.cz:michalks/server-sdk.git
|
||||
|
||||
10
CMakeLists.txt
Normal file
10
CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.11.0)
|
||||
project(colnodconn)
|
||||
message(">> Project colnod-connector")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
add_subdirectory(server-sdk)
|
||||
add_subdirectory(src)
|
||||
109
README.md
109
README.md
@ -169,6 +169,115 @@ It is possible to chain requests: [see doc](https://support.insomnia.rest/articl
|
||||
|
||||
`npm install -g snowboard`
|
||||
|
||||
## Tests made
|
||||
Changes on colnod are made by [Colnod client](https://spaceti.atlassian.net/wiki/spaces/IN/pages/194576388/Colnod+client)
|
||||
|
||||
Changes on db can be made by sql commands directly or by [pgAdmin](https://www.pgadmin.org/)
|
||||
- add token to db/colnod (2 tests)
|
||||
- edit token in db/colnod (2 tests)
|
||||
- delete token from db/colnod (2 tests)
|
||||
- add subject to colnod
|
||||
- edit subject in colnod
|
||||
- delete subject from colnod
|
||||
- edit same token on both db/colnod (diffrent time)
|
||||
|
||||
## First sync expected results
|
||||
- 2892 tokens updated
|
||||
- 173 tokens deleted
|
||||
- 2894 subjects updated
|
||||
- 117 subjects deleted
|
||||
|
||||
## Database inicialization
|
||||
- Token table
|
||||
```SQL create
|
||||
-- Table: public.colnod_token
|
||||
-- DROP TABLE public.colnod_token;
|
||||
CREATE TABLE public.colnod_token
|
||||
(
|
||||
id character(36) COLLATE pg_catalog."default" NOT NULL,
|
||||
auth_errors integer DEFAULT 255,
|
||||
description character varying(255) COLLATE pg_catalog."default",
|
||||
enabled boolean DEFAULT true,
|
||||
last_update timestamp without time zone DEFAULT '1970-01-01 00:00:00.001'::timestamp without time zone,
|
||||
name character varying(255) COLLATE pg_catalog."default",
|
||||
no_validity boolean DEFAULT true,
|
||||
time_to_live integer DEFAULT 255,
|
||||
token_bits integer DEFAULT 32,
|
||||
token_data character varying(255) COLLATE pg_catalog."default",
|
||||
token_type character varying(255) COLLATE pg_catalog."default" DEFAULT 'Token'::character varying,
|
||||
subject_id character(36) COLLATE pg_catalog."default",
|
||||
last_modified timestamp without time zone NOT NULL,
|
||||
deleted boolean DEFAULT false,
|
||||
CONSTRAINT colnod_token_pkey PRIMARY KEY (id)
|
||||
)
|
||||
WITH (
|
||||
OIDS = FALSE
|
||||
)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
ALTER TABLE public.colnod_token
|
||||
OWNER to postgres;
|
||||
```
|
||||
- Subject table
|
||||
```SQL create
|
||||
-- Table: public.colnod_subject
|
||||
-- DROP TABLE public.colnod_subject;
|
||||
CREATE TABLE public.colnod_subject
|
||||
(
|
||||
id character(36) COLLATE pg_catalog."default" NOT NULL,
|
||||
description character varying(255) COLLATE pg_catalog."default",
|
||||
last_update timestamp without time zone NOT NULL,
|
||||
name character varying(255) COLLATE pg_catalog."default",
|
||||
pin character varying(255) COLLATE pg_catalog."default",
|
||||
last_modified timestamp without time zone,
|
||||
deleted boolean,
|
||||
CONSTRAINT colnod_subject_pkey PRIMARY KEY (id)
|
||||
)
|
||||
WITH (
|
||||
OIDS = FALSE
|
||||
)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
ALTER TABLE public.colnod_subject
|
||||
OWNER to postgres;
|
||||
```
|
||||
- Subject attributes table
|
||||
```SQL create
|
||||
-- Table: public.colnod_subject_attribute
|
||||
-- DROP TABLE public.colnod_subject_attribute;
|
||||
CREATE TABLE public.colnod_subject_attribute
|
||||
(
|
||||
id character varying(255) COLLATE pg_catalog."default" NOT NULL,
|
||||
attribute_key character varying(255) COLLATE pg_catalog."default",
|
||||
attribute_value character varying(255) COLLATE pg_catalog."default",
|
||||
subject_id character(36) COLLATE pg_catalog."default",
|
||||
CONSTRAINT colnod_subject_attribute_pkey PRIMARY KEY (id)
|
||||
)
|
||||
WITH (
|
||||
OIDS = FALSE
|
||||
)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
ALTER TABLE public.colnod_subject_attribute
|
||||
OWNER to postgres;
|
||||
```
|
||||
- Config
|
||||
```SQL create
|
||||
-- Table: public.config
|
||||
-- DROP TABLE public.config;
|
||||
CREATE TABLE public.config
|
||||
(
|
||||
last_sync bigint NOT NULL DEFAULT 0,
|
||||
CONSTRAINT config_pkey PRIMARY KEY (last_sync)
|
||||
)
|
||||
WITH (
|
||||
OIDS = FALSE
|
||||
)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
ALTER TABLE public.config
|
||||
OWNER to postgres;
|
||||
```
|
||||
## Possible checks
|
||||
[here](https://gitlab.com/spaceti-app/integrations/acs/colnod-connector/blob/master/doc/possible-checks.md)
|
||||
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 3640c0db5d1e24b314b00cc2b0dd61915080381b
|
||||
Subproject commit 13d09d246cb198291ea5af00ddad3dbd724519cd
|
||||
36
src/CMakeLists.txt
Normal file
36
src/CMakeLists.txt
Normal file
@ -0,0 +1,36 @@
|
||||
cmake_minimum_required(VERSION 3.1.0)
|
||||
project(colnod-connector VERSION 0.1.0)
|
||||
|
||||
message(">> APP ${PROJECT_NAME} ${PROJECT_VERSION}")
|
||||
|
||||
cmake_policy(SET CMP0063 NEW)
|
||||
cmake_policy(SET CMP0075 NEW)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
|
||||
find_package(Qt5 COMPONENTS Core REQUIRED)
|
||||
find_package(Qt5 COMPONENTS Sql REQUIRED)
|
||||
find_package(Qt5 COMPONENTS Network REQUIRED)
|
||||
|
||||
# find all cpp files from app and colnod folders
|
||||
# app contains main()
|
||||
file(GLOB_RECURSE APP_SOURCE_FILES FILES_MATCHING PATTERN "app/*.cpp")
|
||||
# colnod contains additional files, but is part of the application executable
|
||||
# so we do not make colnod folder into separate library but include it in the final executable directly
|
||||
file(GLOB_RECURSE COLNOD_SOURCE_FILES FILES_MATCHING PATTERN "colnod/*.cpp")
|
||||
|
||||
# creates actual cmake target seen in cmake
|
||||
add_executable(${PROJECT_NAME} ${APP_SOURCE_FILES} ${COLNOD_SOURCE_FILES})
|
||||
|
||||
# link QT and server-sdk submodule
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
Qt5::Core
|
||||
Qt5::Sql
|
||||
Qt5::Network
|
||||
serversdk # link server-sdk git submodule
|
||||
)
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
|
||||
target_compile_options(${PROJECT_NAME} PUBLIC -O0 -Wall)
|
||||
@ -1,14 +1,13 @@
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include "syncmanager.h"
|
||||
#include <QCommandLineParser>
|
||||
#include "serversdk/requestmanager.h"
|
||||
#include "serversdk/request.h"
|
||||
|
||||
#include "serversdk/logger.h"
|
||||
#include "serversdk/core.h"
|
||||
#include <serversdk/requestmanager.h>
|
||||
#include <serversdk/request.h>
|
||||
#include <serversdk/logger.h>
|
||||
#include <serversdk/core.h>
|
||||
|
||||
#include "colnodapi.h"
|
||||
#include "../colnod/colnodapi.h"
|
||||
#include "../colnod/syncmanager.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -22,7 +21,7 @@ int main(int argc, char *argv[])
|
||||
parser.setApplicationDescription("Colnod sync");
|
||||
QCommandLineOption dryModeOption("dryMode", "ColnodAPI", "Read-only mode, prints changes which would normally be made");
|
||||
QCommandLineOption dropTablesOption("dropTables", "ColnodAPI", "Delete tables with datas from Colnod");
|
||||
QCommandLineOption createTablesOption("createTables", "ColnodAPI", "Create tables to saving data from Colnod");
|
||||
QCommandLineOption createTablesOption("createTables", "ColnodAPI", "Create tables for saving data from Colnod");
|
||||
parser.addOption(dryModeOption);
|
||||
parser.addOption(dropTablesOption);
|
||||
parser.addOption(createTablesOption);
|
||||
@ -30,7 +29,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
|
||||
// Logger initializiaton
|
||||
serversdk::initAppLogger(); // <-- then Logger::outputMessage will handle all messages
|
||||
serversdk::initAppLogger();
|
||||
|
||||
// Log messge Filtering
|
||||
QStringList filters;
|
||||
@ -40,7 +39,6 @@ int main(int argc, char *argv[])
|
||||
QLoggingCategory::setFilterRules(filters.join(QStringLiteral("\n")));
|
||||
|
||||
|
||||
|
||||
SyncManager syncManager(parser.isSet(dryModeOption));
|
||||
|
||||
// Initialize database and colnod API
|
||||
|
||||
@ -15,9 +15,10 @@ ColnodAPI::ColnodAPI(serversdk::RequestManager* reqMan, const bool &dryMode, QSt
|
||||
|
||||
/**
|
||||
* @brief Downloads new data from Colnod -> emits downloadDataFinished signal
|
||||
* @param time - timestamp -> ms from 1970
|
||||
* @param time
|
||||
*
|
||||
* @return emits signal with data when ok, or nullptr, when error
|
||||
* @return signal with nullptr when something went wrong
|
||||
* @return signal with data when valid data returned
|
||||
*/
|
||||
bool ColnodAPI::downloadData(const qint64 &time)
|
||||
{
|
||||
@ -28,22 +29,21 @@ bool ColnodAPI::downloadData(const qint64 &time)
|
||||
qCCritical(colnod) << "Not possible to create login request";
|
||||
return false;
|
||||
}
|
||||
|
||||
connect(login.get(), &serversdk::Request::finished, this, [=](){
|
||||
// Get login token
|
||||
if (login->status() != 200) {
|
||||
// Get login token and check if is correct
|
||||
if (!checkRequest(login)) {
|
||||
emit downloadDataFinished(nullptr);
|
||||
return false;
|
||||
}
|
||||
AuthToken token;
|
||||
auto responseData = login->responseData();
|
||||
if (responseData.isEmpty()) {
|
||||
|
||||
if (checkResponse(login->responseData())) {
|
||||
qCWarning(colnod) << "empty response data when logging in";
|
||||
emit downloadDataFinished(nullptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
token.fromJson(responseData);
|
||||
token.fromJson(login->responseData());
|
||||
authToken = token.id();
|
||||
if (authToken.isEmpty()) {
|
||||
qCCritical(colnod) << "Token uuid is empty";
|
||||
@ -51,57 +51,69 @@ bool ColnodAPI::downloadData(const qint64 &time)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// if I have all data emit downloadDataFinished
|
||||
//connect(this, &ColnodAPI::partOfDataReady, this, &ColnodAPI::areDataReady);
|
||||
|
||||
auto data = std::make_shared<Data>();
|
||||
Timestamp timestamp;
|
||||
timestamp.setTimestamp(time);
|
||||
|
||||
auto data = std::make_shared<Data>();
|
||||
int dataCount = 0;
|
||||
|
||||
// emit signal when with all data when it is ready
|
||||
auto checkData = [=]() {
|
||||
qDebug() << "check data" << dataCount;
|
||||
// VALIDATE: problem was in unitest getTokens
|
||||
// -> no tests -> destroying QNetworkRequest when QNetworkReply was running
|
||||
// FIXME: Problem with ASSERT: "dataCount < 5" -> datacount sometime -> 32677 ( bad memory allocation )
|
||||
// Not possible to pinpoint memory problem.
|
||||
// Possible sources:
|
||||
// 0) Bad code -> dataCount -> &dataCount -> ++ what it does. Increase dataCount or increment address?
|
||||
// - have to double check this problem
|
||||
// 1) ColnodAPI
|
||||
// 2) RequestManager ( serversdk )
|
||||
// 3) Problem with testing QtTest logic
|
||||
// - try to change stack allocation to heap ( std::unique_ptr )
|
||||
// - reason: Does not make sence but something else could appear
|
||||
// 4) Lambda slots
|
||||
if (dataCount > 5) {
|
||||
int dataCount = data->incrementCounter();
|
||||
if ( dataCount > 5) {
|
||||
qCCritical(colnod) << "check data cannnot be higher then 4";
|
||||
}
|
||||
Q_ASSERT(dataCount < 5);
|
||||
if (dataCount == 4)
|
||||
if (dataCount == 4) {
|
||||
qInfo(colnod) << tab << "- src col:" << tab << "tokens [" << data->updatedTokens.size() << ":" << data->deletedTokens.size() <<
|
||||
"] subjects [" << data->updatedSubjects.size() << ":" << data->deletedSubjects.size() << "] [ added/updated : deleted ]";
|
||||
|
||||
if (!data->updatedTokens.isEmpty() || !data->deletedTokens.isEmpty() ||
|
||||
!data->updatedSubjects.isEmpty() || !data->deletedSubjects.isEmpty()) {
|
||||
qInfo(colnod) << dash;
|
||||
}
|
||||
for (const auto &token : data->updatedTokens) {
|
||||
qInfo(colnod) << Message::massageTemplate("Download updated", "token", "colnod", token->name());
|
||||
}
|
||||
for (const auto &id : data->deletedTokens) {
|
||||
qInfo(colnod) << Message::massageTemplate("Download deleted", "token", "colnod", id);
|
||||
}
|
||||
for (const auto &subject : data->updatedSubjects) {
|
||||
qInfo(colnod) << Message::massageTemplate("Download updated", "subject", "colnod", subject->name());
|
||||
}
|
||||
for (const auto &id : data->deletedSubjects) {
|
||||
qInfo(colnod) << Message::massageTemplate("Download deleted", "token", "colnod", id);
|
||||
}
|
||||
if (!data->updatedTokens.isEmpty() || !data->deletedTokens.isEmpty() ||
|
||||
!data->updatedSubjects.isEmpty() || !data->deletedSubjects.isEmpty()) {
|
||||
qInfo(colnod) << dash;
|
||||
}
|
||||
emit downloadDataFinished(data);
|
||||
}
|
||||
};
|
||||
|
||||
// Getting tokens from ColnodAPI
|
||||
auto tokensRequest = getTokensUpdated(timestamp);
|
||||
connect(tokensRequest.get(), &serversdk::Request::finished, [=](){
|
||||
qDebug(colnod) << "tokens finished";
|
||||
|
||||
// false when not possible to load request data
|
||||
if (!saveUpdatedTokens(data, tokensRequest->responseData())) {
|
||||
if (!checkErrors(tokensRequest)) {
|
||||
qCritical(colnod) << "Error during call getTokensUpdated endpoint";
|
||||
emit downloadDataFinished(nullptr);
|
||||
return;
|
||||
}
|
||||
if (!saveUpdatedTokens(data, tokensRequest->responseData())) {
|
||||
qCritical(colnod) << "Error during saving getTokensUpdated";
|
||||
emit downloadDataFinished(nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
checkData();
|
||||
});
|
||||
|
||||
auto deletedTokensRequest = getTokensDeleted(timestamp);
|
||||
connect(deletedTokensRequest.get(), &serversdk::Request::finished, [=](){
|
||||
qDebug(colnod) << "tokens finished";
|
||||
if (!checkErrors(deletedTokensRequest)) {
|
||||
qCritical(colnod) << "Error during call getTokensDeleted endpoint";
|
||||
emit downloadDataFinished(nullptr);
|
||||
return;
|
||||
}
|
||||
if (!saveDeletedTokens(data, deletedTokensRequest->responseData())) {
|
||||
qCritical(colnod) << "Error during saving getTokensDeleted";
|
||||
emit downloadDataFinished(nullptr);
|
||||
return;
|
||||
}
|
||||
@ -110,8 +122,13 @@ bool ColnodAPI::downloadData(const qint64 &time)
|
||||
|
||||
auto subjectsRequest = getSubjectsUpdated(timestamp);
|
||||
connect(subjectsRequest.get(), &serversdk::Request::finished, [=](){
|
||||
qDebug(colnod) << "tokens finished";
|
||||
if (!checkErrors(subjectsRequest)) {
|
||||
qCritical(colnod) << "Error during call getSubjectsUpdated endpoint";
|
||||
emit downloadDataFinished(nullptr);
|
||||
return;
|
||||
}
|
||||
if (!saveUpdatedSubjects(data, subjectsRequest->responseData())) {
|
||||
qCritical(colnod) << "Error during saving getSubjectsUpdated";
|
||||
emit downloadDataFinished(nullptr);
|
||||
return;
|
||||
}
|
||||
@ -120,46 +137,87 @@ bool ColnodAPI::downloadData(const qint64 &time)
|
||||
|
||||
auto deletedSubjectsRequest = getSubjectsDeleted(timestamp);
|
||||
connect(deletedSubjectsRequest.get(), &serversdk::Request::finished, [=](){
|
||||
qDebug(colnod) << "tokens finished";
|
||||
if (!checkErrors(deletedSubjectsRequest)) {
|
||||
qCritical(colnod) << "Error during call getSubjectsDeleted endpoint";
|
||||
emit downloadDataFinished(nullptr);
|
||||
return;
|
||||
}
|
||||
if (!saveDeletedSubjects(data, deletedSubjectsRequest->responseData())) {
|
||||
qCritical(colnod) << "Error during saving getSubjectsDeleted";
|
||||
emit downloadDataFinished(nullptr);
|
||||
return;
|
||||
}
|
||||
checkData();
|
||||
});
|
||||
return true;
|
||||
});
|
||||
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
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()) {
|
||||
// emit signal when finished
|
||||
auto checkData = [=]() {
|
||||
int dataCount = data->incrementCounter();
|
||||
if ( dataCount > 3) {
|
||||
qCCritical(colnod) << "check data cannnot be higher then 2";
|
||||
}
|
||||
Q_ASSERT(dataCount < 3);
|
||||
if (dataCount == 2) {
|
||||
qInfo(colnod) << tab << "- push col:" << tab << "tokens [" << data->updatedTokens.size() << ":" << data->deletedTokens.size() <<
|
||||
"] [ added/updated : deleted ]";
|
||||
|
||||
if (!data->updatedTokens.isEmpty() || !data->deletedTokens.isEmpty() ||
|
||||
!data->updatedSubjects.isEmpty() || !data->deletedSubjects.isEmpty()) {
|
||||
qInfo(colnod) << dash;
|
||||
}
|
||||
|
||||
for (const auto &token : data->updatedTokens) {
|
||||
qInfo(colnod).noquote() << Message::massageTemplate("Updated", "token", "colnod", token->name());
|
||||
}
|
||||
|
||||
for (const auto &id : data->deletedTokens) {
|
||||
qInfo(colnod).noquote() << Message::massageTemplate("Deleted", "token", "colnod", id);
|
||||
}
|
||||
|
||||
if (!data->updatedTokens.isEmpty() || !data->deletedTokens.isEmpty() ||
|
||||
!data->updatedSubjects.isEmpty() || !data->deletedSubjects.isEmpty()) {
|
||||
qInfo(colnod) << dash;
|
||||
}
|
||||
emit dataProcessFinished(mValid);
|
||||
}
|
||||
};
|
||||
|
||||
if ( !data->updatedTokens.isEmpty() || !data->deletedTokens.isEmpty() ) {
|
||||
qInfo(colnod) << dash;
|
||||
}
|
||||
qInfo(colnod) << tab << "-> DATA PROCESSED TO COLNOD:";
|
||||
qInfo(colnod) << tab << tab << data->updatedTokens.size() << "TOKENS UPDATED";
|
||||
qInfo(colnod) << tab << tab << data->deletedTokens.size() << "TOKENS DELETED";
|
||||
qInfo(colnod) << dash;
|
||||
|
||||
|
||||
connect(this, &ColnodAPI::partOfDataProcessFinished, this, &ColnodAPI::isDataProcessFinished);
|
||||
if ( !data->updatedTokens.isEmpty() && !mDryMode) {
|
||||
setTokens(data->updatedTokens);
|
||||
if ( !data->updatedTokens.isEmpty() && !mDryMode ) {
|
||||
auto setTokensRequest = setTokens(data->updatedTokens);
|
||||
connect(setTokensRequest.get(), &serversdk::Request::finished, [=](){
|
||||
if (!checkErrors(setTokensRequest)) {
|
||||
data->updatedTokens.clear();
|
||||
mValid = false;
|
||||
return;
|
||||
}
|
||||
checkData();
|
||||
});
|
||||
} else {
|
||||
emit partOfDataProcessFinished();
|
||||
checkData();
|
||||
}
|
||||
if ( !data->deletedTokens.isEmpty() && !mDryMode) {
|
||||
deleteTokens(data->deletedTokens);
|
||||
|
||||
if ( !data->deletedTokens.isEmpty() && !mDryMode ) {
|
||||
auto deletedTokensRequest = deleteTokens(data->deletedTokens);
|
||||
connect(deletedTokensRequest.get(), &serversdk::Request::finished, [=](){
|
||||
if (!checkErrors(deletedTokensRequest)) {
|
||||
data->deletedTokens.clear();
|
||||
mValid = false;
|
||||
return;
|
||||
}
|
||||
checkData();
|
||||
});
|
||||
} else {
|
||||
emit partOfDataProcessFinished();
|
||||
checkData();
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,11 +242,6 @@ std::shared_ptr<serversdk::Request> ColnodAPI::requestLogin()
|
||||
return loginRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return sucess :
|
||||
* @return fail :
|
||||
* @return no data :
|
||||
*/
|
||||
std::shared_ptr<serversdk::Request> ColnodAPI::getTokensUpdated(const Timestamp &time)
|
||||
{
|
||||
auto request = composeRequest("/TokenManager/getTokensUpdated", time.jsonData());
|
||||
@ -197,11 +250,6 @@ std::shared_ptr<serversdk::Request> ColnodAPI::getTokensUpdated(const Timestamp
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return sucess :
|
||||
* @return fail :
|
||||
* @return no data :
|
||||
*/
|
||||
std::shared_ptr<serversdk::Request> ColnodAPI::getTokensDeleted(const Timestamp &time)
|
||||
{
|
||||
auto request = composeRequest("/TokenManager/getTokensDeleted", time.jsonData());
|
||||
@ -210,11 +258,6 @@ std::shared_ptr<serversdk::Request> ColnodAPI::getTokensDeleted(const Timestamp
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return sucess :
|
||||
* @return fail :
|
||||
* @return no data :
|
||||
*/
|
||||
std::shared_ptr<serversdk::Request> ColnodAPI::getSubjectsUpdated(const Timestamp &time)
|
||||
{
|
||||
auto request = composeRequest("/SubjectManager/getSubjectsUpdated", time.jsonData());
|
||||
@ -223,11 +266,6 @@ std::shared_ptr<serversdk::Request> ColnodAPI::getSubjectsUpdated(const Timestam
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return sucess :
|
||||
* @return fail :
|
||||
* @return no data :
|
||||
*/
|
||||
std::shared_ptr<serversdk::Request> ColnodAPI::getSubjectsDeleted(const Timestamp &time)
|
||||
{
|
||||
auto request = composeRequest("/SubjectManager/getSubjectsDeleted", time.jsonData());
|
||||
@ -236,29 +274,11 @@ std::shared_ptr<serversdk::Request> ColnodAPI::getSubjectsDeleted(const Timestam
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return sucess :
|
||||
* @return fail :
|
||||
*/
|
||||
std::shared_ptr<serversdk::Request> ColnodAPI::setTokens(const QHash<QString, std::shared_ptr<Token>> &tokens)
|
||||
{
|
||||
auto request = composeRequest("/TokenManager/setTokens", Token::tokensToColnodJson(tokens));
|
||||
request->setUserName(authToken);
|
||||
mReqMan->processRequest(request);
|
||||
connect(request.get(), &serversdk::Request::finished, [=](){
|
||||
if (!checkRequest(request)) {
|
||||
qCritical(colnod) << "ERROR during calling /TokenManager/setTokens, request unsuccessful. EXIT";
|
||||
emit error();
|
||||
}
|
||||
if (checkResponse(request->responseData())) {
|
||||
emit partOfDataProcessFinished();
|
||||
}
|
||||
else {
|
||||
qWarning(colnod) << "Tokens wasn't updated";
|
||||
mValid = false;
|
||||
emit partOfDataProcessFinished();
|
||||
}
|
||||
});
|
||||
return request;
|
||||
}
|
||||
|
||||
@ -267,20 +287,6 @@ std::shared_ptr<serversdk::Request> ColnodAPI::deleteTokens(const QList<QString>
|
||||
auto request = composeRequest("/TokenManager/deleteTokens", Token::idsToJSON(ids));
|
||||
request->setUserName(authToken);
|
||||
mReqMan->processRequest(request);
|
||||
connect(request.get(), &serversdk::Request::finished, [=](){
|
||||
if (!checkRequest(request)) {
|
||||
qCritical(colnod) << "ERROR during calling /TokenManager/deleteTokens, request unsuccessful. EXIT";
|
||||
emit error();
|
||||
}
|
||||
if (checkResponse(request->responseData())) {
|
||||
emit partOfDataProcessFinished();
|
||||
}
|
||||
else {
|
||||
qWarning(colnod) << "Tokens wasn't deleted";
|
||||
mValid = false;
|
||||
emit partOfDataProcessFinished();
|
||||
}
|
||||
});
|
||||
return request;
|
||||
}
|
||||
|
||||
@ -295,6 +301,19 @@ bool ColnodAPI::checkRequest(const std::shared_ptr<serversdk::Request> &request)
|
||||
return request->status() == 200;
|
||||
}
|
||||
|
||||
bool ColnodAPI::checkErrors(const std::shared_ptr<serversdk::Request> &request)
|
||||
{
|
||||
if (!checkRequest(request)) {
|
||||
qCWarning(colnod) << "Status is not 200";
|
||||
return false;
|
||||
}
|
||||
if (!checkResponse(request->responseData())) {
|
||||
qCWarning(colnod) << "Empty response data";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ColnodAPI::isValid()
|
||||
{
|
||||
return mValid;
|
||||
@ -310,17 +329,6 @@ void ColnodAPI::setPassword(const QString &password)
|
||||
mPassword = password;
|
||||
}
|
||||
|
||||
qint64 ColnodAPI::lastSync() const
|
||||
{
|
||||
return mLastSync.timestamp();
|
||||
}
|
||||
|
||||
void ColnodAPI::setlastSync(const qint64 &lastSync)
|
||||
{
|
||||
mLastSync.setTimestamp(lastSync);
|
||||
}
|
||||
|
||||
|
||||
QString ColnodAPI::userName() const
|
||||
{
|
||||
return mUserName;
|
||||
@ -331,29 +339,6 @@ void ColnodAPI::setUserName(const QString &userName)
|
||||
mUserName = userName;
|
||||
}
|
||||
|
||||
void ColnodAPI::areDataReady(const std::shared_ptr<Data> &data)
|
||||
{
|
||||
if (++amountData == 4) {
|
||||
|
||||
qInfo(colnod) << tab << "-> COLNOD DATA:";
|
||||
qInfo(colnod) << tab << tab << data->updatedTokens.size() << "TOKENS WERE ADDED/UPDATED";
|
||||
qInfo(colnod) << tab << tab << data->deletedTokens.size() << "TOKENS DELETED";
|
||||
qInfo(colnod) << tab << tab << data->updatedSubjects.size() << "SUBJECTS WERE ADDED/UPDATED";
|
||||
qInfo(colnod) << tab << tab << data->deletedSubjects.size() << "SUBJECTS DELETED";
|
||||
qInfo(colnod) << dash;
|
||||
|
||||
amountData = 0;
|
||||
emit downloadDataFinished(data);
|
||||
}
|
||||
}
|
||||
|
||||
void ColnodAPI::isDataProcessFinished()
|
||||
{
|
||||
if (++amountProccessesFinished == 2) {
|
||||
emit dataProcessFinished();
|
||||
}
|
||||
}
|
||||
|
||||
bool ColnodAPI::saveUpdatedTokens(const std::shared_ptr<Data>& data, const QByteArray &responseData)
|
||||
{
|
||||
Q_ASSERT(data);
|
||||
@ -392,11 +377,6 @@ bool ColnodAPI::saveDeletedSubjects(const std::shared_ptr<Data>& data, const QBy
|
||||
return true;
|
||||
}
|
||||
|
||||
void ColnodAPI::newData()
|
||||
{
|
||||
mData = std::make_shared<Data>();
|
||||
}
|
||||
|
||||
bool ColnodAPI::checkResponse(const QByteArray &responseData)
|
||||
{
|
||||
QJsonDocument doc = QJsonDocument::fromJson(responseData);
|
||||
|
||||
@ -1,35 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "serversdk/requestmanager.h"
|
||||
#include "serversdk/request.h"
|
||||
#include "serversdk/databasetable.h"
|
||||
#include "serversdk/logger.h"
|
||||
#include <serversdk/requestmanager.h>
|
||||
#include <serversdk/request.h>
|
||||
#include <serversdk/databasetable.h>
|
||||
#include <serversdk/logger.h>
|
||||
|
||||
#include "data.h"
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(colnod)
|
||||
|
||||
/**
|
||||
* @brief Helper class for simply work with Colnod API
|
||||
*/
|
||||
class LoginResp : public serversdk::DatabaseTable {
|
||||
Q_OBJECT
|
||||
TABLE_PROPERTY(QString, username, setUsername, "")
|
||||
TABLE_PROPERTY(QString, password, setPassword, "")
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Helper class for simply work with Colnod API
|
||||
*/
|
||||
class AuthToken : public serversdk::DatabaseTable {
|
||||
Q_OBJECT
|
||||
TABLE_PROPERTY(QString, id, setId, QString())
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class for easy switching date time formats
|
||||
* Especially between from and to miliseconds
|
||||
*/
|
||||
class Timestamp : public serversdk::DatabaseTable {
|
||||
Q_OBJECT
|
||||
TABLE_PROPERTY(qint64, timestamp, setTimestamp, 0)
|
||||
public:
|
||||
Timestamp() = default;
|
||||
public:
|
||||
Timestamp() = default;
|
||||
|
||||
void setTimestamp(QDateTime time)
|
||||
void setTimestamp(const QDateTime &time)
|
||||
{
|
||||
setTimestamp(time.toMSecsSinceEpoch());
|
||||
}
|
||||
|
||||
/**
|
||||
* @breif Function for output date in readable form
|
||||
*
|
||||
* @return String in format: 2019-11-12 16:34:03.932
|
||||
*
|
||||
*/
|
||||
QString toDateString()
|
||||
{
|
||||
return QDateTime::fromMSecsSinceEpoch(a_timestamp).toString("yyyy-MM-dd hh:mm:ss.zzz");
|
||||
@ -41,17 +57,43 @@ class ColnodAPI: public QObject
|
||||
Q_OBJECT
|
||||
friend class ColnodTest;
|
||||
public:
|
||||
// ColnodAPI() = default;
|
||||
ColnodAPI() = default;
|
||||
ColnodAPI(serversdk::RequestManager* reqManconst, const bool &dryMode = false, QString userName = "spaceti", QString password = "spaceti1");
|
||||
|
||||
/**
|
||||
* @brief Downloading changed data from Colnod since last Synchronization
|
||||
*
|
||||
* @param time Time of last sync
|
||||
*
|
||||
* @return Function returns data changed after this time
|
||||
*/
|
||||
bool downloadData(const qint64 &time);
|
||||
|
||||
/**
|
||||
* @brief Push all data prepare during synchronization to Colnod
|
||||
* @param data Data which are pushing to Colnod
|
||||
*/
|
||||
void processData(const std::shared_ptr<Data> &data);
|
||||
|
||||
// New approach
|
||||
/**
|
||||
* @brief Endpoint of Colnod API
|
||||
* @param time Returns changed tokens after time
|
||||
* @return Return request, than waiting for finished
|
||||
*/
|
||||
std::shared_ptr<serversdk::Request> getTokensUpdated(const Timestamp &time);
|
||||
|
||||
// Attributes
|
||||
QString userName() const;
|
||||
void setUserName(const QString &userName);
|
||||
QString password() const;
|
||||
void setPassword(const QString &password);
|
||||
|
||||
bool isValid();
|
||||
|
||||
private:
|
||||
std::shared_ptr<serversdk::Request> requestLogin();
|
||||
|
||||
|
||||
std::shared_ptr<serversdk::Request> getTokensUpdated(const Timestamp &time);
|
||||
// All endpoints of Colnod API that we need to use, simply returns request
|
||||
// than we wait for finish
|
||||
std::shared_ptr<serversdk::Request> getTokensDeleted(const Timestamp &time);
|
||||
std::shared_ptr<serversdk::Request> getSubjectsUpdated(const Timestamp &time);
|
||||
std::shared_ptr<serversdk::Request> getSubjectsDeleted(const Timestamp &time);
|
||||
@ -59,57 +101,38 @@ public:
|
||||
std::shared_ptr<serversdk::Request> setTokens(const QHash<QString, std::shared_ptr<Token>> &tokens);
|
||||
std::shared_ptr<serversdk::Request> deleteTokens(const QList<QString> &tokenIds);
|
||||
|
||||
// Attributes
|
||||
QString userName() const;
|
||||
void setUserName(const QString &userName);
|
||||
QString password() const;
|
||||
void setPassword(const QString &password);
|
||||
qint64 lastSync() const;
|
||||
void setlastSync(const qint64 &lastSync);
|
||||
|
||||
bool isValid();
|
||||
|
||||
private:
|
||||
Q_SLOT void areDataReady(const std::shared_ptr<Data>& data);
|
||||
Q_SLOT void isDataProcessFinished();
|
||||
|
||||
private:
|
||||
// Functions which saves response data from Colnod to variable data
|
||||
bool saveUpdatedTokens(const std::shared_ptr<Data>& data, const QByteArray &responseData);
|
||||
bool saveUpdatedSubjects(const std::shared_ptr<Data>& data, const QByteArray &responseData);
|
||||
bool saveDeletedTokens(const std::shared_ptr<Data>& data, const QByteArray &responseData);
|
||||
bool saveDeletedSubjects(const std::shared_ptr<Data>& data, const QByteArray &responseData);
|
||||
|
||||
void newData();
|
||||
|
||||
// Helper func for check format of response
|
||||
bool checkResponse(const QByteArray &responseData);
|
||||
|
||||
QByteArray getTimestampJson(const qint64 &time);
|
||||
std::shared_ptr<serversdk::Request> composeRequest(const QString &endpoint, const QByteArray &data);
|
||||
|
||||
// Helper func for check status of request
|
||||
bool checkRequest(const std::shared_ptr<serversdk::Request> &request);
|
||||
|
||||
bool checkErrors(const std::shared_ptr<serversdk::Request> &request);
|
||||
|
||||
// Prepares request to be sent
|
||||
std::shared_ptr<serversdk::Request> composeRequest(const QString &endpoint, const QByteArray &data);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal which transfer data to Sync Manager
|
||||
*/
|
||||
void downloadDataFinished(std::shared_ptr<Data> = std::shared_ptr<Data>());
|
||||
// void partOfDataReady(std::shared_ptr<Data> = std::shared_ptr<Data>());
|
||||
void partOfDataProcessFinished();
|
||||
void dataProcessFinished();
|
||||
|
||||
void error();
|
||||
void dataProcessFinished(bool success = true);
|
||||
|
||||
private:
|
||||
serversdk::RequestManager* mReqMan = nullptr;
|
||||
QString mHost = "https://192.168.1.3:8443";
|
||||
QString mUserName;
|
||||
QString mPassword;
|
||||
Timestamp mLastSync;
|
||||
bool mDryMode = false;
|
||||
bool mValid = false;
|
||||
|
||||
std::shared_ptr<Data> mData;
|
||||
bool mValid = true;
|
||||
bool mSuccess = true;
|
||||
|
||||
QString authToken;
|
||||
qint16 amountData = 0;
|
||||
qint16 amountProccessesFinished = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -1,14 +1,5 @@
|
||||
#include "data.h"
|
||||
|
||||
|
||||
void Data::clear()
|
||||
{
|
||||
updatedTokens.clear();
|
||||
updatedSubjects.clear();
|
||||
deletedTokens.clear();
|
||||
deletedSubjects.clear();
|
||||
}
|
||||
|
||||
bool Data::loadTokensFromJson(const QByteArray &data)
|
||||
{
|
||||
if (data.isEmpty())
|
||||
@ -27,7 +18,7 @@ bool Data::loadTokensFromJson(const QByteArray &data)
|
||||
|
||||
bool Data::loadSubjectsFormJson(const QByteArray &data)
|
||||
{
|
||||
if (!data.isEmpty())
|
||||
if (data.isEmpty())
|
||||
return false;
|
||||
|
||||
auto doc = QJsonDocument::fromJson(data);
|
||||
@ -40,3 +31,8 @@ bool Data::loadSubjectsFormJson(const QByteArray &data)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int Data::incrementCounter()
|
||||
{
|
||||
return ++counter;
|
||||
}
|
||||
|
||||
@ -27,16 +27,33 @@ class Data
|
||||
friend class DatabaseAPI;
|
||||
public:
|
||||
Data() = default;
|
||||
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* @brief Fill data with tokens from JSON
|
||||
* @param data Response data in JSON format
|
||||
* @return True if success otherwise False
|
||||
*/
|
||||
bool loadTokensFromJson(const QByteArray &data);
|
||||
|
||||
/**
|
||||
* @brief Fill data with subjects from JSON
|
||||
* @param data Response data in JSON format
|
||||
* @return True if success otherwise False
|
||||
*/
|
||||
bool loadSubjectsFormJson(const QByteArray &data);
|
||||
|
||||
QHash<QString, std::shared_ptr<Token>> updatedTokens;
|
||||
QList<QString> deletedTokens;
|
||||
QHash<QString, std::shared_ptr<Subject>> updatedSubjects;
|
||||
QList<QString> deletedSubjects;
|
||||
|
||||
/**
|
||||
* @brief Helper function for check if all endpoints calls are processed
|
||||
* @return Returns acctual amout of processed endpoints
|
||||
*/
|
||||
int incrementCounter();
|
||||
|
||||
private:
|
||||
int counter = 0;
|
||||
};
|
||||
|
||||
struct PreparedData
|
||||
@ -51,4 +68,5 @@ public:
|
||||
// TODO: make unique_ptr ( neeed because of ColnodAPI )
|
||||
std::shared_ptr<Data> databaseData;
|
||||
std::shared_ptr<Data> colnodData;
|
||||
|
||||
};
|
||||
|
||||
@ -49,29 +49,49 @@ std::shared_ptr<Data> DatabaseAPI::downloadData()
|
||||
}
|
||||
|
||||
bool DatabaseAPI::processData(const std::shared_ptr<Data> &data)
|
||||
{
|
||||
uploadTokens(data->updatedTokens);
|
||||
uploadSubjects(data->updatedSubjects);
|
||||
deleteItems(data->deletedTokens, "colnod_token");
|
||||
deleteItems(data->deletedSubjects, "colnod_subject");
|
||||
if ( !data->updatedTokens.isEmpty() ||
|
||||
!data->updatedSubjects.isEmpty() ||
|
||||
!data->deletedTokens.isEmpty() ||
|
||||
!data->deletedSubjects.isEmpty()) {
|
||||
qInfo(database) << dash;
|
||||
{
|
||||
bool res = true;
|
||||
if (!uploadTokens(data->updatedTokens)) {
|
||||
res = false;
|
||||
}
|
||||
if (!uploadSubjects(data->updatedSubjects)) {
|
||||
res = false;
|
||||
}
|
||||
if (!deleteItems(data->deletedTokens, "colnod_token")) {
|
||||
res = false;
|
||||
}
|
||||
if (!deleteItems(data->deletedSubjects, "colnod_subject")) {
|
||||
res = false;
|
||||
}
|
||||
qInfo(database) << tab << "-> DATA PROCESSED TO DATABASE:";
|
||||
qInfo(database) << tab << tab << data->updatedTokens.size() << "TOKENS ADDED/UPDATED";
|
||||
qInfo(database) << tab << tab << data->deletedTokens.size() << "TOKENS DELETED";
|
||||
qInfo(database) << tab << tab << data->updatedSubjects.size() << "SUBJECTS ADDED/UPDATED";
|
||||
qInfo(database) << tab << tab << data->deletedSubjects.size() << "SUBJECTS DELETED";
|
||||
qInfo(database) << dash;
|
||||
|
||||
// TODO: add error handling
|
||||
return true;
|
||||
qInfo(database) << tab << "- push db:" << tab << "tokens [" << data->updatedTokens.size() << ":" << data->deletedTokens.size() <<
|
||||
"] subjects [" << data->updatedSubjects.size() << ":" << data->deletedSubjects.size() << "] [ added/updated : deleted ]";
|
||||
|
||||
if (!data->updatedTokens.isEmpty() || !data->deletedTokens.isEmpty() ||
|
||||
!data->updatedSubjects.isEmpty() || !data->deletedSubjects.isEmpty()) {
|
||||
qInfo(database) << dash;
|
||||
}
|
||||
for (const auto &token : data->updatedTokens) {
|
||||
qInfo(database) << Message::massageTemplate("Updated", "token", "database", token->name());
|
||||
}
|
||||
for (const auto &id : data->deletedTokens) {
|
||||
qInfo(database) << Message::massageTemplate("Deleted", "token", "database", id);
|
||||
}
|
||||
for (const auto &subject : data->updatedSubjects) {
|
||||
qInfo(database) << Message::massageTemplate("Updated", "subject", "database", subject->name());
|
||||
}
|
||||
for (const auto &id : data->deletedSubjects) {
|
||||
qInfo(database) << Message::massageTemplate("Deleted", "subject", "database", id);
|
||||
}
|
||||
if (!data->updatedTokens.isEmpty() || !data->deletedTokens.isEmpty() ||
|
||||
!data->updatedSubjects.isEmpty() || !data->deletedSubjects.isEmpty()) {
|
||||
qInfo(database) << dash;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
// save data to structure Data to be sent to syncManager
|
||||
std::shared_ptr<Data> DatabaseAPI::composeData(const QSqlQuery &updatedQuery, QSqlQuery &deletedQuery)
|
||||
{
|
||||
auto data = std::make_shared<Data>();
|
||||
@ -83,20 +103,32 @@ std::shared_ptr<Data> DatabaseAPI::composeData(const QSqlQuery &updatedQuery, QS
|
||||
data->deletedTokens.append(deletedQuery.value(0).toString());
|
||||
}
|
||||
|
||||
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) << tab << "- src db:" << tab << "tokens [" << data->updatedTokens.size() << ":" << data->deletedTokens.size() <<
|
||||
"] [ added/updated : deleted ]";
|
||||
|
||||
if (!data->updatedTokens.isEmpty() || !data->deletedTokens.isEmpty()) {
|
||||
qInfo(database) << dash;
|
||||
}
|
||||
for (const auto &token : data->updatedTokens) {
|
||||
qInfo(database) << Message::massageTemplate("Download updated", "token", "database", token->name());
|
||||
}
|
||||
for (const auto &id : data->deletedTokens) {
|
||||
qInfo(database) << Message::massageTemplate("Download deleted", "token", "database", id);
|
||||
}
|
||||
if (!data->updatedTokens.isEmpty() || !data->deletedTokens.isEmpty()) {
|
||||
qInfo(database) << dash;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// Time of last synchronization
|
||||
qint64 DatabaseAPI::getLastSync()
|
||||
{
|
||||
auto query = mDbMan->createQuery();
|
||||
if (!executeQuery(query, "SELECT last_sync FROM config")) {
|
||||
qCritical(database) << "ERROR during getting time of last sync. Exit.";
|
||||
emit error();
|
||||
return -1;
|
||||
}
|
||||
if (query.next()){
|
||||
return query.value(0).toLongLong();
|
||||
@ -104,35 +136,19 @@ qint64 DatabaseAPI::getLastSync()
|
||||
return -1;
|
||||
}
|
||||
|
||||
void DatabaseAPI::setLastSync(qint64 timestamp)
|
||||
bool DatabaseAPI::setLastSync(qint64 timestamp)
|
||||
{
|
||||
auto query = mDbMan->createQuery();
|
||||
query.prepare("UPDATE config SET last_sync = :last_sync");
|
||||
query.bindValue(":last_sync", timestamp);
|
||||
if (!executeQuery(query)) {
|
||||
qCritical(database) << "ERROR during set time of this synchronization as last sync time";
|
||||
emit error();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DatabaseAPI::reupdateUpdated(const QHash<QString, std::shared_ptr<Token>> &tokens)
|
||||
{
|
||||
auto query = mDbMan->createQuery();
|
||||
for (const auto &token : tokens){
|
||||
query.prepare("UPDATE colnod_token SET last_update = :last_update WHERE id = :id");
|
||||
query.bindValue(":last_update", token->lastUpdate());
|
||||
query.bindValue(":id", token->id());
|
||||
if (!executeQuery(query)) {
|
||||
qWarning(database) << "ERROR during updating last update of token:" << token->name() << ", it will be synced from Colnod to db in next sync. Last modified will be invalid";
|
||||
}
|
||||
}
|
||||
|
||||
qInfo(database) << equals;
|
||||
qInfo(database) << "Synchronize last update in database with colnod";
|
||||
qInfo(database) << equals;
|
||||
}
|
||||
|
||||
|
||||
// It update last_update time in db of deleted tokens, because in colnod is later time (time of real deletion from Colnod)
|
||||
void DatabaseAPI::reupdateDeleted(const QList<QString>& ids)
|
||||
{
|
||||
auto query = mDbMan->createQuery();
|
||||
@ -156,51 +172,19 @@ qint64 DatabaseAPI::getNow()
|
||||
return -1;
|
||||
}
|
||||
query.next();
|
||||
qDebug() << "Database time:" << QDateTime::fromMSecsSinceEpoch(query.value(0).toLongLong()).toString("yyyy-MM-dd hh:mm:ss.zzz");
|
||||
qDebug() << "Current time:" << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz");
|
||||
return query.value(0).toLongLong();
|
||||
}
|
||||
|
||||
void DatabaseAPI::initNewTokens()
|
||||
{
|
||||
auto query = mDbMan->createQuery();
|
||||
if (!executeQuery(query, "SELECT * FROM colnod_token WHERE name IS NULL")) {
|
||||
qWarning(database) << "ERROR during getting uninitialized tokens";
|
||||
}
|
||||
QHash<QString, std::shared_ptr<Token>> tokensToInit;
|
||||
auto list = utils->tableFromQuery<Token>(query);
|
||||
for (const auto &token : list) {
|
||||
qint16 num = getNumOfTokensOfSubject(token->subjectId());
|
||||
token->setName(getSubjectNameByTokenId(token->id()) + "_mobile_" + QString::number(num + 1));
|
||||
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);
|
||||
}
|
||||
|
||||
// All tokens which are pushed to Colnad are update back to db, because of diffrent last_update and init of new 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
|
||||
// ERROR -> not possible to update
|
||||
auto query = mDbMan->createQuery();
|
||||
for (const auto &token : tokens) {
|
||||
// Get token
|
||||
|
||||
if (exists(token->id(), "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());
|
||||
}
|
||||
else {
|
||||
// TODO: first check if OK, then message
|
||||
// OK -> token was updated
|
||||
// ERROR -> not possible to update
|
||||
query = utils->insertIntoTable(token.get(), "colnod_token");
|
||||
qInfo(database).noquote() << Message::massageTemplate("Adding", "token", "database", token->name());
|
||||
}
|
||||
if (!query.isActive()) {
|
||||
mValid = false;
|
||||
@ -230,11 +214,9 @@ bool DatabaseAPI::uploadSubjects(const QHash<QString, std::shared_ptr<Subject>>
|
||||
}
|
||||
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());
|
||||
}
|
||||
if (!query.isActive()) {
|
||||
mValid = false;
|
||||
@ -249,14 +231,26 @@ bool 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).noquote() << Message::massageTemplate("Deleting", tableName.mid(tableName.indexOf("_") + 1, tableName.length() - 1), "database", id);
|
||||
|
||||
if (tableName == "colnod_subject") {
|
||||
for (const auto &id : ids) {
|
||||
query.prepare("DELETE FROM colnod_subject_attribute WHERE subject_id = :id");
|
||||
query.bindValue(":id", id);
|
||||
if (!executeQuery(query)) {
|
||||
qWarning(database) << "ERROR during marking as deleted:" << id;
|
||||
mValid = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &id : ids) {
|
||||
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);
|
||||
if (!executeQuery(query)) {
|
||||
qWarning(database) << "ERROR during marking token as deleted:" << id;
|
||||
qWarning(database) << "ERROR during marking as deleted:" << id;
|
||||
mValid = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -270,7 +264,6 @@ std::shared_ptr<Token> DatabaseAPI::getToken(const QString &id)
|
||||
query.bindValue(":id", id);
|
||||
if (!executeQuery(query)) {
|
||||
qCritical(database) << "ERROR during accessing existing tokens. EXIT";
|
||||
emit error();
|
||||
return nullptr;
|
||||
}
|
||||
auto list = utils->tableFromQuery<Token>(query);
|
||||
@ -279,19 +272,6 @@ std::shared_ptr<Token> DatabaseAPI::getToken(const QString &id)
|
||||
return list.at(0);
|
||||
}
|
||||
|
||||
bool DatabaseAPI::isAlreadyDeleted(const QString &id)
|
||||
{
|
||||
auto token = getToken(id);
|
||||
if (!token) {
|
||||
if (id.isEmpty()) {
|
||||
|
||||
}
|
||||
qWarning(database) << "Token deleted in colnod doesn't exists in db, will be noted as already deleted in stats";
|
||||
return true;
|
||||
}
|
||||
return token->deleted();
|
||||
}
|
||||
|
||||
bool DatabaseAPI::isValid()
|
||||
{
|
||||
return mValid;
|
||||
@ -312,7 +292,7 @@ int DatabaseAPI::exists(const QString &id, const QString &tableName)
|
||||
qint16 DatabaseAPI::getNumOfTokensOfSubject(const QString &id)
|
||||
{
|
||||
auto query = mDbMan->createQuery();
|
||||
query.prepare("SELECT 1 FROM colnod_token WHERE subject_id = :id AND deleted = false");
|
||||
query.prepare("SELECT 1 FROM colnod_token WHERE subject_id = :id AND description = 'mobile'");
|
||||
query.bindValue(":id", id);
|
||||
if (!executeQuery(query)) {
|
||||
qCritical(database) << "ERROR during accessing existing tokens. EXIT(1)";
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <QSql>
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include <serversdk/databasemanager.h>
|
||||
#include <serversdk/databasetable.h>
|
||||
#include <serversdk/databaseutils.h>
|
||||
#include <serversdk/logger.h>
|
||||
|
||||
#include "data.h"
|
||||
|
||||
#include "serversdk/databasemanager.h"
|
||||
#include "serversdk/databasetable.h"
|
||||
#include "serversdk/databaseutils.h"
|
||||
#include "serversdk/logger.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(database)
|
||||
|
||||
|
||||
@ -20,46 +20,104 @@ class DatabaseAPI : public QObject
|
||||
public:
|
||||
explicit DatabaseAPI(serversdk::DatabaseManager *dbMan, bool dryMode);
|
||||
|
||||
/**
|
||||
* @brief Connecting to database
|
||||
* @param host
|
||||
* @param name
|
||||
* @param user
|
||||
* @param password
|
||||
* @return True if success False otherwise
|
||||
*/
|
||||
bool open(const QString& host = "192.168.1.94",
|
||||
const QString& name = "deloitte",
|
||||
const QString& user = "postgres",
|
||||
const QString& password = "34rjkciea12");
|
||||
|
||||
bool executeQuery(QSqlQuery &query, const QString &statement = QString());
|
||||
|
||||
std::shared_ptr<Data> downloadData();
|
||||
bool processData(const std::shared_ptr<Data> &data);
|
||||
|
||||
/**
|
||||
* @brief Get time of last synchronization
|
||||
*
|
||||
* LastSync time is stored in database, config table
|
||||
*/
|
||||
qint64 getLastSync();
|
||||
void setLastSync(qint64 timestamp);
|
||||
void reupdateUpdated(const QHash<QString, std::shared_ptr<Token> > &tokens);
|
||||
|
||||
/**
|
||||
* @brief Set time of acctual synchronization
|
||||
* @param timestamp
|
||||
*/
|
||||
bool setLastSync(qint64 timestamp);
|
||||
|
||||
/**
|
||||
* @brief Update time of tokens which were deleted in actual sync
|
||||
* @param ids Ids of deleted items
|
||||
*/
|
||||
void reupdateDeleted(const QList<QString>& ids);
|
||||
|
||||
/**
|
||||
* @brief Get time from database server
|
||||
* @return Time in miliseconds
|
||||
*/
|
||||
qint64 getNow();
|
||||
|
||||
void initNewTokens();
|
||||
|
||||
// process data
|
||||
/**
|
||||
* @brief Push tokens prepared in this sync to database
|
||||
*
|
||||
* @param tokens Tokens to be pushed to database
|
||||
* @param filters Can be used to omit tokens properties (Properties in filters won't be pushed to database
|
||||
*
|
||||
* @return True if success, False otherwise
|
||||
*/
|
||||
bool uploadTokens(const QHash<QString, std::shared_ptr<Token> > &tokens, const QSet<QString> &filters = {});
|
||||
|
||||
/**
|
||||
* @brief Push subjects prepared in this sync to database
|
||||
*
|
||||
* @param subjects Subjects prepared to be pushed to database
|
||||
*
|
||||
* @return True if success, False otherwise
|
||||
*/
|
||||
bool uploadSubjects(const QHash<QString, std::shared_ptr<Subject> > &subjects);
|
||||
|
||||
/**
|
||||
* @brief Set deleted of tokens/subjects to true
|
||||
*
|
||||
* @param ids Items which was prepared to be deleted from database
|
||||
* @param tableName Name of table with subjects or tokens
|
||||
*
|
||||
* @return True if success, False otherwise
|
||||
*/
|
||||
bool deleteItems(const QList<QString> &ids, const QString &tableName);
|
||||
|
||||
/**
|
||||
* @brief Get token from database
|
||||
*
|
||||
* @param id Id of token accessing
|
||||
*
|
||||
* @return Return token
|
||||
*/
|
||||
std::shared_ptr<Token> getToken(const QString &id);
|
||||
|
||||
bool isAlreadyDeleted(const QString &id);
|
||||
|
||||
/**
|
||||
* @brief Check if this sync was without any problem
|
||||
*/
|
||||
bool isValid();
|
||||
|
||||
// Helper functions for naming new tokens
|
||||
qint16 getNumOfTokensOfSubject(const QString &id);
|
||||
QString getSubjectNameByTokenId(const QString &tokenId);
|
||||
|
||||
private:
|
||||
int exists(const QString &id, const QString &tableName);
|
||||
bool executeQuery(QSqlQuery &query, const QString &statement = QString());
|
||||
|
||||
QSqlQuery getUpdatedTokens();
|
||||
std::shared_ptr<Data> composeData(const QSqlQuery &updatedQuery, QSqlQuery &deletedQuery);
|
||||
|
||||
signals:
|
||||
void downloadDataFinished(std::shared_ptr<Data> = std::shared_ptr<Data>());
|
||||
void error();
|
||||
|
||||
private:
|
||||
bool mValid = true;
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDateTime>
|
||||
#include "serversdk/databasetable.h"
|
||||
#include <qjsondocument.h>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include <serversdk/databasetable.h>
|
||||
|
||||
class SubjectAttribute : public serversdk::DatabaseTable {
|
||||
Q_OBJECT
|
||||
TABLE_PROPERTY(QString, id, setId, "")
|
||||
@ -13,7 +14,6 @@ class SubjectAttribute : public serversdk::DatabaseTable {
|
||||
TABLE_PROPERTY(QString, subjectId, setSubjectId, "")
|
||||
};
|
||||
|
||||
|
||||
class Subject : public serversdk::DatabaseTable {
|
||||
Q_OBJECT
|
||||
TABLE_PROPERTY(QString, id, setId, QString())
|
||||
@ -24,7 +24,6 @@ class Subject : public serversdk::DatabaseTable {
|
||||
TABLE_PROPERTY(QDateTime, lastModified, setLastModified, QDateTime())
|
||||
TABLE_PROPERTY(bool, deleted, setDeleted, false)
|
||||
|
||||
|
||||
public:
|
||||
Subject() = default;
|
||||
explicit Subject(const QString& name);
|
||||
@ -32,7 +31,6 @@ public:
|
||||
bool fromJson(const QByteArray &data) override;
|
||||
QList<std::shared_ptr <SubjectAttribute>> getAttributes();
|
||||
|
||||
|
||||
private:
|
||||
QList<std::shared_ptr <SubjectAttribute>> attributes;
|
||||
};
|
||||
|
||||
@ -28,7 +28,7 @@ bool SyncManager::databaseInitialization()
|
||||
}
|
||||
|
||||
// here -> nothing can fail
|
||||
mlastSync.setTimestamp(database->getLastSync());
|
||||
mlastSync.setTimestamp(lastsync_in_ms);
|
||||
colnod = std::make_shared<ColnodAPI>(&reqMan, mDryMode);
|
||||
return true;
|
||||
}
|
||||
@ -36,22 +36,14 @@ bool SyncManager::databaseInitialization()
|
||||
|
||||
bool SyncManager::startSynchronization()
|
||||
{
|
||||
Q_ASSERT(database);
|
||||
// I have to current time from database
|
||||
// Need current time from db server
|
||||
qint64 syncBegin = database->getNow();
|
||||
if (syncBegin == -1) {
|
||||
qCritical(syncmanager) << "Not possible to get last sync date";
|
||||
return false;
|
||||
}
|
||||
|
||||
qInfo(syncmanager) << equals;
|
||||
qInfo(syncmanager) << "SYNCHRONIZATION BEGIN";
|
||||
|
||||
qInfo(syncmanager) << equals;
|
||||
qInfo(syncmanager) << "DOWNLOADING DATA -> BEGIN";
|
||||
qInfo(syncmanager) << dash;
|
||||
qInfo(syncmanager).noquote() << "Modified data since last synchronization (" << mlastSync.toDateString() << "):";
|
||||
qInfo(syncmanager) << dash;
|
||||
qInfo(syncmanager) << tab << "- begin sync ( previous sync" << mlastSync.toDateString() << ")";
|
||||
|
||||
// GETTING DATA FROM DATABASE
|
||||
auto databaseData = database->downloadData();
|
||||
@ -63,39 +55,30 @@ bool SyncManager::startSynchronization()
|
||||
|
||||
colnod->downloadData(mlastSync.timestamp());
|
||||
connect(colnod.get(), &ColnodAPI::downloadDataFinished, [=](const std::shared_ptr<Data> &colnodData) {
|
||||
qInfo(syncmanager) << "DOWNLOADING DATA -> FINISHED";
|
||||
qInfo(syncmanager) << equals;
|
||||
|
||||
// NOW I HAVE DATA FROM COLNOD
|
||||
if (!colnodData) {
|
||||
qCritical(syncmanager) << "Not possible to get correct data from colnod";
|
||||
QCoreApplication::exit(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
// NOW I SHOULD HAVE VALID DATA FROM COLNOD
|
||||
|
||||
|
||||
std::unique_ptr<PreparedData> preparedData = prepareDataNew(databaseData, colnodData);
|
||||
std::unique_ptr<PreparedData> preparedData = prepareData(databaseData, colnodData);
|
||||
if (!preparedData) {
|
||||
qCritical(syncmanager) << "Not possible to compose data";
|
||||
QCoreApplication::exit(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
qInfo(syncmanager) << equals;
|
||||
qInfo(syncmanager) << "PROCESSING DATA -> BEGIN";
|
||||
qInfo(syncmanager) << dash;
|
||||
qInfo(syncmanager) << "Push changes to both Colnod and Database:";
|
||||
qInfo(syncmanager) << dash;
|
||||
|
||||
if (!database->processData(preparedData->colnodData)) {
|
||||
qCritical(syncmanager) << "Not possible to upload data to database";
|
||||
}
|
||||
|
||||
// data is processed to other sides
|
||||
connect(colnod.get(), &ColnodAPI::dataProcessFinished, [&](){
|
||||
qInfo(syncmanager) << "PROCESSING DATA -> FINISHED";
|
||||
qInfo(syncmanager) << equals;
|
||||
connect(colnod.get(), &ColnodAPI::dataProcessFinished, [&,syncBegin](bool success){
|
||||
if (!success) {
|
||||
qCritical(syncmanager) << "Not possible to upload data to colnod";
|
||||
}
|
||||
|
||||
// REUPDATE tokens pushed from database to colnod (cause of lastUpdate time)
|
||||
Timestamp time;
|
||||
@ -106,6 +89,7 @@ bool SyncManager::startSynchronization()
|
||||
|
||||
// updated data are ready
|
||||
connect(tokensRequest.get(), &serversdk::Request::finished, [=](){
|
||||
|
||||
auto uploadedData = std::make_shared<Data>();
|
||||
uploadedData->loadTokensFromJson(tokensRequest->responseData());
|
||||
|
||||
@ -122,34 +106,26 @@ bool SyncManager::startSynchronization()
|
||||
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";
|
||||
qWarning(syncmanager) << "Unsuccessful FINISH, check warnings";
|
||||
}
|
||||
else {
|
||||
database->setLastSync(syncBegin);
|
||||
qInfo(syncmanager).noquote() << "Update last synchronization time to time of this sync ("
|
||||
<< QDateTime::fromMSecsSinceEpoch(syncBegin).toString("yyyy-MM-dd hh:mm:ss.zzz")
|
||||
<< ")";
|
||||
// set new time of last sync to this time of this run
|
||||
if (!database->setLastSync(syncBegin)) {
|
||||
qWarning(syncmanager) << "Unsuccessful FINISH, check warnings";
|
||||
}
|
||||
qInfo(syncmanager) << "Successful FINISH";
|
||||
}
|
||||
|
||||
qInfo(syncmanager) << equals;
|
||||
qInfo(syncmanager) << "SYNCHRONIZATION FINISHED";
|
||||
qInfo(syncmanager) << equals;
|
||||
|
||||
QCoreApplication::exit();
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
colnod->processData(preparedData->databaseData); // TODO: errors???
|
||||
|
||||
//qCritical(syncmanager) << "Not possible to upload data to colnod";
|
||||
colnod->processData(preparedData->databaseData);
|
||||
});
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<PreparedData> SyncManager::prepareDataNew(const std::shared_ptr<Data> &databaseData, const std::shared_ptr<Data> &colnodData)
|
||||
// goes through downloaded data and check if consist conflicts (both sides edit), already sync/deleted tokens or new tokens
|
||||
std::unique_ptr<PreparedData> SyncManager::prepareData(const std::shared_ptr<Data> &databaseData, const std::shared_ptr<Data> &colnodData)
|
||||
{
|
||||
auto preparedColnodData = std::make_shared<Data>();
|
||||
auto preparedDatabaseData = std::make_shared<Data>();
|
||||
@ -157,13 +133,35 @@ std::unique_ptr<PreparedData> SyncManager::prepareDataNew(const std::shared_ptr<
|
||||
QList<QString> conflicts;
|
||||
QList<QString> alreadySynced;
|
||||
|
||||
qInfo(syncmanager) << equals;
|
||||
qInfo(syncmanager) << "PREPARING DATA -> BEGIN";
|
||||
qInfo(syncmanager) << dash;
|
||||
qInfo(syncmanager) << "Resolve conflicts ( changes on same item on both Colnod and DB ):";
|
||||
qInfo(syncmanager) << dash;
|
||||
for (const auto &databaseToken : databaseData->updatedTokens) {
|
||||
if (databaseToken->name().isEmpty()) {
|
||||
initNewToken(databaseToken);
|
||||
}
|
||||
|
||||
// restriction cauesed by colnod rest api
|
||||
if (databaseToken->description() != "mobile") {
|
||||
qCritical(syncmanager) << "Token:" << databaseToken->id() << "doesn't have 'mobile' in description, can't be ";
|
||||
continue;
|
||||
}
|
||||
|
||||
// no conflict
|
||||
if (!colnodData->updatedTokens.contains(databaseToken->id())) {
|
||||
preparedDatabaseData->updatedTokens.insert(databaseToken->id(), databaseToken);
|
||||
continue;
|
||||
}
|
||||
|
||||
// database change is newer
|
||||
if (databaseToken > colnodData->updatedTokens.value(databaseToken->id())) {
|
||||
preparedDatabaseData->updatedTokens.insert(databaseToken->id(), databaseToken);
|
||||
}
|
||||
}
|
||||
|
||||
preparedDatabaseData->deletedTokens = databaseData->deletedTokens;
|
||||
|
||||
qInfo(syncmanager) << tab << "- prep db:" << tab << "tokens [" << preparedDatabaseData->updatedTokens.size() << ":" << preparedDatabaseData->deletedTokens.size() <<
|
||||
"] [ added/updated : deleted ]";
|
||||
|
||||
// add all data which should be pushed to database
|
||||
for (const auto &colnodToken : colnodData->updatedTokens) {
|
||||
|
||||
// not conflict so add to prepered tokens
|
||||
@ -194,46 +192,21 @@ std::unique_ptr<PreparedData> SyncManager::prepareDataNew(const std::shared_ptr<
|
||||
}
|
||||
|
||||
for (const auto &id : colnodData->deletedTokens) {
|
||||
if (!database->isAlreadyDeleted(id)) {
|
||||
auto corespondingToken = database->getToken(id);
|
||||
if ( !corespondingToken) {
|
||||
qWarning(syncmanager) << "Token:" << id << ", deleted in colnod, but not exists in db";
|
||||
continue;
|
||||
}
|
||||
if ( !corespondingToken->deleted()) {
|
||||
preparedColnodData->deletedTokens.append(id);
|
||||
}
|
||||
}
|
||||
|
||||
qInfo(syncmanager) << tab << "-> COLNOD DATA - CHANGES:";
|
||||
qInfo(syncmanager) << tab << tab << conflicts.size() << "TOKENS WERE ADDED/UPDATED IN DATABASE AFTER";
|
||||
qInfo(syncmanager) << tab << tab << alreadySynced.size() << "TOKENS WERE ALREADY SYNCED";
|
||||
qInfo(syncmanager) << tab << tab << colnodData->deletedTokens.size() - preparedColnodData->deletedTokens.size() << "TOKENS WERE ALREADY DELETED";
|
||||
qInfo(syncmanager) << dash;
|
||||
preparedColnodData->updatedSubjects = colnodData->updatedSubjects;
|
||||
preparedColnodData->deletedSubjects = colnodData->deletedSubjects;
|
||||
|
||||
for (const auto &databaseToken : databaseData->updatedTokens) {
|
||||
if (databaseToken->name().isEmpty()) {
|
||||
initNewToken(databaseToken);
|
||||
}
|
||||
|
||||
// restriction cauesed by colnod rest api
|
||||
if (databaseToken->description() != "mobile") {
|
||||
qCritical(syncmanager) << "Token:" << databaseToken->id() << "doesn't have 'mobile' in description, can't be ";
|
||||
continue;
|
||||
}
|
||||
|
||||
// no conflict
|
||||
if (!colnodData->updatedTokens.contains(databaseToken->id())) {
|
||||
preparedDatabaseData->updatedTokens.insert(databaseToken->id(), databaseToken);
|
||||
continue;
|
||||
}
|
||||
|
||||
// database change is newer
|
||||
if (databaseToken > colnodData->updatedTokens.value(databaseToken->id())) {
|
||||
preparedDatabaseData->updatedTokens.insert(databaseToken->id(), databaseToken);
|
||||
}
|
||||
}
|
||||
|
||||
qInfo(syncmanager) << tab << "-> DATABASE DATA - CHANGES:";
|
||||
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";
|
||||
qInfo(syncmanager) << equals;
|
||||
qInfo(syncmanager) << tab << "- prep col:" << tab << "tokens [" << preparedColnodData->updatedTokens.size() << ":" << preparedColnodData->deletedTokens.size() <<
|
||||
"] subjects [" << preparedColnodData->updatedSubjects.size() << ":" << preparedColnodData->deletedSubjects.size() << "] [ added/updated : deleted ]";
|
||||
|
||||
|
||||
auto preparedData = std::make_unique<PreparedData>(preparedDatabaseData, preparedColnodData);
|
||||
@ -251,97 +224,3 @@ void SyncManager::initNewToken(const std::shared_ptr<Token>& token)
|
||||
|
||||
qInfo(syncmanager).noquote() << Message::massageTemplate("Inicializing new", "token", "sync manager", token->name());
|
||||
}
|
||||
|
||||
std::unique_ptr<PreparedData> SyncManager::prepareDataUsindOld(const std::shared_ptr<Data> &databaseData, const std::shared_ptr<Data> &colnodData)
|
||||
{
|
||||
qInfo(syncmanager) << equals;
|
||||
qInfo(syncmanager) << "PREPARING DATA -> BEGIN";
|
||||
qInfo(syncmanager) << dash;
|
||||
qInfo(syncmanager) << "Resolve conflicts ( changes on same item on both Colnod and DB ):";
|
||||
qInfo(syncmanager) << dash;
|
||||
|
||||
|
||||
Q_ASSERT(colnodData);
|
||||
Q_ASSERT(databaseData);
|
||||
|
||||
std::shared_ptr<Data> cloneColnodDataToProcess = std::make_shared<Data>(*colnodData);
|
||||
std::shared_ptr<Data> cloneDatabaseDataToProcess = std::make_shared<Data>(*databaseData);
|
||||
|
||||
QList<QString> conflicts;
|
||||
QList<QString> alreadySynced;
|
||||
|
||||
// check modifed tokens from colnod, dont want update token, if it was edited in db after or has been already synced
|
||||
for (const auto &colnodToken : cloneColnodDataToProcess->updatedTokens) {
|
||||
if (cloneDatabaseDataToProcess->updatedTokens.contains(colnodToken->id())) {
|
||||
// updated in db later
|
||||
if (cloneDatabaseDataToProcess->updatedTokens.value(colnodToken->id()) > colnodToken) {
|
||||
conflicts.append(colnodToken->id());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
auto token = database->getToken(colnodToken->id());
|
||||
if ( token )
|
||||
// alredy synced ( tokens are same )
|
||||
if (token == colnodToken)
|
||||
alreadySynced.append(colnodToken->id());
|
||||
}
|
||||
// remove tokens which should be not updated
|
||||
for (const auto &id : conflicts)
|
||||
cloneColnodDataToProcess->updatedTokens.remove(id);
|
||||
for (const auto &id : alreadySynced)
|
||||
cloneColnodDataToProcess->updatedTokens.remove(id);
|
||||
|
||||
qInfo(syncmanager) << tab << "-> COLNOD DATA - CHANGES:";
|
||||
qInfo(syncmanager) << tab << tab << conflicts.size() << "TOKENS WERE ADDED/UPDATED IN DATABASE TOO";
|
||||
qInfo(syncmanager) << tab << tab << alreadySynced.size() << "TOKENS WERE ALREADY SYNCED";
|
||||
|
||||
|
||||
|
||||
conflicts.clear();
|
||||
|
||||
// chech for already deleted ( in previous synced tokens were deleted from colnod, so it come to this sync but we dont want to sync it again
|
||||
for (const auto &id : cloneColnodDataToProcess->deletedTokens) {
|
||||
if (database->isAlreadyDeleted(id)) {
|
||||
conflicts.append(id);
|
||||
}
|
||||
}
|
||||
for (const auto &id : conflicts) {
|
||||
cloneColnodDataToProcess->deletedTokens.removeOne(id);
|
||||
}
|
||||
|
||||
qInfo(syncmanager) << tab << tab << conflicts.size() << "TOKENS WERE ALREADY DELETED";
|
||||
qInfo(syncmanager) << dash;
|
||||
|
||||
conflicts.clear();
|
||||
|
||||
// chech modified from db, remove token if it was edited in colnod later
|
||||
for (const auto &databaseToken : cloneDatabaseDataToProcess->updatedTokens) {
|
||||
if (cloneColnodDataToProcess->updatedTokens.contains(databaseToken->id())) {
|
||||
if (databaseToken < cloneColnodDataToProcess->updatedTokens.value(databaseToken->id()))
|
||||
conflicts.append(databaseToken->id());
|
||||
}
|
||||
else {
|
||||
// restriction cauesed by colnod rest api
|
||||
if (databaseToken->description() != "mobile") {
|
||||
qCritical(syncmanager) << "Token:" << databaseToken->id() << "doesn't have 'mobile' in description, can't be ";
|
||||
conflicts.append(databaseToken->id());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto &id : conflicts)
|
||||
cloneColnodDataToProcess->updatedTokens.remove(id);
|
||||
|
||||
qInfo(syncmanager) << tab << "-> DATABASE DATA - CHANGES:";
|
||||
qInfo(syncmanager) << tab << tab << conflicts.size() << "TOKENS WERE ADDED/UPDATED IN IN COLNOD TOO";
|
||||
qInfo(syncmanager) << dash;
|
||||
|
||||
qInfo(syncmanager) << "PREPARING DATA -> FINISHED";
|
||||
qInfo(syncmanager) << equals;
|
||||
|
||||
// Prepare data
|
||||
auto preparedData = std::make_unique<PreparedData>();
|
||||
preparedData->colnodData = cloneColnodDataToProcess;
|
||||
preparedData->databaseData = cloneDatabaseDataToProcess;
|
||||
|
||||
return preparedData;
|
||||
}
|
||||
|
||||
@ -15,29 +15,22 @@ public:
|
||||
bool databaseInitialization();
|
||||
bool startSynchronization();
|
||||
|
||||
// New approach
|
||||
private:
|
||||
/**
|
||||
* @brief Preapre data to be pushed to database and colnod from actual downloaded data
|
||||
* @param data from database
|
||||
* @param data from colnod
|
||||
* @return prepared data to be pushed into colnod and db
|
||||
*
|
||||
* @todo rename when removed old aproach
|
||||
*/
|
||||
std::unique_ptr<PreparedData> prepareDataNew(const std::shared_ptr<Data> &databaseData, const std::shared_ptr<Data> &colnodData);
|
||||
std::unique_ptr<PreparedData> prepareDataUsindOld(const std::shared_ptr<Data> &databaseData, const std::shared_ptr<Data> &colnodData);
|
||||
std::unique_ptr<PreparedData> prepareData(const std::shared_ptr<Data> &databaseData, const std::shared_ptr<Data> &colnodData);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Set default values to new tokens from db
|
||||
* @param token New token in this run
|
||||
*/
|
||||
void initNewToken(const std::shared_ptr<Token>& token);
|
||||
|
||||
void updateLastUpdate(qint64 syncBegin);
|
||||
|
||||
signals:
|
||||
void syncFinished();
|
||||
|
||||
void error();
|
||||
|
||||
private:
|
||||
std::shared_ptr<ColnodAPI> colnod;
|
||||
std::shared_ptr<DatabaseAPI> database;
|
||||
|
||||
@ -45,6 +45,7 @@ QByteArray Token::jsonData(const QSet<QString> &filters) const
|
||||
QJsonDocument doc = QJsonDocument::fromVariant(variantMap);
|
||||
return doc.toJson(QJsonDocument::Compact);
|
||||
}
|
||||
|
||||
bool Token::fromJson(const QByteArray &data)
|
||||
{
|
||||
QJsonDocument doc = QJsonDocument::fromJson(data);
|
||||
@ -81,24 +82,3 @@ QByteArray Token::idsToJSON(const QList<QString> &ids)
|
||||
doc.setObject(items);
|
||||
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());
|
||||
}
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDateTime>
|
||||
#include "serversdk/databasetable.h"
|
||||
#include <QSqlQuery>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
#include <serversdk/databasetable.h>
|
||||
|
||||
class Token : public serversdk::DatabaseTable {
|
||||
Q_OBJECT
|
||||
TABLE_PROPERTY(QString, id, setId, QString())
|
||||
@ -24,18 +25,16 @@ class Token : public serversdk::DatabaseTable {
|
||||
TABLE_PROPERTY(QDateTime, lastModified, setLastModified, QDateTime())
|
||||
TABLE_PROPERTY(bool, deleted, setDeleted, false)
|
||||
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* # Needed values to proper sync
|
||||
*
|
||||
* * id - primary key
|
||||
* * lastModified - when it was edited/modified
|
||||
* * tokenData - key to open doors
|
||||
* * subjectId - no way of make unassinged token (token without subject)
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* # Needed values to proper sync
|
||||
*
|
||||
* * id - primary key
|
||||
* * lastModified - when it was edited/modified
|
||||
* * tokenData - key to open doors
|
||||
* * subjectId - no way of make unassinged token (token without subject)
|
||||
*
|
||||
*/
|
||||
|
||||
explicit Token() = default;
|
||||
~Token() override;
|
||||
@ -49,6 +48,11 @@ public:
|
||||
friend bool operator>(const std::shared_ptr<Token> &lToken, const std::shared_ptr<Token> &rToken){
|
||||
return lToken->lastModified() > rToken->lastUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compare of two tokens
|
||||
* @return Returns true, if tokens are same
|
||||
*/
|
||||
friend bool operator==(const std::shared_ptr<Token> &lToken, const std::shared_ptr<Token> &rToken)
|
||||
{
|
||||
return lToken->id() == rToken->id() &&
|
||||
@ -65,8 +69,6 @@ public:
|
||||
lToken->subjectId() == rToken->subjectId();
|
||||
}
|
||||
|
||||
void fromSQLRecord(const QSqlQuery& query);
|
||||
|
||||
static QByteArray tokensToColnodJson(const QHash<QString, std::shared_ptr<Token> > &tokens);
|
||||
static QByteArray idsToJSON(const QList<QString> &ids);
|
||||
|
||||
|
||||
@ -18,12 +18,11 @@ public:
|
||||
qRegisterMetaType<std::shared_ptr<serversdk::Request>>("std::shared_ptr<Request>");
|
||||
}
|
||||
|
||||
private :
|
||||
Q_SLOT void getTokens();
|
||||
Q_SLOT void download_test();
|
||||
Q_SLOT void download_data_test_now();
|
||||
Q_SLOT void download_data_fail_test();
|
||||
private slots:
|
||||
void login();
|
||||
void download_data_test();
|
||||
void download_data_test_now();
|
||||
void download_data_fail_test();
|
||||
|
||||
private:
|
||||
QString getLoginToken(ColnodAPI &colnod);
|
||||
@ -34,67 +33,29 @@ void ColnodTest::login()
|
||||
serversdk::RequestManager reqMan;
|
||||
ColnodAPI colnod(&reqMan);
|
||||
auto login = colnod.requestLogin();
|
||||
QVERIFY(login);
|
||||
QVERIFY(login->networkReply());
|
||||
QSignalSpy spy(login.get(), &serversdk::Request::finished);
|
||||
QCOMPARE(spy.count(), 0);
|
||||
QVERIFY(spy.wait());
|
||||
QCOMPARE(spy.count(), 1);
|
||||
QVERIFY(login->responseData().contains("id"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ColnodTest::getTokens()
|
||||
{
|
||||
// FIXME: finish this -> must be valid test testing something
|
||||
// FIXME: Was not testing anything only causing bug
|
||||
serversdk::RequestManager reqMan;
|
||||
ColnodAPI colnod(&reqMan);
|
||||
|
||||
// get login token
|
||||
// FIXME: calling login request two times
|
||||
auto login = colnod.requestLogin();
|
||||
QSignalSpy spy(login.get(), &serversdk::Request::finished);
|
||||
QVERIFY(spy.isValid());
|
||||
QVERIFY(spy.wait());
|
||||
//login->responseData().mid(7,36);
|
||||
// NOTE: second calling of loging request
|
||||
//QString token = getLoginToken(colnod);
|
||||
Timestamp time;
|
||||
time.setTimestamp(QDateTime::currentMSecsSinceEpoch());
|
||||
auto request = colnod.getTokensUpdated(time);
|
||||
|
||||
// FIXING BUG: creating request not waiting for it immediatelly destroying request
|
||||
// immediatelly reqMan goes out of scope destroying QNetworkRequestManager with QNetworkReply running.
|
||||
QSignalSpy requestSpy(request.get(), &serversdk::Request::finished);
|
||||
QVERIFY(requestSpy.wait()); // <-- have to wait here for request!!!!
|
||||
// FIXME: check request and finish test!!
|
||||
}
|
||||
|
||||
void ColnodTest::download_test()
|
||||
void ColnodTest::download_data_test()
|
||||
{
|
||||
serversdk::RequestManager reqMan;
|
||||
reqMan.setIgnoreSsl(true);
|
||||
//reqMan.setIgnoreSsl(true);
|
||||
ColnodAPI colnod(&reqMan);
|
||||
|
||||
QVERIFY(!colnod.mData);
|
||||
QVERIFY(!colnod.mValid);
|
||||
QVERIFY(!colnod.amountData);
|
||||
QVERIFY(!colnod.amountProccessesFinished);
|
||||
|
||||
QSignalSpy spy(&colnod, &ColnodAPI::downloadDataFinished);
|
||||
QVERIFY(spy.isValid());
|
||||
QVERIFY(colnod.downloadData(1570190399259));
|
||||
colnod.downloadData(1570190399259);
|
||||
QVERIFY(spy.wait());
|
||||
QVERIFY(colnod.amountData == 0);
|
||||
|
||||
|
||||
auto data = qvariant_cast<std::shared_ptr<Data>>(spy.at(0).at(0));
|
||||
QVERIFY(data);
|
||||
|
||||
QVERIFY(! data->updatedTokens.isEmpty());
|
||||
QVERIFY(data->updatedTokens.contains("5e2f1260-da1c-441f-9644-24dfe3b97b2a"));
|
||||
QVERIFY(data->updatedTokens.contains("d3a83bea-2587-4687-946d-ee847eccf477"));
|
||||
}
|
||||
|
||||
void ColnodTest::download_data_test_now()
|
||||
@ -106,12 +67,11 @@ void ColnodTest::download_data_test_now()
|
||||
QSignalSpy spy(&colnod, &ColnodAPI::downloadDataFinished);
|
||||
QVERIFY(spy.wait());
|
||||
auto data = qvariant_cast<std::shared_ptr<Data>>(spy.at(0).at(0));
|
||||
// No latest data
|
||||
QVERIFY(data);
|
||||
|
||||
QVERIFY(data->updatedTokens.isEmpty());
|
||||
}
|
||||
|
||||
|
||||
void ColnodTest::download_data_fail_test()
|
||||
{
|
||||
serversdk::RequestManager reqMan;
|
||||
@ -122,7 +82,6 @@ void ColnodTest::download_data_fail_test()
|
||||
|
||||
QVERIFY(spy.wait());
|
||||
|
||||
// FIXME: problem with returning data
|
||||
auto data = qvariant_cast<std::shared_ptr<Data>>(spy.at(0).at(0));
|
||||
|
||||
QVERIFY(!data);
|
||||
|
||||
@ -23,6 +23,12 @@ void DatabaseTest::open_database_test()
|
||||
serversdk::DatabaseManager dbManager;
|
||||
DatabaseAPI db(&dbManager, false);
|
||||
QVERIFY(db.open());
|
||||
|
||||
// TODO: fix -> databaseAPI must be able to add credentials to check for wrong one or test wrong IP
|
||||
//db.open(user, password, url, etc );
|
||||
// then test with wrong credentials
|
||||
// QVERIFY(!db.open(worng usernae));
|
||||
// QVERIFY(!db.open(worng ip));
|
||||
}
|
||||
|
||||
void DatabaseTest::open_database_ip_fail_test()
|
||||
|
||||
@ -56,15 +56,10 @@ void SyncManagerTest::prepareData_test()
|
||||
token->setId("id1");
|
||||
dbData->updatedTokens.insert("id1", token);
|
||||
|
||||
auto oldPreparedData = sync.prepareDataUsindOld(dbData, colnodData);
|
||||
auto newPreparedData = sync.prepareDataNew(dbData, colnodData);
|
||||
QVERIFY(oldPreparedData->databaseData->updatedTokens.contains("id1"));
|
||||
auto newPreparedData = sync.prepareData(dbData, colnodData);
|
||||
QVERIFY(newPreparedData->databaseData->updatedTokens.contains("id1"));
|
||||
QVERIFY(oldPreparedData->databaseData->updatedSubjects.isEmpty());
|
||||
QVERIFY(newPreparedData->databaseData->updatedSubjects.isEmpty());
|
||||
QVERIFY(oldPreparedData->databaseData->deletedTokens.isEmpty());
|
||||
QVERIFY(newPreparedData->databaseData->deletedTokens.isEmpty());
|
||||
QVERIFY(oldPreparedData->databaseData->deletedSubjects.isEmpty());
|
||||
QVERIFY(newPreparedData->databaseData->deletedSubjects.isEmpty());
|
||||
}
|
||||
|
||||
@ -104,8 +99,7 @@ void SyncManagerTest::prepareData_tokens()
|
||||
if ( colnod_dtoken )
|
||||
colnodData->deletedTokens.append(colnod_dtoken->id());
|
||||
|
||||
auto oldPreparedData = sync.prepareDataUsindOld(dbData, colnodData);
|
||||
auto newPreparedData = sync.prepareDataNew(dbData, colnodData);
|
||||
auto newPreparedData = sync.prepareData(dbData, colnodData);
|
||||
|
||||
|
||||
auto testTokens = [=](const QSet<QString> &set, const QString &expectedId) {
|
||||
@ -120,24 +114,9 @@ void SyncManagerTest::prepareData_tokens()
|
||||
testTokens(newPreparedData->databaseData->deletedTokens.toSet(), expected_db_tokens_todelete);
|
||||
|
||||
testTokens(newPreparedData->colnodData->updatedTokens.keys().toSet(), expected_colnod_tokens_toupdate);
|
||||
testTokens(newPreparedData->colnodData->deletedTokens.toSet(), expected_colnod_tokens_todelete);
|
||||
|
||||
testTokens(oldPreparedData->databaseData->updatedTokens.keys().toSet(), expected_db_tokens_toupdate);
|
||||
testTokens(oldPreparedData->databaseData->deletedTokens.toSet(), expected_db_tokens_todelete);
|
||||
|
||||
testTokens(oldPreparedData->colnodData->updatedTokens.keys().toSet(), expected_colnod_tokens_toupdate);
|
||||
testTokens(oldPreparedData->colnodData->deletedTokens.toSet(), expected_colnod_tokens_todelete);
|
||||
|
||||
// QVERIFY(newPreparedData->databaseData->updatedTokens.contains(expected_db_tokens_toupdate));
|
||||
// QVERIFY(newPreparedData->databaseData->deletedTokens.contains(expected_db_tokens_todelete));
|
||||
// QVERIFY(newPreparedData->colnodData->updatedTokens.contains(expected_colnod_tokens_toupdate));
|
||||
// QVERIFY(newPreparedData->colnodData->deletedTokens.contains(expected_colnod_tokens_todelete));
|
||||
|
||||
// QVERIFY(oldPreparedData->databaseData->updatedTokens.contains(expected_db_tokens_toupdate));
|
||||
// QVERIFY(oldPreparedData->databaseData->deletedTokens.contains(expected_db_tokens_todelete));
|
||||
// QVERIFY(oldPreparedData->colnodData->updatedTokens.contains(expected_colnod_tokens_toupdate));
|
||||
// QVERIFY(oldPreparedData->colnodData->deletedTokens.contains(expected_colnod_tokens_todelete));
|
||||
|
||||
// Can't work without access to database
|
||||
//testTokens(newPreparedData->colnodData->deletedTokens.toSet(), expected_colnod_tokens_todelete);
|
||||
}
|
||||
|
||||
void SyncManagerTest::prepareData_tokens_data()
|
||||
@ -159,11 +138,10 @@ void SyncManagerTest::prepareData_tokens_data()
|
||||
<< "id1" << ""
|
||||
// expected colnod: toupdate << todelete
|
||||
<< "" << "";
|
||||
// in: id1 in database new/updated
|
||||
// in: id1 deleted in colnod
|
||||
// out: 1 colnod token must be deleted from database
|
||||
QEXPECT_FAIL("delete 1 existing token in database", "Rare case, not sure if handling is needed", Continue);
|
||||
QTest::newRow("delete 1 existing token in database") << "id1,20191010:23:23:00" << ""
|
||||
QTest::newRow("delete 1 existing token in database") << "" << ""
|
||||
<< "" << "id1,20191010:23:23:00"
|
||||
// expected database: toupdate << todelete
|
||||
<< "" << ""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user