From b2b445e1f1d7eb361ff4426ec879ec7c97c694f1 Mon Sep 17 00:00:00 2001 From: semenov Date: Tue, 14 Jan 2025 17:05:54 +0300 Subject: [PATCH] ref: segregate dbAnswer --- DOCS/.obsidian/workspace.json | 6 +- ServerLMS/ServerLMS/CMakeLists.txt | 2 + .../ServerLMS/Systems/Parsers/dataparser.cpp | 103 ++--------------- .../ServerLMS/Systems/Parsers/dataparser.h | 12 +- .../Systems/Parsers/dbanswerparser.cpp | 109 ++++++++++++++++++ .../Systems/Parsers/dbanswerparser.h | 29 +++++ .../ServerLMS/Systems/commonclienthandler.h | 2 +- .../ServerLMS/Systems/processingsystem.cpp | 6 +- 8 files changed, 160 insertions(+), 109 deletions(-) create mode 100644 ServerLMS/ServerLMS/Systems/Parsers/dbanswerparser.cpp create mode 100644 ServerLMS/ServerLMS/Systems/Parsers/dbanswerparser.h diff --git a/DOCS/.obsidian/workspace.json b/DOCS/.obsidian/workspace.json index ba81223..e1402e2 100644 --- a/DOCS/.obsidian/workspace.json +++ b/DOCS/.obsidian/workspace.json @@ -67,10 +67,10 @@ "state": { "type": "excalidraw", "state": { - "file": "MainScheme.md" + "file": "Алексей/DataParser scheme.md" }, "icon": "excalidraw-icon", - "title": "MainScheme" + "title": "DataParser scheme" } } ], @@ -219,9 +219,9 @@ }, "active": "9608f84166966ca9", "lastOpenFiles": [ + "MainScheme.md", "Алексей/DataParser scheme.md", "Алексей/ProcessingSystem scheme.md", - "MainScheme.md", "AssetManagerScheme.md", "Алексей/AssetManagerScheme.md", "Как умеем принимать, как умеем отправлять!.md", diff --git a/ServerLMS/ServerLMS/CMakeLists.txt b/ServerLMS/ServerLMS/CMakeLists.txt index 8cd8b7e..94990ea 100644 --- a/ServerLMS/ServerLMS/CMakeLists.txt +++ b/ServerLMS/ServerLMS/CMakeLists.txt @@ -55,6 +55,8 @@ add_library(ServerLMS SHARED Systems/Parsers/dataparser.h Systems/Parsers/clientanswerparser.cpp Systems/Parsers/clientanswerparser.h + Systems/Parsers/dbanswerparser.cpp + Systems/Parsers/dbanswerparser.h Systems/processingsystem.cpp Systems/processingsystem.h Systems/sendsystem.cpp diff --git a/ServerLMS/ServerLMS/Systems/Parsers/dataparser.cpp b/ServerLMS/ServerLMS/Systems/Parsers/dataparser.cpp index 1c6b478..3a66a04 100644 --- a/ServerLMS/ServerLMS/Systems/Parsers/dataparser.cpp +++ b/ServerLMS/ServerLMS/Systems/Parsers/dataparser.cpp @@ -8,8 +8,12 @@ QObject(parent) { this->processingSystem = processingSystem; this->assetsManager = assetManager; + clientAnswer = new ClientAnswerParser; clientAnswer->initialize(this); + dbAnswer = new DBAnswerParser; + dbAnswer->initialize(this); + mutex = new QMutex; if (!QDir(staticDataFolderName).exists()){ @@ -330,101 +334,7 @@ bool DataParser::saveDOMtoXML(QString nameFile, QDomDocument *commonDOM) return true; } -QByteArray DataParser::xmlAnswer_ClientQueryToDB_ListInstructors(bool result, QList *listInstructors) -{ - QDomDocument commonDOM; - if(! loadBlankXML(":/resources/blankXML/ListInstructors.xml", &commonDOM)) - return QByteArray(); - QDomNode listNode = commonDOM.namedItem("ListInstructors"); - - for(Instructor instructor : *listInstructors) - { - //Инструктор - QDomNode instructorNode = commonDOM.createElement("Instructor"); - listNode.appendChild(instructorNode); - instructorNode.toElement().setAttribute("instructor_id", QString::number(instructor.getID())); - instructorNode.toElement().setAttribute("name", instructor.getName()); - instructorNode.toElement().setAttribute("login", instructor.getLogin()); - instructorNode.toElement().setAttribute("password", instructor.getPassword()); - instructorNode.toElement().setAttribute("is_admin", instructor.getIsAdmin()); - instructorNode.toElement().setAttribute("archived", instructor.getArchived()); - instructorNode.toElement().setAttribute("logged_in", instructor.getLoggedIn()); - } - - saveDOMtoXML("ListInstructors.xml", &commonDOM); - - return commonDOM.toByteArray(); -} - -QByteArray DataParser::xmlAnswer_ClientQueryToDB_ListGroups(bool result, QList *listGroups) -{ - QDomDocument commonDOM; - if(! loadBlankXML(":/resources/blankXML/ListGroups.xml", &commonDOM)) - return QByteArray(); - - QDomNode listNode = commonDOM.namedItem("ListGroups"); - - for(Group group : *listGroups) - { - //Группа - QDomNode groupNode = commonDOM.createElement("Group"); - listNode.appendChild(groupNode); - groupNode.toElement().setAttribute("group_id", QString::number(group.getID())); - groupNode.toElement().setAttribute("name", group.getName()); - } - - saveDOMtoXML("ListGroups.xml", &commonDOM); - - return commonDOM.toByteArray(); -} - -QByteArray DataParser::xmlAnswer_ClientQueryToDB_ListTrainees(bool result, QList *listTrainees) -{ - QDomDocument commonDOM; - if(! loadBlankXML(":/resources/blankXML/ListTrainees.xml", &commonDOM)) - return QByteArray(); - - QDomNode listNode = commonDOM.namedItem("ListTrainees"); - - for(Trainee trainee : *listTrainees) - { - //Обучаемый - QDomNode traineeNode = commonDOM.createElement("Trainee"); - listNode.appendChild(traineeNode); - traineeNode.toElement().setAttribute("trainee_id", trainee.getID()); - traineeNode.toElement().setAttribute("name", trainee.getName()); - traineeNode.toElement().setAttribute("login", trainee.getLogin()); - traineeNode.toElement().setAttribute("password", trainee.getPassword()); - traineeNode.toElement().setAttribute("archived", trainee.getArchived()); - traineeNode.toElement().setAttribute("logged_in", trainee.getLoggedIn()); - traineeNode.toElement().setAttribute("group_trainee", trainee.getGroup().getID()); - traineeNode.toElement().setAttribute("computer_trainee", trainee.getComputer().getID()); - //trainee.setTasks() - } - - saveDOMtoXML("ListTrainees.xml", &commonDOM); - - return commonDOM.toByteArray(); -} - -QByteArray DataParser::xmlAnswer_ClientQueryToDB_ListComputers(bool result, QList *listComputers) -{ - //TODO - return QByteArray(); -} - -QByteArray DataParser::xmlAnswer_ClientQueryToDB_ListClassrooms(bool result, QList *listClassrooms) -{ - //TODO - return QByteArray(); -} - -QByteArray DataParser::xmlAnswer_ClientQueryToDB_ListTasks(bool result, QList *listTasks) -{ - //TODO - return QByteArray(); -} QByteArray DataParser::readTempFile() { @@ -453,3 +363,8 @@ ClientAnswerParser *DataParser::ClientAnswer() const { return clientAnswer; } + +DBAnswerParser *DataParser::DbAnswer() const +{ + return dbAnswer; +} diff --git a/ServerLMS/ServerLMS/Systems/Parsers/dataparser.h b/ServerLMS/ServerLMS/Systems/Parsers/dataparser.h index 35b421b..ed5da78 100644 --- a/ServerLMS/ServerLMS/Systems/Parsers/dataparser.h +++ b/ServerLMS/ServerLMS/Systems/Parsers/dataparser.h @@ -6,6 +6,7 @@ #include "Systems/assetsmanager.h" #include "Systems/logger.h" #include "Systems/Parsers/clientanswerparser.h" +#include "dbanswerparser.h" #include "serverlmswidget.h" #include @@ -20,6 +21,7 @@ class ProcessingSystem; class ClientHandler; class AssetsManager; class ClientAnswerParser; +class DBAnswerParser; class DataParser : public QObject { @@ -34,17 +36,10 @@ public: bool loadBlankXML(QString nameFile, QDomDocument* commonDOM); bool saveDOMtoXML(QString nameFile, QDomDocument* commonDOM); - QByteArray xmlAnswer_ClientQueryToDB_ListInstructors(bool result, QList* listInstructors); - QByteArray xmlAnswer_ClientQueryToDB_ListGroups(bool result, QList *listGroups); - QByteArray xmlAnswer_ClientQueryToDB_ListTrainees(bool result, QList *listTrainees); - QByteArray xmlAnswer_ClientQueryToDB_ListComputers(bool result, QList *listComputers); - QByteArray xmlAnswer_ClientQueryToDB_ListClassrooms(bool result, QList *listClassrooms); - QByteArray xmlAnswer_ClientQueryToDB_ListTasks(bool result, QList *listTasks); - - QByteArray xmlAnswer_currentVersion(); ~DataParser(); ClientAnswerParser *ClientAnswer() const; + DBAnswerParser *DbAnswer() const; signals: void sigLogMessage(QString log); @@ -56,6 +51,7 @@ private: ProcessingSystem *processingSystem; AssetsManager *assetsManager; ClientAnswerParser *clientAnswer; + DBAnswerParser *dbAnswer; QByteArray readTempFile(); }; diff --git a/ServerLMS/ServerLMS/Systems/Parsers/dbanswerparser.cpp b/ServerLMS/ServerLMS/Systems/Parsers/dbanswerparser.cpp new file mode 100644 index 0000000..fffd8be --- /dev/null +++ b/ServerLMS/ServerLMS/Systems/Parsers/dbanswerparser.cpp @@ -0,0 +1,109 @@ +#include "dbanswerparser.h" + + + +DBAnswerParser::DBAnswerParser(QObject *parent) : QObject(parent) +{ + +} + +void DBAnswerParser::initialize(DataParser *dataParser) +{ + this->dataParser = dataParser; +} + +QByteArray DBAnswerParser::listInstructors(bool result, QList *listInstructors) +{ + QDomDocument commonDOM; + if(! dataParser->loadBlankXML(":/resources/blankXML/ListInstructors.xml", &commonDOM)) + return QByteArray(); + + QDomNode listNode = commonDOM.namedItem("ListInstructors"); + + for(Instructor instructor : *listInstructors) + { + //Инструктор + QDomNode instructorNode = commonDOM.createElement("Instructor"); + listNode.appendChild(instructorNode); + instructorNode.toElement().setAttribute("instructor_id", QString::number(instructor.getID())); + instructorNode.toElement().setAttribute("name", instructor.getName()); + instructorNode.toElement().setAttribute("login", instructor.getLogin()); + instructorNode.toElement().setAttribute("password", instructor.getPassword()); + instructorNode.toElement().setAttribute("is_admin", instructor.getIsAdmin()); + instructorNode.toElement().setAttribute("archived", instructor.getArchived()); + instructorNode.toElement().setAttribute("logged_in", instructor.getLoggedIn()); + } + + dataParser->saveDOMtoXML("ListInstructors.xml", &commonDOM); + + return commonDOM.toByteArray(); +} + +QByteArray DBAnswerParser::listGroups(bool result, QList *listGroups) +{ + QDomDocument commonDOM; + if(! dataParser->loadBlankXML(":/resources/blankXML/ListGroups.xml", &commonDOM)) + return QByteArray(); + + QDomNode listNode = commonDOM.namedItem("ListGroups"); + + for(Group group : *listGroups) + { + //Группа + QDomNode groupNode = commonDOM.createElement("Group"); + listNode.appendChild(groupNode); + groupNode.toElement().setAttribute("group_id", QString::number(group.getID())); + groupNode.toElement().setAttribute("name", group.getName()); + } + + dataParser->saveDOMtoXML("ListGroups.xml", &commonDOM); + + return commonDOM.toByteArray(); +} + +QByteArray DBAnswerParser::listTrainees(bool result, QList *listTrainees) +{ + QDomDocument commonDOM; + if(! dataParser->loadBlankXML(":/resources/blankXML/ListTrainees.xml", &commonDOM)) + return QByteArray(); + + QDomNode listNode = commonDOM.namedItem("ListTrainees"); + + for(Trainee trainee : *listTrainees) + { + //Обучаемый + QDomNode traineeNode = commonDOM.createElement("Trainee"); + listNode.appendChild(traineeNode); + traineeNode.toElement().setAttribute("trainee_id", trainee.getID()); + traineeNode.toElement().setAttribute("name", trainee.getName()); + traineeNode.toElement().setAttribute("login", trainee.getLogin()); + traineeNode.toElement().setAttribute("password", trainee.getPassword()); + traineeNode.toElement().setAttribute("archived", trainee.getArchived()); + traineeNode.toElement().setAttribute("logged_in", trainee.getLoggedIn()); + traineeNode.toElement().setAttribute("group_trainee", trainee.getGroup().getID()); + traineeNode.toElement().setAttribute("computer_trainee", trainee.getComputer().getID()); + //trainee.setTasks() + } + + dataParser->saveDOMtoXML("ListTrainees.xml", &commonDOM); + + return commonDOM.toByteArray(); +} + +QByteArray DBAnswerParser::listComputers(bool result, QList *listComputers) +{ + //TODO + return QByteArray(); +} + +QByteArray DBAnswerParser::listClassrooms(bool result, QList *listClassrooms) +{ + //TODO + return QByteArray(); +} + +QByteArray DBAnswerParser::listTasks(bool result, QList *listTasks) +{ + //TODO + return QByteArray(); +} diff --git a/ServerLMS/ServerLMS/Systems/Parsers/dbanswerparser.h b/ServerLMS/ServerLMS/Systems/Parsers/dbanswerparser.h new file mode 100644 index 0000000..26300ad --- /dev/null +++ b/ServerLMS/ServerLMS/Systems/Parsers/dbanswerparser.h @@ -0,0 +1,29 @@ +#ifndef DBANSWERPARSER_H +#define DBANSWERPARSER_H + +#include "dataparser.h" +#include "serverlmswidget.h" + +#include +#include + +class DBAnswerParser : public QObject +{ + Q_OBJECT +public: + explicit DBAnswerParser(QObject *parent = nullptr); + void initialize(DataParser *dataParser); + QByteArray listInstructors(bool result, QList *listInstructors); + QByteArray listGroups(bool result, QList *listGroups); + QByteArray listTrainees(bool result, QList *listTrainees); + QByteArray listComputers(bool result, QList *listComputers); + QByteArray listClassrooms(bool result, QList *listClassrooms); + QByteArray listTasks(bool result, QList *listTasks); +signals: + +private: + DataParser *dataParser; + +}; + +#endif // DBANSWERPARSER_H diff --git a/ServerLMS/ServerLMS/Systems/commonclienthandler.h b/ServerLMS/ServerLMS/Systems/commonclienthandler.h index e4af2bd..a6e471b 100644 --- a/ServerLMS/ServerLMS/Systems/commonclienthandler.h +++ b/ServerLMS/ServerLMS/Systems/commonclienthandler.h @@ -2,7 +2,7 @@ #define COMMONCLIENTHANDLER_H #include -#include +#include "clienthandler.h" class ProcessingSystem; class DataParser; diff --git a/ServerLMS/ServerLMS/Systems/processingsystem.cpp b/ServerLMS/ServerLMS/Systems/processingsystem.cpp index 0696d44..ae055ab 100644 --- a/ServerLMS/ServerLMS/Systems/processingsystem.cpp +++ b/ServerLMS/ServerLMS/Systems/processingsystem.cpp @@ -134,13 +134,13 @@ void ProcessingSystem::processingClientQueryToDB(ClientHandler *client, ClientQu QList listTrainees = providerDBLMS->GetListAllTrainees(); QList listGroups = providerDBLMS->GetListAllGroups(); - arrayAnswer = dataParser->xmlAnswer_ClientQueryToDB_ListInstructors(true, &listInstructors); + arrayAnswer = dataParser->DbAnswer()->listInstructors(true, &listInstructors); client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_INSTRUCTORS); - arrayAnswer = dataParser->xmlAnswer_ClientQueryToDB_ListGroups(true, &listGroups); + arrayAnswer = dataParser->DbAnswer()->listGroups(true, &listGroups); client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_GROUPS); - arrayAnswer = dataParser->xmlAnswer_ClientQueryToDB_ListTrainees(true, &listTrainees); + arrayAnswer = dataParser->DbAnswer()->listTrainees(true, &listTrainees); client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_TRAINEES); break; }