gov_service.h 7.44 KB
Newer Older
Martin Straka's avatar
Martin Straka committed
1
/*
Karel Slaný's avatar
Karel Slaný committed
2
 * Copyright (C) 2014-2019 CZ.NIC
Martin Straka's avatar
Martin Straka committed
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
Karel Slaný's avatar
Karel Slaný committed
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Martin Straka's avatar
Martin Straka committed
12 13 14
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
Karel Slaný's avatar
Karel Slaný committed
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Martin Straka's avatar
Martin Straka committed
16 17 18 19 20 21 22 23 24 25 26
 *
 * 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 <QByteArray>
27
#include <QCoreApplication> /* Q_DECLARE_TR_FUNCTIONS */
28
#include <QList>
Martin Straka's avatar
Martin Straka committed
29 30
#include <QString>

Karel Slaný's avatar
Karel Slaný committed
31
#include "src/datovka_shared/gov_services/service/gov_service_form_field.h"
Martin Straka's avatar
Martin Straka committed
32
#include "src/datovka_shared/isds/box_interface.h"
33 34
#include "src/datovka_shared/isds/message_interface.h"
#include "src/datovka_shared/isds/types.h"
Martin Straka's avatar
Martin Straka committed
35 36 37 38 39 40 41 42 43 44

/* Správa základních registrů */
#define GOV_SZR_FULL_NAME "Automat ZR (Správa základních registrů)"
#define GOV_SZR_DB_ID "4h8cxph"
#define GOV_SZR_XML_FILE_NAME "zrds.xml"
/* Ministerstvo vnitra */
#define GOV_MV_FULL_NAME "Automat CzP (Ministerstvo vnitra)"
#define GOV_MV_DB_ID "xhzkdqv"
#define GOV_MV_XML_FILE_NAME "czpathome.xml"

45 46
#define GOV_DATE_FORMAT "yyyy-MM-dd"

47
namespace Gov {
Martin Straka's avatar
Martin Straka committed
48 49

	/*!
50
	 * @brief Encapsulates the general e-gov service request.
Martin Straka's avatar
Martin Straka committed
51
	 */
52
	class Service {
53 54
		Q_DECLARE_TR_FUNCTIONS(Service)

55
	public:
56 57 58 59 60
		/*!
		 * @brief Constructor.
		 */
		Service(void);

61 62 63 64 65 66
		/*!
		 * @brief Destructor.
		 */
		virtual
		~Service(void);

67 68 69 70 71 72 73 74
		/*!
		 * @brief Allocate a new service object.
		 *
		 * @return Newly allocated object or a Q_NULLPTR on any error.
		 */
		virtual
		Service *createNew(void) const = 0;

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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
		/*!
		 * @brief Return application-internal gov service identifier.
		 *
		 * @return Internal service identifier.
		 */
		virtual
		const QString &internalId(void) const = 0;

		/*!
		 * @brief Return gov service full name.
		 *
		 * @return Full name of service.
		 */
		virtual
		const QString &fullName(void) const = 0;

		/*!
		 * @brief Return full name of the gov institute providing
		 *     the service.
		 *
		 * @return Full name of gov institute.
		 */
		virtual
		const QString &instituteName(void) const = 0;

		/*!
		 * @brief Return data-box ID of the target data box
		 *     of the gov institute.
		 *
		 * @return Data-box ID.
		 */
		virtual
		const QString &boxId(void) const = 0;

		/*!
		 * @brief Return gov service data message subject.
		 *
		 * @return Message annotation.
		 */
		virtual
		const QString &dmAnnotation(void) const = 0;

		/*!
		 * @brief Return gov service sender identification.
		 *
		 * @return Message sender identification.
		 */
		virtual
		const QString &dmSenderIdent(void) const = 0;

		/*!
		 * @brief Return gov service attachment file name.
		 *
		 * @return Message attachment file name.
		 */
		virtual
		const QString &dmFileDescr(void) const = 0;

		/*!
		 * @brief Check whether a box of the given type can send
		 *     this request.
		 *
		 * @return True if the box of the type can send the request.
		 */
		virtual
		bool canSend(enum Isds::Type::DbType dbType) const = 0;

		/*!
		 * @brief Return list of required fields needed for the gov
		 *     service request.
		 *
		 * @return List of required fields.
		 */
		virtual
149 150 151 152 153 154 155 156 157 158 159 160 161
		const QList<FormField> &fields(void) const;
		virtual
		QList<FormField> &fields(void);

