Commit 66308f62 authored by Martin Straka's avatar Martin Straka

Added update hierarchy and upload file

parent 6dabedd7
......@@ -70,7 +70,7 @@ Item {
source: "qrc:/ui/checkbox-marked-circle.svg"
accessibleName: qsTr("Accept changes")
onClicked: {
recordsManagement.updateServiceInfo(urlTextField.text, lastUrlFromSettings, "", serviceName.text, tokenName.text)
recordsManagement.updateServiceInfo(urlTextField.text, lastUrlFromSettings, serviceName.text, tokenName.text)
settings.setRmUrl(urlTextField.text)
settings.setRmToken(tokenTextField.text)
pageView.pop(StackView.Immediate)
......@@ -162,6 +162,15 @@ Item {
recordsManagement.callServiceInfo(urlTextField.text, tokenTextField.text)
}
}
AccessibleButton {
id: updateButton
height: inputItemHeight
font.pointSize: defaultTextFont.font.pointSize
text: qsTr("Update")
onClicked: {
recordsManagement.getStoredMsgInfoFromRecordsManagement(urlTextField.text, tokenTextField.text)
}
}
AccessibleButton {
id: clearButton
height: inputItemHeight
......
......@@ -22,17 +22,76 @@
*/
#include <QMessageBox>
#include <QPainter>
#include <QSvgRenderer>
#include "src/datovka_shared/io/records_management_db.h"
#include "src/datovka_shared/records_management/json/service_info.h"
#include "src/datovka_shared/records_management/json/upload_file.h"
#include "src/datovka_shared/records_management/json/upload_hierarchy.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"
/*!
* @brief Process upload file service response.
*
* @note Stores location into database.
*
* @param[in] ifRes Response structure.
* @param[in] dmId Message identifier.
* @patam[in] parent Parent window for potential error dialogues.
* @return True if response could be processed and location has been saved.
*/
static
bool processUploadFileResponse(const UploadFileResp &ufRes, qint64 dmId,
QWidget *parent = Q_NULLPTR)
{
if (ufRes.id().isEmpty()) {
QString errorMessage(
QObject::tr("Message '%1' could not be uploaded.")
.arg(dmId));
errorMessage += QLatin1String("\n");
errorMessage += QObject::tr("Received error") +
QLatin1String(": ") + ufRes.error().trVerbose();
errorMessage += QLatin1String("\n");
errorMessage += ufRes.error().description();
QMessageBox::critical(parent, QObject::tr("File Upload Error"),
errorMessage);
return false;
}
QMessageBox::information(parent, QObject::tr("Successful File Upload"),
QObject::tr("Message '%1' was successfully uploaded into the records management service.").arg(dmId) +
QStringLiteral("\n") +
QObject::tr("It can be now found in the records management service in these locations:") +
QStringLiteral("\n") +
ufRes.locations().join(QStringLiteral("\n")));
if (!ufRes.locations().isEmpty()) {
qCritical("%s", "Message has been stored into records management service.");
if (Q_NULLPTR != globRecordsManagementDbPtr) {
return globRecordsManagementDbPtr->updateStoredMsg(dmId,
ufRes.locations());
} else {
Q_ASSERT(0);
return true;
}
} else {
qCritical("%s",
"Received empty location list when uploading message.");
}
return false;
}
RecordsManagement::RecordsManagement(QObject *parent)
: QObject(parent)
: QObject(parent),
m_rmc(RecordsManagementConnection::ignoreSslErrorsDflt, Q_NULLPTR),
m_logoSvg()
{
globWorkPool.start();
}
......@@ -46,21 +105,67 @@ RecordsManagement::~RecordsManagement(void)
void RecordsManagement::callServiceInfo(const QString &urlStr, const QString &tokenStr)
{
QByteArray response;
RecordsManagementConnection m_rmc(RecordsManagementConnection::ignoreSslErrorsDflt, Q_NULLPTR);
m_rmc.setConnection(urlStr.trimmed(), tokenStr.trimmed());
if (m_rmc.communicate(RecordsManagementConnection::SRVC_SERVICE_INFO, QByteArray(), response)) {
if (m_rmc.communicate(RecordsManagementConnection::SRVC_SERVICE_INFO,
QByteArray(), response)) {
if (!response.isEmpty()) {
bool ok = false;
ServiceInfoResp siRes(
ServiceInfoResp::fromJson(response, &ok));
if (!ok || !siRes.isValid()) {
QMessageBox::critical(Q_NULLPTR, tr("Communication Error"), tr("Received invalid response."));
QMessageBox::critical(Q_NULLPTR,
tr("Communication Error"),
tr("Received invalid response."));
return;
}
emit serviceInfo(siRes.logoSvg(), siRes.name(), siRes.tokenName());
m_logoSvg = siRes.logoSvg();
QPixmap logoPx = fromSvgToPixmap(m_logoSvg);
/* TODO - logoPx to QML */
emit serviceInfo(m_logoSvg, siRes.name(), siRes.tokenName());
} else {
QMessageBox::critical(Q_NULLPTR, tr("Communication Error"), tr("Received empty response."));
QMessageBox::critical(Q_NULLPTR,
tr("Communication Error"),
tr("Received empty response."));
return;
}
} else {
return;
}
}
void RecordsManagement::callUploadHierarchy(const QString &urlStr,
const QString &tokenStr)
{
QByteArray response;
/* Clear model. */
//m_uploadModel.setHierarchy(UploadHierarchyResp());
m_rmc.setConnection(urlStr.trimmed(), tokenStr.trimmed());
if (m_rmc.communicate(RecordsManagementConnection::SRVC_UPLOAD_HIERARCHY,
QByteArray(), response)) {
if (!response.isEmpty()) {
bool ok = false;
UploadHierarchyResp uhRes(
UploadHierarchyResp::fromJson(response, &ok));
if (!ok || !uhRes.isValid()) {
QMessageBox::critical(Q_NULLPTR,
tr("Communication Error"),
tr("Received invalid response."));
return;
}
// m_uploadModel.setHierarchy(uhRes);
} else {
QMessageBox::critical(Q_NULLPTR, tr("Communication Error"),
tr("Received empty response."));
return;
}
} else {
......@@ -125,25 +230,25 @@ void RecordsManagement::loadStoredServiceInfo(void)
return;
}
emit serviceInfo(entry.logoSvg, entry.name, entry.tokenName);
m_logoSvg = entry.logoSvg;
emit serviceInfo(m_logoSvg, entry.name, entry.tokenName);
}
bool RecordsManagement::updateServiceInfo(const QString &urlStr,
const QString &urlStrSettings, const QString &srLogo,
const QString &srName, const QString &srToken)
const QString &urlStrSettings, const QString &srName, const QString &srToken)
{
if (Q_NULLPTR == globRecordsManagementDbPtr) {
return false;
}
if (!urlStr.trimmed().isEmpty()) {
Q_ASSERT(!urlStr.trimmed().isEmpty());
Q_ASSERT(!urlStr.trimmed().isEmpty());
RecordsManagementDb::ServiceInfoEntry entry;
entry.url = urlStr.trimmed();
entry.name = srName;
entry.tokenName = srToken;
entry.logoSvg = srLogo.toUtf8();
entry.logoSvg = m_logoSvg;
globRecordsManagementDbPtr->updateServiceInfo(entry);
if (urlStrSettings != urlStr) {
......@@ -155,3 +260,66 @@ bool RecordsManagement::updateServiceInfo(const QString &urlStr,
return true;
}
bool RecordsManagement::uploadMessage(const QString &urlStr,
const QString &tokenStr, qint64 dmId, const QString &msgFileName,
const QByteArray &msgData)
{
if (msgFileName.isEmpty() || msgData.isEmpty()) {
Q_ASSERT(0);
return false;
}
QStringList uploadIds;
UploadFileReq ufReq(uploadIds, msgFileName, msgData);
if (!ufReq.isValid()) {
Q_ASSERT(0);
return false;
}
QByteArray response;
m_rmc.setConnection(urlStr.trimmed(), tokenStr.trimmed());
if (m_rmc.communicate(RecordsManagementConnection::SRVC_UPLOAD_FILE,
ufReq.toJson(), response)) {
if (!response.isEmpty()) {
bool ok = false;
UploadFileResp ufRes(
UploadFileResp::fromJson(response, &ok));
if (!ok || !ufRes.isValid()) {
QMessageBox::critical(Q_NULLPTR,
tr("Communication Error"),
tr("Received invalid response."));
qWarning("Received invalid response '%s'.",
QString(response).toUtf8().constData());
return false;
}
return processUploadFileResponse(ufRes, dmId);
} else {
QMessageBox::critical(Q_NULLPTR, tr("Communication Error"),
tr("Received empty response."));
return false;
}
} else {
return false;
}
}
QPixmap RecordsManagement::fromSvgToPixmap(const QString &SvgContent)
{
QSize ImageSize(100, 100);
QSvgRenderer SvgRenderer(SvgContent);
QPixmap Image(ImageSize);
QPainter Painter;
Image.fill(Qt::transparent);
Painter.begin(&Image);
SvgRenderer.render(&Painter);
Painter.end();
return Image;
}
......@@ -34,23 +34,6 @@ 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.
*/
......@@ -64,18 +47,27 @@ public:
/*!
* @brief Calls service info and displays results.
*
* @param[in] urlStr records management url string.
* @param[in] tokenStr records management token string.
* @param[in] urlStr Records management url string.
* @param[in] tokenStr Records management token string.
*/
Q_INVOKABLE
void callServiceInfo(const QString &urlStr, const QString &tokenStr);
/*!
* @brief Download upload hierarchy and set model.
*
* @param[in] urlStr Records management url string.
* @param[in] tokenStr Records management token string.
*/
Q_INVOKABLE
void callUploadHierarchy(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.
* @param[in] urlStr Records management url string.
* @param[in] tokenStr Records management token string.
*/
Q_INVOKABLE
void getStoredMsgInfoFromRecordsManagement(const QString &urlStr,
......@@ -90,16 +82,15 @@ public:
/*!
* @brief Update record management settings.
*
* @param[in] urlStr new records management url string.
* @param[in] urlStr New records management url string.
* @param[in] urlStrSettings Records management url string from settings.
* @param[in] srLogo Service SVG logo.
* @param[in] srName Service name.
* @param[in] srToken Service token.
* @return True when data have been updated, false else.
*/
Q_INVOKABLE
bool updateServiceInfo(const QString &urlStr, const QString &urlStrSettings,
const QString &srLogo, const QString &srName, const QString &srToken);
const QString &srName, const QString &srToken);
signals:
......@@ -111,4 +102,31 @@ signals:
* @param[in] srToken Service token.
*/
void serviceInfo(QString srLogo, QString srName, QString srToken);
private:
/*!
* @brief Upload message into records management service.
*
* @param[in] urlStr Records management url string.
* @param[in] tokenStr Records management token string.
* @param[in] dmId Message identifier.
* @param[in] msgFileName Message file name.
* @param[in] msgData Message data.
* @return True when data have been updated, false else.
*/
bool uploadMessage(const QString &urlStr,
const QString &tokenStr, qint64 dmId, const QString &msgFileName,
const QByteArray &msgData);
/*!
* @brief Convert svg to QPixmap.
*
* @param[in] SvgContent Svg content.
* @return Pixmap.
*/
QPixmap fromSvgToPixmap(const QString &SvgContent);
RecordsManagementConnection m_rmc;
QByteArray m_logoSvg; /*!< Raw SVG data. */
};
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