20#ifndef ORES_QT_CHANGE_REASON_CACHE_HPP
21#define ORES_QT_CHANGE_REASON_CACHE_HPP
24#include <unordered_map>
26#include <QFutureWatcher>
27#include "ores.qt/ClientManager.hpp"
28#include "ores.logging/make_logger.hpp"
29#include "ores.dq.api/domain/change_reason.hpp"
30#include "ores.dq.api/domain/change_reason_category.hpp"
51 inline static std::string_view logger_name =
"ores.qt.change_reason_cache";
53 [[nodiscard]]
static auto& lg() {
55 static auto instance = make_logger(logger_name);
61 QObject* parent =
nullptr);
85 const std::vector<dq::domain::change_reason>&
allReasons()
const {
96 const std::string& category_code)
const;
105 const std::string& category_code)
const;
114 const std::string& category_code)
const;
123 const std::string& code)
const;
136 const std::vector<dq::domain::change_reason_category>&
allCategories()
const {
157 void onReasonsLoaded();
158 void onCategoriesLoaded();
159 void onNotificationReceived(
const QString& eventType,
160 const QDateTime& timestamp,
const QStringList& entityIds,
161 const QString& tenantId);
165 void loadCategories();
166 void subscribeToEvents();
168 struct ReasonsResult {
170 std::vector<dq::domain::change_reason> reasons;
173 struct CategoriesResult {
175 std::vector<dq::domain::change_reason_category> categories;
178 ClientManager* clientManager_;
181 std::vector<dq::domain::change_reason> reasons_;
182 std::vector<dq::domain::change_reason_category> categories_;
185 std::unordered_map<std::string, std::size_t> reason_index_;
188 bool is_loaded_{
false};
189 bool is_loading_{
false};
190 bool reasons_loaded_{
false};
191 bool categories_loaded_{
false};
193 QFutureWatcher<ReasonsResult>* reasons_watcher_;
194 QFutureWatcher<CategoriesResult>* categories_watcher_;
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
Defines a specific reason for record changes.
Definition change_reason.hpp:48
Shared cache for change reasons used across all entity dialogs.
Definition ChangeReasonCache.hpp:47
const std::vector< dq::domain::change_reason > & allReasons() const
Get all change reasons.
Definition ChangeReasonCache.hpp:85
void loaded()
Emitted when reasons and categories have been loaded.
const dq::domain::change_reason * getReasonByCode(const std::string &code) const
Get a reason by its code.
Definition ChangeReasonCache.cpp:274
std::vector< dq::domain::change_reason > getReasonsForAmend(const std::string &category_code) const
Get change reasons filtered for amend operations.
Definition ChangeReasonCache.cpp:236
void refreshed()
Emitted when the cache is refreshed due to server event.
std::vector< dq::domain::change_reason > getReasonsForNew(const std::string &category_code) const
Get change reasons filtered for new record creation.
Definition ChangeReasonCache.cpp:218
bool isValidReasonCode(const std::string &code) const
Check if a reason code is valid.
Definition ChangeReasonCache.cpp:284
bool isLoading() const
Check if loading is in progress.
Definition ChangeReasonCache.hpp:80
const std::vector< dq::domain::change_reason_category > & allCategories() const
Get all change reason categories.
Definition ChangeReasonCache.hpp:136
std::vector< dq::domain::change_reason > getReasonsForDelete(const std::string &category_code) const
Get change reasons filtered for delete operations.
Definition ChangeReasonCache.cpp:255
void loadAll()
Load all change reasons and categories from the server.
Definition ChangeReasonCache.cpp:82
void loadError(const QString &error_message)
Emitted when an error occurs during loading.
bool isLoaded() const
Check if reasons have been loaded.
Definition ChangeReasonCache.hpp:75
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109