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"
31#include "ores.qt/export.hpp"
52 inline static std::string_view logger_name =
"ores.qt.change_reason_cache";
54 [[nodiscard]]
static auto& lg() {
56 static auto instance = make_logger(logger_name);
62 QObject* parent =
nullptr);
86 const std::vector<dq::domain::change_reason>&
allReasons()
const {
96 std::vector<dq::domain::change_reason> getReasonsForNew(
97 const std::string& category_code)
const;
105 std::vector<dq::domain::change_reason> getReasonsForAmend(
106 const std::string& category_code)
const;
114 std::vector<dq::domain::change_reason> getReasonsForDelete(
115 const std::string& category_code)
const;
124 const std::string& code)
const;
132 bool isValidReasonCode(
const std::string& code)
const;
137 const std::vector<dq::domain::change_reason_category>&
allCategories()
const {
158 void onReasonsLoaded();
159 void onCategoriesLoaded();
160 void onNotificationReceived(
const QString& eventType,
161 const QDateTime& timestamp,
const QStringList& entityIds,
162 const QString& tenantId);
166 void loadCategories();
167 void subscribeToEvents();
169 struct ReasonsResult {
171 std::vector<dq::domain::change_reason> reasons;
174 struct CategoriesResult {
176 std::vector<dq::domain::change_reason_category> categories;
179 ClientManager* clientManager_;
182 std::vector<dq::domain::change_reason> reasons_;
183 std::vector<dq::domain::change_reason_category> categories_;
186 std::unordered_map<std::string, std::size_t> reason_index_;
189 bool is_loaded_{
false};
190 bool is_loading_{
false};
191 bool reasons_loaded_{
false};
192 bool categories_loaded_{
false};
194 QFutureWatcher<ReasonsResult>* reasons_watcher_;
195 QFutureWatcher<CategoriesResult>* categories_watcher_;
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32
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:48
const std::vector< dq::domain::change_reason > & allReasons() const
Get all change reasons.
Definition ChangeReasonCache.hpp:86
void loaded()
Emitted when reasons and categories have been loaded.
void refreshed()
Emitted when the cache is refreshed due to server event.
bool isLoading() const
Check if loading is in progress.
Definition ChangeReasonCache.hpp:81
const std::vector< dq::domain::change_reason_category > & allCategories() const
Get all change reason categories.
Definition ChangeReasonCache.hpp:137
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:76
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:123