Commit bf0723f5 authored by Martin Straka's avatar Martin Straka
Browse files

Asked recipient databox info before adding into list.

parent 36d146af
......@@ -152,18 +152,34 @@ QString Isds::Tasks::findDatabox(const AcntId &acntId, const QString &dbID,
return QString();
}
QString dbInfo;
QList<Isds::DbOwnerInfoExt2> foundBoxes;
findDatabox2(acntId, dbID, dbType, foundBoxes, dbInfo);
return dbInfo;
}
void Isds::Tasks::findDatabox2(const AcntId &acntId, const QString &dbID,
enum Type::DbType dbType, QList<Isds::DbOwnerInfoExt2> &foundBoxes,
QString &dbInfo)
{
debugFuncCall();
if (Q_UNLIKELY((GlobInstcs::workPoolPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
TaskFindDatabox *task = new (::std::nothrow) TaskFindDatabox(
acntId, dbID, dbType);
if (Q_UNLIKELY(task == Q_NULLPTR)) {
Q_ASSERT(0);
return QString();
return;
}
task->setAutoDelete(false);
GlobInstcs::workPoolPtr->runSingle(task);
QString dbInfo = task->m_dbInfo;
dbInfo = task->m_dbInfo;
foundBoxes = task->m_foundBoxes;
delete task; task = Q_NULLPTR;
return dbInfo;
}
/* Maximal number of search results on one page: ISDS allows 100 */
......
......@@ -27,6 +27,7 @@
#include "src/datovka_shared/isds/box_interface.h"
#include "src/messages.h"
#include "src/isds/services/box_interface.h"
class AccountListModel; /* Forward declaration. */
class AcntId; /* Forward declaration. */
......@@ -63,7 +64,7 @@ namespace Isds {
enum Messages::MessageType messageType, qint64 msgId);
/*!
* @brief Find data box info.
* @brief Find data box and return its detail info string.
*
* @param[in] acntId Account identifier.
* @param[in] dbID Data box ID.
......@@ -74,6 +75,20 @@ namespace Isds {
QString findDatabox(const AcntId &acntId, const QString &dbID,
enum Type::DbType dbType);
/*!
* @brief Find data box.
*
* @param[in] acntId Account identifier.
* @param[in] dbID Data box ID.
* @param[in] dbType Data box Type.
* @param[out] foundBoxes Data box list.
* @param[out] dbInfo Data box detail info string.
*/
static
void findDatabox2(const AcntId &acntId, const QString &dbID,
enum Type::DbType dbType,
QList<Isds::DbOwnerInfoExt2> &foundBoxes, QString &dbInfo);
/*!
* @brief Full-text data-box search based on search criteria.
*
......
......@@ -625,43 +625,78 @@ bool IsdsWrapper::addRecipent(const QmlAcntId *qAcntId, const QString &dbID,
const QString &dbName, const QString &dbAddress, bool canUseInitReply,
DataboxListModel *databoxModel)
{
if (Q_UNLIKELY((qAcntId == Q_NULLPTR) || (dbID.isEmpty()))) {
if (Q_UNLIKELY((qAcntId == Q_NULLPTR) || (dbID.isEmpty())) ||
(databoxModel == Q_NULLPTR)) {
Q_ASSERT(0);
return false;
}
bool canSendNormal = false;
bool canSendInitiatory = false;
bool isOvm = Accounts::isOvm(qAcntId);
bool isRecipientOvm = false;
bool isSenderOvm = Accounts::isOvm(qAcntId);
QString ic;
QString dbType;
QString dbSendOptions;
QList<Isds::Type::DmType> dmTypes;
if (!isOvm) {
Isds::Tasks::downloadPdzSendInfo(*qAcntId, dbID, canSendNormal,
canSendInitiatory);
/* Find recipent data box and check dbType and dbOpenAddressing. */
QString dbInfo;
QList<Isds::DbOwnerInfoExt2> foundBoxes;
Isds::Tasks::findDatabox2(*qAcntId, dbID, Isds::Type::BT_NULL,
foundBoxes, dbInfo);
if (!foundBoxes.isEmpty()) {
/* Test if recipient data box is OVM or sub-OVM */
isRecipientOvm = (foundBoxes.at(0).dbType() < Isds::Type::BT_PO);
dbType= dbType2Str(foundBoxes.at(0).dbType());
ic = foundBoxes.at(0).ic();
if (foundBoxes.at(0).dbOpenAddressing() ==
Isds::Type::BOOL_TRUE) {
dbSendOptions = tr("PDZ receiving: YES");
}
dmTypes = setPossiblePdzPaymentMethods(m_pdzInfos,
canSendNormal, canSendInitiatory, canUseInitReply);
}
// Add recipient into send message recipient model
if (databoxModel != Q_NULLPTR) {
DataboxModelEntry dbEntry;
dbEntry.setDbID(dbID);
dbEntry.setDbName(dbName);
dbEntry.setDbAddress(dbAddress);
dbEntry.setPdz(canSendNormal);
if (!dmTypes.isEmpty()) {
dbEntry.setDmType(dmTypes.at(0));
} else {
dbEntry.setDmType(Isds::Type::MT_UNKNOWN);
/* Sender is non-OVM, recipient is non-OVM so get PDZ send info. */
bool canSendInitiatory = false;
if (!isSenderOvm && !isRecipientOvm) {
Isds::Tasks::downloadPdzSendInfo(*qAcntId, dbID,
canSendNormal, canSendInitiatory);
dmTypes = setPossiblePdzPaymentMethods(m_pdzInfos,
canSendNormal, canSendInitiatory, canUseInitReply);
}
} else {
dbSendOptions = (isSenderOvm) ? tr("Non-active")
: tr("PDZ receiving: NO");
int msgResponse = Dialogues::message(Dialogues::QUESTION,
tr("Cannot send message to data box"),
tr("Recipient with data box ID '%1' does not have active data box or has not activated commercial message receiving.").arg(dbID),
tr("Do you still want to add the box '%1' into the recipient list?").arg(dbID),
Dialogues::NO | Dialogues::YES, Dialogues::NO);
if (msgResponse == Dialogues::NO) {
return false;
}
dbEntry.setDmTypes(dmTypes);
databoxModel->addEntry(dbEntry);
return true;
canSendNormal = true;
dmTypes = setPossiblePdzPaymentMethods(m_pdzInfos,
canSendNormal, false, false);
}
return false;
DataboxModelEntry dbEntry;
dbEntry.setDbID(dbID);
dbEntry.setDbName(dbName);
dbEntry.setDbAddress(dbAddress);
dbEntry.setDbType(dbType);
dbEntry.setDbIC(ic);
dbEntry.setDbSendOptions(dbSendOptions);
dbEntry.setPdz(canSendNormal);
if (!dmTypes.isEmpty()) {
dbEntry.setDmType(dmTypes.at(0));
} else {
dbEntry.setDmType(Isds::Type::MT_UNKNOWN);
}
dbEntry.setDmTypes(dmTypes);
return databoxModel->addEntry(dbEntry);
}
void IsdsWrapper::removeIsdsCtx(const AcntId &acntId)
......
......@@ -25,7 +25,6 @@
#include "src/datovka_shared/log/log.h"
#include "src/global.h"
#include "src/isds/services/box_interface.h"
#include "src/isds/session/isds_session.h"
#include "src/isds/session/isds_sessions.h"
#include "src/net/db_wrapper.h"
......@@ -35,6 +34,7 @@ TaskFindDatabox::TaskFindDatabox(const AcntId &acntId,
const QString &dbID, enum Isds::Type::DbType dbType)
: m_result(DL_ERR),
m_dbInfo(),
m_foundBoxes(),
m_lastError(),
m_acntId(acntId),
m_dbID(dbID),
......@@ -49,7 +49,8 @@ void TaskFindDatabox::run(void)
logDebugLv0NL("%s", "---------------FIND DATABOX TASK---------------");
logDebugLv0NL("Starting in thread '%p'", QThread::currentThreadId());
m_result = findDatabox(m_acntId, m_dbID, m_dbType, m_dbInfo, m_lastError);
m_result = findDatabox(m_acntId, m_dbID, m_dbType, m_foundBoxes,
m_dbInfo, m_lastError);
logDebugLv0NL("Finished in thread '%p'", QThread::currentThreadId());
logDebugLv0NL("%s", "-----------------------------------------------");
......@@ -82,7 +83,8 @@ enum TaskFindDatabox::Result error2result(enum Isds::Type::Error error)
enum TaskFindDatabox::Result TaskFindDatabox::findDatabox(
const AcntId &acntId, const QString &dbID, enum Isds::Type::DbType dbType,
QString &dbInfo, QString &lastError)
QList<Isds::DbOwnerInfoExt2> &foundBoxes, QString &dbInfo,
QString &lastError)
{
if (Q_UNLIKELY((!acntId.isValid()) ||
(GlobInstcs::isdsSessionsPtr == Q_NULLPTR) ||
......@@ -104,7 +106,6 @@ enum TaskFindDatabox::Result TaskFindDatabox::findDatabox(
Isds::DbOwnerInfoExt2 dbOwnerInfo;
dbOwnerInfo.setDbID(dbID);
dbOwnerInfo.setDbType(dbType);
QList<Isds::DbOwnerInfoExt2> foundBoxes;
enum Isds::Type::Error error = Isds::findDatabox2(*session,
dbOwnerInfo, foundBoxes, Q_NULLPTR, &lastError);
if (Q_UNLIKELY(error != Isds::Type::ERR_SUCCESS)) {
......
......@@ -27,6 +27,7 @@
#include "src/datovka_shared/identifiers/account_id.h"
#include "src/datovka_shared/isds/types.h"
#include "src/isds/services/box_interface.h"
#include "src/worker/task.h"
/*!
......@@ -69,6 +70,7 @@ public:
* @param[in] acntId Account id.
* @param[in] dbID Sought data-box ID.
* @param[in] dbType Sought data-box type.
* @param[out] foundBoxes Data box list.
* @param[out] dbInfo Data box detail info string.
* @param[out] lastError Last ISDS error message.
* @return Error state.
......@@ -76,10 +78,12 @@ public:
static
enum Result findDatabox(const AcntId &acntId,
const QString &dbID, enum Isds::Type::DbType dbType,
QString &dbInfo, QString &lastError);
QList<Isds::DbOwnerInfoExt2> &foundBoxes, QString &dbInfo,
QString &lastError);
enum Result m_result; /*!< Return state. */
QString m_dbInfo; /*!< Data box info string. */
QList<Isds::DbOwnerInfoExt2> m_foundBoxes; /*!< Data box list. */
QString m_lastError; /*!< Last ISDS error message. */
private:
......
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