Skip to content

Commit

Permalink
Merge pull request #28 from spacious-team/develop
Browse files Browse the repository at this point in the history
Релиз 2022.2
  • Loading branch information
vananiev authored Feb 1, 2022
2 parents 6215f6d + aeb6c14 commit 3f2a731
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 34 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,25 @@ public class MyBrokerReportFactory extends AbstractBrokerReportFactory {
}

@Override
public BrokerReport create(String excelFileName, InputStream is) {
return super.create(expectedFileNamePattern, excelFileName, is, MyBrokerReport::new);
public boolean canCreate(String reportFileName, InputStream is) {
return super.canCreate(expectedFileNamePattern, reportFileName, is);
}

@Override
public BrokerReport create(String reportFileName, InputStream is) {
return super.create(reportFileName, is, MyBrokerReport::new);
}
}
```
Далее реализуйте интерфейс `ReportTables`, который предоставит информацию из отчета брокера в виде объектов `ReportTable`.
Пример реализации класса `ReportTables` доступен по
[ссылке](https://github.com/spacious-team/investbook/blob/develop/src/main/java/ru/investbook/parser/psb/foreignmarket/PsbForeignMarketReportTables.java)
```java
public class MyReportTables extends AbstractReportTables {
public class MyReportTables extends AbstractReportTables<MyBrokerReport> {

public MyReportTables(MyBrokerReport report) {
super(report);
}

@Override
public ReportTable<Security> getSecuritiesTable() {
Expand All @@ -91,10 +100,10 @@ public class MyReportTables extends AbstractReportTables {
[доступе](https://github.com/spacious-team/investbook/blob/develop/src/main/java/ru/investbook/parser/psb/SecuritiesTable.java).

Обратите внимание, ответ брокера может не содержать всей информации, например если брокер не предоставляет информации
о котировках, можно вернуть заглушку `EmptyReportTable`. На первом этапе вы можете парсить из отчета
брокера только часть информации, для информации, которую не парсите просто верните `EmptyReportTable`.
о котировках, можно вернуть заглушку `emptyTable()`. На первом этапе вы можете парсить из отчета
брокера только часть информации, для информации, которую не парсите просто верните заглушку.

Когда клас `ReportTables` реализован, нужно создать для него фабричный класс
Когда интерфейс `ReportTables` реализован, нужно создать для него фабричный класс
```java
public class MyReportTablesFactory implements ReportTablesFactory {
@Override
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<groupId>org.spacious-team</groupId>
<artifactId>broker-report-parser-api</artifactId>
<version>2021.10</version>
<version>2022.2</version>
<packaging>jar</packaging>

<name>Broker Report Parser API</name>
Expand Down Expand Up @@ -92,7 +92,7 @@
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.1.11</version>
<version>2.1.12</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.Instant;
Expand All @@ -46,7 +47,7 @@ public class EventCashFlow {
@Schema(description = "Идентификатор записи", example = "123", nullable = true)
private final Integer id;

@NotNull
@NotEmpty
@Schema(description = "Номер счета", example = "10200I", required = true)
private final String portfolio;

Expand All @@ -63,6 +64,7 @@ public class EventCashFlow {
@Schema(description = "Значение", example = "100.50", required = true)
private final BigDecimal value;

//@Nullable
@Builder.Default
@Schema(description = "Валюта", example = "RUB", defaultValue = "RUB", nullable = true)
private final String currency = "RUB";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;
Expand All @@ -43,7 +44,7 @@ public class ForeignExchangeRate {
@Schema(description = "Дата", example = "2021-21-23", required = true)
private final LocalDate date;

@NotNull
@NotEmpty
@JsonProperty("currency-pair")
@Schema(description = "Валютная пара, для курса доллара в рублях - USDRUB", example = "USDRUB", required = true)
private final String currencyPair;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/spacious_team/broker/pojo/Issuer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

import static lombok.EqualsAndHashCode.CacheStrategy.LAZY;
Expand All @@ -45,7 +46,7 @@ public class Issuer {
example = "7736050003", nullable = true)
private final Long taxpayerId;

@NotNull
@NotEmpty
@Schema(description = "Наименование", example = "ПАО Газпром")
private final String name;
}
3 changes: 2 additions & 1 deletion src/main/java/org/spacious_team/broker/pojo/Portfolio.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

import static lombok.EqualsAndHashCode.CacheStrategy.LAZY;
Expand All @@ -36,7 +37,7 @@
@EqualsAndHashCode(cacheStrategy = LAZY)
@Schema(name = "Счет")
public class Portfolio {
@NotNull
@NotEmpty
@Schema(description = "Номер счета в системе учета брокера", example = "10200I", required = true)
private final String id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.Instant;

Expand All @@ -44,18 +46,23 @@ public class PortfolioCash {
@Schema(description = "Внутренний идентификатор", example = "123", nullable = true)
private final Integer id;

@NotEmpty
@Schema(description = "Номер счета в системе учета брокера", example = "10200I", required = true)
private final String portfolio;

@NotNull
@Schema(description = "Значение актуально на дату", example = "2021-01-23T12:00:00+03:00", required = true)
private final Instant timestamp;

@Schema(description = "Рынок", example = "Фондовый", nullable = true)
@NotNull
@Schema(description = "Рынок", example = "Фондовый", required = true)
private final String market;

@NotNull
@Schema(description = "Остаток денежных средств", example = "102.30", required = true)
private final BigDecimal value;

@NotEmpty
@Schema(description = "Валюта", example = "RUB", required = true)
private final String currency;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.Instant;

Expand All @@ -41,7 +42,7 @@ public class PortfolioProperty {
@Schema(description = "Внутренний идентификатор записи", example = "111", nullable = true)
private final Integer id;

@NotNull
@NotEmpty
@Schema(description = "Номер счета", example = "10200I", required = true)
private final String portfolio;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.Instant;
Expand All @@ -45,7 +46,7 @@ public class SecurityEventCashFlow {
@Schema(description = "Внутренний идентификатор записи", example = "222", nullable = true)
private final Integer id;

@NotNull
@NotEmpty
@Schema(description = "Номер счета в системе учета брокера", example = "10200I", required = true)
private final String portfolio;

Expand All @@ -70,6 +71,7 @@ public class SecurityEventCashFlow {
@Schema(description = "Сумма", example = "100.20", required = true)
private final BigDecimal value;

//@Nullable
@Builder.Default
@Schema(description = "Валюта", example = "RUB", defaultValue = "RUB", nullable = true)
private final String currency = "RUR";
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/spacious_team/broker/pojo/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.Instant;

Expand All @@ -42,12 +43,12 @@ public class Transaction {
@Schema(description = "Внутренний идентификатор сделки", example = "123", nullable = true)
private final Integer id;

@NotNull
@NotEmpty
@JsonProperty("trade-id")
@Schema(description = "Номер сделки в системе учета брокера", example = "123SP", required = true)
private final String tradeId;

@NotNull
@NotEmpty
@Schema(description = "Номер счета в системе учета брокера", example = "10200I", required = true)
private final String portfolio;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class TransactionCashFlow {
@Schema(description = "Сумма по событию", example = "1000.20", required = true)
private final BigDecimal value;

//@Nullable
@Builder.Default
@Schema(description = "Валюта", example = "RUB", defaultValue = "RUB", nullable = true)
private final String currency = "RUB";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,15 @@ public interface ReportTables {

ReportTable<PortfolioProperty> getPortfolioPropertyTable();

ReportTable<PortfolioCash> getCashTable();
ReportTable<PortfolioCash> getPortfolioCashTable();

ReportTable<EventCashFlow> getCashFlowTable();

ReportTable<Security> getSecuritiesTable();

ReportTable<SecurityTransaction> getSecurityTransactionTable();
ReportTable<AbstractTransaction> getTransactionTable();

ReportTable<DerivativeTransaction> getDerivativeTransactionTable();

ReportTable<ForeignExchangeTransaction> getForeignExchangeTransactionTable();

ReportTable<SecurityEventCashFlow> getCouponAmortizationRedemptionTable();

ReportTable<SecurityEventCashFlow> getDividendTable();

ReportTable<SecurityEventCashFlow> getDerivativeCashFlowTable();
ReportTable<SecurityEventCashFlow> getSecurityEventCashFlowTable();

ReportTable<SecurityQuote> getSecurityQuoteTable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public class WrappingReportTable<RowType> implements ReportTable<RowType> {
private final ReportTable<RowType> reportTable;

@SafeVarargs
public static <T> WrappingReportTable<T> of(BrokerReport report, Collection<T>... dataset) {
public static <T> WrappingReportTable<T> of(BrokerReport report, Collection<? extends T>... dataset) {
return new WrappingReportTable<>(new EagerWrappingReportTable<>(report, dataset));
}

@SafeVarargs
public static <T> WrappingReportTable<T> of(ReportTable<T>... tables) {
public static <T> WrappingReportTable<T> of(ReportTable<? extends T>... tables) {
assertIsTrue(tables.length > 0, "Can't wrap, report tables not provided");
BrokerReport report = tables[0].getReport();
boolean isAllReportsIsSame = Arrays.stream(tables)
Expand Down Expand Up @@ -71,9 +71,9 @@ private static class EagerWrappingReportTable<RowType> implements ReportTable<Ro
private final List<RowType> data;

@SafeVarargs
public EagerWrappingReportTable(BrokerReport report, Collection<RowType>... dataset) {
public EagerWrappingReportTable(BrokerReport report, Collection<? extends RowType>... dataset) {
List<RowType> data = new ArrayList<>();
for (Collection<RowType> d : dataset) {
for (Collection<? extends RowType> d : dataset) {
data.addAll(d);
}
this.report = report;
Expand All @@ -84,11 +84,11 @@ public EagerWrappingReportTable(BrokerReport report, Collection<RowType>... data
private static class LazyWrappingReportTable<RowType> implements ReportTable<RowType> {
@Getter
private final BrokerReport report;
private volatile ReportTable<RowType>[] tables;
private volatile ReportTable<? extends RowType>[] tables;
private volatile List<RowType> data;

@SafeVarargs
private LazyWrappingReportTable(BrokerReport report, ReportTable<RowType>... tables) {
private LazyWrappingReportTable(BrokerReport report, ReportTable<? extends RowType>... tables) {
this.report = report;
this.tables = tables;
}
Expand Down

0 comments on commit 3f2a731

Please sign in to comment.