FOSSredder 0.5.0
Loading...
Searching...
No Matches
Analysis.cpp
Go to the documentation of this file.
1
5
7
8#include <utility>
9
10#include <nlohmann/json.hpp>
11
12namespace core::domain {
13
14Analysis::Analysis() = default;
15
17 name_ = std::move(value.value());
18}
19
20void Analysis::rename(std::string value) {
21 rename(EntityName(std::move(value)));
22}
23
25 type_ = std::move(value.value());
26}
27
28void Analysis::setType(std::string value) {
29 setType(AnalysisType(std::move(value)));
30}
31
32void Analysis::setConfigJson(std::string value) {
33 configJson_ = std::move(value);
34}
35
37 filterSpec_ = std::move(value.value());
38}
39
40void Analysis::setFilterSpec(std::string value) {
41 setFilterSpec(FilterSpec(std::move(value)));
42}
43
45 exportFormat_ = std::move(value.value());
46}
47
48void Analysis::setExportFormat(std::string value) {
49 setExportFormat(ExportFormat(std::move(value)));
50}
51
53 includeCalculationAdjustments_ = value;
54}
55
56void Analysis::setExportStateJson(std::string value) {
57 exportStateJson_ = std::move(value);
58}
59
61 try {
62 auto parsed = nlohmann::json::parse(value);
63 if (parsed.is_array()) {
64 bool allStrings = true;
65 for (const auto& item : parsed) {
66 if (!item.is_string()) {
67 allStrings = false;
68 break;
69 }
70 }
71 if (allStrings) {
72 nlohmann::json normalized = nlohmann::json::array();
73 for (const auto& item : parsed) {
74 nlohmann::json row;
75 row["transactionId"] = item.get<std::string>();
76 normalized.push_back(std::move(row));
77 }
78 value = normalized.dump();
79 }
80 } else if (parsed.is_object()) {
81 auto it = parsed.find("transactions");
82 if (it != parsed.end() && it->is_array()) {
83 bool allStrings = true;
84 for (const auto& item : *it) {
85 if (!item.is_string()) {
86 allStrings = false;
87 break;
88 }
89 }
90 if (allStrings) {
91 nlohmann::json normalizedRows = nlohmann::json::array();
92 for (const auto& item : *it) {
93 nlohmann::json row;
94 row["transactionId"] = item.get<std::string>();
95 normalizedRows.push_back(std::move(row));
96 }
97 parsed["transactions"] = std::move(normalizedRows);
98 value = parsed.dump();
99 }
100 }
101 }
102 } catch (...) {
103 }
104 snapshotTransactionsJson_ = std::move(value);
105}
106
108 adjustments_.clear();
109}
110
111void Analysis::setAdjustment(std::string key, double value) {
113 if (key.empty()) {
114 return;
115 }
116 adjustments_[std::move(key)] = value;
117}
118
119void Analysis::removeAdjustment(const std::string& key) {
120 const auto normalized = core::domain::policies::analysis::normalizeKey(key);
121 adjustments_.erase(normalized);
122}
123
124bool Analysis::hasAdjustment(const std::string& key) const {
125 const auto normalized = core::domain::policies::analysis::normalizeKey(key);
126 return adjustments_.find(normalized) != adjustments_.end();
127}
128
129std::size_t Analysis::adjustmentCount() const noexcept {
130 return adjustments_.size();
131}
132
133bool Analysis::hasType() const noexcept {
135}
136
137bool Analysis::hasExportFormat() const noexcept {
138 return !core::domain::ExportFormat::normalize(exportFormat_).empty();
139}
140
141bool Analysis::hasConfig() const noexcept {
142 return !configJson_.empty();
143}
144
145bool Analysis::hasFilterSpec() const noexcept {
146 return !FilterSpec::normalize(filterSpec_).empty();
147}
148
150 return !snapshotTransactionsJson_.empty();
151}
152
153bool Analysis::isReadyForExport() const noexcept {
154 return policies::analysis::isExportable(type_, exportFormat_);
155}
156
157bool Analysis::isConfigured() const noexcept {
158 return policies::analysis::isConfigured(type_, configJson_, filterSpec_, exportFormat_);
159}
160
161bool Analysis::isTabular() const noexcept {
163}
164
165bool Analysis::isChartLike() const noexcept {
167}
168
169bool Analysis::supportsExportFormat(const std::string& candidate) const {
170 const auto normalized = ExportFormat::normalize(candidate);
171 if (normalized.empty()) {
172 return false;
173 }
174 return exportFormat_.empty() || exportFormat_ == normalized;
175}
176
177bool Analysis::hasAdjustments() const noexcept {
178 return !adjustments_.empty();
179}
180
181bool Analysis::isResultReady() const noexcept {
182 return hasSnapshotTransactions() || hasConfig() || hasType();
183}
184
185std::string Analysis::executionType() const {
187}
188
189std::string Analysis::outputType() const {
190 return policies::analysis::resolveOutputType(type_, configJson_);
191}
192
193const std::string& Analysis::id() const noexcept { return id_; }
194const std::string& Analysis::name() const noexcept { return name_; }
195const std::string& Analysis::type() const noexcept { return type_; }
196const std::string& Analysis::configJson() const noexcept { return configJson_; }
197const std::string& Analysis::filterSpec() const noexcept { return filterSpec_; }
198const std::string& Analysis::exportFormat() const noexcept { return exportFormat_; }
199const bool& Analysis::includeCalculationAdjustments() const noexcept { return includeCalculationAdjustments_; }
200const std::string& Analysis::exportStateJson() const noexcept { return exportStateJson_; }
201const std::string& Analysis::snapshotTransactionsJson() const noexcept { return snapshotTransactionsJson_; }
202const std::unordered_map<std::string, double>& Analysis::adjustments() const noexcept { return adjustments_; }
203const std::string& Analysis::createdAt() const noexcept { return createdAt_; }
204const std::string& Analysis::updatedAt() const noexcept { return updatedAt_; }
205void Analysis::setId(std::string value) { id_ = std::move(value); }
206void Analysis::setCreatedAt(std::string value) { createdAt_ = std::move(value); }
207void Analysis::setUpdatedAt(std::string value) { updatedAt_ = std::move(value); }
208
209} // namespace core::domain
Domain model for persisted analysis definitions.
bool isResultReady() const noexcept
Checks whether the analysis has enough data to represent a result.
Definition Analysis.cpp:181
std::string outputType() const
Resolves the effective output type for the analysis.
Definition Analysis.cpp:189
bool isChartLike() const noexcept
Checks whether the analysis type is chart-like.
Definition Analysis.cpp:165
bool isTabular() const noexcept
Checks whether the analysis type is tabular.
Definition Analysis.cpp:161
void rename(EntityName value)
Renames the analysis with normalized entity text.
Definition Analysis.cpp:16
bool hasType() const noexcept
Checks whether the analysis has a valid type.
Definition Analysis.cpp:133
const std::string & filterSpec() const noexcept
Definition Analysis.cpp:197
void setAdjustment(std::string key, double value)
Sets or updates a normalized adjustment entry.
Definition Analysis.cpp:111
void setCreatedAt(std::string value)
Definition Analysis.cpp:206
const std::string & createdAt() const noexcept
Definition Analysis.cpp:203
void setExportStateJson(std::string value)
Stores the export state JSON snapshot.
Definition Analysis.cpp:56
void setType(AnalysisType value)
Sets the analysis type from a value object.
Definition Analysis.cpp:24
void removeAdjustment(const std::string &key)
Removes a normalized adjustment entry.
Definition Analysis.cpp:119
const std::string & configJson() const noexcept
Definition Analysis.cpp:196
const std::string & snapshotTransactionsJson() const noexcept
Definition Analysis.cpp:201
std::size_t adjustmentCount() const noexcept
Returns the number of adjustments.
Definition Analysis.cpp:129
const std::string & name() const noexcept
Definition Analysis.cpp:194
const std::string & exportFormat() const noexcept
Definition Analysis.cpp:198
const std::string & id() const noexcept
Definition Analysis.cpp:193
bool isReadyForExport() const noexcept
Checks whether the analysis is ready to export.
Definition Analysis.cpp:153
bool hasSnapshotTransactions() const noexcept
Checks whether snapshot transactions are present.
Definition Analysis.cpp:149
bool hasFilterSpec() const noexcept
Checks whether a filter specification exists.
Definition Analysis.cpp:145
void setUpdatedAt(std::string value)
Definition Analysis.cpp:207
const std::string & exportStateJson() const noexcept
Definition Analysis.cpp:200
bool hasConfig() const noexcept
Checks whether configuration JSON exists.
Definition Analysis.cpp:141
bool hasAdjustment(const std::string &key) const
Checks whether an adjustment exists.
Definition Analysis.cpp:124
void setSnapshotTransactionsJson(std::string value)
Stores the snapshot transactions JSON.
Definition Analysis.cpp:60
void setId(std::string value)
Definition Analysis.cpp:205
void setExportFormat(ExportFormat value)
Sets the export format from a value object.
Definition Analysis.cpp:44
std::string executionType() const
Resolves the effective execution type for the analysis.
Definition Analysis.cpp:185
const bool & includeCalculationAdjustments() const noexcept
Definition Analysis.cpp:199
void setFilterSpec(FilterSpec value)
Sets the filter specification from a value object.
Definition Analysis.cpp:36
void setConfigJson(std::string value)
Stores the raw configuration JSON.
Definition Analysis.cpp:32
const std::unordered_map< std::string, double > & adjustments() const noexcept
Definition Analysis.cpp:202
void clearAdjustments()
Clears all adjustment entries.
Definition Analysis.cpp:107
const std::string & updatedAt() const noexcept
Definition Analysis.cpp:204
bool isConfigured() const noexcept
Checks whether the analysis is configured sufficiently for processing.
Definition Analysis.cpp:157
const std::string & type() const noexcept
Definition Analysis.cpp:195
void setIncludeCalculationAdjustments(bool value)
Enables or disables calculation adjustments.
Definition Analysis.cpp:52
bool hasExportFormat() const noexcept
Checks whether the analysis has a valid export format.
Definition Analysis.cpp:137
bool supportsExportFormat(const std::string &candidate) const
Checks whether a candidate export format matches this analysis.
Definition Analysis.cpp:169
bool hasAdjustments() const noexcept
Checks whether at least one adjustment exists.
Definition Analysis.cpp:177
const std::string & value() const noexcept
const std::string & value() const noexcept
static std::string normalize(std::string value)
Trims leading and trailing whitespace from an export format.
const std::string & value() const noexcept
const std::string & value() const noexcept
static std::string normalize(std::string value)
Trims leading and trailing whitespace from a filter specification.
bool isConfigured(const std::string &type, const std::string &configJson, const std::string &filterSpec, const std::string &exportFormat)
Checks whether an analysis is sufficiently configured.
bool isExportable(const std::string &type, const std::string &exportFormat)
Checks whether an analysis type can be exported.
bool supportsResultType(const std::string &type)
Checks whether an analysis type is supported at all.
std::string resolveOutputType(const std::string &type, const std::string &configJson)
Resolves the effective output type for an analysis.
bool isChartLikeType(const std::string &type)
Checks whether an analysis type produces chart-like output.
bool isTabularType(const std::string &type)
Checks whether an analysis type produces tabular output.
std::string resolveExecutionType(const std::string &type)
Resolves the effective execution type for an analysis.
std::string normalizeKey(std::string key)
Normalizes filter keys used by analysis adjustments.