Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,182 @@
|
||||
/**
|
||||
* Handler for static meteo data request
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by hjl, SLSE, 2016-10-12
|
||||
*/
|
||||
|
||||
#include "handler_static_meteo_data.h"
|
||||
|
||||
using namespace MeteoDataManagement;
|
||||
|
||||
HandlerStaticMeteoData::HandlerStaticMeteoData(const std::shared_ptr<DdsHandler> &ddsHandler,
|
||||
const std::shared_ptr<DatabaseInterface> &db)
|
||||
: StaticMeteoDataModifyRequestHandler(ddsHandler->fts())
|
||||
, m_ddsHandler(ddsHandler)
|
||||
, m_db(db)
|
||||
, m_logger(getLogger("HandlerStaticMeteoData"))
|
||||
{
|
||||
} // end of ctor()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool HandlerStaticMeteoData::init()
|
||||
{
|
||||
INFO_LOG(m_logger) << "Start HandlerStaticMeteoData.";
|
||||
|
||||
// read data from db-table 'mdm_static_meteo_data'
|
||||
QVector<Database::MdmStaticMeteoData> dataVec;
|
||||
if (!m_db->select(dataVec))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error reading data from database 'mdm_static_meteo_data'!";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dataVec.isEmpty())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "DB table 'mdm_static_meteo_data' is empty! Try to create default entry.";
|
||||
|
||||
if (!insertDefaultStaticMeteoDataEntry())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Insert DB table 'mdm_static_meteo_data' failed! No static meteo data may be handled!";
|
||||
return false; // Damit werden alle moeglicherweise erreichbaren MDU's nicht bearbeitet,
|
||||
// da die Initialisierung des Service im 'SCM' mit Error beendet wird.
|
||||
}
|
||||
|
||||
m_db->select(dataVec);
|
||||
m_dbStaticMeteoData = dataVec.at(0);
|
||||
|
||||
m_dbStaticMeteoData.timeStamp = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
INFO_LOG(m_logger) << "Insert into DB table 'mdm_static_meteo_data' successfully. id: "
|
||||
<< m_dbStaticMeteoData.id;
|
||||
|
||||
onPublishData();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (dataVec.size() > 1)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Invalid number of table entries for 'mdm_static_meteo_data' size:"
|
||||
<< dataVec.size()
|
||||
<< " The first entry will be used only!";
|
||||
}
|
||||
m_dbStaticMeteoData = dataVec.at(0);
|
||||
onPublishData();
|
||||
|
||||
return true;
|
||||
} // end of init()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void HandlerStaticMeteoData::onStaticMeteoDataModifyRequest(const rti::core::SampleIdentity &cookie,
|
||||
const StaticMeteoDataModifyRequest &request)
|
||||
{
|
||||
INFO_LOG(m_logger) << "onStaticMeteoDataModifyRequest: " << request;
|
||||
|
||||
Core::FunctionReplyObject rep(request.id());
|
||||
|
||||
if (!updateStaticMeteoDatainDB(request))
|
||||
{
|
||||
rep = Core::FunctionReplyObject(request.id(), tr_lts("dds", "Update database failed"));
|
||||
m_ddsHandler->fts()->staticMeteoDataModifyReply(cookie, rep);
|
||||
return;
|
||||
}
|
||||
|
||||
// publish static meteo data
|
||||
onPublishData();
|
||||
|
||||
// set reply object on non error and return to acknowledge the FTC-Request
|
||||
m_ddsHandler->fts()->staticMeteoDataModifyReply(cookie, rep);
|
||||
} // end of onStaticMeteoDataModifyRequest()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool HandlerStaticMeteoData::updateStaticMeteoDatainDB(const StaticMeteoDataModifyRequest &request)
|
||||
{
|
||||
if (request.id() != m_dbStaticMeteoData.id)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Invalid id for db-table 'mdm_static_meteo_data'"
|
||||
<< m_dbStaticMeteoData.id
|
||||
<< " correct id: " << m_dbStaticMeteoData.id;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_db->update(ddsInputDataToDbData(request)))
|
||||
return false;
|
||||
|
||||
// safe new data (used in onPublishData()
|
||||
m_dbStaticMeteoData = ddsInputDataToDbData(request);
|
||||
return true;
|
||||
} // end of updateStaticMeteoDatainDB()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void HandlerStaticMeteoData::onPublishData()
|
||||
{
|
||||
// convert db-Data to dds output data
|
||||
MeteoDataManagement::MeteoData ddsData = toDdsData(m_dbStaticMeteoData);
|
||||
|
||||
const auto note(tr_lts("dds", "static data"));
|
||||
|
||||
ddsData.isStaticMeteoData(true);
|
||||
ddsData.note(note);
|
||||
ddsData.weatherStationId(ddsData.id()); // MDUid == dbId
|
||||
|
||||
INFO_LOG(m_logger) << "Publish static MeteoData to dds: " << ddsData;
|
||||
|
||||
if (!m_ddsHandler->dts()->publish(ddsData))
|
||||
ERROR_LOG(m_logger) << "Error publishing static MdmMeteoData to dds";
|
||||
|
||||
} // end of onPublishData()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool HandlerStaticMeteoData::insertDefaultStaticMeteoDataEntry()
|
||||
{
|
||||
Database::MdmStaticMeteoData dbData;
|
||||
|
||||
// Info: currentPartitionTime() liefert beim Start hier noch 0!
|
||||
dbData.timeStamp = m_ddsHandler->currentPartitionTime();
|
||||
dbData.windDirection = 90.0;
|
||||
dbData.windSpeed = 0.0;
|
||||
dbData.temperature = 18.5;
|
||||
dbData.pressure = 1010.3;
|
||||
dbData.humidity = 45.8;
|
||||
|
||||
if (!m_db->insert(dbData))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "insertDefaultStaticMeteoDataEntry for db-table 'mdm_static_meteo_data' failed!";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} // end of insertDefaultStaticMeteoDataEntry()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Database::MdmStaticMeteoData HandlerStaticMeteoData::ddsInputDataToDbData(const StaticMeteoDataModifyRequest &ddsData)
|
||||
{
|
||||
Database::MdmStaticMeteoData dbData;
|
||||
|
||||
dbData.id = ddsData.id();
|
||||
dbData.timeStamp = ddsData.timeStamp();
|
||||
dbData.windDirection = ddsData.windDirection();
|
||||
dbData.windSpeed = ddsData.windSpeed();
|
||||
dbData.temperature = ddsData.temperature();
|
||||
dbData.pressure = ddsData.pressure();
|
||||
dbData.humidity = ddsData.humidity();
|
||||
|
||||
return dbData;
|
||||
} // end of toDbData()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
MeteoData HandlerStaticMeteoData::toDdsData(const Database::MdmStaticMeteoData &dbData)
|
||||
{
|
||||
MeteoData ddsData;
|
||||
|
||||
ddsData.id(dbData.id);
|
||||
ddsData.timeStamp(dbData.timeStamp);
|
||||
ddsData.windDirection(dbData.windDirection);
|
||||
ddsData.windSpeed(dbData.windSpeed);
|
||||
ddsData.temperature(dbData.temperature);
|
||||
ddsData.pressure(dbData.pressure);
|
||||
ddsData.humidity(dbData.humidity);
|
||||
|
||||
return ddsData;
|
||||
} // end of toDdsData()
|
||||
//-----------------------------------------------------------------------------
|
||||
Reference in new issue
Block a user