Loading...
Searching...
No Matches
action.h
1
2#ifndef FUNCTIONS_ACTION
3#define FUNCTIONS_ACTION
4
5
6#include <string>
7#include <vector>
8#include <memory>
9#include <array>
10#include <map>
11#include <stdexcept>
12#include <vector>
13#include <thread>
14
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>
21#include <Poco/URI.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>
32
33#include "query/database_manager.h"
34#include "tools/settings_manager.h"
35#include "query/results.h"
36#include "query/parameter.h"
37#include "query/condition.h"
38#include "tools/manage_json.h"
39#include "tools/output_logger.h"
40#include "tools/dvalue.h"
41#include "files/file_manager.h"
42
43
44namespace NAF
45{
46 namespace Functions
47 {
48 class Action;
49 }
50}
51
52using namespace Poco;
53using namespace Poco::Net;
54using namespace Poco::Data;
55using namespace Poco::Data::Keywords;
56
57
59{
60 public:
61 using Ptr = std::shared_ptr<Action>;
62
63 Action(std::string identifier);
64 virtual ~Action();
65
66 std::string get_identifier() const { return identifier_; };
67 std::string get_status() const { return status_; };
68 std::string get_message() const { return message_; };
69 std::string get_custom_error() const { return custom_error_; };
70 int get_last_insert_id() const { return last_insert_id_; };
71 bool get_final() const { return final_; };
72 bool get_error() const { return error_; };
73 std::vector<Query::Parameter::Ptr>& get_parameters()
74 {
75 auto& var = parameters_;
76 return var;
77 }
78 Query::Condition<Action&>::Ptr get_condition()
79 {
80 auto& var = condition_;
81 return var;
82 }
83 Query::Results::Ptr get_results()
84 {
85 auto& var = results_;
86 return var;
87 }
88 JSON::Object::Ptr get_json_result()
89 {
90 auto& var = json_result_;
91 return var;
92 }
93 std::vector<Ptr>& get_actions_container()
94 {
95 auto& var = actions_container_;
96 return var;
97 }
98 std::string get_sql_code() const { return sql_code_; };
99 std::string get_final_query() const {return final_query_;}
100 int get_affected_rows_() const {return affected_rows_;}
101 std::shared_ptr<Data::Session>& get_session()
102 {
103 auto& var = session_;
104 return var;
105 }
106 std::shared_ptr<Data::Statement>& get_query()
107 {
108 auto& var = query_;
109 return var;
110 }
111 Query::DatabaseManager::Credentials& get_credentials()
112 {
113 auto& var = credentials_;
114 return var;
115 }
116
117 void set_identifier(std::string identifier) { identifier_ = identifier; };
118 void set_status(std::string status) { status_ = status; };
119 void set_message(std::string message) { message_ = message; };
120 void set_custom_error(std::string custom_error) { custom_error_ = custom_error; };
121 void set_final(bool final) { final_ = final; };
122 void set_error(bool error) { error_ = error; };
123 void set_sql_code(std::string sql_code) { sql_code_ = sql_code; };
124 void set_final_query(std::string final_query) {final_query_ = final_query;}
125
126 void ReplaceParamater_(Query::Parameter::Ptr parameter);
127 std::vector<Query::Parameter::Ptr>::iterator GetParameter(std::string name);
128 Query::Parameter::Ptr AddParameter_(std::string name, std::string value_string, bool editable);
129 Query::Parameter::Ptr AddParameter_(std::string name, const char* value_string, bool editable);
130 Query::Parameter::Ptr AddParameter_(std::string name, int value_int, bool editable);
131 Query::Parameter::Ptr AddParameter_(std::string name, float value_float, bool editable);
132 Query::Parameter::Ptr AddParameter_(std::string name, bool value_bool, bool editable);
133 Query::Parameter::Ptr AddParameter_(std::string name, Tools::DValue::Ptr value, bool editable);
134 Query::Parameter::Ptr AddParameter_(std::string name, Query::Field::Position field_position, std::string related_action, bool editable);
135 void SetupCondition_(std::string identifier, Query::ConditionType type, Query::Condition<Action&>::Functor functor);
136 bool ComposeQuery_();
137 void ExecuteQuery_();
138 void ExecuteAsyncQuery_();
139 void MakeResults_();
140 JSON::Object::Ptr CreateJSONResult_();
141 virtual bool Work_();
142
143 protected:
144 void GetLastInsertID_();
145 void NotifyError_(std::string message);
146 void SetupPositionParameter_(Query::Parameter::Ptr parameter);
147 bool VerifyParameterCondition_(Query::Parameter::Ptr parameter);
148 bool VerifyCondition_();
149
150 private:
151 bool InitializeQuery_();
152
153 bool async_;
154 bool async_finished_;
155 std::string identifier_;
156 std::string status_;
157 std::string message_;
158 std::string custom_error_;
159 int last_insert_id_;
160 bool final_;
161 bool error_;
162 std::vector<Query::Parameter::Ptr> parameters_;
163 Query::Condition<Action&>::Ptr condition_;
164 std::shared_ptr<Query::Results> results_;
165 JSON::Object::Ptr json_result_;
166 std::vector<Ptr> actions_container_;
167 std::string sql_code_;
168 std::string final_query_;
169 int affected_rows_;
170 std::shared_ptr<Data::Session> session_;
171 std::shared_ptr<Data::Statement> query_;
173 std::mutex mutex_;
174
175};
176
177#endif // FUNCTIONS_ACTION
Definition action.h:59
Definition database_manager.h:51
Definition field.h:43