From 6e942ce925d9de06dfa7496689a12e029b8027e3 Mon Sep 17 00:00:00 2001 From: Vitalii Ananev Date: Sat, 13 Nov 2021 23:52:10 +0300 Subject: [PATCH 1/6] add BrokerReportFactory.canCreate() method --- .../report_parser/api/AbstractBrokerReportFactory.java | 10 ++-------- .../broker/report_parser/api/BrokerReportFactory.java | 8 ++++++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/spacious_team/broker/report_parser/api/AbstractBrokerReportFactory.java b/src/main/java/org/spacious_team/broker/report_parser/api/AbstractBrokerReportFactory.java index d96071e..c47fc94 100644 --- a/src/main/java/org/spacious_team/broker/report_parser/api/AbstractBrokerReportFactory.java +++ b/src/main/java/org/spacious_team/broker/report_parser/api/AbstractBrokerReportFactory.java @@ -29,14 +29,8 @@ public abstract class AbstractBrokerReportFactory implements BrokerReportFactory /** * @param expectedFileNamePattern used for fast report check without input stream reading */ - protected BrokerReport create(Pattern expectedFileNamePattern, - String excelFileName, - InputStream is, - BiFunction brokerReportProvider) { - if (expectedFileNamePattern.matcher(excelFileName).matches()) { - return create(excelFileName, is, brokerReportProvider); - } - return null; + protected boolean canCreate(Pattern expectedFileNamePattern, String excelFileName, InputStream is) { + return expectedFileNamePattern.matcher(excelFileName).matches(); } /** diff --git a/src/main/java/org/spacious_team/broker/report_parser/api/BrokerReportFactory.java b/src/main/java/org/spacious_team/broker/report_parser/api/BrokerReportFactory.java index aeaf003..d4b2c34 100644 --- a/src/main/java/org/spacious_team/broker/report_parser/api/BrokerReportFactory.java +++ b/src/main/java/org/spacious_team/broker/report_parser/api/BrokerReportFactory.java @@ -22,6 +22,14 @@ public interface BrokerReportFactory { + /** + * Fast check if this factory can't parse report. + * Method should always reset input stream mark to original position. + * @return false when can't parse, true when parsing maybe possible + * @throws IllegalArgumentException if InputStream is not supports mark + */ + boolean canCreate(String excelFileName, InputStream is); + /** * Checks input stream and returns broker report if can, otherwise reset input stream mark to original position * and returns null From 8f954d0f7fe278c670336477a0c3faed1012eda1 Mon Sep 17 00:00:00 2001 From: Vitalii Ananev Date: Sun, 14 Nov 2021 17:17:07 +0300 Subject: [PATCH 2/6] update comment spacious-team/investbook#357 --- .../org/spacious_team/broker/pojo/PortfolioPropertyType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/spacious_team/broker/pojo/PortfolioPropertyType.java b/src/main/java/org/spacious_team/broker/pojo/PortfolioPropertyType.java index 8089d23..5b27d80 100644 --- a/src/main/java/org/spacious_team/broker/pojo/PortfolioPropertyType.java +++ b/src/main/java/org/spacious_team/broker/pojo/PortfolioPropertyType.java @@ -20,6 +20,6 @@ public enum PortfolioPropertyType { TOTAL_ASSETS_RUB, - TOTAL_ASSETS_USD, // use one of TOTAL_ASSETS_RUB or TOTAL_ASSETS_USD + TOTAL_ASSETS_USD, // if TOTAL_ASSETS_RUB and TOTAL_ASSETS_USD exists for same date, total assets is sum of them CASH } From 1719822f3427acc0c2cf8c36c5c08eb07e080d5a Mon Sep 17 00:00:00 2001 From: Vitalii Ananev Date: Fri, 19 Nov 2021 01:01:14 +0300 Subject: [PATCH 3/6] update Transaction, TransactionCashFlow spacious-team/investbook#363 --- .../org/spacious_team/broker/pojo/Transaction.java | 4 ++++ .../broker/pojo/TransactionCashFlow.java | 12 ++++++------ .../report_parser/api/AbstractTransaction.java | 4 ---- .../report_parser/api/DerivativeTransaction.java | 4 ---- .../report_parser/api/SecurityTransaction.java | 2 -- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/spacious_team/broker/pojo/Transaction.java b/src/main/java/org/spacious_team/broker/pojo/Transaction.java index 59b7292..e0f282f 100644 --- a/src/main/java/org/spacious_team/broker/pojo/Transaction.java +++ b/src/main/java/org/spacious_team/broker/pojo/Transaction.java @@ -37,6 +37,10 @@ @EqualsAndHashCode(cacheStrategy = LAZY) @Schema(name = "Сделка") public class Transaction { + //@Nullable // autoincrement + @Schema(description = "Внутренний идентификатор сделки", example = "123", required = true) + private final Integer pk; + @NotNull @Schema(description = "Номер сделки в системе учета брокера", example = "123SP", required = true) private final String id; diff --git a/src/main/java/org/spacious_team/broker/pojo/TransactionCashFlow.java b/src/main/java/org/spacious_team/broker/pojo/TransactionCashFlow.java index 5b4ecd7..ba462d3 100644 --- a/src/main/java/org/spacious_team/broker/pojo/TransactionCashFlow.java +++ b/src/main/java/org/spacious_team/broker/pojo/TransactionCashFlow.java @@ -39,14 +39,14 @@ @EqualsAndHashCode(cacheStrategy = LAZY) @Schema(name = "Движение ДС по сделке") public class TransactionCashFlow { - @NotNull - @JsonProperty("transaction-id") - @Schema(description = "Номер сделки в системе учета брокера", example = "123SP", required = true) - private final String transactionId; + //@Nullable // autoincrement + @Schema(description = "Внутренний идентификатор записи", example = "1", required = true) + private final Integer pk; @NotNull - @Schema(description = "Номер счета в системе учета брокера", example = "10200I", required = true) - private final String portfolio; + @JsonProperty("transaction-pk") + @Schema(description = "Внутренний идентификатор сделки", example = "123", required = true) + private final Integer transactionPk; @NotNull @JsonProperty("event-type") diff --git a/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java b/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java index e065b9f..f7d5f03 100644 --- a/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java +++ b/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java @@ -70,8 +70,6 @@ public List getTransactionCashFlows() { protected Optional getValueCashFlow(CashFlowType type) { if (value != null && value.abs().compareTo(minValue) >= 0) { return Optional.of(TransactionCashFlow.builder() - .transactionId(transactionId) - .portfolio(portfolio) .eventType(type) .value(value) .currency(valueCurrency) @@ -83,8 +81,6 @@ protected Optional getValueCashFlow(CashFlowType type) { protected Optional getCommissionCashFlow() { if (commission != null && commission.abs().compareTo(minValue) >= 0) { return Optional.of(TransactionCashFlow.builder() - .transactionId(transactionId) - .portfolio(portfolio) .eventType(CashFlowType.COMMISSION) .value(commission) .currency(commissionCurrency) diff --git a/src/main/java/org/spacious_team/broker/report_parser/api/DerivativeTransaction.java b/src/main/java/org/spacious_team/broker/report_parser/api/DerivativeTransaction.java index a002c33..95c9ecb 100644 --- a/src/main/java/org/spacious_team/broker/report_parser/api/DerivativeTransaction.java +++ b/src/main/java/org/spacious_team/broker/report_parser/api/DerivativeTransaction.java @@ -51,8 +51,6 @@ public List getTransactionCashFlows() { protected Optional getValueInPointsCashFlow() { if (valueInPoints != null) { return Optional.of(TransactionCashFlow.builder() - .transactionId(transactionId) - .portfolio(portfolio) .eventType(CashFlowType.DERIVATIVE_QUOTE) .value(valueInPoints) .currency(QUOTE_CURRENCY) @@ -65,8 +63,6 @@ protected Optional getValueInPointsCashFlow() { protected Optional getValueCashFlow(CashFlowType type) { if (value != null) { return Optional.of(TransactionCashFlow.builder() - .transactionId(transactionId) - .portfolio(portfolio) .eventType(type) .value(value) .currency(valueCurrency) diff --git a/src/main/java/org/spacious_team/broker/report_parser/api/SecurityTransaction.java b/src/main/java/org/spacious_team/broker/report_parser/api/SecurityTransaction.java index 3d58a6a..1d025f7 100644 --- a/src/main/java/org/spacious_team/broker/report_parser/api/SecurityTransaction.java +++ b/src/main/java/org/spacious_team/broker/report_parser/api/SecurityTransaction.java @@ -51,8 +51,6 @@ private Optional getAccruedInterestCashFlow() { // for securities accrued interest = 0 if (accruedInterest != null && accruedInterest.abs().compareTo(minValue) >= 0) { return Optional.of(TransactionCashFlow.builder() - .transactionId(transactionId) - .portfolio(portfolio) .eventType(CashFlowType.ACCRUED_INTEREST) .value(accruedInterest) .currency(valueCurrency) From ca46274c705e487538f943b28da7da928c3bd788 Mon Sep 17 00:00:00 2001 From: Vitalii Ananev Date: Fri, 19 Nov 2021 23:44:33 +0300 Subject: [PATCH 4/6] rename Transaction.id to Transaction.tradeId spacious-team/investbook#363 --- .../java/org/spacious_team/broker/pojo/Transaction.java | 6 ++++-- .../org/spacious_team/broker/pojo/TransactionCashFlow.java | 6 +++--- .../broker/report_parser/api/AbstractTransaction.java | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/spacious_team/broker/pojo/Transaction.java b/src/main/java/org/spacious_team/broker/pojo/Transaction.java index e0f282f..702b1c1 100644 --- a/src/main/java/org/spacious_team/broker/pojo/Transaction.java +++ b/src/main/java/org/spacious_team/broker/pojo/Transaction.java @@ -18,6 +18,7 @@ package org.spacious_team.broker.pojo; +import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.EqualsAndHashCode; @@ -39,11 +40,12 @@ public class Transaction { //@Nullable // autoincrement @Schema(description = "Внутренний идентификатор сделки", example = "123", required = true) - private final Integer pk; + private final Integer id; @NotNull + @JsonProperty("trade-id") @Schema(description = "Номер сделки в системе учета брокера", example = "123SP", required = true) - private final String id; + private final String tradeId; @NotNull @Schema(description = "Номер счета в системе учета брокера", example = "10200I", required = true) diff --git a/src/main/java/org/spacious_team/broker/pojo/TransactionCashFlow.java b/src/main/java/org/spacious_team/broker/pojo/TransactionCashFlow.java index ba462d3..bc409fe 100644 --- a/src/main/java/org/spacious_team/broker/pojo/TransactionCashFlow.java +++ b/src/main/java/org/spacious_team/broker/pojo/TransactionCashFlow.java @@ -41,12 +41,12 @@ public class TransactionCashFlow { //@Nullable // autoincrement @Schema(description = "Внутренний идентификатор записи", example = "1", required = true) - private final Integer pk; + private final Integer id; @NotNull - @JsonProperty("transaction-pk") + @JsonProperty("transaction-id") @Schema(description = "Внутренний идентификатор сделки", example = "123", required = true) - private final Integer transactionPk; + private final Integer transactionId; @NotNull @JsonProperty("event-type") diff --git a/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java b/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java index f7d5f03..24ef2b8 100644 --- a/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java +++ b/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java @@ -40,7 +40,7 @@ @EqualsAndHashCode(cacheStrategy = LAZY) public abstract class AbstractTransaction { protected static final BigDecimal minValue = BigDecimal.valueOf(0.01); - protected final String transactionId; + protected final String tradeId; protected final String portfolio; protected final String security; protected final Instant timestamp; @@ -52,7 +52,7 @@ public abstract class AbstractTransaction { public Transaction getTransaction() { return Transaction.builder() - .id(transactionId) + .tradeId(tradeId) .portfolio(portfolio) .security(security) .timestamp(timestamp) From eac6a03e4eec8c0849a28cbee4cd805a3bdbae23 Mon Sep 17 00:00:00 2001 From: Vitalii Ananev Date: Sat, 20 Nov 2021 00:47:13 +0300 Subject: [PATCH 5/6] update AbstractTransaction spacious-team/investbook#363 --- .../broker/report_parser/api/AbstractTransaction.java | 4 ++++ .../broker/report_parser/api/DerivativeTransaction.java | 2 ++ .../broker/report_parser/api/SecurityTransaction.java | 1 + 3 files changed, 7 insertions(+) diff --git a/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java b/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java index 24ef2b8..8070a29 100644 --- a/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java +++ b/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java @@ -40,6 +40,7 @@ @EqualsAndHashCode(cacheStrategy = LAZY) public abstract class AbstractTransaction { protected static final BigDecimal minValue = BigDecimal.valueOf(0.01); + protected final Integer id; protected final String tradeId; protected final String portfolio; protected final String security; @@ -52,6 +53,7 @@ public abstract class AbstractTransaction { public Transaction getTransaction() { return Transaction.builder() + .id(id) .tradeId(tradeId) .portfolio(portfolio) .security(security) @@ -70,6 +72,7 @@ public List getTransactionCashFlows() { protected Optional getValueCashFlow(CashFlowType type) { if (value != null && value.abs().compareTo(minValue) >= 0) { return Optional.of(TransactionCashFlow.builder() + .transactionId(id) .eventType(type) .value(value) .currency(valueCurrency) @@ -81,6 +84,7 @@ protected Optional getValueCashFlow(CashFlowType type) { protected Optional getCommissionCashFlow() { if (commission != null && commission.abs().compareTo(minValue) >= 0) { return Optional.of(TransactionCashFlow.builder() + .transactionId(id) .eventType(CashFlowType.COMMISSION) .value(commission) .currency(commissionCurrency) diff --git a/src/main/java/org/spacious_team/broker/report_parser/api/DerivativeTransaction.java b/src/main/java/org/spacious_team/broker/report_parser/api/DerivativeTransaction.java index 95c9ecb..ad16b0c 100644 --- a/src/main/java/org/spacious_team/broker/report_parser/api/DerivativeTransaction.java +++ b/src/main/java/org/spacious_team/broker/report_parser/api/DerivativeTransaction.java @@ -51,6 +51,7 @@ public List getTransactionCashFlows() { protected Optional getValueInPointsCashFlow() { if (valueInPoints != null) { return Optional.of(TransactionCashFlow.builder() + .transactionId(id) .eventType(CashFlowType.DERIVATIVE_QUOTE) .value(valueInPoints) .currency(QUOTE_CURRENCY) @@ -63,6 +64,7 @@ protected Optional getValueInPointsCashFlow() { protected Optional getValueCashFlow(CashFlowType type) { if (value != null) { return Optional.of(TransactionCashFlow.builder() + .transactionId(id) .eventType(type) .value(value) .currency(valueCurrency) diff --git a/src/main/java/org/spacious_team/broker/report_parser/api/SecurityTransaction.java b/src/main/java/org/spacious_team/broker/report_parser/api/SecurityTransaction.java index 1d025f7..ab6c036 100644 --- a/src/main/java/org/spacious_team/broker/report_parser/api/SecurityTransaction.java +++ b/src/main/java/org/spacious_team/broker/report_parser/api/SecurityTransaction.java @@ -51,6 +51,7 @@ private Optional getAccruedInterestCashFlow() { // for securities accrued interest = 0 if (accruedInterest != null && accruedInterest.abs().compareTo(minValue) >= 0) { return Optional.of(TransactionCashFlow.builder() + .transactionId(id) .eventType(CashFlowType.ACCRUED_INTEREST) .value(accruedInterest) .currency(valueCurrency) From 9bfbe74305b029323c5b6a4f04099a8f7df1f853 Mon Sep 17 00:00:00 2001 From: Vitalii Ananev Date: Sun, 21 Nov 2021 18:38:29 +0300 Subject: [PATCH 6/6] update version 2021.9 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ba96b5b..b902de7 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ org.spacious-team broker-report-parser-api - 2021.8 + 2021.9 jar Broker Report Parser API