/* * 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 . * * 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/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" //#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_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_mv_rtpo_vt.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/isds/message_interface.h" #include "src/datovka_shared/log/log.h" #include "src/datovka_shared/log/memory_log.h" #include "src/dialogues/dialogues.h" #include "src/global.h" #include "src/gov_wrapper.h" #include "src/models/accountmodel.h" #include "src/net/isds_wrapper.h" #include "src/sqlite/account_db.h" GovWrapper::GovWrapper(IsdsWrapper *isds, QObject *parent) : QObject(parent), m_govServices(), m_isds(isds) { initGovServices(); } void GovWrapper::deleteGovServices(void) { debugFuncCall(); QStringList keys = m_govServices.keys(); foreach (const QString &key, keys) { delete m_govServices.take(key); } } void GovWrapper::initGovServices(void) { debugFuncCall(); m_govServices.clear(); Gov::Service *gs; // /* Výpis z Registru obyvatel */ // GovSzrRobVu *gs1 = new GovSzrRobVu(); // m_govServices.insert(gs1->serviceId(), gs1); // /* Výpis o využití údajů z registru obyvatel */ // GovSzrRobVvu *gs2 = new GovSzrRobVvu(); // m_govServices.insert(gs2->serviceId(), gs2); // /* Veřejný výpis z registru osob */ // GovSzrRosVv *gs3 = new GovSzrRosVv(); // m_govServices.insert(gs3->serviceId(), gs3); /* Výpis bodového hodnocení z Centrálního registru řidičů */ gs = new (std::nothrow) Gov::SrvcMvCrrVbh; if (gs != Q_NULLPTR) { const QString &key(gs->internalId()); if (!m_govServices.contains(key)) { m_govServices.insert(key, gs); } else { logError( "Key '%s' already exists in gov services container.", key.toUtf8().constData()); } } // /* Výpis z Rejstříku trestů právnických osob */ // GovMvRtpoVt *gs5 = new GovMvRtpoVt(); // m_govServices.insert(gs5->serviceId(), gs5); /* Výpis z Rejstříku trestů */ gs = new (std::nothrow) Gov::SrvcMvRtVt; if (gs != Q_NULLPTR) { const QString &key(gs->internalId()); if (!m_govServices.contains(key)) { m_govServices.insert(key, gs); } else { logError( "Key '%s' already exists in gov services container.", key.toUtf8().constData()); } } // /* Výpis z živnostenského rejstříku */ // GovMvZrVp *gs7 = new GovMvZrVp(); // m_govServices.insert(gs7->serviceId(), gs7); // /* Výpis z veřejného rejstříku */ // GovMvVrVp *gs8 = new GovMvVrVp(); // m_govServices.insert(gs8->serviceId(), gs8); // /* Výpis z insolvenčního rejstříku */ // GovMvIrVp *gs9 = new GovMvIrVp(); // m_govServices.insert(gs9->serviceId(), gs9); // /* Výpis ze seznamu kvalifikovaných dodavatelů */ // GovMvSkdVp *gs10 = new GovMvSkdVp(); // m_govServices.insert(gs10->serviceId(), gs10); } void GovWrapper::loadServicesToModel(const QVariant &srvcModelVariant) const { debugFuncCall(); GovServiceListModel *srvcModel = GovServiceListModel::fromVariant(srvcModelVariant); if (Q_UNLIKELY(srvcModel == Q_NULLPTR)) { logErrorNL("%s", "Cannot access gov services model."); Q_ASSERT(0); return; } srvcModel->clearAll(); 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() )); } } void GovWrapper::loadFormToModel(const QString &userName, const QString &serviceInternalId, const QVariant &formModelVariant) const { debugFuncCall(); Q_UNUSED(userName); /* Currently unused. */ Gov::Service *govSrvc = m_govServices.value(serviceInternalId, Q_NULLPTR); if (Q_UNLIKELY(govSrvc == Q_NULLPTR)) { logErrorNL("Cannot access gov service '%s'.", serviceInternalId.toUtf8().constData()); Q_ASSERT(0); 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(govSrvc->requiredFields()); } bool GovWrapper::sendGovRequest(const QString &userName, const QString &serviceInternalId, const QVariant &formModelVariant) const { debugFuncCall(); Gov::Service *govSrvc = m_govServices.value(serviceInternalId, Q_NULLPTR); if (govSrvc == Q_NULLPTR) { logErrorNL("Cannot access gov service '%s'.", serviceInternalId.toUtf8().constData()); Q_ASSERT(0); return false; } 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(govSrvc->fullName()); service.append("\n"); service.append(tr("Recipient: %1").arg(govSrvc->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); if (msgResponse == Dialogues::NO) { return false; } } if (GlobInstcs::accountDbPtr == Q_NULLPTR) { return false; } /* Set message content according to model data. */ foreach (const Gov::RequiredInput &ri, formModel->allEntries()) { if (!govSrvc->setRequiredField(ri.key, ri.val)) { logWarningNL("The gov service '%s' does not accept the key '%s'.", govSrvc->internalId().toUtf8().constData(), ri.key.toUtf8().constData()); } } if (!govSrvc->haveAllMandatoryFields()) { logErrorNL("The gov service '%s' is missing some mandatory data.", govSrvc->internalId().toUtf8().constData()); return false; } const Isds::DbOwnerInfo dbOwnerInfo( GlobInstcs::accountDbPtr->getOwnerInfo(userName)); const Isds::Message msg(govSrvc->dataMessage(dbOwnerInfo)); if (Q_UNLIKELY(msg.isNull())) { Q_ASSERT(0); return false; } if (Q_NULLPTR != m_isds) { return m_isds->sendGovRequest(userName, msg); } return false; }