From bcbb5084d75577c6741f125120629a69155db07d Mon Sep 17 00:00:00 2001 From: vananiev Date: Mon, 18 Nov 2024 22:54:44 +0300 Subject: [PATCH] fix runtime exceptions for forms pages --- pom.xml | 2 +- .../ru/investbook/web/forms/model/EventCashFlowModel.java | 6 ++++-- .../ru/investbook/web/forms/model/TransactionModel.java | 6 +++--- .../web/forms/service/TransactionFormsService.java | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index ee610374..415b54a0 100644 --- a/pom.xml +++ b/pom.xml @@ -253,7 +253,7 @@ org.apache.maven.plugins maven-compiler-plugin - true + true true true diff --git a/src/main/java/ru/investbook/web/forms/model/EventCashFlowModel.java b/src/main/java/ru/investbook/web/forms/model/EventCashFlowModel.java index 6513d0c9..19c68414 100644 --- a/src/main/java/ru/investbook/web/forms/model/EventCashFlowModel.java +++ b/src/main/java/ru/investbook/web/forms/model/EventCashFlowModel.java @@ -30,6 +30,7 @@ import java.time.LocalDate; import java.time.LocalTime; +import static java.util.Objects.isNull; import static java.util.Objects.requireNonNull; import static org.spacious_team.broker.pojo.CashFlowType.*; import static org.springframework.util.StringUtils.hasLength; @@ -47,7 +48,7 @@ public class EventCashFlowModel { @DateTimeFormat(pattern = "HH:mm:ss") private @NotNull LocalTime time = LocalTime.NOON; - private @NotNull CashFlowType type; + private @NotNull CashFlowType type = CASH; /** * Negative value for cash out, otherwise - positive @@ -98,7 +99,8 @@ public void setStringType(String value) { } private boolean isValuePositive() { - return value.compareTo(BigDecimal.ZERO) >= 0; + //noinspection ConstantValue + return isNull(value) || value.compareTo(BigDecimal.ZERO) >= 0; } public boolean isAttachedToSecurity() { diff --git a/src/main/java/ru/investbook/web/forms/model/TransactionModel.java b/src/main/java/ru/investbook/web/forms/model/TransactionModel.java index 8d9f0cd3..0c384805 100644 --- a/src/main/java/ru/investbook/web/forms/model/TransactionModel.java +++ b/src/main/java/ru/investbook/web/forms/model/TransactionModel.java @@ -136,14 +136,14 @@ public String getSecurityName() { return SecurityHelper.getSecurityIsin(security); } - public String getTradeId() { + public String getOrGenerateTradeId() { if (!hasText(tradeId)) { - setTradeId(createTradeId()); + setTradeId(generateTradeId()); } return requireNonNull(tradeId, "Не задан trade-id"); } - private String createTradeId() { + private String generateTradeId() { //noinspection ConstantValue Assert.isTrue(portfolio != null && security != null && date != null && action != null, "Невалидные данные, ошибка вычисления trade-id"); diff --git a/src/main/java/ru/investbook/web/forms/service/TransactionFormsService.java b/src/main/java/ru/investbook/web/forms/service/TransactionFormsService.java index ff585bab..a735c570 100644 --- a/src/main/java/ru/investbook/web/forms/service/TransactionFormsService.java +++ b/src/main/java/ru/investbook/web/forms/service/TransactionFormsService.java @@ -176,7 +176,7 @@ public void save(TransactionModel tr) { } AbstractTransaction transaction = builder - .tradeId(tr.getTradeId()) + .tradeId(tr.getOrGenerateTradeId()) .portfolio(tr.getPortfolio()) .timestamp(tr.getDate().atTime(tr.getTime()).atZone(zoneId).toInstant()) .security(savedSecurityId)