Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+103
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ClientMessage class is an abstract base class for concrete ClientMessage objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#include "client_message.h"
|
||||
|
||||
#include "WebSocketInterface/Messages/reply_message.h"
|
||||
#include "WebSocketInterface/json_keys.h"
|
||||
#include "WebSocketInterface/data_manager.h"
|
||||
|
||||
#include <QtCore/QJsonDocument>
|
||||
#include <QtCore/QUuid>
|
||||
|
||||
namespace FileManagement
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace ClientMessages
|
||||
{
|
||||
using namespace JsonKeys;
|
||||
|
||||
// ####### ClientMessageFactory begin #######
|
||||
ClientMessageFactory::ClientMessageFactory(DataManager *dataManager)
|
||||
: LtsWebSocket::AbstractClientMessageFactory(getLogger("ClientMessageFactory"))
|
||||
, m_dataManager(dataManager)
|
||||
{}
|
||||
|
||||
LtsWebSocket::AbstractClientMessage *ClientMessageFactory::createMessage(LtsWebSocket::ReplyHandler *client,
|
||||
const QString &message)
|
||||
{
|
||||
LtsWebSocket::AbstractClientMessage *result = checkAttributes(client, message);
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
if (m_type == OcBaseDownload::WebSocketInterface::JsonKeys::BASE_DL_REQUEST())
|
||||
result = new BaseDlRequest(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
|
||||
else if (m_type == OcBaseDownload::WebSocketInterface::JsonKeys::PDF_LIST_REQUEST())
|
||||
result = new PdfListRequest(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
|
||||
|
||||
return checkResult(client, message, result);
|
||||
}
|
||||
// ####### ClientMessageFactory end #######
|
||||
|
||||
// ####### ClientMessage begin #######
|
||||
ClientMessage::ClientMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
|
||||
: LtsWebSocket::AbstractClientMessage(client, type, typeId, uuid, data)
|
||||
, m_dataManager(dataManager)
|
||||
, m_logger(getLogger("ClientMessage"))
|
||||
{}
|
||||
// ####### ClientMessage end #######
|
||||
|
||||
// ####### BaseDlRequest begin #######
|
||||
BaseDlRequest::BaseDlRequest(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
|
||||
: ClientMessage(dataManager, client, type, typeId, uuid, data)
|
||||
{}
|
||||
|
||||
void BaseDlRequest::process()
|
||||
{
|
||||
if (m_data.toObject().contains(OcBaseDownload::WebSocketInterface::JsonKeys::EXERCISE_ID()))
|
||||
{
|
||||
int exerciseId = m_data.toObject().value(OcBaseDownload::WebSocketInterface::JsonKeys::EXERCISE_ID()).toInt();
|
||||
m_client->addReply(m_dataManager->folderBaseData(m_uuid));
|
||||
m_client->addReply(m_dataManager->fileContentBaseData(m_uuid, exerciseId));
|
||||
}
|
||||
else
|
||||
{
|
||||
LtsWebSocket::ErrorMessage::ErrorData errorData;
|
||||
errorData.uuid = m_uuid;
|
||||
errorData.errorMessage = QStringLiteral("No exercise ID specified for FLM base DL.");
|
||||
m_client->addReply(new LtsWebSocket::ErrorMessage(errorData));
|
||||
}
|
||||
}
|
||||
|
||||
bool BaseDlRequest::hasValidData() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// ####### BaseDlRequest end #######
|
||||
|
||||
// ####### PdfListRequest begin #######
|
||||
PdfListRequest::PdfListRequest(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
|
||||
: ClientMessage(dataManager, client, type, typeId, uuid, data)
|
||||
{}
|
||||
|
||||
void PdfListRequest::process()
|
||||
{
|
||||
m_client->addReply(m_dataManager->pdfList(m_uuid,
|
||||
m_data.toObject().value(OcBaseDownload::WebSocketInterface::JsonKeys::EXERCISE_ID()).toInt()));
|
||||
}
|
||||
|
||||
bool PdfListRequest::hasValidData() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// ####### PdfListRequest end #######
|
||||
|
||||
} // namespace ClientMessages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace FileManagement
|
||||
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ClientMessage class is an abstract base class for concrete ClientMessage objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QJsonObject>
|
||||
|
||||
#include <LtsWebSocket/client_message_factory.h>
|
||||
#include <LtsWebSocket/client_message.h>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
namespace FileManagement
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
class DataManager;
|
||||
|
||||
namespace ClientMessages
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The ClientMessageFactory class creates ClientMessages which will then be processed
|
||||
*/
|
||||
class ClientMessageFactory final : public LtsWebSocket::AbstractClientMessageFactory
|
||||
{
|
||||
public:
|
||||
explicit ClientMessageFactory(DataManager *dataManager);
|
||||
|
||||
/**
|
||||
* @brief create Only way to create a ClientMessage object
|
||||
* @param message Text message which will be converted to a ClientMessage object
|
||||
* @return A ClientMessage object, which represents a concrete ClientMessage
|
||||
*/
|
||||
LtsWebSocket::AbstractClientMessage *createMessage(LtsWebSocket::ReplyHandler *client,
|
||||
const QString &message);
|
||||
|
||||
private:
|
||||
DataManager *m_dataManager;
|
||||
|
||||
}; // class ClientMessageFactory
|
||||
|
||||
/**
|
||||
* @brief The ClientMessage class is an abstract base class for concrete ClientMessage objects
|
||||
*/
|
||||
class ClientMessage : public LtsWebSocket::AbstractClientMessage
|
||||
{
|
||||
protected: // method
|
||||
explicit ClientMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data = QJsonValue());
|
||||
|
||||
protected: // attributes
|
||||
DataManager *m_dataManager;
|
||||
LOGGER_T m_logger;
|
||||
}; // class ClientMessage
|
||||
|
||||
/**
|
||||
* @brief The BaseDlRequest class handles the base DL request and sends multiple replys depending on the data requested
|
||||
*/
|
||||
class BaseDlRequest : public ClientMessage
|
||||
{
|
||||
public:
|
||||
explicit BaseDlRequest(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
|
||||
|
||||
void process();
|
||||
bool hasValidData() const;
|
||||
}; // class BaseDlRequest
|
||||
|
||||
/**
|
||||
* @brief The PdfListRequest class handles the PdfList request and sends a list of all available PDF documents
|
||||
*/
|
||||
class PdfListRequest : public ClientMessage
|
||||
{
|
||||
public:
|
||||
explicit PdfListRequest(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
|
||||
|
||||
void process();
|
||||
bool hasValidData() const;
|
||||
}; // class PdfListRequest
|
||||
|
||||
} // namespace ClientMessages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace FileManagement
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ReplyMessage class is an abstract base class for all possible messages which are sent to the client
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#include "reply_message.h"
|
||||
|
||||
#include <LtsWebSocket/json_keys.h>
|
||||
#include "WebSocketInterface/json_keys.h"
|
||||
|
||||
namespace FileManagement
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace ReplyMessages
|
||||
{
|
||||
using namespace JsonKeys;
|
||||
using namespace LtsWebSocket::JsonKeys;
|
||||
|
||||
|
||||
// ####### FolderBaseData begin #######
|
||||
FolderBaseData::FolderBaseData(const QJsonArray &data, const QString &uuid)
|
||||
: LtsWebSocket::ReplyMessage(FOLDER_BASE_DATA(), 1, uuid) // Todo: Check whether typeId is correct
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(), data);
|
||||
}
|
||||
// ####### FolderBaseData end #######
|
||||
|
||||
// ####### FileContentBaseData begin #######
|
||||
FileContentBaseData::FileContentBaseData(const QJsonArray &data, const QString &uuid)
|
||||
: LtsWebSocket::ReplyMessage(FILE_CONTENT_BASE_DATA(), 2, uuid) // Todo: Check whether typeId is correct
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(), data);
|
||||
}
|
||||
// ####### FileContentBaseData end #######
|
||||
|
||||
// ####### PdfListData begin #######
|
||||
PdfListData::PdfListData(const QJsonArray &data, const QString &uuid)
|
||||
: LtsWebSocket::ReplyMessage(PDF_LIST_DATA(), 3, uuid) // Todo: Check whether typeId is correct
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(), data);
|
||||
}
|
||||
// ####### PdfListData end #######
|
||||
|
||||
} // namespace ReplyMessages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace FileManagement
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ReplyMessage class is an abstract base class for all possible messages which are sent to the client
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <LtsWebSocket/reply_message.h>
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QString>
|
||||
|
||||
namespace FileManagement
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace ReplyMessages
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The FolderBaseData class training area data for base DL
|
||||
*/
|
||||
class FolderBaseData : public LtsWebSocket::ReplyMessage
|
||||
{
|
||||
public:
|
||||
explicit FolderBaseData(const QJsonArray &data, const QString &uuid);
|
||||
}; // class FolderBaseData
|
||||
|
||||
/**
|
||||
* @brief The FileContentBaseData class map description data for base DL
|
||||
*/
|
||||
class FileContentBaseData : public LtsWebSocket::ReplyMessage
|
||||
{
|
||||
public:
|
||||
explicit FileContentBaseData(const QJsonArray &data, const QString &uuid);
|
||||
}; // class FileContentBaseData
|
||||
|
||||
/**
|
||||
* @brief The PdfListData class contains a list of all available PDF documents
|
||||
*/
|
||||
class PdfListData : public LtsWebSocket::ReplyMessage
|
||||
{
|
||||
public:
|
||||
explicit PdfListData(const QJsonArray &data, const QString &uuid);
|
||||
}; // class PdfListData
|
||||
|
||||
} // namespace ReplyMessages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace FileManagement
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The DataManager class handles data to be send to the websocket
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#include "data_manager.h"
|
||||
#include "Messages/reply_message.h"
|
||||
#include "main_handler.h"
|
||||
#include "flm_db.h"
|
||||
#include "json_keys.h"
|
||||
#include <ngldb/nsqlquery.h>
|
||||
|
||||
namespace FileManagement
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
//---------------------------------------------------------------------------------------------------------
|
||||
DataManager::DataManager(MainHandler *mainHandler)
|
||||
: LtsWebSocket::DataManagerBaseDl<DatabaseInterface>(mainHandler->db(), getLogger("DataManager"))
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
LtsWebSocket::ReplyMessage *DataManager::folderBaseData(const QString &uuid) const
|
||||
{
|
||||
return toBaseDataMessageFromDb<Database::FlmFolder, ReplyMessages::FolderBaseData>(uuid);
|
||||
}
|
||||
|
||||
LtsWebSocket::ReplyMessage *DataManager::fileContentBaseData(const QString &uuid, int exerciseId) const
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "preparing file content base data for exercise " << exerciseId;
|
||||
QVector<Database::FlmFolder> folderVec;
|
||||
m_dbInterface->select(folderVec);
|
||||
int snapshotFolderId = getFolderId(folderVec, QStringLiteral("Snapshots"), exerciseId);
|
||||
|
||||
// Filter for everything that is in the given exercise + global tactical plans and symbols
|
||||
QVector<Database::FlmFileContent> dataVec;
|
||||
|
||||
|
||||
//this is DONE BY HAND!!!! so very uncool
|
||||
//I HATE YOU SO MUCH YOU FUCKING FUCK FUCK!
|
||||
const QString where = QStringLiteral(" WHERE exercise_id is null OR exercise_id = ") + QString::number(exerciseId) + QStringLiteral(" and file_type_id in (1,2,4,5,6,7,8)");
|
||||
const QString tableName(QStringLiteral("flm.flm_file_content"));
|
||||
const QString stmt(QStringLiteral("SELECT id, name, is_template, folder_id, file_category_id, file_type_id, file_status_id, exercise_id, phase_id, operator_id, content, properties, is_used_by, used_by, last_modified"
|
||||
" FROM ") + tableName + where);
|
||||
|
||||
std::unique_ptr<NSqlQuery> query = std::unique_ptr<NSqlQuery>(new NSqlQuery(m_dbInterface->database(), m_logger));
|
||||
query->prepare(stmt);
|
||||
|
||||
if(query->exec())
|
||||
{
|
||||
Database::FlmFileContent data;
|
||||
while (query->next())
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
data.id = query->value(i++).toLongLong();
|
||||
data.name = query->value(i++).toString();
|
||||
data.isTemplate = query->value(i++).toBool();
|
||||
data.folderId = query->value(i++).toLongLong();
|
||||
data.fileCategoryId = static_cast<FileManagement::FileCategory_def::type>(query->value(i++).toInt());
|
||||
data.fileTypeId = static_cast<FileManagement::FileType_def::type>(query->value(i++).toInt());
|
||||
data.fileStatusId = static_cast<FileManagement::FileStatus_def::type>(query->value(i++).toInt());
|
||||
data.exerciseId = query->value(i++);
|
||||
data.phaseId = query->value(i++);
|
||||
data.operatorId = query->value(i++).toInt();
|
||||
data.content = query->value(i++).toByteArray();
|
||||
QVariant xx = query->value(i++);
|
||||
data.properties = xx.isNull() ? QStringLiteral("{}") : xx.toString();
|
||||
data.isUsedBy = query->value(i++).toBool();
|
||||
data.usedBy = query->value(i++).toInt();
|
||||
data.lastModified = query->value(i++).toLongLong();
|
||||
if ((data.fileTypeId == FileManagement::FileType::Jpg ||
|
||||
data.fileTypeId == FileManagement::FileType::Png)
|
||||
&& data.folderId == snapshotFolderId )
|
||||
{
|
||||
//ERROR_LOG(m_logger) << "errorMessage";
|
||||
continue;
|
||||
}
|
||||
//ERROR_LOG(m_logger) << "ADD " << data.name;
|
||||
|
||||
dataVec.append(data);
|
||||
}
|
||||
|
||||
}else
|
||||
{
|
||||
const QString errorMessage = QStringLiteral("Error reading data from database!");
|
||||
ERROR_LOG(m_logger) << errorMessage;
|
||||
LtsWebSocket::ErrorMessage::ErrorData errData;
|
||||
errData.errorMessage = errorMessage;
|
||||
errData.uuid = uuid;
|
||||
return new LtsWebSocket::ErrorMessage(errData);
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "filtering file content base data for exercise ID: " << exerciseId;
|
||||
DEBUG_LOG(m_logger) << "sending file content base data" << dataVec.size();
|
||||
|
||||
return new ReplyMessages::FileContentBaseData(DatabaseInterface::toJson(dataVec), uuid);
|
||||
|
||||
/*
|
||||
auto cb = [&dataVec, snapshotFolderId, exerciseId](const Database::FlmFileContent & content)
|
||||
{
|
||||
if ((content.exerciseId != exerciseId) && (content.exerciseId != 0))
|
||||
return;
|
||||
//now skip all unneeded document types -> i prefer opt out instead of opt in
|
||||
if (content.fileTypeId == FileManagement::FileType::MSOfficeDocument || 12
|
||||
content.fileTypeId == FileManagement::FileType::MSOfficeDocument97 || 13
|
||||
content.fileTypeId == FileManagement::FileType::MSOfficeSpreadsheet || 10
|
||||
content.fileTypeId == FileManagement::FileType::MSOfficeSpreadsheet97 || 13
|
||||
content.fileTypeId == FileManagement::FileType::MSOfficePresentation || 16
|
||||
content.fileTypeId == FileManagement::FileType::MSOfficePresentation97 || 17
|
||||
content.fileTypeId == FileManagement::FileType::OpenOfficePresentation || 11
|
||||
content.fileTypeId == FileManagement::FileType::OpenOfficeSpreadsheet || 10
|
||||
content.fileTypeId == FileManagement::FileType::OpenOfficeDocument || 9
|
||||
content.fileTypeId == FileManagement::FileType::Unknown || 0
|
||||
content.fileTypeId == FileManagement::FileType::Pdf) 3
|
||||
* 1 2 4 5 6 7 8 18*
|
||||
return;
|
||||
if ((content.fileTypeId == FileManagement::FileType::Jpg ||
|
||||
content.fileTypeId == FileManagement::FileType::Png)
|
||||
&& content.folderId == snapshotFolderId)
|
||||
return; //no snapsholts
|
||||
dataVec += content;
|
||||
};
|
||||
// read all data from database
|
||||
if (!m_dbInterface->select(cb))
|
||||
{
|
||||
const QString errorMessage = QStringLiteral("Error reading data from database!");
|
||||
ERROR_LOG(m_logger) << errorMessage;
|
||||
LtsWebSocket::ErrorMessage::ErrorData errData;
|
||||
errData.errorMessage = errorMessage;
|
||||
errData.uuid = uuid;
|
||||
return new LtsWebSocket::ErrorMessage(errData);
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "filtering file content base data for exercise ID: " << exerciseId;
|
||||
DEBUG_LOG(m_logger) << "sending file content base data";
|
||||
|
||||
return new ReplyMessages::FileContentBaseData(DatabaseInterface::toJson(dataVec), uuid);
|
||||
*/
|
||||
}
|
||||
|
||||
LtsWebSocket::ReplyMessage *DataManager::pdfList(const QString &uuid, int exerciseId) const
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Preparing file content base data for PDF list";
|
||||
QJsonArray dataArr;
|
||||
|
||||
auto cb = [&dataArr, exerciseId] (const Database::FlmFileContent ¤t)
|
||||
{
|
||||
if ((current.exerciseId != exerciseId) && (current.exerciseId != 0))
|
||||
return;
|
||||
if (current.fileTypeId != FileManagement::FileType::Pdf)
|
||||
return;
|
||||
|
||||
QJsonObject obj({{JsonKeys::NAME(), current.name},
|
||||
{JsonKeys::FILE_ID(), current.id},
|
||||
{JsonKeys::FILE_SIZE(), current.content.size()},
|
||||
{JsonKeys::FILE_CATEGORY(), current.fileCategoryId.underlying()},
|
||||
{JsonKeys::IS_TEMPLATE(), current.isTemplate},
|
||||
{JsonKeys::PROPERTIES(), current.properties},
|
||||
{JsonKeys::FILE_STATUS(), current.fileStatusId.underlying() },
|
||||
{JsonKeys::FOLDER_ID(), current.folderId },
|
||||
{JsonKeys::PHASE_ID(), current.phaseId.toInt() },
|
||||
{JsonKeys::OPERATOR_ID(), current.operatorId},
|
||||
{JsonKeys::EXERCISE_ID(), current.exerciseId.toInt()}});
|
||||
dataArr.append(obj);
|
||||
};
|
||||
if (!m_dbInterface->select(cb))
|
||||
{
|
||||
const QString errorMessage = QStringLiteral("Error reading data from database!");
|
||||
ERROR_LOG(m_logger) << errorMessage;
|
||||
LtsWebSocket::ErrorMessage::ErrorData errData;
|
||||
errData.errorMessage = errorMessage;
|
||||
errData.uuid = uuid;
|
||||
return new LtsWebSocket::ErrorMessage(errData);
|
||||
}
|
||||
|
||||
return new ReplyMessages::PdfListData(dataArr, uuid);
|
||||
}
|
||||
|
||||
int DataManager::getFolderId(const QVector<Database::FlmFolder> &dataVec, const QString &folderName, int exerciseId) const
|
||||
{
|
||||
int parentFolder = 0;
|
||||
if (exerciseId > 0)
|
||||
{
|
||||
const QString exName = QLatin1String("$EX_")+QString::number(exerciseId);
|
||||
parentFolder = getFolderId(dataVec, exName, 0);
|
||||
|
||||
}
|
||||
|
||||
for (const auto &fld :dataVec)
|
||||
{
|
||||
if (fld.name == folderName)
|
||||
{
|
||||
if (exerciseId > 0 && parentFolder > 0)
|
||||
{
|
||||
if (fld.path().size() > 1 && fld.path().at(fld.path().size() - 2) == parentFolder)
|
||||
return fld.id;
|
||||
}
|
||||
else
|
||||
return fld.id;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace FileManagement
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The DataManager class handles data to be send to the websocket
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <LtsWebSocket/data_manager_base_dl.h>
|
||||
#include <FileManagement/flm_db.h>
|
||||
#include "logger.h"
|
||||
|
||||
namespace FileManagement
|
||||
{
|
||||
class MainHandler;
|
||||
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The DataManager class is a convenience class for managing base DL data
|
||||
*/
|
||||
class DataManager final : public LtsWebSocket::DataManagerBaseDl<DatabaseInterface>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief DataManager Constructor
|
||||
* @param mainHandler Source for needed handlers
|
||||
*/
|
||||
explicit DataManager(MainHandler *mainHandler);
|
||||
|
||||
LtsWebSocket::ReplyMessage *folderBaseData(const QString &uuid) const;
|
||||
LtsWebSocket::ReplyMessage *fileContentBaseData(const QString &uuid, int exerciseId) const;
|
||||
LtsWebSocket::ReplyMessage *pdfList(const QString &uuid, int exerciseId) const;
|
||||
int getFolderId(const QVector<Database::FlmFolder> &dataVec, const QString &folderName, int exerciseId ) const;
|
||||
}; // class DataManager
|
||||
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace FileManagement
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Header file which holds all occuring JSON keys
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <OcBaseDownload/WebSocketInterface/json_keys.h>
|
||||
|
||||
namespace FileManagement
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
/**
|
||||
* @brief Namespace which holds all occuring JSON keys as const QString objects
|
||||
*/
|
||||
namespace JsonKeys
|
||||
{
|
||||
// types for client --> server messages
|
||||
|
||||
// types for server --> client messages
|
||||
inline QString FILE_CONTENT_BASE_DATA() { return QStringLiteral("fileContentBaseData"); }
|
||||
inline QString FOLDER_BASE_DATA() { return QStringLiteral("folderBaseData"); }
|
||||
inline QString PDF_LIST_DATA() { return QStringLiteral("pdfListData"); }
|
||||
|
||||
// data keys
|
||||
inline QString EXERCISE_ID() { return QStringLiteral("exerciseId"); }
|
||||
inline QString FILE_CATEGORY() { return QStringLiteral("fileCategory"); }
|
||||
inline QString FILE_ID() { return QStringLiteral("fileId"); }
|
||||
inline QString FILE_SIZE() { return QStringLiteral("fileSize"); }
|
||||
inline QString FILE_STATUS() { return QStringLiteral("fileStatus"); }
|
||||
inline QString FOLDER_ID() { return QStringLiteral("folderId"); }
|
||||
inline QString IS_TEMPLATE() { return QStringLiteral("isTemplate"); }
|
||||
inline QString NAME() { return QStringLiteral("name"); }
|
||||
inline QString OPERATOR_ID() { return QStringLiteral("operatorID"); }
|
||||
inline QString PHASE_ID() { return QStringLiteral("phaseId"); }
|
||||
inline QString PROPERTIES() { return QStringLiteral("properties"); }
|
||||
|
||||
} // namespace JsonKeys
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace FileManagement
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Handler for the WebSocket Interface
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#include "websocket_interface_handler.h"
|
||||
|
||||
#include "main_handler.h"
|
||||
#include "data_manager.h"
|
||||
#include "WebSocketInterface/Messages/client_message.h"
|
||||
#include "settings.h"
|
||||
|
||||
namespace FileManagement
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
|
||||
WebSocketInterfaceHandler::WebSocketInterfaceHandler(MainHandler *mainHandler, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_webSocketServer(nullptr)
|
||||
, m_messageFactory(nullptr)
|
||||
, m_dataManager(nullptr)
|
||||
, m_mainHandler(mainHandler)
|
||||
, m_logger(getLogger("WebSocketInterfaceHandler"))
|
||||
{
|
||||
}
|
||||
|
||||
WebSocketInterfaceHandler::~WebSocketInterfaceHandler()
|
||||
{
|
||||
cleanup();
|
||||
}
|
||||
|
||||
bool WebSocketInterfaceHandler::init()
|
||||
{
|
||||
cleanup();
|
||||
|
||||
DEBUG_LOG(m_logger) << "... ok";
|
||||
|
||||
m_dataManager = new DataManager(m_mainHandler);
|
||||
|
||||
m_messageFactory = new ClientMessages::ClientMessageFactory(m_dataManager);
|
||||
|
||||
m_webSocketServer = new LtsWebSocket::LtsWebSocketServer(m_messageFactory, this);
|
||||
|
||||
DEBUG_LOG(m_logger) << "Initialising LtsWebSocketServer";
|
||||
if (!m_webSocketServer->init(QStringLiteral("FLM"), Settings::getWebSocketServerPortRange(1)))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Failed to initialise LtsWebSocketServer";
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "... ok";
|
||||
|
||||
DEBUG_LOG(m_logger) << "Connection signals and slots";
|
||||
DEBUG_LOG(m_logger) << "... ok";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WebSocketInterfaceHandler::cleanup()
|
||||
{
|
||||
delete m_webSocketServer;
|
||||
delete m_messageFactory;
|
||||
delete m_dataManager;
|
||||
}
|
||||
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace FileManagement
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Handler for the WebSocket Interface
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <LtsWebSocket/lts_web_socket_server.h>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
namespace FileManagement
|
||||
{
|
||||
class MainHandler;
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
namespace ClientMessages
|
||||
{
|
||||
class ClientMessageFactory;
|
||||
}
|
||||
class DataManager;
|
||||
|
||||
/**
|
||||
* @brief The WebSocketInterfaceHandler class is the main class for the WebSocketInterface
|
||||
*/
|
||||
class WebSocketInterfaceHandler final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
* @brief WebSocketInterfaceHandler Constructor
|
||||
* @param mainHandler MainHandler to get the HandlerStructureElement from
|
||||
*/
|
||||
explicit WebSocketInterfaceHandler(MainHandler *mainHandler, QObject *parent = nullptr);
|
||||
|
||||
/**
|
||||
* @brief ~WebSocketInterfaceHandler Destructor
|
||||
*/
|
||||
~WebSocketInterfaceHandler();
|
||||
|
||||
/**
|
||||
* @brief init Initialises all needed classes for the WebSocketInterface
|
||||
* @return True on success, otherwise false
|
||||
*/
|
||||
bool init();
|
||||
|
||||
/**
|
||||
* @brief webSocketPort returns the listen port
|
||||
* @return listen port
|
||||
*/
|
||||
unsigned short serverWebSocketPort() { return m_webSocketServer->webSocketPort(); }
|
||||
|
||||
private:
|
||||
void cleanup();
|
||||
|
||||
private:
|
||||
LtsWebSocket::LtsWebSocketServer *m_webSocketServer;
|
||||
ClientMessages::ClientMessageFactory *m_messageFactory;
|
||||
DataManager *m_dataManager;
|
||||
MainHandler *m_mainHandler;
|
||||
LOGGER_T m_logger;
|
||||
}; // class WebSocketInterfaceHandle
|
||||
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace FileManagement
|
||||
Reference in new issue
Block a user