Commit 4e77a0a8 authored by Martin Straka's avatar Martin Straka

Added insert of new sent message to database

parent 2138e20e
......@@ -145,7 +145,7 @@ bool DbWrapper::insertMessageListToDb(const QString &userName,
// -1 = message is not in the database, mesasge is new
if (-1 == msgStatus) {
newMsgs++;
if (!msgDb->insertMessageEnvelopeIntoDb(messages.at(i))) {
if (!msgDb->insertOrUpdateMessageEnvelopeInDb(messages.at(i))) {
txt = tr("Message %1 envelope insertion failed!").
arg(messages.at(i).dmID);
} else {
......@@ -180,13 +180,8 @@ bool DbWrapper::insertMessageListToDb(const QString &userName,
return true;
}
/* ========================================================================= */
/*
* Func: Insert complete message to db.
*/
bool DbWrapper::insertCompleteMessageToDb(const QString &userName,
Messages::Message &msg, QList<Files::File> &fileList, QString &txt)
/* ========================================================================= */
{
bool ret = true;
......@@ -222,7 +217,7 @@ bool DbWrapper::insertCompleteMessageToDb(const QString &userName,
if (ret) {
msg._dmReadLocally = true;
msg._dmAttachDownloaded = true;
if (!msgDb->updateMessageEnvelopeInDb(msg)) {
if (!msgDb->insertOrUpdateMessageEnvelopeInDb(msg)) {
txt = tr("Message %1 envelope update failed!").
arg(msg.dmID);
ret = ret * false;
......
......@@ -24,6 +24,7 @@
#include <QDebug>
#include <QFileInfo>
#include "src/auxiliaries/attachment_helper.h"
#include "src/dialogues/dialogues.h"
#include "src/models/accountmodel.h"
#include "src/models/databoxmodel.h"
......@@ -464,19 +465,39 @@ void IsdsWrapper::sendMessage(const QString &userName,
return;
}
QList<QPair<QString, QByteArray>> fileList;
QPair<QString, QByteArray> fileData;
/* Load file contents from storage (path) */
Messages::Message msg;
/* Fill message envelope */
msg.dmAnnotation = dmAnnotation;
msg.dmLegalTitleLaw = dmLegalTitleLaw;
msg.dmLegalTitleYear = dmLegalTitleYear;
msg.dmLegalTitleSect = dmLegalTitleSect;
msg.dmLegalTitlePar = dmLegalTitlePar;
msg.dmLegalTitlePoint = dmLegalTitlePoint;
msg.dmToHands = dmToHands;
msg.dmRecipientRefNumber = dmRecipientRefNumber;
msg.dmRecipientIdent = dmRecipientIdent;
msg.dmSenderRefNumber = dmSenderRefNumber;
msg.dmSenderIdent = dmSenderIdent;
msg.dmAllowSubstDelivery = dmAllowSubstDelivery;
msg.dmPersonalDelivery =dmPersonalDelivery;
QList<Files::File> attachList;
/* Load file contents from storage (path) to file structure */
foreach (const QString &file, filePaths) {
Files::File attach;
QFileInfo fi(file);
fileData.first = fi.fileName();
attach.dmFileDescr = fi.fileName();
QFile fin(file);
if (!fin.open(QIODevice::ReadOnly)) {
continue;
}
fileData.second = fin.readAll().toBase64();
fileList.append(fileData);
attach.dmEncodedContent = fin.readAll().toBase64();
attach._dmFileSize =
getApproximatelyAttachmentFileSizeFromBase64(
attach.dmEncodedContent.length());
attach._icon =
getAttachmentFileIconFromFileExtension(attach.dmFileDescr);
attachList.append(attach);
}
emit statusBarTextChanged(tr("%1: sending message").arg(userName),
......@@ -484,15 +505,13 @@ void IsdsWrapper::sendMessage(const QString &userName,
/* Send message to all recipients */
foreach (const DataboxModelEntry &db, databoxModel->allEntries()) {
msg.dbIDRecipient = db.dbID();
msg.dmRecipient = db.dbName();
msg.dmRecipientAddress = db.dbAddress();
TaskSendMessage *task;
task = new (std::nothrow) TaskSendMessage(
m_isdsSession.isdsCtxMap[userName], &m_netLayer,
dmAnnotation, db.dbID(), db.dbName(),
dmLegalTitleLaw, dmLegalTitleYear, dmLegalTitleSect,
dmLegalTitlePar, dmLegalTitlePoint, dmToHands,
dmRecipientRefNumber, dmRecipientIdent,
dmSenderRefNumber, dmSenderIdent, dmOVM, dmPublishOwnID,
dmAllowSubstDelivery, dmPersonalDelivery, fileList);
&m_dbWrapper, msg, attachList, dmOVM, dmPublishOwnID);
task->setAutoDelete(true);
m_workPool.assignHi(task);
}
......
......@@ -223,15 +223,8 @@ QByteArray XmlLayer::xmlCreateMarkMessageAsDownloadedSoapRequest(qint64 msgId)
return xmlCreateSoapEnvelope(xmlContent);
}
QByteArray XmlLayer::xmlCreateSendMessageSoapRequest(const QString &dmAnnotation,
const QString &dbIDRecipient, const QString &dmLegalTitleLaw,
const QString &dmLegalTitleYear, const QString &dmLegalTitleSect,
const QString &dmLegalTitlePar, const QString &dmLegalTitlePoint,
const QString &dmToHands, const QString &dmRecipientRefNumber,
const QString &dmRecipientIdent, const QString &dmSenderRefNumber,
const QString &dmSenderIdent, bool dmOVM, bool dmPublishOwnID,
bool dmAllowSubstDelivery, bool dmPersonalDelivery,
const QList<QPair<QString, QByteArray>> &fileList)
QByteArray XmlLayer::xmlCreateSendMessageSoapRequest(const Messages::Message &msg,
const QList<Files::File> &fileList, bool dmOVM, bool dmPublishOwnID)
{
QString xmlContent("<CreateMessage xmlns=\"");
xmlContent.append(ISDS_NS);
......@@ -239,89 +232,89 @@ QByteArray XmlLayer::xmlCreateSendMessageSoapRequest(const QString &dmAnnotation
xmlContent.append("<dmEnvelope>");
xmlContent.append("<dmSenderOrgUnit/><dmSenderOrgUnitNum/>");
xmlContent.append("<dbIDRecipient>");
xmlContent.append(dbIDRecipient);
xmlContent.append(msg.dbIDRecipient);
xmlContent.append("</dbIDRecipient>");
xmlContent.append("<dmRecipientOrgUnit/><dmRecipientOrgUnitNum/>");
if (dmToHands.isEmpty()) {
if (msg.dmToHands.isEmpty()) {
xmlContent.append("<dmToHands/>");
} else {
xmlContent.append("<dmToHands>");
xmlContent.append(dmToHands);
xmlContent.append(msg.dmToHands);
xmlContent.append("</dmToHands>");
}
xmlContent.append("<dmAnnotation>");
xmlContent.append(dmAnnotation);
xmlContent.append(msg.dmAnnotation);
xmlContent.append("</dmAnnotation>");
if (dmRecipientRefNumber.isEmpty()) {
if (msg.dmRecipientRefNumber.isEmpty()) {
xmlContent.append("<dmRecipientRefNumber/>");
} else {
xmlContent.append("<dmRecipientRefNumber>");
xmlContent.append(dmRecipientRefNumber);
xmlContent.append(msg.dmRecipientRefNumber);
xmlContent.append("</dmRecipientRefNumber>");
}
if (dmSenderRefNumber.isEmpty()) {
if (msg.dmSenderRefNumber.isEmpty()) {
xmlContent.append("<dmSenderRefNumber/>");
} else {
xmlContent.append("<dmSenderRefNumber>");
xmlContent.append(dmSenderRefNumber);
xmlContent.append(msg.dmSenderRefNumber);
xmlContent.append("</dmSenderRefNumber>");
}
if (dmRecipientIdent.isEmpty()) {
if (msg.dmRecipientIdent.isEmpty()) {
xmlContent.append("<dmRecipientIdent/>");
} else {
xmlContent.append("<dmRecipientIdent>");
xmlContent.append(dmRecipientIdent);
xmlContent.append(msg.dmRecipientIdent);
xmlContent.append("</dmRecipientIdent>");
}
if (dmSenderIdent.isEmpty()) {
if (msg.dmSenderIdent.isEmpty()) {
xmlContent.append("<dmSenderIdent/>");
} else {
xmlContent.append("<dmSenderIdent>");
xmlContent.append(dmSenderIdent);
xmlContent.append(msg.dmSenderIdent);
xmlContent.append("</dmSenderIdent>");
}
if (dmLegalTitleLaw.isEmpty()) {
if (msg.dmLegalTitleLaw.isEmpty()) {
xmlContent.append("<dmLegalTitleLaw/>");
} else {
xmlContent.append("<dmLegalTitleLaw>");
xmlContent.append(dmLegalTitleLaw);
xmlContent.append(msg.dmLegalTitleLaw);
xmlContent.append("</dmLegalTitleLaw>");
}
if (dmLegalTitleYear.isEmpty()) {
if (msg.dmLegalTitleYear.isEmpty()) {
xmlContent.append("<dmLegalTitleYear/>");
} else {
xmlContent.append("<dmLegalTitleYear>");
xmlContent.append(dmLegalTitleYear);
xmlContent.append(msg.dmLegalTitleYear);
xmlContent.append("</dmLegalTitleYear>");
}
if (dmLegalTitleSect.isEmpty()) {
if (msg.dmLegalTitleSect.isEmpty()) {
xmlContent.append("<dmLegalTitleSect/>");
} else {
xmlContent.append("<dmLegalTitleSect>");
xmlContent.append(dmLegalTitleSect);
xmlContent.append(msg.dmLegalTitleSect);
xmlContent.append("</dmLegalTitleSect>");
}
if (dmLegalTitlePar.isEmpty()) {
if (msg.dmLegalTitlePar.isEmpty()) {
xmlContent.append("<dmLegalTitlePar/>");
} else {
xmlContent.append("<dmLegalTitlePar>");
xmlContent.append(dmLegalTitlePar);
xmlContent.append(msg.dmLegalTitlePar);
xmlContent.append("</dmLegalTitlePar>");
}
if (dmLegalTitlePoint.isEmpty()) {
if (msg.dmLegalTitlePoint.isEmpty()) {
xmlContent.append("<dmLegalTitlePoint/>");
} else {
xmlContent.append("<dmLegalTitlePoint>");
xmlContent.append(dmLegalTitlePoint);
xmlContent.append(msg.dmLegalTitlePoint);
xmlContent.append("</dmLegalTitlePoint>");
}
xmlContent.append("<dmPersonalDelivery>");
xmlContent.append((dmPersonalDelivery)?"true":"false");
xmlContent.append((msg.dmPersonalDelivery)?"true":"false");
xmlContent.append("</dmPersonalDelivery>");
xmlContent.append("<dmAllowSubstDelivery>");
xmlContent.append((dmAllowSubstDelivery)?"true":"false");
xmlContent.append((msg.dmAllowSubstDelivery)?"true":"false");
xmlContent.append("</dmAllowSubstDelivery>");
xmlContent.append("<dmOVM>");
......@@ -339,10 +332,10 @@ QByteArray XmlLayer::xmlCreateSendMessageSoapRequest(const QString &dmAnnotation
xmlContent.append("<dmFile dmMimeType=\"\" dmFileMetaType=\"");
(i > 0) ? xmlContent.append("enclosure") : xmlContent.append("main");
xmlContent.append("\" dmFileDescr=\"");
xmlContent.append(fileList.at(i).first);
xmlContent.append(fileList.at(i).dmFileDescr);
xmlContent.append("\">");
xmlContent.append("<dmEncodedContent>");
xmlContent.append(fileList.at(i).second);
xmlContent.append(fileList.at(i).dmEncodedContent);
xmlContent.append("</dmEncodedContent>");
xmlContent.append("</dmFile>");
}
......@@ -388,8 +381,6 @@ bool XmlLayer::completeMessageParse(QXmlStreamReader &xml,
bool ret = true;
QString dwnlDate = QDate::currentDate().toString("yyyy-MM-dd");
while ((xml.tokenType() != QXmlStreamReader::StartElement)
&& (xml.name() != "dmDm")) {
return false;
......@@ -513,8 +504,7 @@ bool XmlLayer::completeMessageParse(QXmlStreamReader &xml,
xml.readNext();
while (!(xml.tokenType() == QXmlStreamReader::EndElement
&& xml.name() == "dmFiles")) {
fileList.append(parseFile(xml,
msg.dmID, dwnlDate));
fileList.append(parseFile(xml, msg.dmID));
xml.readNext();
}
}
......@@ -1452,7 +1442,6 @@ Messages::Message XmlLayer::msgEnvelopeParse(QXmlStreamReader &xml,
msg.dmQTimestamp = "";
msg._dmMessageType = messageType;
msg._dmReadLocally = false;
msg._dmDownloadDate = QDateTime::currentDateTime().toString();
msg._dmCustomData = "";
msg._dmAttachDownloaded = false;
......@@ -1510,8 +1499,7 @@ DataboxModelEntry XmlLayer::parseDataboxData(QXmlStreamReader &xml)
dbEffectiveOVM, dbSendOptions);
}
Files::File XmlLayer::parseFile(QXmlStreamReader &xml,
const qint64 msgId, const QString &downloadDate)
Files::File XmlLayer::parseFile(QXmlStreamReader &xml, const qint64 msgId)
{
qDebug("%s()", __func__);
......@@ -1543,7 +1531,6 @@ Files::File XmlLayer::parseFile(QXmlStreamReader &xml,
file.dmEncodedContent = xml.text().toString();
file._dmFileSize =
getApproximatelyAttachmentFileSizeFromBase64(file.dmEncodedContent.length());
file._dmDownloadDate = downloadDate;
file._icon = getAttachmentFileIconFromFileExtension(file.dmFileDescr);
}
......
......@@ -173,35 +173,15 @@ public:
/*!
* @brief Create send message soap request.
*
* @param[in] dmAnnotation Message subject string.
* @param[in] dbIDRecipient Message recipient databox ID string.
* @param[in] dmLegalTitleLaw Mandate Law string.
* @param[in] dmLegalTitleYear Mandate Year string.
* @param[in] dmLegalTitleSect Mandate Section string.
* @param[in] dmLegalTitlePar Mandate Paragraph string.
* @param[in] dmLegalTitlePoint Mandate Letter string.
* @param[in] dmToHands Mesasge to hands string.
* @param[in] dmRecipientRefNumber Your ref. number string.
* @param[in] dmRecipientIdent Your identification string.
* @param[in] dmSenderRefNumber Our ref. number string.
* @param[in] dmSenderIdent Our identification string.
* @param[in] msg Message envelope.
* @param[in] fileList List of files.
* @param[in] dmOVM True if send message as OVM.
* @param[in] dmPublishOwnID True if add sender name to message.
* @param[in] dmAllowSubstDelivery True if allow acceptance by fiction.
* @param[in] dmPersonalDelivery True if personal delivery.
* @param[in] fileList List of files (first = filename, second = file content in base64).
* @return Soap request string as byte array.
*/
static
QByteArray xmlCreateSendMessageSoapRequest(const QString &dmAnnotation,
const QString &dbIDRecipient, const QString &dmLegalTitleLaw,
const QString &dmLegalTitleYear, const QString &dmLegalTitleSect,
const QString &dmLegalTitlePar, const QString &dmLegalTitlePoint,
const QString &dmToHands, const QString &dmRecipientRefNumber,
const QString &dmRecipientIdent, const QString &dmSenderRefNumber,
const QString &dmSenderIdent, bool dmOVM, bool dmPublishOwnID,
bool dmAllowSubstDelivery, bool dmPersonalDelivery,
const QList<QPair<QString, QByteArray>> &fileList);
QByteArray xmlCreateSendMessageSoapRequest(const Messages::Message &msg,
const QList<Files::File> &fileList, bool dmOVM, bool dmPublishOwnID);
/*!
* @brief Create send SMS soap request.
......@@ -445,12 +425,10 @@ public:
*
* @param[in] xml Xml Data for parsing.
* @param[in] msgId Message id.
* @param[in] downloadDate Datetime when complete message was downloaded.
* @return File structure.
*/
static
Files::File parseFile(QXmlStreamReader &xml, const qint64 msgId,
const QString &downloadDate);
Files::File parseFile(QXmlStreamReader &xml, const qint64 msgId);
/*!
* @brief Parse find databox info xml data.
......
......@@ -28,6 +28,9 @@
#include <QDateTime>
#include <QString>
#define DATE_DB_FORMAT "yyyy-MM-dd"
#define DATETIME_DB_FORMAT "yyyy-MM-dd HH:mm:ss.zzz"
#define DATETIME_QML_FORMAT "dd.MM.yyyy HH:mm:ss"
/*!
......
......@@ -286,7 +286,7 @@ bool FileDb::insertUpdateFilesIntoDb(const Files::File &fileData)
query.bindValue(":dmFileMetaType", fileData.dmFileMetaType);
query.bindValue(":dmEncodedContent", fileData.dmEncodedContent);
query.bindValue(":_dmFileSize", fileData._dmFileSize);
query.bindValue(":_dmDownloadDate", fileData._dmDownloadDate);
query.bindValue(":_dmDownloadDate", QDate::currentDate().toString(DATE_DB_FORMAT));
query.bindValue(":_icon", fileData._icon);
if (-1 != id) {
query.bindValue(":id", id);
......
......@@ -196,8 +196,7 @@ QList<qint64> MessageDb::getExpireMsgListFromDb(int days)
QDate now = QDate::currentDate();
now = now.addDays(-1*days);
QString queryStr = "SELECT dmID FROM messages WHERE "
"(dmDeliveryTime < :date) OR (dmDeliveryTime IS NULL)";
QString queryStr = "SELECT dmID FROM messages WHERE dmDeliveryTime < :date";
if (!query.prepare(queryStr)) {
qCritical() << "Cannot prepare SQL query:" <<
query.lastError().text().toUtf8().constData();
......@@ -548,12 +547,36 @@ fail:
return false;
}
bool MessageDb::insertMessageEnvelopeIntoDb(
bool MessageDb::insertOrUpdateMessageEnvelopeInDb(
const Messages::Message &msgEnvelopeData)
{
QSqlQuery query(m_db);
qint64 dmID = -1;
QString queryStr = "INSERT INTO messages ("
QString queryStr = "SELECT dmID FROM messages WHERE dmID = :dmID";
if (!query.prepare(queryStr)) {
qCritical() << "Cannot prepare SQL query:" <<
query.lastError().text().toUtf8().constData();
goto fail;
}
query.bindValue(":dmID", msgEnvelopeData.dmID);
if (query.exec() && query.isActive()) {
query.first();
if (query.isValid()) {
dmID = query.value(0).toLongLong();
}
} else {
qCritical() << "Cannot execute SQL query:" <<
query.lastError().text().toUtf8().constData();
goto fail;
}
// update message envelope
if (-1 != dmID) {
return updateMessageEnvelopeInDb(msgEnvelopeData);
}
queryStr = "INSERT INTO messages ("
"dmID, dbIDSender, dmSender, dmSenderAddress, dmSenderType, "
"dmRecipient, dmRecipientAddress, dmAmbiguousRecipient, "
"dmSenderOrgUnit, dmSenderOrgUnitNum, dbIDRecipient, "
......@@ -579,6 +602,7 @@ bool MessageDb::insertMessageEnvelopeIntoDb(
":dmAttachmentSize, :dmType, :_dmMessageType, :_dmDownloadDate, "
":_dmCustomData, :_dmAttachDownloaded, :_dmReadLocally"
")";
if (!query.prepare(queryStr)) {
qCritical() << "Cannot prepare SQL query:" <<
query.lastError().text().toUtf8().constData();
......@@ -617,7 +641,7 @@ bool MessageDb::insertMessageEnvelopeIntoDb(
query.bindValue(":dmAttachmentSize", msgEnvelopeData.dmAttachmentSize);
query.bindValue(":dmType", msgEnvelopeData.dmType);
query.bindValue(":_dmMessageType", msgEnvelopeData._dmMessageType);
query.bindValue(":_dmDownloadDate", dateTimeStrToUTCDbFormat(msgEnvelopeData._dmDownloadDate));
query.bindValue(":_dmDownloadDate", QDateTime::currentDateTime().toString(DATETIME_DB_FORMAT));
query.bindValue(":_dmCustomData", msgEnvelopeData._dmCustomData);
query.bindValue(":_dmAttachDownloaded", msgEnvelopeData._dmAttachDownloaded);
query.bindValue(":_dmReadLocally", msgEnvelopeData._dmReadLocally);
......@@ -839,11 +863,6 @@ bool MessageDb::updateMessageEnvelopeInDb(
"dmAcceptanceTime = :dmAcceptanceTime, "
"dmMessageStatus = :dmMessageStatus, "
"dmAttachmentSize = :dmAttachmentSize, "
// "_dmMessageType = :_dmMessageType, "
// "_dmDownloadDate = :_dmDownloadDate, "
// "_dmCustomData = :_dmCustomData, "
// "_dmAttachDownloaded = :_dmAttachDownloaded, "
// "_dmReadLocally = :_dmReadLocally, "
"dmType = :dmType "
"WHERE dmID = :dmID";
if (!query.prepare(queryStr)) {
......@@ -883,11 +902,6 @@ bool MessageDb::updateMessageEnvelopeInDb(
query.bindValue(":dmMessageStatus", msgEnvelopeData.dmMessageStatus);
query.bindValue(":dmAttachmentSize", msgEnvelopeData.dmAttachmentSize);
query.bindValue(":dmType", msgEnvelopeData.dmType);
// query.bindValue(":_dmMessageType", msgEnvelopeData._dmMessageType);
// query.bindValue(":_dmDownloadDate", dateTimeStrToUTCDbFormat(msgEnvelopeData._dmDownloadDate));
// query.bindValue(":_dmCustomData", msgEnvelopeData._dmCustomData);
// query.bindValue(":_dmAttachDownloaded", msgEnvelopeData._dmAttachDownloaded);
// query.bindValue(":_dmReadLocally", msgEnvelopeData._dmReadLocally);
if (!query.exec()) {
qCritical() << "Cannot execute SQL query:" <<
......
......@@ -174,12 +174,13 @@ public:
bool insertEventsIntoDb(qint64 msgId, const Messages::Event &event);
/*!
* @brief Insert message envelope into messages table.
* @brief Insert or update message envelope into messages table.
*
* @param[in] msgEnvelopeData Contains message envelope data.
* @return True on success.
*/
bool insertMessageEnvelopeIntoDb(const Messages::Message &msgEnvelopeData);
bool insertOrUpdateMessageEnvelopeInDb(
const Messages::Message &msgEnvelopeData);
/*!
* @brief Set message in database as localy read.
......
......@@ -21,6 +21,7 @@
* the two.
*/
#include "src/auxiliaries/attachment_helper.h"
#include "src/log/log.h"
#include "src/net/isds_const.h"
#include "src/net/xml_layer.h"
......@@ -28,38 +29,19 @@
#include "src/worker/pool.h" /* List with whole messages. */
#include "src/worker/task_send_message.h"
TaskSendMessage::TaskSendMessage(IsdsSession::IsdsContext &ctx, NetLayer *netLayer,
const QString &dmAnnotation, const QString &dbIDRecipient, const QString &dmRecipient,
const QString &dmLegalTitleLaw, const QString &dmLegalTitleYear,
const QString &dmLegalTitleSect, const QString &dmLegalTitlePar,
const QString &dmLegalTitlePoint, const QString &dmToHands,
const QString &dmRecipientRefNumber, const QString &dmRecipientIdent,
const QString &dmSenderRefNumber, const QString &dmSenderIdent,
bool dmOVM, bool dmPublishOwnID, bool dmAllowSubstDelivery,
bool dmPersonalDelivery, const QList<QPair<QString, QByteArray>> &fileList)
TaskSendMessage::TaskSendMessage(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, DbWrapper *dbWrapper, Messages::Message &msg,
QList<Files::File> &fileList, bool dmOVM, bool dmPublishOwnID)
: m_result(DL_ERR),
m_msgID(0),
m_lastError(),
m_ctx(ctx),
m_netLayer(netLayer),
m_dmAnnotation(dmAnnotation),
m_dbIDRecipient(dbIDRecipient),
m_dmRecipient(dmRecipient),
m_dmLegalTitleLaw(dmLegalTitleLaw),
m_dmLegalTitleYear(dmLegalTitleYear),
m_dmLegalTitleSect(dmLegalTitleSect),
m_dmLegalTitlePar(dmLegalTitlePar),
m_dmLegalTitlePoint(dmLegalTitlePoint),
m_dmToHands(dmToHands),
m_dmRecipientRefNumber(dmRecipientRefNumber),
m_dmRecipientIdent(dmRecipientIdent),
m_dmSenderRefNumber(dmSenderRefNumber),
m_dmSenderIdent(dmSenderIdent),
m_dbWrapper(dbWrapper),
m_msg(msg),
m_fileList(fileList),
m_dmOVM(dmOVM),
m_dmPublishOwnID(dmPublishOwnID),
m_dmAllowSubstDelivery(dmAllowSubstDelivery),
m_dmPersonalDelivery(dmPersonalDelivery),
m_fileList(fileList)
m_dmPublishOwnID(dmPublishOwnID)
{
}
......@@ -80,17 +62,13 @@ void TaskSendMessage::run(void)
m_ctx.account_name.toUtf8().constData());
logDebugLv1NL("%s", "-----------------------------------------------");
m_result = sendMessage(m_ctx, m_netLayer, m_dmAnnotation, m_dbIDRecipient,
m_dmLegalTitleLaw, m_dmLegalTitleYear, m_dmLegalTitleSect, m_dmLegalTitlePar,
m_dmLegalTitlePoint, m_dmToHands, m_dmRecipientRefNumber,
m_dmRecipientIdent, m_dmSenderRefNumber, m_dmSenderIdent,
m_dmOVM, m_dmPublishOwnID, m_dmAllowSubstDelivery, m_dmPersonalDelivery,
m_fileList, m_msgID, m_lastError);
m_result = sendMessage(m_ctx, m_netLayer, m_dbWrapper, m_msg, m_fileList,
m_dmOVM, m_dmPublishOwnID, m_msgID, m_lastError);
/* ### Worker task end. ### */
emit globMsgProcEmitter.sendMessageFinishedSignal(m_ctx.username,
m_dbIDRecipient, m_dmRecipient, m_msgID,
m_msg.dbIDRecipient, m_msg.dmRecipient, m_msgID,
TaskSendMessage::DL_SUCCESS == m_result, m_lastError);
logDebugLv0NL("Send message task finished in thread '%p'",
......@@ -98,16 +76,9 @@ void TaskSendMessage::run(void)
}
enum TaskSendMessage::Result TaskSendMessage::sendMessage(
IsdsSession::IsdsContext &ctx, NetLayer *netLayer, const QString &dmAnnotation,
const QString &dbIDRecipient, const QString &dmLegalTitleLaw,
const QString &dmLegalTitleYear, const QString &dmLegalTitleSect,
const QString &dmLegalTitlePar, const QString &dmLegalTitlePoint,
const QString &dmToHands, const QString &dmRecipientRefNumber,
const QString &dmRecipientIdent, const QString &dmSenderRefNumber,
const QString &dmSenderIdent, bool dmOVM, bool dmPublishOwnID,
bool dmAllowSubstDelivery, bool dmPersonalDelivery,
const QList<QPair<QString, QByteArray>> &fileList, qint64 &msgID,
QString &lastError)
IsdsSession::IsdsContext &ctx, NetLayer *netLayer, DbWrapper *dbWrapper,
Messages::Message &msg, QList<Files::File> &fileList,
bool dmOVM, bool dmPublishOwnID, qint64 &msgID, QString &lastError)
{
if (ctx.username.isEmpty()) {
Q_ASSERT(0);
......@@ -119,12 +90,8 @@ enum TaskSendMessage::Result TaskSendMessage::sendMessage(
/* Send SOAP request */
if (!netLayer->createChangePwdRequest(ctx, LOGIN_SERVICE,
XmlLayer::xmlCreateSendMessageSoapRequest(dmAnnotation, dbIDRecipient,
dmLegalTitleLaw, dmLegalTitleYear, dmLegalTitleSect, dmLegalTitlePar,
dmLegalTitlePoint, dmToHands, dmRecipientRefNumber,
dmRecipientIdent, dmSenderRefNumber, dmSenderIdent,
dmOVM, dmPublishOwnID, dmAllowSubstDelivery, dmPersonalDelivery,
fileList), xmlDataOut)) {
XmlLayer::xmlCreateSendMessageSoapRequest(msg, fileList,
dmOVM, dmPublishOwnID), xmlDataOut)) {
lastError = ctx.last_isds_msg;
return DL_ISDS_ERROR;
}
......@@ -137,5 +104,28 @@ enum TaskSendMessage::Result TaskSendMessage::sendMessage(
}
lastError = ctx.last_isds_msg;
/* Fill missing message envelope data */
msg.dmID = msgID;
msg.dmQTimestamp = "";
msg.dmAttachmentSize = 1;
msg.dmMessageStatus = 1;
msg._dmCustomData = "";
msg._dmReadLocally = true;
msg._dmAttachDownloaded = true;
msg._dmMessageType = Messages::TYPE_SENT;
/* Fill missing message id to file list */
QList<Files::File>::iterator it_file;
for (it_file = fileList.begin(); it_file != fileList.end(); ++it_file) {
it_file->dmID = msgID;
}
/* Store data into db */
if (!dbWrapper->insertCompleteMessageToDb(ctx.username, msg,
fileList, ctx.last_isds_msg)) {
return DL_DB_INS_ERR;
}
return DL_SUCCESS;
}
......@@ -24,6 +24,7 @@
#ifndef _TASK_SEND_MESSAGE_H_
#define _TASK_SEND_MESSAGE_H_
#include "src/net/db_wrapper.h"
#include "src/net/isds_session.h"
#include "src/net/net_layer.h"
#include "src/worker/task.h"
......@@ -40,6 +41,7 @@ public:
DL_SUCCESS, /*!< Operation was successful. */
DL_ISDS_ERROR, /*!< Error communicating with ISDS. */
DL_XML_ERROR, /*!< Error xml parse. */
DL_DB_INS_ERR, /*!< Error inserting into database. */
DL_ERR /*!< Other error. */
};
......@@ -48,34 +50,16 @@ public:
*
* @param[in] ctx Account isds context (include username).
* @param[in] netLayer Pointer to network manager.
* @param[in] dmAnnotation Message subject string.
* @param[in] dbIDRecipient Message recipient databox ID string.
* @param[in] dmRecipient Recipient full name.
* @param[in] dmLegalTitleLaw Mandate Law string.
* @param[in] dmLegalTitleYear Mandate Year string.
* @param[in] dmLegalTitleSect Mandate Section string.
* @param[in] dmLegalTitlePar Mandate Paragraph string.
* @param[in] dmLegalTitlePoint Mandate Letter string.
* @param[in] dmToHands Mesasge to hands string.
* @param[in] dmRecipientRefNumber Your ref. number string.
* @param[in] dmRecipientIdent Your identification string.
* @param[in] dmSenderRefNumber Our ref. number string.
* @param[in] dmSenderIdent Our identification string.
* @param[in] dbWrapper Pointer to database wrapper.
* @param[in] msg Message envelope.
* @param[in] fileList List of files.
* @param[in] dmOVM True if send message as OVM.
* @param[in] dmPublishOwnID True if add sender name to message.
* @param[in] dmAllowSubstDelivery True if allow acceptance by fiction.
* @param[in] dmPersonalDelivery True if personal delivery.
* @param[in] fileList List of files (first = filename, second = file content in base64).
*/
explicit TaskSendMessage(IsdsSession::IsdsContext &ctx, NetLayer *netLayer,
const QString &dmAnnotation, const QString &dbIDRecipient, const QString &dmRecipient,
const QString &dmLegalTitleLaw, const QString &dmLegalTitleYear,
const QString &dmLegalTitleSect, const QString &dmLegalTitlePar,
const QString &dmLegalTitlePoint, const QString &dmToHands,
const QString &dmRecipientRefNumber, const QString &dmRecipientIdent,
const QString &dmSenderRefNumber, const QString &dmSenderIdent,
bool dmOVM, bool dmPublishOwnID, bool dmAllowSubstDelivery,
bool dmPersonalDelivery, const QList<QPair<QString, QByteArray>> &fileList);
explicit TaskSendMessage(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, DbWrapper *dbWrapper,
Messages::Message &msg, QList<Files::File> &fileList,
bool dmOVM, bool dmPublishOwnID);
/*!
* @brief Performs actual send message.
......@@ -88,37 +72,19 @@ public:
*
* @param[in] ctx Account isds context (include username).
* @param[in] netLayer Pointer to network manager.
* @param[in] dmAnnotation Message subject string.
* @param[in] dbIDRecipient Message recipient databox ID string.
* @param[in] dmLegalTitleLaw Mandate Law string.
* @param[in] dmLegalTitleYear Mandate Year string.
* @param[in] dmLegalTitleSect Mandate Section string.
* @param[in] dmLegalTitlePar Mandate Paragraph string.
* @param[in] dmLegalTitlePoint Mandate Letter string.
* @param[in] dmToHands Mesasge to hands string.
* @param[in] dmRecipientRefNumber Your ref. number string.
* @param[in] dmRecipientIdent Your identification string.
* @param[in] dmSenderRefNumber Our ref. number string.
* @param[in] dmSenderIdent Our identification string.
* @param[in] dbWrapper Pointer to database wrapper.
* @param[in] msg Message envelope.
* @param[in] fileList List of files.
* @param[in] dmOVM True if send message as OVM.
* @param[in] dmPublishOwnID True if add sender name to message.
* @param[in] dmAllowSubstDelivery True if allow acceptance by fiction.
* @param[in] dmPersonalDelivery True if personal delivery.
* @param[in] fileList List of files (first = filename, second = file content in base64).
* @param[out] msgID Sent message ID.
* @param[out] lastError Last ISDS error message.
* @return Error state.
*/
static
enum Result sendMessage(IsdsSession::IsdsContext &ctx, NetLayer *netLayer,
const QString &dmAnnotation, const QString &dbIDRecipient,
const QString &dmLegalTitleLaw, const QString &dmLegalTitleYear,
const QString &dmLegalTitleSect, const QString &dmLegalTitlePar,
const QString &dmLegalTitlePoint, const QString &dmToHands,
const QString &dmRecipientRefNumber, const QString &dmRecipientIdent,
const QString &dmSenderRefNumber, const QString &dmSenderIdent,
bool dmOVM, bool dmPublishOwnID, bool dmAllowSubstDelivery,
bool dmPersonalDelivery, const QList<QPair<QString, QByteArray>> &fileList,
enum Result sendMessage(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, DbWrapper *dbWrapper, Messages::Message &msg,
QList<Files::File> &fileList, bool dmOVM, bool dmPublishOwnID,
qint64 &msgID, QString &lastError);
enum Result m_result; /*!< Return state. */
......@@ -134,27 +100,11 @@ private:
IsdsSession::IsdsContext m_ctx; /*!< Account isds context. */
NetLayer *m_netLayer; /*!< Pointer to network manager to send request. */
QString m_dmAnnotation; /*!< Message subject string. */
QString m_dbIDRecipient; /*!< Message recipient databox ID string. */
QString m_dmRecipient; /*!< Recipient full name. */
QString m_dmLegalTitleLaw; /*!< Mandate Law string. */
QString m_dmLegalTitleYear; /*!< Mandate Year string. */
QString m_dmLegalTitleSect; /*!< Mandate Section string. */
QString m_dmLegalTitlePar; /*!< Mandate Paragraph string. */
QString m_dmLegalTitlePoint; /*!< Mandate Letter string. */
QString m_dmToHands; /*!< Mesasge to hands string. */
QString m_dmRecipientRefNumber; /*!< Your ref. number string. */
QString m_dmRecipientIdent; /*!< Your identification string. */
QString m_dmSenderRefNumber; /*!< Our ref. number string. */