Commit 300a2b06 authored by Martin Straka's avatar Martin Straka

Refactor some tasks and databases on new isds structures

parent aa66f317
......@@ -121,6 +121,7 @@ SOURCES += \
src/global.cpp \
src/io/filesystem.cpp \
src/isds/isds_conversion.cpp \
src/isds/isds_type_conversion.cpp \
src/locker.cpp \
src/log/log.cpp \
src/main.cpp \
......@@ -167,6 +168,15 @@ SOURCES += \
src/worker/task_records_management_stored_messages.cpp \
src/worker/task_send_message.cpp \
src/worker/task_send_sms.cpp \
src/xml/xml_authenticate_message.cpp \
src/xml/xml_base.cpp \
src/xml/xml_download_delivery_info.cpp \
src/xml/xml_download_message.cpp \
src/xml/xml_download_message_author.cpp \
src/xml/xml_download_message_list.cpp \
src/xml/xml_mark_message_as_read.cpp \
src/xml/xml_parse_zfo.cpp \
src/xml/xml_send_message.cpp \
src/zfo.cpp
HEADERS += \
......@@ -207,8 +217,9 @@ HEADERS += \
src/files.h \
src/global.h \
src/io/db_tables.h \
src/io/filesystem.h \
src/io/filesystem.h \
src/isds/isds_conversion.h \
src/isds/isds_type_conversion.h \
src/locker.h \
src/log/log.h \
src/messages.h \
......@@ -257,6 +268,15 @@ HEADERS += \
src/worker/task_records_management_stored_messages.h \
src/worker/task_send_message.h \
src/worker/task_send_sms.h \
src/xml/xml_authenticate_message.h \
src/xml/xml_base.h \
src/xml/xml_download_delivery_info.h \
src/xml/xml_download_message.h \
src/xml/xml_download_message_author.h \
src/xml/xml_download_message_list.h \
src/xml/xml_mark_message_as_read.h \
src/xml/xml_parse_zfo.h \
src/xml/xml_send_message.h \
src/zfo.h
android {
......
......@@ -108,7 +108,7 @@ QString DbWrapper::createAccountInfoStringForQml(
bool DbWrapper::insertMessageListToDb(const QString &userName,
enum MessageDb::MessageType messageType,
const QList<MsgEnvelope> &messages,
const QList<Isds::Envelope> &envelopes,
QList<qint64> &messageChangedStatusList, QString &txt,
QList<qint64> &listOfNewMsgIds)
{
......@@ -128,42 +128,38 @@ bool DbWrapper::insertMessageListToDb(const QString &userName,
}
bool isSentMessage = (messageType == MessageDb::TYPE_SENT);
int newMsgs = 0;
int msgs = messages.count();
msgDb->beginTransaction();
for (int i = 0; i < msgs; ++i) {
foreach (const Isds::Envelope &envelope, envelopes) {
bool hasFiles;
int msgStatus =
msgDb->getMessageStatusFromDb(messages.at(i).dmID(), hasFiles);
msgDb->getMessageStatusFromDb(envelope.dmId(), hasFiles);
// -1 = message is not in the database, mesasge is new
if (-1 == msgStatus) {
newMsgs++;
if (!msgDb->insertOrUpdateMessageEnvelopeInDb(messages.at(i))) {
if (!msgDb->insertOrUpdateMessageEnvelopeInDb(
envelope.dmId(), messageType, envelope)) {
txt = tr("Message %1 envelope insertion failed!").
arg(messages.at(i).dmID());
arg(envelope.dmId());
} else {
// New message envelope has been saved into
// database. Append message id to list
// of complete messages to be downloaded.
listOfNewMsgIds.append(messages.at(i).dmID());
listOfNewMsgIds.append(envelope.dmId());
}
} else {
if (!msgDb->updateMessageEnvelopeInDb(messages.at(i))) {
if (!msgDb->updateMessageEnvelopeInDb(envelope)) {
txt = tr("Message %1 envelope update failed!").
arg(messages.at(i).dmID());
arg(envelope.dmId());
}
if (isSentMessage) {
if (msgStatus != messages.at(i).dmMessageStatus() && hasFiles) {
messageChangedStatusList.append(messages.at(i).dmID());
if (msgStatus != envelope.dmMessageStatus() && hasFiles) {
messageChangedStatusList.append(envelope.dmId());
}
}
}
}
msgDb->commitTransaction();
if (!isSentMessage) {
......@@ -178,8 +174,9 @@ bool DbWrapper::insertMessageListToDb(const QString &userName,
return true;
}
bool DbWrapper::insertCompleteMessageToDb(const QString &userName,
MsgEnvelope &msg, QList<AttachmentData> &fileList, QString &txt)
bool DbWrapper::insertCompleteMessageToDb(const QString &userName, qint64 dmId,
const Isds::Message &message, enum MessageDb::MessageType messageType,
QString &txt)
{
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
......@@ -202,10 +199,10 @@ bool DbWrapper::insertCompleteMessageToDb(const QString &userName,
/* Insert or update files into files database */
fDb->beginTransaction();
for (int i = 0; i < fileList.count(); ++i) {
if (!fDb->insertUpdateFileIntoDb(fileList.at(i))) {
foreach (const Isds::Document &document, message.documents()) {
if (!fDb->insertUpdateFileIntoDb(dmId, document)) {
txt = tr("File %1 insertion failed!").
arg(fileList.at(i).dmFileDescr());
arg(document.fileDescr());
ret = ret * false;
}
}
......@@ -222,17 +219,17 @@ bool DbWrapper::insertCompleteMessageToDb(const QString &userName,
/* Update message envelope data in messages database */
if (ret) {
msg._setDmReadLocally(true);
msg._setDmAttachDownloaded(true);
if (!msgDb->insertOrUpdateMessageEnvelopeInDb(msg)) {
if (!msgDb->insertOrUpdateMessageEnvelopeInDb(dmId, messageType,
message.envelope())) {
txt = tr("Message %1 envelope update failed!").
arg(msg.dmID());
arg(dmId);
ret = ret * false;
}
}
if (ret) {
msgDb->setAttachmentDownloaded(msg.dmID(), true);
msgDb->markMessageLocallyRead(dmId, true);
msgDb->setAttachmentDownloaded(dmId, true);
}
txt = tr("Message has been downloaded");
......@@ -303,7 +300,7 @@ bool DbWrapper::updateAuthorInfo(const QString &userName,
}
bool DbWrapper::insertMesasgeDeliveryInfoToDb(const QString &userName,
const QList<Messages::Event> &eventList, qint64 msgId, QString &txt)
const QList<Isds::Event> &events, qint64 msgId, QString &txt)
{
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
......@@ -323,7 +320,7 @@ bool DbWrapper::insertMesasgeDeliveryInfoToDb(const QString &userName,
}
ret = ret & msgDb->beginTransaction();
foreach (const Messages::Event &event, eventList) {
foreach (const Isds::Event &event, events) {
ret = ret & msgDb->insertEventsIntoDb(msgId, event);
}
ret = ret & msgDb->commitTransaction();
......
......@@ -21,11 +21,11 @@
* the two.
*/
#ifndef _DB_WRAPPER_H_
#define _DB_WRAPPER_H_
#pragma once
#include <QCoreApplication> /* Q_DECLARE_TR_FUNCTIONS */
#include "src/datovka_shared/isds/message_interface.h"
#include "src/qml_interaction/message_envelope.h"
#include "src/sqlite/message_db_container.h"
#include "src/sqlite/file_db_container.h"
......@@ -113,7 +113,7 @@ public:
*
* @param[in] userName Account username string.
* @param[in] messageType Message type.
* @param[in] messages List of message envelopes.
* @param[in] envelopes List of message envelopes.
* @param[out] messageChangedStatusList List of message ids
* where message status has changed.
* @param[out] txt Error description if something fails.
......@@ -124,7 +124,7 @@ public:
static
bool insertMessageListToDb(const QString &userName,
enum MessageDb::MessageType messageType,
const QList<MsgEnvelope> &messages,
const QList<Isds::Envelope> &envelopes,
QList<qint64> &messageChangedStatusList, QString &txt,
QList<qint64> &listOfNewMsgIds);
......@@ -132,14 +132,16 @@ public:
* @brief Insert complete message to db.
*
* @param[in] userName Account username string.
* @param[in] msg Message envelope data.
* @param[in] fileList List of files.
* @param[in] dmId Message Id.
* @param[in] message Message data.
* @param[in] messageType Message type.
* @param[out] txt Error description if something fails.
* @return true if success.
*/
static
bool insertCompleteMessageToDb(const QString &userName,
MsgEnvelope &msg, QList<AttachmentData> &fileList,
qint64 dmId, const Isds::Message &message,
enum MessageDb::MessageType messageType,
QString &txt);
/*!
......@@ -189,14 +191,14 @@ public:
* @brief Insert or update delivery info to db.
*
* @param[in] userName Account username string.
* @param[in] eventList Event list.
* @param[in] events Event list.
* @param[in] msgId Message ID.
* @param[out] txt Error description if something fails.
* @return true if success.
*/
static
bool insertMesasgeDeliveryInfoToDb(const QString &userName,
const QList<Messages::Event> &eventList, qint64 msgId,
const QList<Isds::Event> &events, qint64 msgId,
QString &txt);
/*!
......@@ -218,6 +220,3 @@ private:
*/
DbWrapper(void);
};
#endif /* _DB_WRAPPER_H_ */
......@@ -25,6 +25,9 @@
#include <QFileInfo>
#include "src/auxiliaries/attachment_helper.h"
#include "src/datovka_shared/isds/message_interface.h"
#include "src/datovka_shared/isds/types.h"
#include "src/datovka_shared/isds/type_conversion.h"
#include "src/datovka_shared/utility/strings.h"
#include "src/datovka_shared/worker/pool.h"
#include "src/dialogues/dialogues.h"
......@@ -616,22 +619,30 @@ void IsdsWrapper::sendMessage(const QString &userName, qint64 dmID,
return;
}
MsgEnvelope msg;
Isds::Envelope envelope;
/* Fill message envelope */
msg.setDmAnnotation(dmAnnotation);
msg.setDmLegalTitleLaw(dmLegalTitleLaw);
msg.setDmLegalTitleYear(dmLegalTitleYear);
msg.setDmLegalTitleSect(dmLegalTitleSect);
msg.setDmLegalTitlePar(dmLegalTitlePar);
msg.setDmLegalTitlePoint(dmLegalTitlePoint);
msg.setDmToHands(dmToHands);
msg.setDmRecipientRefNumber(dmRecipientRefNumber);
msg.setDmRecipientIdent(dmRecipientIdent);
msg.setDmSenderRefNumber(dmSenderRefNumber);
msg.setDmSenderIdent(dmSenderIdent);
msg.setDmAllowSubstDelivery(dmAllowSubstDelivery);
msg.setDmPersonalDelivery(dmPersonalDelivery);
msg.setDmType(dmType);
envelope.setDmAnnotation(dmAnnotation);
envelope.setDmLegalTitleLawStr(dmLegalTitleLaw);
envelope.setDmLegalTitleYearStr(dmLegalTitleYear);
envelope.setDmLegalTitleSect(dmLegalTitleSect);
envelope.setDmLegalTitlePar(dmLegalTitlePar);
envelope.setDmLegalTitlePoint(dmLegalTitlePoint);
envelope.setDmToHands(dmToHands);
envelope.setDmRecipientRefNumber(dmRecipientRefNumber);
envelope.setDmRecipientIdent(dmRecipientIdent);
envelope.setDmSenderRefNumber(dmSenderRefNumber);
envelope.setDmSenderIdent(dmSenderIdent);
envelope.setDmAllowSubstDelivery(dmAllowSubstDelivery ?
Isds::Type::BOOL_TRUE : Isds::Type::BOOL_FALSE);
envelope.setDmPersonalDelivery(dmPersonalDelivery ?
Isds::Type::BOOL_TRUE : Isds::Type::BOOL_FALSE);
envelope.setDmType(dmType.isEmpty() ? QChar() : dmType[0]);
envelope.setDmMessageStatus(Isds::Type::MS_POSTED);
envelope.setDmOVM(dmOVM ? Isds::Type::BOOL_TRUE :
Isds::Type::BOOL_FALSE);
envelope.setDmPublishOwnID(dmPublishOwnID ? Isds::Type::BOOL_TRUE :
Isds::Type::BOOL_FALSE);
int totalAttachmentSizeKBs = 0;
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
......@@ -645,24 +656,34 @@ void IsdsWrapper::sendMessage(const QString &userName, qint64 dmID,
return;
}
QList<AttachmentData> attachList;
QList<Isds::Document> documents;
Isds::Type::FileMetaType fileMetaType = Isds::Type::FMT_MAIN;
/* Load file contents from storage or database to file structure */
foreach (const FileListModel::Entry &file, attachModel->allEntries()) {
AttachmentData attach;
attach.setDmFileDescr(file.dmFileDescr());
Isds::Document document;
document.setFileDescr(file.dmFileDescr());
document.setFileMetaType(fileMetaType);
/*
* Since 2011 Mime Type can be empty and MIME type will
* be filled up on the ISDS server. It allows sending files
* with special mime types without recognition by application.
*/
document.setMimeType(QStringLiteral(""));
if (file.fileId() > 0) {
// load file content from database, valid file ID
FileDb::FileData fileData = fDb->getFileFromDb(file.fileId());
attach.setDmEncodedContent(fileData.content);
document.setBase64Content(fileData.content);
totalAttachmentSizeKBs += fileData.content.length() / 1024;
} else if (file.fileId() == Files::DB_ZFO_ID) {
// load zfo content from zfo database
attach.setDmEncodedContent(
document.setBase64Content(
GlobInstcs::zfoDbPtr->getZfoContentFromDb(dmID,
(*GlobInstcs::acntMapPtr)[userName].isTestAccount()));
totalAttachmentSizeKBs += attach.dmEncodedContent().length() / 1024;
QByteArray binData = QByteArray::fromBase64(document.base64Content().toUtf8());
totalAttachmentSizeKBs += binData.length() / 1024;
GlobInstcs::zfoDbPtr->updateZfoLastAccessTime(dmID,
(*GlobInstcs::acntMapPtr)[userName].isTestAccount());
} else if (!file.filePath().isEmpty()) {
......@@ -676,7 +697,7 @@ void IsdsWrapper::sendMessage(const QString &userName, qint64 dmID,
file.filePath());
return;
}
attach.setDmEncodedContent(fin.readAll().toBase64());
document.setBase64Content(fin.readAll().toBase64());
} else {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), tr("No file to sending."),
......@@ -684,12 +705,13 @@ void IsdsWrapper::sendMessage(const QString &userName, qint64 dmID,
return;
}
attach._setDmFileSize(getApproximatelyAttachmentFileSizeFromBase64(attach.dmEncodedContent().length()));
attach._setIcon(getAttachmentFileIconFromFileExtension(attach.dmFileDescr()));
attachList.append(attach);
//document._setDmFileSize(getApproximatelyAttachmentFileSizeFromBase64(document.base64Content().length()));
//document._setIcon(getAttachmentFileIconFromFileExtension(document.fileDescr()));
documents.append(document);
fileMetaType = Isds::Type::FMT_ENCLOSURE;
}
msg.setDmAttachmentSize(totalAttachmentSizeKBs);
envelope.setDmAttachmentSize(totalAttachmentSizeKBs);
/* Test if total attachment size is above the limit */
if (totalAttachmentSizeKBs > SEND_ATTACH_SIZE_LIMIT_KB) {
......@@ -723,17 +745,20 @@ void IsdsWrapper::sendMessage(const QString &userName, qint64 dmID,
emit statusBarTextChanged(tr("%1: sending message").arg(userName),
true, true);
Isds::Message message;
message.setDocuments(documents);
/* Send message to all recipients. */
for (int i = 0; i < dbList.size(); ++i) {
const DataboxModelEntry &db(dbList.at(i));
msg.setDbIDRecipient(db.dbID());
msg.setDmRecipient(db.dbName());
msg.setDmRecipientAddress(db.dbAddress());
envelope.setDbIDRecipient(db.dbID());
envelope.setDmRecipient(db.dbName());
envelope.setDmRecipientAddress(db.dbAddress());
message.setEnvelope(envelope);
TaskSendMessage *task;
task = new (std::nothrow) TaskSendMessage(
m_isdsSession.isdsCtxMap[userName], &m_netLayer,
msg, attachList, dmOVM, dmPublishOwnID,
taskIdentifiers.at(i));
message, taskIdentifiers.at(i));
task->setAutoDelete(true);
GlobInstcs::workPoolPtr->assignHi(task);
}
......
......@@ -21,24 +21,12 @@
* the two.
*/
#include <QDateTime>
#include <QString>
#include "src/sqlite/dbs.h"
/*!
* @brief Date/time format stored in db.
*
* @note Old implementation of datovka is likely to contain a bug.
* Milliseconds are probably stored as microseconds.
*/
static const QString dbDateTimeFormat("yyyy-MM-dd HH:mm:ss.zzz");
static const QString dbShortDateTimeFormat("yyyy-MM-dd HH:mm:ss");
QDateTime dateTimeFromDbFormat(const QString &dateTimeDbStr)
{
QDateTime dateTime = QDateTime::fromString(dateTimeDbStr,
dbDateTimeFormat);
DATETIME_DB_FORMAT);
dateTime.setTimeSpec(Qt::UTC);
return dateTime.toLocalTime();
}
......@@ -47,7 +35,6 @@ QString dateTimeStrFromDbFormat(const QString &dateTimeDbStr,
const QString &tgtFmt)
{
QDateTime dateTime = dateTimeFromDbFormat(dateTimeDbStr);
if (dateTime.isValid()) {
return dateTime.toString(tgtFmt);
} else {
......@@ -59,9 +46,28 @@ QString dateTimeStrToUTCDbFormat(const QString &dateTimeStr)
{
QDateTime dateTime = QDateTime::fromString(dateTimeStr, Qt::ISODate);
dateTime = dateTime.toTimeSpec(Qt::UTC);
if (dateTime.isValid()) {
return dateTime.toString(DATETIME_DB_FORMAT);
} else {
return QString();
}
}
QDateTime isoDateTimeStrToUtcDateTime(const QString &dateTimeStr)
{
QDateTime dateTime = QDateTime::fromString(dateTimeStr, Qt::ISODate);
dateTime = dateTime.toTimeSpec(Qt::UTC);
if (dateTime.isValid()) {
return dateTime;
} else {
return QDateTime();
}
}
QString utcDateTimeToDbFormatStr(const QDateTime &dateTime)
{
if (dateTime.isValid()) {
return dateTime.toString(dbDateTimeFormat);
return dateTime.toString(DATETIME_DB_FORMAT);
} else {
return QString();
}
......
......@@ -23,7 +23,6 @@
#pragma once
#include <QDate>
#include <QDateTime>
#include <QString>
......@@ -47,3 +46,13 @@ QString dateTimeStrFromDbFormat(const QString &dateTimeDbStr,
* @brief Converts date and time to UTC for database store.
*/
QString dateTimeStrToUTCDbFormat(const QString &dateTimeStr);
/*!
* @brief Converts ISDS ISO datetime string to UTC datetime.
*/
QDateTime isoDateTimeStrToUtcDateTime(const QString &dateTimeStr);
/*!
* @brief Converts UTC datetime to database datetime string.
*/
QString utcDateTimeToDbFormatStr(const QDateTime &dateTime);
......@@ -198,7 +198,7 @@ QList<FileDb::FileData> FileDb::getFilesFromDb(qint64 dmId) const
return filelist;
}
bool FileDb::insertUpdateFileIntoDb(const AttachmentData &fileData)
bool FileDb::insertUpdateFileIntoDb(qint64 dmId, const Isds::Document &document)
{
QSqlQuery query(m_db);
int id = -1;
......@@ -210,8 +210,8 @@ bool FileDb::insertUpdateFileIntoDb(const AttachmentData &fileData)
query.lastError().text().toUtf8().constData();
goto fail;
}
query.bindValue(":dmID", fileData.dmId());
query.bindValue(":dmFileDescr", fileData.dmFileDescr());
query.bindValue(":dmID", dmId);
query.bindValue(":dmFileDescr", document.fileDescr());
if (query.exec() && query.isActive()) {
query.first();
if (query.isValid()) {
......@@ -248,17 +248,17 @@ bool FileDb::insertUpdateFileIntoDb(const AttachmentData &fileData)
goto fail;
}
query.bindValue(":dmID", fileData.dmId());
query.bindValue(":dmFileDescr", fileData.dmFileDescr());
query.bindValue(":dmUpFileGuid", fileData.dmUpFileGuid());
query.bindValue(":dmFileGuid", fileData.dmFileGuid());
query.bindValue(":dmMimeType", fileData.dmMimeType());
query.bindValue(":dmFormat", fileData.dmFormat());
query.bindValue(":dmFileMetaType", fileData.dmFileMetaType());
query.bindValue(":dmEncodedContent", fileData.dmEncodedContent());
query.bindValue(":_dmFileSize", fileData._dmFileSize());
query.bindValue(":dmID", dmId);
query.bindValue(":dmFileDescr", document.fileDescr());
query.bindValue(":dmUpFileGuid", document.upFileGuid());
query.bindValue(":dmFileGuid", document.fileGuid());
query.bindValue(":dmMimeType", document.mimeType());
query.bindValue(":dmFormat", document.format());
query.bindValue(":dmFileMetaType", document.fileMetaType());
query.bindValue(":dmEncodedContent", document.base64Content());
query.bindValue(":_dmFileSize", QString());
query.bindValue(":_dmDownloadDate", QDate::currentDate().toString(DATE_DB_FORMAT));
query.bindValue(":_icon", fileData._icon());
query.bindValue(":_icon", QString());
if (-1 != id) {
query.bindValue(":id", id);
}
......
......@@ -27,6 +27,7 @@
#include <QString>
#include "src/datovka_shared/io/sqlite/db.h"
#include "src/datovka_shared/isds/message_interface.h"
#include "src/files.h"
#include "src/messages.h"
#include "src/models/filemodel.h"
......@@ -117,10 +118,11 @@ public:
/*!
* @brief Insert or update file data into files table.
*
* @param[in] fileData Struct holds file data (name and content).
* @param[in] dmId Message Id.
* @param[in] document Struct holds file data.
* @return True on success.
*/
bool insertUpdateFileIntoDb(const AttachmentData &fileData);
bool insertUpdateFileIntoDb(qint64 dmId, const Isds::Document &document);
/*!
* @brief Open database file.
......
This diff is collapsed.
......@@ -27,6 +27,7 @@
#include <QString>
#include "src/datovka_shared/io/sqlite/db.h"
#include "src/datovka_shared/isds/message_interface.h"
#include "src/messages.h"
#include "src/models/databoxmodel.h"
#include "src/qml_interaction/message_envelope.h"
......@@ -178,16 +179,18 @@ public:
* @param[in] event Event structure.
* @return True on success.
*/
bool insertEventsIntoDb(qint64 msgId, const Messages::Event &event);
bool insertEventsIntoDb(qint64 msgId, const Isds::Event &event);
/*!
* @brief Insert or update message envelope into messages table.
*
* @param[in] msgEnvelopeData Contains message envelope data.
* @param[in] msgId Message Id.
* @param[in] messageType Received or sent.
* @param[in] envelope Contains message envelope data.
* @return True on success.
*/
bool insertOrUpdateMessageEnvelopeInDb(
const MsgEnvelope &msgEnvelopeData);
bool insertOrUpdateMessageEnvelopeInDb(qint64 msgId,
enum MessageType messageType, const Isds::Envelope &envelope);
/*!
* @brief Set message in database as localy read.
......@@ -258,10 +261,10 @@ public:
/*!
* @brief Update message envelope in messages table.
*
* @param[in] msgEnvelopeData Contains message envelope data.
* @param[in] envelope Contains message envelope data.
* @return True on success.
*/
bool updateMessageEnvelopeInDb(const MsgEnvelope &msgEnvelopeData);
bool updateMessageEnvelopeInDb(const Isds::Envelope &envelope);
protected:
/*!
......
......@@ -27,9 +27,9 @@
#include "src/log/log.h"
#include "src/net/db_wrapper.h"
#include "src/net/isds_const.h"
#include "src/net/xml_layer.h"
#include "src/worker/emitter.h"
#include "src/worker/task_download_delivery_info.h"
#include "src/xml/xml_download_delivery_info.h"
TaskDownloadDeliveryInfo::TaskDownloadDeliveryInfo(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, qint64 msgId)
......@@ -82,25 +82,22 @@ enum TaskDownloadDeliveryInfo::Result TaskDownloadDeliveryInfo::downloadDelivery
}
QByteArray xmlDataOut;
QList<Messages::Event> eventList;
/* Send SOAP request */
if (!netLayer->sendSoapRequest(ctx, MESSAGE_SERVICE,
XmlLayer::xmlCreateSignedDeliveryInfoSoapRequest(msgId),
xmlDataOut)) {
Xml::xmlCreateSignedDeliveryInfoSoapRequest(msgId), xmlDataOut)) {
return DL_ISDS_ERROR;
}
/* Parse SOAP response */
if (!XmlLayer::parseGetSignedMsgDeliveryInfoResponse(xmlDataOut,
eventList, ctx.last_isds_msg)) {
return DL_XML_ERROR;
}
QList<Isds::Event> events =
Xml::parseGetSignedMsgDeliveryInfoResponse(xmlDataOut,
ctx.last_isds_msg);
/* Store data into db */
if (!eventList.isEmpty()) {
if (!events.isEmpty()) {
if (!DbWrapper::insertMesasgeDeliveryInfoToDb(ctx.username,
eventList, msgId, ctx.last_isds_msg)) {
events, msgId, ctx.last_isds_msg)) {
return DL_DB_INS_ERR;
}
}
......
......@@ -26,13 +26,17 @@
#include "src/global.h"
#include "src/log/log.h"
#include "src/io/filesystem.h"
#include "src/messages.h"
#include "src/net/db_wrapper.h"
#include "src/net/isds_const.h"
#include "src/net/xml_layer.h"
#include "src/qml_interaction/message_envelope.h"
#include "src/worker/emitter.h"
#include "src/worker/task_download_message.h"
#include "src/sqlite/message_db_container.h"
#include "src/xml/xml_download_delivery_info.h"
#include "src/xml/xml_download_message.h"
#include "src/xml/xml_download_message_author.h"
#include "src/xml/xml_mark_message_as_read.h"
TaskDownloadMessage::TaskDownloadMessage(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, qint64 msgId,
......@@ -99,33 +103,50 @@ enum TaskDownloadMessage::Result TaskDownloadMessage::downloadMessage(
return DL_ERR;
}
MsgEnvelope msg;
QByteArray xmlDataOut;
QList<AttachmentData> fileList;
QList<Messages::Event> eventList;
QString userType, authorName;
QByteArray zfoData;
/* Send SOAP request to download complete message */
if (!netLayer->sendSoapRequest(ctx, LOGIN_SERVICE,
XmlLayer::xmlCreateDownloadMessageSoapRequest(msgId, msgDirect),
Xml::xmlCreateDownloadMessageSoapRequest(msgId, msgDirect),
xmlDataOut)) {
return DL_ISDS_ERROR;
}
/* Parse SOAP response */
if (!XmlLayer::parseSignedMessageDownloadResponse(xmlDataOut, msg,
fileList, ctx.last_isds_msg, zfoData)) {
Isds::Message message = Xml::parseSignedMessageDownloadResponse(
xmlDataOut, ctx.last_isds_msg, zfoData);
if (message.isNull()) {
return DL_XML_ERROR;
}
if (fileList.isEmpty()) {
if (message.documents().isEmpty()) {
return DL_ERR;
}
enum MessageDb::MessageType msgType = MessageDb::TYPE_RECEIVED;
switch (msgDirect) {
case Messages::TYPE_RECEIVED:
msgType = MessageDb::TYPE_RECEIVED;
break;
case Messages::TYPE_SENT:
msgType = MessageDb::TYPE_SENT;
break;
default:
/*
* Any other translates to sent, but forces the application to
* crash in debugging mode.
*/
Q_ASSERT(0);
msgType = MessageDb::TYPE_SENT;
break;
}
/* Store data into db */
if (!DbWrapper::insertCompleteMessageToDb(ctx.username, msg,
fileList, ctx.last_isds_msg)) {
if (!DbWrapper::insertCompleteMessageToDb(ctx.username, msgId, message,
msgType, ctx.last_isds_msg)) {
return DL_DB_INS_ERR;
}
......@@ -142,11 +163,10 @@ enum TaskDownloadMessage::Result TaskDownloadMessage::downloadMessage(
/* Send SOAP request to download message author info */
netLayer->sendSoapRequest(ctx, MESSAGE_SERVICE,
XmlLayer::xmlCreateGetMessageAuthorSoapRequest(msgId), xmlDataOut);
Xml::xmlCreateGetMessageAuthorSoapRequest(msgId), xmlDataOut);
/* Parse SOAP response */
XmlLayer::parseGetAuthorInfo(xmlDataOut, userType, authorName,
ctx.last_isds_msg);
Xml::parseGetAuthorInfo(xmlDataOut, userType, authorName, ctx.last_isds_msg);