Commit 61fa9c20 authored by Karel Slaný's avatar Karel Slaný Committed by Martin Straka

Services form now the data basis for the form model.

parent cd9c40a3
......@@ -240,14 +240,6 @@ bool Gov::SrvcMvCrrVbh::setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo)
return true;
}
bool Gov::SrvcMvCrrVbh::haveAllMandatoryFields(void) const
{
return (!fieldVal(DRILIC_KEY).isEmpty()) &&
(!fieldVal(NAME_KEY).isEmpty()) &&
(!fieldVal(SURNAME_KEY).isEmpty()) &&
(!fieldVal(BIRTH_KEY).isEmpty());
}
QByteArray Gov::SrvcMvCrrVbh::binaryXmlContent(void) const
{
QString xml(xml_template);
......
......@@ -80,9 +80,6 @@ namespace Gov {
virtual
bool setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo) Q_DECL_OVERRIDE;
virtual
bool haveAllMandatoryFields(void) const Q_DECL_OVERRIDE;
virtual
QByteArray binaryXmlContent(void) const Q_DECL_OVERRIDE;
};
......
......@@ -614,11 +614,6 @@ bool Gov::SrvcMvIrVp::setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo)
return true;
}
bool Gov::SrvcMvIrVp::haveAllMandatoryFields(void) const
{
return !fieldVal(IC_KEY).isEmpty();
}
QByteArray Gov::SrvcMvIrVp::binaryXmlContent(void) const
{
QString xml(xml_template);
......
......@@ -79,9 +79,6 @@ namespace Gov {
virtual
bool setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo) Q_DECL_OVERRIDE;
virtual
bool haveAllMandatoryFields(void) const Q_DECL_OVERRIDE;
virtual
QByteArray binaryXmlContent(void) const Q_DECL_OVERRIDE;
};
......
......@@ -275,15 +275,6 @@ bool Gov::SrvcMvRtVt::setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo)
return true;
}
bool Gov::SrvcMvRtVt::haveAllMandatoryFields(void) const
{
return (!fieldVal(NAME_KEY).isEmpty()) &&
(!fieldVal(SURNAME_KEY).isEmpty()) &&
(!fieldVal(BIRTH_KEY).isEmpty()) &&
(!fieldVal(REGION_KEY).isEmpty()) &&
(!fieldVal(CITY_KEY).isEmpty());
}
QByteArray Gov::SrvcMvRtVt::binaryXmlContent(void) const
{
const QDate boxBirthDate(
......
......@@ -79,9 +79,6 @@ namespace Gov {
virtual
bool setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo) Q_DECL_OVERRIDE;
virtual
bool haveAllMandatoryFields(void) const Q_DECL_OVERRIDE;
virtual
QByteArray binaryXmlContent(void) const Q_DECL_OVERRIDE;
};
......
......@@ -619,11 +619,6 @@ bool Gov::SrvcMvRtpoVt::setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo)
return true;
}
bool Gov::SrvcMvRtpoVt::haveAllMandatoryFields(void) const
{
return !fieldVal(IC_KEY).isEmpty();
}
QByteArray Gov::SrvcMvRtpoVt::binaryXmlContent(void) const
{
QString xml(xml_template);
......
......@@ -79,9 +79,6 @@ namespace Gov {
virtual
bool setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo) Q_DECL_OVERRIDE;
virtual
bool haveAllMandatoryFields(void) const Q_DECL_OVERRIDE;
virtual
QByteArray binaryXmlContent(void) const Q_DECL_OVERRIDE;
};
......
......@@ -615,11 +615,6 @@ bool Gov::SrvcMvSkdVp::setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo)
return true;
}
bool Gov::SrvcMvSkdVp::haveAllMandatoryFields(void) const
{
return !fieldVal(IC_KEY).isEmpty();
}
QByteArray Gov::SrvcMvSkdVp::binaryXmlContent(void) const
{
QString xml(xml_template);
......
......@@ -79,9 +79,6 @@ namespace Gov {
virtual
bool setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo) Q_DECL_OVERRIDE;
virtual
bool haveAllMandatoryFields(void) const Q_DECL_OVERRIDE;
virtual
QByteArray binaryXmlContent(void) const Q_DECL_OVERRIDE;
};
......
......@@ -648,11 +648,6 @@ bool Gov::SrvcMvVrVp::setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo)
return true;
}
bool Gov::SrvcMvVrVp::haveAllMandatoryFields(void) const
{
return !fieldVal(IC_KEY).isEmpty();
}
QByteArray Gov::SrvcMvVrVp::binaryXmlContent(void) const
{
QString xml(xml_template);
......
......@@ -79,9 +79,6 @@ namespace Gov {
virtual
bool setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo) Q_DECL_OVERRIDE;
virtual
bool haveAllMandatoryFields(void) const Q_DECL_OVERRIDE;
virtual
QByteArray binaryXmlContent(void) const Q_DECL_OVERRIDE;
};
......
......@@ -614,11 +614,6 @@ bool Gov::SrvcMvZrVp::setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo)
return true;
}
bool Gov::SrvcMvZrVp::haveAllMandatoryFields(void) const
{
return !fieldVal(IC_KEY).isEmpty();
}
QByteArray Gov::SrvcMvZrVp::binaryXmlContent(void) const
{
QString xml(xml_template);
......
......@@ -79,9 +79,6 @@ namespace Gov {
virtual
bool setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo) Q_DECL_OVERRIDE;
virtual
bool haveAllMandatoryFields(void) const Q_DECL_OVERRIDE;
virtual
QByteArray binaryXmlContent(void) const Q_DECL_OVERRIDE;
};
......
......@@ -72,6 +72,18 @@ bool Gov::Service::setFieldVal(const QString &key, const QString &val)
return false;
}
bool Gov::Service::haveAllMandatoryFields(void) const
{
foreach (const FormField &ff, m_formFields) {
if ((ff.properties() & FormFieldType::PROP_MANDATORY) &&
ff.val().isEmpty()) {
return false;
}
}
return true;
}
Isds::Message Gov::Service::dataMessage(void) const
{
Isds::Message message;
......
......@@ -180,7 +180,7 @@ namespace Gov {
* @return True if all mandatory fields are set.
*/
virtual
bool haveAllMandatoryFields(void) const = 0;
bool haveAllMandatoryFields(void) const;
/*!
* @brief Create ISDS message containing the request.
......
......@@ -153,12 +153,6 @@ bool Gov::SrvcSzrRobVu::setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo)
return true;
}
bool Gov::SrvcSzrRobVu::haveAllMandatoryFields(void) const
{
/* No fields required. */
return true;
}
QByteArray Gov::SrvcSzrRobVu::binaryXmlContent(void) const
{
return QString(xml_template).toUtf8();
......
......@@ -79,9 +79,6 @@ namespace Gov {
virtual
bool setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo) Q_DECL_OVERRIDE;
virtual
bool haveAllMandatoryFields(void) const Q_DECL_OVERRIDE;
virtual
QByteArray binaryXmlContent(void) const Q_DECL_OVERRIDE;
};
......
......@@ -201,11 +201,6 @@ bool Gov::SrvcSzrRobVvu::setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo
return true;
}
bool Gov::SrvcSzrRobVvu::haveAllMandatoryFields(void) const
{
return (!fieldVal(FROM_KEY).isEmpty()) && (!fieldVal(TO_KEY).isEmpty());
}
QByteArray Gov::SrvcSzrRobVvu::binaryXmlContent(void) const
{
QString xml(xml_template);
......
......@@ -79,9 +79,6 @@ namespace Gov {
virtual
bool setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo) Q_DECL_OVERRIDE;
virtual
bool haveAllMandatoryFields(void) const Q_DECL_OVERRIDE;
virtual
QByteArray binaryXmlContent(void) const Q_DECL_OVERRIDE;
};
......
......@@ -200,11 +200,6 @@ bool Gov::SrvcSzrRosVv::setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo)
return true;
}
bool Gov::SrvcSzrRosVv::haveAllMandatoryFields(void) const
{
return !fieldVal(IC_KEY).isEmpty();
}
QByteArray Gov::SrvcSzrRosVv::binaryXmlContent(void) const
{
QString xml(xml_template);
......
......@@ -79,9 +79,6 @@ namespace Gov {
virtual
bool setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo) Q_DECL_OVERRIDE;
virtual
bool haveAllMandatoryFields(void) const Q_DECL_OVERRIDE;
virtual
QByteArray binaryXmlContent(void) const Q_DECL_OVERRIDE;
};
......
......@@ -34,20 +34,37 @@ void GovFormListModel::declareQML(void)
GovFormListModel::GovFormListModel(QObject *parent)
: QAbstractListModel(parent),
m_formFieldList()
m_service(Q_NULLPTR)
{
}
GovFormListModel::GovFormListModel(const GovFormListModel &model,
GovFormListModel::GovFormListModel(const GovFormListModel &other,
QObject *parent)
: QAbstractListModel(parent),
m_formFieldList(model.m_formFieldList)
m_service(Q_NULLPTR)
{
/* Copy service data. */
if (other.m_service != Q_NULLPTR) {
m_service = other.m_service->createNew();
if (m_service != Q_NULLPTR) {
foreach (const Gov::FormField &ff, other.m_service->fields()) {
m_service->setFieldVal(ff.key(), ff.val());
}
}
}
}
GovFormListModel::~GovFormListModel(void)
{
if (m_service != Q_NULLPTR) {
delete m_service; m_service = Q_NULLPTR;
}
}
int GovFormListModel::rowCount(const QModelIndex &parent) const
{
return !parent.isValid() ? m_formFieldList.size() : 0;
return ((!parent.isValid()) && (m_service != Q_NULLPTR)) ?
m_service->fields().size() : 0;
}
/* Property keys used in QML. */
......@@ -78,13 +95,18 @@ QHash<int, QByteArray> GovFormListModel::roleNames(void) const
QVariant GovFormListModel::data(const QModelIndex &index, int role) const
{
if (Q_UNLIKELY(m_service == Q_NULLPTR)) {
Q_ASSERT(0);
return QVariant();
}
int row = index.row();
if (Q_UNLIKELY((row < 0) || (row >= m_formFieldList.size()))) {
if (Q_UNLIKELY((row < 0) || (row >= m_service->fields().size()))) {
Q_ASSERT(0);
return QVariant();
}
const Gov::FormField &ff(m_formFieldList[row]);
const Gov::FormField &ff(m_service->fields()[row]);
switch (role) {
case ROLE_GOV_SRVC_KEY:
......@@ -119,48 +141,36 @@ QVariant GovFormListModel::data(const QModelIndex &index, int role) const
return QVariant();
}
const QList<Gov::FormField> &GovFormListModel::allEntries(void) const
{
return m_formFieldList;
}
Qt::ItemFlags GovFormListModel::flags(const QModelIndex &index) const
{
return QAbstractListModel::flags(index);
}
void GovFormListModel::appendEntry(const Gov::FormField &entry)
const Gov::Service *GovFormListModel::service(void) const
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_formFieldList.append(entry);
endInsertRows();
return m_service;
}
void GovFormListModel::setEntries(const QList<Gov::FormField> &entries)
Gov::Service *GovFormListModel::setService(Gov::Service *service)
{
beginResetModel();
m_formFieldList = entries;
endResetModel();
}
Gov::Service *oldService = m_service;
void GovFormListModel::setEntries(QList<Gov::FormField> &&entries)
{
beginResetModel();
m_formFieldList = entries;
m_service = service;
endResetModel();
}
void GovFormListModel::clearAll(void)
{
beginResetModel();
m_formFieldList.clear();
endResetModel();
return oldService;
}
void GovFormListModel::setProperty(int index, const QString &property,
const QVariant &value)
{
if (Q_UNLIKELY((index < 0) || (index >= m_formFieldList.size()))) {
if (Q_UNLIKELY(m_service == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
if (Q_UNLIKELY((index < 0) || (index >= m_service->fields().size()))) {
Q_ASSERT(0);
return;
}
......@@ -169,30 +179,29 @@ void GovFormListModel::setProperty(int index, const QString &property,
return;
}
m_formFieldList[index].setVal(value.toString());
m_service->fields()[index].setVal(value.toString());
emit dataChanged(QAbstractListModel::index(index, 0),
QAbstractListModel::index(index, 0));
}
bool GovFormListModel::haveAllMandatory(void) const
{
foreach (const Gov::FormField &ff, m_formFieldList) {
if ((ff.properties() & Gov::FormFieldType::PROP_MANDATORY) &&
ff.val().isEmpty()) {
return false;
}
if (m_service != Q_NULLPTR) {
return m_service->haveAllMandatoryFields();
} else {
return true;
}
return true;
}
bool GovFormListModel::containsMandatoryUser(void) const
{
foreach (const Gov::FormField &ff, m_formFieldList) {
const Gov::FormFieldType::Properties props = ff.properties();
if ((props & Gov::FormFieldType::PROP_MANDATORY) &&
(props & Gov::FormFieldType::PROP_USER_INPUT)) {
return true;
if (m_service != Q_NULLPTR) {
foreach (const Gov::FormField &ff, m_service->fields()) {
const Gov::FormFieldType::Properties props = ff.properties();
if ((props & Gov::FormFieldType::PROP_MANDATORY) &&
(props & Gov::FormFieldType::PROP_USER_INPUT)) {
return true;
}
}
}
......@@ -201,9 +210,11 @@ bool GovFormListModel::containsMandatoryUser(void) const
bool GovFormListModel::containsBoxOwnerData(void) const
{
foreach (const Gov::FormField &ff, m_formFieldList) {
if (ff.properties() & Gov::FormFieldType::PROP_BOX_INPUT) {
return true;
if (m_service != Q_NULLPTR) {
foreach (const Gov::FormField &ff, m_service->fields()) {
if (ff.properties() & Gov::FormFieldType::PROP_BOX_INPUT) {
return true;
}
}
}
......
......@@ -28,6 +28,7 @@
#include <QString>
#include "src/datovka_shared/gov_services/service/gov_service.h"
#include "src/datovka_shared/gov_services/service/gov_service_form_field.h"
/*!
* @brief Holds form data for gov services.
......@@ -67,12 +68,20 @@ public:
*
* @note Needed for QVariant conversion.
*
* @param[in] model Model to be copied.
* @param[in] other Model to be copied.
* @param[in] parent Pointer to parent object.
*/
explicit GovFormListModel(const GovFormListModel &model,
explicit GovFormListModel(const GovFormListModel &other,
QObject *parent = Q_NULLPTR);
/*!
* @brief Destructor.
*
* @note Deletes held service.
*/
virtual
~GovFormListModel(void);
/*!
* @brief Return number of rows under the given parent.
*
......@@ -101,13 +110,6 @@ public:
virtual
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
/*!
* @brief Return list of all entries.
*
* @return List of all entries.
*/
const QList<Gov::FormField> &allEntries(void) const;
/*!
* @brief Returns item flags for given index.
*
......@@ -118,27 +120,22 @@ public:
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
/*!
* @brief Appends entry line to model.
* @brief Returns pointer to currently held service.
*
* @param[in] entry Entry to append to model data.
* @return Pointer to currently associated service.
*/
void appendEntry(const Gov::FormField &entry);
const Gov::Service *service(void) const;
/*!
* @brief Sets all model entries.
* @brief Associate a service. The model takes ownership of the service object.
*
* @param[in] entryList List of entries.
*/
void setEntries(const QList<Gov::FormField> &entries);
#ifdef Q_COMPILER_RVALUE_REFS
void setEntries(QList<Gov::FormField> &&entries);
#endif /* Q_COMPILER_RVALUE_REFS */
/*!
* @brief Clears the model.
* @note The associated service is deleted in model destruction. It is
* on the caller to delete the old service object.
*
* @param[in] service New service to be associated with the model.
* @return Old associated service.
*/
Q_INVOKABLE
void clearAll(void);
Gov::Service *setService(Gov::Service *service);
/*!
* @brief Modify model data.
......@@ -194,7 +191,7 @@ public:
GovFormListModel *fromVariant(const QVariant &modelVariant);
private:
QList<Gov::FormField> m_formFieldList; /*!< Form data description. */
Gov::Service *m_service; /*!< Service data, the model is the owner. */
};
/* QML passes its arguments via QVariant. */
......
......@@ -208,7 +208,10 @@ void GovWrapper::loadFormToModel(const QString &userName,
GlobInstcs::accountDbPtr->getOwnerInfo(userName));
gs->setOwnerInfoFields(dbOwnerInfo);
formModel->setEntries(gs->fields());
Gov::Service *oldService = formModel->setService(gs.take());
if (oldService != Q_NULLPTR) {
delete oldService; oldService = Q_NULLPTR;
}
}
bool GovWrapper::sendGovRequest(const QString &userName,
......@@ -218,21 +221,23 @@ bool GovWrapper::sendGovRequest(const QString &userName,
const Gov::Service *cgs = m_govServices.value(serviceInternalId, Q_NULLPTR);
if (cgs == Q_NULLPTR) {
logErrorNL("Cannot access gov service '%s'.",
logErrorNL("Cannot access e-gov service '%s'.",
serviceInternalId.toUtf8().constData());
Q_ASSERT(0);
return false;
}
QScopedPointer<Gov::Service> gs(cgs->createNew());
if (Q_UNLIKELY(gs.isNull())) {
Q_ASSERT(0);
return false;
}
const GovFormListModel *formModel =
GovFormListModel::fromVariant(formModelVariant);
if (Q_UNLIKELY(formModel == Q_NULLPTR)) {
logErrorNL("%s", "Cannot access gov form model.");
logErrorNL("%s", "Cannot access e-gov form model.");
Q_ASSERT(0);
return false;
}
const Gov::Service *gs = formModel->service();
if (Q_UNLIKELY(gs == Q_NULLPTR)) {
logErrorNL("%s", "Cannot access e-gov service from form model.");
Q_ASSERT(0);
return false;
}
......@@ -256,15 +261,8 @@ bool GovWrapper::sendGovRequest(const QString &userName,
}
/* Set message content according to model data. */
foreach (const Gov::FormField &ff, formModel->allEntries()) {
if (!gs->setFieldVal(ff.key(), ff.val())) {
logWarningNL("The gov service '%s' does not accept the key '%s'.",
gs->internalId().toUtf8().constData(),
ff.key().toUtf8().constData());
}
}
if (!gs->haveAllMandatoryFields()) {
logErrorNL("The gov service '%s' is missing some mandatory data.",
logErrorNL("The e-gov service '%s' is missing some mandatory data.",
gs->internalId().toUtf8().constData());
return false;
}
......
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