Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,220 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* ISM Handler Presentations
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Iuliana Ojog, SLSE, 2016-11-26
|
||||
*/
|
||||
|
||||
#include "handler_presentation.h"
|
||||
#include "object_presentation.h"
|
||||
#include "initialization.h"
|
||||
#include "dds_handler.h"
|
||||
|
||||
|
||||
namespace PresentationManagement
|
||||
{
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
HandlerPresentation::HandlerPresentation(Initialization *mainHandler)
|
||||
: Interface::Fts::PresentationModifyRequestHandler(mainHandler->dds()->fts())
|
||||
, Interface::Fts::PresentationRemoveRequestHandler(mainHandler->dds()->fts())
|
||||
, Interface::Fts::GetPresentationContentRequestHandler(mainHandler->dds()->fts())
|
||||
, Interface::Fts::PresentationChangeStatusRequestHandler(mainHandler->dds()->fts())
|
||||
, m_mainHandler(mainHandler)
|
||||
, m_logger(getLogger("HandlerPresentation"))
|
||||
{
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
HandlerPresentation::~HandlerPresentation()
|
||||
{
|
||||
qDeleteAll(m_objectPresentationMap);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
bool HandlerPresentation::init()
|
||||
{
|
||||
{
|
||||
// create presentation objects
|
||||
auto cb = [this](const Database::PrePresentation &data)
|
||||
{
|
||||
const PresentationManagement::Presentation ddsData = ObjectPresentation::toDdsData(data);
|
||||
ObjectPresentation *ifs(new ObjectPresentation(ddsData, m_mainHandler));
|
||||
m_objectPresentationMap.insert(ifs->getId(), ifs);
|
||||
};
|
||||
if (!m_mainHandler->db()->select(cb))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error reading data from database!";
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "m_objectPresentationMap.size() = " << m_objectPresentationMap.size();
|
||||
}
|
||||
|
||||
{
|
||||
// add presentationContent to presentation
|
||||
auto cb = [this] (const Database::PrePresentationContent &data)
|
||||
{
|
||||
ObjectPresentation *objPre = m_objectPresentationMap.value(data.presentationId);
|
||||
if (!objPre || !objPre->isValid())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Cannot find presentation Id = " << data.presentationId
|
||||
<< " for presentationContent " << data.id;
|
||||
return;
|
||||
}
|
||||
objPre->addPresentationContent(ObjectPresentation::toDdsData(data));
|
||||
};
|
||||
if (!m_mainHandler->db()->select(cb))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error reading data from database!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// publish
|
||||
for (ObjectPresentation *objPre : qAsConst(m_objectPresentationMap))
|
||||
objPre->onPublishData();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void HandlerPresentation::onPresentationModifyRequest(const rti::core::SampleIdentity &cookie,
|
||||
const PresentationModifyRequest &request)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onPresentationModifyRequest: " << request;
|
||||
auto ret = request.id() > 0 ? presentationModifyRequest(request) : presentationCreateRequest(request);
|
||||
if (ret.error())
|
||||
WARNING_LOG(m_logger) << ret();
|
||||
m_mainHandler->dds()->fts()->presentationModifyReply(cookie, ret);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Core::FunctionReplyObject HandlerPresentation::presentationCreateRequest(const PresentationModifyRequest &request)
|
||||
{
|
||||
PresentationManagement::ObjectPresentation *ifs(new ObjectPresentation(m_mainHandler));
|
||||
Core::FunctionReplyObject ret = ifs->createObject(request);
|
||||
if (ret.error())
|
||||
{
|
||||
delete ifs;
|
||||
return ret;
|
||||
}
|
||||
|
||||
m_objectPresentationMap.insert(ifs->getId(), ifs);
|
||||
|
||||
// publish
|
||||
ifs->onPublishData();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Core::FunctionReplyObject HandlerPresentation::presentationModifyRequest(const PresentationModifyRequest &request)
|
||||
{
|
||||
PresentationManagement::ObjectPresentation *ifs = m_objectPresentationMap.value(request.id());
|
||||
if (ifs == nullptr)
|
||||
return Core::FunctionReplyObject(request.id(), tr_lts("dds", "Presentation with id %1 not found")).arg(request.id());
|
||||
|
||||
int oldId = request.id();
|
||||
Core::FunctionReplyObject ret = ifs->updateObject(request);
|
||||
if (ret.error())
|
||||
return ret;
|
||||
|
||||
m_objectPresentationMap.remove(oldId);
|
||||
m_objectPresentationMap.insert(ifs->getId(), ifs);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void HandlerPresentation::onPresentationRemoveRequest(const rti::core::SampleIdentity &cookie,
|
||||
const Core::RemoveElementRequest &request)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onPresentationRemoveRequest: " << request;
|
||||
Core::FunctionReplyObject ret;
|
||||
int presentationId = request.id();
|
||||
|
||||
// gest presentation object
|
||||
PresentationManagement::ObjectPresentation *ifs = m_objectPresentationMap.value(presentationId);
|
||||
if (ifs == nullptr)
|
||||
{
|
||||
ret = Core::FunctionReplyObject(presentationId, tr_lts("dds", "Presentation with id %1 not found")).arg(presentationId);
|
||||
m_mainHandler->dds()->fts()->presentationRemoveReply(cookie, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_mainHandler->dds()->topicLockMaster()->isLocked(ifs->getData(), m_mainHandler->exerciseId()))
|
||||
{
|
||||
ret = Core::FunctionReplyObject(request.id(), tr_lts("dds", "Presentation '%1' is used by another user!")).arg(ifs->getName());
|
||||
m_mainHandler->dds()->fts()->presentationRemoveReply(cookie, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "Deleting presentation id = " << presentationId;
|
||||
ret = ifs->removeObject(); // removes all from db due to fk
|
||||
if (ret.error())
|
||||
ERROR_LOG(m_logger) << ret();
|
||||
|
||||
// delete ObjectPresentation (including Map)
|
||||
delete ifs;
|
||||
m_objectPresentationMap.remove(presentationId);
|
||||
|
||||
m_mainHandler->dds()->dts()->removePresentationByKey(presentationId);
|
||||
|
||||
m_mainHandler->dds()->fts()->presentationRemoveReply(cookie, ret);
|
||||
|
||||
return;
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void HandlerPresentation::onGetPresentationContentRequest(const rti::core::SampleIdentity &cookie,
|
||||
const GetPresentationContentRequest &request)
|
||||
{
|
||||
Core::FunctionReplyObject fro;
|
||||
GetPresentationContentReply reply;
|
||||
|
||||
ObjectPresentation *ifs = m_objectPresentationMap.value(request.presentationId());
|
||||
|
||||
if (ifs)
|
||||
{
|
||||
reply.id(ifs->getId());
|
||||
/*
|
||||
if (ifs->getContent().size() <= 0)
|
||||
fro = Core::FunctionReplyObject(request.presentationId(), tr_lts("dds", "No content for presentation "));
|
||||
else
|
||||
*/
|
||||
reply.content(ifs->getContent());
|
||||
}
|
||||
else
|
||||
fro = Core::FunctionReplyObject(request.presentationId(), tr_lts("dds", "No valid presentation id for retrieving presentation content"));
|
||||
|
||||
if (fro.error())
|
||||
{
|
||||
reply.id(fro.id());
|
||||
reply.errorString(fro.str());
|
||||
reply.errorParams(fro.args());
|
||||
}
|
||||
|
||||
m_mainHandler->dds()->fts()->getPresentationContentReply(cookie, reply);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------------
|
||||
void HandlerPresentation::onPresentationChangeStatusRequest(const rti::core::SampleIdentity &cookie,
|
||||
const PresentationChangeStatusRequest &request)
|
||||
{
|
||||
ObjectPresentation *ifs = m_objectPresentationMap.value(request.id());
|
||||
if (ifs == nullptr)
|
||||
{
|
||||
Core::FunctionReplyObject ret = Core::FunctionReplyObject(request.id(), tr_lts("dds", "Presentation with id %1 not found")).arg(request.id());
|
||||
m_mainHandler->dds()->fts()->presentationChangeStatusReply(cookie, ret);
|
||||
return;
|
||||
}
|
||||
Core::FunctionReplyObject ret = ifs->changeStatus(request);
|
||||
if (ret.error())
|
||||
ERROR_LOG(m_logger) << ret();
|
||||
|
||||
m_mainHandler->dds()->fts()->presentationChangeStatusReply(cookie, ret);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
} // Namespace PresentationManagement
|
||||
Reference in new issue
Block a user