FOSSredder 0.5.0
Loading...
Searching...
No Matches
WorkspaceSnapshotCatalogMapper.cpp
Go to the documentation of this file.
1
5
7
17
18#include <nlohmann/json.hpp>
19
20#include <memory>
21#include <utility>
22#include <vector>
23
24namespace {
25
26std::vector<core::domain::Alias> toAliases(
27 const std::vector<core::ports::workspace::AliasSnapshot>& source) {
28 std::vector<core::domain::Alias> aliases;
29 aliases.reserve(source.size());
30 for (const auto& alias : source) {
31 aliases.emplace_back(alias.value,
32 alias.kind,
33 alias.source,
34 alias.createdAt,
35 alias.updatedAt,
36 alias.hitCount,
37 alias.lastUsedAt);
38 }
39 return aliases;
40}
41
42std::string serializeSnapshotTransactionsForDomain(
43 const std::vector<core::ports::workspace::TransactionSnapshot>& source) {
44 if (source.empty()) {
45 return {};
46 }
47 nlohmann::json rows = nlohmann::json::array();
48 for (const auto& tx : source) {
49 rows.push_back(nlohmann::json{
50 {"id", tx.id},
51 {"transactionId", tx.id},
52 {"name", tx.name},
53 {"transactionName", tx.name},
54 {"bookingDate", tx.bookingDate},
55 {"date", tx.bookingDate},
56 {"valuta", tx.valuta},
57 {"amount", tx.amount},
58 {"status", tx.status},
59 {"contractId", tx.contractId},
60 {"contractType", tx.contractType},
61 {"actorId", tx.actorId},
62 {"statementId", tx.statementId},
63 {"allocatable", tx.allocatable},
64 {"propertyIds", tx.propertyIds},
65 {"propertyNames", tx.propertyNames},
66 });
67 }
68 return rows.dump();
69}
70
71} // namespace
72
74
75core::domain::catalog::WorkspaceCatalog
78
80 actors.reserve(snapshot.actors.size());
81 for (const auto& src : snapshot.actors) {
82 auto entity = std::make_shared<core::domain::Actor>();
83 entity->setId(src.id);
84 entity->rename(src.name);
85 entity->setAliases(toAliases(src.aliases));
86 entity->setContractIds(src.contractIds);
87 entity->setCreatedAt(src.createdAt);
88 entity->setUpdatedAt(src.updatedAt);
89 actors.push_back(std::move(entity));
90 }
91 state.setActors(std::move(actors));
92
94 properties.reserve(snapshot.properties.size());
95 for (const auto& src : snapshot.properties) {
96 auto entity = std::make_shared<core::domain::Property>();
97 entity->setId(src.id);
98 entity->rename(src.name);
99 entity->setAliases(toAliases(src.aliases));
100 entity->setContractIds(src.contractIds);
101 entity->setCreatedAt(src.createdAt);
102 entity->setUpdatedAt(src.updatedAt);
103 properties.push_back(std::move(entity));
104 }
105 state.setProperties(std::move(properties));
106
108 contracts.reserve(snapshot.contracts.size());
109 for (const auto& src : snapshot.contracts) {
110 auto entity = std::make_shared<core::domain::Contract>();
111 entity->setId(src.id);
112 entity->rename(src.name);
113 entity->setType(src.type);
114 entity->setAllocatableMode(src.allocatableMode);
115 entity->setActorIds(src.actorIds);
116 entity->setPropertyIds(src.propertyIds);
117 entity->setAliases(toAliases(src.aliases));
118 entity->setCreatedAt(src.createdAt);
119 entity->setUpdatedAt(src.updatedAt);
120 contracts.push_back(std::move(entity));
121 }
122 state.setContracts(std::move(contracts));
123
125 statements.reserve(snapshot.statements.size());
126 for (const auto& src : snapshot.statements) {
127 auto entity = std::make_shared<core::domain::Statement>();
128 entity->setId(src.id);
129 entity->rename(src.name);
130 entity->setTransactionIds(src.transactionIds);
131 entity->setCreatedAt(src.createdAt);
132 entity->setUpdatedAt(src.updatedAt);
133 statements.push_back(std::move(entity));
134 }
135 state.setStatements(std::move(statements));
136
138 transactions.reserve(snapshot.transactions.size());
139 for (const auto& src : snapshot.transactions) {
140 auto entity = std::make_shared<core::domain::Transaction>();
141 entity->setId(src.id);
142 entity->setName(src.name);
143 entity->setBookingDate(src.bookingDate);
144 entity->setValuta(src.valuta);
145 entity->setAmount(src.amount);
146 entity->setStatus(static_cast<core::domain::Transaction::Status>(src.status));
147 entity->setContractId(src.contractId);
148 entity->setActorId(src.actorId);
149 entity->setStatementId(src.statementId);
150 entity->setAllocatable(src.allocatable);
151 entity->setPropertyIds(src.propertyIds);
152 entity->setCreatedAt(src.createdAt);
153 entity->setUpdatedAt(src.updatedAt);
154 transactions.push_back(std::move(entity));
155 }
156 state.setTransactions(std::move(transactions));
157
159 analyses.reserve(snapshot.analyses.size());
160 for (const auto& src : snapshot.analyses) {
161 auto entity = std::make_shared<core::domain::Analysis>();
162 entity->setId(src.id);
163 entity->rename(src.name);
164 entity->setType(src.type);
165 entity->setConfigJson(core::application::analysis::buildAnalysisConfigJson(src.config));
166 entity->setFilterSpec(core::domain::FilterSpec(
168 entity->setExportFormat(src.exportFormat);
169 entity->setIncludeCalculationAdjustments(src.includeCalculationAdjustments);
170 entity->setExportStateJson({});
171 entity->setSnapshotTransactionsJson(
172 serializeSnapshotTransactionsForDomain(src.snapshotTransactions));
173 for (const auto& [key, value] : src.adjustments) {
174 entity->setAdjustment(key, value);
175 }
176 entity->setCreatedAt(src.createdAt);
177 entity->setUpdatedAt(src.updatedAt);
178 analyses.push_back(std::move(entity));
179 }
180 state.setAnalyses(std::move(analyses));
181
183 annuals.reserve(snapshot.annuals.size());
184 for (const auto& src : snapshot.annuals) {
185 auto entity = std::make_shared<core::domain::Annual>();
186 entity->setId(src.id);
187 entity->rename(src.name);
188 entity->setYear(src.year);
189 entity->setAnalysisIds(src.analysisIds);
190 entity->setCreatedAt(src.createdAt);
191 entity->setUpdatedAt(src.updatedAt);
192 annuals.push_back(std::move(entity));
193 }
194 state.setAnnuals(std::move(annuals));
195
196 return state;
197}
198
199} // namespace core::application::workspace
Domain model for actors.
Domain model for entity aliases.
Domain model for persisted analysis definitions.
Shared analysis request/config helpers for UI and application layers.
Domain model for annual aggregates.
Domain model for contracts.
Domain model for properties.
Domain model for statements.
Domain model for transactions.
Maps workspace port snapshots into internal catalog state.
EntityList< core::domain::Contract > ContractList
EntityList< core::domain::Transaction > TransactionList
void setAnnuals(AnnualList value)
Replaces all annuals in the catalog.
EntityList< core::domain::Annual > AnnualList
void setAnalyses(AnalysisList value)
Replaces all analyses in the catalog.
EntityList< core::domain::Analysis > AnalysisList
void setProperties(PropertyList value)
Replaces all properties in the catalog.
void setStatements(StatementList value)
Replaces all statements in the catalog.
EntityList< core::domain::Property > PropertyList
EntityList< core::domain::Statement > StatementList
void setActors(ActorList value)
Replaces all actors in the catalog.
void setContracts(ContractList value)
Replaces all contracts in the catalog.
void setTransactions(TransactionList value)
Replaces all transactions in the catalog.
EntityList< core::domain::Actor > ActorList
std::string buildAnalysisConfigJson(const core::ports::analysis::AnalysisConfigInput &input)
core::domain::catalog::WorkspaceCatalog toWorkspaceCatalog(const core::ports::workspace::WorkspaceSnapshot &snapshot)
std::string buildAnalysisFilterSpec(const AnalysisFilterSelection &selection)
Serializes an analysis filter selection.
std::vector< AnalysisSnapshot > analyses
std::vector< PropertySnapshot > properties
std::vector< ContractSnapshot > contracts
std::vector< StatementSnapshot > statements
std::vector< TransactionSnapshot > transactions