Skip to content

Commit

Permalink
allow null for trade currencies if value is null
Browse files Browse the repository at this point in the history
  • Loading branch information
vananiev committed Jan 6, 2024
1 parent c14a94f commit ef12113
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 25 deletions.
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 && Math.abs(value.floatValue()) >= 0.0001) {
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 && Math.abs(fee.floatValue()) >= 0.0001) {
return Optional.of(TransactionCashFlow.builder()
.transactionId(id)
.eventType(FEE)
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; // НКД, в валюте бумаги. Если задано, то поле currency обязательно

@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 && Math.abs(accruedInterest.floatValue()) >= 0.0001) {
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)
.valueCurrency(null)
.build();
expectedCashFlows(tr,
getValueCashFlow(tr),
Expand All @@ -103,6 +105,7 @@ void getTransactionCashFlows_valueIsZero() {
void getTransactionCashFlows_valueIsNull() {
SecurityTransaction tr = this.tr.toBuilder()
.value(null)
.valueCurrency(null)
.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

0 comments on commit ef12113

Please sign in to comment.