11#include <nlohmann/json.hpp>
24 snapshot.
id = draft.
id;
41std::string jsonString(
const nlohmann::json&
object, std::string_view key) {
42 const auto it =
object.find(std::string(key));
43 return it !=
object.end() && it->is_string() ? it->get<std::string>() : std::string{};
46double jsonDouble(
const nlohmann::json&
object, std::string_view key) {
47 const auto it =
object.find(std::string(key));
48 return it !=
object.end() && it->is_number() ? it->get<
double>() : 0.0;
51bool jsonBool(
const nlohmann::json&
object, std::string_view key) {
52 const auto it =
object.find(std::string(key));
53 return it !=
object.end() && it->is_boolean() ? it->get<
bool>() : false;
56std::vector<std::string> jsonStringList(
const nlohmann::json&
object,
57 std::string_view key) {
58 std::vector<std::string> out;
59 const auto it =
object.find(std::string(key));
60 if (it ==
object.end() || !it->is_array()) {
63 for (
const auto& item : *it) {
64 if (item.is_string()) {
65 out.push_back(item.get<std::string>());
72analysisConfigFromJson(
const std::string& raw,
const std::string& type) {
78 nlohmann::json config;
80 config = nlohmann::json::parse(raw);
84 if (!config.is_object()) {
95std::vector<core::ports::workspace::TransactionSnapshot>
96snapshotTransactionsFromJson(
const std::string& raw) {
97 std::vector<core::ports::workspace::TransactionSnapshot> out;
103 rows = nlohmann::json::parse(raw);
107 if (rows.is_object()) {
108 const auto transactions = rows.find(
"transactions");
109 rows = transactions != rows.end() ? *transactions : nlohmann::json{};
111 if (!rows.is_array()) {
114 out.reserve(rows.size());
115 for (
const auto& row : rows) {
116 if (!row.is_object()) {
120 tx.
id = jsonString(row,
"id");
122 tx.
id = jsonString(row,
"transactionId");
124 tx.
name = jsonString(row,
"name");
125 if (tx.
name.empty()) {
126 tx.
name = jsonString(row,
"transactionName");
132 tx.
valuta = jsonString(row,
"valuta");
133 tx.
amount = jsonDouble(row,
"amount");
134 tx.
status =
static_cast<int>(jsonDouble(row,
"status"));
135 tx.
contractId = jsonString(row,
"contractId");
137 tx.
actorId = jsonString(row,
"actorId");
140 tx.
propertyIds = jsonStringList(row,
"propertyIds");
142 out.push_back(std::move(tx));
153 const std::string& currentPath)
const {
166 row.
name = item->name();
170 row.
aliases.reserve(item->aliases().size());
171 for (
const auto& alias : item->aliases()) {
172 row.
aliases.push_back(projectAlias(alias));
174 snapshot.
actors.push_back(std::move(row));
185 row.
name = item->name();
189 row.
aliases.reserve(item->aliases().size());
190 for (
const auto& alias : item->aliases()) {
191 row.
aliases.push_back(projectAlias(alias));
193 snapshot.
properties.push_back(std::move(row));
204 row.
name = item->name();
205 row.
type = item->type();
211 row.
aliases.reserve(item->aliases().size());
212 for (
const auto& alias : item->aliases()) {
213 row.
aliases.push_back(projectAlias(alias));
215 snapshot.
contracts.push_back(std::move(row));
226 row.
name = item->name();
230 snapshot.
statements.push_back(std::move(row));
241 row.
name = item->name();
243 row.
valuta = item->valuta();
244 row.
amount = item->amount();
245 row.
status =
static_cast<int>(item->status());
264 row.
name = item->name();
265 row.
type = item->type();
266 row.
config = analysisConfigFromJson(item->configJson(), item->type());
273 row.
adjustments.reserve(item->adjustments().size());
274 for (
const auto& [key, value] : item->adjustments()) {
277 snapshot.
analyses.push_back(std::move(row));
288 row.
name = item->name();
289 row.
year = item->year();
293 snapshot.
annuals.push_back(std::move(row));
304 row.
name = item->name;
309 std::vector<const core::application::importing::draft::TransactionDraft*> txDrafts;
312 if (!tx || tx->statementDraftId != item->
id) {
315 txDrafts.push_back(tx.get());
317 std::sort(txDrafts.begin(), txDrafts.end(), [](
const auto* lhs,
const auto* rhs) {
318 return lhs->position < rhs->position;
322 for (
const auto* tx : txDrafts) {
323 row.
transactions.push_back(projectTransactionDraft(*tx));
344 item->statementDraftIds,
371 const std::string& draftId)
const {
372 const auto snapshot =
project(state, {});
373 if (snapshot.statementDrafts.empty()) {
377 if (draftId.empty()) {
378 return snapshot.statementDrafts.front();
381 const auto it = std::find_if(snapshot.statementDrafts.begin(), snapshot.statementDrafts.end(),
382 [&draftId](
const auto& item) {
383 return item.id == draftId;
385 if (it == snapshot.statementDrafts.end()) {
Defines stable analysis type, configuration, filter, and result keys.
Declares analysis use-case request DTOs and filter-spec helpers.
Projects internal workspace session state into immutable port snapshots.
core::ports::workspace::WorkspaceSnapshot project(const core::application::workspace::WorkspaceSessionState &state, const std::string ¤tPath) const
Builds an immutable workspace snapshot from session state.
std::optional< core::ports::workspace::StatementDraftSnapshot > projectStatementDraft(const core::application::workspace::WorkspaceSessionState &state, const std::string &draftId={}) const
Resolves a single draft snapshot from session state.
core::domain::Transaction::Status status
std::vector< uint8_t > proofImageData
std::vector< std::string > propertyIds
std::string statementDraftId
const std::string & lastUsedAt() const noexcept
const std::string & createdAt() const noexcept
int hitCount() const noexcept
const std::string & updatedAt() const noexcept
const std::string & kind() const noexcept
const std::string & value() const noexcept
const std::string & source() const noexcept
const PropertyList & properties() const noexcept
Returns all properties in the catalog.
const AnnualList & annuals() const noexcept
Returns all annuals in the catalog.
const StatementList & statements() const noexcept
Returns all statements in the catalog.
const TransactionList & transactions() const noexcept
Returns all transactions in the catalog.
const ActorList & actors() const noexcept
Returns all actors in the catalog.
const ContractList & contracts() const noexcept
Returns all contracts in the catalog.
const AnalysisList & analyses() const noexcept
Returns all analyses in the catalog.
constexpr std::string_view kPercentKey
constexpr std::string_view kPlotTypeKey
constexpr std::string_view kPropertiesKey
constexpr std::string_view kPlotMeasureKey
constexpr std::string_view kContractTypesKey
AnalysisFilterSelection parseAnalysisFilterSelection(const std::string &filterSpec)
Parses a serialized analysis filter specification.
core::domain::catalog::WorkspaceCatalog catalog
WorkspaceWorkflowState workflow
TransactionDraftList transactionDrafts
StatementDraftList statementDrafts
std::vector< AliasSnapshot > aliases
std::vector< std::string > contractIds
bool includeCalculationAdjustments
core::ports::analysis::AnalysisFilterSelection filter
core::ports::analysis::AnalysisConfigInput config
std::vector< TransactionSnapshot > snapshotTransactions
std::vector< std::pair< std::string, double > > adjustments
std::vector< std::string > analysisIds
std::vector< std::string > actorIds
std::vector< AliasSnapshot > aliases
std::string allocatableMode
std::vector< std::string > propertyIds
std::vector< std::string > contractIds
std::vector< AliasSnapshot > aliases
std::vector< std::string > transactionIds
std::vector< TransactionDraftSnapshot > transactions
std::vector< std::string > transactionIds
std::vector< std::string > propertyIds
std::string statementDraftId
std::vector< uint8_t > proofImageData
std::vector< std::string > propertyNames
std::vector< std::string > propertyIds
std::vector< AnalysisSnapshot > analyses
std::vector< PropertySnapshot > properties
std::vector< ActorSnapshot > actors
std::vector< ContractSnapshot > contracts
std::vector< StatementDraftSnapshot > statementDrafts
std::vector< StatementSnapshot > statements
std::vector< ImportLogSnapshot > importLogs
std::vector< AnnualSnapshot > annuals
std::vector< ExportLogSnapshot > exportLogs
std::vector< TransactionSnapshot > transactions