gov_mv_rt_vt.cpp 9.62 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2019 CZ.NIC
3 4 5 6 7 8 9 10
 *
 * 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
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 13 14
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23
 *
 * 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.
 */

24 25
#include <QDate>

26 27
#include "src/datovka_shared/gov_services/service/gov_mv_rt_vt.h"

Karel Slaný's avatar
Karel Slaný committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
static const char xml_template[] =
"<?xml version='1.0' encoding='utf-8'?>"
"<d:root xmlns:d=\"http://software602.cz/sample\" "
  "xmlns:date=\"http://exslt.org/dates-and-times\" "
  "xmlns:rs=\"http://portal.gov.cz/rejstriky/ISRS/1.2/\" ancestor_id=\"\" "
  "folder_id=\"\" formdata_id=\"\" fsuser_id=\"\" institute_type=\"\" "
  "ldapPass=\"\" nazev=\"\" page=\"0\" page_id=\"\" query_seq=\"1\" "
  "register=\"262\" retry=\"0\" seq=\"\" templateVersion_id=\"\" url=\"\" "
  "url_release=\"\" user_name=\"\" version=\"1.4o\" xml:lang=\"cs\">""\n"
"  <d:gw_sn/>""\n"
"  <d:gw_form_name/>""\n"
"  <d:stav_form/>""\n"
"  <d:stav_rizeni>""\n"
"    <d:vydano>0</d:vydano>""\n"
"  </d:stav_rizeni>""\n"
"  <d:requestZadostVM>""\n"
"    <zvm:czechPointUrl xmlns:zvm=\"http://fo.rt.cleverlance.com/zadostVM_2.0\"/>""\n"
"    <zvm:vydejniMisto xmlns:zvm=\"http://fo.rt.cleverlance.com/zadostVM_2.0\"/>""\n"
"    <zvm:X509CertificateVM xmlns:zvm=\"http://fo.rt.cleverlance.com/zadostVM_2.0\" KeyName=\"\"/>""\n"
"    <zvm:zadostVM xmlns:zvm=\"http://fo.rt.cleverlance.com/zadostVM_2.0\" identZadost=\"\" vystupDokument=\"V\">""\n"
"      <zvm:ucel zkratka=\"BEZUH\"/>""\n"
"      <zvm:mail/>""\n"
"      <zvm:osoba rozlisovatJmPr=\"true\">""\n"
"        <com:jmeno xmlns:com=\"http://fo.rt.cleverlance.com/commons_2.0\">__repl_NAME__</com:jmeno>""\n"
"        <com:prijmeniRodne xmlns:com=\"http://fo.rt.cleverlance.com/commons_2.0\"/>""\n"
"        <com:prijmeniNynejsi xmlns:com=\"http://fo.rt.cleverlance.com/commons_2.0\">__repl_SURNAME__</com:prijmeniNynejsi>""\n"
"        <com:datumNarozeni xmlns:com=\"http://fo.rt.cleverlance.com/commons_2.0\">""\n"
"          <com:den>__repl_BIRTH_DATE_DAY__</com:den>""\n"
"          <com:mesic>__repl_BIRTH_DATE_MONTH__</com:mesic>""\n"
"          <com:rok>__repl_BIRTH_DATE_YEAR__</com:rok>""\n"
"        </com:datumNarozeni>""\n"
"        <com:pohlavi xmlns:com=\"http://fo.rt.cleverlance.com/commons_2.0\" zkratka=\"\"/>""\n"
"        <com:rodneCislo xmlns:com=\"http://fo.rt.cleverlance.com/commons_2.0\"/>""\n"
"        <com:mistoNarozeni xmlns:com=\"http://fo.rt.cleverlance.com/commons_2.0\">""\n"
"          <com:stat zkratka=\"\">CZ</com:stat>""\n"
"          <com:okres>__repl_REGION__</com:okres>""\n"
"          <com:obec>__repl_CITY__</com:obec>""\n"
"        </com:mistoNarozeni>""\n"
"        <zvm:statniPrislusnost zkratka=\"\"/>""\n"
"        <zvm:bydlisteStPrislusnostMin zkratka=\"\"/>""\n"
"      </zvm:osoba>""\n"
"    </zvm:zadostVM>""\n"
"  </d:requestZadostVM>""\n"
"</d:root>";
72

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
#define NAME_KEY "name"
#define SURNAME_KEY "surname"
#define BIRTH_KEY "birthDate"
#define REGION_KEY "region"
#define CITY_KEY "city"

class MvRtVtData {
	Q_DECLARE_TR_FUNCTIONS(MvRtVtData)

public:
	MvRtVtData(void)
	    : m_boxName(), m_boxSurname(), m_boxBirthDate(), m_boxBirthRegion(),
	    m_boxBirthCity()
	{ }

