2 #ifndef FUNCTIONS_ACTION
3 #define FUNCTIONS_ACTION
15 #include "Poco/JSON/Object.h"
16 #include <Poco/Net/HTTPServerRequest.h>
17 #include "Poco/Data/Session.h"
18 #include "Poco/Data/MySQL/Connector.h"
19 #include <Poco/Data/MySQL/MySQLException.h>
20 #include <Poco/Data/Statement.h>
22 #include <Poco/StreamCopier.h>
23 #include <Poco/JSON/JSON.h>
24 #include <Poco/JSON/JSONException.h>
25 #include <Poco/JSON/Array.h>
26 #include <Poco/JSON/Object.h>
27 #include <Poco/JSON/Parser.h>
28 #include <Poco/Dynamic/Var.h>
29 #include <Poco/Dynamic/Struct.h>
30 #include <Poco/Data/RecordSet.h>
31 #include <Poco/Net/HTMLForm.h>
33 #include "query/results.h"
34 #include "query/parameter.h"
35 #include "query/condition.h"
36 #include "tools/manage_json.h"
37 #include "tools/output_logger.h"
38 #include "tools/dvalue.h"
39 #include "files/file_manager.h"
51 using namespace Poco::Net;
52 using namespace Poco::Data;
53 using namespace Poco::Data::Keywords;
56 class DatabaseManager;
57 class SettingsManager;
63 using Ptr = std::shared_ptr<Action>;
65 Action(std::string identifier);
68 std::string get_identifier()
const {
return identifier_; };
69 std::string get_status()
const {
return status_; };
70 std::string get_message()
const {
return message_; };
71 std::string get_custom_error()
const {
return custom_error_; };
72 bool get_final()
const {
return final_; };
73 bool get_error()
const {
return error_; };
74 std::vector<Query::Parameter::Ptr> get_parameters()
76 auto& var = parameters_;
79 Query::Condition<Action&>::Ptr get_condition()
81 auto& var = condition_;
84 Query::Results::Ptr get_results()
89 JSON::Object::Ptr get_json_result()
91 auto& var = json_result_;
94 std::vector<Ptr>& get_actions()
99 std::string get_sql_code()
const {
return sql_code_; };
100 std::string get_final_query()
const {
return final_query_;}
101 int get_affected_rows_()
const {
return affected_rows_;}
102 std::shared_ptr<Data::Session>& get_session()
104 auto& var = session_;
107 std::shared_ptr<Data::Statement>& get_query()
113 void set_identifier(std::string identifier) { identifier_ = identifier; };
114 void set_status(std::string status) { status_ = status; };
115 void set_message(std::string message) { message_ = message; };
116 void set_custom_error(std::string custom_error) { custom_error_ = custom_error; };
117 void set_final(
bool final) { final_ =
final; };
118 void set_error(
bool error) { error_ = error; };
119 void set_sql_code(std::string sql_code) { sql_code_ = sql_code; };
120 void set_final_query(std::string final_query) {final_query_ = final_query;}
122 JSON::Array::Ptr GetParametersArray_(JSON::Array::Ptr json_array,
int counter);
123 Query::Parameter::Ptr GetParameterObject_(JSON::Array::Ptr parameters_array,
int counter);
124 void ReplaceParamater_(Query::Parameter::Ptr parameter);
125 Query::Parameter::Ptr AddParameter_(std::string name,
Tools::DValue value,
bool editable);
126 Query::Parameter::Ptr AddParameter_(std::string name,
Query::Field::Position field_position, std::string related_action,
bool editable);
127 void IdentifyParameters_(std::shared_ptr<Net::HTMLForm> form);
129 void IdentifyParameters_(JSON::Array::Ptr json_array);
130 void IdentifyParameters_(URI::QueryParameters& query_parameters);
131 void SetupCondition_(std::string identifier, Query::ConditionType type, Query::Condition<Action&>::Functor functor);
132 bool ComposeQuery_();
133 void ExecuteQuery_();
134 void ExecuteAsyncQuery_();
136 JSON::Object::Ptr CreateJSONResult_();
137 virtual bool Work_();
140 void NotifyError_(std::string message);
141 void SetupPositionParameter_(Query::Parameter::Ptr parameter);
142 bool VerifyParameterCondition_(Query::Parameter::Ptr parameter);
143 bool VerifyCondition_();
146 bool InitializeQuery_();
149 bool async_finished_;
150 std::string identifier_;
152 std::string message_;
153 std::string custom_error_;
156 std::vector<Query::Parameter::Ptr> parameters_;
157 Query::Condition<Action&>::Ptr condition_;
158 std::shared_ptr<Query::Results> results_;
159 JSON::Object::Ptr json_result_;
160 std::vector<Ptr> actions_;
161 std::string sql_code_;
162 std::string final_query_;
164 std::shared_ptr<Data::Session> session_;
165 std::shared_ptr<Data::Statement> query_;
Definition: file_manager.h:73