		/*!
		 * @brief Get value associated with key.
		 *
		 * @param[in]  key Key identifying the data.
		 * @param[out] ok Set to false if key does not exist in the form fields.
		 * @return Value, null string if key does not exist.
		 */
		virtual
		QString fieldVal(const QString &key, bool *ok = Q_NULLPTR) const;
162 163 164 165 166 167

		/*!
		 * @brief Set service form field data.
		 *
		 * @param[in] key Key identifying the data.
		 * @param[in] val Value to be set.
168
		 * @return True if key found and data were set, false on any error.
169 170
		 */
		virtual
171
		bool setFieldVal(const QString &key, const QString &val);
172

173 174 175 176 177 178 179 180 181
		/*!
		 * @brief Set form data that can be acquired from the owner info.
		 *
		 * @param[in] dbOwnerInfo Box owner info.
		 * @return True if data were set, false on any error.
		 */
		virtual
		bool setOwnerInfoFields(const Isds::DbOwnerInfo &dbOwnerInfo) = 0;

182 183 184 185 186 187
		/*!
		 * @brief Check whether all mandatory data are set.
		 *
		 * @return True if all mandatory fields are set.
		 */
		virtual
188
		bool haveAllMandatoryFields(void) const;
189

190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
		/*!
		 * @brief Return true if service requires mandatory data that
		 *     must be provided by the user.
		 *
		 * @return True if at least one such field exists.
		 */
		virtual
		bool containsMandatoryUserFields(void) const;

		/*!
		 * @brief Return true if service requires data that must be
		 *     acquired from the data box.
		 *
		 * @return true if at least on such field is in the model.
		 */
		virtual
		bool containsBoxOwnerDataFields(void) const;

208 209 210 211 212 213 214 215 216 217
		/*!
		 * @brief Check whether fields contain valid data.
		 *
		 * @param[out] errDescr Non-empty string with error description,
		 *                      empty string if no error found.
		 * @return True on success.
		 */
		virtual
		bool haveAllValidFields(QString *errDescr = Q_NULLPTR) = 0;

218 219 220 221 222 223
		/*!
		 * @brief Create ISDS message containing the request.
		 *
		 * @return Message structure, null structure on any error.
		 */
		virtual
224
		Isds::Message dataMessage(void) const;
225 226 227 228 229 230 231

		/*!
		 * @brief Create and fill XML attachment content.
		 *
		 * @return XML string for attachment.
		 */
		virtual
232
		QByteArray binaryXmlContent(void) const = 0;
233 234

	protected:
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
		/*!
		 * @brief Get index of the entry with given key.
		 *
		 * @param[in] key Key identifying the data.
		 * Return non-negative index, if key found, -1 else.
		 */
		int fieldIndex(const QString &key) const;

		/*!
		 * @brief Removes white spaces. Checks whether contains a valid
		 *     date in GOV_DATE_FORMAT.
		 *
		 * @param[in] key Key identifying the data.
		 * @param[out] errDescr Error description if value invalid.
		 * @return True on success.
		 */
		bool checkDate(const QString &key,
		    QString *errDescr = Q_NULLPTR);

		/*!
		 * @brief removes white spaces. Checks whether sting contains
		 *     a valid IC.
		 *
		 * @param[in] key Key identifying the data.
		 * @param[out] errDescr Error description if value invalid.
		 * @return True on success.
		 */
		bool checkIc(const QString &key, QString *errDescr = Q_NULLPTR);

		/*!
		 * @brief removes all white spaces. Checks whether remaining
		 *     sting is non-empty.
		 *
		 * @param[in] key Key identifying the data.
		 * @param[out] errDescr Error description if value invalid.
		 * @return True on success.
		 */
		bool checkStrRemoveWhiteSpace(const QString &key,
		    QString *errDescr = Q_NULLPTR);

		/*!
		 * @brief removes leading and trailing white spaces. Checks
		 *     whether remaining sting is non-empty.
		 *
		 * @param[in] key Key identifying the data.
		 * @param[out] errDescr Error description if value invalid.
		 * @return True on success.
		 */
		bool checkStrTrimmed(const QString &key,
		    QString *errDescr = Q_NULLPTR);

286
		QList<FormField> m_formFields; /*!< Data within the form. */
287 288 289
	};

}