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

Added Gov::Service::createNew() in order to create local working copies.

parent ea64494f
......@@ -60,6 +60,11 @@ Gov::SrvcMvCrrVbh::SrvcMvCrrVbh(void)
{
}
Gov::Service *Gov::SrvcMvCrrVbh::createNew(void) const
{
return new (std::nothrow) SrvcMvCrrVbh;
}
const QString &Gov::SrvcMvCrrVbh::internalId(void) const
{
static const QString shortName("SrvcMvCrrVbh");
......
......@@ -46,6 +46,9 @@ namespace Gov {
*/
SrvcMvCrrVbh(void);
virtual
Service *createNew(void) const Q_DECL_OVERRIDE;
virtual
const QString &internalId(void) const Q_DECL_OVERRIDE;
......
......@@ -494,6 +494,11 @@ Gov::SrvcMvIrVp::SrvcMvIrVp(void)
{
}
Gov::Service *Gov::SrvcMvIrVp::createNew(void) const
{
return new (std::nothrow) SrvcMvIrVp;
}
const QString &Gov::SrvcMvIrVp::internalId(void) const
{
static const QString shortName("SrvcMvIrVp");
......
......@@ -45,6 +45,9 @@ namespace Gov {
*/
SrvcMvIrVp(void);
virtual
Service *createNew(void) const Q_DECL_OVERRIDE;
virtual
const QString &internalId(void) const Q_DECL_OVERRIDE;
......
......@@ -72,6 +72,11 @@ Gov::SrvcMvRtVt::SrvcMvRtVt(void)
{
}
Gov::Service *Gov::SrvcMvRtVt::createNew(void) const
{
return new (std::nothrow) SrvcMvRtVt;
}
const QString &Gov::SrvcMvRtVt::internalId(void) const
{
static const QString shortName("SrvcMvRtVt");
......
......@@ -45,6 +45,9 @@ namespace Gov {
*/
SrvcMvRtVt(void);
virtual
Service *createNew(void) const Q_DECL_OVERRIDE;
virtual
const QString &internalId(void) const Q_DECL_OVERRIDE;
......
......@@ -499,6 +499,11 @@ Gov::SrvcMvRtpoVt::SrvcMvRtpoVt(void)
{
}
Gov::Service *Gov::SrvcMvRtpoVt::createNew(void) const
{
return new (std::nothrow) SrvcMvRtpoVt;
}
const QString &Gov::SrvcMvRtpoVt::internalId(void) const
{
static const QString shortName("SrvcMvRtpoVt");
......
......@@ -45,6 +45,9 @@ namespace Gov {
*/
SrvcMvRtpoVt(void);
virtual
Service *createNew(void) const Q_DECL_OVERRIDE;
virtual
const QString &internalId(void) const Q_DECL_OVERRIDE;
......
......@@ -495,6 +495,11 @@ Gov::SrvcMvSkdVp::SrvcMvSkdVp(void)
{
}
Gov::Service *Gov::SrvcMvSkdVp::createNew(void) const
{
return new (std::nothrow) SrvcMvSkdVp;
}
const QString &Gov::SrvcMvSkdVp::internalId(void) const
{
static const QString shortName("SrvcMvSkdVp");
......
......@@ -45,6 +45,9 @@ namespace Gov {
*/
SrvcMvSkdVp(void);
virtual
Service *createNew(void) const Q_DECL_OVERRIDE;
virtual
const QString &internalId(void) const Q_DECL_OVERRIDE;
......
......@@ -528,6 +528,11 @@ Gov::SrvcMvVrVp::SrvcMvVrVp(void)
{
}
Gov::Service *Gov::SrvcMvVrVp::createNew(void) const
{
return new (std::nothrow) SrvcMvVrVp;
}
const QString &Gov::SrvcMvVrVp::internalId(void) const
{
static const QString shortName("SrvcMvVrVp");
......
......@@ -45,6 +45,9 @@ namespace Gov {
*/
SrvcMvVrVp(void);
virtual
Service *createNew(void) const Q_DECL_OVERRIDE;
virtual
const QString &internalId(void) const Q_DECL_OVERRIDE;
......
......@@ -494,6 +494,11 @@ Gov::SrvcMvZrVp::SrvcMvZrVp(void)
{
}
Gov::Service *Gov::SrvcMvZrVp::createNew(void) const
{
return new (std::nothrow) SrvcMvZrVp;
}
const QString &Gov::SrvcMvZrVp::internalId(void) const
{
static const QString shortName("SrvcMvZrVp");
......
......@@ -45,6 +45,9 @@ namespace Gov {
*/
SrvcMvZrVp(void);
virtual
Service *createNew(void) const Q_DECL_OVERRIDE;
virtual
const QString &internalId(void) const Q_DECL_OVERRIDE;
......
......@@ -64,7 +64,7 @@ namespace Gov {
};
/*!
* @brief Encapsulates the general gov service request.
* @brief Encapsulates the general e-gov service request.
*/
class Service {
public:
......@@ -74,6 +74,14 @@ namespace Gov {
virtual
~Service(void);
/*!
* @brief Allocate a new service object.
*
* @return Newly allocated object or a Q_NULLPTR on any error.
*/
virtual
Service *createNew(void) const = 0;
/*!
* @brief Return application-internal gov service identifier.
*
......
......@@ -61,6 +61,11 @@ Gov::SrvcSzrRobVu::SrvcSzrRobVu(void)
{
}
Gov::Service *Gov::SrvcSzrRobVu::createNew(void) const
{
return new (std::nothrow) SrvcSzrRobVu;
}
const QString &Gov::SrvcSzrRobVu::internalId(void) const
{
static const QString shortName("SrvcSzrRobVu");
......
......@@ -45,6 +45,9 @@ namespace Gov {
*/
SrvcSzrRobVu(void);
virtual
Service *createNew(void) const Q_DECL_OVERRIDE;
virtual
const QString &internalId(void) const Q_DECL_OVERRIDE;
......
......@@ -68,6 +68,11 @@ Gov::SrvcSzrRobVvu::SrvcSzrRobVvu(void)
{
}
Gov::Service *Gov::SrvcSzrRobVvu::createNew(void) const
{
return new (std::nothrow) SrvcSzrRobVvu;
}
const QString &Gov::SrvcSzrRobVvu::internalId(void) const
{
static const QString shortName("SrvcSzrRobVvu");
......
......@@ -46,6 +46,9 @@ namespace Gov {
*/
SrvcSzrRobVvu(void);
virtual
Service *createNew(void) const Q_DECL_OVERRIDE;
virtual
const QString &internalId(void) const Q_DECL_OVERRIDE;
......
......@@ -80,6 +80,11 @@ Gov::SrvcSzrRosVv::SrvcSzrRosVv(void)
{
}
Gov::Service *Gov::SrvcSzrRosVv::createNew(void) const
{
return new (std::nothrow) SrvcSzrRosVv;
}
const QString &Gov::SrvcSzrRosVv::internalId(void) const
{
static const QString shortName("SrvcSzrRosVv");
......
......@@ -45,6 +45,9 @@ namespace Gov {
*/
SrvcSzrRosVv(void);
virtual
Service *createNew(void) const Q_DECL_OVERRIDE;
virtual
const QString &internalId(void) const Q_DECL_OVERRIDE;
......
......@@ -21,6 +21,8 @@
* the two.
*/
#include <QScopedPointer>
#include "src/datovka_shared/gov_services/model/gov_form_list_model.h"
#include "src/datovka_shared/gov_services/model/gov_service_list_model.h"
#include "src/datovka_shared/gov_services/service/gov_mv_crr_vbh.h"
......@@ -245,18 +247,18 @@ void GovWrapper::loadServicesToModel(const QString &userName,
}
foreach (const QString &key, m_govServices.keys()) {
Gov::Service *gs = m_govServices.value(key);
if (Q_UNLIKELY(gs == Q_NULLPTR)) {
const Gov::Service *cgs = m_govServices.value(key);
if (Q_UNLIKELY(cgs == Q_NULLPTR)) {
Q_ASSERT(0);
continue;
}
/* Enlist only services which can be used. */
if (gs->canSend(dbOwnerInfo.dbType())) {
srvcModel->appendService(gs);
if (cgs->canSend(dbOwnerInfo.dbType())) {
srvcModel->appendService(cgs);
} else {
logInfo("User '%s' cannot use the e-gov service '%s'.",
userName.toUtf8().constData(),
gs->internalId().toUtf8().constData());
cgs->internalId().toUtf8().constData());
}
}
}
......@@ -268,8 +270,8 @@ void GovWrapper::loadFormToModel(const QString &userName,
Q_UNUSED(userName); /* Currently unused. */
Gov::Service *govSrvc = m_govServices.value(serviceInternalId, Q_NULLPTR);
if (Q_UNLIKELY(govSrvc == Q_NULLPTR)) {
const Gov::Service *cgs = m_govServices.value(serviceInternalId, Q_NULLPTR);
if (Q_UNLIKELY(cgs == Q_NULLPTR)) {
logErrorNL("Cannot access gov service '%s'.",
serviceInternalId.toUtf8().constData());
Q_ASSERT(0);
......@@ -284,7 +286,7 @@ void GovWrapper::loadFormToModel(const QString &userName,
return;
}
formModel->setEntries(govSrvc->requiredFields());
formModel->setEntries(cgs->requiredFields());
}
bool GovWrapper::sendGovRequest(const QString &userName,
......@@ -292,13 +294,18 @@ bool GovWrapper::sendGovRequest(const QString &userName,
{
debugFuncCall();
Gov::Service *govSrvc = m_govServices.value(serviceInternalId, Q_NULLPTR);
if (govSrvc == Q_NULLPTR) {
const Gov::Service *cgs = m_govServices.value(serviceInternalId, Q_NULLPTR);
if (cgs == Q_NULLPTR) {
logErrorNL("Cannot access 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);
......@@ -309,15 +316,14 @@ bool GovWrapper::sendGovRequest(const QString &userName,
}
{
QString service = tr("Request: %1").arg(govSrvc->fullName());
QString service = tr("Request: %1").arg(gs->fullName());
service.append("\n");
service.append(tr("Recipient: %1").arg(govSrvc->instituteName()));
service.append(tr("Recipient: %1").arg(gs->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(govSrvc->boxId()), service,
Dialogues::NO | Dialogues::YES, Dialogues::NO);
tr("Send e-gov request"),
tr("Do you want to send the e-gov request to data box '%1'?").arg(gs->boxId()),
service, Dialogues::NO | Dialogues::YES, Dialogues::NO);
if (msgResponse == Dialogues::NO) {
return false;
}
......@@ -329,22 +335,22 @@ bool GovWrapper::sendGovRequest(const QString &userName,
/* Set message content according to model data. */
foreach (const Gov::RequiredInput &ri, formModel->allEntries()) {
if (!govSrvc->setRequiredField(ri.key, ri.val)) {
if (!gs->setRequiredField(ri.key, ri.val)) {
logWarningNL("The gov service '%s' does not accept the key '%s'.",
govSrvc->internalId().toUtf8().constData(),
gs->internalId().toUtf8().constData(),
ri.key.toUtf8().constData());
}
}
if (!govSrvc->haveAllMandatoryFields()) {
if (!gs->haveAllMandatoryFields()) {
logErrorNL("The gov service '%s' is missing some mandatory data.",
govSrvc->internalId().toUtf8().constData());
gs->internalId().toUtf8().constData());
return false;
}
const Isds::DbOwnerInfo dbOwnerInfo(
GlobInstcs::accountDbPtr->getOwnerInfo(userName));
const Isds::Message msg(govSrvc->dataMessage(dbOwnerInfo));
const Isds::Message msg(gs->dataMessage(dbOwnerInfo));
if (Q_UNLIKELY(msg.isNull())) {
Q_ASSERT(0);
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