13map<int, string>
const Errors{{401,
"Unauthorized Access (check user login and password)"},
14 {403,
"Token invalid or expired"},
15 {404,
"Requested Data not found"},
16 {409,
"Incorrect Database Request (e.g. violating constraints)"},
17 {422,
"Incorrect Input Request"},
18 {500,
"Internal Server Error"},
19 {503,
"Service Unavaialble"},
20 {504,
"Server Timeout"}};
24 auto it =
Errors.find(error_id);
25 return it !=
Errors.end() ? it->second :
"";
72 curl_global_init(CURL_GLOBAL_DEFAULT);
76 throw runtime_error(
"CURL initialisation failed");
91 curl_global_cleanup();
96 vector<unique_ptr<EventInfo>> event_array;
97 cout <<
"ERROR: EventCatalogue::GetEventList is not implemented yet" << endl;
104 unique_ptr<EventInfo> event_info;
105 cout <<
"ERROR: EventCatalogue::GetEventInfo is not implemented yet" << endl;
112 cout <<
"ERROR: EventCatalogue::AddEventInfo is not implemented yet" << endl;
119 size_t realsize = size * nmemb;
121 data->append((
char*)contents, realsize);
122 }
catch (std::bad_alloc& e) {
130static size_t header_callback(
char* buffer,
size_t size,
size_t nitems,
void* userdata)
132 string* headers = (
string*)userdata;
134 headers->append(buffer, nitems * size);
135 }
catch (std::bad_alloc& e) {
140 return nitems * size;
145 ifstream json_file(json_file_path);
147 sstr << json_file.rdbuf();
148 string json_string = sstr.str();
150 cout <<
"DEBUG: json_string = " << json_string << endl;
152 string success_message =
153 "Event metadata have been written from JSON file '" + json_file_path +
"' to the Event Catalogue";
161 cout <<
"ERROR: EventCatalogue::UpdateEventInfo is not implemented yet" << endl;
168 cout <<
"ERROR: EventCatalogue::DeleteEventInfo is not implemented yet" << endl;
175 cout <<
"ERROR: EventCatalogue::CheckEventInfo is not implemented yet" << endl;
182 cout <<
"ERROR: EventCatalogue::PrintEventInfo is not implemented yet" << endl;
193 string json_string =
"{\"storage_id\": -1, \"storage_name\": \"" + storage_name +
"\"}";
195 cout <<
"DEBUG: json_string = " << json_string << endl;
197 string success_message =
"Storage information has been added for '" + storage_name +
"' to the Event Catalogue";
209 string json_string =
"{\"software_id\": -1, \"software_version\": \"" + software_version +
"\"}";
211 cout <<
"ERROR: json_string = " << json_string << endl;
213 string success_message =
214 "Software version has been added for '" + software_version +
"' version to the Event Catalogue";
222 vector<unique_ptr<EventInfo>> event_array;
223 cout <<
"ERROR: EventCatalogue::EventCatalogueRequest is not implemented yet" << endl;
230 cout <<
"ERROR: EventCatalogue::EventCatalogueChecks is not implemented yet" << endl;
237 cout <<
"ERROR: EventCatalogue::EventCatalogueStats is not implemented yet" << endl;
244 struct curl_slist* http_header =
nullptr;
245 http_header = curl_slist_append(http_header,
"Accept: */*");
246 http_header = curl_slist_append(http_header,
"Content-Type: application/json");
247 http_header = curl_slist_append(http_header,
"charset: utf-8");
248 curl_easy_setopt(
curlInstance, CURLOPT_HTTPHEADER, http_header);
249 curl_easy_setopt(
curlInstance, CURLOPT_URL, RequestUrl.c_str());
258 curl_easy_setopt(
curlInstance, CURLOPT_POSTFIELDS, json_string.c_str());
260 string response_string, header_string;
262 curl_easy_setopt(
curlInstance, CURLOPT_WRITEDATA, &response_string);
264 curl_easy_setopt(
curlInstance, CURLOPT_HEADERDATA, &header_string);
269 cout <<
"ERROR: sending command to '" << RequestUrl <<
"' failed with code = " << res << endl;
270 curl_slist_free_all(http_header);
273 curl_slist_free_all(http_header);
276 curl_easy_getinfo(
curlInstance, CURLINFO_RESPONSE_CODE, &response_code);
279 curl_easy_getinfo(
curlInstance, CURLINFO_TOTAL_TIME, &elapsed);
281 curl_easy_getinfo(
curlInstance, CURLINFO_EFFECTIVE_URL, &url);
282 cout <<
"DEBUG: CURLINFO_TOTAL_TIME = " << elapsed <<
", CURLINFO_EFFECTIVE_URL = " << string(url) << endl;
285 if ((response_code >= 200) && (response_code < 205)) {
287 cout << success_message << endl;
289 cout <<
"Request has been completed with the following response: " << response_string << endl;
292 cout <<
"ERROR: Sending request to '" << RequestUrl <<
"' has been failed";
293 if (error_message !=
"")
294 cout <<
": " << error_message << endl;
296 cout <<
" with code = " << response_code << endl;
298 cout <<
"Error Message:" << endl
299 << response_string << endl
300 <<
"Error Output Header:" << endl
301 << header_string << endl;
302 return -1 * response_code;
static size_t header_callback(char *buffer, size_t size, size_t nitems, void *userdata)
map< int, string > const Errors
size_t response_callback(void *contents, size_t size, size_t nmemb, string *data)
string const GetErrorString(int error_id)
virtual ~EventCatalogue()
int DeleteEventInfo(string storage_name, string file_path, int event_number)
Function to delete metadata for the event stored at the given location.
int AddSoftwareInfo(string software_version)
Function to add software version to the dictionary used by the Event Catalogue.
int UpdateEventInfo(string storage_name, string file_path, int event_number, EventInfo event_metadata)
Function to update metadata of the event stored at the given location.
int PostRequest(string RequestUrl, string json_string, string success_message)
vector< unique_ptr< EventInfo > > EventCatalogueRequest(string rest_api_request)
Function for searching for event metadata in the Event Catalogue using REST API request as an HTTP(s)...
int AddEventInfo(string storage_name, string file_path, int event_number, EventInfo event_metadata)
Function to add metadata for the event stored at the given location.
int CheckEventInfo(string storage_name, string file_path, int event_number)
Function to check metadata for the event stored at the given location.
int AddStorageInfo(string storage_name)
Function to add storage to the dictionary used by the Event Catalogue.
int EventCatalogueStats(int &record_count)
Function to collect summary statistics on the Event Catalogue.
int EventCatalogueChecks(int &file_not_found, vector< unique_ptr< EventInfo > > &event_list)
Function to perform a set of specific checks in the Event Catalogue.
vector< unique_ptr< EventInfo > > GetEventList(vector< unique_ptr< EventCondition > > event_conditions)
Function for searching for event metadata in the Event Catalogue using specified conditions.
int PrintEventInfo(string storage_name, string file_path, int event_number)
Function to print metadata for the event stored at the given location.
unique_ptr< EventInfo > GetEventInfo(string storage_name, string file_path, int event_number)
Function tp get metadata of the event stored at the given location.
matchCriteria EventMatchCriteria
searchAttributes
enumeration for attributes, which can be used in searching event metadata
searchAttributes EventAttribute
matchCriteria
enumeration for conditions, which can be used for matching with a specified value
Class presenting Event Info (Metadata) Structure.
static const int Version
structure (API) version
const char *const EVENT_API_HOST
const char *const EVENT_API_NAME
const char *const EVENT_API_PASSWORD
const char *const EVENT_API_USERNAME
basic_json< nlohmann::ordered_map > ordered_json
specialization that maintains the insertion order of object keys