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

Sending gov service request.

parent b2e80655
......@@ -271,8 +271,10 @@ Item {
target: isds
onRunSendGovMessageSig: {
actionButton.enabled = false
if (gov.sendGovRequest(userName, gsInternId, icoText.text, drvlicText.text, fromDateText.text, toDateText.text)) {
if (gov.sendGovRequest(userName, gsInternId, govFormModel)) {
pageView.pop(StackView.Immediate)
} else {
actionButton.enabled = govFormModel.haveAllMandatory()
}
}
}
......
......@@ -155,16 +155,16 @@ Component {
"gsInstName": gsInstName
}, StackView.Immediate)
} else {
gsInternIdSelected = gsInternId
isds.doIsdsAction("sendGovMessage", userName)
// gsInternIdSelected = gsInternId
// isds.doIsdsAction("sendGovMessage", userName)
}
}
Connections {
target: isds
onRunSendGovMessageSig: {
if (gov.sendGovRequest(userName, gsInternIdSelected, "","","","")) {
pageView.pop(StackView.Immediate)
}
// if (gov.sendGovRequest(userName, gsInternIdSelected, "","","","")) {
// pageView.pop(StackView.Immediate)
// }
}
}
}
......
......@@ -123,7 +123,7 @@ public:
/*!
* @brief Sets all model entries.
*
* @param[in] entryList List of entires.
* @param[in] entryList List of entries.
*/
void setEntries(const QList<RequiredInput> &entries);
......
......@@ -102,14 +102,16 @@ const QString &GovMvCrrVbh::dmFileDescr(void) const
return dmFileDescr;
}
#define DRILIC_KEY "drivingLicenceId"
QList<RequiredInput> GovMvCrrVbh::requiredFields(void) const
{
QList<RequiredInput> formList;
{
RequiredInput ri;
ri.key = "drivingLicenceId";
ri.val = QString();
ri.key = DRILIC_KEY;
ri.val = m_drivingLicenceId;
ri.descr = tr("Driving licence ID");
ri.placeholder = tr("Enter driving licence ID without spaces");
ri.mandatory = true;
......@@ -121,12 +123,18 @@ QList<RequiredInput> GovMvCrrVbh::requiredFields(void) const
bool GovMvCrrVbh::setRequiredField(const QString &key, const QString &val)
{
return false;
if (key != DRILIC_KEY) {
return false;
}
m_drivingLicenceId = val;
return true;
}
bool GovMvCrrVbh::haveAllRequiredFields(void)
bool GovMvCrrVbh::haveAllRequiredFields(void) const
{
return false;
return !m_drivingLicenceId.isEmpty();
}
QByteArray GovMvCrrVbh::binaryXmlContent(
......
......@@ -72,7 +72,7 @@ public:
bool setRequiredField(const QString &key, const QString &val) Q_DECL_OVERRIDE;
virtual
bool haveAllRequiredFields(void) Q_DECL_OVERRIDE;
bool haveAllRequiredFields(void) const Q_DECL_OVERRIDE;
virtual
QByteArray binaryXmlContent(
......
......@@ -146,7 +146,7 @@ public:
bool setRequiredField(const QString &key, const QString &val) = 0;
virtual
bool haveAllRequiredFields(void) = 0;
bool haveAllRequiredFields(void) const = 0;
/*!
* @brief Create GOV ISDS message.
......
......@@ -147,14 +147,6 @@ void Gov::loadFormToModel(const QString &userName,
Q_UNUSED(userName); /* Currently unused. */
GovFormListModel *formModel =
GovFormListModel::fromVariant(formModelVariant);
if (Q_UNLIKELY(formModel == Q_NULLPTR)) {
logErrorNL("%s", "Cannot access gov form model.");
Q_ASSERT(0);
return;
}
GovService *govService = m_govServices.value(serviceInternalId, Q_NULLPTR);
if (Q_UNLIKELY(govService == Q_NULLPTR)) {
logErrorNL("Cannot access gov service '%s'.",
......@@ -163,50 +155,79 @@ void Gov::loadFormToModel(const QString &userName,
return;
}
GovFormListModel *formModel =
GovFormListModel::fromVariant(formModelVariant);
if (Q_UNLIKELY(formModel == Q_NULLPTR)) {
logErrorNL("%s", "Cannot access gov form model.");
Q_ASSERT(0);
return;
}
formModel->setEntries(govService->requiredFields());
}
bool Gov::sendGovRequest(const QString &userName, const QString &gsId,
const QString &ic, const QString &rpId, const QString &dFrom,
const QString &dTo)
bool Gov::sendGovRequest(const QString &userName,
const QString &serviceInternalId, const QVariant &formModelVariant) const
{
debugFuncCall();
if (!m_govServices.contains(gsId)) {
GovService *govService = m_govServices.value(serviceInternalId, Q_NULLPTR);
if (govService == Q_NULLPTR) {
logErrorNL("Cannot access gov service '%s'.",
serviceInternalId.toUtf8().constData());
Q_ASSERT(0);
return false;
}
QString service = tr("Request: %1").
arg(m_govServices.value(gsId)->serviceFullName());
service.append("\n");
service.append(tr("Recipient: %1").
arg(m_govServices.value(gsId)->serviceGovName()));
int msgResponse = Dialogues::message(Dialogues::QUESTION,
tr("Send GOV request"),
tr("Do you want to send the GOV request to databox '%1'?").
arg(m_govServices.value(gsId)->serviceDbId()),
service,
Dialogues::NO | Dialogues::YES, Dialogues::NO);
if (msgResponse == Dialogues::NO) {
const GovFormListModel *formModel =
GovFormListModel::fromVariant(formModelVariant);
if (Q_UNLIKELY(formModel == Q_NULLPTR)) {
logErrorNL("%s", "Cannot access gov form model.");
Q_ASSERT(0);
return false;
}
{
QString service = tr("Request: %1").arg(govService->fullName());
service.append("\n");
service.append(tr("Recipient: %1").arg(govService->instituteName()));
int msgResponse = Dialogues::message(Dialogues::QUESTION,
tr("Send GOV request"),
tr("Do you want to send the GOV request to data box '%1'?").
arg(govService->boxId()), service,
Dialogues::NO | Dialogues::YES, Dialogues::NO);
if (msgResponse == Dialogues::NO) {
return false;
}
}
if (GlobInstcs::accountDbPtr == Q_NULLPTR) {
return false;
}
const Isds::DbOwnerInfo dbOwnerInfo =
GlobInstcs::accountDbPtr->getOwnerInfo(userName);
/* Set message content according to model data. */
foreach (const RequiredInput &ri, formModel->allEntries()) {
if (!govService->setRequiredField(ri.key, ri.val)) {
logWarningNL("The gov service '%s' does not accept the key '%s'.",
govService->internalId().toUtf8().constData(),
ri.key.toUtf8().constData());
}
}
if (!govService->haveAllRequiredFields()) {
logErrorNL("The gov service '%s' is missing some required data.",
govService->internalId().toUtf8().constData());
return false;
}
XmlRequiredFileds reqFileds;
reqFileds.ic = ic;
reqFileds.rpId = rpId;
reqFileds.from = dFrom;
reqFileds.to = dTo;
const Isds::DbOwnerInfo dbOwnerInfo(
GlobInstcs::accountDbPtr->getOwnerInfo(userName));
const Isds::Message msg = m_govServices.value(gsId)->createMessage(
dbOwnerInfo, reqFileds);
const Isds::Message msg(govService->dataMessage(dbOwnerInfo));
if (Q_UNLIKELY(msg.isNull())) {
Q_ASSERT(0);
return false;
}
if (Q_NULLPTR != m_isds) {
return m_isds->sendGovRequest(userName, msg);
......
......@@ -81,16 +81,13 @@ public:
* @brief Create and send gov service request.
*
* @param[in] userName Account user name.
* @param[in] gsId Gov service ID.
* @param[in] ic Subjec IC identifier.
* @param[in] rpId Drive license ID.
* @param[in] dFrom Date From.
* @param[in] dTo Date To.
* @param[in] serviceInternalId Internal service identifier.
* @param[in] formModelVariant QVariant holding gov form model to be set.
*/
Q_INVOKABLE
bool sendGovRequest(const QString &userName, const QString &gsId,
const QString &ic, const QString &rpId, const QString &dFrom,
const QString &dTo);
bool sendGovRequest(const QString &userName,
const QString &serviceInternalId,
const QVariant &formModelVariant) const;
private:
QMap<QString, GovService *> m_govServices; /*!< Holds pointers to Gov services. */
......
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