191 lines
5.3 KiB
C++
Executable File
191 lines
5.3 KiB
C++
Executable File
/**
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Philipp Last, NLSE, 2018-01-11
|
|
*/
|
|
|
|
#include "handler_san_nine_liner.h"
|
|
#include "object_san_nine_liner.h"
|
|
#include "object_san_category_line.h"
|
|
#include "san_category_line_json.h"
|
|
#include <LtsCoordTrans/lts_coord_trans.h>
|
|
|
|
#include "settings.h"
|
|
|
|
#include <QJsonDocument>
|
|
|
|
namespace Evaluations
|
|
{
|
|
|
|
HandlerSanNineLiner::HandlerSanNineLiner(const std::shared_ptr<DdsHandler> &ddsHandler,
|
|
const std::shared_ptr<DatabaseInterface> &db)
|
|
: Interface::Fts::SanNineLinerModifyRequestHandler(ddsHandler->fts())
|
|
, Interface::Fts::SanNineLinerRemoveRequestHandler(ddsHandler->fts())
|
|
, m_ddsHandler(ddsHandler)
|
|
, m_db(db)
|
|
, m_logger(getLogger("HandlerSanNineLiner"))
|
|
{}
|
|
|
|
HandlerSanNineLiner::~HandlerSanNineLiner()
|
|
{
|
|
qDeleteAll(m_mapObjectSanNineLiner);
|
|
}
|
|
|
|
bool HandlerSanNineLiner::init()
|
|
{
|
|
bool bRet = true;
|
|
// Comment
|
|
auto cbSanNineLiner = [this, &bRet] (const Database::SanNineLiner &data)
|
|
{
|
|
ObjectSanNineLiner *ifs(new ObjectSanNineLiner(m_ddsHandler, m_db));
|
|
Core::FunctionReplyObject ret = ifs->createObject(data);
|
|
if (ret.error())
|
|
{
|
|
delete ifs;
|
|
ERROR_LOG(m_logger) << ret();
|
|
bRet = false;
|
|
return;
|
|
}
|
|
m_mapObjectSanNineLiner.insert(ifs->getId(), ifs);
|
|
};
|
|
if (!m_db->select(cbSanNineLiner) || !bRet)
|
|
{
|
|
ERROR_LOG(m_logger) << "Error reading data from database!";
|
|
return false;
|
|
}
|
|
|
|
// add categoryLine to sanNineLiner object
|
|
auto cb = [this] (const Database::SanCategoryLine &data)
|
|
{
|
|
ObjectSanNineLiner *objSan = m_mapObjectSanNineLiner.value(data.nineLinerId);
|
|
if (!objSan)
|
|
{
|
|
WARNING_LOG(m_logger) << "Cannot find nineLiner Id = " << data.nineLinerId
|
|
<< " for categoryLineId " << data.id;
|
|
return;
|
|
}
|
|
objSan->addLineCategory(data);
|
|
};
|
|
|
|
if (!m_db->select(cb))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error reading data from database!";
|
|
return false;
|
|
}
|
|
|
|
// publish
|
|
for (ObjectSanNineLiner *objSan : qAsConst(m_mapObjectSanNineLiner))
|
|
objSan->onPublishData();
|
|
|
|
return true;
|
|
}
|
|
|
|
void HandlerSanNineLiner::onSanNineLinerModifyRequest(const rti::core::SampleIdentity &cookie,
|
|
const SanNineLinerModifyRequest &request)
|
|
{
|
|
Database::SanNineLiner data;
|
|
data.id = request.id();
|
|
data.lastModified = request.lastModified();
|
|
data.position = QPointF(request.line1_position().lon(), request.line1_position().lat());
|
|
|
|
LtsCoordTrans::UtmCoordinate coord(LtsCoordTrans::UtmCoordinate::fromGeographic(request.line1_position().lon(),
|
|
request.line1_position().lat()));
|
|
data.positionXM = coord.x;
|
|
data.positionYM = coord.y;
|
|
|
|
data.radioFrequencySuffixCallsign = QString::fromStdString(request.line2_radioFrequencyCallSignSuffix());
|
|
|
|
INFO_LOG(m_logger) << "lines: " << request.lines();
|
|
|
|
Core::FunctionReplyObject ret;
|
|
ObjectSanNineLiner *ifs = nullptr;
|
|
if (request.id() <= 0)
|
|
{
|
|
ifs = new ObjectSanNineLiner(m_ddsHandler, m_db);
|
|
ret = ifs->createObject(data);
|
|
|
|
if (ret.error())
|
|
{
|
|
delete ifs;
|
|
ifs = nullptr;
|
|
ERROR_LOG(m_logger) << ret();
|
|
}
|
|
else
|
|
{
|
|
m_mapObjectSanNineLiner.insert(ifs->getId(), ifs);
|
|
data.id = ifs->getId();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
data.id = request.id();
|
|
ifs = m_mapObjectSanNineLiner.value(data.id);
|
|
ret = ifs->updateObject(data);
|
|
}
|
|
|
|
if (!ifs)
|
|
{
|
|
m_ddsHandler->fts()->sanNineLinerModifyReply(cookie, ret);
|
|
return;
|
|
}
|
|
|
|
// delete old entries
|
|
if (!m_db->removeCategoryLinesPerNineLiner(data.id))
|
|
ERROR_LOG(m_logger) << "Error while deleting old entries for nineLinerId " << data.id;
|
|
|
|
ifs->removeCategoryLines();
|
|
|
|
// line3 - line9 in object_san_category_line
|
|
INFO_LOG(m_logger) << "data.id: " << data.id;
|
|
|
|
QVector<Database::SanCategoryLine> linesCategory = SanCategoryLine::fromJson(request.lines(), data.id);
|
|
INFO_LOG(m_logger) << "LinesCategory count: " << linesCategory.count();
|
|
|
|
for (Database::SanCategoryLine cl : qAsConst(linesCategory))
|
|
{
|
|
ObjectSanCategoryLine *ifsCl(new ObjectSanCategoryLine(m_ddsHandler, m_db));
|
|
ret = ifsCl->createObject(cl);
|
|
if (ret.error())
|
|
ERROR_LOG(m_logger) << ret();
|
|
else
|
|
{
|
|
cl.id = ifsCl->getId();
|
|
ifs->addLineCategory(cl);
|
|
}
|
|
}
|
|
|
|
ifs->onPublishData();
|
|
ret.setId(ifs->getId());
|
|
|
|
m_ddsHandler->fts()->sanNineLinerModifyReply(cookie, ret);
|
|
}
|
|
|
|
void HandlerSanNineLiner::onSanNineLinerRemoveRequest(const rti::core::SampleIdentity &cookie,
|
|
const Core::RemoveElementRequest &request)
|
|
{
|
|
|
|
ObjectSanNineLiner *ifs = m_mapObjectSanNineLiner.value(request.id());
|
|
|
|
Core::FunctionReplyObject ret;
|
|
if (!ifs)
|
|
{
|
|
ret = Core::FunctionReplyObject(request.id(), tr_lts("dds", "SanNineLiner with id %1 not found")).arg(request.id());
|
|
m_ddsHandler->fts()->sanNineLinerRemoveReply(cookie, ret);
|
|
return;
|
|
}
|
|
|
|
if (!m_db->removeCategoryLinesPerNineLiner(request.id()))
|
|
ret = Core::FunctionReplyObject(request.id(), tr_lts("dds", "SanCategoryLine with id %1 not found")).arg(request.id());
|
|
else
|
|
{
|
|
ifs->removeObject();
|
|
m_mapObjectSanNineLiner.remove(request.id());
|
|
}
|
|
|
|
m_ddsHandler->fts()->sanNineLinerRemoveReply(cookie, ret);
|
|
}
|
|
|
|
|
|
} // Namespace Evaluations
|