FOSSredder 0.5.0
Loading...
Searching...
No Matches
AnalysisWorkflow.cpp
Go to the documentation of this file.
1
6
8
12#include "ui/i18n/Text.h"
16
17#include <stdexcept>
18#include <utility>
19
20namespace ui {
21
23 StateSnapshotProvider stateSnapshotProvider,
24 std::shared_ptr<ui::adapters::AnalysisAdapter> analysisAdapter,
25 std::shared_ptr<core::ports::diagnostics::IErrorReporter> errorReporter,
26 QObject* parent)
27 : QObject(parent), stateSnapshotProvider_(std::move(stateSnapshotProvider)),
28 analysisAdapter_(std::move(analysisAdapter)),
29 errorReporter_(std::move(errorReporter)) {
30 if (!errorReporter_) {
31 throw std::invalid_argument("AnalysisWorkflow requires an error reporter");
32 }
33}
34
36 const QString& dateField, const QString& dateMode, const QString& year,
37 const QString& dateFrom, const QString& dateTo,
38 const QStringList& propertyIds, const QStringList& contractTypes,
39 const QString& allocatableMode) const {
40 return analysisAdapter_
41 ? analysisAdapter_->buildFilterSpec(dateField, dateMode, year,
42 dateFrom, dateTo, propertyIds,
43 contractTypes, allocatableMode)
44 : QString{};
45}
46
48 const QVariantList& transactions, const QStringList& selectedTransactionIds,
49 const QString& percentText) const {
50 if (selectedTransactionIds.isEmpty()) {
51 return {};
52 }
53 const double taxPercent =
54 analysisAdapter_ ? analysisAdapter_->parseAnalysisPercentText(percentText)
55 : 0.0;
56 return analysisAdapter_
57 ? analysisAdapter_->buildAnalysisAdjustmentAmounts(
58 transactions, selectedTransactionIds, taxPercent)
59 : QVariantMap{};
60}
61
63 const QString& analysisId, const QString& filterSpec,
64 bool includeAdjustments, const QVariantMap& adjustmentAmounts) const {
65 if (!analysisAdapter_) {
67 errorReporter_.get(),
71 return {};
72 }
73 if (!stateSnapshotProvider_) {
75 errorReporter_.get(),
79 return {};
80 }
81
84 "Analysis preview compute submitted",
85 {{"analysisId", analysisId.trimmed().toStdString()}});
86
87 try {
88 auto snapshot = stateSnapshot();
89 const auto adjustments =
90 analysisAdapter_->adjustmentAmountsFromMap(adjustmentAmounts);
91 analysisAdapter_->applyAnalysisPreviewOverrides(
92 snapshot, analysisId.trimmed().toStdString(), includeAdjustments,
93 adjustments);
94
95 const auto result = analysisAdapter_->runAnalysis(
96 snapshot,
97 analysisAdapter_->buildAnalysisRequest(analysisId, filterSpec));
98 if (!result.found) {
99 return {};
100 }
101 QVariantMap payload = analysisAdapter_->mapAnalysisResult(result);
102 payload.insert(
103 QStringLiteral("tableState"),
104 analysisAdapter_->mapAnalysisTableState(
105 analysisAdapter_->projectTableState(
106 result, adjustments, includeAdjustments,
108 return payload;
109 } catch (...) {
111 errorReporter_.get(), core::errors::ErrorSeverity::Error,
114 std::current_exception());
115 }
116 return {};
117}
118
119QVariantMap
120AnalysisWorkflow::previewTransactions(const QString& filterSpec) const {
121 if (!analysisAdapter_ || !stateSnapshotProvider_) {
122 return {};
123 }
126 "Analysis transaction preview submitted");
127 return analysisAdapter_->mapPreviewResult(
128 analysisAdapter_->previewTransactions(stateSnapshot(),
129 strings::toStdString(filterSpec)));
130}
131
133 if (!analysisAdapter_ || !stateSnapshotProvider_) {
134 return {};
135 }
136 return analysisAdapter_->mapContractTypes(
137 analysisAdapter_->contractTypes(stateSnapshot()));
138}
139
141AnalysisWorkflow::stateSnapshot() const {
142 return stateSnapshotProvider_ ? stateSnapshotProvider_()
143 : core::ports::workspace::WorkspaceSnapshot{};
144}
145
146} // namespace ui
Declares the analysis adapter used by UI workflows.
Declares the UI workflow for analysis creation and computation.
Provides shared helpers for reporting structured errors and exceptions.
Declarations for the UI Origins component.
Declares lightweight conversions between common Qt string types and standard strings.
Provides translated C++ UI strings for shell, workflow, adapter and view model code.
Declarations for the UI Trace component.
QVariantMap previewTransactions(const QString &filterSpec) const
Builds a transaction preview for the current filter.
std::function< core::ports::workspace::WorkspaceSnapshot()> StateSnapshotProvider
AnalysisWorkflow(StateSnapshotProvider stateSnapshotProvider, std::shared_ptr< ui::adapters::AnalysisAdapter > analysisAdapter, std::shared_ptr< core::ports::diagnostics::IErrorReporter > errorReporter, QObject *parent=nullptr)
Creates an analysis workflow.
QStringList contractTypes() const
Returns contract types available in the current workspace snapshot.
QVariantMap analysisAdjustmentAmountsFromPercentText(const QVariantList &transactions, const QStringList &selectedTransactionIds, const QString &percentText) const
Builds adjustment amounts from selected transactions and percent text.
QString analysisFilterSpec(const QString &dateField, const QString &dateMode, const QString &year, const QString &dateFrom, const QString &dateTo, const QStringList &propertyIds, const QStringList &contractTypes, const QString &allocatableMode) const
Builds a serialized filter specification from UI fields.
QVariantMap computeAnalysisPreview(const QString &analysisId, const QString &filterSpec, bool includeAdjustments, const QVariantMap &adjustmentAmounts) const
Computes the current analysis preview.
Defines shared structured error codes.
constexpr const char * ExceptionError
Fallback code for exception-backed errors.
constexpr const char * GenericError
Fallback code for generic structured errors.
void reportException(core::ports::diagnostics::IErrorReporter *reporter, ErrorSeverity severity, const char *origin, std::exception_ptr exception)
Report an exception through the reporter's default exception handling.
void report(core::ports::diagnostics::IErrorReporter *reporter, const ErrorEvent &event)
Report an already constructed error event when a reporter exists.
void traceWorkflow(const char *origin, std::string message, core::errors::ErrorContext context={})
Emits a workflow trace event.
Definition Trace.h:108
std::string toStdString(const QString &value)
Converts a QString to a UTF-8 encoded std::string.
QString unassignedContractType()
Label for transactions without an assigned contract type.
Definition Text.h:432
QString analysisEngineUnavailable()
Error text when the analysis runner is unavailable.
Definition Text.h:247
QString analysisViewModelUnavailable()
Error text when the analysis view model state is unavailable.
Definition Text.h:251