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 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 } 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..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; @@ -37,9 +38,14 @@ @EqualsAndHashCode(cacheStrategy = LAZY) @Schema(name = "Сделка") public class Transaction { + //@Nullable // autoincrement + @Schema(description = "Внутренний идентификатор сделки", example = "123", required = true) + 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 5b4ecd7..bc409fe 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 id; @NotNull - @Schema(description = "Номер счета в системе учета брокера", example = "10200I", required = true) - private final String portfolio; + @JsonProperty("transaction-id") + @Schema(description = "Внутренний идентификатор сделки", example = "123", required = true) + private final Integer transactionId; @NotNull @JsonProperty("event-type") 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/AbstractTransaction.java b/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java index e065b9f..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,7 +40,8 @@ @EqualsAndHashCode(cacheStrategy = LAZY) public abstract class AbstractTransaction { protected static final BigDecimal minValue = BigDecimal.valueOf(0.01); - protected final String transactionId; + protected final Integer id; + protected final String tradeId; protected final String portfolio; protected final String security; protected final Instant timestamp; @@ -52,7 +53,8 @@ public abstract class AbstractTransaction { public Transaction getTransaction() { return Transaction.builder() - .id(transactionId) + .id(id) + .tradeId(tradeId) .portfolio(portfolio) .security(security) .timestamp(timestamp) @@ -70,8 +72,7 @@ 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) + .transactionId(id) .eventType(type) .value(value) .currency(valueCurrency) @@ -83,8 +84,7 @@ 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) + .transactionId(id) .eventType(CashFlowType.COMMISSION) .value(commission) .currency(commissionCurrency) 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 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..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,8 +51,7 @@ public List getTransactionCashFlows() { protected Optional getValueInPointsCashFlow() { if (valueInPoints != null) { return Optional.of(TransactionCashFlow.builder() - .transactionId(transactionId) - .portfolio(portfolio) + .transactionId(id) .eventType(CashFlowType.DERIVATIVE_QUOTE) .value(valueInPoints) .currency(QUOTE_CURRENCY) @@ -65,8 +64,7 @@ protected Optional getValueInPointsCashFlow() { protected Optional getValueCashFlow(CashFlowType type) { if (value != null) { return Optional.of(TransactionCashFlow.builder() - .transactionId(transactionId) - .portfolio(portfolio) + .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 3d58a6a..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,8 +51,7 @@ 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) + .transactionId(id) .eventType(CashFlowType.ACCRUED_INTEREST) .value(accruedInterest) .currency(valueCurrency)