Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+189
@@ -0,0 +1,189 @@
|
||||
/**
|
||||
* Handler for the HMI language
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "object_order.h"
|
||||
|
||||
#include "esc_operator_rights.h"
|
||||
#include "logger.h"
|
||||
#include "main_handler.h"
|
||||
|
||||
#include <QHostInfo>
|
||||
|
||||
namespace EffectShowClient
|
||||
{
|
||||
|
||||
ObjectOrder::ObjectOrder(MainHandler *mainHandler, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_mainHandler(mainHandler)
|
||||
, m_logger(getLogger("ObjectOrder"))
|
||||
{
|
||||
}
|
||||
|
||||
ObjectOrder::~ObjectOrder()
|
||||
{
|
||||
if (m_data.id > 0)
|
||||
m_mainHandler->dds()->dts()->removeOrderByKey(m_data.id);
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject ObjectOrder::createObject(const Database::EscOrder &data)
|
||||
{
|
||||
m_data = data;
|
||||
if (m_data.id <= 0)
|
||||
{
|
||||
if (!m_mainHandler->db()->insert(m_data))
|
||||
return Core::FunctionReplyObject(0, tr_lts("dds", "Error inserting Order into database."));
|
||||
|
||||
DEBUG_LOG(m_logger) << "New Order created Id: " << m_data.id;
|
||||
}
|
||||
|
||||
// Publish Data via DTS
|
||||
onPublishData();
|
||||
|
||||
return Core::FunctionReplyObject(m_data.id);
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject ObjectOrder::updateObject(const Database::EscOrder &data)
|
||||
{
|
||||
if (data.id <= 0)
|
||||
return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "Object not valid/blocked"));
|
||||
|
||||
m_data = data;
|
||||
|
||||
if (!m_mainHandler->db()->update(m_data))
|
||||
return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "Error updating Order into database"));
|
||||
|
||||
DEBUG_LOG(m_logger) << "Data changed for Changed Id: " << m_data.id;
|
||||
|
||||
// Publish Data via DTS
|
||||
onPublishData();
|
||||
|
||||
return Core::FunctionReplyObject(m_data.id);
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject ObjectOrder::removeObject()
|
||||
{
|
||||
if (!m_mainHandler->db()->removeEscOrder(m_data.id))
|
||||
return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "Order %1 can not be removed")).arg(m_data.id);
|
||||
|
||||
return Core::FunctionReplyObject(m_data.id);
|
||||
}
|
||||
|
||||
void ObjectOrder::onPublishData()
|
||||
{
|
||||
|
||||
EffectShowClient::Order ddsData;
|
||||
|
||||
ddsData.id(m_data.id);
|
||||
ddsData.areaDepth(m_data.areaDepth);
|
||||
ddsData.areaWidth(m_data.areaWidth);
|
||||
ddsData.areaRotation(m_data.areaRotation);
|
||||
ddsData.duration(m_data.duration);
|
||||
ddsData.idOrder(m_data.idOrder);
|
||||
ddsData.numOfVolley(m_data.numOfVolley);
|
||||
ddsData.shotsPerVolley(m_data.shotsPerVolley);
|
||||
EffectShowManagement::OrderConfirmation_e oc = EffectShowManagement::OrderConfirmation_e::inner_enum(m_data.orderConfirmation);
|
||||
ddsData.orderConfirmation(oc);
|
||||
ddsData.position(Core::GeoPosition2D(m_data.centerPosition.x(), m_data.centerPosition.y()));
|
||||
ddsData.lowerLeftPosition(Core::GeoPosition2D(m_data.lowerLeftPosition.x(), m_data.lowerLeftPosition.y()));
|
||||
ddsData.startTime(m_data.startTime);
|
||||
ddsData.typeOfOrder(m_data.typeOfOrder);
|
||||
ddsData.info(m_data.info.toStdString());
|
||||
INFO_LOG(m_logger) << "Publish EscOrder-data to dds (" << m_data.id << ") ...";
|
||||
|
||||
if (oc == EffectShowManagement::OrderConfirmation_e::WaitingForAcceptance)
|
||||
createNotificationRequest();
|
||||
|
||||
if (!m_mainHandler->dds()->dts()->publish(ddsData))
|
||||
ERROR_LOG(m_logger) << "Error publishing EscOrder-data to dds";
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void ObjectOrder::getCreateNotificationRequestData(NotificationManagement::CreateNotification &data)
|
||||
{
|
||||
qint64 currentTime = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
// 100 seconds
|
||||
qint64 expiryTime = currentTime + 100 * 1000;
|
||||
NotificationManagement::NomNotification notif;
|
||||
|
||||
QString localHostName = QHostInfo::localHostName().toUpper();
|
||||
int addressId = m_mainHandler->dds()->dtcAsm()->getAssetId(localHostName);
|
||||
|
||||
if ( m_data.typeOfOrder == 1)
|
||||
{
|
||||
QString title = QString::fromUtf8(tr_lts("Notification", "DMF Order")); // deutsch Wirkdarstellungen
|
||||
notif.title(title.toStdString());
|
||||
}
|
||||
else
|
||||
{
|
||||
QString title = QString::fromUtf8(tr_lts("Notification", "Relocation Order")); // deutsch Stellungswechsel
|
||||
notif.title(title.toStdString());
|
||||
}
|
||||
|
||||
QString content = QString::fromUtf8(tr_lts("Notification","<a href='lts://escOrderList/%1'>Open Dialog</a>"));
|
||||
|
||||
std::vector<std::string> args;
|
||||
args.reserve(1);
|
||||
const QString str = QString::number(m_data.typeOfOrder);
|
||||
args.emplace_back(str.toStdString());
|
||||
|
||||
notif.content(content.toStdString());
|
||||
notif.contentArgs(args);
|
||||
notif.timeStamp(m_mainHandler->dds()->currentPartitionTime());
|
||||
notif.expiryTime(expiryTime);
|
||||
notif.priority(NotificationManagement::Priority_def::High);
|
||||
notif.processedPriority(NotificationManagement::Priority_def::Low);
|
||||
notif.messageType(NotificationManagement::MessageType_def::Info);
|
||||
notif.exerciseId(m_mainHandler->dds()->getExerciseId());
|
||||
|
||||
NotificationManagement::Address wsAddr;
|
||||
wsAddr.addressId(addressId);
|
||||
wsAddr.isRead(false);
|
||||
QString name = localHostName;
|
||||
wsAddr.name(name.toStdString());
|
||||
wsAddr.addressType(NotificationManagement::AddressType_def::Workstation);
|
||||
|
||||
notif.recipientIds().reserve(1);
|
||||
notif.recipientIds().push_back(wsAddr);
|
||||
|
||||
NotificationManagement::Address addrSender;
|
||||
addrSender.addressId(EffectShowClient::Offset);
|
||||
addrSender.name(QStringLiteral("svcEffectShowClient").toStdString());
|
||||
addrSender.addressType(NotificationManagement::AddressType_def::Service);
|
||||
notif.sender(addrSender);
|
||||
|
||||
data.notification(notif);
|
||||
} // end of getCreateNotificationRequestData()
|
||||
|
||||
void ObjectOrder::createNotificationRequest()
|
||||
{
|
||||
NotificationManagement::CreateNotification data;
|
||||
getCreateNotificationRequestData(data);
|
||||
|
||||
INFO_LOG(m_logger) << "trying to send CreateNotificationRequest";
|
||||
if (!m_mainHandler->dds()->ftcNom()->createNotificationRequest(data, this))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error requesting create data";
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void ObjectOrder::onCreateNotificationReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Got createReply with id " << replyObject.id() << " and errorString " << replyObject.translated();
|
||||
|
||||
if (replyObject.error())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error requesting CreateNotification";
|
||||
return;
|
||||
}
|
||||
else
|
||||
DEBUG_LOG(m_logger) << "Requesting create data ok. Got new id:" << replyObject.id() << " ... ok.";
|
||||
|
||||
} // end of onNotificationCreateReply()
|
||||
|
||||
} // Namespace EffectShowClient
|
||||
Reference in new issue
Block a user