FOSSredder 0.5.0
Loading...
Searching...
No Matches
Transaction.cpp
Go to the documentation of this file.
1
5
7
8#include <algorithm>
9#include <utility>
10
11namespace core::domain {
12
13Transaction::Transaction() noexcept = default;
14
15Transaction::Transaction(std::string nameValue,
16 std::string bookingDateValue,
17 std::string valutaValue,
18 double amountValue,
19 bool allocatableValue)
20 : amount_(amountValue),
21 allocatable_(allocatableValue) {
22 setName(std::move(nameValue));
23 setBookingDate(std::move(bookingDateValue));
24 setValuta(std::move(valutaValue));
25}
26
28 name_ = std::move(value.value());
29}
30
31void Transaction::setName(std::string value) {
32 setName(EntityName(std::move(value)));
33}
34
36 bookingDate_ = std::move(value.value());
37}
38
39void Transaction::setBookingDate(std::string value) {
40 setBookingDate(BookingDate(std::move(value)));
41}
42
43void Transaction::setValuta(std::string value) {
44 valuta_ = policies::transaction::normalizeText(std::move(value));
45}
46
48 amount_ = value.value();
49}
50
51void Transaction::setAmount(double value) {
52 setAmount(MoneyAmount(value));
53}
54
56 status_ = value;
57}
58
59void Transaction::setContractId(std::string value) {
60 contractId_ = policies::transaction::normalizeId(std::move(value));
61}
62
63void Transaction::setActorId(std::string value) {
64 actorId_ = policies::transaction::normalizeId(std::move(value));
65}
66
67void Transaction::setStatementId(std::string value) {
68 statementId_ = policies::transaction::normalizeId(std::move(value));
69}
70
72 allocatable_ = value;
73}
74
76 contractId_.clear();
77}
78
80 actorId_.clear();
81}
82
84 statementId_.clear();
85}
86
88 propertyIds_.clear();
89}
90
91bool Transaction::hasStatus(Status value) const noexcept {
92 return status_ == value;
93}
94
95bool Transaction::hasStatement() const noexcept {
96 return !statementId_.empty();
97}
98
99bool Transaction::hasContract() const noexcept {
100 return !contractId_.empty();
101}
102
103bool Transaction::hasActor() const noexcept {
104 return !actorId_.empty();
105}
106
107bool Transaction::hasProperties() const noexcept {
108 return !propertyIds_.empty();
109}
110
111std::size_t Transaction::propertyCount() const noexcept {
112 return propertyIds_.size();
113}
114
115bool Transaction::belongsToStatement(const std::string& value) const {
116 return hasStatement() && statementId_ == policies::transaction::normalizeId(value);
117}
118
119bool Transaction::isAllocatable() const noexcept {
120 return allocatable_;
121}
122
124 if (core::domain::policies::transaction::statusCanAdvance(static_cast<int>(status_), static_cast<int>(Status::Unverified))) {
126 }
127}
128
130 if (core::domain::policies::transaction::statusCanAdvance(static_cast<int>(status_), static_cast<int>(Status::Verified))) {
132 }
133}
134
136 if (core::domain::policies::transaction::statusCanAdvance(static_cast<int>(status_), static_cast<int>(Status::Completed))) {
138 }
139}
140
141bool Transaction::hasRelations() const noexcept {
142 return hasStatement() || hasContract() || hasActor() || hasProperties();
143}
144
145bool Transaction::isStandalone() const noexcept {
146 return !hasRelations();
147}
148
149void Transaction::setPropertyIds(std::vector<std::string> value) {
151 propertyIds_ = std::move(value);
152}
153
154void Transaction::addPropertyId(std::string value) {
155 value = policies::transaction::normalizeId(std::move(value));
156 if (value.empty() || containsPropertyId(value)) {
157 return;
158 }
159 propertyIds_.push_back(std::move(value));
160}
161
162void Transaction::removePropertyId(const std::string& value) {
163 const auto normalized = policies::transaction::normalizeId(value);
164 propertyIds_.erase(std::remove(propertyIds_.begin(), propertyIds_.end(), normalized), propertyIds_.end());
165}
166
167bool Transaction::containsPropertyId(const std::string& value) const {
168 const auto normalized = policies::transaction::normalizeId(value);
169 return std::find(propertyIds_.begin(), propertyIds_.end(), normalized) != propertyIds_.end();
170}
171
172const std::string& Transaction::id() const noexcept { return id_; }
173const std::string& Transaction::name() const noexcept { return name_; }
174const std::string& Transaction::bookingDate() const noexcept { return bookingDate_; }
175const std::string& Transaction::valuta() const noexcept { return valuta_; }
176const double& Transaction::amount() const noexcept { return amount_; }
177const Transaction::Status& Transaction::status() const noexcept { return status_; }
178const std::string& Transaction::contractId() const noexcept { return contractId_; }
179const std::string& Transaction::actorId() const noexcept { return actorId_; }
180const std::string& Transaction::statementId() const noexcept { return statementId_; }
181const std::vector<std::string>& Transaction::propertyIds() const noexcept { return propertyIds_; }
182const std::string& Transaction::createdAt() const noexcept { return createdAt_; }
183const std::string& Transaction::updatedAt() const noexcept { return updatedAt_; }
184void Transaction::setId(std::string value) { id_ = std::move(value); }
185void Transaction::setCreatedAt(std::string value) { createdAt_ = std::move(value); }
186void Transaction::setUpdatedAt(std::string value) { updatedAt_ = std::move(value); }
187
188} // namespace core::domain
Domain model for transactions.
const std::string & value() const noexcept
const std::string & value() const noexcept
double value() const noexcept
bool hasRelations() const noexcept
Checks whether the transaction has any relations.
void clearActor()
Clears the linked actor id.
void setAmount(MoneyAmount value)
Sets the amount from a value object.
void setStatementId(std::string value)
Sets the statement id.
bool isStandalone() const noexcept
Checks whether the transaction is standalone.
void removePropertyId(const std::string &value)
Removes a property id from the transaction.
void setActorId(std::string value)
Sets the actor id.
bool containsPropertyId(const std::string &value) const
Checks whether a property id exists.
bool hasStatus(Status value) const noexcept
Checks whether the transaction has a given status.
void clearProperties()
Clears linked property ids.
void setName(EntityName value)
Sets the transaction name from a value object.
void setStatus(Status value)
Sets the transaction status.
void setValuta(std::string value)
Sets the valuta text.
void setContractId(std::string value)
Sets the contract id.
std::size_t propertyCount() const noexcept
Returns the number of linked properties.
const std::string & id() const noexcept
bool hasProperties() const noexcept
Checks whether the transaction is linked to properties.
const std::string & name() const noexcept
const std::vector< std::string > & propertyIds() const noexcept
const std::string & statementId() const noexcept
void markVerified()
Advances the transaction to verified status when allowed.
void setPropertyIds(std::vector< std::string > value)
Replaces the property id list with normalized values.
const std::string & actorId() const noexcept
void addPropertyId(std::string value)
Adds a property id when it is not already present.
const std::string & updatedAt() const noexcept
bool belongsToStatement(const std::string &value) const
Checks whether the transaction belongs to a statement.
bool isAllocatable() const noexcept
Checks whether the transaction can be allocated.
const std::string & createdAt() const noexcept
const std::string & bookingDate() const noexcept
const std::string & valuta() const noexcept
void markUnverified()
Advances the transaction to unverified status when allowed.
void markCompleted()
Advances the transaction to completed status when allowed.
bool hasActor() const noexcept
Checks whether the transaction is linked to an actor.
bool hasStatement() const noexcept
Checks whether the transaction is linked to a statement.
const Status & status() const noexcept
void setCreatedAt(std::string value)
void setBookingDate(BookingDate value)
Sets the booking date from a value object.
void setId(std::string value)
void setUpdatedAt(std::string value)
void setAllocatable(bool value)
Sets the allocatable flag.
bool hasContract() const noexcept
Checks whether the transaction is linked to a contract.
const double & amount() const noexcept
const std::string & contractId() const noexcept
void clearContract()
Clears the linked contract id.
void clearStatement()
Clears the linked statement id.
bool statusCanAdvance(int current, int next)
Checks whether a transaction status may advance.
void normalizeIds(std::vector< std::string > &values)
Normalizes and deduplicates relation ids.
std::string normalizeId(std::string value)
Normalizes a relation id.
std::string normalizeText(std::string value)
Normalizes free-form transaction text.