	QList<Gov::FormField> allFields(void) const;

private:
	QString m_boxName; /*!< First name derived from box data. */
	QString m_boxSurname; /*!< Seurname derived from box data. */
	QDate m_boxBirthDate; /*!< Birth date derived from box data. */
	QString m_boxBirthRegion; /*!< Birth region. */
	QString m_boxBirthCity; /*!< Birth city. */
};

QList<Gov::FormField> MvRtVtData::allFields(void) const
{
	QList<Gov::FormField> formList;

	{
		Gov::FormField ff;
		ff.setKey(NAME_KEY);
		ff.setVal(m_boxName);
		ff.setDescr(tr("Data-box owner name"));
		//ff.setPlaceholder(QString());
		ff.setProperties(Gov::FormFieldType::PROP_MANDATORY |
		    Gov::FormFieldType::PROP_BOX_INPUT);
		formList.append(ff);
	}
	{
		Gov::FormField ff;
		ff.setKey(SURNAME_KEY);
		ff.setVal(m_boxSurname);
		ff.setDescr(tr("Data-box owner surname"));
		//ff.setPlaceholder(QString());
		ff.setProperties(Gov::FormFieldType::PROP_MANDATORY |
		    Gov::FormFieldType::PROP_BOX_INPUT);
		formList.append(ff);
	}
	{
		Gov::FormField ff;
		ff.setKey(BIRTH_KEY);
125
		ff.setVal(m_boxBirthDate.isNull() ? QString() : m_boxBirthDate.toString(GOV_DATE_FORMAT));
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
		ff.setDescr(tr("Birth date"));
		//ff.setPlaceholder(QString());
		ff.setProperties(Gov::FormFieldType::PROP_MANDATORY |
		    Gov::FormFieldType::PROP_BOX_INPUT);
		formList.append(ff);
	}
	{
		Gov::FormField ff;
		ff.setKey(REGION_KEY);
		ff.setVal(m_boxBirthRegion);
		ff.setDescr(tr("Birth region"));
		//ff.setPlaceholder(QString());
		ff.setProperties(Gov::FormFieldType::PROP_MANDATORY |
		    Gov::FormFieldType::PROP_BOX_INPUT);
		formList.append(ff);
	}
	{
		Gov::FormField ff;
		ff.setKey(CITY_KEY);
		ff.setVal(m_boxBirthCity);
		ff.setDescr(tr("City"));
		//ff.setPlaceholder(QString());
		ff.setProperties(Gov::FormFieldType::PROP_MANDATORY |
		    Gov::FormFieldType::PROP_BOX_INPUT);
		formList.append(ff);
	}

	return formList;
}

Karel Slaný's avatar
Karel Slaný committed
156
Gov::SrvcMvRtVt::SrvcMvRtVt(void)
157
    : Service()
158
{
159
	m_formFields = MvRtVtData().allFields();
160 161
}

162 163 164 165 166
Gov::Service *Gov::SrvcMvRtVt::createNew(void) const
{
	return new (std::nothrow) SrvcMvRtVt;
}

Karel Slaný's avatar
Karel Slaný committed
167
const QString &Gov::SrvcMvRtVt::internalId(void) const
168
{
Karel Slaný's avatar
Karel Slaný committed
169 170
	static const QString shortName("SrvcMvRtVt");
	return shortName;
171 172
}

Karel Slaný's avatar
Karel Slaný committed
173
const QString &Gov::SrvcMvRtVt::fullName(void) const
174
{
Karel Slaný's avatar
Karel Slaný committed
175
	static const QString fullName(tr("Printout from the criminal records"));
176
	// "Výpis z Rejstříku trestů"
Karel Slaný's avatar
Karel Slaný committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
	return fullName;
}

const QString &Gov::SrvcMvRtVt::instituteName(void) const
{
	static const QString instituteName(GOV_MV_FULL_NAME);
	return instituteName;
}

const QString &Gov::SrvcMvRtVt::boxId(void) const
{
	static const QString boxId(GOV_MV_DB_ID);
	return boxId;
}

const QString &Gov::SrvcMvRtVt::dmAnnotation(void) const
{
	static const QString dmAnnotation("CzechPOINT@home - Žádost o výpis z Rejstříku trestů");
	return dmAnnotation;
}

const QString &Gov::SrvcMvRtVt::dmSenderIdent(void) const
{
	static const QString dmSenderIdent("CzechPOINT@home - 262");
	return dmSenderIdent;
}

const QString &Gov::SrvcMvRtVt::dmFileDescr(void) const
{
	static const QString dmFileDescr(GOV_MV_XML_FILE_NAME);
	return dmFileDescr;
}

