Commit c4b8fabd authored by Martin Straka's avatar Martin Straka

Added another records management json files

parent 795fae5c
......@@ -97,6 +97,9 @@ SOURCES += \
src/datovka_shared/records_management/json/entry_error.cpp \
src/datovka_shared/records_management/json/helper.cpp \
src/datovka_shared/records_management/json/service_info.cpp \
src/datovka_shared/records_management/json/stored_files.cpp \
src/datovka_shared/records_management/json/upload_file.cpp \
src/datovka_shared/records_management/json/upload_hierarchy.cpp \
src/datovka_shared/settings/pin.cpp \
src/datovka_shared/settings/records_management.cpp \
src/datovka_shared/utility/strings.cpp \
......@@ -170,6 +173,9 @@ HEADERS += \
src/datovka_shared/records_management/json/entry_error.h \
src/datovka_shared/records_management/json/helper.h \
src/datovka_shared/records_management/json/service_info.h \
src/datovka_shared/records_management/json/stored_files.h \
src/datovka_shared/records_management/json/upload_file.h \
src/datovka_shared/records_management/json/upload_hierarchy.h \
src/datovka_shared/settings/pin.h \
src/datovka_shared/settings/records_management.h \
src/datovka_shared/utility/strings.h \
......@@ -228,7 +234,6 @@ HEADERS += \
src/worker/task_send_message.h \
src/worker/task_send_sms.h \
src/zfo.h
android {
SOURCES += \
src/os_android.cpp
......
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 <QByteArray>
#include <QList>
#include <QStringList>
#include "src/datovka_shared/records_management/json/entry_error.h"
class QJsonValue; /* Forward declaration. */
/*!
* @brief Encapsulates the stored_files request.
*/
class StoredFilesReq {
private:
/*!
* @brief Constructor. Creates an invalid structure.
*/
StoredFilesReq(void);
public:
/*!
* @brief Constructor.
*
* @param[in] dmIds Data message identifiers.
* @param[in] diIds Delivery info identifiers.
*/
StoredFilesReq(const QList<qint64> &dmIds, const QList<qint64> &diIds);
/*!
* @brief Copy constructor.
*
* @param[in] sfr Stored files request.
*/
StoredFilesReq(const StoredFilesReq &sfr);
/*!
* @brief Return data message identifiers.
*
* @return Data message identifiers as used in ISDS.
*/
const QList<qint64> &dmIds(void) const;
/*!
* @brief Return delivery info identifiers.
*
* @return Delivery info identifiers as used in ISDS.
*/
const QList<qint64> &diIds(void) const;
/*!
* @brief Check whether content is valid.
*
* @return True if content is valid.
*/
bool isValid(void) const;
/*!
* @brief Creates a stored files request structure from supplied JSON
* document.
*
* @param[in] json JSON document.
* @param[out] ok Set to true on success.
* @return Invalid structure on error a valid structure else.
*/
static
StoredFilesReq fromJson(const QByteArray &json, bool *ok = Q_NULLPTR);
/*!
* @brief Converts stored files structure into a JSON document.
*
* @note Unspecified values are stores as null into the JSON document.
*
* @return JSON document containing stored data.
*/
QByteArray toJson(void) const;
private:
QList<qint64> m_dmIds; /*!< Data message identifiers. */
QList<qint64> m_diIds; /*!< Delivery info identifiers. */
};
/*!
* @brief Encapsulates stored_files data message entry structure.
*/
class DmEntry {
public:
/*!
* @brief Constructor. Constructs invalid entry.
*/
DmEntry(void);
/*!
* @brief Constructor.
*
* @param[in] dmId Message identifier.
* @param[in] locations List of locations.
*/
DmEntry(qint64 dmId, const QStringList &locations);
/*!
* @brief Copy constructor.
*
* @param[in] me Message entry.
*/
DmEntry(const DmEntry &me);
/*!
* @brief Return message identifier.
*
* @return Data message identifier.
*/
qint64 dmId(void) const;
/*!
* @brief Return list of locations.
*
* @return Locations.
*/
const QStringList &locations(void) const;
/*!
* @brief Check whether content is valid.
*
* @return True if content is valid.
*/
bool isValid(void) const;
/*!
* @brief Set content according to JSON value.
*
* @note Method does not modify value of error entry if false returned.
* JSON null values are converted into no-error entries.
*
* @param[in] jsonVal Value to read from.
* @return True on success, false else.
*/
bool fromJsonVal(const QJsonValue *jsonVal);
/*!
* @brief Set content of supplied JSON value.
*
* @note No-error entries are converted into JSON null values.
*
* @param[out] jsonVal Value to store to.
* @return True on success, false else.
*/
bool toJsonVal(QJsonValue *jsonVal) const;
private:
qint64 m_dmId; /*!< Data message identifier. */
QStringList m_locations; /*!< Where the uploaded file is located in the service. */
};
/*!
* @brief Encapsulates stored_files delivery info entry structure.
*/
class DiEntry {
public:
/*!
* @brief Constructor. Constructs invalid entry.
*/
DiEntry(void);
/*!
* @brief Constructor.
*
* @param[in] diId Info identifier.
* @param[in] locations List of locations.
*/
DiEntry(qint64 diId, const QStringList &locations);
/*!
* @brief Copy constructor.
*
* @param[in] ie Info entry.
*/
DiEntry(const DiEntry &ie);
/*!
* @brief Return info identifier.
*
* @return Data info identifier.
*/
qint64 diId(void) const;
/*!
* @brief Return list of locations.
*
* @return Locations.
*/
const QStringList &locations(void) const;
/*!
* @brief Check whether content is valid.
*
* @return True if content is valid.
*/
bool isValid(void) const;
/*!
* @brief Set content according to JSON value.
*
* @note Method does not modify value of error entry if false returned.
* JSON null values are converted into no-error entries.
*
* @param[in] jsonVal Value to read from.
* @return True on success, false else.
*/
bool fromJsonVal(const QJsonValue *jsonVal);
/*!
* @brief Set content of supplied JSON value.
*
* @note No-error entries are converted into JSON null values.
*
* @param[out] jsonVal Value to store to.
* @return True on success, false else.
*/
bool toJsonVal(QJsonValue *jsonVal) const;
private:
qint64 m_diId; /*!< Delivery info identifier. */
QStringList m_locations; /*!< Where the uploaded file is located in the service. */
};
/*!
* @brief Encapsulates the stored_files response.
*/
class StoredFilesResp {
private:
/*!
* @brief Constructor. Creates an invalid structure.
*/
StoredFilesResp(void);
/*!
* @brief Constructor.
*
* @param[in] dms List of data message entries.
* @param[in] dis List of delivery information entries.
* @param[in] limit Request limit.
* @param[in] error Error entry.
*/
StoredFilesResp(const QList<DmEntry> &dms, const QList<DiEntry> &dis,
int limit, const ErrorEntry &error);
public:
/*!
* @brief Copy constructor.
*
* @param[in] sfr Stored files response.
*/
StoredFilesResp(const StoredFilesResp &sfr);
/*!
* @brief Return list of data message entries.
*
* @return List of held data message entries.
*/
const QList<DmEntry> &dms(void) const;
/*!
* @brief Return list of delivery info entries.
*
* @return List of held delivery info entries.
*/
const QList<DiEntry> &dis(void) const;
/*!
* @brief Return request limit.
*
* @return Request limit as obtained from the service.
*/
int limit(void) const;
/*!
* @brief Return error entry.
*
* @return Error entry.
*/
const ErrorEntry &error(void) const;
/*!
* @brief Check whether content is valid.
*
* @return True if content is valid.
*/
bool isValid(void) const;
/*!
* @brief Creates a stored files response structure from supplied JSON
* document.
*
* @param[in] json JSON document.
* @param[out] ok Set to true on success.
* @return Invalid structure on error a valid structure else.
*/
static
StoredFilesResp fromJson(const QByteArray &json,
bool *ok = Q_NULLPTR);
/*!
* @brief Converts stored files response structure into a JSON document.
*
* @note Unspecified values are stores as null into the JSON document.
*
* @return JSON document containing stored data.
*/
QByteArray toJson(void) const;
private:
QList<DmEntry> m_dms; /*!< List of received data message entries. */
QList<DiEntry> m_dis; /*!< List of received delivery info entries. */
int m_limit; /*!< Request limit, must be greater than zero. */
ErrorEntry m_error; /*!< Encountered error. */
};
/*
* 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 <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include "src/datovka_shared/records_management/json/entry_error.h"
#include "src/datovka_shared/records_management/json/helper.h"
#include "src/datovka_shared/records_management/json/upload_file.h"
static
const QString keyIds("ids");
static
const QString keyFileName("file_name");
static
const QString keyFileContent("file_content");
static
const QString keyId("id");
static
const QString keyError("error");
static
const QString keyLocations("locations");
UploadFileReq::UploadFileReq(void)
: m_ids(),
m_fileName(),
m_fileContent()
{
}
UploadFileReq::UploadFileReq(const QStringList &ids, const QString &fileName,
const QByteArray &fileContent)
: m_ids(ids),
m_fileName(fileName),
m_fileContent(fileContent)
{
}
UploadFileReq::UploadFileReq(const UploadFileReq &ufr)
: m_ids(ufr.m_ids),
m_fileName(ufr.m_fileName),
m_fileContent(ufr.m_fileContent)
{
}
const QStringList &UploadFileReq::ids(void) const
{
return m_ids;
}
const QString &UploadFileReq::fileName(void) const
{
return m_fileName;
}
const QByteArray &UploadFileReq::fileContent(void) const
{
return m_fileContent;
}
bool UploadFileReq::isValid(void) const
{
bool valid = !m_ids.isEmpty() && !m_fileName.isEmpty() &&
!m_fileContent.isEmpty();
if (!valid) {
return false;
}
foreach (const QString &id, m_ids) {
if (id.isEmpty()) {
return false;
}
}
return true;
}
UploadFileReq UploadFileReq::fromJson(const QByteArray &json, bool *ok)
{
QJsonObject jsonObj;
if (!JsonHelper::readRootObject(json, jsonObj)) {
if (ok != Q_NULLPTR) {
*ok = false;
}
return UploadFileReq();
}
UploadFileReq ufr;
if (!JsonHelper::readStringList(jsonObj, keyIds, ufr.m_ids, false)) {
if (ok != Q_NULLPTR) {
*ok = false;
}
return UploadFileReq();
}
if (!JsonHelper::readString(jsonObj, keyFileName, ufr.m_fileName,
false)) {
if (ok != Q_NULLPTR) {
*ok = false;
}
return UploadFileReq();
}
{
QString valStr;
if (!JsonHelper::readString(jsonObj, keyFileContent, valStr,
false)) {
if (ok != Q_NULLPTR) {
*ok = false;
}
return UploadFileReq();
}
ufr.m_fileContent = QByteArray::fromBase64(valStr.toUtf8());
}
if (ok != Q_NULLPTR) {
*ok = true;
}
return ufr;
}
QByteArray UploadFileReq::toJson(void) const
{
QJsonObject jsonObj;
jsonObj.insert(keyIds, QJsonArray::fromStringList(m_ids));
jsonObj.insert(keyFileName, !m_fileName.isNull() ?
m_fileName : QJsonValue());
jsonObj.insert(keyFileContent, !m_fileContent.isNull() ?
QString::fromUtf8(m_fileContent.toBase64()) : QJsonValue());
return QJsonDocument(jsonObj).toJson(QJsonDocument::Indented);
}
UploadFileResp::UploadFileResp(void)
: m_id(),
m_error(),
m_locations()
{
}
UploadFileResp::UploadFileResp(const QString &id, const ErrorEntry &error,
const QStringList &locations)
: m_id(id),
m_error(error),
m_locations(locations)
{
}
UploadFileResp::UploadFileResp(const UploadFileResp &ufr)
: m_id(ufr.m_id),
m_error(ufr.m_error),
m_locations(ufr.m_locations)
{
}
const QString &UploadFileResp::id(void) const
{
return m_id;
}
const ErrorEntry &UploadFileResp::error(void) const
{
return m_error;
}
const QStringList &UploadFileResp::locations(void) const
{
return m_locations;
}
bool UploadFileResp::isValid(void) const
{
return (!m_id.isEmpty() && !m_locations.isEmpty()) ||
(m_error.code() != ErrorEntry::ERR_NO_ERROR);
}
UploadFileResp UploadFileResp::fromJson(const QByteArray &json, bool *ok)
{
QJsonObject jsonObj;
if (!JsonHelper::readRootObject(json, jsonObj)) {
if (ok != Q_NULLPTR) {
*ok = false;
}
return UploadFileResp();
}
UploadFileResp ufr;
if (!JsonHelper::readString(jsonObj, keyId, ufr.m_id, true)) {
if (ok != Q_NULLPTR) {
*ok = false;
}
return UploadFileResp();
}
{
QJsonValue jsonVal;
if (!JsonHelper::readValue(jsonObj, keyError, jsonVal)) {
if (ok != Q_NULLPTR) {
*ok = false;
}
return UploadFileResp();
}
if (!ufr.m_error.fromJsonVal(&jsonVal)) {
if (ok != Q_NULLPTR) {
*ok = false;
}
return UploadFileResp();
}
}
if (!JsonHelper::readStringList(jsonObj, keyLocations, ufr.m_locations,
false)) {
if (ok != Q_NULLPTR) {
*ok = false;
}
return UploadFileResp();
}
if (ok != Q_NULLPTR) {
*ok = true;
}
return ufr;
}
QByteArray UploadFileResp::toJson(void) const
{
QJsonObject jsonObj;
jsonObj.insert(keyId, !m_id.isNull() ? m_id : QJsonValue());
QJsonValue jsonVal;
m_error.toJsonVal(&jsonVal);
jsonObj.insert(keyError, jsonVal);
jsonObj.insert(keyLocations, QJsonArray::fromStringList(m_locations));
return QJsonDocument(jsonObj).toJson(QJsonDocument::Indented);
}
/*
* 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 <QByteArray>
#include <QList>
#include <QString>
#include <QStringList>
#include "src/datovka_shared/records_management/json/entry_error.h"
/*!
* @brief Encapsulates the upload_file request.
*/
class UploadFileReq {
private:
/*!
* @brief Constructor. Creates an invalid structure.
*/
UploadFileReq(void);
public:
/*!
* @brief Constructor.
*
* @param[in] ids Location identifiers as obtained from upload_hierarchy.
* @param[in] fileName File name.
* @param[in] fileContent Raw file content.
*/
UploadFileReq(const QStringList &ids, const QString &fileName,
const QByteArray &fileContent);
/*!
* @brief Copy constructor.
*
* @param[in] ufr Upload file request.
*/
UploadFileReq(const UploadFileReq &ufr);
/*!
* @brief Return location identifier.
*
* @return Location identifier.
*/
const QStringList &ids(void) const;
/*!
* @brief Return file name.
*
* @return File name.
*/
const QString &fileName(void) const;
/*!
* @brief Return file content.
*
* @return Raw file content.
*/
const QByteArray &fileContent(void) const;
/*!
* @brief Check whether content is valid.
*
* @return True if content is valid.
*/
bool isValid(void) const;
/*!
* @brief Creates a upload file request structure from supplied JSON
* document.
*
* @param[in] json JSON document.
* @param[out] ok Set to true on success.
* @return Invalid structure on error a valid structure else.
*/