Commit 6dabedd7 authored by Martin Straka's avatar Martin Straka

Added records management stored task

parent c4b8fabd
......@@ -145,6 +145,7 @@ SOURCES += \
src/sqlite/message_db.cpp \
src/sqlite/zfo_db.cpp \
src/worker/emitter.cpp \
src/worker/pool.cpp \
src/worker/task.cpp \
src/worker/task_change_password.cpp \
src/worker/task_download_account_info.cpp \
......@@ -155,6 +156,7 @@ SOURCES += \
src/worker/task_find_databox_fulltext.cpp \
src/worker/task_import_zfo.cpp \
src/worker/task_keep_alive.cpp \
src/worker/task_records_management_stored_messages.cpp \
src/worker/task_send_message.cpp \
src/worker/task_send_sms.cpp \
src/zfo.cpp
......@@ -221,6 +223,7 @@ HEADERS += \
src/sqlite/message_db.h \
src/sqlite/zfo_db.h \
src/worker/emitter.h \
src/worker/pool.h \
src/worker/task.h \
src/worker/task_change_password.h \
src/worker/task_download_account_info.h \
......@@ -231,9 +234,11 @@ HEADERS += \
src/worker/task_find_databox_fulltext.h \
src/worker/task_import_zfo.h \
src/worker/task_keep_alive.h \
src/worker/task_records_management_stored_messages.h \
src/worker/task_send_message.h \
src/worker/task_send_sms.h \
src/zfo.h
android {
SOURCES += \
src/os_android.cpp
......
......@@ -38,6 +38,7 @@
#include "src/settings.h"
#include "src/sqlite/zfo_db.h"
#include "src/worker/emitter.h"
#include "src/worker/pool.h"
#include "src/worker/task_change_password.h"
#include "src/worker/task_download_account_info.h"
#include "src/worker/task_download_delivery_info.h"
......@@ -51,7 +52,6 @@
IsdsWrapper::IsdsWrapper(QObject *parent)
: QObject(parent),
m_workPool(1),
m_transactIds()
/*
* TODO -- To be able to run multiple therads in the pool a locking mechanism
......@@ -60,7 +60,7 @@ IsdsWrapper::IsdsWrapper(QObject *parent)
* waiting.
*/
{
m_workPool.start();
globWorkPool.start();
/* Worker-related processing signals. */
connect(&globMsgProcEmitter,
......@@ -94,8 +94,8 @@ IsdsWrapper::IsdsWrapper(QObject *parent)
IsdsWrapper::~IsdsWrapper(void)
{
m_workPool.wait();
m_workPool.stop();
globWorkPool.wait();
globWorkPool.stop();
}
QString IsdsWrapper::importZfoMessages(const QString &userName,
......@@ -155,7 +155,7 @@ QString IsdsWrapper::importZfoMessages(const QString &userName,
&m_netLayer, &m_dbWrapper, userNameList, file,
authenticate, zfoNumber, zfoTotal);
task->setAutoDelete(true);
m_workPool.assignLo(task);
globWorkPool.assignLo(task);
}
return tr("ZFO import is running... Wait until import will finished!");
......@@ -196,7 +196,7 @@ bool IsdsWrapper::changePassword(const QString &userName, const QString &oldPwd,
m_isdsSession.isdsCtxMap[userName], &m_netLayer, otpType,
oldPwd, newPwd);
task->setAutoDelete(false);
m_workPool.runSingle(task);
globWorkPool.runSingle(task);
success = TaskChangePassword::DL_SUCCESS == task->m_result;
isdsText = task->m_isdsText;
delete task; task = Q_NULLPTR;
......@@ -303,7 +303,7 @@ void IsdsWrapper::getAccountInfo(const QString &userName)
task = new (std::nothrow) TaskDownloadAccountInfo(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper);
task->setAutoDelete(true);
m_workPool.assignHi(task);
globWorkPool.assignHi(task);
}
int IsdsWrapper::findDataboxFulltext(const QString &userName,
......@@ -347,7 +347,7 @@ int IsdsWrapper::findDataboxFulltext(const QString &userName,
return 0;
}
task->setAutoDelete(false);
m_workPool.runSingle(task);
globWorkPool.runSingle(task);
bool success = TaskFindDataboxFulltext::DL_SUCCESS == task->m_result;
QList<DataboxModelEntry> dbList = task->m_dbList;
int totalCount = task->m_totalCount;
......@@ -399,7 +399,7 @@ QString IsdsWrapper::findDatabox(const QString &userName, const QString &dbID,
return tr("Error creating task");
}
task->setAutoDelete(false);
m_workPool.runSingle(task);
globWorkPool.runSingle(task);
QString dbInfo = task->m_dbInfo;
delete task; task = Q_NULLPTR;
......@@ -430,7 +430,7 @@ void IsdsWrapper::getDeliveryInfo(const QString &userName, qint64 msgId)
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper,
msgId);
task->setAutoDelete(true);
m_workPool.assignHi(task);
globWorkPool.assignHi(task);
bool success = TaskDownloadDeliveryInfo::DL_SUCCESS == task->m_result;
delete task; task = Q_NULLPTR;
......@@ -689,7 +689,7 @@ void IsdsWrapper::sendMessage(const QString &userName, qint64 dmID,
&m_dbWrapper, msg, attachList, dmOVM, dmPublishOwnID,
taskIdentifiers.at(i));
task->setAutoDelete(true);
m_workPool.assignHi(task);
globWorkPool.assignHi(task);
}
}
......@@ -725,7 +725,7 @@ bool IsdsWrapper::sendSMS(const QString &userName, const QString &oldPwd)
TaskSendSMS *taskSMS = new (std::nothrow) TaskSendSMS(
m_isdsSession.isdsCtxMap[userName], &m_netLayer);
taskSMS->setAutoDelete(false);
m_workPool.runSingle(taskSMS);
globWorkPool.runSingle(taskSMS);
success = TaskSendSMS::DL_SUCCESS == taskSMS->m_result;
delete taskSMS; taskSMS = Q_NULLPTR;
......@@ -1040,7 +1040,7 @@ void IsdsWrapper::downloadMessage(MessageListModel *messageModel,
msgId, messageType, messageModel, (globSet.zfoDbSizeMBs > 0),
AccountListModel::globAccounts[userName].isTestAccount());
task->setAutoDelete(true);
m_workPool.assignLo(task);
globWorkPool.assignLo(task);
}
bool IsdsWrapper::hasCtxAllLoginData(const QString &isdsAction,
......@@ -1249,10 +1249,10 @@ void IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
task = new (std::nothrow) TaskDownloadMessageList(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper,
msgDirect, (globSet.downloadOnlyNewMsgs) ? DOWNLOAD_NEW_MESSAGES : DOWNLOAD_ALL_MESSAGES,
1, MESSAGE_LIST_LIMIT, &m_workPool, messageModel, accountModel,
1, MESSAGE_LIST_LIMIT, &globWorkPool, messageModel, accountModel,
globSet.downloadCompleteMsgs, globSet.dbsLocation,
(globSet.zfoDbSizeMBs > 0),
AccountListModel::globAccounts[userName].isTestAccount());
task->setAutoDelete(true);
m_workPool.assignHi(task);
globWorkPool.assignHi(task);
}
......@@ -26,7 +26,6 @@
#include <QObject>
#include "src/datovka_shared/worker/pool.h"
#include "src/messages.h"
#include "src/net/db_wrapper.h"
#include "src/net/net_layer.h"
......@@ -627,11 +626,6 @@ private:
*/
IsdsSession m_isdsSession;
/*!
* @brief Worker pool instance.
*/
WorkerPool m_workPool;
/* Used to collect sending results. */
QSet<QString> m_transactIds; /*!< Temporary transaction identifiers. */
QList<TaskSendMessage::ResultData> m_sentMsgResultList; /*!< Send status list. */
......
......@@ -25,11 +25,22 @@
#include "src/datovka_shared/io/records_management_db.h"
#include "src/datovka_shared/records_management/json/service_info.h"
#include "src/models/accountmodel.h"
#include "src/records_management.h"
#include "src/settings.h"
#include "src/worker/pool.h"
#include "src/worker/task_records_management_stored_messages.h"
RecordsManagement::RecordsManagement(QObject *parent)
: QObject(parent)
{
globWorkPool.start();
}
RecordsManagement::~RecordsManagement(void)
{
globWorkPool.wait();
globWorkPool.stop();
}
void RecordsManagement::callServiceInfo(const QString &urlStr, const QString &tokenStr)
......@@ -57,6 +68,51 @@ void RecordsManagement::callServiceInfo(const QString &urlStr, const QString &to
}
}
void RecordsManagement::getStoredMsgInfoFromRecordsManagement(
const QString &urlStr, const QString &tokenStr)
{
TaskRecordsManagementStoredMessages *task =
new (::std::nothrow) TaskRecordsManagementStoredMessages(
urlStr, tokenStr,
TaskRecordsManagementStoredMessages::RM_UPDATE_STORED,
Q_NULLPTR);
if (Q_NULLPTR == task) {
qCritical("%s", "Cannot create stored_files update task.");
return;
}
task->setAutoDelete(true);
/* Run in background. */
globWorkPool.assignHi(task);
foreach (const QString &userName, AccountListModel::globAccounts.keys()) {
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qWarning("%s", "Cannot open message database.");
return;
}
TaskRecordsManagementStoredMessages *task =
new (::std::nothrow) TaskRecordsManagementStoredMessages(
urlStr, tokenStr,
TaskRecordsManagementStoredMessages::RM_DOWNLOAD_ALL,
msgDb);
if (Q_NULLPTR == task) {
qWarning("Cannot create stored_files task for '%s'.",
userName.toUtf8().constData());
continue;
}
task->setAutoDelete(true);
/* Run in background. */
globWorkPool.assignHi(task);
}
/* TODO - update message model */
}
void RecordsManagement::loadStoredServiceInfo(void)
{
if (Q_NULLPTR == globRecordsManagementDbPtr) {
......
......@@ -25,6 +25,8 @@
#include <QObject>
#include "src/sqlite/message_db_container.h"
#include "src/datovka_shared/records_management/io/records_management_connection.h"
#include "src/datovka_shared/settings/records_management.h"
......@@ -32,11 +34,33 @@ class RecordsManagement : public QObject {
Q_OBJECT
public:
/*!
* @brief Describes account information.
*/
class AcntData {
public:
AcntData(const QString &aName, const QString &uName,
const MessageDb *msgDb)
: accountName(aName), userName(uName), msgDb(msgDb)
{
}
QString accountName; /*!< Account name. */
QString userName; /*!< User name (login). */
const MessageDb *msgDb; /*!< Database set related to account. */
};
/*!
* @brief Constructor.
*/
RecordsManagement(QObject *parent = Q_NULLPTR);
/*!
* @brief Destructor.
*/
~RecordsManagement(void);
/*!
* @brief Calls service info and displays results.
*
......@@ -46,6 +70,17 @@ public:
Q_INVOKABLE
void callServiceInfo(const QString &urlStr, const QString &tokenStr);
/*!
* @brief Obtain information about stored messages from records
* management.
*
* @param[in] urlStr records management url string.
* @param[in] tokenStr records management token string.
*/
Q_INVOKABLE
void getStoredMsgInfoFromRecordsManagement(const QString &urlStr,
const QString &tokenStr);
/*!
* @brief Loads service information from storage.
*/
......
/*
* Copyright (C) 2014-2017 CZ.NIC
* Copyright (C) 2014-2018 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -131,6 +131,30 @@ int MessageDb::getDbSizeInBytes(void)
return fi.size();
}
QSet<qint64> MessageDb::getAllMessageIDsFromDB(void)
{
QSqlQuery query(m_db);
QSet<qint64> msgIDList;
QString queryStr = "SELECT dmID FROM messages";
if (!query.prepare(queryStr)) {
qCritical() << "Cannot prepare SQL query:" <<
query.lastError().text().toUtf8().constData();
return QSet<qint64>();
}
if (query.exec() && query.isActive()) {
query.first();
while (query.isValid()) {
msgIDList.insert(query.value(0).toLongLong());
query.next();
}
} else {
return QSet<qint64>();
}
return msgIDList;
}
QList<qint64> MessageDb::getExpireMsgListFromDb(int days)
{
QSqlQuery query(m_db);
......
/*
* Copyright (C) 2014-2017 CZ.NIC
* Copyright (C) 2014-2018 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -21,8 +21,7 @@
* the two.
*/
#ifndef _MESSAGE_DB_H_
#define _MESSAGE_DB_H_
#pragma once
#include <QList>
#include <QString>
......@@ -102,6 +101,13 @@ public:
*/
int getDbSizeInBytes(void);
/*!
* @brief Get list of message IDs.
*
* @return Set of message IDs.
*/
QSet<qint64> getAllMessageIDsFromDB(void);
/*!
* @brief Get list of messages from db which are older than number of days.
*
......@@ -273,5 +279,3 @@ private:
static
const QVector<QString> fileItemIds;
};
#endif /* _MESSAGE_DB_H_ */
/*
* Copyright (C) 2014-2018 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#include "src/worker/pool.h"
WorkerPool globWorkPool(1); /*!< Only one worker thread currently. */
/*
* TODO -- To be able to run multiple therads in the pool a locking mechanism
* over libisds context structures must be implemented.
* Also, per-context queueing ought to be implemented to avoid unnecessary
* waiting.
*/
/*
* Copyright (C) 2014-2018 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#pragma once
#include "src/datovka_shared/worker/pool.h"
/*!
* @brief Global instance of the structure.
*/
extern WorkerPool globWorkPool;
This diff is collapsed.
/*
* Copyright (C) 2014-2018 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#pragma once
#include <QList>
#include <QString>
#include "src/sqlite/message_db_container.h"
#include "src/worker/task.h"
/*!
* @brief Task describing downloading information about stored messages.
*/
class TaskRecordsManagementStoredMessages : public Task {
public:
/*!
* @brief Return state describing what happened.
*/
enum Result {
DS_DSM_SUCCESS, /*!< Operation was successful. */
DS_DSM_COM_ERROR, /*!< Error communicating with ISDS. */
DS_DSM_DB_INS_ERR, /*!< Error inserting into database. */
DS_DSM_ERR /*!< Other error. */
};
/*!
* @brief Operation to be performed.
*/
enum Operation {
RM_UPDATE_STORED, /*!< Update only messages in records management database. */
RM_DOWNLOAD_ALL /*!< Download all messages that are held in database set. */
};
/*!
* @brief Constructor.
*
* @param[in] urlStr Records management URL.
* @param[in] tokenStr Records management access token.
* @param[in] operation Actual action to be performed.
* @param[in] msgDb Database set to be used to obtain message identifiers.
* @patam[in] exludedDmIds Message identifiers that should not be queried.
*/
explicit TaskRecordsManagementStoredMessages(
const QString &urlStr, const QString &tokenStr,
enum Operation operation, MessageDb *msgDb,
const QList<qint64> &exludedDmIds = QList<qint64>());
/*!
* @brief Performs actual message download.
*/
virtual
void run(void) Q_DECL_OVERRIDE;
/*!
* @brief Returns task identifier.
*
* @return Task identifier string.
*/
const QString &id(void) const;
enum Result m_result; /*!< Return state. */
private:
/*!
* @brief Download stored files information and save to records
* management database.
*
* @param[in] urlStr Records management URL.
* @param[in] tokenStr Records management access token.
* @param[in] operation Actual action to be performed.
* @param[in] msgDb Database set to be used to obtain message identifiers.
* @patam[in] exludedDmIds Message identifiers that should not be queried.
* @return Return state.
*/
static
enum Result downloadStoredMessages(const QString &urlStr,
const QString &tokenStr, enum Operation operation,
MessageDb *msgDb, const QList<qint64> &exludedDmIds);
const QString m_id; /*!< Task identifier. */
const QString m_url; /*!< String containing records management URL. */
const QString m_token; /*!< Records management access token. */
const enum Operation m_operation; /*!< Operation to be performed. */
MessageDb *m_msgDb; /*!< Pointer to database container. */
const QList<qint64> m_exludedDmIds; /*!<
* List of messages that should
* not be queried.
*/
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment