10#include <nlohmann/json.hpp>
17 name_ = std::move(value.
value());
25 type_ = std::move(value.
value());
33 configJson_ = std::move(value);
37 filterSpec_ = std::move(value.
value());
45 exportFormat_ = std::move(value.
value());
53 includeCalculationAdjustments_ = value;
57 exportStateJson_ = std::move(value);
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()) {
72 nlohmann::json normalized = nlohmann::json::array();
73 for (
const auto& item : parsed) {
75 row[
"transactionId"] = item.get<std::string>();
76 normalized.push_back(std::move(row));
78 value = normalized.dump();
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()) {
91 nlohmann::json normalizedRows = nlohmann::json::array();
92 for (
const auto& item : *it) {
94 row[
"transactionId"] = item.get<std::string>();
95 normalizedRows.push_back(std::move(row));
97 parsed[
"transactions"] = std::move(normalizedRows);
98 value = parsed.dump();
104 snapshotTransactionsJson_ = std::move(value);
108 adjustments_.clear();
116 adjustments_[std::move(key)] = value;
121 adjustments_.erase(normalized);
126 return adjustments_.find(normalized) != adjustments_.end();
130 return adjustments_.size();
142 return !configJson_.empty();
150 return !snapshotTransactionsJson_.empty();
171 if (normalized.empty()) {
174 return exportFormat_.empty() || exportFormat_ == normalized;
178 return !adjustments_.empty();
Domain model for persisted analysis definitions.
bool isResultReady() const noexcept
Checks whether the analysis has enough data to represent a result.
std::string outputType() const
Resolves the effective output type for the analysis.
bool isChartLike() const noexcept
Checks whether the analysis type is chart-like.
bool isTabular() const noexcept
Checks whether the analysis type is tabular.
void rename(EntityName value)
Renames the analysis with normalized entity text.
bool hasType() const noexcept
Checks whether the analysis has a valid type.
const std::string & filterSpec() const noexcept
void setAdjustment(std::string key, double value)
Sets or updates a normalized adjustment entry.
void setCreatedAt(std::string value)
const std::string & createdAt() const noexcept
void setExportStateJson(std::string value)
Stores the export state JSON snapshot.
void setType(AnalysisType value)
Sets the analysis type from a value object.
void removeAdjustment(const std::string &key)
Removes a normalized adjustment entry.
const std::string & configJson() const noexcept
const std::string & snapshotTransactionsJson() const noexcept
std::size_t adjustmentCount() const noexcept
Returns the number of adjustments.
const std::string & name() const noexcept
const std::string & exportFormat() const noexcept
const std::string & id() const noexcept
bool isReadyForExport() const noexcept
Checks whether the analysis is ready to export.
bool hasSnapshotTransactions() const noexcept
Checks whether snapshot transactions are present.
bool hasFilterSpec() const noexcept
Checks whether a filter specification exists.
void setUpdatedAt(std::string value)
const std::string & exportStateJson() const noexcept
bool hasConfig() const noexcept
Checks whether configuration JSON exists.
bool hasAdjustment(const std::string &key) const
Checks whether an adjustment exists.
void setSnapshotTransactionsJson(std::string value)
Stores the snapshot transactions JSON.
void setId(std::string value)
void setExportFormat(ExportFormat value)
Sets the export format from a value object.
std::string executionType() const
Resolves the effective execution type for the analysis.
const bool & includeCalculationAdjustments() const noexcept
void setFilterSpec(FilterSpec value)
Sets the filter specification from a value object.
void setConfigJson(std::string value)
Stores the raw configuration JSON.
const std::unordered_map< std::string, double > & adjustments() const noexcept
void clearAdjustments()
Clears all adjustment entries.
const std::string & updatedAt() const noexcept
bool isConfigured() const noexcept
Checks whether the analysis is configured sufficiently for processing.
const std::string & type() const noexcept
void setIncludeCalculationAdjustments(bool value)
Enables or disables calculation adjustments.
bool hasExportFormat() const noexcept
Checks whether the analysis has a valid export format.
bool supportsExportFormat(const std::string &candidate) const
Checks whether a candidate export format matches this analysis.
bool hasAdjustments() const noexcept
Checks whether at least one adjustment exists.
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.