Skip to content

Commit

Permalink
fix nullable warns
Browse files Browse the repository at this point in the history
  • Loading branch information
vananiev committed Jan 6, 2024
1 parent 5390adf commit 0379e61
Show file tree
Hide file tree
Showing 24 changed files with 144 additions and 212 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<dependency>
<groupId>com.github.spacious-team</groupId>
<artifactId>broker-report-parser-api</artifactId>
<version>2023.1</version>
<version>ef121138c6</version>
</dependency>
<dependency>
<groupId>com.github.spacious-team</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package ru.investbook.converter;

import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spacious_team.broker.pojo.SecurityDescription;
import org.springframework.stereotype.Component;
import ru.investbook.entity.IssuerEntity;
Expand All @@ -33,7 +34,7 @@ public class SecurityDescriptionConverter implements EntityConverter<SecurityDes

@Override
public SecurityDescriptionEntity toEntity(SecurityDescription security) {
IssuerEntity issuerEntity = null;
@Nullable IssuerEntity issuerEntity = null;
if (security.getIssuer() != null) {
issuerEntity = issuerRepository.findById(security.getIssuer())
.orElseThrow(() -> new IllegalArgumentException("Эмитент c идентификатором не найден: " + security.getIssuer()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public TransactionEntity toEntity(Transaction transaction) {
.orElseThrow(() -> new IllegalArgumentException("Ценная бумага с заданным ID не найдена: " + transaction.getSecurity()));

TransactionEntity entity = new TransactionEntity();
//noinspection DataFlowIssue
entity.setId(transaction.getId());
entity.setTradeId(transaction.getTradeId());
entity.setPortfolio(transaction.getPortfolio());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package ru.investbook.repository;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
Expand All @@ -30,7 +31,7 @@ public interface SecurityDescriptionRepository extends JpaRepository<SecurityDes
JpaSpecificationExecutor<SecurityDescriptionEntity> {

@Transactional
default void createOrUpdateSector(int securityId, String sector) {
default void createOrUpdateSector(int securityId, @Nullable String sector) {
if (existsById(securityId)) {
updateSector(securityId, sector);
} else {
Expand All @@ -41,10 +42,10 @@ default void createOrUpdateSector(int securityId, String sector) {
@Transactional
@Modifying
@Query("UPDATE SecurityDescriptionEntity SET sector = :sector WHERE security = :securityId")
void updateSector(int securityId, String sector);
void updateSector(int securityId, @Nullable String sector);

@Transactional
default void createSectorIfNotExists(int securityId, String sector) {
default void createSectorIfNotExists(int securityId, @Nullable String sector) {
if (!existsById(securityId)) {
SecurityDescriptionEntity entity = new SecurityDescriptionEntity();
entity.setSecurity(securityId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public Optional<String> getFuturesShortname(@Nullable String contract) {
if (month != -1) {
char yearChar = contract.charAt(3);
if (isDigit(yearChar)) {
String prefix = codeToShortnames.get(contract.substring(0, 2));
@Nullable String prefix = codeToShortnames.get(contract.substring(0, 2));
if (prefix != null) {
int year = getShortnameYear(yearChar);
if (year != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@

package ru.investbook.web.forms.model;

import jakarta.validation.constraints.NotNull;
import lombok.Data;

import java.util.Set;

@Data
public class ArchivedPortfolioModel {

@NotNull
private Set<String> portfolios;

}
50 changes: 22 additions & 28 deletions src/main/java/ru/investbook/web/forms/model/EventCashFlowModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package ru.investbook.web.forms.model;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import lombok.Data;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand All @@ -37,47 +36,41 @@
@Data
public class EventCashFlowModel {

@Nullable
private Integer id;
private @Nullable Integer id;

@NotEmpty
private String portfolio;
private @NotEmpty String portfolio;

@NotNull
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate date = LocalDate.now();

@NotNull
@DateTimeFormat(pattern = "HH:mm:ss")
private LocalTime time = LocalTime.NOON;

@NotNull
private CashFlowType type;

/**
* Negative value for cash out, otherwise - positive
*/
@NotNull
private BigDecimal value;

@NotEmpty
private String valueCurrency = "RUB";
private @NotEmpty String valueCurrency = "RUB";

@Nullable
private String description;
private @Nullable String description;

/**
* Используется для привязки выплаты к бумаге из того же или другого счета
*/
@Nullable
private AttachedSecurity attachedSecurity = new AttachedSecurity();
private @Nullable AttachedSecurity attachedSecurity = new AttachedSecurity();

public void setValueCurrency(String currency) {
this.valueCurrency = currency.toUpperCase();
}

/**
* Used by templates/events/edit-form.html
*/
@SuppressWarnings("unused")
public String getStringType() {
if (type == null) return null;
return switch (type) {
case DIVIDEND, COUPON, REDEMPTION, AMORTIZATION, ACCRUED_INTEREST -> type.name();
case CASH -> {
Expand All @@ -87,13 +80,14 @@ public String getStringType() {
}
yield type.name() + (isValuePositive() ? "_IN" : "_OUT");
}
default -> type.name() + (isValuePositive() ? "_IN" : "_OUT");
default -> type.name() + (isValuePositive() ? "_IN" : "_OUT");
};
}

/**
* Used by templates/events/edit-form.html
*/
@SuppressWarnings("unused")
public void setStringType(String value) {
if (value.equals("TAX_IIS_A")) {
type = CashFlowType.CASH;
Expand All @@ -113,18 +107,14 @@ public boolean isAttachedToSecurity() {
@Data
public class AttachedSecurity {

@Nullable
private Integer securityEventCashFlowId;
private @Nullable Integer securityEventCashFlowId;

/**
* In "name (isin)" or "contract-name" format
*/
@Nullable
private String security;
private @Nullable String security;

@Nullable
@Positive
private Integer count;
private @Nullable @Positive Integer count;

public boolean isValid() {
return hasLength(security) &&
Expand All @@ -135,8 +125,10 @@ public boolean isValid() {
/**
* Returns ISIN if description in "Name (ISIN)" format, null otherwise
*/
public String getSecurityIsin() {
return SecurityHelper.getSecurityIsin(requireNonNull(security));
public @Nullable String getSecurityIsin() {
@SuppressWarnings("nullness")
String securityDescription = requireNonNull(security);
return SecurityHelper.getSecurityIsin(securityDescription);
}

/**
Expand All @@ -145,14 +137,16 @@ public String getSecurityIsin() {
public String getSecurityName() {
// Для Типа выплаты TAX может выдавать неверный тип бумаги,
// но для текущего алгоритма SecurityHelper.getSecurityName() типа достаточно
SecurityType securityType = switch(type) {
SecurityType securityType = switch (type) {
case DIVIDEND -> SecurityType.SHARE;
case ACCRUED_INTEREST, AMORTIZATION, REDEMPTION, COUPON -> SecurityType.BOND;
case DERIVATIVE_PROFIT, DERIVATIVE_PRICE, DERIVATIVE_QUOTE -> SecurityType.DERIVATIVE;
case TAX -> SecurityType.SHARE; // для TAX выдает не верный тип бумаги
default -> throw new IllegalArgumentException("Не смог получить тип ЦБ по типу выплаты: " + type);
};
return SecurityHelper.getSecurityName(security, securityType);
@SuppressWarnings("nullness")
String securityDescription = requireNonNull(security);
return SecurityHelper.getSecurityName(securityDescription, securityType);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package ru.investbook.web.forms.model;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
Expand All @@ -30,19 +29,14 @@
@Data
public class ForeignExchangeRateModel {

@NotNull
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate date = LocalDate.now();

@NotEmpty
private String baseCurrency;
private @NotEmpty String baseCurrency;

@NotEmpty
String quoteCurrency;
@NotEmpty String quoteCurrency;

@NotNull
@Positive
private BigDecimal rate;
private @Positive BigDecimal rate;

public void setBaseCurrency(String currency) {
this.baseCurrency = currency.toUpperCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package ru.investbook.web.forms.model;

import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.springframework.data.domain.Page;

import java.util.List;
Expand All @@ -35,18 +36,22 @@ public int getTotal() {
return page.getTotalPages();
}

@SuppressWarnings("unused")
public int getCurrent() {
return page.getNumber();
}

public Integer getNext() {
@SuppressWarnings("unused")
public @Nullable Integer getNext() {
return page.hasNext() ? page.nextPageable().getPageNumber() : null;
}

public Integer getPrevious() {
@SuppressWarnings("unused")
public @Nullable Integer getPrevious() {
return page.hasPrevious() ? page.previousPageable().getPageNumber(): null;
}

@SuppressWarnings("unused")
public boolean isLast() {
return page.isLast();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
package ru.investbook.web.forms.model;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.time.LocalDate;
Expand All @@ -33,26 +32,19 @@
@EqualsAndHashCode
public class PortfolioCashModel {

@Nullable
private Integer id;
private @Nullable Integer id;

@NotEmpty
private String portfolio;
private @NotEmpty String portfolio;

@Nullable
private String market;
private @Nullable String market;

@NotNull
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate date = LocalDate.now();

@NotNull
@DateTimeFormat(pattern = "HH:mm:ss")
private LocalTime time = LocalTime.NOON;

@NotNull
private BigDecimal cash = BigDecimal.ZERO;

@NotNull
private String currency = "RUB";
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,23 @@
package ru.investbook.web.forms.model;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.time.LocalTime;

@Data
public abstract class PortfolioPropertyModel {

@Nullable
private Integer id;
private @Nullable Integer id;

@NotEmpty
private String portfolio;
private @NotEmpty String portfolio;

@NotNull
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate date = LocalDate.now();

@NotNull
@DateTimeFormat(pattern = "HH:mm:ss")
private LocalTime time = LocalTime.NOON;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package ru.investbook.web.forms.model;

import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.spacious_team.broker.pojo.PortfolioPropertyType;
Expand All @@ -32,10 +31,8 @@
@EqualsAndHashCode(callSuper = true)
public class PortfolioPropertyTotalAssetsModel extends PortfolioPropertyModel {

@NotNull
private BigDecimal totalAssets;

@NotNull
private Currency totalAssetsCurrency;

public enum Currency {
Expand Down
Loading

0 comments on commit 0379e61

Please sign in to comment.