221 lines
6.8 KiB
C++
Executable File
221 lines
6.8 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* PDM Custom functions (extends pdmm_dtc_impl.cpp/.h)
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Iuliana Ojog, SLSE, 2016-11-26
|
|
*/
|
|
|
|
#include "opm_dtc_impl_custom.h"
|
|
#include <QJsonArray>
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
#include <QVariantList>
|
|
#include <QVector>
|
|
#include <DDS/DTC/generic_dtc.h>
|
|
#include <DDS/Generic/generic_data_reader.h>
|
|
|
|
namespace OperatorManagement
|
|
{
|
|
namespace Interface
|
|
{
|
|
DtcImplCustom::DtcImplCustom(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector)
|
|
: DtcImpl(ddsConnector)
|
|
{
|
|
}
|
|
|
|
QVector<int> DtcImplCustom::getOperatorsByOperatorRight(int operatorRight)
|
|
{
|
|
QVector<int> ret;
|
|
|
|
DEBUG_LOG(m_logger) << "OperatorRight: " << operatorRight;
|
|
for (const User &user : qAsConst(m_userCont))
|
|
{
|
|
for (int acl : user.effectiveAcls())
|
|
{
|
|
if (operatorRight != acl)
|
|
continue;
|
|
|
|
DEBUG_LOG(m_logger) << "Found acl in Operator " << user.id() << ", operatorRight=" << operatorRight << ", acl=" << acl;
|
|
ret.append(user.id());
|
|
break;
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
QVector<int> DtcImplCustom::operatorForExerciseParty(int exerciseId, int partyId)
|
|
{
|
|
QVector<int> ret = {};
|
|
|
|
DEBUG_LOG(m_logger) << LOGFUNCTION << " exerciseId: " << exerciseId << ", partyId: " << partyId;
|
|
|
|
for (const User &user : qAsConst(m_userCont))
|
|
{
|
|
const auto visiblePartiesByExercise = user.visiblePartiesByExercise();
|
|
for (const auto &pbe : visiblePartiesByExercise)
|
|
{
|
|
if (pbe.exerciseId() != exerciseId)
|
|
continue;
|
|
|
|
if (!pbe.visibleParties().is_set())
|
|
continue;
|
|
|
|
std::vector<int32_t> hiddenParties = {};
|
|
if (pbe.hiddenParties().is_set())
|
|
hiddenParties = pbe.hiddenParties().get();
|
|
|
|
for (const auto &id : pbe.visibleParties().get())
|
|
{
|
|
if (id != partyId)
|
|
continue;
|
|
|
|
bool isHidden = false;
|
|
for (const int &hiddenId : hiddenParties)
|
|
{
|
|
if (hiddenId != partyId)
|
|
continue;
|
|
isHidden = true;
|
|
}
|
|
|
|
if (!isHidden)
|
|
ret.append(user.id());
|
|
}
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
bool DtcImplCustom::sendAdlerNotification(const QString &jsonStr, const int exerciseId, const int partyId, const int notificationType)
|
|
{
|
|
bool found = false;
|
|
|
|
DEBUG_LOG(m_logger) << "sendAdlerNotification"
|
|
<< ", jsonStr:" << jsonStr
|
|
<< ", exercieId: " << exerciseId
|
|
<< ", partyId: " << partyId
|
|
<< ", notificationType" << notificationType;
|
|
QJsonDocument doc = QJsonDocument::fromJson(jsonStr.toUtf8());
|
|
if (!doc.isObject())
|
|
{
|
|
DEBUG_LOG(m_logger) << "sendAdlerNotification !doc.isObject()";
|
|
return true;
|
|
}
|
|
|
|
if (!doc.object().contains(QStringLiteral("Exercises")))
|
|
{
|
|
DEBUG_LOG(m_logger) << "sendAdlerNotification no Exercises";
|
|
return true;
|
|
}
|
|
|
|
DEBUG_LOG(m_logger) << "sendAdlerNotification";
|
|
|
|
const QJsonArray &exercisesArr = doc.object().value(QStringLiteral("Exercises")).toArray();
|
|
for (const QJsonValue &exercisesVal : qAsConst(exercisesArr))
|
|
{
|
|
const QJsonObject exercisesObj = exercisesVal.toObject();
|
|
|
|
// 1. exerciseId pruefen
|
|
if (exercisesObj.value(QStringLiteral("exerciseId")).toInt() != exerciseId)
|
|
{
|
|
DEBUG_LOG(m_logger) << "continue exerciseId=" << exerciseId
|
|
<< ", properties exerciseId=" << exercisesObj.value(QStringLiteral("exerciseId")).toInt();
|
|
continue;
|
|
}
|
|
|
|
if (!exercisesObj.contains(QStringLiteral("suppressNotifications")))
|
|
{
|
|
DEBUG_LOG(m_logger) << "return !exercisesObj.contains suppressNotifications";
|
|
return true;
|
|
}
|
|
|
|
DEBUG_LOG(m_logger) << "sendAdlerNotification Array durchlaufen";
|
|
// 2. Array durchlaufen
|
|
QJsonArray notifications = exercisesObj.value(QStringLiteral("suppressNotifications")).toArray();
|
|
|
|
for (const QJsonValue &val : qAsConst(notifications))
|
|
{
|
|
DEBUG_LOG(m_logger) << "sendAdlerNotification notifications";
|
|
const QJsonObject entry = val.toObject();
|
|
if (entry.value(QStringLiteral("partyId")).toInt() == partyId)
|
|
{
|
|
DEBUG_LOG(m_logger) << "sendAdlerNotification partyId=" << partyId;
|
|
if (entry.contains(QStringLiteral("NotificationType")))
|
|
{
|
|
DEBUG_LOG(m_logger) << "sendAdlerNotification contains NotificationType"
|
|
<< ", NotificationType=" << entry.value(QStringLiteral("NotificationType")).toInt()
|
|
<< ", notificationType" << notificationType;
|
|
if (entry.value(QStringLiteral("NotificationType")).toInt() == notificationType)
|
|
{
|
|
DEBUG_LOG(m_logger) << "sendAdlerNotification contains NotificationType = AdlerNotification found = true";
|
|
found = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return !found;
|
|
}
|
|
|
|
QVector<int> DtcImplCustom::getNotificationRecipents(const int exerciseId, const int partyId, const int operatorRight, const int notificationType)
|
|
{
|
|
const QVector<int> operatorsByOperatorRight = getOperatorsByOperatorRight(operatorRight);
|
|
QVector<int> operatorIds;
|
|
|
|
for (const auto &userId : operatorsByOperatorRight)
|
|
{
|
|
bool inExercise = false;
|
|
const auto user = m_userCont.value(userId);
|
|
// Only include operators who are assigned to the exercise.
|
|
for (const auto &exerciseIdUser : qAsConst(user.exerciseIds()))
|
|
{
|
|
if (exerciseIdUser == exerciseId)
|
|
{
|
|
inExercise = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!inExercise)
|
|
{
|
|
DEBUG_LOG(m_logger) << "Operator name=" << user.name() << " not in Exercise id=" << exerciseId;
|
|
continue;
|
|
}
|
|
DEBUG_LOG(m_logger) << "getNotificationRecipents OperatorId" << user.id() << ", Name=" << user.name() << ", properties=" << user.properties();
|
|
if (isAdlerAllowedParty(exerciseId, partyId, user.id()) &&
|
|
sendAdlerNotification(QString::fromStdString(user.properties()), exerciseId, partyId, notificationType))
|
|
operatorIds.push_back(user.id());
|
|
}
|
|
return operatorIds;
|
|
}
|
|
|
|
bool DtcImplCustom::isAdlerAllowedParty(int exerciseId, int partyId, int operatorId)
|
|
{
|
|
DEBUG_LOG(m_logger) << LOGFUNCTION << " exerciseId: " << exerciseId << ", partyId: "
|
|
<< partyId << ", operatorId: " << operatorId;
|
|
|
|
const auto visiblePartiesByExercise = m_userCont[operatorId].visiblePartiesByExercise();
|
|
for (const auto &pbe : visiblePartiesByExercise)
|
|
{
|
|
if (pbe.exerciseId() != exerciseId)
|
|
continue;
|
|
|
|
const QJsonObject propsObj(QJsonDocument::fromJson(QByteArray::fromStdString(pbe.properties())).object());
|
|
const QJsonArray parties = propsObj.value(QStringLiteral("adlerAllowed")).toArray();
|
|
|
|
for (const QJsonValue &val : parties)
|
|
{
|
|
const int id = val.toInt();
|
|
if (id != partyId)
|
|
continue;
|
|
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
} // namespace Interface
|
|
} // namespace OperatorManagement
|