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

List of form fields is the main contained for form data.

parent 06ed87db
......@@ -91,6 +91,7 @@ SOURCES += \
src/accounts.cpp \
src/auxiliaries/attachment_helper.cpp \
src/auxiliaries/email_helper.cpp \
src/datovka_shared/gov_services/helper.cpp \
src/datovka_shared/gov_services/service/gov_mv_crr_vbh.cpp \
src/datovka_shared/gov_services/service/gov_mv_ir_vp.cpp \
src/datovka_shared/gov_services/service/gov_mv_rt_vt.cpp \
......@@ -212,6 +213,7 @@ HEADERS += \
src/auxiliaries/attachment_helper.h \
src/auxiliaries/email_helper.h \
src/common.h \
src/datovka_shared/gov_services/helper.h \
src/datovka_shared/gov_services/service/gov_mv_crr_vbh.h \
src/datovka_shared/gov_services/service/gov_mv_ir_vp.h \
src/datovka_shared/gov_services/service/gov_mv_rt_vt.h \
......
/*
* 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 <QRegularExpression>
#include <QtGlobal>
#include "src/datovka_shared/gov_services/helper.h"
#define MAX_IC_LEN 8 /* IC has 8 digits. */
/*!
* @brief Check number whether it contains a valid IC. Also checks the checksum
* digit value.
*
* @param[in] num Number to be checked.
* @return True if number a is a valid IC.
*/
static
bool isValidIcNum(qint64 num)
{
if ((num < 0) || (num > Q_INT64_C(99999999))) {
return false;
}
int d8 = (num / 10000000) % 10;
int d7 = (num / 1000000) % 10;
int d6 = (num / 100000) % 10;
int d5 = (num / 10000) % 10;
int d4 = (num / 1000) % 10;
int d3 = (num / 100) % 10;
int d2 = (num / 10) % 10;
int d1 = num % 10; /* Lowest digit is a checksum digit. */
int x = (11 - ((8 * d8 + 7 * d7 + 6 * d6 + 5 * d5 + 4 * d4 + 3 * d3 + 2 * d2) % 11)) % 10;
return d1 == x;
}
bool Gov::Helper::isValidIcStr(const QString &str)
{
const static QRegularExpression numRe("\\d+");
QRegularExpressionMatchIterator it(numRe.globalMatch(str));
if (it.hasNext()) {
const QRegularExpressionMatch match(it.next());
if (str != match.captured()) {
return false;
}
} else {
return false;
}
if (str.length() > MAX_IC_LEN) {
return false;
}
bool iOk = false;
qint64 ic = str.toLongLong(&iOk);
if (!iOk) {
return false;
}
return isValidIcNum(ic);
}
/*
* 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 <QString>
namespace Gov {
/*!
* @brief Contains various conversion and checking sunctions.
*/
namespace Helper {
/*!
* @brief Check whether strin gcontains a valid IC.
*
* @param[in] str String containing an IC number.
* @return True if supplied string contains a valuid IC only.
*/
bool isValidIcStr(const QString &str);
}
}
......@@ -21,6 +21,8 @@
* the two.
*/
#include <QDate>
#include "src/datovka_shared/gov_services/service/gov_mv_crr_vbh.h"
static const char xml_template[] =
......@@ -55,12 +57,85 @@ static const char xml_template[] =
" </d:crr>""\n"
"</d:root>";
#define DRILIC_KEY "drivingLicenceId"
#define NAME_KEY "name"
#define SURNAME_KEY "surname"
#define BIRTH_KEY "birthDate"
#define DATE_FORMAT "yyyy-MM-dd"
class MvCrrVbhData {
Q_DECLARE_TR_FUNCTIONS(MvCrrVbhData)
public:
MvCrrVbhData(void)
: m_userDrivingLicenceId(), m_boxName(), m_boxSurname(),
m_boxBirthDate()
{ }
QList<Gov::FormField> allFields(void) const;
private:
QString m_userDrivingLicenceId; /*!< Driving licence identifier (number) without white spaces. */
QString m_boxName; /*!< First name derived from box data. */
QString m_boxSurname; /*!< Seurname derived from box data. */
QDate m_boxBirthDate; /*!< Birth date derived from box data. */
};
QList<Gov::FormField> MvCrrVbhData::allFields(void) const
{
QList<Gov::FormField> formList;
{
Gov::FormField ff;
ff.setKey(DRILIC_KEY);
ff.setVal(m_userDrivingLicenceId);
ff.setDescr(tr("Driving licence ID"));
ff.setPlaceholder(tr("Enter driving licence ID without spaces"));
ff.setProperties(Gov::FormFieldType::PROP_MANDATORY |
Gov::FormFieldType::PROP_USER_INPUT);
formList.append(ff);
}
{
Gov::FormField ff;
ff.setKey(NAME_KEY);
ff.setVal(m_boxName);
ff.setDescr(tr("Data-box owner name"));
//ff.setPlaceholder(QString());
ff.setProperties(Gov::FormFieldType::PROP_MANDATORY |
Gov::FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
Gov::FormField ff;
ff.setKey(SURNAME_KEY);
ff.setVal(m_boxSurname);
ff.setDescr(tr("Data-box owner surname"));
//ff.setPlaceholder(QString());
ff.setProperties(Gov::FormFieldType::PROP_MANDATORY |
Gov::FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
Gov::FormField ff;
ff.setKey(BIRTH_KEY);
ff.setVal(m_boxBirthDate.isNull() ? QString() : m_boxBirthDate.toString(DATE_FORMAT));
ff.setDescr(tr("Birth date"));
//ff.setPlaceholder(QString());
ff.setProperties(Gov::FormFieldType::PROP_MANDATORY |
Gov::FormFieldType::PROP_BOX_INPUT |
Gov::FormFieldType::PROP_TYPE_DATE);
formList.append(ff);
}
return formList;
}
Gov::SrvcMvCrrVbh::SrvcMvCrrVbh(void)
: m_userDrivingLicenceId(),
m_boxName(),
m_boxSurname(),
m_boxBirthDate()
: Service()
{
m_formFields = MvCrrVbhData().allFields();
}
Gov::Service *Gov::SrvcMvCrrVbh::createNew(void) const
......@@ -124,84 +199,15 @@ bool Gov::SrvcMvCrrVbh::canSend(enum Isds::Type::DbType dbType) const
}
}
#define DRILIC_KEY "drivingLicenceId"
#define NAME_KEY "name"
#define SURNAME_KEY "surname"
#define BIRTH_KEY "birthDate"
#define DATE_FORMAT "yyyy-MM-dd"
QList<Gov::FormField> Gov::SrvcMvCrrVbh::requiredFields(void) const
{
QList<FormField> formList;
{
FormField ff;
ff.setKey(DRILIC_KEY);
ff.setVal(m_userDrivingLicenceId);
ff.setDescr(tr("Driving licence ID"));
ff.setPlaceholder(tr("Enter driving licence ID without spaces"));
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_USER_INPUT);
formList.append(ff);
}
{
FormField ff;
ff.setKey(NAME_KEY);
ff.setVal(m_boxName);
ff.setDescr(tr("Data-box owner name"));
//ff.setPlaceholder(QString());
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
FormField ff;
ff.setKey(SURNAME_KEY);
ff.setVal(m_boxSurname);
ff.setDescr(tr("Data-box owner surname"));
//ff.setPlaceholder(QString());
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
FormField ff;
ff.setKey(BIRTH_KEY);
ff.setVal(m_boxBirthDate.isNull() ? QString() : m_boxBirthDate.toString(DATE_FORMAT));
ff.setDescr(tr("Birth date"));
//ff.setPlaceholder(QString());
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_BOX_INPUT |
FormFieldType::PROP_TYPE_DATE);
formList.append(ff);
}
return formList;
}
bool Gov::SrvcMvCrrVbh::setRequiredField(const QString &key, const QString &val)
bool Gov::SrvcMvCrrVbh::setFieldVal(const QString &key, const QString &val)
{
if (key == DRILIC_KEY) {
m_userDrivingLicenceId = val;
return true;
} else if (key == NAME_KEY) {
m_boxName = val;
return true;
} else if (key == SURNAME_KEY) {
m_boxSurname = val;
return true;
} else if (key == BIRTH_KEY) {
QDate date(QDate::fromString(val, DATE_FORMAT));
if (date.isNull()) {
if (key == BIRTH_KEY) {
if (QDate::fromString(val, DATE_FORMAT).isNull()) {
return false;
}
m_boxBirthDate = date;
return true;
} else {
return false;
}
return Service::setFieldVal(key, val);
}
bool Gov::SrvcMvCrrVbh::setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo)
......@@ -210,26 +216,44 @@ bool Gov::SrvcMvCrrVbh::setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo)
return false;
}
m_boxName = dbOwnerInfo.personName().firstName();
m_boxSurname = dbOwnerInfo.personName().lastName();
m_boxBirthDate = dbOwnerInfo.birthInfo().date();
const QString &boxName(dbOwnerInfo.personName().firstName());
const QString &boxSurname(dbOwnerInfo.personName().lastName());
const QDate &boxBirthDate(dbOwnerInfo.birthInfo().date());
if (Q_UNLIKELY(boxName.isEmpty() || boxSurname.isEmpty() ||
boxBirthDate.isNull())) {
return false;
}
if (Q_UNLIKELY(!Service::setFieldVal(NAME_KEY, boxName))) {
Q_ASSERT(0);
return false;
}
if (Q_UNLIKELY(!Service::setFieldVal(SURNAME_KEY, boxSurname))) {
Q_ASSERT(0);
return false;
}
if (Q_UNLIKELY(!Service::setFieldVal(BIRTH_KEY, boxBirthDate.toString(DATE_FORMAT)))) {
Q_ASSERT(0);
return false;
}
return (!m_boxName.isEmpty()) && (!m_boxSurname.isEmpty()) &&
(!m_boxBirthDate.isNull());
return true;
}
bool Gov::SrvcMvCrrVbh::haveAllMandatoryFields(void) const
{
return (!m_userDrivingLicenceId.isEmpty()) && (!m_boxName.isEmpty()) &&
(!m_boxSurname.isEmpty()) && (!m_boxBirthDate.isNull());
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);
xml.replace("__repl_DRIVE_LICENSE_ID__", m_userDrivingLicenceId);
xml.replace("__repl_NAME__", m_boxName);
xml.replace("__repl_SURNAME__", m_boxSurname);
xml.replace("__repl_BIRTH_DATE__", m_boxBirthDate.toString(DATE_FORMAT));
xml.replace("__repl_DRIVE_LICENSE_ID__", fieldVal(DRILIC_KEY));
xml.replace("__repl_NAME__", fieldVal(NAME_KEY));
xml.replace("__repl_SURNAME__", fieldVal(SURNAME_KEY));
xml.replace("__repl_BIRTH_DATE__", fieldVal(BIRTH_KEY));
return xml.toUtf8();
}
......@@ -24,7 +24,6 @@
#pragma once
#include <QCoreApplication> /* Q_DECLARE_TR_FUNCTIONS */
#include <QDate>
#include "src/datovka_shared/gov_services/service/gov_service_form_field.h"
#include "src/datovka_shared/gov_services/service/gov_service.h"
......@@ -76,10 +75,7 @@ namespace Gov {
bool canSend(enum Isds::Type::DbType dbType) const Q_DECL_OVERRIDE;
virtual
QList<FormField> requiredFields(void) const Q_DECL_OVERRIDE;
virtual
bool setRequiredField(const QString &key, const QString &val) Q_DECL_OVERRIDE;
bool setFieldVal(const QString &key, const QString &val) Q_DECL_OVERRIDE;
virtual
bool setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo) Q_DECL_OVERRIDE;
......@@ -89,12 +85,6 @@ namespace Gov {
virtual
QByteArray binaryXmlContent(void) const Q_DECL_OVERRIDE;
private:
QString m_userDrivingLicenceId; /*!< Driving licence identifier (number) without white spaces. */
QString m_boxName; /*!< First name derived from box data. */
QString m_boxSurname; /*!< Seurname derived from box data. */
QDate m_boxBirthDate; /*!< Birth date derived from box data. */
};
}
......@@ -489,9 +489,44 @@ static const char xml_template[] =
" </d:evidencni_udaje_hk>""\n"
"</d:root>";
#define IC_KEY "ic"
class MvIrVpData {
Q_DECLARE_TR_FUNCTIONS(MvIrVpData)
public:
MvIrVpData(void)
: m_userIc()
{ }
QList<Gov::FormField> allFields(void) const;
private:
QString m_userIc; /*!< Identification number. */
};
QList<Gov::FormField> MvIrVpData::allFields(void) const
{
QList<Gov::FormField> formList;
{
Gov::FormField ff;
ff.setKey(IC_KEY);
ff.setVal(m_userIc);
ff.setDescr(tr("Subject ID (IČ)"));
ff.setPlaceholder(tr("Enter subject ID (IČ)"));
ff.setProperties(Gov::FormFieldType::PROP_MANDATORY |
Gov::FormFieldType::PROP_USER_INPUT);
formList.append(ff);
}
return formList;
}
Gov::SrvcMvIrVp::SrvcMvIrVp(void)
: m_userIc()
: Service()
{
m_formFields = MvIrVpData().allFields();
}
Gov::Service *Gov::SrvcMvIrVp::createNew(void) const
......@@ -565,34 +600,9 @@ bool Gov::SrvcMvIrVp::canSend(enum Isds::Type::DbType dbType) const
}
}
#define IC_KEY "ic"
QList<Gov::FormField> Gov::SrvcMvIrVp::requiredFields(void) const
{
QList<FormField> formList;
{
FormField ff;
ff.setKey(IC_KEY);
ff.setVal(m_userIc);
ff.setDescr(tr("Subject ID (IČ)"));
ff.setPlaceholder(tr("Enter subject ID (IČ)"));
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_USER_INPUT);
formList.append(ff);
}
return formList;
}
bool Gov::SrvcMvIrVp::setRequiredField(const QString &key, const QString &val)
bool Gov::SrvcMvIrVp::setFieldVal(const QString &key, const QString &val)
{
if (key == IC_KEY) {
m_userIc = val;
return true;
} else {
return false;
}
return Service::setFieldVal(key, val);
}
bool Gov::SrvcMvIrVp::setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo)
......@@ -606,12 +616,12 @@ bool Gov::SrvcMvIrVp::setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo)
bool Gov::SrvcMvIrVp::haveAllMandatoryFields(void) const
{
return !m_userIc.isEmpty();
return !fieldVal(IC_KEY).isEmpty();
}
QByteArray Gov::SrvcMvIrVp::binaryXmlContent(void) const
{
QString xml(xml_template);
xml.replace("__repl_IC_SUBJECT__", m_userIc);
xml.replace("__repl_IC_SUBJECT__", fieldVal(IC_KEY));
return xml.toUtf8();
}
......@@ -74,10 +74,7 @@ namespace Gov {
bool canSend(enum Isds::Type::DbType dbType) const Q_DECL_OVERRIDE;
virtual
QList<FormField> requiredFields(void) const Q_DECL_OVERRIDE;
virtual
bool setRequiredField(const QString &key, const QString &val) Q_DECL_OVERRIDE;
bool setFieldVal(const QString &key, const QString &val) Q_DECL_OVERRIDE;
virtual
bool setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo) Q_DECL_OVERRIDE;
......@@ -87,9 +84,6 @@ namespace Gov {
virtual
QByteArray binaryXmlContent(void) const Q_DECL_OVERRIDE;
private:
QString m_userIc; /*!< Identification number. */
};
}
......@@ -21,6 +21,8 @@
* the two.
*/
#include <QDate>
#include "src/datovka_shared/gov_services/service/gov_mv_rt_vt.h"
static const char xml_template[] =
......@@ -68,13 +70,95 @@ static const char xml_template[] =
" </d:requestZadostVM>""\n"
"</d:root>";
#define NAME_KEY "name"
#define SURNAME_KEY "surname"
#define BIRTH_KEY "birthDate"
#define REGION_KEY "region"
#define CITY_KEY "city"
#define DATE_FORMAT "yyyy-MM-dd"
class MvRtVtData {
Q_DECLARE_TR_FUNCTIONS(MvRtVtData)
public:
MvRtVtData(void)
: m_boxName(), m_boxSurname(), m_boxBirthDate(), m_boxBirthRegion(),
m_boxBirthCity()
{ }
QList<Gov::FormField> allFields(void) const;
private:
QString m_boxName; /*!< First name derived from box data. */
QString m_boxSurname; /*!< Seurname derived from box data. */
QDate m_boxBirthDate; /*!< Birth date derived from box data. */
QString m_boxBirthRegion; /*!< Birth region. */
QString m_boxBirthCity; /*!< Birth city. */
};
QList<Gov::FormField> MvRtVtData::allFields(void) const
{
QList<Gov::FormField> formList;
{
Gov::FormField ff;
ff.setKey(NAME_KEY);
ff.setVal(m_boxName);
ff.setDescr(tr("Data-box owner name"));
//ff.setPlaceholder(QString());
ff.setProperties(Gov::FormFieldType::PROP_MANDATORY |
Gov::FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
Gov::FormField ff;
ff.setKey(SURNAME_KEY);
ff.setVal(m_boxSurname);
ff.setDescr(tr("Data-box owner surname"));
//ff.setPlaceholder(QString());
ff.setProperties(Gov::FormFieldType::PROP_MANDATORY |
Gov::FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
Gov::FormField ff;
ff.setKey(BIRTH_KEY);
ff.setVal(m_boxBirthDate.isNull() ? QString() : m_boxBirthDate.toString(DATE_FORMAT));
ff.setDescr(tr("Birth date"));
//ff.setPlaceholder(QString());
ff.setProperties(Gov::FormFieldType::PROP_MANDATORY |
Gov::FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
Gov::FormField ff;
ff.setKey(REGION_KEY);
ff.setVal(m_boxBirthRegion);
ff.setDescr(tr("Birth region"));
//ff.setPlaceholder(QString());
ff.setProperties(Gov::FormFieldType::PROP_MANDATORY |
Gov::FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
Gov::FormField ff;
ff.setKey(CITY_KEY);
ff.setVal(m_boxBirthCity);
ff.setDescr(tr("City"));
//ff.setPlaceholder(QString());
ff.setProperties(Gov::FormFieldType::PROP_MANDATORY |
Gov::FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
return formList;
}
Gov::SrvcMvRtVt::SrvcMvRtVt(void)
: m_boxName(),
m_boxSurname(),
m_boxBirthDate(),
m_boxBirthRegion(),
m_boxBirthCity()
: Service()
{
m_formFields = MvRtVtData().allFields();
}
Gov::Service *Gov::SrvcMvRtVt::createNew(void) const
......@@ -138,96 +222,15 @@ bool Gov::SrvcMvRtVt::canSend(enum Isds::Type::DbType dbType) const
}
}
#define NAME_KEY "name"
#define SURNAME_KEY "surname"
#define BIRTH_KEY "birthDate"
#define REGION_KEY "region"
#define CITY_KEY "city"
#define DATE_FORMAT "yyyy-MM-dd"
QList<Gov::FormField> Gov::SrvcMvRtVt::requiredFields(void) const
bool Gov::SrvcMvRtVt::setFieldVal(const QString &key, const QString &val)
{
QList<FormField> formList;
{
FormField ff;
ff.setKey(NAME_KEY);
ff.setVal(m_boxName);
ff.setDescr(tr("Data-box owner name"));
//ff.setPlaceholder(QString());
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
FormField ff;
ff.setKey(SURNAME_KEY);
ff.setVal(m_boxSurname);
ff.setDescr(tr("Data-box owner surname"));
//ff.setPlaceholder(QString());
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
FormField ff;
ff.setKey(BIRTH_KEY);
ff.setVal(m_boxBirthDate.isNull() ? QString() : m_boxBirthDate.toString(DATE_FORMAT));
ff.setDescr(tr("Birth date"));
//ff.setPlaceholder(QString());
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
FormField ff;
ff.setKey(REGION_KEY);
ff.setVal(m_boxBirthRegion);
ff.setDescr(tr("Birth region"));
//ff.setPlaceholder(QString());
ff.setProperties(FormFieldType::PROP_MANDATORY |