Commit 0c5d654c authored by Karel Slaný's avatar Karel Slaný
Browse files

Pulled changes of shared code and applied them on the application code.

Also removed some unnecessary methods.
parent 7a8909d9
......@@ -101,6 +101,7 @@ SOURCES += \
src/datovka_shared/gov_services/service/gov_mv_zr_vp.cpp \
src/datovka_shared/gov_services/service/gov_service_form_field.cpp \
src/datovka_shared/gov_services/service/gov_service.cpp \
src/datovka_shared/gov_services/service/gov_services_all.cpp \
src/datovka_shared/gov_services/service/gov_szr_rob_vu.cpp \
src/datovka_shared/gov_services/service/gov_szr_rob_vvu.cpp \
src/datovka_shared/gov_services/service/gov_szr_ros_vv.cpp \
......@@ -223,6 +224,7 @@ HEADERS += \
src/datovka_shared/gov_services/service/gov_mv_zr_vp.h \
src/datovka_shared/gov_services/service/gov_service_form_field.h \
src/datovka_shared/gov_services/service/gov_service.h \
src/datovka_shared/gov_services/service/gov_services_all.h \
src/datovka_shared/gov_services/service/gov_szr_rob_vu.h \
src/datovka_shared/gov_services/service/gov_szr_rob_vvu.h \
src/datovka_shared/gov_services/service/gov_szr_ros_vv.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 "src/datovka_shared/gov_services/service/gov_mv_crr_vbh.h"
#include "src/datovka_shared/gov_services/service/gov_mv_ir_vp.h"
#include "src/datovka_shared/gov_services/service/gov_mv_rt_vt.h"
#include "src/datovka_shared/gov_services/service/gov_mv_rtpo_vt.h"
#include "src/datovka_shared/gov_services/service/gov_mv_skd_vp.h"
#include "src/datovka_shared/gov_services/service/gov_mv_vr_vp.h"
#include "src/datovka_shared/gov_services/service/gov_mv_zr_vp.h"
#include "src/datovka_shared/gov_services/service/gov_service.h"
#include "src/datovka_shared/gov_services/service/gov_services_all.h"
#include "src/datovka_shared/gov_services/service/gov_szr_rob_vu.h"
#include "src/datovka_shared/gov_services/service/gov_szr_rob_vvu.h"
#include "src/datovka_shared/gov_services/service/gov_szr_ros_vv.h"
#include "src/datovka_shared/log/log.h"
/*!
* @brief Add a newly allocated service into the service container.
*
* @note The service object is freed when it cannot be added into the container.
*
* @param[in] map Service container.
* @param[in] gs Newly allocated service object.
*/
static
void insertService(QMap<QString, const Gov::Service *> &map, Gov::Service *gs)
{
if (Q_UNLIKELY(gs == Q_NULLPTR)) {
return;
}
const QString &key(gs->internalId());
if (!map.contains(key)) {
map.insert(key, gs);
} else {
logError("Key '%s' already exists in e-gov service container.",
key.toUtf8().constData());
delete gs;
}
}
QMap<QString, const Gov::Service *> Gov::allServiceMap(void)
{
QMap<QString, const Service *> map;
/* Výpis bodového hodnocení z Centrálního registru řidičů */
insertService(map, new (std::nothrow) SrvcMvCrrVbh);
/* Výpis z insolvenčního rejstříku */
insertService(map, new (std::nothrow) SrvcMvIrVp);
/* Výpis z Rejstříku trestů */
insertService(map, new (std::nothrow) SrvcMvRtVt);
/* Výpis z Rejstříku trestů právnických osob */
insertService(map, new (std::nothrow) SrvcMvRtpoVt);
/* Výpis ze seznamu kvalifikovaných dodavatelů */
insertService(map, new (std::nothrow) SrvcMvSkdVp);
/* Výpis z veřejného rejstříku */
insertService(map, new (std::nothrow) SrvcMvVrVp);
/* Výpis z živnostenského rejstříku */
insertService(map, new (std::nothrow) SrvcMvZrVp);
/* Výpis z Registru obyvatel */
insertService(map, new (std::nothrow) SrvcSzrRobVu);
/* Výpis o využití údajů z registru obyvatel */
insertService(map, new (std::nothrow) SrvcSzrRobVvu);
/* Veřejný výpis z registru osob */
insertService(map, new (std::nothrow) SrvcSzrRosVv);
return map;
}
void Gov::clearServiceMap(QMap<QString, const Service *> &map)
{
foreach (const Service *gs, map.values()) {
delete const_cast<Service *>(gs);
}
map.clear();
}
/*
* 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 <QMap>
#include <QString>
namespace Gov {
class Service; /* Forward declaration. */
/*!
* @brief Obtain container containing all available services.
*
* @note You must explicitly delete the services which the pointers
* point to.
*
* @return Map of all available services. Keys are the internal ids.
* Values are pointers to newly allocated services.
*/
QMap<QString, const Service *> allServiceMap(void);
/*!
* @brief Clear map content and delete objects which the pointers
* point to.
*/
void clearServiceMap(QMap<QString, const Service *> &map);
}
......@@ -8,7 +8,7 @@
*
* 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
* 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
......@@ -80,7 +80,7 @@ bool SQLiteTbl::existsInDb(const QSqlDatabase &db) const
return false;
}
bool SQLiteTbl::createEmpty(QSqlDatabase &db) const
bool SQLiteTbl::createEmpty(const QSqlDatabase &db) const
{
if (!db.isValid()) {
Q_ASSERT(0);
......
......@@ -8,7 +8,7 @@
*
* 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
* 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
......@@ -82,7 +82,7 @@ public:
* @param[in] db Database.
* @return True if table in database was successfully created.
*/
bool createEmpty(QSqlDatabase &db) const;
bool createEmpty(const QSqlDatabase &db) const;
/*!
* @brief Reloads descriptions according to selected localisation.
......
......@@ -23,17 +23,8 @@
#include <QScopedPointer>
#include "src/datovka_shared/gov_services/service/gov_mv_crr_vbh.h"
#include "src/datovka_shared/gov_services/service/gov_mv_ir_vp.h"
#include "src/datovka_shared/gov_services/service/gov_mv_rt_vt.h"
#include "src/datovka_shared/gov_services/service/gov_mv_rtpo_vt.h"
#include "src/datovka_shared/gov_services/service/gov_mv_skd_vp.h"
#include "src/datovka_shared/gov_services/service/gov_mv_vr_vp.h"
#include "src/datovka_shared/gov_services/service/gov_mv_zr_vp.h"
#include "src/datovka_shared/gov_services/service/gov_service.h"
#include "src/datovka_shared/gov_services/service/gov_szr_rob_vu.h"
#include "src/datovka_shared/gov_services/service/gov_szr_rob_vvu.h"
#include "src/datovka_shared/gov_services/service/gov_szr_ros_vv.h"
#include "src/datovka_shared/gov_services/service/gov_services_all.h"
#include "src/datovka_shared/isds/message_interface.h"
#include "src/datovka_shared/log/log.h"
#include "src/datovka_shared/log/memory_log.h"
......@@ -51,88 +42,12 @@ GovWrapper::GovWrapper(IsdsWrapper *isds, QObject *parent)
m_govServices(),
m_isds(isds)
{
initGovServices();
m_govServices = Gov::allServiceMap();
}
GovWrapper::~GovWrapper(void)
{
clearGovServices();
}
/*!
* @brief Add a newly allocated service into the service container.
*
* @note The service object is freed when it cannot be added into the container.
*
* @param[in] map Service container.
* @param[in] gs Newly allocated service object.
*/
static
void insertService(QMap<QString, const Gov::Service *> &map,
Gov::Service *gs)
{
if (Q_UNLIKELY(gs == Q_NULLPTR)) {
return;
}
const QString &key(gs->internalId());
if (!map.contains(key)) {
map.insert(key, gs);
} else {
logError("Key '%s' already exists in gov service container.",
key.toUtf8().constData());
delete gs;
}
}
void GovWrapper::initGovServices(void)
{
debugFuncCall();
clearGovServices();
/* Výpis bodového hodnocení z Centrálního registru řidičů */
insertService(m_govServices, new (std::nothrow) Gov::SrvcMvCrrVbh);
/* Výpis z insolvenčního rejstříku */
insertService(m_govServices, new (std::nothrow) Gov::SrvcMvIrVp);
/* Výpis z Rejstříku trestů */
insertService(m_govServices, new (std::nothrow) Gov::SrvcMvRtVt);
/* Výpis z Rejstříku trestů právnických osob */
insertService(m_govServices, new (std::nothrow) Gov::SrvcMvRtpoVt);
/* Výpis ze seznamu kvalifikovaných dodavatelů */
insertService(m_govServices, new (std::nothrow) Gov::SrvcMvSkdVp);
/* Výpis z veřejného rejstříku */
insertService(m_govServices, new (std::nothrow) Gov::SrvcMvVrVp);
/* Výpis z živnostenského rejstříku */
insertService(m_govServices, new (std::nothrow) Gov::SrvcMvZrVp);
/* Výpis z Registru obyvatel */
insertService(m_govServices, new (std::nothrow) Gov::SrvcSzrRobVu);
/* Výpis o využití údajů z registru obyvatel */
insertService(m_govServices, new (std::nothrow) Gov::SrvcSzrRobVvu);
/* Veřejný výpis z registru osob */
insertService(m_govServices, new (std::nothrow) Gov::SrvcSzrRosVv);
}
void GovWrapper::clearGovServices(void)
{
/* This log can cause crash when application is shutdown.
* Log device can be deallocate earlier than GovWrapper object.
*/
//debugFuncCall();
foreach (const Gov::Service *gs, m_govServices.values()) {
delete const_cast<Gov::Service *>(gs);
}
m_govServices.clear();
Gov::clearServiceMap(m_govServices);
}
void GovWrapper::loadServicesToModel(const QString &userName,
......
......@@ -51,19 +51,9 @@ public:
/*!
* @brief Destructor.
*/
virtual
~GovWrapper(void);
/*!
* @brief Init all Gov services and insert to map.
*/
void initGovServices(void);
/*!
* @brief Remove all Gov services from map and delete their objects.
*/
Q_INVOKABLE
void clearGovServices(void);
/*!
* @brief Load Gov services into QML.
*
......
Supports Markdown
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