Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Релиз 2024.1 #35

Merged
merged 5 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ jobs:
run: mvn --batch-mode clean test

- name: Test Coverage
uses: codecov/codecov-action@v3
uses: codecov/[email protected]
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: SonarCloud Analyze
run: >
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<lombok.version>1.18.28</lombok.version>
<checkerframework.version>3.34.0</checkerframework.version>
<lombok.version>1.18.30</lombok.version>
<checkerframework.version>3.42.0</checkerframework.version>
</properties>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public abstract class AbstractTransaction {
protected final @Nullable BigDecimal value; // стоимость в валюте цены, null для зачисления и списания ЦБ
@EqualsAndHashCode.Exclude
protected final @Nullable BigDecimal fee;
protected final String valueCurrency; // валюта платежа
protected final String feeCurrency; // валюта комиссии
protected final @Nullable String valueCurrency; // валюта платежа. Обязателен, если заполнен value
protected final @Nullable String feeCurrency; // валюта комиссии. Обязателен, если заполнен fee


@SuppressWarnings("unused")
Expand All @@ -76,7 +76,7 @@ public List<TransactionCashFlow> getTransactionCashFlows() {
}

protected Optional<TransactionCashFlow> getValueCashFlow(CashFlowType type) {
if (value != null && Math.abs(value.floatValue()) >= 0.0001) {
if (value != null && valueCurrency != null && isNotZero(value)) {
return Optional.of(TransactionCashFlow.builder()
.transactionId(id)
.eventType(type)
Expand All @@ -88,7 +88,7 @@ protected Optional<TransactionCashFlow> getValueCashFlow(CashFlowType type) {
}

protected Optional<TransactionCashFlow> getFeeCashFlow() {
if (fee != null && Math.abs(fee.floatValue()) >= 0.0001) {
if (fee != null && feeCurrency != null && isNotZero(fee)) {
return Optional.of(TransactionCashFlow.builder()
.transactionId(id)
.eventType(FEE)
Expand All @@ -99,6 +99,10 @@ protected Optional<TransactionCashFlow> getFeeCashFlow() {
return Optional.empty();
}

protected boolean isNotZero(BigDecimal value) {
return Math.abs(value.floatValue()) > 0.000_000_99f;
}

@EqualsAndHashCode.Include
@SuppressWarnings("unused")
private @Nullable BigDecimal getValueForEquals() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ protected Optional<TransactionCashFlow> getValueInPointsCashFlow() {

@Override
protected Optional<TransactionCashFlow> getValueCashFlow(CashFlowType type) {
if (value != null) {
if (value != null && valueCurrency != null) {
return Optional.of(TransactionCashFlow.builder()
.transactionId(id)
.eventType(type)
.value(value)
.value(value) // zero value is permitted
.currency(valueCurrency)
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
@EqualsAndHashCode(callSuper = true, cacheStrategy = LAZY)
public class SecurityTransaction extends AbstractTransaction {
@EqualsAndHashCode.Exclude
private final @Nullable BigDecimal accruedInterest; // НКД, в валюте бумаги
private final @Nullable BigDecimal accruedInterest; // НКД, в валюте бумаги. Если задано, то поле valueCurrency обязательно

@Override
public List<TransactionCashFlow> getTransactionCashFlows() {
Expand All @@ -52,7 +52,7 @@ public List<TransactionCashFlow> getTransactionCashFlows() {

private Optional<TransactionCashFlow> getAccruedInterestCashFlow() {
// for securities accrued interest = 0
if (accruedInterest != null && Math.abs(accruedInterest.floatValue()) >= 0.0001) {
if (accruedInterest != null && valueCurrency != null && isNotZero(accruedInterest)) {
return Optional.of(TransactionCashFlow.builder()
.transactionId(id)
.eventType(CashFlowType.ACCRUED_INTEREST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.time.Instant;
import java.util.List;

import static java.util.Objects.requireNonNull;
import static nl.jqno.equalsverifier.Warning.STRICT_INHERITANCE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.spacious_team.broker.pojo.CashFlowType.*;
Expand Down Expand Up @@ -105,6 +106,7 @@ void getTransactionCashFlows_valueIsZero() {
void getTransactionCashFlows_valueIsNull() {
DerivativeTransaction tr = this.tr.toBuilder()
.value(null)
.valueCurrency(null)
.build();
expectedCashFlows(tr,
getValueInPointsCashFlow(tr),
Expand All @@ -125,6 +127,7 @@ void getTransactionCashFlows_feeIsZero() {
void getTransactionCashFlows_feeIsNull() {
DerivativeTransaction tr = this.tr.toBuilder()
.fee(null)
.feeCurrency(null)
.build();
expectedCashFlows(tr,
getValueInPointsCashFlow(tr),
Expand All @@ -136,7 +139,7 @@ private TransactionCashFlow getValueInPointsCashFlow(DerivativeTransaction trans
return TransactionCashFlow.builder()
.transactionId(transaction.getId())
.eventType(DERIVATIVE_QUOTE)
.value(transaction.getValueInPoints())
.value(requireNonNull(transaction.getValueInPoints()))
.currency(DerivativeTransaction.QUOTE_CURRENCY)
.build();
}
Expand All @@ -146,8 +149,8 @@ private TransactionCashFlow getValueCashFlow(DerivativeTransaction transaction)
return TransactionCashFlow.builder()
.transactionId(transaction.getId())
.eventType(DERIVATIVE_PRICE)
.value(transaction.getValue())
.currency(transaction.getValueCurrency())
.value(requireNonNull(transaction.getValue()))
.currency(requireNonNull(transaction.getValueCurrency()))
.build();
}

Expand All @@ -156,8 +159,8 @@ private TransactionCashFlow getFeeCashFlow(DerivativeTransaction transaction) {
return TransactionCashFlow.builder()
.transactionId(transaction.getId())
.eventType(FEE)
.value(transaction.getFee())
.currency(transaction.getFeeCurrency())
.value(requireNonNull(transaction.getFee()))
.currency(requireNonNull(transaction.getFeeCurrency()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.time.Instant;
import java.util.List;

import static java.util.Objects.requireNonNull;
import static nl.jqno.equalsverifier.Warning.STRICT_INHERITANCE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.spacious_team.broker.pojo.CashFlowType.FEE;
Expand Down Expand Up @@ -80,6 +81,7 @@ void getTransactionCashFlows_valueIsZero() {
void getTransactionCashFlows_valueIsNull() {
ForeignExchangeTransaction tr = this.tr.toBuilder()
.value(null)
.valueCurrency(null)
.build();
expectedCashFlows(tr, getFeeCashFlow(tr));
}
Expand All @@ -96,6 +98,7 @@ void getTransactionCashFlows_feeIsZero() {
void getTransactionCashFlows_feeIsNull() {
ForeignExchangeTransaction tr = this.tr.toBuilder()
.fee(null)
.feeCurrency(null)
.build();
expectedCashFlows(tr, getValueCashFlow(tr));
}
Expand All @@ -105,8 +108,8 @@ private TransactionCashFlow getValueCashFlow(ForeignExchangeTransaction transact
return TransactionCashFlow.builder()
.transactionId(transaction.getId())
.eventType(PRICE)
.value(transaction.getValue())
.currency(transaction.getValueCurrency())
.value(requireNonNull(transaction.getValue()))
.currency(requireNonNull(transaction.getValueCurrency()))
.build();
}

Expand All @@ -115,8 +118,8 @@ private TransactionCashFlow getFeeCashFlow(ForeignExchangeTransaction transactio
return TransactionCashFlow.builder()
.transactionId(transaction.getId())
.eventType(FEE)
.value(transaction.getFee())
.currency(transaction.getFeeCurrency())
.value(requireNonNull(transaction.getFee()))
.currency(requireNonNull(transaction.getFeeCurrency()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.time.Instant;
import java.util.List;

import static java.util.Objects.requireNonNull;
import static nl.jqno.equalsverifier.Warning.STRICT_INHERITANCE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.spacious_team.broker.pojo.CashFlowType.*;
Expand Down Expand Up @@ -83,6 +84,7 @@ void getTransactionCashFlows_accruedInterestIsZero() {
void getTransactionCashFlows_accruedInterestIsNull() {
SecurityTransaction tr = this.tr.toBuilder()
.accruedInterest(null)
// can't set "valueCurrency(null)", "valueCurrency" is used by not null "value" field
.build();
expectedCashFlows(tr,
getValueCashFlow(tr),
Expand All @@ -103,6 +105,7 @@ void getTransactionCashFlows_valueIsZero() {
void getTransactionCashFlows_valueIsNull() {
SecurityTransaction tr = this.tr.toBuilder()
.value(null)
// can't set "valueCurrency(null)", "valueCurrency" is used by not null "accruedInterest" field
.build();
expectedCashFlows(tr,
getAccruedInterestCashFlow(tr),
Expand All @@ -123,6 +126,7 @@ void getTransactionCashFlows_feeIsZero() {
void getTransactionCashFlows_feeIsNull() {
SecurityTransaction tr = this.tr.toBuilder()
.fee(null)
.feeCurrency(null)
.build();
expectedCashFlows(tr,
getValueCashFlow(tr),
Expand All @@ -134,8 +138,8 @@ private TransactionCashFlow getAccruedInterestCashFlow(SecurityTransaction trans
return TransactionCashFlow.builder()
.transactionId(transaction.getId())
.eventType(ACCRUED_INTEREST)
.value(transaction.getAccruedInterest())
.currency(transaction.getValueCurrency())
.value(requireNonNull(transaction.getAccruedInterest()))
.currency(requireNonNull(transaction.getValueCurrency()))
.build();
}

Expand All @@ -144,8 +148,8 @@ private TransactionCashFlow getValueCashFlow(SecurityTransaction transaction) {
return TransactionCashFlow.builder()
.transactionId(transaction.getId())
.eventType(PRICE)
.value(transaction.getValue())
.currency(transaction.getValueCurrency())
.value(requireNonNull(transaction.getValue()))
.currency(requireNonNull(transaction.getValueCurrency()))
.build();
}

Expand All @@ -154,8 +158,8 @@ private TransactionCashFlow getFeeCashFlow(SecurityTransaction transaction) {
return TransactionCashFlow.builder()
.transactionId(transaction.getId())
.eventType(FEE)
.value(transaction.getFee())
.currency(transaction.getFeeCurrency())
.value(requireNonNull(transaction.getFee()))
.currency(requireNonNull(transaction.getFeeCurrency()))
.build();
}

Expand Down
Loading