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

Listing only e-gov services which can actually be sent from respective boxes.

parent 65a211b2
......@@ -40,7 +40,7 @@ Component {
property string gsInternIdSelected
Component.onCompleted: {
gov.loadServicesToModel(govServiceModel)
gov.loadServicesToModel(userName, govServiceModel)
proxyGovServiceModel.setSourceModel(govServiceModel)
}
......
......@@ -24,6 +24,7 @@
#include <QQmlEngine> /* qmlRegisterType */
#include "src/datovka_shared/gov_services/model/gov_service_list_model.h"
#include "src/datovka_shared/gov_services/service/gov_service.h"
#include "src/global.h"
GovServiceListModel::Entry::Entry(const Entry &sme)
......@@ -54,31 +55,16 @@ const QString &GovServiceListModel::Entry::srvcFullName(void) const
return m_srvcFullName;
}
void GovServiceListModel::Entry::setSrvcFullName(const QString &fn)
{
m_srvcFullName = fn;
}
const QString &GovServiceListModel::Entry::instName(void) const
{
return m_instName;
}
void GovServiceListModel::Entry::setInstName(const QString &in)
{
m_instName = in;
}
const QString &GovServiceListModel::Entry::srvcBoxId(void) const
{
return m_srvcBoxId;
}
void GovServiceListModel::Entry::setSrvcBoxId(const QString &bi)
{
m_srvcBoxId = bi;
}
void GovServiceListModel::declareQML(void)
{
qmlRegisterType<GovServiceListModel>("cz.nic.mobileDatovka.models", 1, 0, "GovServiceListModel");
......@@ -158,10 +144,16 @@ Qt::ItemFlags GovServiceListModel::flags(const QModelIndex &index) const
return QAbstractListModel::flags(index);
}
void GovServiceListModel::appendEntry(const Entry &entry)
void GovServiceListModel::appendService(const Gov::Service *gs)
{
if (Q_UNLIKELY(gs == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_services.append(entry);
m_services.append(Entry(gs->internalId(), gs->fullName(),
gs->instituteName(), gs->boxId()));
endInsertRows();
}
......
......@@ -26,6 +26,10 @@
#include <QAbstractListModel>
#include <QString>
namespace Gov {
class Service; /* Forward declaration. */
}
/*!
* @brief Holds information about available gov services.
*/
......@@ -44,11 +48,8 @@ public:
const QString &srvcInternId(void) const;
const QString &srvcFullName(void) const;
void setSrvcFullName(const QString &fn);
const QString &instName(void) const;
void setInstName(const QString &in);
const QString &srvcBoxId(void) const;
void setSrvcBoxId(const QString &bi);
private:
QString m_srvcInternId; /*!< Short unique internal gov service identifier. */
......@@ -135,11 +136,11 @@ public:
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
/*!
* @brief Appends entry line to model.
* @brief Appends service to model.
*
* @param[in] entry Entry to append to model data.
* @param[in] gg E-gov service data.
*/
void appendEntry(const Entry &entry);
void appendService(const Gov::Service *gs);
/*!
* @brief Clears the model.
......
......@@ -216,7 +216,8 @@ void GovWrapper::clearGovServices(void)
m_govServices.clear();
}
void GovWrapper::loadServicesToModel(const QVariant &srvcModelVariant) const
void GovWrapper::loadServicesToModel(const QString &userName,
const QVariant &srvcModelVariant) const
{
debugFuncCall();
......@@ -228,15 +229,35 @@ void GovWrapper::loadServicesToModel(const QVariant &srvcModelVariant) const
return;
}
const Isds::DbOwnerInfo dbOwnerInfo(
GlobInstcs::accountDbPtr->getOwnerInfo(userName));
srvcModel->clearAll();
if ((*GlobInstcs::acntMapPtr)[userName].isTestAccount()) {
/*
* The e-gov services aren't available in the testing
* environment.
*/
logWarningNL("%s",
"Cannot access e-gov services from an testing account.");
return;
}
foreach (const QString &key, m_govServices.keys()) {
srvcModel->appendEntry(GovServiceListModel::Entry(
m_govServices.value(key)->internalId(),
m_govServices.value(key)->fullName(),
m_govServices.value(key)->instituteName(),
m_govServices.value(key)->boxId()
));
Gov::Service *gs = m_govServices.value(key);
if (Q_UNLIKELY(gs == Q_NULLPTR)) {
Q_ASSERT(0);
continue;
}
/* Enlist only services which can be used. */
if (gs->canSend(dbOwnerInfo.dbType())) {
srvcModel->appendService(gs);
} else {
logInfo("User '%s' cannot use the e-gov service '%s'.",
userName.toUtf8().constData(),
gs->internalId().toUtf8().constData());
}
}
}
......
......@@ -67,10 +67,12 @@ public:
/*!
* @brief Load Gov services into QML.
*
* @param[in] userName Account login.
* @param[in,out] srvcModelVariant QVariant holding gov model.
*/
Q_INVOKABLE
void loadServicesToModel(const QVariant &srvcModelVariant) const;
void loadServicesToModel(const QString &userName,
const QVariant &srvcModelVariant) const;
/*!
* @brief Load gof form data into QML model.
......@@ -97,6 +99,6 @@ public:
const QVariant &formModelVariant) const;
private:
QMap<QString, Gov::Service *> m_govServices; /*!< Holds pointers to Gov services. */
QMap<QString, Gov::Service *> m_govServices; /*!< Holds pointers to all available Gov services. */
IsdsWrapper *m_isds; /*!< Pointer to isds wrapper. */
};
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