mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 12:00:37 +02:00
edit proceessData inn colnod to not using signals inside class
This commit is contained in:
parent
d7b9c15dd6
commit
82d93fd115
@ -1 +1 @@
|
||||
Subproject commit 3640c0db5d1e24b314b00cc2b0dd61915080381b
|
||||
Subproject commit 28a61d7c120ad466cc4f661b688b61266b6ab73f
|
||||
@ -31,7 +31,7 @@ bool ColnodAPI::downloadData(const qint64 &time)
|
||||
}
|
||||
connect(login.get(), &serversdk::Request::finished, this, [=](){
|
||||
// Get login token
|
||||
if (login->status() != 200) {
|
||||
if (!checkRequest(login)) {
|
||||
emit downloadDataFinished(nullptr);
|
||||
return false;
|
||||
}
|
||||
@ -69,16 +69,16 @@ bool ColnodAPI::downloadData(const qint64 &time)
|
||||
!data->updatedSubjects.isEmpty() || !data->deletedSubjects.isEmpty()) {
|
||||
qInfo(colnod) << dash;
|
||||
}
|
||||
for (auto token : data->updatedTokens) {
|
||||
for (const auto &token : data->updatedTokens) {
|
||||
qInfo(colnod) << Message::massageTemplate("Download updated", "token", "colnod", token->name());
|
||||
}
|
||||
for (auto id : data->deletedTokens) {
|
||||
for (const auto &id : data->deletedTokens) {
|
||||
qInfo(colnod) << Message::massageTemplate("Download deleted", "token", "colnod", id);
|
||||
}
|
||||
for (auto subject : data->updatedSubjects) {
|
||||
for (const auto &subject : data->updatedSubjects) {
|
||||
qInfo(colnod) << Message::massageTemplate("Download updated", "subject", "colnod", subject->name());
|
||||
}
|
||||
for (auto id : data->deletedSubjects) {
|
||||
for (const auto &id : data->deletedSubjects) {
|
||||
qInfo(colnod) << Message::massageTemplate("Download deleted", "token", "colnod", id);
|
||||
}
|
||||
if (!data->updatedTokens.isEmpty() || !data->deletedTokens.isEmpty() ||
|
||||
@ -91,7 +91,13 @@ bool ColnodAPI::downloadData(const qint64 &time)
|
||||
|
||||
auto tokensRequest = getTokensUpdated(timestamp);
|
||||
connect(tokensRequest.get(), &serversdk::Request::finished, [=](){
|
||||
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;
|
||||
}
|
||||
@ -100,7 +106,13 @@ bool ColnodAPI::downloadData(const qint64 &time)
|
||||
|
||||
auto deletedTokensRequest = getTokensDeleted(timestamp);
|
||||
connect(deletedTokensRequest.get(), &serversdk::Request::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;
|
||||
}
|
||||
@ -109,7 +121,13 @@ bool ColnodAPI::downloadData(const qint64 &time)
|
||||
|
||||
auto subjectsRequest = getSubjectsUpdated(timestamp);
|
||||
connect(subjectsRequest.get(), &serversdk::Request::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;
|
||||
}
|
||||
@ -118,7 +136,13 @@ bool ColnodAPI::downloadData(const qint64 &time)
|
||||
|
||||
auto deletedSubjectsRequest = getSubjectsDeleted(timestamp);
|
||||
connect(deletedSubjectsRequest.get(), &serversdk::Request::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;
|
||||
}
|
||||
@ -132,26 +156,66 @@ bool ColnodAPI::downloadData(const qint64 &time)
|
||||
|
||||
void ColnodAPI::processData(const std::shared_ptr<Data> &data)
|
||||
{
|
||||
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 ]";
|
||||
|
||||
connect(this, &ColnodAPI::partOfDataProcessFinished, this, &ColnodAPI::isDataProcessFinished);
|
||||
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;
|
||||
}
|
||||
if ( !data->updatedTokens.isEmpty() && !mDryMode ) {
|
||||
setTokens(data->updatedTokens);
|
||||
} else {
|
||||
emit partOfDataProcessFinished();
|
||||
auto setTokensRequest = setTokens(data->updatedTokens);
|
||||
connect(setTokensRequest.get(), &serversdk::Request::finished, [=](){
|
||||
if (!checkErrors(setTokensRequest)) {
|
||||
data->updatedTokens.clear();
|
||||
mValid = false;
|
||||
return;
|
||||
}
|
||||
checkData();
|
||||
});
|
||||
} else {
|
||||
checkData();
|
||||
}
|
||||
|
||||
if ( !data->deletedTokens.isEmpty() && !mDryMode ) {
|
||||
deleteTokens(data->deletedTokens);
|
||||
} else {
|
||||
emit partOfDataProcessFinished();
|
||||
auto deletedTokensRequest = deleteTokens(data->deletedTokens);
|
||||
connect(deletedTokensRequest.get(), &serversdk::Request::finished, [=](){
|
||||
if (!checkErrors(deletedTokensRequest)) {
|
||||
data->deletedTokens.clear();
|
||||
mValid = false;
|
||||
return;
|
||||
}
|
||||
if (!data->updatedTokens.isEmpty() || !data->deletedTokens.isEmpty()) {
|
||||
qInfo(colnod) << dash;
|
||||
checkData();
|
||||
});
|
||||
} else {
|
||||
checkData();
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,22 +277,6 @@ std::shared_ptr<serversdk::Request> ColnodAPI::setTokens(const QHash<QString, st
|
||||
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";
|
||||
}
|
||||
if (checkResponse(request->responseData())) {
|
||||
for (const auto &token : tokens) {
|
||||
qInfo(colnod).noquote() << Message::massageTemplate("Updated", "token", "colnod", token->name());
|
||||
}
|
||||
emit partOfDataProcessFinished();
|
||||
}
|
||||
else {
|
||||
qWarning(colnod) << "Tokens wasn't updated";
|
||||
mValid = false;
|
||||
emit partOfDataProcessFinished(false);
|
||||
}
|
||||
});
|
||||
return request;
|
||||
}
|
||||
|
||||
@ -237,22 +285,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";
|
||||
}
|
||||
if (checkResponse(request->responseData())) {
|
||||
for (const auto &id : ids) {
|
||||
qInfo(colnod).noquote() << Message::massageTemplate("Deleted", "token", "colnod", id);
|
||||
}
|
||||
emit partOfDataProcessFinished();
|
||||
}
|
||||
else {
|
||||
qWarning(colnod) << "Tokens wasn't deleted";
|
||||
mValid = false;
|
||||
emit partOfDataProcessFinished(false);
|
||||
}
|
||||
});
|
||||
return request;
|
||||
}
|
||||
|
||||
@ -267,6 +299,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;
|
||||
@ -292,16 +337,6 @@ void ColnodAPI::setUserName(const QString &userName)
|
||||
mUserName = userName;
|
||||
}
|
||||
|
||||
void ColnodAPI::isDataProcessFinished(bool success)
|
||||
{
|
||||
if (!success) {
|
||||
mSuccess = false;
|
||||
}
|
||||
if (++amountProccessesFinished == 2) {
|
||||
emit dataProcessFinished(mSuccess);
|
||||
}
|
||||
}
|
||||
|
||||
bool ColnodAPI::saveUpdatedTokens(const std::shared_ptr<Data>& data, const QByteArray &responseData)
|
||||
{
|
||||
Q_ASSERT(data);
|
||||
|
||||
@ -71,16 +71,16 @@ bool DatabaseAPI::processData(const std::shared_ptr<Data> &data)
|
||||
!data->updatedSubjects.isEmpty() || !data->deletedSubjects.isEmpty()) {
|
||||
qInfo(database) << dash;
|
||||
}
|
||||
for (auto token : data->updatedTokens) {
|
||||
for (const auto &token : data->updatedTokens) {
|
||||
qInfo(database) << Message::massageTemplate("Updated", "token", "database", token->name());
|
||||
}
|
||||
for (auto id : data->deletedTokens) {
|
||||
for (const auto &id : data->deletedTokens) {
|
||||
qInfo(database) << Message::massageTemplate("Deleted", "token", "database", id);
|
||||
}
|
||||
for (auto subject : data->updatedSubjects) {
|
||||
for (const auto &subject : data->updatedSubjects) {
|
||||
qInfo(database) << Message::massageTemplate("Updated", "subject", "database", subject->name());
|
||||
}
|
||||
for (auto id : data->deletedSubjects) {
|
||||
for (const auto &id : data->deletedSubjects) {
|
||||
qInfo(database) << Message::massageTemplate("Deleted", "token", "database", id);
|
||||
}
|
||||
if (!data->updatedTokens.isEmpty() || !data->deletedTokens.isEmpty() ||
|
||||
@ -109,10 +109,10 @@ std::shared_ptr<Data> DatabaseAPI::composeData(const QSqlQuery &updatedQuery, QS
|
||||
if (!data->updatedTokens.isEmpty() || !data->deletedTokens.isEmpty()) {
|
||||
qInfo(database) << dash;
|
||||
}
|
||||
for (auto token : data->updatedTokens) {
|
||||
for (const auto &token : data->updatedTokens) {
|
||||
qInfo(database) << Message::massageTemplate("Download updated", "token", "database", token->name());
|
||||
}
|
||||
for (auto id : data->deletedTokens) {
|
||||
for (const auto &id : data->deletedTokens) {
|
||||
qInfo(database) << Message::massageTemplate("Download deleted", "token", "database", id);
|
||||
}
|
||||
if (!data->updatedTokens.isEmpty() || !data->deletedTokens.isEmpty()) {
|
||||
|
||||
@ -61,7 +61,7 @@ bool SyncManager::startSynchronization()
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
@ -122,7 +122,7 @@ bool SyncManager::startSynchronization()
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<PreparedData> SyncManager::prepareDataNew(const std::shared_ptr<Data> &databaseData, const std::shared_ptr<Data> &colnodData)
|
||||
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>();
|
||||
|
||||
@ -15,17 +15,14 @@ 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> prepareData(const std::shared_ptr<Data> &databaseData, const std::shared_ptr<Data> &colnodData);
|
||||
|
||||
private:
|
||||
void initNewToken(const std::shared_ptr<Token>& token);
|
||||
|
||||
@ -56,7 +56,7 @@ void SyncManagerTest::prepareData_test()
|
||||
token->setId("id1");
|
||||
dbData->updatedTokens.insert("id1", token);
|
||||
|
||||
auto newPreparedData = sync.prepareDataNew(dbData, colnodData);
|
||||
auto newPreparedData = sync.prepareData(dbData, colnodData);
|
||||
QVERIFY(newPreparedData->databaseData->updatedTokens.contains("id1"));
|
||||
QVERIFY(newPreparedData->databaseData->updatedSubjects.isEmpty());
|
||||
QVERIFY(newPreparedData->databaseData->deletedTokens.isEmpty());
|
||||
@ -99,7 +99,7 @@ void SyncManagerTest::prepareData_tokens()
|
||||
if ( colnod_dtoken )
|
||||
colnodData->deletedTokens.append(colnod_dtoken->id());
|
||||
|
||||
auto newPreparedData = sync.prepareDataNew(dbData, colnodData);
|
||||
auto newPreparedData = sync.prepareData(dbData, colnodData);
|
||||
|
||||
|
||||
auto testTokens = [=](const QSet<QString> &set, const QString &expectedId) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user