bool Gov::SrvcMvRtVt::canSend(enum Isds::Type::DbType dbType) const
{
212 213 214 215 216 217 218 219 220
	switch (dbType) {
	case Isds::Type::BT_OVM_FO:
	case Isds::Type::BT_FO:
		return true;
		break;
	default:
		return false;
		break;
	}
Karel Slaný's avatar
Karel Slaný committed
221
}
222

223
bool Gov::SrvcMvRtVt::setFieldVal(const QString &key, const QString &val)
Karel Slaný's avatar
Karel Slaný committed
224
{
225
	if (key == BIRTH_KEY) {
226
		if (QDate::fromString(val, GOV_DATE_FORMAT).isNull()) {
227 228 229
			return false;
		}
	}
230 231

	return Service::setFieldVal(key, val);
232 233 234 235 236 237 238 239
}

bool Gov::SrvcMvRtVt::setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo)
{
	if (Q_UNLIKELY(dbOwnerInfo.isNull())) {
		return false;
	}

240 241 242 243 244
	const QString &boxName(dbOwnerInfo.personName().firstName());
	const QString &boxSurname(dbOwnerInfo.personName().lastName());
	const QDate &boxBirthDate(dbOwnerInfo.birthInfo().date());
	const QString &boxBirthRegion(dbOwnerInfo.birthInfo().county());
	const QString &boxBirthCity(dbOwnerInfo.birthInfo().city());
Karel Slaný's avatar
Karel Slaný committed
245

246 247 248 249 250 251 252 253 254 255 256 257 258 259
	if (Q_UNLIKELY(boxName.isEmpty() || boxSurname.isEmpty() ||
	        boxBirthDate.isNull() || boxBirthRegion.isEmpty() ||
	        boxBirthCity.isEmpty())) {
		return false;
	}

	if (Q_UNLIKELY(!Service::setFieldVal(NAME_KEY, boxName))) {
		Q_ASSERT(0);
		return false;
	}
	if (Q_UNLIKELY(!Service::setFieldVal(SURNAME_KEY, boxSurname))) {
		Q_ASSERT(0);
		return false;
	}
260
	if (Q_UNLIKELY(!Service::setFieldVal(BIRTH_KEY, boxBirthDate.toString(GOV_DATE_FORMAT)))) {
261 262 263 264 265 266 267 268 269 270 271 272 273
		Q_ASSERT(0);
		return false;
	}
	if (Q_UNLIKELY(!Service::setFieldVal(REGION_KEY, boxBirthRegion))) {
		Q_ASSERT(0);
		return false;
	}
	if (Q_UNLIKELY(!Service::setFieldVal(CITY_KEY, boxBirthCity))) {
		Q_ASSERT(0);
		return false;
	}

	return true;
Karel Slaný's avatar
Karel Slaný committed
274 275
}

276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
bool Gov::SrvcMvRtVt::haveAllValidFields(QString *errDescr)
{
	bool ret = false;

	ret = Service::checkStrTrimmed(NAME_KEY, errDescr);
	if (!ret) {
		return ret;
	}
	ret = Service::checkStrTrimmed(SURNAME_KEY, errDescr);
	if (!ret) {
		return ret;
	}
	ret = Service::checkDate(BIRTH_KEY, errDescr);
	if (!ret) {
		return ret;
	}
	ret = Service::checkStrTrimmed(REGION_KEY, errDescr);
	if (!ret) {
		return ret;
	}
	ret = Service::checkStrTrimmed(CITY_KEY, errDescr);
	if (!ret) {
		return ret;
	}

	if (errDescr != Q_NULLPTR) {
		errDescr->clear();
	}
	return true;
}

307
QByteArray Gov::SrvcMvRtVt::binaryXmlContent(void) const
Karel Slaný's avatar
Karel Slaný committed
308
{
309
	const QDate boxBirthDate(
310
	    QDate::fromString(fieldVal(BIRTH_KEY), GOV_DATE_FORMAT));
311

Karel Slaný's avatar
Karel Slaný committed
312
	QString xml(xml_template);
313 314 315 316 317 318 319
	xml.replace("__repl_NAME__", fieldVal(NAME_KEY));
	xml.replace("__repl_SURNAME__", fieldVal(SURNAME_KEY));
	xml.replace("__repl_BIRTH_DATE_DAY__", boxBirthDate.toString("d"));
	xml.replace("__repl_BIRTH_DATE_MONTH__", boxBirthDate.toString("M"));
	xml.replace("__repl_BIRTH_DATE_YEAR__", boxBirthDate.toString("yyyy"));
	xml.replace("__repl_REGION__", fieldVal(REGION_KEY));
	xml.replace("__repl_CITY__", fieldVal(CITY_KEY));
320 321
	return xml.toUtf8();
}