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/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"
40 
41 
42 namespace Atom
43 {
44  namespace Functions
45  {
46  class Action;
47  }
48 }
49 
50 using namespace Poco;
51 using namespace Poco::Net;
52 using namespace Poco::Data;
53 using namespace Poco::Data::Keywords;
54 
55 
56 class DatabaseManager;
57 class SettingsManager;
58 
60  public Tools::ManageJSON
61 {
62  public:
63  using Ptr = std::shared_ptr<Action>;
64 
65  Action(std::string identifier);
66  virtual ~Action();
67 
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::Condition::Ptr> get_conditions()
75  {
76  auto& var = conditions_;
77  return var;
78  }
79  std::vector<Query::Parameter::Ptr> get_parameters()
80  {
81  auto& var = parameters_;
82  return var;
83  }
84  Query::Results::Ptr get_results()
85  {
86  auto& var = results_;
87  return var;
88  }
89  JSON::Object::Ptr get_json_result()
90  {
91  auto& var = json_result_;
92  return var;
93  }
94  std::vector<Ptr>& get_actions()
95  {
96  auto& var = actions_;
97  return var;
98  }
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()
103  {
104  auto& var = session_;
105  return var;
106  }
107  std::shared_ptr<Data::Statement>& get_query()
108  {
109  auto& var = query_;
110  return var;
111  }
112 
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;}
121 
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  Query::Condition::Ptr AddCondition_(std::string identifier, Query::ConditionType type, Query::Condition::Functor functor);
128  void IdentifyParameters_(std::shared_ptr<Net::HTMLForm> form);
129  void IdentifyParameters_(Files::FileManager& files_parameters);
130  void IdentifyParameters_(JSON::Array::Ptr json_array);
131  void IdentifyParameters_(URI::QueryParameters& query_parameters);
132  bool ComposeQuery_();
133  void ExecuteQuery_();
134  void ExecuteAsyncQuery_();
135  void MakeResults_();
136  JSON::Object::Ptr CreateJSONResult_();
137  virtual bool Work_();
138 
139  protected:
140  void NotifyError_(std::string message);
141 
142  private:
143  bool InitializeQuery_();
144 
145  bool async_;
146  bool async_finished_;
147  std::string identifier_;
148  std::string status_;
149  std::string message_;
150  std::string custom_error_;
151  bool final_;
152  bool error_;
153  std::vector<Query::Condition::Ptr> conditions_;
154  std::vector<Query::Parameter::Ptr> parameters_;
155  std::shared_ptr<Query::Results> results_;
156  JSON::Object::Ptr json_result_;
157  std::vector<Ptr> actions_;
158  std::string sql_code_;
159  std::string final_query_;
160  int affected_rows_;
161  std::shared_ptr<Data::Session> session_;
162  std::shared_ptr<Data::Statement> query_;
163 
164 };
165 
166 #endif // FUNCTIONS_ACTION
Definition: file_manager.h:73
Definition: action.h:61
Definition: dvalue.h:48
Definition: manage_json.h:48
Definition: field.h:43