Commit 13adbe8b authored by Martin Straka's avatar Martin Straka

Updated messages and files on new isds structures

parent 8cc295be
......@@ -147,7 +147,7 @@ QByteArray Files::getFileRawContentFromDb(const QString &userName, int fileId)
return QByteArray();
}
return base64ToRaw(fDb->getFileFromDb(fileId).content.toUtf8());
return base64ToRaw(fDb->getFileFromDb(fileId).base64Content().toUtf8());
}
void Files::openAttachmentFromDb(const QString &userName, int fileId)
......@@ -170,9 +170,9 @@ void Files::openAttachmentFromDb(const QString &userName, int fileId)
return;
}
FileDb::FileData file = fDb->getFileFromDb(fileId);
Isds::Document document = fDb->getFileFromDb(fileId);
openAttachment(file.filename, file.content.toUtf8());
openAttachment(document.fileDescr(), document.base64Content().toUtf8());
}
void Files::openAttachment(const QString &fileName,
......@@ -276,7 +276,7 @@ void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId,
return;
}
QList<FileDb::FileData> filelist;
QList<Isds::Document> documents;
/* Get attachment files from database if needed */
if (attachFlags & MSG_ATTACHS) {
......@@ -289,8 +289,8 @@ void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId,
return;
}
filelist = fDb->getFilesFromDb(msgId);
if (filelist.isEmpty()) {
documents = fDb->getFilesFromDb(msgId);
if (documents.isEmpty()) {
qCritical("Missing attachments for message '%s'.",
QString::number(msgId).toUtf8().constData());
return;
......@@ -299,10 +299,10 @@ void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId,
/* Get zfo file from database if needed */
if (attachFlags & MSG_ZFO) {
FileDb::FileData msgData;
msgData.content = GlobInstcs::zfoDbPtr->getZfoContentFromDb(
msgId, (*GlobInstcs::acntMapPtr)[userName].isTestAccount());
if (msgData.content.isEmpty()) {
Isds::Document document;
document.setBase64Content(GlobInstcs::zfoDbPtr->getZfoContentFromDb(
msgId, (*GlobInstcs::acntMapPtr)[userName].isTestAccount()));
if (document.base64Content().isEmpty()) {
qCritical("Missing zfo data for message '%s'.",
QString::number(msgId).toUtf8().constData());
Dialogues::errorMessage(Dialogues::CRITICAL,
......@@ -312,8 +312,8 @@ void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId,
Q_ASSERT(0);
return;
}
msgData.filename = QString("DZ_%1.zfo").arg(msgId);
filelist.append(msgData);
document.setFileDescr(QString("DZ_%1.zfo").arg(msgId));
documents.append(document);
}
/* Create email content, email attachment path, email eml content */
......@@ -324,17 +324,17 @@ void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId,
QStringList filePathList;
/* Write attachment files to email directory */
foreach (const FileDb::FileData &file, filelist) {
QString fileName = file.filename;
foreach (const Isds::Document &document, documents) {
QString fileName = document.fileDescr();
if (fileName.isEmpty()) {
qCritical("%s", "File name is empty.");
return;
}
fileName = writeFile(targetPath, fileName,
base64ToRaw(file.content.toUtf8()));
base64ToRaw(document.base64Content().toUtf8()));
filePathList.append(fileName);
addAttachmentToEmailMessage(emailMessage, file.filename,
file.content.toUtf8(), boundary);
addAttachmentToEmailMessage(emailMessage, document.fileDescr(),
document.base64Content().toUtf8(), boundary);
}
finishEmailMessage(emailMessage, boundary);
......@@ -616,7 +616,7 @@ void Files::saveMsgFilesToDisk(const QString &userName,
return;
}
QList<FileDb::FileData> filelist;
QList<Isds::Document> documents;
/* Get attachment files from database if needed */
if (attachFlags & MSG_ATTACHS) {
......@@ -629,8 +629,8 @@ void Files::saveMsgFilesToDisk(const QString &userName,
return;
}
filelist = fDb->getFilesFromDb(msgId);
if (filelist.isEmpty()) {
documents = fDb->getFilesFromDb(msgId);
if (documents.isEmpty()) {
qCritical("Missing attachments for message '%s'.",
QString::number(msgId).toUtf8().constData());
return;
......@@ -639,10 +639,10 @@ void Files::saveMsgFilesToDisk(const QString &userName,
/* Get zfo file from database if needed */
if (attachFlags & MSG_ZFO) {
FileDb::FileData msgData;
msgData.content = GlobInstcs::zfoDbPtr->getZfoContentFromDb(
msgId, (*GlobInstcs::acntMapPtr)[userName].isTestAccount());
if (msgData.content.isEmpty()) {
Isds::Document document;
document.setBase64Content(GlobInstcs::zfoDbPtr->getZfoContentFromDb(
msgId, (*GlobInstcs::acntMapPtr)[userName].isTestAccount()));
if (document.base64Content().isEmpty()) {
qCritical("Missing zfo data for message '%s'.",
QString::number(msgId).toUtf8().constData());
Dialogues::errorMessage(Dialogues::CRITICAL,
......@@ -652,16 +652,16 @@ void Files::saveMsgFilesToDisk(const QString &userName,
Q_ASSERT(0);
return;
}
msgData.filename = QString("DZ_%1.zfo").arg(msgId);
filelist.append(msgData);
document.setFileDescr(QString("DZ_%1.zfo").arg(msgId));
documents.append(document);
}
QString filePath(appMsgAttachDirPath(msgIdStr));
QString destPath;
foreach (const FileDb::FileData &file, filelist) {
destPath = writeFile(filePath, file.filename,
base64ToRaw(file.content.toUtf8()));
foreach (const Isds::Document &document, documents) {
destPath = writeFile(filePath, document.fileDescr(),
base64ToRaw(document.base64Content().toUtf8()));
}
attachmentSavingNotification(destPath);
......
......@@ -47,3 +47,57 @@ const QString &Isds::boolType2Str(enum Type::NilBool b)
return strFalse;
}
}
static const QString strNull;
static const QString strMain("main"), strEncl("enclosure"), strSign("signature"), strMeta("meta");
enum Isds::Type::FileMetaType Isds::m_str2FileMetaType(const QString &s)
{
if (s.isNull()) {
return Type::FMT_UNKNOWN;
} else if (s == strMain) {
return Type::FMT_MAIN;
} else if (s == strEncl) {
return Type::FMT_ENCLOSURE;
} else if (s == strSign) {
return Type::FMT_SIGNATURE;
} else if (s == strMeta) {
return Type::FMT_META;
} else {
Q_ASSERT(0);
return Type::FMT_UNKNOWN;
}
}
const QString &Isds::m_fileMetaType2Str(enum Type::FileMetaType fmt)
{
switch (fmt) {
case Type::FMT_UNKNOWN: return strNull; break;
case Type::FMT_MAIN: return strMain; break;
case Type::FMT_ENCLOSURE: return strEncl; break;
case Type::FMT_SIGNATURE: return strSign; break;
case Type::FMT_META: return strMeta; break;
default:
Q_ASSERT(0);
return strNull;
break;
}
}
enum Isds::Type::FileMetaType Isds::m_variant2FileMetaType(const QVariant &v)
{
if (v.isNull()) {
return Type::FMT_UNKNOWN;
}
return m_str2FileMetaType(v.toString());
}
QVariant Isds::m_fileMetaType2Variant(enum Type::FileMetaType fmt)
{
if (fmt == Type::FMT_UNKNOWN) {
return QVariant();
}
return QVariant(m_fileMetaType2Str(fmt));
}
......@@ -24,6 +24,7 @@
#pragma once
#include <QString>
#include <QVariant>
#include "src/datovka_shared/isds/types.h"
......@@ -31,4 +32,9 @@ namespace Isds {
enum Type::NilBool str2BoolType(const QString &s);
const QString &boolType2Str(enum Type::NilBool b);
enum Type::FileMetaType m_str2FileMetaType(const QString &s);
const QString &m_fileMetaType2Str(enum Type::FileMetaType fmt);
enum Type::FileMetaType m_variant2FileMetaType(const QVariant &v);
QVariant m_fileMetaType2Variant(enum Type::FileMetaType fmt);
}
......@@ -674,15 +674,16 @@ void IsdsWrapper::sendMessage(const QString &userName, qint64 dmID,
if (file.fileId() > 0) {
// load file content from database, valid file ID
FileDb::FileData fileData = fDb->getFileFromDb(file.fileId());
document.setBase64Content(fileData.content);
totalAttachmentSizeKBs += fileData.content.length() / 1024;
document = fDb->getFileFromDb(file.fileId());
document.setFileMetaType(fileMetaType);
totalAttachmentSizeKBs += document.base64Content().length() / 1024;
} else if (file.fileId() == Files::DB_ZFO_ID) {
// load zfo content from zfo database
document.setBase64Content(
GlobInstcs::zfoDbPtr->getZfoContentFromDb(dmID,
(*GlobInstcs::acntMapPtr)[userName].isTestAccount()));
QByteArray binData = QByteArray::fromBase64(document.base64Content().toUtf8());
QByteArray binData = QByteArray::fromBase64(
document.base64Content().toUtf8());
totalAttachmentSizeKBs += binData.length() / 1024;
GlobInstcs::zfoDbPtr->updateZfoLastAccessTime(dmID,
(*GlobInstcs::acntMapPtr)[userName].isTestAccount());
......
......@@ -31,7 +31,9 @@
#include "src/auxiliaries/attachment_helper.h"
#include "src/common.h"
#include "src/datovka_shared/isds/type_conversion.h"
#include "src/io/filesystem.h"
#include "src/isds/isds_type_conversion.h"
#include "src/sqlite/file_db.h"
#include "src/sqlite/db_tables.h"
#include "src/sqlite/dbs.h"
......@@ -141,62 +143,75 @@ void FileDb::setFileModelFromDb(FileListModel &model, const qint64 dmId) const
}
}
FileDb::FileData FileDb::getFileFromDb(int fileId) const
Isds::Document FileDb::getFileFromDb(int fileId) const
{
QSqlQuery query(m_db);
FileDb::FileData filedata;
Isds::Document document;
QString queryStr = "SELECT dmFileDescr, dmEncodedContent "
QString queryStr = "SELECT dmFileDescr, dmUpFileGuid, dmFileGuid, "
"dmMimeType, dmFormat, dmFileMetaType, dmEncodedContent "
"FROM files WHERE id = :id";
if (!query.prepare(queryStr)) {
qCritical() << "Cannot prepare SQL query:" <<
query.lastError().text().toUtf8().constData();
return FileDb::FileData();
goto fail;
}
query.bindValue(":id", fileId);
if (query.exec() && query.isActive() &&
query.first() && query.isValid()) {
filedata.filename = query.value(0).toString();
filedata.content = query.value(1).toString();
return filedata;
document.setFileDescr(query.value(0).toString());
document.setUpFileGuid(query.value(1).toString());
document.setFileGuid(query.value(2).toString());
document.setMimeType(query.value(3).toString());
document.setFormat(query.value(4).toString());
document.setFileMetaType(
Isds::m_variant2FileMetaType(query.value(5)));
document.setBase64Content(query.value(6).toString());
return document;
} else {
qCritical() << "Cannot execute SQL query:" <<
query.lastError().text().toUtf8().constData();
}
return FileDb::FileData();
fail:
return Isds::Document();
}
QList<FileDb::FileData> FileDb::getFilesFromDb(qint64 dmId) const
QList<Isds::Document> FileDb::getFilesFromDb(qint64 dmId) const
{
QSqlQuery query(m_db);
FileDb::FileData filedata;
QList<FileDb::FileData> filelist;
QList<Isds::Document> documents;
QString queryStr = "SELECT dmFileDescr, dmEncodedContent "
QString queryStr = "SELECT dmFileDescr, dmUpFileGuid, dmFileGuid, "
"dmMimeType, dmFormat, dmFileMetaType, dmEncodedContent "
"FROM files WHERE dmID = :dmID";
if (!query.prepare(queryStr)) {
qCritical() << "Cannot prepare SQL query:" <<
query.lastError().text().toUtf8().constData();
return QList<FileDb::FileData>();
goto fail;
}
query.bindValue(":dmID", dmId);
if (query.exec() && query.isActive()) {
query.first();
while (query.isValid()) {
filedata.filename = query.value(0).toString();
filedata.content = query.value(1).toString();
filelist.append(filedata);
Isds::Document document;
document.setFileDescr(query.value(0).toString());
document.setUpFileGuid(query.value(1).toString());
document.setFileGuid(query.value(2).toString());
document.setMimeType(query.value(3).toString());
document.setFormat(query.value(4).toString());
document.setFileMetaType(
Isds::m_variant2FileMetaType(query.value(5)));
document.setBase64Content(query.value(6).toString());
documents.append(document);
query.next();
}
return documents;
} else {
qCritical() << "Cannot execute SQL query:" <<
query.lastError().text().toUtf8().constData();
return QList<FileDb::FileData>();
}
return filelist;
fail:
return QList<Isds::Document>();
}
bool FileDb::insertUpdateFileIntoDb(qint64 dmId, const Isds::Document &document)
......@@ -255,7 +270,8 @@ bool FileDb::insertUpdateFileIntoDb(qint64 dmId, const Isds::Document &document)
query.bindValue(":dmFileGuid", document.fileGuid());
query.bindValue(":dmMimeType", document.mimeType());
query.bindValue(":dmFormat", document.format());
query.bindValue(":dmFileMetaType", document.fileMetaType());
query.bindValue(":dmFileMetaType",
Isds::m_fileMetaType2Variant(document.fileMetaType()));
query.bindValue(":dmEncodedContent", document.base64Content());
query.bindValue(":_dmFileSize",
getApproximatelyAttachmentFileSizeFromBase64(
......
......@@ -39,14 +39,6 @@ class FileDb : public SQLiteDb {
public:
/*!
* @brief Structure holds file name and its content.
*/
struct FileData {
public: QString filename;
QString content;
};
explicit FileDb(const QString &connectionName);
/*!
......@@ -94,17 +86,17 @@ public:
* @brief Get file content from db.
*
* @param[in] fileId File Id.
* @return File name and content.
* @return File data.
*/
FileDb::FileData getFileFromDb(int fileId) const;
Isds::Document getFileFromDb(int fileId) const;
/*!
* @brief Get list of files from db.
*
* @param[in] dmId Message Id.
* @return List of files (name and content).
* @return List of files.
*/
QList<FileDb::FileData> getFilesFromDb(qint64 dmId) const;
QList<Isds::Document> getFilesFromDb(qint64 dmId) const;
/*!
* @brief Set attachment model from db - for QML listview.
......
......@@ -53,7 +53,7 @@ Isds::Document parseMessageDocument(QXmlStreamReader &xml)
document.setFormat(attr.value().toString());
} else if (attr.name() == "dmFileMetaType") {
document.setFileMetaType(
Isds::str2FileMetaType(
Isds::m_str2FileMetaType(
attr.value().toString()));
}
}
......
......@@ -144,7 +144,7 @@ QByteArray Xml::xmlCreateSendMessageSoapRequest(const Isds::Message &message)
xmlContent.append("<dmFiles>");
foreach (const Isds::Document &document, message.documents()) {
xmlContent.append("<dmFile dmMimeType=\"\" dmFileMetaType=\"");
xmlContent.append(Isds::fileMetaType2Str(document.fileMetaType()));
xmlContent.append(Isds::m_fileMetaType2Str(document.fileMetaType()));
xmlContent.append("\" dmFileDescr=\"");
xmlContent.append(document.fileDescr());
xmlContent.append("\">");
......
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