From 63bafe7720cbff4001eaa77a799783b80c4bb8e6 Mon Sep 17 00:00:00 2001
From: mr-impossibru <64555470+mr-impossibru@users.noreply.github.com>
Date: Thu, 26 May 2022 14:23:33 +0300
Subject: [PATCH 01/36] ft/TD-249/optimize db schema (#48)
* TD-249: optimise db schema, refactor, temporarily rename to daway
---
.github/workflows/build.yml | 2 +-
.github/workflows/deploy.yml | 1 +
pom.xml | 2 +-
.../newway/config/ApplicationConfig.java | 4 +-
.../dev/vality/newway/config/CacheConfig.java | 18 +-
.../vality/newway/config/SchedulerConfig.java | 2 +-
.../dao/invoicing/iface/CashFlowLinkDao.java | 22 +
.../dao/invoicing/iface/InvoiceCartDao.java | 5 +-
.../dao/invoicing/iface/InvoiceDao.java | 3 -
.../invoicing/iface/InvoiceStatusInfoDao.java | 18 +
.../iface/PaymentAdditionalInfoDao.java | 19 +
.../dao/invoicing/iface/PaymentDao.java | 5 -
.../dao/invoicing/iface/PaymentFeeDao.java | 19 +
.../invoicing/iface/PaymentPayerInfoDao.java | 16 +
.../iface/PaymentRecurrentInfoDao.java | 19 +
.../invoicing/iface/PaymentRiskDataDao.java | 19 +
.../dao/invoicing/iface/PaymentRouteDao.java | 19 +
.../invoicing/iface/PaymentStatusInfoDao.java | 18 +
.../invoicing/impl/CashFlowLinkDaoImpl.java | 124 +
...a => CashFlowLinkIdsGeneratorDaoImpl.java} | 4 +-
.../invoicing/impl/InvoiceCartDaoImpl.java | 28 +-
.../dao/invoicing/impl/InvoiceDaoImpl.java | 31 +-
.../impl/InvoiceIdsGeneratorDaoImpl.java | 29 -
.../impl/InvoiceStatusInfoDaoImpl.java | 87 +
.../impl/PaymentAdditionalInfoDaoImpl.java | 95 +
.../dao/invoicing/impl/PaymentDaoImpl.java | 47 +-
.../dao/invoicing/impl/PaymentFeeDaoImpl.java | 94 +
.../impl/PaymentPayerInfoDaoImpl.java | 60 +
.../impl/PaymentRecurrentInfoDaoImpl.java | 93 +
.../impl/PaymentRiskDataDaoImpl.java | 94 +
.../invoicing/impl/PaymentRouteDaoImpl.java | 94 +
.../impl/PaymentStatusInfoDaoImpl.java | 95 +
.../dao/invoicing/impl/RefundDaoImpl.java | 18 +-
.../dao/party/impl/RevisionDaoImpl.java | 12 +-
.../newway/dao/rate/impl/RateDaoImpl.java | 4 +-
.../factory/cash/flow/CashFlowFactory.java | 69 +
.../cash/flow/CashFlowLinkFactory.java | 26 +
.../contractor/ContractorFactory.java} | 14 +-
.../InvoicePaymentEventIdHolderFactory.java | 20 +
.../invoice/payment/PaymentFeeFactory.java | 37 +
.../invoice/payment/PaymentRouteFactory.java | 29 +
.../payment/PaymentStatusInfoFactory.java | 45 +
...AdjustmentMachineEventCopyFactoryImpl.java | 2 +-
.../ChallengeMachineEventCopyFactoryImpl.java | 2 +-
...ChargebackMachineEventCopyFactoryImpl.java | 2 +-
...tAjustmentMachineEventCopyFactoryImpl.java | 2 +-
.../DepositMachineEventCopyFactoryImpl.java | 2 +-
...ositRevertMachineEventCopyFactoryImpl.java | 2 +-
...estinationMachineEventCopyFactoryImpl.java | 2 +-
.../IdentityMachineEventCopyFactoryImpl.java | 2 +-
.../event}/MachineEventCopyFactory.java | 2 +-
.../PartyMachineEventCopyFactoryImpl.java | 2 +-
.../RecurrentPaymentToolCopyFactoryImpl.java | 2 +-
.../RefundMachineEventCopyFactoryImpl.java | 2 +-
.../SourceMachineEventCopyFactoryImpl.java | 2 +-
.../WalletMachineEventCopyFactoryImpl.java | 2 +-
...WithdrawalMachineEventCopyFactoryImpl.java | 2 +-
...walSessionMachineEventCopyFactoryImpl.java | 2 +-
.../handler/event/stock/LocalStorage.java | 18 -
.../impl/deposit/DepositCreatedHandler.java | 2 +-
.../deposit/DepositStatusChangedHandler.java | 2 +-
.../DepositTransferCreatedHandler.java | 2 +-
.../DepositTransferStatusChangedHandler.java | 2 +-
.../DepositAdjustmentCreatedHandler.java | 2 +-
...DepositAdjustmentStatusChangedHandler.java | 2 +-
...positAdjustmentTransferCreatedHandler.java | 2 +-
...djustmentTransferStatusChangedHandler.java | 2 +-
.../revert/DepositRevertCreatedHandler.java | 2 +-
.../DepositRevertStatusChangedHandler.java | 2 +-
.../DepositRevertTransferCreatedHandler.java | 2 +-
...sitRevertTransferStatusChangedHandler.java | 2 +-
.../DestinationAccountCreatedHandler.java | 2 +-
.../DestinationCreatedHandler.java | 2 +-
.../DestinationStatusChangedHandler.java | 2 +-
.../IdentityChallengeCreatedHandler.java | 2 +-
...IdentityChallengeStatusChangedHandler.java | 2 +-
.../impl/identity/IdentityCreatedHandler.java | 2 +-
...ntityEffectiveChallengeChangedHandler.java | 2 +-
.../identity/IdentityLevelChangedHandler.java | 2 +-
...nvoicePaymentAdjustmentCreatedHandler.java | 8 +-
...PaymentAdjustmentStatusChangedHandler.java | 2 +-
...cePaymentChargebackBodyChangedHandler.java | 2 +-
...ymentChargebackCashFlowChangedHandler.java | 6 +-
...nvoicePaymentChargebackCreatedHandler.java | 2 +-
...cePaymentChargebackLevyChangedHandler.java | 2 +-
...ePaymentChargebackStageChangedHandler.java | 2 +-
...PaymentChargebackStatusChangedHandler.java | 2 +-
.../InvoicePaymentRefundCreatedHandler.java | 8 +-
...dSessionChangeTransactionBoundHandler.java | 2 +-
...oicePaymentRefundStatusChangedHandler.java | 2 +-
.../contract/ContractCreatedHandler.java | 4 +-
.../contractor/ContractorCreatedHandler.java | 4 +-
.../party/PartyBlockingHandler.java | 2 +-
.../party/PartyCreatedHandler.java | 2 +-
.../party/PartyMetaSetHandler.java | 2 +-
.../party/PartyRevisionChangedHandler.java | 2 +-
.../party/PartySuspensionHandler.java | 2 +-
...currentPaymentToolHasAbandonedHandler.java | 2 +-
...ecurrentPaymentToolHasAcquiredHandler.java | 2 +-
...RecurrentPaymentToolHasCreatedHandler.java | 2 +-
.../RecurrentPaymentToolHasFailedHandler.java | 2 +-
...entPaymentToolRiskScoreChangedHandler.java | 2 +-
...currentPaymentToolRouteChangedHandler.java | 2 +-
...SessionChangedTransactionBoundHandler.java | 2 +-
.../source/SourceAccountCreatedHandler.java | 2 +-
.../impl/source/SourceCreatedHandler.java | 2 +-
.../source/SourceStatusChangedHandler.java | 2 +-
.../wallet/WalletAccountCreatedHandler.java | 2 +-
.../impl/wallet/WalletCreatedHandler.java | 2 +-
.../withdrawal/WithdrawalCreatedHandler.java | 2 +-
.../WithdrawalRouteChangeHandler.java | 2 +-
.../WithdrawalStatusChangedHandler.java | 2 +-
.../WithdrawalTransferCreatedHandler.java | 2 +-
...ithdrawalTransferStatusChangedHandler.java | 2 +-
.../WithdrawalSessionCreatedHandler.java | 2 +-
.../WithdrawalSessionFinishedHandler.java | 2 +-
.../WithdrawalSessionNextStateHandler.java | 2 +-
...hdrawalSessionTransactionBoundHandler.java | 2 +-
.../handler/wrapper/WrapperHandler.java | 11 +
.../invoice/InvoiceCartWrapperHandler.java | 47 +
.../InvoiceStatusInfoWrapperHandler.java | 53 +
.../invoice/InvoiceWrapperHandler.java | 36 +
.../payment/CashFlowWrapperHandler.java | 96 +
.../PaymentAdditionalInfoWrapperHandler.java | 37 +
.../payment/PaymentFeeWrapperHandler.java | 37 +
.../PaymentPayerInfoWrapperHandler.java | 35 +
.../PaymentRecurrentInfoWrapperHandler.java | 37 +
.../PaymentRiskDataWrapperHandler.java | 37 +
.../payment/PaymentRouteWrapperHandler.java | 37 +
.../PaymentStatusInfoWrapperHandler.java | 37 +
.../payment/PaymentWrapperHandler.java | 35 +
.../mapper/AbstractInvoicingMapper.java | 7 -
.../java/dev/vality/newway/mapper/Mapper.java | 9 +-
.../AbstractInvoicingInvoiceMapper.java | 17 -
.../mapper/invoice/InvoiceCreatedMapper.java | 104 +-
.../invoice/InvoiceStatusChangedMapper.java | 44 +-
.../AbstractInvoicingPaymentMapper.java | 32 -
.../InvoicePaymentCaptureStartedMapper.java | 62 +-
.../InvoicePaymentCashFlowChangedMapper.java | 53 +-
.../payment/InvoicePaymentCreatedMapper.java | 249 +-
.../InvoicePaymentRecTokenAcquiredMapper.java | 39 +-
.../InvoicePaymentRiskScoreChangedMapper.java | 37 +-
.../InvoicePaymentRouteChangedMapper.java | 45 +-
...ntSessionChangeTransactionBoundMapper.java | 75 +-
.../InvoicePaymentStatusChangedMapper.java | 72 +-
.../newway/{util => model}/CashFlowType.java | 6 +-
.../vality/newway/model/CashFlowWrapper.java | 17 +
.../model/InvoicePaymentEventIdHolder.java | 11 +
.../vality/newway/model/InvoiceWrapper.java | 21 +-
.../dev/vality/newway/model/PartyShop.java | 12 +
.../vality/newway/model/PaymentWrapper.java | 35 +-
.../newway/service/CashFlowService.java | 7 +-
.../newway/service/InvoiceBatchService.java | 52 -
.../newway/service/InvoiceWrapperService.java | 51 +-
.../newway/service/InvoicingService.java | 103 +-
.../newway/service/PartyShopCacheService.java | 49 +
.../newway/service/PaymentBatchService.java | 40 -
.../newway/service/PaymentSquashService.java | 74 -
.../newway/service/PaymentWrapperService.java | 85 +-
.../dev/vality/newway/util/CashFlowUtil.java | 59 +-
.../newway/util/PaymentWrapperUtil.java | 21 +
src/main/resources/application.yml | 15 +-
src/main/resources/banner.png | Bin 109929 -> 0 bytes
src/main/resources/banner.txt | 15 +
.../db/migration/V10__commissions.sql | 12 -
.../V11__add_recurrent_payer_type.sql | 1 -
.../db/migration/V12__recurrents.sql | 4 -
.../V13__party_revision_to_refunds.sql | 2 -
.../db/migration/V14__session_info_remove.sql | 21 -
.../db/migration/V15__1.0.20_fistful_data.sql | 115 -
...destination_and_source_event_sink_data.sql | 123 -
.../V17__1.0.25_add_withdrawal_session.sql | 48 -
.../db/migration/V18__1.0.26_add_rate.sql | 24 -
.../migration/V19__1.0.27_payout_wallet.sql | 7 -
src/main/resources/db/migration/V1__init.sql | 2168 +++++++++++++----
.../V20__1.0.28_fix_withdrawal_session.sql | 7 -
...1.0.33_remove_unused_columns_in_payout.sql | 2 -
...35_remove_revision_not_null_constraint.sql | 3 -
....0.36_add_wallet_payout_tool_info_type.sql | 1 -
...36_add_wallet_payout_tool_info_columns.sql | 1 -
.../migration/V25__1.0.37_add_payout_type.sql | 1 -
.../V26__1.0.39_actualized_fistful_proto.sql | 16 -
.../V27__1.0.43_add_payment_method_type.sql | 1 -
...__1.0.44_add_change_id_remove_event_id.sql | 19 -
...29__1.0.46_add_additional_payment_info.sql | 12 -
.../V2__cash_flow_aggregate_functions.sql | 436 ----
.../V30__1.0.46_crypto_payment_tool_type.sql | 1 -
.../migration/V31__1.0.46_crypto_wallet.sql | 7 -
...dd_resource_type_in_withdrawal_session.sql | 8 -
.../V33__1.0.51_add_adjustment_status.sql | 1 -
.../V34__1.0.52_update_fistful_proto.sql | 16 -
.../V35__1.0.53_xrates_sequence_id.sql | 6 -
.../V36__add_capture_started_reason.sql | 1 -
.../V37__add_mobile_commerce_type.sql | 1 -
.../V38__add_payment_mobile_commerce.sql | 7 -
.../V39__add_payment_method_mobile.sql | 2 -
.../db/migration/V3__party_revision.sql | 5 -
.../db/migration/V40__1.0.56_batch.sql | 14 -
.../V41__1.0.58_recurrent_payment_tool.sql | 57 -
.../db/migration/V42__1.0.60_external_id.sql | 8 -
.../migration/V43__1.0.61_drop_not_null.sql | 2 -
...__1.0.62_add_payment_bank_info_columns.sql | 2 -
...V45__1.0.62_add_payment_system_in_rate.sql | 4 -
.../V46__1.0.64_withdrawal_provider.sql | 19 -
...__1.0.65_add_payment_status_adjustment.sql | 1 -
.../V48__1.0.66_add_sequence_change_id.sql | 18 -
...49__1.0.67_remove_rec_paytool_event_id.sql | 3 -
...optimize_cash_flow_aggregate_functions.sql | 517 ----
.../db/migration/V50__1.0.68_add_revision.sql | 8 -
.../db/migration/V51__cntrct_seq.sql | 5 -
.../db/migration/V52__drop_index.sql | 11 -
.../db/migration/V53__drop_fk_party.sql | 2 -
.../db/migration/V54__add_ids_contr.sql | 8 -
.../db/migration/V55__drop_cntrct_seq.sql | 1 -
.../db/migration/V56__revision_tables.sql | 39 -
.../db/migration/V57.1__add_chargeback.sql | 1 -
.../db/migration/V57.2__add_chargeback.sql | 44 -
.../V58__drop_f_payment_system_rates.sql | 4 -
.../db/migration/V59__revert_V58.sql | 4 -
.../db/migration/V5__domain_objects.sql | 11 -
.../V60__add_adjustment_cashflow_amount.sql | 17 -
.../V61__drop_f_payment_system_rates.sql | 8 -
.../V62__new_withdrawal_provider_id.sql | 6 -
.../migration/V63__optional_abs_account.sql | 1 -
.../migration/V64__optional_terminal_json.sql | 1 -
.../V65__add_payer_cardholder_name.sql | 1 -
.../V66__unied_provider-n-ext-term.sql | 7 -
.../V67__add_terminal_provider_ref.sql | 1 -
...68__remove_not_null_contraint_terminal.sql | 1 -
.../V69__add_charged_back_payment_status.sql | 1 -
.../db/migration/V6__1.0.10_swift_data.sql | 47 -
.../V71__add_payment_routing_rules_table.sql | 12 -
...ange_type_for_routing_decisions_column.sql | 2 -
..._rename_rule_id_and_add_version_column.sql | 2 -
.../V74__change_fileds_for_new_seq_scheme.sql | 34 -
.../V75__add_new_payment_systems.sql | 3 -
.../V76__add_uzcard_payment_system.sql | 1 -
.../V77__add_deposit_revert_type.sql | 1 -
.../V78__add_deposit_adjustment_type.sql | 1 -
...__revert_and_adjustment_deposit_tables.sql | 56 -
.../db/migration/V7__domain_objects.sql | 199 --
.../V80__change_payment_method_ids.sql | 2 -
...V81__fix_deposit_adjustment_and_revert.sql | 17 -
...2__add_crypto_currency_deprecated_type.sql | 1 -
.../V83__change_mobile_operator_type.sql | 5 -
.../V84__add_country_and_trade_bloc.sql | 29 -
.../db/migration/V85__fix_not_req_field.sql | 2 -
.../V86__destination_type_digital_wallet.sql | 1 -
.../V87__destination_digital_wallet.sql | 5 -
.../db/migration/V88__new_payouts.sql | 23 -
.../V89__add_payout_tool_info_type.sql | 1 -
.../db/migration/V8__session_change.sql | 25 -
...V90__drop_non_null_provider_json_field.sql | 1 -
.../V91__drop_cls_field_identity.sql | 2 -
.../db/migration/V92__add_schedlock.sql | 8 -
.../db/migration/V93__add_adjustmen_diffs.sql | 4 -
.../db/migration/V94__add_generic_type.sql | 2 -
..._truncate_party_mngmnt_for_contractors.sql | 1 -
.../dev/vality/newway/IntegrationTest.java | 373 ++-
.../vality/newway/dao/ChallengeDaoTest.java | 2 +-
.../java/dev/vality/newway/dao/DaoTests.java | 612 ++---
.../dev/vality/newway/dao/DepositDaoTest.java | 2 +-
.../vality/newway/dao/DestinationDaoTest.java | 2 +-
.../vality/newway/dao/IdentityDaoTest.java | 2 +-
.../dev/vality/newway/dao/PayoutDaoTest.java | 2 +-
.../dev/vality/newway/dao/SourceDaoTest.java | 2 +-
.../dev/vality/newway/dao/WalletDaoTest.java | 2 +-
.../vality/newway/dao/WithdrawalDaoTest.java | 2 +-
.../newway/dao/WithdrawalSessionDaoTest.java | 2 +-
.../PartyRevisionChangedHandlerTest.java | 6 +-
...DestinationCreatedBankCardHandlerTest.java | 2 +-
...inationCreatedCryptoWalletHandlerTest.java | 2 +-
...nationCreatedDigitalWalletHandlerTest.java | 2 +-
...awalSessionCreatedBankCardHandlerTest.java | 2 +-
...SessionCreatedCryptoWalletHandlerTest.java | 2 +-
...essionCreatedDigitalWalletHandlerTest.java | 2 +-
.../vality/newway/kafka/KafkaProducer.java | 3 +-
.../listener/InvoicingListenerTest.java | 30 +-
.../newway/model/InvoiceWrapperTest.java | 17 -
.../newway/model/PaymentWrapperTest.java | 17 -
.../service/CashFlowWrapperHandlerTest.java | 130 +
.../service/InvoiceBatchServiceTest.java | 66 -
.../service/InvoiceWrapperServiceTest.java | 101 +-
.../newway/service/InvoicingServiceTest.java | 159 +-
.../service/PartyManagementServiceTest.java | 2 +-
.../service/PaymentBatchServiceTest.java | 81 -
.../service/PaymentSquashServiceTest.java | 176 --
.../service/PaymentWrapperServiceTest.java | 134 +
.../newway/service/RateServiceTests.java | 12 +-
.../RecurrentPaymentToolServiceTest.java | 7 +-
.../vality/newway/util/CashFlowUtilTest.java | 1 +
...ilTest.java => ContractorFactoryTest.java} | 11 +-
.../dev/vality/newway/utils/JdbcUtil.java | 42 +
.../dev/vality/newway/utils/MockUtils.java | 39 +-
.../newway/utils/PaymentWrapperTestUtil.java | 77 +
295 files changed, 5585 insertions(+), 4635 deletions(-)
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/iface/CashFlowLinkDao.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/iface/InvoiceStatusInfoDao.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentAdditionalInfoDao.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentFeeDao.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentPayerInfoDao.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentRecurrentInfoDao.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentRiskDataDao.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentRouteDao.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentStatusInfoDao.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/impl/CashFlowLinkDaoImpl.java
rename src/main/java/dev/vality/newway/dao/invoicing/impl/{PaymentIdsGeneratorDaoImpl.java => CashFlowLinkIdsGeneratorDaoImpl.java} (84%)
delete mode 100644 src/main/java/dev/vality/newway/dao/invoicing/impl/InvoiceIdsGeneratorDaoImpl.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/impl/InvoiceStatusInfoDaoImpl.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentAdditionalInfoDaoImpl.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentFeeDaoImpl.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentPayerInfoDaoImpl.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentRecurrentInfoDaoImpl.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentRiskDataDaoImpl.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentRouteDaoImpl.java
create mode 100644 src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentStatusInfoDaoImpl.java
create mode 100644 src/main/java/dev/vality/newway/factory/cash/flow/CashFlowFactory.java
create mode 100644 src/main/java/dev/vality/newway/factory/cash/flow/CashFlowLinkFactory.java
rename src/main/java/dev/vality/newway/{util/ContractorUtil.java => factory/contractor/ContractorFactory.java} (91%)
create mode 100644 src/main/java/dev/vality/newway/factory/invoice/payment/InvoicePaymentEventIdHolderFactory.java
create mode 100644 src/main/java/dev/vality/newway/factory/invoice/payment/PaymentFeeFactory.java
create mode 100644 src/main/java/dev/vality/newway/factory/invoice/payment/PaymentRouteFactory.java
create mode 100644 src/main/java/dev/vality/newway/factory/invoice/payment/PaymentStatusInfoFactory.java
rename src/main/java/dev/vality/newway/factory/{ => machine/event}/AdjustmentMachineEventCopyFactoryImpl.java (95%)
rename src/main/java/dev/vality/newway/factory/{ => machine/event}/ChallengeMachineEventCopyFactoryImpl.java (96%)
rename src/main/java/dev/vality/newway/factory/{ => machine/event}/ChargebackMachineEventCopyFactoryImpl.java (95%)
rename src/main/java/dev/vality/newway/factory/{ => machine/event}/DepositAjustmentMachineEventCopyFactoryImpl.java (96%)
rename src/main/java/dev/vality/newway/factory/{ => machine/event}/DepositMachineEventCopyFactoryImpl.java (96%)
rename src/main/java/dev/vality/newway/factory/{ => machine/event}/DepositRevertMachineEventCopyFactoryImpl.java (96%)
rename src/main/java/dev/vality/newway/factory/{ => machine/event}/DestinationMachineEventCopyFactoryImpl.java (96%)
rename src/main/java/dev/vality/newway/factory/{ => machine/event}/IdentityMachineEventCopyFactoryImpl.java (95%)
rename src/main/java/dev/vality/newway/factory/{ => machine/event}/MachineEventCopyFactory.java (84%)
rename src/main/java/dev/vality/newway/factory/{ => machine/event}/PartyMachineEventCopyFactoryImpl.java (95%)
rename src/main/java/dev/vality/newway/factory/{ => machine/event}/RecurrentPaymentToolCopyFactoryImpl.java (96%)
rename src/main/java/dev/vality/newway/factory/{ => machine/event}/RefundMachineEventCopyFactoryImpl.java (95%)
rename src/main/java/dev/vality/newway/factory/{ => machine/event}/SourceMachineEventCopyFactoryImpl.java (95%)
rename src/main/java/dev/vality/newway/factory/{ => machine/event}/WalletMachineEventCopyFactoryImpl.java (95%)
rename src/main/java/dev/vality/newway/factory/{ => machine/event}/WithdrawalMachineEventCopyFactoryImpl.java (96%)
rename src/main/java/dev/vality/newway/factory/{ => machine/event}/WithdrawalSessionMachineEventCopyFactoryImpl.java (96%)
delete mode 100644 src/main/java/dev/vality/newway/handler/event/stock/LocalStorage.java
create mode 100644 src/main/java/dev/vality/newway/handler/wrapper/WrapperHandler.java
create mode 100644 src/main/java/dev/vality/newway/handler/wrapper/invoice/InvoiceCartWrapperHandler.java
create mode 100644 src/main/java/dev/vality/newway/handler/wrapper/invoice/InvoiceStatusInfoWrapperHandler.java
create mode 100644 src/main/java/dev/vality/newway/handler/wrapper/invoice/InvoiceWrapperHandler.java
create mode 100644 src/main/java/dev/vality/newway/handler/wrapper/payment/CashFlowWrapperHandler.java
create mode 100644 src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentAdditionalInfoWrapperHandler.java
create mode 100644 src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentFeeWrapperHandler.java
create mode 100644 src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentPayerInfoWrapperHandler.java
create mode 100644 src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentRecurrentInfoWrapperHandler.java
create mode 100644 src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentRiskDataWrapperHandler.java
create mode 100644 src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentRouteWrapperHandler.java
create mode 100644 src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentStatusInfoWrapperHandler.java
create mode 100644 src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentWrapperHandler.java
delete mode 100644 src/main/java/dev/vality/newway/mapper/AbstractInvoicingMapper.java
delete mode 100644 src/main/java/dev/vality/newway/mapper/invoice/AbstractInvoicingInvoiceMapper.java
delete mode 100644 src/main/java/dev/vality/newway/mapper/payment/AbstractInvoicingPaymentMapper.java
rename src/main/java/dev/vality/newway/{util => model}/CashFlowType.java (95%)
create mode 100644 src/main/java/dev/vality/newway/model/CashFlowWrapper.java
create mode 100644 src/main/java/dev/vality/newway/model/InvoicePaymentEventIdHolder.java
create mode 100644 src/main/java/dev/vality/newway/model/PartyShop.java
delete mode 100644 src/main/java/dev/vality/newway/service/InvoiceBatchService.java
create mode 100644 src/main/java/dev/vality/newway/service/PartyShopCacheService.java
delete mode 100644 src/main/java/dev/vality/newway/service/PaymentBatchService.java
delete mode 100644 src/main/java/dev/vality/newway/service/PaymentSquashService.java
create mode 100644 src/main/java/dev/vality/newway/util/PaymentWrapperUtil.java
delete mode 100644 src/main/resources/banner.png
create mode 100644 src/main/resources/banner.txt
delete mode 100644 src/main/resources/db/migration/V10__commissions.sql
delete mode 100644 src/main/resources/db/migration/V11__add_recurrent_payer_type.sql
delete mode 100644 src/main/resources/db/migration/V12__recurrents.sql
delete mode 100644 src/main/resources/db/migration/V13__party_revision_to_refunds.sql
delete mode 100644 src/main/resources/db/migration/V14__session_info_remove.sql
delete mode 100644 src/main/resources/db/migration/V15__1.0.20_fistful_data.sql
delete mode 100644 src/main/resources/db/migration/V16__1.0.23_add_deposit_destination_and_source_event_sink_data.sql
delete mode 100644 src/main/resources/db/migration/V17__1.0.25_add_withdrawal_session.sql
delete mode 100644 src/main/resources/db/migration/V18__1.0.26_add_rate.sql
delete mode 100644 src/main/resources/db/migration/V19__1.0.27_payout_wallet.sql
delete mode 100644 src/main/resources/db/migration/V20__1.0.28_fix_withdrawal_session.sql
delete mode 100644 src/main/resources/db/migration/V21__1.0.33_remove_unused_columns_in_payout.sql
delete mode 100644 src/main/resources/db/migration/V22__1.0.35_remove_revision_not_null_constraint.sql
delete mode 100644 src/main/resources/db/migration/V23__1.0.36_add_wallet_payout_tool_info_type.sql
delete mode 100644 src/main/resources/db/migration/V24__1.0.36_add_wallet_payout_tool_info_columns.sql
delete mode 100644 src/main/resources/db/migration/V25__1.0.37_add_payout_type.sql
delete mode 100644 src/main/resources/db/migration/V26__1.0.39_actualized_fistful_proto.sql
delete mode 100644 src/main/resources/db/migration/V27__1.0.43_add_payment_method_type.sql
delete mode 100644 src/main/resources/db/migration/V28__1.0.44_add_change_id_remove_event_id.sql
delete mode 100644 src/main/resources/db/migration/V29__1.0.46_add_additional_payment_info.sql
delete mode 100644 src/main/resources/db/migration/V2__cash_flow_aggregate_functions.sql
delete mode 100644 src/main/resources/db/migration/V30__1.0.46_crypto_payment_tool_type.sql
delete mode 100644 src/main/resources/db/migration/V31__1.0.46_crypto_wallet.sql
delete mode 100644 src/main/resources/db/migration/V32__add_resource_type_in_withdrawal_session.sql
delete mode 100644 src/main/resources/db/migration/V33__1.0.51_add_adjustment_status.sql
delete mode 100644 src/main/resources/db/migration/V34__1.0.52_update_fistful_proto.sql
delete mode 100644 src/main/resources/db/migration/V35__1.0.53_xrates_sequence_id.sql
delete mode 100644 src/main/resources/db/migration/V36__add_capture_started_reason.sql
delete mode 100644 src/main/resources/db/migration/V37__add_mobile_commerce_type.sql
delete mode 100644 src/main/resources/db/migration/V38__add_payment_mobile_commerce.sql
delete mode 100644 src/main/resources/db/migration/V39__add_payment_method_mobile.sql
delete mode 100644 src/main/resources/db/migration/V3__party_revision.sql
delete mode 100644 src/main/resources/db/migration/V40__1.0.56_batch.sql
delete mode 100644 src/main/resources/db/migration/V41__1.0.58_recurrent_payment_tool.sql
delete mode 100644 src/main/resources/db/migration/V42__1.0.60_external_id.sql
delete mode 100644 src/main/resources/db/migration/V43__1.0.61_drop_not_null.sql
delete mode 100644 src/main/resources/db/migration/V44__1.0.62_add_payment_bank_info_columns.sql
delete mode 100644 src/main/resources/db/migration/V45__1.0.62_add_payment_system_in_rate.sql
delete mode 100644 src/main/resources/db/migration/V46__1.0.64_withdrawal_provider.sql
delete mode 100644 src/main/resources/db/migration/V47__1.0.65_add_payment_status_adjustment.sql
delete mode 100644 src/main/resources/db/migration/V48__1.0.66_add_sequence_change_id.sql
delete mode 100644 src/main/resources/db/migration/V49__1.0.67_remove_rec_paytool_event_id.sql
delete mode 100644 src/main/resources/db/migration/V4__1.0.6_optimize_cash_flow_aggregate_functions.sql
delete mode 100644 src/main/resources/db/migration/V50__1.0.68_add_revision.sql
delete mode 100644 src/main/resources/db/migration/V51__cntrct_seq.sql
delete mode 100644 src/main/resources/db/migration/V52__drop_index.sql
delete mode 100644 src/main/resources/db/migration/V53__drop_fk_party.sql
delete mode 100644 src/main/resources/db/migration/V54__add_ids_contr.sql
delete mode 100644 src/main/resources/db/migration/V55__drop_cntrct_seq.sql
delete mode 100644 src/main/resources/db/migration/V56__revision_tables.sql
delete mode 100644 src/main/resources/db/migration/V57.1__add_chargeback.sql
delete mode 100644 src/main/resources/db/migration/V57.2__add_chargeback.sql
delete mode 100644 src/main/resources/db/migration/V58__drop_f_payment_system_rates.sql
delete mode 100644 src/main/resources/db/migration/V59__revert_V58.sql
delete mode 100644 src/main/resources/db/migration/V5__domain_objects.sql
delete mode 100644 src/main/resources/db/migration/V60__add_adjustment_cashflow_amount.sql
delete mode 100644 src/main/resources/db/migration/V61__drop_f_payment_system_rates.sql
delete mode 100644 src/main/resources/db/migration/V62__new_withdrawal_provider_id.sql
delete mode 100644 src/main/resources/db/migration/V63__optional_abs_account.sql
delete mode 100644 src/main/resources/db/migration/V64__optional_terminal_json.sql
delete mode 100644 src/main/resources/db/migration/V65__add_payer_cardholder_name.sql
delete mode 100644 src/main/resources/db/migration/V66__unied_provider-n-ext-term.sql
delete mode 100644 src/main/resources/db/migration/V67__add_terminal_provider_ref.sql
delete mode 100644 src/main/resources/db/migration/V68__remove_not_null_contraint_terminal.sql
delete mode 100644 src/main/resources/db/migration/V69__add_charged_back_payment_status.sql
delete mode 100644 src/main/resources/db/migration/V6__1.0.10_swift_data.sql
delete mode 100644 src/main/resources/db/migration/V71__add_payment_routing_rules_table.sql
delete mode 100644 src/main/resources/db/migration/V72__change_type_for_routing_decisions_column.sql
delete mode 100644 src/main/resources/db/migration/V73__rename_rule_id_and_add_version_column.sql
delete mode 100644 src/main/resources/db/migration/V74__change_fileds_for_new_seq_scheme.sql
delete mode 100644 src/main/resources/db/migration/V75__add_new_payment_systems.sql
delete mode 100644 src/main/resources/db/migration/V76__add_uzcard_payment_system.sql
delete mode 100644 src/main/resources/db/migration/V77__add_deposit_revert_type.sql
delete mode 100644 src/main/resources/db/migration/V78__add_deposit_adjustment_type.sql
delete mode 100644 src/main/resources/db/migration/V79__revert_and_adjustment_deposit_tables.sql
delete mode 100644 src/main/resources/db/migration/V7__domain_objects.sql
delete mode 100644 src/main/resources/db/migration/V80__change_payment_method_ids.sql
delete mode 100644 src/main/resources/db/migration/V81__fix_deposit_adjustment_and_revert.sql
delete mode 100644 src/main/resources/db/migration/V82__add_crypto_currency_deprecated_type.sql
delete mode 100644 src/main/resources/db/migration/V83__change_mobile_operator_type.sql
delete mode 100644 src/main/resources/db/migration/V84__add_country_and_trade_bloc.sql
delete mode 100644 src/main/resources/db/migration/V85__fix_not_req_field.sql
delete mode 100644 src/main/resources/db/migration/V86__destination_type_digital_wallet.sql
delete mode 100644 src/main/resources/db/migration/V87__destination_digital_wallet.sql
delete mode 100644 src/main/resources/db/migration/V88__new_payouts.sql
delete mode 100644 src/main/resources/db/migration/V89__add_payout_tool_info_type.sql
delete mode 100644 src/main/resources/db/migration/V8__session_change.sql
delete mode 100644 src/main/resources/db/migration/V90__drop_non_null_provider_json_field.sql
delete mode 100644 src/main/resources/db/migration/V91__drop_cls_field_identity.sql
delete mode 100644 src/main/resources/db/migration/V92__add_schedlock.sql
delete mode 100644 src/main/resources/db/migration/V93__add_adjustmen_diffs.sql
delete mode 100644 src/main/resources/db/migration/V94__add_generic_type.sql
delete mode 100644 src/main/resources/db/migration/V9__truncate_party_mngmnt_for_contractors.sql
delete mode 100644 src/test/java/dev/vality/newway/model/InvoiceWrapperTest.java
delete mode 100644 src/test/java/dev/vality/newway/model/PaymentWrapperTest.java
create mode 100644 src/test/java/dev/vality/newway/service/CashFlowWrapperHandlerTest.java
delete mode 100644 src/test/java/dev/vality/newway/service/InvoiceBatchServiceTest.java
delete mode 100644 src/test/java/dev/vality/newway/service/PaymentBatchServiceTest.java
delete mode 100644 src/test/java/dev/vality/newway/service/PaymentSquashServiceTest.java
create mode 100644 src/test/java/dev/vality/newway/service/PaymentWrapperServiceTest.java
rename src/test/java/dev/vality/newway/util/{ContractorUtilTest.java => ContractorFactoryTest.java} (83%)
create mode 100644 src/test/java/dev/vality/newway/utils/JdbcUtil.java
create mode 100644 src/test/java/dev/vality/newway/utils/PaymentWrapperTestUtil.java
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index a6547029..3b310f08 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -3,7 +3,7 @@ name: Maven Build Artifact
on:
pull_request:
branches:
- - '*'
+ - '**'
jobs:
build:
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index 6a394b04..5a405cb6 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -5,6 +5,7 @@ on:
branches:
- 'master'
- 'main'
+ - 'epic/**'
env:
REGISTRY: ghcr.io
diff --git a/pom.xml b/pom.xml
index d3476ebd..0168d8d3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
postgres
postgres
newway
- nw
+ dw
jdbc:postgresql://localhost:5432/newway
5432
./src/main/resources/checkstyle/checkstyle-suppressions.xml
diff --git a/src/main/java/dev/vality/newway/config/ApplicationConfig.java b/src/main/java/dev/vality/newway/config/ApplicationConfig.java
index 3270b24c..9f308c5b 100644
--- a/src/main/java/dev/vality/newway/config/ApplicationConfig.java
+++ b/src/main/java/dev/vality/newway/config/ApplicationConfig.java
@@ -1,7 +1,7 @@
package dev.vality.newway.config;
import dev.vality.damsel.domain_config.RepositorySrv;
-import dev.vality.newway.domain.Nw;
+import dev.vality.newway.domain.Dw;
import dev.vality.woody.thrift.impl.http.THSpawnClientBuilder;
import org.jooq.Schema;
import org.springframework.beans.factory.annotation.Value;
@@ -25,6 +25,6 @@ public RepositorySrv.Iface dominantClient(@Value("${dmt.url}") Resource resource
@Bean
public Schema schema() {
- return Nw.NW;
+ return Dw.DW;
}
}
diff --git a/src/main/java/dev/vality/newway/config/CacheConfig.java b/src/main/java/dev/vality/newway/config/CacheConfig.java
index 34dce07b..db105f4b 100644
--- a/src/main/java/dev/vality/newway/config/CacheConfig.java
+++ b/src/main/java/dev/vality/newway/config/CacheConfig.java
@@ -2,23 +2,23 @@
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
-import dev.vality.newway.model.InvoiceWrapper;
-import dev.vality.newway.model.InvoicingKey;
-import dev.vality.newway.model.PaymentWrapper;
+import dev.vality.newway.model.PartyShop;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import java.time.Duration;
+
@Configuration
public class CacheConfig {
@Bean
- public Cache invoiceDataCache(@Value("${cache.invoice.size}") int cacheSize) {
- return Caffeine.newBuilder().maximumSize(cacheSize).build();
+ public Cache partyShopDataCache(@Value("${cache.party-shop.size}") int cacheSize,
+ @Value("${cache.party-shop.expire.after.sec}") long expireAfter) {
+ return Caffeine.newBuilder()
+ .maximumSize(cacheSize)
+ .expireAfterWrite(Duration.ofSeconds(expireAfter))
+ .build();
}
- @Bean
- public Cache paymentDataCache(@Value("${cache.payment.size}") int cacheSize) {
- return Caffeine.newBuilder().maximumSize(cacheSize).build();
- }
}
diff --git a/src/main/java/dev/vality/newway/config/SchedulerConfig.java b/src/main/java/dev/vality/newway/config/SchedulerConfig.java
index 4282a496..38d90a2e 100644
--- a/src/main/java/dev/vality/newway/config/SchedulerConfig.java
+++ b/src/main/java/dev/vality/newway/config/SchedulerConfig.java
@@ -18,7 +18,7 @@
@EnableSchedulerLock(defaultLockAtMostFor = "PT5M")
public class SchedulerConfig {
- public static final String TABLE_NAME = "nw.shedlock";
+ public static final String TABLE_NAME = "dw.shedlock";
@Bean
public DominantPoller dominantPoller(RepositorySrv.Iface dominantClient,
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/iface/CashFlowLinkDao.java b/src/main/java/dev/vality/newway/dao/invoicing/iface/CashFlowLinkDao.java
new file mode 100644
index 00000000..58c3992f
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/iface/CashFlowLinkDao.java
@@ -0,0 +1,22 @@
+package dev.vality.newway.dao.invoicing.iface;
+
+import dev.vality.dao.GenericDao;
+import dev.vality.newway.domain.tables.pojos.CashFlowLink;
+import dev.vality.newway.exception.DaoException;
+import dev.vality.newway.model.InvoicePaymentEventIdHolder;
+import dev.vality.newway.model.InvoicingKey;
+
+import java.util.List;
+import java.util.Set;
+
+public interface CashFlowLinkDao extends GenericDao {
+
+ void saveBatch(List links) throws DaoException;
+
+ CashFlowLink get(String invoiceId, String paymentId);
+
+ void switchCurrent(Set keys) throws DaoException;
+
+ Set getExistingEvents(List links);
+
+}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/iface/InvoiceCartDao.java b/src/main/java/dev/vality/newway/dao/invoicing/iface/InvoiceCartDao.java
index dc6773ea..b284033c 100644
--- a/src/main/java/dev/vality/newway/dao/invoicing/iface/InvoiceCartDao.java
+++ b/src/main/java/dev/vality/newway/dao/invoicing/iface/InvoiceCartDao.java
@@ -5,11 +5,14 @@
import dev.vality.newway.exception.DaoException;
import java.util.List;
+import java.util.Set;
public interface InvoiceCartDao extends GenericDao {
void save(List invoiceCartList) throws DaoException;
- List getByInvId(Long invId) throws DaoException;
+ List getByInvoiceId(String invoiceId) throws DaoException;
+
+ Set getExistingInvoiceIds(Set invoiceIds) throws DaoException;
}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/iface/InvoiceDao.java b/src/main/java/dev/vality/newway/dao/invoicing/iface/InvoiceDao.java
index 7813731b..5124af9b 100644
--- a/src/main/java/dev/vality/newway/dao/invoicing/iface/InvoiceDao.java
+++ b/src/main/java/dev/vality/newway/dao/invoicing/iface/InvoiceDao.java
@@ -3,9 +3,7 @@
import dev.vality.dao.GenericDao;
import dev.vality.newway.domain.tables.pojos.Invoice;
import dev.vality.newway.exception.DaoException;
-import dev.vality.newway.model.InvoicingKey;
-import java.util.Collection;
import java.util.List;
public interface InvoiceDao extends GenericDao {
@@ -14,5 +12,4 @@ public interface InvoiceDao extends GenericDao {
Invoice get(String invoiceId) throws DaoException;
- void switchCurrent(Collection invoicesSwitchIds) throws DaoException;
}
\ No newline at end of file
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/iface/InvoiceStatusInfoDao.java b/src/main/java/dev/vality/newway/dao/invoicing/iface/InvoiceStatusInfoDao.java
new file mode 100644
index 00000000..bab72c01
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/iface/InvoiceStatusInfoDao.java
@@ -0,0 +1,18 @@
+package dev.vality.newway.dao.invoicing.iface;
+
+import dev.vality.dao.GenericDao;
+import dev.vality.newway.domain.tables.pojos.InvoiceStatusInfo;
+import dev.vality.newway.exception.DaoException;
+
+import java.util.List;
+import java.util.Set;
+
+public interface InvoiceStatusInfoDao extends GenericDao {
+
+ void saveBatch(List statuses) throws DaoException;
+
+ InvoiceStatusInfo get(String invoiceId);
+
+ void switchCurrent(Set invoiceIds) throws DaoException;
+
+}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentAdditionalInfoDao.java b/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentAdditionalInfoDao.java
new file mode 100644
index 00000000..bebf4fd8
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentAdditionalInfoDao.java
@@ -0,0 +1,19 @@
+package dev.vality.newway.dao.invoicing.iface;
+
+import dev.vality.dao.GenericDao;
+import dev.vality.newway.domain.tables.pojos.PaymentAdditionalInfo;
+import dev.vality.newway.exception.DaoException;
+import dev.vality.newway.model.InvoicingKey;
+
+import java.util.List;
+import java.util.Set;
+
+public interface PaymentAdditionalInfoDao extends GenericDao {
+
+ void saveBatch(List paymentAdditionalInfos) throws DaoException;
+
+ PaymentAdditionalInfo get(String invoiceId, String paymentId) throws DaoException;
+
+ void switchCurrent(Set invoicesSwitchIds) throws DaoException;
+
+}
\ No newline at end of file
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentDao.java b/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentDao.java
index 076c54ca..ee94ade6 100644
--- a/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentDao.java
+++ b/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentDao.java
@@ -3,18 +3,13 @@
import dev.vality.dao.GenericDao;
import dev.vality.newway.domain.tables.pojos.Payment;
import dev.vality.newway.exception.DaoException;
-import dev.vality.newway.model.InvoicingKey;
-import java.util.Collection;
import java.util.List;
public interface PaymentDao extends GenericDao {
void saveBatch(List payments) throws DaoException;
- void updateBatch(List records) throws DaoException;
-
Payment get(String invoiceId, String paymentId) throws DaoException;
- void switchCurrent(Collection invoicesSwitchIds) throws DaoException;
}
\ No newline at end of file
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentFeeDao.java b/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentFeeDao.java
new file mode 100644
index 00000000..90ed3359
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentFeeDao.java
@@ -0,0 +1,19 @@
+package dev.vality.newway.dao.invoicing.iface;
+
+import dev.vality.dao.GenericDao;
+import dev.vality.newway.domain.tables.pojos.PaymentFee;
+import dev.vality.newway.exception.DaoException;
+import dev.vality.newway.model.InvoicingKey;
+
+import java.util.List;
+import java.util.Set;
+
+public interface PaymentFeeDao extends GenericDao {
+
+ void saveBatch(List paymentFees) throws DaoException;
+
+ PaymentFee get(String invoiceId, String paymentId) throws DaoException;
+
+ void switchCurrent(Set invoicingKeys) throws DaoException;
+
+}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentPayerInfoDao.java b/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentPayerInfoDao.java
new file mode 100644
index 00000000..821817cb
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentPayerInfoDao.java
@@ -0,0 +1,16 @@
+package dev.vality.newway.dao.invoicing.iface;
+
+import dev.vality.dao.GenericDao;
+
+import dev.vality.newway.domain.tables.pojos.PaymentPayerInfo;
+import dev.vality.newway.exception.DaoException;
+
+import java.util.List;
+
+public interface PaymentPayerInfoDao extends GenericDao {
+
+ void saveBatch(List payerInfos) throws DaoException;
+
+ PaymentPayerInfo get(String invoiceId, String paymentId) throws DaoException;
+
+}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentRecurrentInfoDao.java b/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentRecurrentInfoDao.java
new file mode 100644
index 00000000..c1a4490b
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentRecurrentInfoDao.java
@@ -0,0 +1,19 @@
+package dev.vality.newway.dao.invoicing.iface;
+
+import dev.vality.dao.GenericDao;
+import dev.vality.newway.domain.tables.pojos.PaymentRecurrentInfo;
+import dev.vality.newway.exception.DaoException;
+import dev.vality.newway.model.InvoicingKey;
+
+import java.util.List;
+import java.util.Set;
+
+public interface PaymentRecurrentInfoDao extends GenericDao {
+
+ void saveBatch(List paymentRecurrentInfos) throws DaoException;
+
+ PaymentRecurrentInfo get(String invoiceId, String paymentId) throws DaoException;
+
+ void switchCurrent(Set invoicesSwitchIds) throws DaoException;
+
+}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentRiskDataDao.java b/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentRiskDataDao.java
new file mode 100644
index 00000000..8ab00f94
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentRiskDataDao.java
@@ -0,0 +1,19 @@
+package dev.vality.newway.dao.invoicing.iface;
+
+import dev.vality.dao.GenericDao;
+import dev.vality.newway.domain.tables.pojos.PaymentRiskData;
+import dev.vality.newway.exception.DaoException;
+import dev.vality.newway.model.InvoicingKey;
+
+import java.util.List;
+import java.util.Set;
+
+public interface PaymentRiskDataDao extends GenericDao {
+
+ void saveBatch(List paymentRiskDataList) throws DaoException;
+
+ PaymentRiskData get(String invoiceId, String paymentId) throws DaoException;
+
+ void switchCurrent(Set invoicingKeys) throws DaoException;
+
+}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentRouteDao.java b/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentRouteDao.java
new file mode 100644
index 00000000..447db170
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentRouteDao.java
@@ -0,0 +1,19 @@
+package dev.vality.newway.dao.invoicing.iface;
+
+import dev.vality.dao.GenericDao;
+import dev.vality.newway.domain.tables.pojos.PaymentRoute;
+import dev.vality.newway.exception.DaoException;
+import dev.vality.newway.model.InvoicingKey;
+
+import java.util.List;
+import java.util.Set;
+
+public interface PaymentRouteDao extends GenericDao {
+
+ void saveBatch(List paymentRoutes) throws DaoException;
+
+ PaymentRoute get(String invoiceId, String paymentId) throws DaoException;
+
+ void switchCurrent(Set invoicingKeys) throws DaoException;
+
+}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentStatusInfoDao.java b/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentStatusInfoDao.java
new file mode 100644
index 00000000..3315389c
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/iface/PaymentStatusInfoDao.java
@@ -0,0 +1,18 @@
+package dev.vality.newway.dao.invoicing.iface;
+
+import dev.vality.dao.GenericDao;
+import dev.vality.newway.domain.tables.pojos.PaymentStatusInfo;
+import dev.vality.newway.exception.DaoException;
+import dev.vality.newway.model.InvoicingKey;
+
+import java.util.List;
+import java.util.Set;
+
+public interface PaymentStatusInfoDao extends GenericDao {
+
+ void saveBatch(List paymentStatusInfos) throws DaoException;
+
+ PaymentStatusInfo get(String invoiceId, String paymentId) throws DaoException;
+
+ void switchCurrent(Set invoicesSwitchIds) throws DaoException;
+}
\ No newline at end of file
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/impl/CashFlowLinkDaoImpl.java b/src/main/java/dev/vality/newway/dao/invoicing/impl/CashFlowLinkDaoImpl.java
new file mode 100644
index 00000000..1fcc99c4
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/impl/CashFlowLinkDaoImpl.java
@@ -0,0 +1,124 @@
+package dev.vality.newway.dao.invoicing.impl;
+
+import dev.vality.dao.impl.AbstractGenericDao;
+import dev.vality.mapper.RecordRowMapper;
+import dev.vality.newway.dao.invoicing.iface.CashFlowLinkDao;
+import dev.vality.newway.domain.tables.pojos.CashFlowLink;
+import dev.vality.newway.exception.DaoException;
+import dev.vality.newway.exception.NotFoundException;
+import dev.vality.newway.model.InvoicePaymentEventIdHolder;
+import dev.vality.newway.model.InvoicingKey;
+import org.jooq.Field;
+import org.jooq.Query;
+import org.jooq.impl.DSL;
+import org.springframework.jdbc.core.DataClassRowMapper;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
+
+import javax.sql.DataSource;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static dev.vality.newway.domain.Tables.CASH_FLOW_LINK;
+
+@Component
+public class CashFlowLinkDaoImpl extends AbstractGenericDao implements CashFlowLinkDao {
+
+ private final RowMapper rowMapper;
+ private final RowMapper invoicePaymentEventIdRowMapper;
+
+ private static final Field[] INVOICE_PAYMENT_EVENT_ID_HOLDER_FIELDS = new Field[]{
+ CASH_FLOW_LINK.INVOICE_ID,
+ CASH_FLOW_LINK.PAYMENT_ID,
+ CASH_FLOW_LINK.CHANGE_ID,
+ CASH_FLOW_LINK.SEQUENCE_ID
+ };
+
+ public CashFlowLinkDaoImpl(DataSource dataSource) {
+ super(dataSource);
+ rowMapper = new RecordRowMapper<>(CASH_FLOW_LINK, CashFlowLink.class);
+ invoicePaymentEventIdRowMapper = new DataClassRowMapper<>(InvoicePaymentEventIdHolder.class);
+ }
+
+ @Override
+ public void saveBatch(List links) throws DaoException {
+ batchExecute(links.stream()
+ .map(status -> getDslContext().newRecord(CASH_FLOW_LINK, status))
+ .map(invoiceStatusInfoRecord -> getDslContext().insertInto(CASH_FLOW_LINK)
+ .set(invoiceStatusInfoRecord))
+ .collect(Collectors.toList())
+ );
+ }
+
+ @Override
+ public CashFlowLink get(String invoiceId, String paymentId) {
+ Query query = getDslContext().selectFrom(CASH_FLOW_LINK)
+ .where(CASH_FLOW_LINK.INVOICE_ID.eq(invoiceId)
+ .and(CASH_FLOW_LINK.PAYMENT_ID.eq(paymentId))
+ .and(CASH_FLOW_LINK.CURRENT));
+ return Optional.ofNullable(fetchOne(query, rowMapper))
+ .orElseThrow(() -> new NotFoundException(
+ String.format("CashFlowLink not found, invoiceId='%s', paymentId='%s'", invoiceId, paymentId)));
+ }
+
+ @Override
+ public void switchCurrent(Set keys) throws DaoException {
+ keys.forEach(key -> {
+ setOldCashFlowLinkNotCurrent(key);
+ setLatestCashFlowLinkCurrent(key);
+ });
+ }
+
+ @Override
+ public Set getExistingEvents(List links) {
+ Set invoiceIds = new HashSet<>();
+ Set paymentIds = new HashSet<>();
+ Set changeIds = new HashSet<>();
+ Set sequenceIds = new HashSet<>();
+ Set concatenatedIds = new HashSet<>();
+ links.forEach(link -> {
+ invoiceIds.add(link.getInvoiceId());
+ paymentIds.add(link.getPaymentId());
+ changeIds.add(link.getChangeId());
+ sequenceIds.add(link.getSequenceId());
+ concatenatedIds.add(link.getInvoiceId() + link.getPaymentId() + link.getChangeId() + link.getSequenceId());
+ });
+
+ // we have to use concatenated ids otherwise there is small probability of collision.
+ // some non-processed events might fall under "invoice_id/payment_id/change_id/sequence_id in()" conditiona.
+ // e.g. we will receive several cash_flow_change events within one batch
+ // and there will be overlap in change ids.
+ // concat() is used as last step so there is minimal operation overhead.
+ Query query = getDslContext()
+ .select(INVOICE_PAYMENT_EVENT_ID_HOLDER_FIELDS)
+ .from(CASH_FLOW_LINK)
+ .where(CASH_FLOW_LINK.INVOICE_ID.in(invoiceIds))
+ .and(CASH_FLOW_LINK.PAYMENT_ID.in(paymentIds))
+ .and(CASH_FLOW_LINK.CHANGE_ID.in(changeIds))
+ .and(CASH_FLOW_LINK.SEQUENCE_ID.in(sequenceIds))
+ .and(DSL.concat(INVOICE_PAYMENT_EVENT_ID_HOLDER_FIELDS).in(concatenatedIds));
+
+ return new HashSet<>(fetch(query, invoicePaymentEventIdRowMapper));
+ }
+
+ private void setOldCashFlowLinkNotCurrent(InvoicingKey key) {
+ execute(getDslContext().update(CASH_FLOW_LINK)
+ .set(CASH_FLOW_LINK.CURRENT, false)
+ .where(CASH_FLOW_LINK.INVOICE_ID.eq(key.getInvoiceId())
+ .and(CASH_FLOW_LINK.PAYMENT_ID.eq(key.getPaymentId()))
+ .and(CASH_FLOW_LINK.CURRENT))
+ );
+ }
+
+ private void setLatestCashFlowLinkCurrent(InvoicingKey key) {
+ execute(getDslContext().update(CASH_FLOW_LINK)
+ .set(CASH_FLOW_LINK.CURRENT, true)
+ .where(CASH_FLOW_LINK.ID.eq(
+ DSL.select(DSL.max(CASH_FLOW_LINK.ID))
+ .from(CASH_FLOW_LINK)
+ .where(CASH_FLOW_LINK.INVOICE_ID.eq(key.getInvoiceId())
+ .and(CASH_FLOW_LINK.PAYMENT_ID.eq(key.getPaymentId())))
+ ))
+ );
+ }
+}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentIdsGeneratorDaoImpl.java b/src/main/java/dev/vality/newway/dao/invoicing/impl/CashFlowLinkIdsGeneratorDaoImpl.java
similarity index 84%
rename from src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentIdsGeneratorDaoImpl.java
rename to src/main/java/dev/vality/newway/dao/invoicing/impl/CashFlowLinkIdsGeneratorDaoImpl.java
index eb359bc7..018a964b 100644
--- a/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentIdsGeneratorDaoImpl.java
+++ b/src/main/java/dev/vality/newway/dao/invoicing/impl/CashFlowLinkIdsGeneratorDaoImpl.java
@@ -14,14 +14,14 @@
@Slf4j
@Component
@RequiredArgsConstructor
-public class PaymentIdsGeneratorDaoImpl implements IdsGeneratorDao {
+public class CashFlowLinkIdsGeneratorDaoImpl implements IdsGeneratorDao {
private final NamedParameterJdbcTemplate jdbcTemplate;
@Override
public List get(int size) throws DaoException {
try {
- String sql = "select nextval('nw.pmnt_seq') from generate_series(1, :size)";
+ String sql = "select nextval('dw.cash_flow_link_id_seq') from generate_series(1, :size)";
MapSqlParameterSource parameterSource = new MapSqlParameterSource().addValue("size", size);
return jdbcTemplate.queryForList(sql, parameterSource, Long.class);
} catch (NestedRuntimeException e) {
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/impl/InvoiceCartDaoImpl.java b/src/main/java/dev/vality/newway/dao/invoicing/impl/InvoiceCartDaoImpl.java
index 6d734db4..ab285f42 100644
--- a/src/main/java/dev/vality/newway/dao/invoicing/impl/InvoiceCartDaoImpl.java
+++ b/src/main/java/dev/vality/newway/dao/invoicing/impl/InvoiceCartDaoImpl.java
@@ -6,12 +6,16 @@
import dev.vality.newway.domain.tables.pojos.InvoiceCart;
import dev.vality.newway.exception.DaoException;
import org.jooq.Query;
+import org.jooq.impl.DSL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
+import org.springframework.jdbc.core.SingleColumnRowMapper;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.stream.Collectors;
import static dev.vality.newway.domain.tables.InvoiceCart.INVOICE_CART;
@@ -37,9 +41,29 @@ public void save(List carts) throws DaoException {
}
@Override
- public List getByInvId(Long invId) throws DaoException {
+ public List getByInvoiceId(String invoiceId) throws DaoException {
Query query = getDslContext().selectFrom(INVOICE_CART)
- .where(INVOICE_CART.INV_ID.eq(invId));
+ .where(INVOICE_CART.INVOICE_ID.eq(invoiceId));
return fetch(query, invoiceCartRowMapper);
}
+
+ /**
+ * Invoice cart can be written only once when Invoice is created.
+ * Invoice cart cannot be changed, only way to change invoice cart is to cancel invoice and create new one.
+ *
+ * @param invoiceIds set of invoice ids to check for existence.
+ * @return List of invoice ids which haven't been saved already.
+ * @throws DaoException
+ */
+ @Override
+ public Set getExistingInvoiceIds(Set invoiceIds) throws DaoException {
+ Query query = getDslContext()
+ .select(INVOICE_CART.INVOICE_ID)
+ .from(INVOICE_CART)
+ .where(INVOICE_CART.INVOICE_ID.in(invoiceIds))
+ .groupBy(INVOICE_CART.INVOICE_ID)
+ .having(DSL.count(INVOICE_CART.ID).greaterThan(0));
+
+ return new HashSet<>(fetch(query, new SingleColumnRowMapper<>(String.class)));
+ }
}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/impl/InvoiceDaoImpl.java b/src/main/java/dev/vality/newway/dao/invoicing/impl/InvoiceDaoImpl.java
index 1490b4f8..99be3cca 100644
--- a/src/main/java/dev/vality/newway/dao/invoicing/impl/InvoiceDaoImpl.java
+++ b/src/main/java/dev/vality/newway/dao/invoicing/impl/InvoiceDaoImpl.java
@@ -4,18 +4,16 @@
import dev.vality.mapper.RecordRowMapper;
import dev.vality.newway.dao.invoicing.iface.InvoiceDao;
import dev.vality.newway.domain.tables.pojos.Invoice;
+import dev.vality.newway.domain.tables.records.InvoiceRecord;
import dev.vality.newway.exception.DaoException;
import dev.vality.newway.exception.NotFoundException;
-import dev.vality.newway.model.InvoicingKey;
import org.jooq.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
-import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import javax.validation.constraints.NotNull;
-import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -37,11 +35,7 @@ public InvoiceDaoImpl(DataSource dataSource) {
public void saveBatch(List invoices) throws DaoException {
List queries = invoices.stream()
.map(invoice -> getDslContext().newRecord(INVOICE, invoice))
- .map(invoiceRecord -> getDslContext().insertInto(INVOICE)
- .set(invoiceRecord)
- .onConflict(INVOICE.INVOICE_ID, INVOICE.SEQUENCE_ID, INVOICE.CHANGE_ID)
- .doNothing()
- )
+ .map(this::prepareInsertQuery)
.collect(Collectors.toList());
batchExecute(queries);
}
@@ -50,20 +44,21 @@ public void saveBatch(List invoices) throws DaoException {
@Override
public Invoice get(String invoiceId) throws DaoException {
Query query = getDslContext().selectFrom(INVOICE)
- .where(INVOICE.INVOICE_ID.eq(invoiceId).and(INVOICE.CURRENT));
+ .where(INVOICE.INVOICE_ID.eq(invoiceId));
return Optional.ofNullable(fetchOne(query, invoiceRowMapper))
.orElseThrow(
() -> new NotFoundException(String.format("Invoice not found, invoiceId='%s'", invoiceId)));
}
- @Override
- public void switchCurrent(Collection invoicesSwitchIds) throws DaoException {
- invoicesSwitchIds.forEach(ik ->
- this.getNamedParameterJdbcTemplate()
- .update("update nw.invoice set current = false " +
- "where invoice_id =:invoice_id and current;" +
- "update nw.invoice set current = true " +
- "where id = (select max(id) from nw.invoice where invoice_id =:invoice_id);",
- new MapSqlParameterSource("invoice_id", ik.getInvoiceId())));
+ private Query prepareInsertQuery(InvoiceRecord invoiceRecord) {
+ return getDslContext().insertInto(INVOICE)
+ .set(invoiceRecord)
+ .onConflict(
+ INVOICE.INVOICE_ID,
+ INVOICE.SEQUENCE_ID,
+ INVOICE.CHANGE_ID
+ )
+ .doNothing();
}
+
}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/impl/InvoiceIdsGeneratorDaoImpl.java b/src/main/java/dev/vality/newway/dao/invoicing/impl/InvoiceIdsGeneratorDaoImpl.java
deleted file mode 100644
index be6da94d..00000000
--- a/src/main/java/dev/vality/newway/dao/invoicing/impl/InvoiceIdsGeneratorDaoImpl.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package dev.vality.newway.dao.invoicing.impl;
-
-import dev.vality.newway.dao.invoicing.iface.IdsGeneratorDao;
-import dev.vality.newway.exception.DaoException;
-import lombok.RequiredArgsConstructor;
-import org.springframework.core.NestedRuntimeException;
-import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
-import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
-import org.springframework.stereotype.Component;
-
-import java.util.List;
-
-@Component
-@RequiredArgsConstructor
-public class InvoiceIdsGeneratorDaoImpl implements IdsGeneratorDao {
-
- private final NamedParameterJdbcTemplate jdbcTemplate;
-
- @Override
- public List get(int size) throws DaoException {
- try {
- String sql = "select nextval('nw.inv_seq') from generate_series(1, :size)";
- MapSqlParameterSource parameterSource = new MapSqlParameterSource().addValue("size", size);
- return jdbcTemplate.queryForList(sql, parameterSource, Long.class);
- } catch (NestedRuntimeException e) {
- throw new DaoException(e);
- }
- }
-}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/impl/InvoiceStatusInfoDaoImpl.java b/src/main/java/dev/vality/newway/dao/invoicing/impl/InvoiceStatusInfoDaoImpl.java
new file mode 100644
index 00000000..cbc49a3b
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/impl/InvoiceStatusInfoDaoImpl.java
@@ -0,0 +1,87 @@
+package dev.vality.newway.dao.invoicing.impl;
+
+import dev.vality.dao.impl.AbstractGenericDao;
+import dev.vality.mapper.RecordRowMapper;
+import dev.vality.newway.dao.invoicing.iface.InvoiceStatusInfoDao;
+import dev.vality.newway.domain.tables.pojos.InvoiceStatusInfo;
+import dev.vality.newway.domain.tables.records.InvoiceStatusInfoRecord;
+import dev.vality.newway.exception.DaoException;
+import dev.vality.newway.exception.NotFoundException;
+import org.jooq.Query;
+import org.jooq.impl.DSL;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
+
+import javax.sql.DataSource;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static dev.vality.newway.domain.Tables.*;
+
+@Component
+public class InvoiceStatusInfoDaoImpl extends AbstractGenericDao implements InvoiceStatusInfoDao {
+
+ private final RowMapper rowMapper;
+
+ public InvoiceStatusInfoDaoImpl(DataSource dataSource) {
+ super(dataSource);
+ this.rowMapper = new RecordRowMapper<>(INVOICE_STATUS_INFO, InvoiceStatusInfo.class);
+ }
+
+ @Override
+ public void saveBatch(List statuses) throws DaoException {
+ batchExecute(statuses.stream()
+ .map(status -> getDslContext().newRecord(INVOICE_STATUS_INFO, status))
+ .map(this::prepareInsertQuery)
+ .collect(Collectors.toList())
+ );
+ }
+
+ @Override
+ public InvoiceStatusInfo get(String invoiceId) {
+ Query query = getDslContext().selectFrom(INVOICE_STATUS_INFO)
+ .where(INVOICE_STATUS_INFO.INVOICE_ID.eq(invoiceId)
+ .and(INVOICE_STATUS_INFO.CURRENT));
+ return Optional.ofNullable(fetchOne(query, rowMapper)).orElseThrow(() ->
+ new NotFoundException(String.format("InvoiceStatusInfo not found, invoiceId='%s'", invoiceId)));
+ }
+
+ @Override
+ public void switchCurrent(Set invoiceIds) throws DaoException {
+ invoiceIds.forEach(invoiceId -> {
+ setOldStatusInfoNotCurrent(invoiceId);
+ setLatestStatusInfoCurrent(invoiceId);
+ });
+ }
+
+ private Query prepareInsertQuery(InvoiceStatusInfoRecord invoiceStatusInfoRecord) {
+ return getDslContext().insertInto(INVOICE_STATUS_INFO)
+ .set(invoiceStatusInfoRecord)
+ .onConflict(
+ INVOICE_STATUS_INFO.INVOICE_ID,
+ INVOICE_STATUS_INFO.SEQUENCE_ID,
+ INVOICE_STATUS_INFO.CHANGE_ID)
+ .doNothing();
+ }
+
+ private void setOldStatusInfoNotCurrent(String invoiceId) {
+ execute(getDslContext().update(INVOICE_STATUS_INFO)
+ .set(INVOICE_STATUS_INFO.CURRENT, false)
+ .where(INVOICE_STATUS_INFO.INVOICE_ID.eq(invoiceId)
+ .and(INVOICE_STATUS_INFO.CURRENT))
+ );
+ }
+
+ private void setLatestStatusInfoCurrent(String invoiceId) {
+ execute(getDslContext().update(INVOICE_STATUS_INFO)
+ .set(INVOICE_STATUS_INFO.CURRENT, true)
+ .where(INVOICE_STATUS_INFO.ID.eq(
+ DSL.select(DSL.max(INVOICE_STATUS_INFO.ID))
+ .from(INVOICE_STATUS_INFO)
+ .where(INVOICE_STATUS_INFO.INVOICE_ID.eq(invoiceId))
+ ))
+ );
+ }
+}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentAdditionalInfoDaoImpl.java b/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentAdditionalInfoDaoImpl.java
new file mode 100644
index 00000000..84da3e1e
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentAdditionalInfoDaoImpl.java
@@ -0,0 +1,95 @@
+package dev.vality.newway.dao.invoicing.impl;
+
+import dev.vality.dao.impl.AbstractGenericDao;
+import dev.vality.mapper.RecordRowMapper;
+import dev.vality.newway.dao.invoicing.iface.PaymentAdditionalInfoDao;
+import dev.vality.newway.domain.tables.pojos.PaymentAdditionalInfo;
+import dev.vality.newway.domain.tables.records.PaymentAdditionalInfoRecord;
+import dev.vality.newway.exception.DaoException;
+import dev.vality.newway.exception.NotFoundException;
+import dev.vality.newway.model.InvoicingKey;
+import org.jooq.Query;
+import org.jooq.impl.DSL;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
+
+import javax.sql.DataSource;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static dev.vality.newway.domain.tables.PaymentAdditionalInfo.PAYMENT_ADDITIONAL_INFO;
+
+@Component
+public class PaymentAdditionalInfoDaoImpl extends AbstractGenericDao implements PaymentAdditionalInfoDao {
+
+ private final RowMapper rowMapper;
+
+ public PaymentAdditionalInfoDaoImpl(DataSource dataSource) {
+ super(dataSource);
+ this.rowMapper = new RecordRowMapper<>(PAYMENT_ADDITIONAL_INFO, PaymentAdditionalInfo.class);
+
+ }
+
+ @Override
+ public void saveBatch(List paymentAdditionalInfos) throws DaoException {
+ List queries = paymentAdditionalInfos.stream()
+ .map(statusInfo -> getDslContext().newRecord(PAYMENT_ADDITIONAL_INFO, statusInfo))
+ .map(this::prepareInsertQuery
+ )
+ .collect(Collectors.toList());
+ batchExecute(queries);
+ }
+
+ @Override
+ public PaymentAdditionalInfo get(String invoiceId, String paymentId) throws DaoException {
+ Query query = getDslContext().selectFrom(PAYMENT_ADDITIONAL_INFO)
+ .where(PAYMENT_ADDITIONAL_INFO.INVOICE_ID.eq(invoiceId)
+ .and(PAYMENT_ADDITIONAL_INFO.PAYMENT_ID.eq(paymentId))
+ .and(PAYMENT_ADDITIONAL_INFO.CURRENT));
+ return Optional.ofNullable(fetchOne(query, rowMapper)).orElseThrow(() ->
+ new NotFoundException("PaymentAdditionalInfo not found, invoiceId=" + invoiceId + " paymentId=" + paymentId));
+ }
+
+ @Override
+ public void switchCurrent(Set invoicesSwitchIds) throws DaoException {
+ invoicesSwitchIds.forEach(key -> {
+ setOldAdditionalInfoNotCurrent(key);
+ setLatestAdditionalInfoCurrent(key);
+ });
+ }
+
+ private Query prepareInsertQuery(PaymentAdditionalInfoRecord record) {
+ return getDslContext().insertInto(PAYMENT_ADDITIONAL_INFO)
+ .set(record)
+ .onConflict(
+ PAYMENT_ADDITIONAL_INFO.INVOICE_ID,
+ PAYMENT_ADDITIONAL_INFO.PAYMENT_ID,
+ PAYMENT_ADDITIONAL_INFO.SEQUENCE_ID,
+ PAYMENT_ADDITIONAL_INFO.CHANGE_ID
+ )
+ .doNothing();
+ }
+
+ private void setOldAdditionalInfoNotCurrent(InvoicingKey key) {
+ execute(getDslContext().update(PAYMENT_ADDITIONAL_INFO)
+ .set(PAYMENT_ADDITIONAL_INFO.CURRENT, false)
+ .where(PAYMENT_ADDITIONAL_INFO.INVOICE_ID.eq(key.getInvoiceId())
+ .and(PAYMENT_ADDITIONAL_INFO.PAYMENT_ID.eq(key.getPaymentId()))
+ .and(PAYMENT_ADDITIONAL_INFO.CURRENT))
+ );
+ }
+
+ private void setLatestAdditionalInfoCurrent(InvoicingKey key) {
+ execute(getDslContext().update(PAYMENT_ADDITIONAL_INFO)
+ .set(PAYMENT_ADDITIONAL_INFO.CURRENT, true)
+ .where(PAYMENT_ADDITIONAL_INFO.ID.eq(
+ DSL.select(DSL.max(PAYMENT_ADDITIONAL_INFO.ID))
+ .from(PAYMENT_ADDITIONAL_INFO)
+ .where(PAYMENT_ADDITIONAL_INFO.INVOICE_ID.eq(key.getInvoiceId())
+ .and(PAYMENT_ADDITIONAL_INFO.PAYMENT_ID.eq(key.getPaymentId())))
+ ))
+ );
+ }
+}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentDaoImpl.java b/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentDaoImpl.java
index 7af1bbb7..2d6c0074 100644
--- a/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentDaoImpl.java
+++ b/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentDaoImpl.java
@@ -4,18 +4,16 @@
import dev.vality.mapper.RecordRowMapper;
import dev.vality.newway.dao.invoicing.iface.PaymentDao;
import dev.vality.newway.domain.tables.pojos.Payment;
+import dev.vality.newway.domain.tables.records.PaymentRecord;
import dev.vality.newway.exception.DaoException;
import dev.vality.newway.exception.NotFoundException;
-import dev.vality.newway.model.InvoicingKey;
import org.jooq.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
-import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import javax.validation.constraints.NotNull;
-import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -37,22 +35,7 @@ public PaymentDaoImpl(DataSource dataSource) {
public void saveBatch(List payments) throws DaoException {
List queries = payments.stream()
.map(payment -> getDslContext().newRecord(PAYMENT, payment))
- .map(paymentRecord -> getDslContext().insertInto(PAYMENT)
- .set(paymentRecord)
- .onConflict(PAYMENT.INVOICE_ID, PAYMENT.SEQUENCE_ID, PAYMENT.CHANGE_ID)
- .doNothing()
- )
- .collect(Collectors.toList());
- batchExecute(queries);
- }
-
- @Override
- public void updateBatch(List payments) throws DaoException {
- List queries = payments.stream()
- .map(payment -> getDslContext().newRecord(PAYMENT, payment))
- .map(paymentRecord -> getDslContext().update(PAYMENT)
- .set(paymentRecord)
- .where(PAYMENT.ID.eq(paymentRecord.getId())))
+ .map(this::prepareInsertQuery)
.collect(Collectors.toList());
batchExecute(queries);
}
@@ -62,24 +45,22 @@ public void updateBatch(List payments) throws DaoException {
public Payment get(String invoiceId, String paymentId) throws DaoException {
Query query = getDslContext().selectFrom(PAYMENT)
.where(PAYMENT.INVOICE_ID.eq(invoiceId)
- .and(PAYMENT.PAYMENT_ID.eq(paymentId))
- .and(PAYMENT.CURRENT));
-
+ .and(PAYMENT.PAYMENT_ID.eq(paymentId)));
return Optional.ofNullable(fetchOne(query, paymentRowMapper))
.orElseThrow(() -> new NotFoundException(
String.format("Payment not found, invoiceId='%s', paymentId='%s'", invoiceId, paymentId)));
}
- @Override
- public void switchCurrent(Collection paymentsSwitchIds) throws DaoException {
- paymentsSwitchIds.forEach(ik ->
- this.getNamedParameterJdbcTemplate()
- .update("update nw.payment set current = false " +
- "where invoice_id =:invoice_id and payment_id=:payment_id and current;" +
- "update nw.payment set current = true " +
- "where id = (select max(id) from nw.payment where invoice_id =:invoice_id " +
- "and payment_id=:payment_id);",
- new MapSqlParameterSource("invoice_id", ik.getInvoiceId())
- .addValue("payment_id", ik.getPaymentId())));
+ private Query prepareInsertQuery(PaymentRecord paymentRecord) {
+ return getDslContext().insertInto(PAYMENT)
+ .set(paymentRecord)
+ .onConflict(
+ PAYMENT.INVOICE_ID,
+ PAYMENT.PAYMENT_ID,
+ PAYMENT.SEQUENCE_ID,
+ PAYMENT.CHANGE_ID
+ )
+ .doNothing();
}
+
}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentFeeDaoImpl.java b/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentFeeDaoImpl.java
new file mode 100644
index 00000000..fd5d0b16
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentFeeDaoImpl.java
@@ -0,0 +1,94 @@
+package dev.vality.newway.dao.invoicing.impl;
+
+import dev.vality.dao.impl.AbstractGenericDao;
+import dev.vality.mapper.RecordRowMapper;
+import dev.vality.newway.dao.invoicing.iface.PaymentFeeDao;
+import dev.vality.newway.domain.tables.pojos.PaymentFee;
+import dev.vality.newway.domain.tables.records.PaymentFeeRecord;
+import dev.vality.newway.exception.DaoException;
+import dev.vality.newway.exception.NotFoundException;
+import dev.vality.newway.model.InvoicingKey;
+import org.jooq.Query;
+import org.jooq.impl.DSL;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
+
+import javax.sql.DataSource;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static dev.vality.newway.domain.tables.PaymentFee.PAYMENT_FEE;
+
+@Component
+public class PaymentFeeDaoImpl extends AbstractGenericDao implements PaymentFeeDao {
+
+ private final RowMapper rowMapper;
+
+ public PaymentFeeDaoImpl(DataSource dataSource) {
+ super(dataSource);
+ this.rowMapper = new RecordRowMapper<>(PAYMENT_FEE, PaymentFee.class);
+ }
+
+ @Override
+ public void saveBatch(List paymentFees) throws DaoException {
+ List queries = paymentFees.stream()
+ .map(statusInfo -> getDslContext().newRecord(PAYMENT_FEE, statusInfo))
+ .map(this::prepareInsertQuery)
+ .collect(Collectors.toList());
+ batchExecute(queries);
+ }
+
+ @Override
+ public PaymentFee get(String invoiceId, String paymentId) throws DaoException {
+ Query query = getDslContext().selectFrom(PAYMENT_FEE)
+ .where(PAYMENT_FEE.INVOICE_ID.eq(invoiceId)
+ .and(PAYMENT_FEE.PAYMENT_ID.eq(paymentId))
+ .and(PAYMENT_FEE.CURRENT)
+ );
+ return Optional.ofNullable(fetchOne(query, rowMapper)).orElseThrow(() ->
+ new NotFoundException("PaymentFee not found, invoiceId=" + invoiceId + " paymentId=" + paymentId));
+ }
+
+ @Override
+ public void switchCurrent(Set invoicingKeys) throws DaoException {
+ invoicingKeys.forEach(key -> {
+ setOldPaymentFeeNotCurrent(key);
+ setLatestPaymentFeeCurrent(key);
+ });
+ }
+
+ private Query prepareInsertQuery(PaymentFeeRecord record) {
+ return getDslContext().insertInto(PAYMENT_FEE)
+ .set(record)
+ .onConflict(
+ PAYMENT_FEE.INVOICE_ID,
+ PAYMENT_FEE.PAYMENT_ID,
+ PAYMENT_FEE.SEQUENCE_ID,
+ PAYMENT_FEE.CHANGE_ID
+ )
+ .doNothing();
+ }
+
+ private void setOldPaymentFeeNotCurrent(InvoicingKey key) {
+ execute(getDslContext().update(PAYMENT_FEE)
+ .set(PAYMENT_FEE.CURRENT, false)
+ .where(PAYMENT_FEE.INVOICE_ID.eq(key.getInvoiceId())
+ .and(PAYMENT_FEE.PAYMENT_ID.eq(key.getPaymentId()))
+ .and(PAYMENT_FEE.CURRENT))
+ );
+ }
+
+ private void setLatestPaymentFeeCurrent(InvoicingKey key) {
+ execute(getDslContext().update(PAYMENT_FEE)
+ .set(PAYMENT_FEE.CURRENT, true)
+ .where(PAYMENT_FEE.ID.eq(
+ DSL.select(DSL.max(PAYMENT_FEE.ID))
+ .from(PAYMENT_FEE)
+ .where(PAYMENT_FEE.INVOICE_ID.eq(key.getInvoiceId())
+ .and(PAYMENT_FEE.PAYMENT_ID.eq(key.getPaymentId())))
+ ))
+ );
+ }
+}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentPayerInfoDaoImpl.java b/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentPayerInfoDaoImpl.java
new file mode 100644
index 00000000..71f65ed9
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentPayerInfoDaoImpl.java
@@ -0,0 +1,60 @@
+package dev.vality.newway.dao.invoicing.impl;
+
+import dev.vality.dao.impl.AbstractGenericDao;
+import dev.vality.mapper.RecordRowMapper;
+import dev.vality.newway.dao.invoicing.iface.PaymentPayerInfoDao;
+import dev.vality.newway.domain.tables.pojos.PaymentPayerInfo;
+import dev.vality.newway.domain.tables.records.PaymentPayerInfoRecord;
+import dev.vality.newway.exception.DaoException;
+import dev.vality.newway.exception.NotFoundException;
+import org.jooq.Query;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
+
+import javax.sql.DataSource;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static dev.vality.newway.domain.tables.PaymentPayerInfo.PAYMENT_PAYER_INFO;
+
+@Component
+public class PaymentPayerInfoDaoImpl extends AbstractGenericDao implements PaymentPayerInfoDao {
+
+ private final RowMapper rowMapper;
+
+ public PaymentPayerInfoDaoImpl(DataSource dataSource) {
+ super(dataSource);
+ this.rowMapper = new RecordRowMapper<>(PAYMENT_PAYER_INFO, PaymentPayerInfo.class);
+ }
+
+ @Override
+ public void saveBatch(List payerInfos) throws DaoException {
+ List queries = payerInfos.stream()
+ .map(statusInfo -> getDslContext().newRecord(PAYMENT_PAYER_INFO, statusInfo))
+ .map(this::prepareInsertQuery)
+ .collect(Collectors.toList());
+ batchExecute(queries);
+ }
+
+ @Override
+ public PaymentPayerInfo get(String invoiceId, String paymentId) throws DaoException {
+ Query query = getDslContext().selectFrom(PAYMENT_PAYER_INFO)
+ .where(PAYMENT_PAYER_INFO.INVOICE_ID.eq(invoiceId)
+ .and(PAYMENT_PAYER_INFO.PAYMENT_ID.eq(paymentId)));
+ return Optional.ofNullable(fetchOne(query, rowMapper)).orElseThrow(() ->
+ new NotFoundException("PaymentPayerInfo not found, invoiceId=" + invoiceId + " paymentId=" + paymentId));
+ }
+
+ private Query prepareInsertQuery(PaymentPayerInfoRecord record) {
+ return getDslContext().insertInto(PAYMENT_PAYER_INFO)
+ .set(record)
+ .onConflict(
+ PAYMENT_PAYER_INFO.INVOICE_ID,
+ PAYMENT_PAYER_INFO.PAYMENT_ID,
+ PAYMENT_PAYER_INFO.SEQUENCE_ID,
+ PAYMENT_PAYER_INFO.CHANGE_ID
+ )
+ .doNothing();
+ }
+}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentRecurrentInfoDaoImpl.java b/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentRecurrentInfoDaoImpl.java
new file mode 100644
index 00000000..d6eed7c6
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentRecurrentInfoDaoImpl.java
@@ -0,0 +1,93 @@
+package dev.vality.newway.dao.invoicing.impl;
+
+import dev.vality.dao.impl.AbstractGenericDao;
+import dev.vality.mapper.RecordRowMapper;
+import dev.vality.newway.dao.invoicing.iface.PaymentRecurrentInfoDao;
+import dev.vality.newway.domain.tables.pojos.PaymentRecurrentInfo;
+import dev.vality.newway.domain.tables.records.PaymentRecurrentInfoRecord;
+import dev.vality.newway.exception.DaoException;
+import dev.vality.newway.exception.NotFoundException;
+import dev.vality.newway.model.InvoicingKey;
+import org.jooq.Query;
+import org.jooq.impl.DSL;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
+
+import javax.sql.DataSource;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static dev.vality.newway.domain.tables.PaymentRecurrentInfo.PAYMENT_RECURRENT_INFO;
+
+@Component
+public class PaymentRecurrentInfoDaoImpl extends AbstractGenericDao implements PaymentRecurrentInfoDao {
+
+ private final RowMapper rowMapper;
+
+ public PaymentRecurrentInfoDaoImpl(DataSource dataSource) {
+ super(dataSource);
+ this.rowMapper = new RecordRowMapper<>(PAYMENT_RECURRENT_INFO, PaymentRecurrentInfo.class);
+ }
+
+ @Override
+ public void saveBatch(List paymentRecurrentInfos) throws DaoException {
+ List queries = paymentRecurrentInfos.stream()
+ .map(statusInfo -> getDslContext().newRecord(PAYMENT_RECURRENT_INFO, statusInfo))
+ .map(this::prepareInsertQuery)
+ .collect(Collectors.toList());
+ batchExecute(queries);
+ }
+
+ @Override
+ public PaymentRecurrentInfo get(String invoiceId, String paymentId) throws DaoException {
+ Query query = getDslContext().selectFrom(PAYMENT_RECURRENT_INFO)
+ .where(PAYMENT_RECURRENT_INFO.INVOICE_ID.eq(invoiceId)
+ .and(PAYMENT_RECURRENT_INFO.PAYMENT_ID.eq(paymentId))
+ .and(PAYMENT_RECURRENT_INFO.CURRENT));
+ return Optional.ofNullable(fetchOne(query, rowMapper)).orElseThrow(() ->
+ new NotFoundException("PaymentPayerInfo not found, invoiceId=" + invoiceId + " paymentId=" + paymentId));
+ }
+
+ @Override
+ public void switchCurrent(Set invoicesSwitchIds) throws DaoException {
+ invoicesSwitchIds.forEach(key -> {
+ setOldRecurrentInfoNotCurrent(key);
+ setLatestRecurrentInfoCurrent(key);
+ });
+ }
+
+ private Query prepareInsertQuery(PaymentRecurrentInfoRecord record) {
+ return getDslContext().insertInto(PAYMENT_RECURRENT_INFO)
+ .set(record)
+ .onConflict(
+ PAYMENT_RECURRENT_INFO.INVOICE_ID,
+ PAYMENT_RECURRENT_INFO.PAYMENT_ID,
+ PAYMENT_RECURRENT_INFO.SEQUENCE_ID,
+ PAYMENT_RECURRENT_INFO.CHANGE_ID
+ )
+ .doNothing();
+ }
+
+ private void setOldRecurrentInfoNotCurrent(InvoicingKey key) {
+ execute(getDslContext().update(PAYMENT_RECURRENT_INFO)
+ .set(PAYMENT_RECURRENT_INFO.CURRENT, false)
+ .where(PAYMENT_RECURRENT_INFO.INVOICE_ID.eq(key.getInvoiceId())
+ .and(PAYMENT_RECURRENT_INFO.PAYMENT_ID.eq(key.getPaymentId()))
+ .and(PAYMENT_RECURRENT_INFO.CURRENT))
+ );
+ }
+
+ private void setLatestRecurrentInfoCurrent(InvoicingKey key) {
+ execute(getDslContext().update(PAYMENT_RECURRENT_INFO)
+ .set(PAYMENT_RECURRENT_INFO.CURRENT, true)
+ .where(PAYMENT_RECURRENT_INFO.ID.eq(
+ DSL.select(DSL.max(PAYMENT_RECURRENT_INFO.ID))
+ .from(PAYMENT_RECURRENT_INFO)
+ .where(PAYMENT_RECURRENT_INFO.INVOICE_ID.eq(key.getInvoiceId())
+ .and(PAYMENT_RECURRENT_INFO.PAYMENT_ID.eq(key.getPaymentId())))
+ ))
+ );
+ }
+}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentRiskDataDaoImpl.java b/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentRiskDataDaoImpl.java
new file mode 100644
index 00000000..3811b5ec
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentRiskDataDaoImpl.java
@@ -0,0 +1,94 @@
+package dev.vality.newway.dao.invoicing.impl;
+
+import dev.vality.dao.impl.AbstractGenericDao;
+import dev.vality.mapper.RecordRowMapper;
+import dev.vality.newway.dao.invoicing.iface.PaymentRiskDataDao;
+import dev.vality.newway.domain.tables.pojos.PaymentRiskData;
+import dev.vality.newway.domain.tables.records.PaymentRiskDataRecord;
+import dev.vality.newway.exception.DaoException;
+import dev.vality.newway.exception.NotFoundException;
+import dev.vality.newway.model.InvoicingKey;
+import org.jooq.Query;
+import org.jooq.impl.DSL;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
+
+import javax.sql.DataSource;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static dev.vality.newway.domain.tables.PaymentRiskData.PAYMENT_RISK_DATA;
+
+@Component
+public class PaymentRiskDataDaoImpl extends AbstractGenericDao implements PaymentRiskDataDao {
+
+ private final RowMapper rowMapper;
+
+ public PaymentRiskDataDaoImpl(DataSource dataSource) {
+ super(dataSource);
+ this.rowMapper = new RecordRowMapper<>(PAYMENT_RISK_DATA, PaymentRiskData.class);
+ }
+
+ @Override
+ public void saveBatch(List paymentRiskDataList) throws DaoException {
+ List queries = paymentRiskDataList.stream()
+ .map(statusInfo -> getDslContext().newRecord(PAYMENT_RISK_DATA, statusInfo))
+ .map(this::prepareInsertQuery)
+ .collect(Collectors.toList());
+ batchExecute(queries);
+ }
+
+ @Override
+ public PaymentRiskData get(String invoiceId, String paymentId) throws DaoException {
+ Query query = getDslContext().selectFrom(PAYMENT_RISK_DATA)
+ .where(PAYMENT_RISK_DATA.INVOICE_ID.eq(invoiceId)
+ .and(PAYMENT_RISK_DATA.PAYMENT_ID.eq(paymentId))
+ .and(PAYMENT_RISK_DATA.CURRENT)
+ );
+ return Optional.ofNullable(fetchOne(query, rowMapper)).orElseThrow(() ->
+ new NotFoundException("PaymentRiskData not found, invoiceId=" + invoiceId + " paymentId=" + paymentId));
+ }
+
+ @Override
+ public void switchCurrent(Set invoicingKeys) throws DaoException {
+ invoicingKeys.forEach(key -> {
+ setOldRiskDataNotCurrent(key);
+ setLatestRiskDataCurrent(key);
+ });
+ }
+
+ private Query prepareInsertQuery(PaymentRiskDataRecord record) {
+ return getDslContext().insertInto(PAYMENT_RISK_DATA)
+ .set(record)
+ .onConflict(
+ PAYMENT_RISK_DATA.INVOICE_ID,
+ PAYMENT_RISK_DATA.PAYMENT_ID,
+ PAYMENT_RISK_DATA.SEQUENCE_ID,
+ PAYMENT_RISK_DATA.CHANGE_ID
+ )
+ .doNothing();
+ }
+
+ private void setOldRiskDataNotCurrent(InvoicingKey key) {
+ execute(getDslContext().update(PAYMENT_RISK_DATA)
+ .set(PAYMENT_RISK_DATA.CURRENT, false)
+ .where(PAYMENT_RISK_DATA.INVOICE_ID.eq(key.getInvoiceId())
+ .and(PAYMENT_RISK_DATA.PAYMENT_ID.eq(key.getPaymentId()))
+ .and(PAYMENT_RISK_DATA.CURRENT))
+ );
+ }
+
+ private void setLatestRiskDataCurrent(InvoicingKey key) {
+ execute(getDslContext().update(PAYMENT_RISK_DATA)
+ .set(PAYMENT_RISK_DATA.CURRENT, true)
+ .where(PAYMENT_RISK_DATA.ID.eq(
+ DSL.select(DSL.max(PAYMENT_RISK_DATA.ID))
+ .from(PAYMENT_RISK_DATA)
+ .where(PAYMENT_RISK_DATA.INVOICE_ID.eq(key.getInvoiceId())
+ .and(PAYMENT_RISK_DATA.PAYMENT_ID.eq(key.getPaymentId())))
+ ))
+ );
+ }
+}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentRouteDaoImpl.java b/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentRouteDaoImpl.java
new file mode 100644
index 00000000..cd182e4a
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentRouteDaoImpl.java
@@ -0,0 +1,94 @@
+package dev.vality.newway.dao.invoicing.impl;
+
+import dev.vality.dao.impl.AbstractGenericDao;
+import dev.vality.mapper.RecordRowMapper;
+import dev.vality.newway.dao.invoicing.iface.PaymentRouteDao;
+import dev.vality.newway.domain.tables.pojos.PaymentRoute;
+import dev.vality.newway.domain.tables.records.PaymentRouteRecord;
+import dev.vality.newway.exception.DaoException;
+import dev.vality.newway.exception.NotFoundException;
+import dev.vality.newway.model.InvoicingKey;
+import org.jooq.Query;
+import org.jooq.impl.DSL;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
+
+import javax.sql.DataSource;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static dev.vality.newway.domain.tables.PaymentRoute.PAYMENT_ROUTE;
+
+@Component
+public class PaymentRouteDaoImpl extends AbstractGenericDao implements PaymentRouteDao {
+
+ private final RowMapper rowMapper;
+
+ public PaymentRouteDaoImpl(DataSource dataSource) {
+ super(dataSource);
+ this.rowMapper = new RecordRowMapper<>(PAYMENT_ROUTE, PaymentRoute.class);
+ }
+
+ @Override
+ public void saveBatch(List paymentRoutes) throws DaoException {
+ List queries = paymentRoutes.stream()
+ .map(statusInfo -> getDslContext().newRecord(PAYMENT_ROUTE, statusInfo))
+ .map(this::prepareInsertQuery)
+ .collect(Collectors.toList());
+ batchExecute(queries);
+ }
+
+ @Override
+ public PaymentRoute get(String invoiceId, String paymentId) throws DaoException {
+ Query query = getDslContext().selectFrom(PAYMENT_ROUTE)
+ .where(PAYMENT_ROUTE.INVOICE_ID.eq(invoiceId)
+ .and(PAYMENT_ROUTE.PAYMENT_ID.eq(paymentId))
+ .and(PAYMENT_ROUTE.CURRENT)
+ );
+ return Optional.ofNullable(fetchOne(query, rowMapper)).orElseThrow(() ->
+ new NotFoundException("PaymentRoute not found, invoiceId=" + invoiceId + " paymentId=" + paymentId));
+ }
+
+ @Override
+ public void switchCurrent(Set invoicingKeys) throws DaoException {
+ invoicingKeys.forEach(key -> {
+ setOldRouteNotCurrent(key);
+ setLatestRouteCurrent(key);
+ });
+ }
+
+ private void setOldRouteNotCurrent(InvoicingKey key) {
+ execute(getDslContext().update(PAYMENT_ROUTE)
+ .set(PAYMENT_ROUTE.CURRENT, false)
+ .where(PAYMENT_ROUTE.INVOICE_ID.eq(key.getInvoiceId())
+ .and(PAYMENT_ROUTE.PAYMENT_ID.eq(key.getPaymentId()))
+ .and(PAYMENT_ROUTE.CURRENT))
+ );
+ }
+
+ private void setLatestRouteCurrent(InvoicingKey key) {
+ execute(getDslContext().update(PAYMENT_ROUTE)
+ .set(PAYMENT_ROUTE.CURRENT, true)
+ .where(PAYMENT_ROUTE.ID.eq(
+ DSL.select(DSL.max(PAYMENT_ROUTE.ID))
+ .from(PAYMENT_ROUTE)
+ .where(PAYMENT_ROUTE.INVOICE_ID.eq(key.getInvoiceId())
+ .and(PAYMENT_ROUTE.PAYMENT_ID.eq(key.getPaymentId())))
+ ))
+ );
+ }
+
+ private Query prepareInsertQuery(PaymentRouteRecord record) {
+ return getDslContext().insertInto(PAYMENT_ROUTE)
+ .set(record)
+ .onConflict(
+ PAYMENT_ROUTE.INVOICE_ID,
+ PAYMENT_ROUTE.PAYMENT_ID,
+ PAYMENT_ROUTE.SEQUENCE_ID,
+ PAYMENT_ROUTE.CHANGE_ID
+ )
+ .doNothing();
+ }
+}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentStatusInfoDaoImpl.java b/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentStatusInfoDaoImpl.java
new file mode 100644
index 00000000..3d7f1745
--- /dev/null
+++ b/src/main/java/dev/vality/newway/dao/invoicing/impl/PaymentStatusInfoDaoImpl.java
@@ -0,0 +1,95 @@
+package dev.vality.newway.dao.invoicing.impl;
+
+import dev.vality.dao.impl.AbstractGenericDao;
+import dev.vality.mapper.RecordRowMapper;
+import dev.vality.newway.dao.invoicing.iface.PaymentStatusInfoDao;
+import dev.vality.newway.domain.tables.pojos.PaymentStatusInfo;
+import dev.vality.newway.domain.tables.records.PaymentStatusInfoRecord;
+import dev.vality.newway.exception.DaoException;
+import dev.vality.newway.exception.NotFoundException;
+import dev.vality.newway.model.InvoicingKey;
+import org.jooq.Query;
+import org.jooq.impl.DSL;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
+
+import javax.sql.DataSource;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static dev.vality.newway.domain.tables.PaymentStatusInfo.PAYMENT_STATUS_INFO;
+
+@Component
+public class PaymentStatusInfoDaoImpl extends AbstractGenericDao implements PaymentStatusInfoDao {
+
+ private final RowMapper rowMapper;
+
+ public PaymentStatusInfoDaoImpl(DataSource dataSource) {
+ super(dataSource);
+ this.rowMapper = new RecordRowMapper<>(PAYMENT_STATUS_INFO, PaymentStatusInfo.class);
+ }
+
+ // TODO: try with resources?
+
+ @Override
+ public void saveBatch(List paymentStatusInfos) throws DaoException {
+ List queries = paymentStatusInfos.stream()
+ .map(statusInfo -> getDslContext().newRecord(PAYMENT_STATUS_INFO, statusInfo))
+ .map(this::prepareInsertQuery)
+ .collect(Collectors.toList());
+ batchExecute(queries);
+ }
+
+ @Override
+ public PaymentStatusInfo get(String invoiceId, String paymentId) throws DaoException {
+ Query query = getDslContext().selectFrom(PAYMENT_STATUS_INFO)
+ .where(PAYMENT_STATUS_INFO.INVOICE_ID.eq(invoiceId)
+ .and(PAYMENT_STATUS_INFO.PAYMENT_ID.eq(paymentId))
+ .and(PAYMENT_STATUS_INFO.CURRENT));
+ return Optional.ofNullable(fetchOne(query, rowMapper)).orElseThrow(() ->
+ new NotFoundException("PaymentStatusInfo not found, invoiceId=" + invoiceId + " paymentId=" + paymentId));
+ }
+
+ @Override
+ public void switchCurrent(Set invoicesSwitchIds) throws DaoException {
+ invoicesSwitchIds.forEach(key -> {
+ setOldStatusInfoNotCurrent(key);
+ setLatestStatusInfoCurrent(key);
+ });
+ }
+
+ private Query prepareInsertQuery(PaymentStatusInfoRecord record) {
+ return getDslContext().insertInto(PAYMENT_STATUS_INFO)
+ .set(record)
+ .onConflict(
+ PAYMENT_STATUS_INFO.INVOICE_ID,
+ PAYMENT_STATUS_INFO.PAYMENT_ID,
+ PAYMENT_STATUS_INFO.SEQUENCE_ID,
+ PAYMENT_STATUS_INFO.CHANGE_ID
+ )
+ .doNothing();
+ }
+
+ private void setOldStatusInfoNotCurrent(InvoicingKey key) {
+ execute(getDslContext().update(PAYMENT_STATUS_INFO)
+ .set(PAYMENT_STATUS_INFO.CURRENT, false)
+ .where(PAYMENT_STATUS_INFO.INVOICE_ID.eq(key.getInvoiceId())
+ .and(PAYMENT_STATUS_INFO.PAYMENT_ID.eq(key.getPaymentId()))
+ .and(PAYMENT_STATUS_INFO.CURRENT))
+ );
+ }
+
+ private void setLatestStatusInfoCurrent(InvoicingKey key) {
+ execute(getDslContext().update(PAYMENT_STATUS_INFO)
+ .set(PAYMENT_STATUS_INFO.CURRENT, true)
+ .where(PAYMENT_STATUS_INFO.ID.eq(
+ DSL.select(DSL.max(PAYMENT_STATUS_INFO.ID))
+ .from(PAYMENT_STATUS_INFO)
+ .where(PAYMENT_STATUS_INFO.INVOICE_ID.eq(key.getInvoiceId())
+ .and(PAYMENT_STATUS_INFO.PAYMENT_ID.eq(key.getPaymentId())))
+ ))
+ );
+ }
+}
diff --git a/src/main/java/dev/vality/newway/dao/invoicing/impl/RefundDaoImpl.java b/src/main/java/dev/vality/newway/dao/invoicing/impl/RefundDaoImpl.java
index 7ef47d39..44d9889c 100644
--- a/src/main/java/dev/vality/newway/dao/invoicing/impl/RefundDaoImpl.java
+++ b/src/main/java/dev/vality/newway/dao/invoicing/impl/RefundDaoImpl.java
@@ -64,15 +64,15 @@ public void updateCommissions(Long rfndId) throws DaoException {
MapSqlParameterSource params =
new MapSqlParameterSource("rfndId", rfndId).addValue("objType", PaymentChangeType.refund.name());
this.getNamedParameterJdbcTemplate().update(
- "UPDATE nw.refund SET fee = (SELECT nw.get_refund_fee(nw.cash_flow.*) " +
- "FROM nw.cash_flow WHERE obj_id = :rfndId " +
- "AND obj_type = CAST(:objType as nw.payment_change_type)), " +
- "provider_fee = (SELECT nw.get_refund_provider_fee(nw.cash_flow.*) " +
- "FROM nw.cash_flow WHERE obj_id = :rfndId " +
- "AND obj_type = CAST(:objType as nw.payment_change_type)), " +
- "external_fee = (SELECT nw.get_refund_external_fee(nw.cash_flow.*) " +
- "FROM nw.cash_flow WHERE obj_id = :rfndId " +
- "AND obj_type = CAST(:objType as nw.payment_change_type)) " +
+ "UPDATE dw.refund SET fee = (SELECT dw.get_refund_fee(dw.cash_flow.*) " +
+ "FROM dw.cash_flow WHERE obj_id = :rfndId " +
+ "AND obj_type = CAST(:objType as dw.payment_change_type)), " +
+ "provider_fee = (SELECT dw.get_refund_provider_fee(dw.cash_flow.*) " +
+ "FROM dw.cash_flow WHERE obj_id = :rfndId " +
+ "AND obj_type = CAST(:objType as dw.payment_change_type)), " +
+ "external_fee = (SELECT dw.get_refund_external_fee(dw.cash_flow.*) " +
+ "FROM dw.cash_flow WHERE obj_id = :rfndId " +
+ "AND obj_type = CAST(:objType as dw.payment_change_type)) " +
"WHERE id = :rfndId",
params);
}
diff --git a/src/main/java/dev/vality/newway/dao/party/impl/RevisionDaoImpl.java b/src/main/java/dev/vality/newway/dao/party/impl/RevisionDaoImpl.java
index 15332d70..e5ba6c0c 100644
--- a/src/main/java/dev/vality/newway/dao/party/impl/RevisionDaoImpl.java
+++ b/src/main/java/dev/vality/newway/dao/party/impl/RevisionDaoImpl.java
@@ -17,8 +17,8 @@ public RevisionDaoImpl(DataSource dataSource) {
@Override
public void saveShopsRevision(String partyId, long revision) throws DaoException {
- getNamedParameterJdbcTemplate().update("insert into nw.shop_revision(obj_id, revision) " +
- "select id, :revision from nw.shop where party_id = :party_id and current",
+ getNamedParameterJdbcTemplate().update("insert into dw.shop_revision(obj_id, revision) " +
+ "select id, :revision from dw.shop where party_id = :party_id and current",
new MapSqlParameterSource()
.addValue("party_id", partyId)
.addValue("revision", revision));
@@ -26,8 +26,8 @@ public void saveShopsRevision(String partyId, long revision) throws DaoException
@Override
public void saveContractsRevision(String partyId, long revision) throws DaoException {
- getNamedParameterJdbcTemplate().update("insert into nw.contract_revision(obj_id, revision) " +
- "select id, :revision from nw.contract where party_id = :party_id and current",
+ getNamedParameterJdbcTemplate().update("insert into dw.contract_revision(obj_id, revision) " +
+ "select id, :revision from dw.contract where party_id = :party_id and current",
new MapSqlParameterSource()
.addValue("party_id", partyId)
.addValue("revision", revision));
@@ -35,8 +35,8 @@ public void saveContractsRevision(String partyId, long revision) throws DaoExcep
@Override
public void saveContractorsRevision(String partyId, long revision) throws DaoException {
- getNamedParameterJdbcTemplate().update("insert into nw.contractor_revision(obj_id, revision) " +
- "select id, :revision from nw.contractor where party_id = :party_id and current",
+ getNamedParameterJdbcTemplate().update("insert into dw.contractor_revision(obj_id, revision) " +
+ "select id, :revision from dw.contractor where party_id = :party_id and current",
new MapSqlParameterSource()
.addValue("party_id", partyId)
.addValue("revision", revision));
diff --git a/src/main/java/dev/vality/newway/dao/rate/impl/RateDaoImpl.java b/src/main/java/dev/vality/newway/dao/rate/impl/RateDaoImpl.java
index 8fbf84c3..6fcd54e3 100644
--- a/src/main/java/dev/vality/newway/dao/rate/impl/RateDaoImpl.java
+++ b/src/main/java/dev/vality/newway/dao/rate/impl/RateDaoImpl.java
@@ -42,7 +42,7 @@ public Long save(Rate rate) throws DaoException {
@Override
public List getIds(String sourceId) throws DaoException {
return this.getNamedParameterJdbcTemplate()
- .queryForList("select id from nw.rate where source_id=:source_id and current",
+ .queryForList("select id from dw.rate where source_id=:source_id and current",
new MapSqlParameterSource("source_id", sourceId), Long.class);
}
@@ -50,7 +50,7 @@ public List getIds(String sourceId) throws DaoException {
public void updateNotCurrent(List ids) throws DaoException {
if (ids != null && !ids.isEmpty()) {
this.getNamedParameterJdbcTemplate()
- .update("update nw.rate set current=false where id in (:ids)",
+ .update("update dw.rate set current=false where id in (:ids)",
new MapSqlParameterSource("ids", ids));
}
}
diff --git a/src/main/java/dev/vality/newway/factory/cash/flow/CashFlowFactory.java b/src/main/java/dev/vality/newway/factory/cash/flow/CashFlowFactory.java
new file mode 100644
index 00000000..44d8349c
--- /dev/null
+++ b/src/main/java/dev/vality/newway/factory/cash/flow/CashFlowFactory.java
@@ -0,0 +1,69 @@
+package dev.vality.newway.factory.cash.flow;
+
+import dev.vality.damsel.domain.FinalCashFlowAccount;
+import dev.vality.damsel.domain.FinalCashFlowPosting;
+import dev.vality.geck.common.util.TypeUtil;
+import dev.vality.newway.domain.enums.AdjustmentCashFlowType;
+import dev.vality.newway.domain.enums.PaymentChangeType;
+import dev.vality.newway.domain.tables.pojos.CashFlow;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class CashFlowFactory {
+
+ public static List build(List cashFlowPostings, Long objId,
+ PaymentChangeType paymentChangeType) {
+ return build(cashFlowPostings, objId, paymentChangeType, null);
+ }
+
+ public static List build(List cashFlowPostings, Long objId,
+ PaymentChangeType paymentChangeType,
+ AdjustmentCashFlowType adjustmentCashFlowType) {
+ return cashFlowPostings.stream().map(cf -> {
+ CashFlow pcf = new CashFlow();
+ pcf.setObjId(objId);
+ pcf.setObjType(paymentChangeType);
+ pcf.setAdjFlowType(adjustmentCashFlowType);
+ pcf.setSourceAccountType(getCashFlowAccountType(cf.getSource()));
+ pcf.setSourceAccountTypeValue(getCashFlowAccountTypeValue(cf.getSource()));
+ pcf.setSourceAccountId(cf.getSource().getAccountId());
+ pcf.setDestinationAccountType(getCashFlowAccountType(cf.getDestination()));
+ pcf.setDestinationAccountTypeValue(getCashFlowAccountTypeValue(cf.getDestination()));
+ pcf.setDestinationAccountId(cf.getDestination().getAccountId());
+ pcf.setAmount(cf.getVolume().getAmount());
+ pcf.setCurrencyCode(cf.getVolume().getCurrency().getSymbolicCode());
+ pcf.setDetails(cf.getDetails());
+ return pcf;
+ }).collect(Collectors.toList());
+ }
+
+ private static dev.vality.newway.domain.enums.CashFlowAccount getCashFlowAccountType(FinalCashFlowAccount cfa) {
+ dev.vality.newway.domain.enums.CashFlowAccount sourceAccountType =
+ TypeUtil.toEnumField(cfa.getAccountType().getSetField().getFieldName(), dev.vality.newway.domain.enums.CashFlowAccount.class);
+ if (sourceAccountType == null) {
+ throw new IllegalArgumentException("Illegal cash flow account type: " + cfa.getAccountType());
+ }
+ return sourceAccountType;
+ }
+
+ private static String getCashFlowAccountTypeValue(FinalCashFlowAccount cfa) {
+ if (cfa.getAccountType().isSetMerchant()) {
+ return cfa.getAccountType().getMerchant().name();
+ } else if (cfa.getAccountType().isSetProvider()) {
+ return cfa.getAccountType().getProvider().name();
+ } else if (cfa.getAccountType().isSetSystem()) {
+ return cfa.getAccountType().getSystem().name();
+ } else if (cfa.getAccountType().isSetExternal()) {
+ return cfa.getAccountType().getExternal().name();
+ } else if (cfa.getAccountType().isSetWallet()) {
+ return cfa.getAccountType().getWallet().name();
+ } else {
+ throw new IllegalArgumentException("Illegal cash flow account type: " + cfa.getAccountType());
+ }
+ }
+
+}
diff --git a/src/main/java/dev/vality/newway/factory/cash/flow/CashFlowLinkFactory.java b/src/main/java/dev/vality/newway/factory/cash/flow/CashFlowLinkFactory.java
new file mode 100644
index 00000000..00c727dd
--- /dev/null
+++ b/src/main/java/dev/vality/newway/factory/cash/flow/CashFlowLinkFactory.java
@@ -0,0 +1,26 @@
+package dev.vality.newway.factory.cash.flow;
+
+import dev.vality.newway.domain.tables.pojos.CashFlowLink;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.time.LocalDateTime;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class CashFlowLinkFactory {
+
+ public static CashFlowLink build(String paymentId,
+ String invoiceId,
+ LocalDateTime eventCreatedAt,
+ Integer changeId,
+ Long sequenceId) {
+ CashFlowLink link = new CashFlowLink();
+ link.setPaymentId(paymentId);
+ link.setInvoiceId(invoiceId);
+ link.setEventCreatedAt(eventCreatedAt);
+ link.setChangeId(changeId);
+ link.setSequenceId(sequenceId);
+ return link;
+ }
+
+}
diff --git a/src/main/java/dev/vality/newway/util/ContractorUtil.java b/src/main/java/dev/vality/newway/factory/contractor/ContractorFactory.java
similarity index 91%
rename from src/main/java/dev/vality/newway/util/ContractorUtil.java
rename to src/main/java/dev/vality/newway/factory/contractor/ContractorFactory.java
index 3ef2b4a8..2a31ff4b 100644
--- a/src/main/java/dev/vality/newway/util/ContractorUtil.java
+++ b/src/main/java/dev/vality/newway/factory/contractor/ContractorFactory.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.util;
+package dev.vality.newway.factory.contractor;
import dev.vality.damsel.domain.InternationalLegalEntity;
import dev.vality.damsel.domain.RussianLegalEntity;
@@ -9,11 +9,15 @@
import dev.vality.newway.domain.enums.LegalEntity;
import dev.vality.newway.domain.enums.PrivateEntity;
import dev.vality.newway.domain.tables.pojos.Contractor;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
-public class ContractorUtil {
- public static Contractor convertContractor(long sequenceId, String eventCreatedAt, String partyId,
- dev.vality.damsel.domain.Contractor contractorSource,
- String contractorId, Integer changeId, Integer claimEffectId) {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class ContractorFactory {
+
+ public static Contractor build(long sequenceId, String eventCreatedAt, String partyId,
+ dev.vality.damsel.domain.Contractor contractorSource,
+ String contractorId, Integer changeId, Integer claimEffectId) {
Contractor contractor = new Contractor();
contractor.setSequenceId((int) sequenceId);
contractor.setChangeId(changeId);
diff --git a/src/main/java/dev/vality/newway/factory/invoice/payment/InvoicePaymentEventIdHolderFactory.java b/src/main/java/dev/vality/newway/factory/invoice/payment/InvoicePaymentEventIdHolderFactory.java
new file mode 100644
index 00000000..a52e990e
--- /dev/null
+++ b/src/main/java/dev/vality/newway/factory/invoice/payment/InvoicePaymentEventIdHolderFactory.java
@@ -0,0 +1,20 @@
+package dev.vality.newway.factory.invoice.payment;
+
+import dev.vality.newway.domain.tables.pojos.CashFlowLink;
+import dev.vality.newway.model.InvoicePaymentEventIdHolder;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class InvoicePaymentEventIdHolderFactory {
+
+ public static InvoicePaymentEventIdHolder build(CashFlowLink link) {
+ return new InvoicePaymentEventIdHolder(
+ link.getInvoiceId(),
+ link.getPaymentId(),
+ link.getSequenceId(),
+ link.getChangeId()
+ );
+ }
+
+}
diff --git a/src/main/java/dev/vality/newway/factory/invoice/payment/PaymentFeeFactory.java b/src/main/java/dev/vality/newway/factory/invoice/payment/PaymentFeeFactory.java
new file mode 100644
index 00000000..b55d8fb0
--- /dev/null
+++ b/src/main/java/dev/vality/newway/factory/invoice/payment/PaymentFeeFactory.java
@@ -0,0 +1,37 @@
+package dev.vality.newway.factory.invoice.payment;
+
+import dev.vality.damsel.domain.FinalCashFlowPosting;
+import dev.vality.newway.domain.tables.pojos.PaymentFee;
+import dev.vality.newway.model.CashFlowType;
+import dev.vality.newway.util.CashFlowUtil;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.Map;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class PaymentFeeFactory {
+
+ public static PaymentFee build(List finalCashFlow,
+ String invoiceId,
+ String paymentId,
+ LocalDateTime eventCreatedAt,
+ Integer changeId,
+ Long sequenceId) {
+ PaymentFee paymentFee = new PaymentFee();
+ paymentFee.setEventCreatedAt(eventCreatedAt);
+ paymentFee.setInvoiceId(invoiceId);
+ paymentFee.setPaymentId(paymentId);
+ Map parsedCashFlow = CashFlowUtil.parseCashFlow(finalCashFlow);
+ paymentFee.setFee(parsedCashFlow.getOrDefault(CashFlowType.FEE, 0L));
+ paymentFee.setProviderFee(parsedCashFlow.getOrDefault(CashFlowType.PROVIDER_FEE, 0L));
+ paymentFee.setExternalFee(parsedCashFlow.getOrDefault(CashFlowType.EXTERNAL_FEE, 0L));
+ paymentFee.setGuaranteeDeposit(parsedCashFlow.getOrDefault(CashFlowType.GUARANTEE_DEPOSIT, 0L));
+ paymentFee.setSequenceId(sequenceId);
+ paymentFee.setChangeId(changeId);
+ return paymentFee;
+ }
+
+}
diff --git a/src/main/java/dev/vality/newway/factory/invoice/payment/PaymentRouteFactory.java b/src/main/java/dev/vality/newway/factory/invoice/payment/PaymentRouteFactory.java
new file mode 100644
index 00000000..b583e47d
--- /dev/null
+++ b/src/main/java/dev/vality/newway/factory/invoice/payment/PaymentRouteFactory.java
@@ -0,0 +1,29 @@
+package dev.vality.newway.factory.invoice.payment;
+
+import dev.vality.newway.domain.tables.pojos.PaymentRoute;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.time.LocalDateTime;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class PaymentRouteFactory {
+
+ public static PaymentRoute build(dev.vality.damsel.domain.PaymentRoute paymentRouteSource,
+ String invoiceId,
+ String paymentId,
+ LocalDateTime eventCreatedAt,
+ Integer changeId,
+ Long sequenceId) {
+ PaymentRoute paymentRoute = new PaymentRoute();
+ paymentRoute.setEventCreatedAt(eventCreatedAt);
+ paymentRoute.setInvoiceId(invoiceId);
+ paymentRoute.setPaymentId(paymentId);
+ paymentRoute.setRouteProviderId(paymentRouteSource.getProvider().getId());
+ paymentRoute.setRouteTerminalId(paymentRouteSource.getTerminal().getId());
+ paymentRoute.setSequenceId(sequenceId);
+ paymentRoute.setChangeId(changeId);
+ return paymentRoute;
+ }
+
+}
diff --git a/src/main/java/dev/vality/newway/factory/invoice/payment/PaymentStatusInfoFactory.java b/src/main/java/dev/vality/newway/factory/invoice/payment/PaymentStatusInfoFactory.java
new file mode 100644
index 00000000..f6895af1
--- /dev/null
+++ b/src/main/java/dev/vality/newway/factory/invoice/payment/PaymentStatusInfoFactory.java
@@ -0,0 +1,45 @@
+package dev.vality.newway.factory.invoice.payment;
+
+import dev.vality.damsel.domain.InvoicePaymentCaptured;
+import dev.vality.damsel.domain.InvoicePaymentStatus;
+import dev.vality.geck.common.util.TBaseUtil;
+import dev.vality.newway.domain.enums.PaymentStatus;
+import dev.vality.newway.domain.tables.pojos.PaymentStatusInfo;
+import dev.vality.newway.util.JsonUtil;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.time.LocalDateTime;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class PaymentStatusInfoFactory {
+
+ public static PaymentStatusInfo build(InvoicePaymentStatus status,
+ String invoiceId,
+ String paymentId,
+ LocalDateTime eventCreatedAt,
+ Integer changeId,
+ Long sequenceId) {
+ PaymentStatusInfo statusInfo = new PaymentStatusInfo();
+ statusInfo.setInvoiceId(invoiceId);
+ statusInfo.setPaymentId(paymentId);
+ statusInfo.setStatus(TBaseUtil.unionFieldToEnum(status, PaymentStatus.class));
+ statusInfo.setEventCreatedAt(eventCreatedAt);
+ if (status.isSetCancelled()) {
+ statusInfo.setReason(status.getCancelled().getReason());
+ } else if (status.isSetFailed()) {
+ statusInfo.setReason(JsonUtil.thriftBaseToJsonString(status.getFailed()));
+ } else if (status.isSetCaptured()) {
+ InvoicePaymentCaptured invoicePaymentCaptured = status.getCaptured();
+ statusInfo.setReason(invoicePaymentCaptured.getReason());
+ if (invoicePaymentCaptured.isSetCost()) {
+ statusInfo.setAmount(invoicePaymentCaptured.getCost().getAmount());
+ statusInfo.setCurrencyCode(invoicePaymentCaptured.getCost().getCurrency().getSymbolicCode());
+ }
+ }
+ statusInfo.setChangeId(changeId);
+ statusInfo.setSequenceId(sequenceId);
+ return statusInfo;
+ }
+
+}
diff --git a/src/main/java/dev/vality/newway/factory/AdjustmentMachineEventCopyFactoryImpl.java b/src/main/java/dev/vality/newway/factory/machine/event/AdjustmentMachineEventCopyFactoryImpl.java
similarity index 95%
rename from src/main/java/dev/vality/newway/factory/AdjustmentMachineEventCopyFactoryImpl.java
rename to src/main/java/dev/vality/newway/factory/machine/event/AdjustmentMachineEventCopyFactoryImpl.java
index 4a4b2289..dc975c9d 100644
--- a/src/main/java/dev/vality/newway/factory/AdjustmentMachineEventCopyFactoryImpl.java
+++ b/src/main/java/dev/vality/newway/factory/machine/event/AdjustmentMachineEventCopyFactoryImpl.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.factory;
+package dev.vality.newway.factory.machine.event;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
diff --git a/src/main/java/dev/vality/newway/factory/ChallengeMachineEventCopyFactoryImpl.java b/src/main/java/dev/vality/newway/factory/machine/event/ChallengeMachineEventCopyFactoryImpl.java
similarity index 96%
rename from src/main/java/dev/vality/newway/factory/ChallengeMachineEventCopyFactoryImpl.java
rename to src/main/java/dev/vality/newway/factory/machine/event/ChallengeMachineEventCopyFactoryImpl.java
index 39557103..69ef6036 100644
--- a/src/main/java/dev/vality/newway/factory/ChallengeMachineEventCopyFactoryImpl.java
+++ b/src/main/java/dev/vality/newway/factory/machine/event/ChallengeMachineEventCopyFactoryImpl.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.factory;
+package dev.vality.newway.factory.machine.event;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
diff --git a/src/main/java/dev/vality/newway/factory/ChargebackMachineEventCopyFactoryImpl.java b/src/main/java/dev/vality/newway/factory/machine/event/ChargebackMachineEventCopyFactoryImpl.java
similarity index 95%
rename from src/main/java/dev/vality/newway/factory/ChargebackMachineEventCopyFactoryImpl.java
rename to src/main/java/dev/vality/newway/factory/machine/event/ChargebackMachineEventCopyFactoryImpl.java
index a2c2d793..b7d8ebbc 100644
--- a/src/main/java/dev/vality/newway/factory/ChargebackMachineEventCopyFactoryImpl.java
+++ b/src/main/java/dev/vality/newway/factory/machine/event/ChargebackMachineEventCopyFactoryImpl.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.factory;
+package dev.vality.newway.factory.machine.event;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
diff --git a/src/main/java/dev/vality/newway/factory/DepositAjustmentMachineEventCopyFactoryImpl.java b/src/main/java/dev/vality/newway/factory/machine/event/DepositAjustmentMachineEventCopyFactoryImpl.java
similarity index 96%
rename from src/main/java/dev/vality/newway/factory/DepositAjustmentMachineEventCopyFactoryImpl.java
rename to src/main/java/dev/vality/newway/factory/machine/event/DepositAjustmentMachineEventCopyFactoryImpl.java
index 60fcc30e..cdc37411 100644
--- a/src/main/java/dev/vality/newway/factory/DepositAjustmentMachineEventCopyFactoryImpl.java
+++ b/src/main/java/dev/vality/newway/factory/machine/event/DepositAjustmentMachineEventCopyFactoryImpl.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.factory;
+package dev.vality.newway.factory.machine.event;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
diff --git a/src/main/java/dev/vality/newway/factory/DepositMachineEventCopyFactoryImpl.java b/src/main/java/dev/vality/newway/factory/machine/event/DepositMachineEventCopyFactoryImpl.java
similarity index 96%
rename from src/main/java/dev/vality/newway/factory/DepositMachineEventCopyFactoryImpl.java
rename to src/main/java/dev/vality/newway/factory/machine/event/DepositMachineEventCopyFactoryImpl.java
index b38a5c35..7b833030 100644
--- a/src/main/java/dev/vality/newway/factory/DepositMachineEventCopyFactoryImpl.java
+++ b/src/main/java/dev/vality/newway/factory/machine/event/DepositMachineEventCopyFactoryImpl.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.factory;
+package dev.vality.newway.factory.machine.event;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
diff --git a/src/main/java/dev/vality/newway/factory/DepositRevertMachineEventCopyFactoryImpl.java b/src/main/java/dev/vality/newway/factory/machine/event/DepositRevertMachineEventCopyFactoryImpl.java
similarity index 96%
rename from src/main/java/dev/vality/newway/factory/DepositRevertMachineEventCopyFactoryImpl.java
rename to src/main/java/dev/vality/newway/factory/machine/event/DepositRevertMachineEventCopyFactoryImpl.java
index 736dd686..6ebb37ff 100644
--- a/src/main/java/dev/vality/newway/factory/DepositRevertMachineEventCopyFactoryImpl.java
+++ b/src/main/java/dev/vality/newway/factory/machine/event/DepositRevertMachineEventCopyFactoryImpl.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.factory;
+package dev.vality.newway.factory.machine.event;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
diff --git a/src/main/java/dev/vality/newway/factory/DestinationMachineEventCopyFactoryImpl.java b/src/main/java/dev/vality/newway/factory/machine/event/DestinationMachineEventCopyFactoryImpl.java
similarity index 96%
rename from src/main/java/dev/vality/newway/factory/DestinationMachineEventCopyFactoryImpl.java
rename to src/main/java/dev/vality/newway/factory/machine/event/DestinationMachineEventCopyFactoryImpl.java
index 30648faf..7b9a692e 100644
--- a/src/main/java/dev/vality/newway/factory/DestinationMachineEventCopyFactoryImpl.java
+++ b/src/main/java/dev/vality/newway/factory/machine/event/DestinationMachineEventCopyFactoryImpl.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.factory;
+package dev.vality.newway.factory.machine.event;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
diff --git a/src/main/java/dev/vality/newway/factory/IdentityMachineEventCopyFactoryImpl.java b/src/main/java/dev/vality/newway/factory/machine/event/IdentityMachineEventCopyFactoryImpl.java
similarity index 95%
rename from src/main/java/dev/vality/newway/factory/IdentityMachineEventCopyFactoryImpl.java
rename to src/main/java/dev/vality/newway/factory/machine/event/IdentityMachineEventCopyFactoryImpl.java
index 71d5238b..a8fd1244 100644
--- a/src/main/java/dev/vality/newway/factory/IdentityMachineEventCopyFactoryImpl.java
+++ b/src/main/java/dev/vality/newway/factory/machine/event/IdentityMachineEventCopyFactoryImpl.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.factory;
+package dev.vality.newway.factory.machine.event;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
diff --git a/src/main/java/dev/vality/newway/factory/MachineEventCopyFactory.java b/src/main/java/dev/vality/newway/factory/machine/event/MachineEventCopyFactory.java
similarity index 84%
rename from src/main/java/dev/vality/newway/factory/MachineEventCopyFactory.java
rename to src/main/java/dev/vality/newway/factory/machine/event/MachineEventCopyFactory.java
index e8f363f2..7736997a 100644
--- a/src/main/java/dev/vality/newway/factory/MachineEventCopyFactory.java
+++ b/src/main/java/dev/vality/newway/factory/machine/event/MachineEventCopyFactory.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.factory;
+package dev.vality.newway.factory.machine.event;
import dev.vality.machinegun.eventsink.MachineEvent;
diff --git a/src/main/java/dev/vality/newway/factory/PartyMachineEventCopyFactoryImpl.java b/src/main/java/dev/vality/newway/factory/machine/event/PartyMachineEventCopyFactoryImpl.java
similarity index 95%
rename from src/main/java/dev/vality/newway/factory/PartyMachineEventCopyFactoryImpl.java
rename to src/main/java/dev/vality/newway/factory/machine/event/PartyMachineEventCopyFactoryImpl.java
index 128b6059..bcbb8df2 100644
--- a/src/main/java/dev/vality/newway/factory/PartyMachineEventCopyFactoryImpl.java
+++ b/src/main/java/dev/vality/newway/factory/machine/event/PartyMachineEventCopyFactoryImpl.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.factory;
+package dev.vality.newway.factory.machine.event;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
diff --git a/src/main/java/dev/vality/newway/factory/RecurrentPaymentToolCopyFactoryImpl.java b/src/main/java/dev/vality/newway/factory/machine/event/RecurrentPaymentToolCopyFactoryImpl.java
similarity index 96%
rename from src/main/java/dev/vality/newway/factory/RecurrentPaymentToolCopyFactoryImpl.java
rename to src/main/java/dev/vality/newway/factory/machine/event/RecurrentPaymentToolCopyFactoryImpl.java
index f1b1c457..a5dd50e3 100644
--- a/src/main/java/dev/vality/newway/factory/RecurrentPaymentToolCopyFactoryImpl.java
+++ b/src/main/java/dev/vality/newway/factory/machine/event/RecurrentPaymentToolCopyFactoryImpl.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.factory;
+package dev.vality.newway.factory.machine.event;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
diff --git a/src/main/java/dev/vality/newway/factory/RefundMachineEventCopyFactoryImpl.java b/src/main/java/dev/vality/newway/factory/machine/event/RefundMachineEventCopyFactoryImpl.java
similarity index 95%
rename from src/main/java/dev/vality/newway/factory/RefundMachineEventCopyFactoryImpl.java
rename to src/main/java/dev/vality/newway/factory/machine/event/RefundMachineEventCopyFactoryImpl.java
index 787cb4c6..5a63295e 100644
--- a/src/main/java/dev/vality/newway/factory/RefundMachineEventCopyFactoryImpl.java
+++ b/src/main/java/dev/vality/newway/factory/machine/event/RefundMachineEventCopyFactoryImpl.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.factory;
+package dev.vality.newway.factory.machine.event;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
diff --git a/src/main/java/dev/vality/newway/factory/SourceMachineEventCopyFactoryImpl.java b/src/main/java/dev/vality/newway/factory/machine/event/SourceMachineEventCopyFactoryImpl.java
similarity index 95%
rename from src/main/java/dev/vality/newway/factory/SourceMachineEventCopyFactoryImpl.java
rename to src/main/java/dev/vality/newway/factory/machine/event/SourceMachineEventCopyFactoryImpl.java
index 93064b24..cc4292a1 100644
--- a/src/main/java/dev/vality/newway/factory/SourceMachineEventCopyFactoryImpl.java
+++ b/src/main/java/dev/vality/newway/factory/machine/event/SourceMachineEventCopyFactoryImpl.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.factory;
+package dev.vality.newway.factory.machine.event;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
diff --git a/src/main/java/dev/vality/newway/factory/WalletMachineEventCopyFactoryImpl.java b/src/main/java/dev/vality/newway/factory/machine/event/WalletMachineEventCopyFactoryImpl.java
similarity index 95%
rename from src/main/java/dev/vality/newway/factory/WalletMachineEventCopyFactoryImpl.java
rename to src/main/java/dev/vality/newway/factory/machine/event/WalletMachineEventCopyFactoryImpl.java
index eedc085f..f40c2815 100644
--- a/src/main/java/dev/vality/newway/factory/WalletMachineEventCopyFactoryImpl.java
+++ b/src/main/java/dev/vality/newway/factory/machine/event/WalletMachineEventCopyFactoryImpl.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.factory;
+package dev.vality.newway.factory.machine.event;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
diff --git a/src/main/java/dev/vality/newway/factory/WithdrawalMachineEventCopyFactoryImpl.java b/src/main/java/dev/vality/newway/factory/machine/event/WithdrawalMachineEventCopyFactoryImpl.java
similarity index 96%
rename from src/main/java/dev/vality/newway/factory/WithdrawalMachineEventCopyFactoryImpl.java
rename to src/main/java/dev/vality/newway/factory/machine/event/WithdrawalMachineEventCopyFactoryImpl.java
index 3be91301..aded5c65 100644
--- a/src/main/java/dev/vality/newway/factory/WithdrawalMachineEventCopyFactoryImpl.java
+++ b/src/main/java/dev/vality/newway/factory/machine/event/WithdrawalMachineEventCopyFactoryImpl.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.factory;
+package dev.vality.newway.factory.machine.event;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
diff --git a/src/main/java/dev/vality/newway/factory/WithdrawalSessionMachineEventCopyFactoryImpl.java b/src/main/java/dev/vality/newway/factory/machine/event/WithdrawalSessionMachineEventCopyFactoryImpl.java
similarity index 96%
rename from src/main/java/dev/vality/newway/factory/WithdrawalSessionMachineEventCopyFactoryImpl.java
rename to src/main/java/dev/vality/newway/factory/machine/event/WithdrawalSessionMachineEventCopyFactoryImpl.java
index e678e388..67b357e5 100644
--- a/src/main/java/dev/vality/newway/factory/WithdrawalSessionMachineEventCopyFactoryImpl.java
+++ b/src/main/java/dev/vality/newway/factory/machine/event/WithdrawalSessionMachineEventCopyFactoryImpl.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.factory;
+package dev.vality.newway.factory.machine.event;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/LocalStorage.java b/src/main/java/dev/vality/newway/handler/event/stock/LocalStorage.java
deleted file mode 100644
index b4f9e0c8..00000000
--- a/src/main/java/dev/vality/newway/handler/event/stock/LocalStorage.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package dev.vality.newway.handler.event.stock;
-
-import dev.vality.newway.model.InvoicingKey;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class LocalStorage {
- private Map map = new HashMap<>();
-
- public Object get(InvoicingKey key) {
- return map.get(key);
- }
-
- public void put(InvoicingKey key, Object object) {
- map.put(key, object);
- }
-}
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/DepositCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/DepositCreatedHandler.java
index ffe5dba7..17859f2e 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/DepositCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/DepositCreatedHandler.java
@@ -11,7 +11,7 @@
import dev.vality.newway.dao.deposit.iface.DepositDao;
import dev.vality.newway.domain.enums.DepositStatus;
import dev.vality.newway.domain.tables.pojos.Deposit;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/DepositStatusChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/DepositStatusChangedHandler.java
index 03599b4d..25d96719 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/DepositStatusChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/DepositStatusChangedHandler.java
@@ -15,7 +15,7 @@
import dev.vality.newway.domain.enums.FistfulCashFlowChangeType;
import dev.vality.newway.domain.tables.pojos.Deposit;
import dev.vality.newway.domain.tables.pojos.FistfulCashFlow;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/DepositTransferCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/DepositTransferCreatedHandler.java
index 4d619863..b7262101 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/DepositTransferCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/DepositTransferCreatedHandler.java
@@ -14,7 +14,7 @@
import dev.vality.newway.domain.enums.FistfulCashFlowChangeType;
import dev.vality.newway.domain.tables.pojos.Deposit;
import dev.vality.newway.domain.tables.pojos.FistfulCashFlow;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.util.FistfulCashFlowUtil;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/DepositTransferStatusChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/DepositTransferStatusChangedHandler.java
index 1891ab64..efef023a 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/DepositTransferStatusChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/DepositTransferStatusChangedHandler.java
@@ -15,7 +15,7 @@
import dev.vality.newway.domain.enums.FistfulCashFlowChangeType;
import dev.vality.newway.domain.tables.pojos.Deposit;
import dev.vality.newway.domain.tables.pojos.FistfulCashFlow;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/adjustment/DepositAdjustmentCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/adjustment/DepositAdjustmentCreatedHandler.java
index 13b22be3..34affdae 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/adjustment/DepositAdjustmentCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/adjustment/DepositAdjustmentCreatedHandler.java
@@ -16,7 +16,7 @@
import dev.vality.newway.domain.enums.DepositStatus;
import dev.vality.newway.domain.tables.pojos.Deposit;
import dev.vality.newway.domain.tables.pojos.DepositAdjustment;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.deposit.DepositHandler;
import dev.vality.newway.util.FistfulCashFlowUtil;
import lombok.Getter;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/adjustment/DepositAdjustmentStatusChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/adjustment/DepositAdjustmentStatusChangedHandler.java
index ff0a19b9..e809a768 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/adjustment/DepositAdjustmentStatusChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/adjustment/DepositAdjustmentStatusChangedHandler.java
@@ -15,7 +15,7 @@
import dev.vality.newway.domain.enums.FistfulCashFlowChangeType;
import dev.vality.newway.domain.tables.pojos.DepositAdjustment;
import dev.vality.newway.domain.tables.pojos.FistfulCashFlow;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.deposit.DepositHandler;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/adjustment/DepositAdjustmentTransferCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/adjustment/DepositAdjustmentTransferCreatedHandler.java
index 11d068cc..8f3162cd 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/adjustment/DepositAdjustmentTransferCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/adjustment/DepositAdjustmentTransferCreatedHandler.java
@@ -14,7 +14,7 @@
import dev.vality.newway.domain.enums.FistfulCashFlowChangeType;
import dev.vality.newway.domain.tables.pojos.DepositAdjustment;
import dev.vality.newway.domain.tables.pojos.FistfulCashFlow;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.deposit.DepositHandler;
import dev.vality.newway.util.FistfulCashFlowUtil;
import lombok.Getter;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/adjustment/DepositAdjustmentTransferStatusChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/adjustment/DepositAdjustmentTransferStatusChangedHandler.java
index 4f92df29..e5bc7482 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/adjustment/DepositAdjustmentTransferStatusChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/adjustment/DepositAdjustmentTransferStatusChangedHandler.java
@@ -15,7 +15,7 @@
import dev.vality.newway.domain.enums.FistfulCashFlowChangeType;
import dev.vality.newway.domain.tables.pojos.DepositAdjustment;
import dev.vality.newway.domain.tables.pojos.FistfulCashFlow;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.deposit.DepositHandler;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/revert/DepositRevertCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/revert/DepositRevertCreatedHandler.java
index 2b1e7824..9f8e240a 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/revert/DepositRevertCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/revert/DepositRevertCreatedHandler.java
@@ -12,7 +12,7 @@
import dev.vality.newway.dao.deposit.revert.iface.DepositRevertDao;
import dev.vality.newway.domain.enums.DepositRevertStatus;
import dev.vality.newway.domain.tables.pojos.DepositRevert;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.deposit.DepositHandler;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/revert/DepositRevertStatusChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/revert/DepositRevertStatusChangedHandler.java
index 9b989d01..230ed616 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/revert/DepositRevertStatusChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/revert/DepositRevertStatusChangedHandler.java
@@ -15,7 +15,7 @@
import dev.vality.newway.domain.enums.FistfulCashFlowChangeType;
import dev.vality.newway.domain.tables.pojos.DepositRevert;
import dev.vality.newway.domain.tables.pojos.FistfulCashFlow;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.deposit.DepositHandler;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/revert/DepositRevertTransferCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/revert/DepositRevertTransferCreatedHandler.java
index 70c450f8..76ee2aac 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/revert/DepositRevertTransferCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/revert/DepositRevertTransferCreatedHandler.java
@@ -14,7 +14,7 @@
import dev.vality.newway.domain.enums.FistfulCashFlowChangeType;
import dev.vality.newway.domain.tables.pojos.DepositRevert;
import dev.vality.newway.domain.tables.pojos.FistfulCashFlow;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.deposit.DepositHandler;
import dev.vality.newway.util.FistfulCashFlowUtil;
import lombok.Getter;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/revert/DepositRevertTransferStatusChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/revert/DepositRevertTransferStatusChangedHandler.java
index d884eceb..8fe800e6 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/revert/DepositRevertTransferStatusChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/deposit/revert/DepositRevertTransferStatusChangedHandler.java
@@ -15,7 +15,7 @@
import dev.vality.newway.domain.enums.FistfulCashFlowChangeType;
import dev.vality.newway.domain.tables.pojos.DepositRevert;
import dev.vality.newway.domain.tables.pojos.FistfulCashFlow;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.deposit.DepositHandler;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/destination/DestinationAccountCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/destination/DestinationAccountCreatedHandler.java
index d12bd261..28179c5e 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/destination/DestinationAccountCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/destination/DestinationAccountCreatedHandler.java
@@ -12,7 +12,7 @@
import dev.vality.newway.dao.identity.iface.IdentityDao;
import dev.vality.newway.domain.tables.pojos.Destination;
import dev.vality.newway.domain.tables.pojos.Identity;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/destination/DestinationCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/destination/DestinationCreatedHandler.java
index afcdccb3..dc08b2a4 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/destination/DestinationCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/destination/DestinationCreatedHandler.java
@@ -15,7 +15,7 @@
import dev.vality.newway.domain.enums.DestinationResourceType;
import dev.vality.newway.domain.enums.DestinationStatus;
import dev.vality.newway.domain.tables.pojos.Destination;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.util.JsonUtil;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/destination/DestinationStatusChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/destination/DestinationStatusChangedHandler.java
index 0321e836..da4b4485 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/destination/DestinationStatusChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/destination/DestinationStatusChangedHandler.java
@@ -12,7 +12,7 @@
import dev.vality.newway.dao.destination.iface.DestinationDao;
import dev.vality.newway.domain.enums.DestinationStatus;
import dev.vality.newway.domain.tables.pojos.Destination;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityChallengeCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityChallengeCreatedHandler.java
index 88009d4e..8cf7d576 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityChallengeCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityChallengeCreatedHandler.java
@@ -12,7 +12,7 @@
import dev.vality.newway.dao.identity.iface.ChallengeDao;
import dev.vality.newway.domain.enums.ChallengeStatus;
import dev.vality.newway.domain.tables.pojos.Challenge;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.util.JsonUtil;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityChallengeStatusChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityChallengeStatusChangedHandler.java
index ed833f87..836665c3 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityChallengeStatusChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityChallengeStatusChangedHandler.java
@@ -10,7 +10,7 @@
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.newway.dao.identity.iface.ChallengeDao;
import dev.vality.newway.domain.tables.pojos.Challenge;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityCreatedHandler.java
index 27e441e3..3002942c 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityCreatedHandler.java
@@ -10,7 +10,7 @@
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.newway.dao.identity.iface.IdentityDao;
import dev.vality.newway.domain.tables.pojos.Identity;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.util.JsonUtil;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityEffectiveChallengeChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityEffectiveChallengeChangedHandler.java
index 258e9cba..ab93ed77 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityEffectiveChallengeChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityEffectiveChallengeChangedHandler.java
@@ -9,7 +9,7 @@
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.newway.dao.identity.iface.IdentityDao;
import dev.vality.newway.domain.tables.pojos.Identity;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityLevelChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityLevelChangedHandler.java
index 42122851..add147a7 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityLevelChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/identity/IdentityLevelChangedHandler.java
@@ -9,7 +9,7 @@
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.newway.dao.identity.iface.IdentityDao;
import dev.vality.newway.domain.tables.pojos.Identity;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/adjustment/InvoicePaymentAdjustmentCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/adjustment/InvoicePaymentAdjustmentCreatedHandler.java
index a54d35a8..3e8e3942 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/adjustment/InvoicePaymentAdjustmentCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/adjustment/InvoicePaymentAdjustmentCreatedHandler.java
@@ -22,10 +22,10 @@
import dev.vality.newway.domain.tables.pojos.Adjustment;
import dev.vality.newway.domain.tables.pojos.CashFlow;
import dev.vality.newway.domain.tables.pojos.Payment;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.cash.flow.CashFlowFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.invoicing.InvoicingHandler;
import dev.vality.newway.util.AdjustmentUtils;
-import dev.vality.newway.util.CashFlowUtil;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -111,13 +111,13 @@ public void handle(InvoiceChange invoiceChange, MachineEvent event, Integer chan
adjustmentDao.save(adjustment).ifPresentOrElse(
id -> {
- List newCashFlowList = CashFlowUtil.convertCashFlows(
+ List newCashFlowList = CashFlowFactory.build(
invoicePaymentAdjustment.getNewCashFlow(),
id,
PaymentChangeType.adjustment,
AdjustmentCashFlowType.new_cash_flow);
cashFlowDao.save(newCashFlowList);
- List oldCashFlowList = CashFlowUtil.convertCashFlows(
+ List oldCashFlowList = CashFlowFactory.build(
invoicePaymentAdjustment.getOldCashFlowInverse(),
id,
PaymentChangeType.adjustment,
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/adjustment/InvoicePaymentAdjustmentStatusChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/adjustment/InvoicePaymentAdjustmentStatusChangedHandler.java
index ded4b1b5..5b549bdc 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/adjustment/InvoicePaymentAdjustmentStatusChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/adjustment/InvoicePaymentAdjustmentStatusChangedHandler.java
@@ -17,7 +17,7 @@
import dev.vality.newway.domain.enums.AdjustmentStatus;
import dev.vality.newway.domain.tables.pojos.Adjustment;
import dev.vality.newway.domain.tables.pojos.CashFlow;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.invoicing.InvoicingHandler;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackBodyChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackBodyChangedHandler.java
index 620a18a4..c4610673 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackBodyChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackBodyChangedHandler.java
@@ -12,7 +12,7 @@
import dev.vality.newway.dao.invoicing.iface.ChargebackDao;
import dev.vality.newway.domain.enums.PaymentChangeType;
import dev.vality.newway.domain.tables.pojos.Chargeback;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.invoicing.InvoicingHandler;
import dev.vality.newway.service.CashFlowService;
import lombok.Getter;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackCashFlowChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackCashFlowChangedHandler.java
index 499e3a84..c70cf221 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackCashFlowChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackCashFlowChangedHandler.java
@@ -14,10 +14,10 @@
import dev.vality.newway.domain.enums.PaymentChangeType;
import dev.vality.newway.domain.tables.pojos.CashFlow;
import dev.vality.newway.domain.tables.pojos.Chargeback;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.cash.flow.CashFlowFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.invoicing.InvoicingHandler;
import dev.vality.newway.service.CashFlowService;
-import dev.vality.newway.util.CashFlowUtil;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -65,7 +65,7 @@ public void handle(InvoiceChange change, MachineEvent event, Integer changeId) {
Long oldId = chargebackOld.getId();
chargebackDao.updateNotCurrent(oldId);
cashFlowService.save(oldId, id, PaymentChangeType.chargeback);
- List cashFlows = CashFlowUtil.convertCashFlows(
+ List cashFlows = CashFlowFactory.build(
invoicePaymentChargebackCashFlowChanged.getCashFlow(),
id,
PaymentChangeType.chargeback);
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackCreatedHandler.java
index 33fb4568..297079a4 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackCreatedHandler.java
@@ -19,7 +19,7 @@
import dev.vality.newway.domain.enums.ChargebackStatus;
import dev.vality.newway.domain.tables.pojos.Chargeback;
import dev.vality.newway.domain.tables.pojos.Payment;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.invoicing.InvoicingHandler;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackLevyChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackLevyChangedHandler.java
index 86294133..ba5192fb 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackLevyChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackLevyChangedHandler.java
@@ -12,7 +12,7 @@
import dev.vality.newway.dao.invoicing.iface.ChargebackDao;
import dev.vality.newway.domain.enums.PaymentChangeType;
import dev.vality.newway.domain.tables.pojos.Chargeback;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.invoicing.InvoicingHandler;
import dev.vality.newway.service.CashFlowService;
import lombok.Getter;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackStageChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackStageChangedHandler.java
index 3d8b83ad..4e93fee4 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackStageChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackStageChangedHandler.java
@@ -14,7 +14,7 @@
import dev.vality.newway.domain.enums.ChargebackStage;
import dev.vality.newway.domain.enums.PaymentChangeType;
import dev.vality.newway.domain.tables.pojos.Chargeback;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.invoicing.InvoicingHandler;
import dev.vality.newway.service.CashFlowService;
import lombok.Getter;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackStatusChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackStatusChangedHandler.java
index ebe1f23e..39f931e9 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackStatusChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/chargeback/InvoicePaymentChargebackStatusChangedHandler.java
@@ -14,7 +14,7 @@
import dev.vality.newway.domain.enums.ChargebackStatus;
import dev.vality.newway.domain.enums.PaymentChangeType;
import dev.vality.newway.domain.tables.pojos.Chargeback;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.invoicing.InvoicingHandler;
import dev.vality.newway.service.CashFlowService;
import lombok.Getter;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/refund/InvoicePaymentRefundCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/refund/InvoicePaymentRefundCreatedHandler.java
index 12caefa6..6ef785c1 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/refund/InvoicePaymentRefundCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/refund/InvoicePaymentRefundCreatedHandler.java
@@ -20,9 +20,9 @@
import dev.vality.newway.domain.tables.pojos.CashFlow;
import dev.vality.newway.domain.tables.pojos.Payment;
import dev.vality.newway.domain.tables.pojos.Refund;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.cash.flow.CashFlowFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.invoicing.InvoicingHandler;
-import dev.vality.newway.util.CashFlowUtil;
import dev.vality.newway.util.JsonUtil;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -99,8 +99,8 @@ public void handle(InvoiceChange invoiceChange, MachineEvent event, Integer chan
refundDao.save(refund).ifPresentOrElse(
id -> {
- List cashFlowList = CashFlowUtil
- .convertCashFlows(invoicePaymentRefundCreated.getCashFlow(), id, PaymentChangeType.refund);
+ List cashFlowList = CashFlowFactory.build(
+ invoicePaymentRefundCreated.getCashFlow(), id, PaymentChangeType.refund);
cashFlowDao.save(cashFlowList);
refundDao.updateCommissions(id);
log.info("Refund has been saved, sequenceId={}, invoiceId={}, paymentId={}, refundId={}",
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/refund/InvoicePaymentRefundSessionChangeTransactionBoundHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/refund/InvoicePaymentRefundSessionChangeTransactionBoundHandler.java
index 20e98886..45e90295 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/refund/InvoicePaymentRefundSessionChangeTransactionBoundHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/refund/InvoicePaymentRefundSessionChangeTransactionBoundHandler.java
@@ -13,7 +13,7 @@
import dev.vality.newway.dao.invoicing.iface.RefundDao;
import dev.vality.newway.domain.enums.PaymentChangeType;
import dev.vality.newway.domain.tables.pojos.Refund;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.invoicing.InvoicingHandler;
import dev.vality.newway.service.CashFlowService;
import dev.vality.newway.util.JsonUtil;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/refund/InvoicePaymentRefundStatusChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/refund/InvoicePaymentRefundStatusChangedHandler.java
index 7acea134..c2f22d59 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/refund/InvoicePaymentRefundStatusChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/invoicing/refund/InvoicePaymentRefundStatusChangedHandler.java
@@ -14,7 +14,7 @@
import dev.vality.newway.domain.enums.PaymentChangeType;
import dev.vality.newway.domain.enums.RefundStatus;
import dev.vality.newway.domain.tables.pojos.Refund;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.invoicing.InvoicingHandler;
import dev.vality.newway.service.CashFlowService;
import dev.vality.newway.util.JsonUtil;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/contract/ContractCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/contract/ContractCreatedHandler.java
index 2515e08b..fe1d8ebd 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/contract/ContractCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/contract/ContractCreatedHandler.java
@@ -15,7 +15,7 @@
import dev.vality.newway.factory.claim.effect.ClaimEffectCopyFactory;
import dev.vality.newway.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import dev.vality.newway.util.ContractUtil;
-import dev.vality.newway.util.ContractorUtil;
+import dev.vality.newway.factory.contractor.ContractorFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
@@ -118,7 +118,7 @@ private void updateContractReference(MachineEvent event, Integer changeId, long
String contractId, String partyId, String contractorId, Long cntrctId,
Integer claimEffectId) {
if (contractCreated.isSetContractor()) {
- Contractor contractor = ContractorUtil.convertContractor(sequenceId, event.getCreatedAt(),
+ Contractor contractor = ContractorFactory.build(sequenceId, event.getCreatedAt(),
partyId, contractCreated.getContractor(), contractorId, changeId, claimEffectId);
contractorDao.save(contractor);
}
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/contractor/ContractorCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/contractor/ContractorCreatedHandler.java
index c00a796b..0b13a8b6 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/contractor/ContractorCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/contractor/ContractorCreatedHandler.java
@@ -9,7 +9,7 @@
import dev.vality.newway.dao.party.iface.PartyDao;
import dev.vality.newway.domain.tables.pojos.Contractor;
import dev.vality.newway.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
-import dev.vality.newway.util.ContractorUtil;
+import dev.vality.newway.factory.contractor.ContractorFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
@@ -55,7 +55,7 @@ private void handleEvent(MachineEvent event, Integer changeId, long eventId, lon
eventId, partyId, contractorId);
partyDao.get(partyId); //check party is exist
- Contractor contractor = ContractorUtil.convertContractor(
+ Contractor contractor = ContractorFactory.build(
eventId, event.getCreatedAt(), partyId, contractorCreated, contractorId, changeId, claimEffectId);
contractor.setIdentificationalLevel(partyContractor.getStatus().name());
contractorDao.save(contractor).ifPresentOrElse(
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartyBlockingHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartyBlockingHandler.java
index 9faf6a82..5c53a4ed 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartyBlockingHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartyBlockingHandler.java
@@ -11,7 +11,7 @@
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.newway.dao.party.iface.PartyDao;
import dev.vality.newway.domain.tables.pojos.Party;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.partymngmnt.PartyManagementHandler;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartyCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartyCreatedHandler.java
index 1dabd73e..006ad437 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartyCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartyCreatedHandler.java
@@ -12,7 +12,7 @@
import dev.vality.newway.domain.enums.Blocking;
import dev.vality.newway.domain.enums.Suspension;
import dev.vality.newway.domain.tables.pojos.Party;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.partymngmnt.PartyManagementHandler;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartyMetaSetHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartyMetaSetHandler.java
index ec1d8fbf..8f231185 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartyMetaSetHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartyMetaSetHandler.java
@@ -9,7 +9,7 @@
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.newway.dao.party.iface.PartyDao;
import dev.vality.newway.domain.tables.pojos.Party;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.partymngmnt.PartyManagementHandler;
import dev.vality.newway.util.JsonUtil;
import lombok.Getter;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartyRevisionChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartyRevisionChangedHandler.java
index 32275f28..365f9e52 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartyRevisionChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartyRevisionChangedHandler.java
@@ -11,7 +11,7 @@
import dev.vality.newway.dao.party.iface.PartyDao;
import dev.vality.newway.dao.party.iface.RevisionDao;
import dev.vality.newway.domain.tables.pojos.Party;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.partymngmnt.PartyManagementHandler;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartySuspensionHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartySuspensionHandler.java
index 57c9a936..99df479f 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartySuspensionHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/partymngmnt/party/PartySuspensionHandler.java
@@ -11,7 +11,7 @@
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.newway.dao.party.iface.PartyDao;
import dev.vality.newway.domain.tables.pojos.Party;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.handler.event.stock.impl.partymngmnt.PartyManagementHandler;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolHasAbandonedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolHasAbandonedHandler.java
index 87927c7f..33931f02 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolHasAbandonedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolHasAbandonedHandler.java
@@ -9,7 +9,7 @@
import dev.vality.newway.dao.recurrent.payment.tool.iface.RecurrentPaymentToolDao;
import dev.vality.newway.domain.enums.RecurrentPaymentToolStatus;
import dev.vality.newway.domain.tables.pojos.RecurrentPaymentTool;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolHasAcquiredHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolHasAcquiredHandler.java
index 79c53bec..951e3953 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolHasAcquiredHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolHasAcquiredHandler.java
@@ -9,7 +9,7 @@
import dev.vality.newway.dao.recurrent.payment.tool.iface.RecurrentPaymentToolDao;
import dev.vality.newway.domain.enums.RecurrentPaymentToolStatus;
import dev.vality.newway.domain.tables.pojos.RecurrentPaymentTool;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolHasCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolHasCreatedHandler.java
index adcf593b..f67ce263 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolHasCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolHasCreatedHandler.java
@@ -14,7 +14,7 @@
import dev.vality.newway.domain.enums.PaymentToolType;
import dev.vality.newway.domain.enums.RecurrentPaymentToolStatus;
import dev.vality.newway.domain.tables.pojos.RecurrentPaymentTool;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.util.JsonUtil;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolHasFailedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolHasFailedHandler.java
index b78fcf0c..2ddde637 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolHasFailedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolHasFailedHandler.java
@@ -9,7 +9,7 @@
import dev.vality.newway.dao.recurrent.payment.tool.iface.RecurrentPaymentToolDao;
import dev.vality.newway.domain.enums.RecurrentPaymentToolStatus;
import dev.vality.newway.domain.tables.pojos.RecurrentPaymentTool;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.util.JsonUtil;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolRiskScoreChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolRiskScoreChangedHandler.java
index d7915f37..c1afef15 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolRiskScoreChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolRiskScoreChangedHandler.java
@@ -8,7 +8,7 @@
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.newway.dao.recurrent.payment.tool.iface.RecurrentPaymentToolDao;
import dev.vality.newway.domain.tables.pojos.RecurrentPaymentTool;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolRouteChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolRouteChangedHandler.java
index 98ecdb53..19c1ae30 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolRouteChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolRouteChangedHandler.java
@@ -8,7 +8,7 @@
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.newway.dao.recurrent.payment.tool.iface.RecurrentPaymentToolDao;
import dev.vality.newway.domain.tables.pojos.RecurrentPaymentTool;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolSessionChangedTransactionBoundHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolSessionChangedTransactionBoundHandler.java
index fc7b58fd..37faf404 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolSessionChangedTransactionBoundHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/recurrent/payment/tool/RecurrentPaymentToolSessionChangedTransactionBoundHandler.java
@@ -9,7 +9,7 @@
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.newway.dao.recurrent.payment.tool.iface.RecurrentPaymentToolDao;
import dev.vality.newway.domain.tables.pojos.RecurrentPaymentTool;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.util.JsonUtil;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/source/SourceAccountCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/source/SourceAccountCreatedHandler.java
index be93dc27..9b1e930d 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/source/SourceAccountCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/source/SourceAccountCreatedHandler.java
@@ -12,7 +12,7 @@
import dev.vality.newway.dao.source.iface.SourceDao;
import dev.vality.newway.domain.tables.pojos.Identity;
import dev.vality.newway.domain.tables.pojos.Source;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/source/SourceCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/source/SourceCreatedHandler.java
index 9fd4de57..5e9ce9e6 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/source/SourceCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/source/SourceCreatedHandler.java
@@ -12,7 +12,7 @@
import dev.vality.newway.dao.source.iface.SourceDao;
import dev.vality.newway.domain.enums.SourceStatus;
import dev.vality.newway.domain.tables.pojos.Source;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/source/SourceStatusChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/source/SourceStatusChangedHandler.java
index 276ccfe6..5cfa662a 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/source/SourceStatusChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/source/SourceStatusChangedHandler.java
@@ -12,7 +12,7 @@
import dev.vality.newway.dao.source.iface.SourceDao;
import dev.vality.newway.domain.enums.SourceStatus;
import dev.vality.newway.domain.tables.pojos.Source;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/wallet/WalletAccountCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/wallet/WalletAccountCreatedHandler.java
index 6ff4d804..2e2a900d 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/wallet/WalletAccountCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/wallet/WalletAccountCreatedHandler.java
@@ -12,7 +12,7 @@
import dev.vality.newway.dao.wallet.iface.WalletDao;
import dev.vality.newway.domain.tables.pojos.Identity;
import dev.vality.newway.domain.tables.pojos.Wallet;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/wallet/WalletCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/wallet/WalletCreatedHandler.java
index 6c7adc87..5094f0df 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/wallet/WalletCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/wallet/WalletCreatedHandler.java
@@ -9,7 +9,7 @@
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.newway.dao.wallet.iface.WalletDao;
import dev.vality.newway.domain.tables.pojos.Wallet;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalCreatedHandler.java
index 71e8561e..10f4faaa 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalCreatedHandler.java
@@ -11,7 +11,7 @@
import dev.vality.newway.dao.withdrawal.iface.WithdrawalDao;
import dev.vality.newway.domain.enums.WithdrawalStatus;
import dev.vality.newway.domain.tables.pojos.Withdrawal;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalRouteChangeHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalRouteChangeHandler.java
index 06997275..1516eeba 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalRouteChangeHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalRouteChangeHandler.java
@@ -13,7 +13,7 @@
import dev.vality.newway.domain.enums.FistfulCashFlowChangeType;
import dev.vality.newway.domain.tables.pojos.FistfulCashFlow;
import dev.vality.newway.domain.tables.pojos.Withdrawal;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalStatusChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalStatusChangedHandler.java
index 2043215f..bb8c97b5 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalStatusChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalStatusChangedHandler.java
@@ -15,7 +15,7 @@
import dev.vality.newway.domain.enums.WithdrawalStatus;
import dev.vality.newway.domain.tables.pojos.FistfulCashFlow;
import dev.vality.newway.domain.tables.pojos.Withdrawal;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.util.JsonUtil;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalTransferCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalTransferCreatedHandler.java
index b712bc2e..1beb5b0b 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalTransferCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalTransferCreatedHandler.java
@@ -14,7 +14,7 @@
import dev.vality.newway.domain.enums.WithdrawalTransferStatus;
import dev.vality.newway.domain.tables.pojos.FistfulCashFlow;
import dev.vality.newway.domain.tables.pojos.Withdrawal;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.util.FistfulCashFlowUtil;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalTransferStatusChangedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalTransferStatusChangedHandler.java
index c0915894..4cd1518d 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalTransferStatusChangedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/WithdrawalTransferStatusChangedHandler.java
@@ -15,7 +15,7 @@
import dev.vality.newway.domain.enums.WithdrawalTransferStatus;
import dev.vality.newway.domain.tables.pojos.FistfulCashFlow;
import dev.vality.newway.domain.tables.pojos.Withdrawal;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/session/WithdrawalSessionCreatedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/session/WithdrawalSessionCreatedHandler.java
index f04e1aad..b340a287 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/session/WithdrawalSessionCreatedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/session/WithdrawalSessionCreatedHandler.java
@@ -16,7 +16,7 @@
import dev.vality.newway.domain.enums.DestinationResourceType;
import dev.vality.newway.domain.enums.WithdrawalSessionStatus;
import dev.vality.newway.domain.tables.pojos.WithdrawalSession;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/session/WithdrawalSessionFinishedHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/session/WithdrawalSessionFinishedHandler.java
index 93dd4007..898a8464 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/session/WithdrawalSessionFinishedHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/session/WithdrawalSessionFinishedHandler.java
@@ -11,7 +11,7 @@
import dev.vality.newway.dao.withdrawal.session.iface.WithdrawalSessionDao;
import dev.vality.newway.domain.enums.WithdrawalSessionStatus;
import dev.vality.newway.domain.tables.pojos.WithdrawalSession;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.util.JsonUtil;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/session/WithdrawalSessionNextStateHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/session/WithdrawalSessionNextStateHandler.java
index 26891fa1..f688f46f 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/session/WithdrawalSessionNextStateHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/session/WithdrawalSessionNextStateHandler.java
@@ -9,7 +9,7 @@
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.newway.dao.withdrawal.session.iface.WithdrawalSessionDao;
import dev.vality.newway.domain.tables.pojos.WithdrawalSession;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.util.JsonUtil;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/session/WithdrawalSessionTransactionBoundHandler.java b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/session/WithdrawalSessionTransactionBoundHandler.java
index 8fd769c4..a26a80a2 100644
--- a/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/session/WithdrawalSessionTransactionBoundHandler.java
+++ b/src/main/java/dev/vality/newway/handler/event/stock/impl/withdrawal/session/WithdrawalSessionTransactionBoundHandler.java
@@ -12,7 +12,7 @@
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.newway.dao.withdrawal.session.iface.WithdrawalSessionDao;
import dev.vality.newway.domain.tables.pojos.WithdrawalSession;
-import dev.vality.newway.factory.MachineEventCopyFactory;
+import dev.vality.newway.factory.machine.event.MachineEventCopyFactory;
import dev.vality.newway.util.JsonUtil;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/src/main/java/dev/vality/newway/handler/wrapper/WrapperHandler.java b/src/main/java/dev/vality/newway/handler/wrapper/WrapperHandler.java
new file mode 100644
index 00000000..0aca84eb
--- /dev/null
+++ b/src/main/java/dev/vality/newway/handler/wrapper/WrapperHandler.java
@@ -0,0 +1,11 @@
+package dev.vality.newway.handler.wrapper;
+
+import java.util.List;
+
+public interface WrapperHandler {
+
+ boolean accept(List wrappers);
+
+ void saveBatch(List wrappers);
+
+}
diff --git a/src/main/java/dev/vality/newway/handler/wrapper/invoice/InvoiceCartWrapperHandler.java b/src/main/java/dev/vality/newway/handler/wrapper/invoice/InvoiceCartWrapperHandler.java
new file mode 100644
index 00000000..7c3d724a
--- /dev/null
+++ b/src/main/java/dev/vality/newway/handler/wrapper/invoice/InvoiceCartWrapperHandler.java
@@ -0,0 +1,47 @@
+package dev.vality.newway.handler.wrapper.invoice;
+
+import dev.vality.newway.dao.invoicing.iface.InvoiceCartDao;
+import dev.vality.newway.domain.tables.pojos.InvoiceCart;
+import dev.vality.newway.handler.wrapper.WrapperHandler;
+import dev.vality.newway.model.InvoiceWrapper;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@RequiredArgsConstructor
+@Component
+public class InvoiceCartWrapperHandler implements WrapperHandler {
+
+ private final InvoiceCartDao invoiceCartDao;
+
+ @Override
+ public boolean accept(List wrappers) {
+ return wrappers.stream()
+ .map(InvoiceWrapper::getCarts)
+ .anyMatch(invoiceCarts -> !CollectionUtils.isEmpty(invoiceCarts));
+ }
+
+ @Override
+ public void saveBatch(List wrappers) {
+ List carts = wrappers.stream()
+ .map(InvoiceWrapper::getCarts)
+ .filter(Objects::nonNull)
+ .flatMap(Collection::stream)
+ .collect(Collectors.toList());
+ Set invoiceIds = carts.stream()
+ .map(InvoiceCart::getInvoiceId)
+ .collect(Collectors.toSet());
+ Set existingInvoiceIds = invoiceCartDao.getExistingInvoiceIds(invoiceIds);
+ carts.removeIf(cart -> existingInvoiceIds.contains(cart.getInvoiceId()));
+ if (!carts.isEmpty()) {
+ invoiceCartDao.save(carts);
+ }
+ }
+
+}
diff --git a/src/main/java/dev/vality/newway/handler/wrapper/invoice/InvoiceStatusInfoWrapperHandler.java b/src/main/java/dev/vality/newway/handler/wrapper/invoice/InvoiceStatusInfoWrapperHandler.java
new file mode 100644
index 00000000..d997a7fc
--- /dev/null
+++ b/src/main/java/dev/vality/newway/handler/wrapper/invoice/InvoiceStatusInfoWrapperHandler.java
@@ -0,0 +1,53 @@
+package dev.vality.newway.handler.wrapper.invoice;
+
+import dev.vality.newway.dao.invoicing.iface.InvoiceStatusInfoDao;
+import dev.vality.newway.domain.tables.pojos.InvoiceStatusInfo;
+import dev.vality.newway.handler.wrapper.WrapperHandler;
+import dev.vality.newway.model.InvoiceWrapper;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@Slf4j
+@RequiredArgsConstructor
+@Component
+public class InvoiceStatusInfoWrapperHandler implements WrapperHandler {
+
+ private final InvoiceStatusInfoDao invoiceStatusInfoDao;
+
+ @Override
+ public boolean accept(List wrappers) {
+ return wrappers.stream()
+ .map(InvoiceWrapper::getInvoiceStatusInfo)
+ .anyMatch(Objects::nonNull);
+ }
+
+ @Override
+ public void saveBatch(List wrappers) {
+ saveInvoiceStatusInfos(wrappers);
+ switchCurrent(wrappers);
+ }
+
+ private void saveInvoiceStatusInfos(List wrappers) {
+ List invoiceStatusInfos = wrappers.stream()
+ .map(InvoiceWrapper::getInvoiceStatusInfo)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ invoiceStatusInfoDao.saveBatch(invoiceStatusInfos);
+ }
+
+ private void switchCurrent(List wrappers) {
+ Set invoiceStatusInfoChangedIds = wrappers.stream()
+ .map(InvoiceWrapper::getInvoiceStatusInfo)
+ .filter(Objects::nonNull)
+ .map(InvoiceStatusInfo::getInvoiceId)
+ .collect(Collectors.toSet());
+ log.info("Switch to current ids - invoiceStatusInfo:{}", invoiceStatusInfoChangedIds);
+ invoiceStatusInfoDao.switchCurrent(invoiceStatusInfoChangedIds);
+ }
+}
diff --git a/src/main/java/dev/vality/newway/handler/wrapper/invoice/InvoiceWrapperHandler.java b/src/main/java/dev/vality/newway/handler/wrapper/invoice/InvoiceWrapperHandler.java
new file mode 100644
index 00000000..33bd512b
--- /dev/null
+++ b/src/main/java/dev/vality/newway/handler/wrapper/invoice/InvoiceWrapperHandler.java
@@ -0,0 +1,36 @@
+package dev.vality.newway.handler.wrapper.invoice;
+
+import dev.vality.newway.dao.invoicing.iface.InvoiceDao;
+import dev.vality.newway.domain.tables.pojos.Invoice;
+import dev.vality.newway.handler.wrapper.WrapperHandler;
+import dev.vality.newway.model.InvoiceWrapper;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+@RequiredArgsConstructor
+@Component
+public class InvoiceWrapperHandler implements WrapperHandler {
+
+ private final InvoiceDao invoiceDao;
+
+ @Override
+ public boolean accept(List wrappers) {
+ return wrappers.stream()
+ .map(InvoiceWrapper::getInvoice)
+ .anyMatch(Objects::nonNull);
+ }
+
+ @Override
+ public void saveBatch(List wrappers) {
+ List invoices = wrappers.stream()
+ .map(InvoiceWrapper::getInvoice)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ invoiceDao.saveBatch(invoices);
+ }
+
+}
diff --git a/src/main/java/dev/vality/newway/handler/wrapper/payment/CashFlowWrapperHandler.java b/src/main/java/dev/vality/newway/handler/wrapper/payment/CashFlowWrapperHandler.java
new file mode 100644
index 00000000..a42ef999
--- /dev/null
+++ b/src/main/java/dev/vality/newway/handler/wrapper/payment/CashFlowWrapperHandler.java
@@ -0,0 +1,96 @@
+package dev.vality.newway.handler.wrapper.payment;
+
+import dev.vality.newway.dao.invoicing.iface.CashFlowDao;
+import dev.vality.newway.dao.invoicing.iface.CashFlowLinkDao;
+import dev.vality.newway.dao.invoicing.impl.CashFlowLinkIdsGeneratorDaoImpl;
+import dev.vality.newway.domain.tables.pojos.CashFlow;
+import dev.vality.newway.domain.tables.pojos.CashFlowLink;
+import dev.vality.newway.handler.wrapper.WrapperHandler;
+import dev.vality.newway.model.CashFlowWrapper;
+import dev.vality.newway.model.InvoicePaymentEventIdHolder;
+import dev.vality.newway.model.InvoicingKey;
+import dev.vality.newway.factory.invoice.payment.InvoicePaymentEventIdHolderFactory;
+import dev.vality.newway.model.PaymentWrapper;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+@RequiredArgsConstructor
+@Component
+public class CashFlowWrapperHandler implements WrapperHandler {
+
+ private final CashFlowLinkDao cashFlowLinkDao;
+
+ private final CashFlowDao cashFlowDao;
+
+ private final CashFlowLinkIdsGeneratorDaoImpl idsGenerator;
+
+ @Override
+ public boolean accept(List wrappers) {
+ return wrappers.stream()
+ .map(PaymentWrapper::getCashFlowWrapper)
+ .anyMatch(Objects::nonNull);
+ }
+
+ @Override
+ public void saveBatch(List wrappers) {
+ List cashFlowWrappers = wrappers.stream()
+ .map(PaymentWrapper::getCashFlowWrapper)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+
+ removeAlreadyProcessedWrappers(cashFlowWrappers);
+ if (CollectionUtils.isEmpty(wrappers)) {
+ return;
+ }
+ setLinkIds(cashFlowWrappers);
+ saveCashFlowLinks(cashFlowWrappers);
+ saveCashFlows(cashFlowWrappers);
+ }
+
+ private void removeAlreadyProcessedWrappers(List cashFlowWrappers) {
+ Set existingEvents = cashFlowLinkDao.getExistingEvents(
+ cashFlowWrappers.stream()
+ .map(CashFlowWrapper::getCashFlowLink)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList())
+ );
+ cashFlowWrappers.removeIf(wrapper ->
+ existingEvents.contains(InvoicePaymentEventIdHolderFactory.build(wrapper.getCashFlowLink()))
+ );
+ }
+
+ private void setLinkIds(List cashFlowWrappers) {
+ Iterator linkIdIterator = idsGenerator.get(cashFlowWrappers.size()).iterator();
+ for (CashFlowWrapper wrapper : cashFlowWrappers) {
+ Long linkId = linkIdIterator.next();
+ wrapper.getCashFlowLink().setId(linkId);
+ for (CashFlow cashFlow : wrapper.getCashFlows()) {
+ cashFlow.setObjId(linkId);
+ }
+ }
+ }
+
+ private void saveCashFlowLinks(List cashFlowWrappers) {
+ List links = cashFlowWrappers.stream()
+ .map(CashFlowWrapper::getCashFlowLink)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ cashFlowLinkDao.saveBatch(links);
+ Set invoicingKeys = links.stream()
+ .map(link -> InvoicingKey.buildKey(link.getInvoiceId(), link.getPaymentId()))
+ .collect(Collectors.toSet());
+ cashFlowLinkDao.switchCurrent(invoicingKeys);
+ }
+
+ private void saveCashFlows(List cashFlowWrappers) {
+ List cashFlows = cashFlowWrappers.stream()
+ .flatMap(wrapper -> wrapper.getCashFlows().stream())
+ .collect(Collectors.toList());
+ cashFlowDao.save(cashFlows);
+ }
+
+}
diff --git a/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentAdditionalInfoWrapperHandler.java b/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentAdditionalInfoWrapperHandler.java
new file mode 100644
index 00000000..0f14e70d
--- /dev/null
+++ b/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentAdditionalInfoWrapperHandler.java
@@ -0,0 +1,37 @@
+package dev.vality.newway.handler.wrapper.payment;
+
+import dev.vality.newway.dao.invoicing.iface.PaymentAdditionalInfoDao;
+import dev.vality.newway.domain.tables.pojos.PaymentAdditionalInfo;
+import dev.vality.newway.handler.wrapper.WrapperHandler;
+import dev.vality.newway.model.PaymentWrapper;
+import dev.vality.newway.util.PaymentWrapperUtil;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+@RequiredArgsConstructor
+@Component
+public class PaymentAdditionalInfoWrapperHandler implements WrapperHandler {
+
+ private final PaymentAdditionalInfoDao paymentAdditionalInfoDao;
+
+ @Override
+ public boolean accept(List wrappers) {
+ return wrappers.stream()
+ .map(PaymentWrapper::getPaymentAdditionalInfo)
+ .anyMatch(Objects::nonNull);
+ }
+
+ @Override
+ public void saveBatch(List wrappers) {
+ List paymentAdditionalInfos = wrappers.stream()
+ .map(PaymentWrapper::getPaymentAdditionalInfo)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ paymentAdditionalInfoDao.saveBatch(paymentAdditionalInfos);
+ paymentAdditionalInfoDao.switchCurrent(PaymentWrapperUtil.getInvoicingKeys(wrappers));
+ }
+}
diff --git a/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentFeeWrapperHandler.java b/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentFeeWrapperHandler.java
new file mode 100644
index 00000000..79b5fea8
--- /dev/null
+++ b/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentFeeWrapperHandler.java
@@ -0,0 +1,37 @@
+package dev.vality.newway.handler.wrapper.payment;
+
+import dev.vality.newway.dao.invoicing.iface.PaymentFeeDao;
+import dev.vality.newway.domain.tables.pojos.PaymentFee;
+import dev.vality.newway.handler.wrapper.WrapperHandler;
+import dev.vality.newway.model.PaymentWrapper;
+import dev.vality.newway.util.PaymentWrapperUtil;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+@RequiredArgsConstructor
+@Component
+public class PaymentFeeWrapperHandler implements WrapperHandler {
+
+ private final PaymentFeeDao paymentFeeDao;
+
+ @Override
+ public boolean accept(List wrappers) {
+ return wrappers.stream()
+ .map(PaymentWrapper::getPaymentFee)
+ .anyMatch(Objects::nonNull);
+ }
+
+ @Override
+ public void saveBatch(List wrappers) {
+ List paymentFees = wrappers.stream()
+ .map(PaymentWrapper::getPaymentFee)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ paymentFeeDao.saveBatch(paymentFees);
+ paymentFeeDao.switchCurrent(PaymentWrapperUtil.getInvoicingKeys(wrappers));
+ }
+}
diff --git a/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentPayerInfoWrapperHandler.java b/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentPayerInfoWrapperHandler.java
new file mode 100644
index 00000000..046d2255
--- /dev/null
+++ b/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentPayerInfoWrapperHandler.java
@@ -0,0 +1,35 @@
+package dev.vality.newway.handler.wrapper.payment;
+
+import dev.vality.newway.dao.invoicing.iface.PaymentPayerInfoDao;
+import dev.vality.newway.domain.tables.pojos.PaymentPayerInfo;
+import dev.vality.newway.handler.wrapper.WrapperHandler;
+import dev.vality.newway.model.PaymentWrapper;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+@RequiredArgsConstructor
+@Component
+public class PaymentPayerInfoWrapperHandler implements WrapperHandler {
+
+ private final PaymentPayerInfoDao paymentPayerInfoDao;
+
+ @Override
+ public boolean accept(List wrappers) {
+ return wrappers.stream()
+ .map(PaymentWrapper::getPaymentPayerInfo)
+ .anyMatch(Objects::nonNull);
+ }
+
+ @Override
+ public void saveBatch(List wrappers) {
+ List paymentPayerInfos = wrappers.stream()
+ .map(PaymentWrapper::getPaymentPayerInfo)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ paymentPayerInfoDao.saveBatch(paymentPayerInfos);
+ }
+}
diff --git a/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentRecurrentInfoWrapperHandler.java b/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentRecurrentInfoWrapperHandler.java
new file mode 100644
index 00000000..416cc4c9
--- /dev/null
+++ b/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentRecurrentInfoWrapperHandler.java
@@ -0,0 +1,37 @@
+package dev.vality.newway.handler.wrapper.payment;
+
+import dev.vality.newway.dao.invoicing.iface.PaymentRecurrentInfoDao;
+import dev.vality.newway.domain.tables.pojos.PaymentRecurrentInfo;
+import dev.vality.newway.handler.wrapper.WrapperHandler;
+import dev.vality.newway.model.PaymentWrapper;
+import dev.vality.newway.util.PaymentWrapperUtil;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+@RequiredArgsConstructor
+@Component
+public class PaymentRecurrentInfoWrapperHandler implements WrapperHandler {
+
+ private final PaymentRecurrentInfoDao paymentRecurrentInfoDao;
+
+ @Override
+ public boolean accept(List wrappers) {
+ return wrappers.stream()
+ .map(PaymentWrapper::getPaymentRecurrentInfo)
+ .anyMatch(Objects::nonNull);
+ }
+
+ @Override
+ public void saveBatch(List wrappers) {
+ List paymentRecurrentInfos = wrappers.stream()
+ .map(PaymentWrapper::getPaymentRecurrentInfo)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ paymentRecurrentInfoDao.saveBatch(paymentRecurrentInfos);
+ paymentRecurrentInfoDao.switchCurrent(PaymentWrapperUtil.getInvoicingKeys(wrappers));
+ }
+}
diff --git a/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentRiskDataWrapperHandler.java b/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentRiskDataWrapperHandler.java
new file mode 100644
index 00000000..02c79367
--- /dev/null
+++ b/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentRiskDataWrapperHandler.java
@@ -0,0 +1,37 @@
+package dev.vality.newway.handler.wrapper.payment;
+
+import dev.vality.newway.dao.invoicing.iface.PaymentRiskDataDao;
+import dev.vality.newway.domain.tables.pojos.PaymentRiskData;
+import dev.vality.newway.handler.wrapper.WrapperHandler;
+import dev.vality.newway.model.PaymentWrapper;
+import dev.vality.newway.util.PaymentWrapperUtil;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+@RequiredArgsConstructor
+@Component
+public class PaymentRiskDataWrapperHandler implements WrapperHandler {
+
+ private final PaymentRiskDataDao paymentRiskDataDao;
+
+ @Override
+ public boolean accept(List wrappers) {
+ return wrappers.stream()
+ .map(PaymentWrapper::getPaymentRiskData)
+ .anyMatch(Objects::nonNull);
+ }
+
+ @Override
+ public void saveBatch(List wrappers) {
+ List paymentRiskDataList = wrappers.stream()
+ .map(PaymentWrapper::getPaymentRiskData)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ paymentRiskDataDao.saveBatch(paymentRiskDataList);
+ paymentRiskDataDao.switchCurrent(PaymentWrapperUtil.getInvoicingKeys(wrappers));
+ }
+}
diff --git a/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentRouteWrapperHandler.java b/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentRouteWrapperHandler.java
new file mode 100644
index 00000000..873803f1
--- /dev/null
+++ b/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentRouteWrapperHandler.java
@@ -0,0 +1,37 @@
+package dev.vality.newway.handler.wrapper.payment;
+
+import dev.vality.newway.dao.invoicing.iface.PaymentRouteDao;
+import dev.vality.newway.domain.tables.pojos.PaymentRoute;
+import dev.vality.newway.handler.wrapper.WrapperHandler;
+import dev.vality.newway.model.PaymentWrapper;
+import dev.vality.newway.util.PaymentWrapperUtil;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+@RequiredArgsConstructor
+@Component
+public class PaymentRouteWrapperHandler implements WrapperHandler {
+
+ private final PaymentRouteDao paymentRouteDao;
+
+ @Override
+ public boolean accept(List wrappers) {
+ return wrappers.stream()
+ .map(PaymentWrapper::getPaymentRoute)
+ .anyMatch(Objects::nonNull);
+ }
+
+ @Override
+ public void saveBatch(List wrappers) {
+ List paymentRoutes = wrappers.stream()
+ .map(PaymentWrapper::getPaymentRoute)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ paymentRouteDao.saveBatch(paymentRoutes);
+ paymentRouteDao.switchCurrent(PaymentWrapperUtil.getInvoicingKeys(wrappers));
+ }
+}
diff --git a/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentStatusInfoWrapperHandler.java b/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentStatusInfoWrapperHandler.java
new file mode 100644
index 00000000..de891d95
--- /dev/null
+++ b/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentStatusInfoWrapperHandler.java
@@ -0,0 +1,37 @@
+package dev.vality.newway.handler.wrapper.payment;
+
+import dev.vality.newway.dao.invoicing.iface.PaymentStatusInfoDao;
+import dev.vality.newway.domain.tables.pojos.PaymentStatusInfo;
+import dev.vality.newway.handler.wrapper.WrapperHandler;
+import dev.vality.newway.model.PaymentWrapper;
+import dev.vality.newway.util.PaymentWrapperUtil;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+@RequiredArgsConstructor
+@Component
+public class PaymentStatusInfoWrapperHandler implements WrapperHandler {
+
+ private final PaymentStatusInfoDao paymentStatusInfoDao;
+
+ @Override
+ public boolean accept(List wrappers) {
+ return wrappers.stream()
+ .map(PaymentWrapper::getPaymentStatusInfo)
+ .anyMatch(Objects::nonNull);
+ }
+
+ @Override
+ public void saveBatch(List wrappers) {
+ List paymentStatusInfos = wrappers.stream()
+ .map(PaymentWrapper::getPaymentStatusInfo)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ paymentStatusInfoDao.saveBatch(paymentStatusInfos);
+ paymentStatusInfoDao.switchCurrent(PaymentWrapperUtil.getInvoicingKeys(wrappers));
+ }
+}
diff --git a/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentWrapperHandler.java b/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentWrapperHandler.java
new file mode 100644
index 00000000..c7cf2af0
--- /dev/null
+++ b/src/main/java/dev/vality/newway/handler/wrapper/payment/PaymentWrapperHandler.java
@@ -0,0 +1,35 @@
+package dev.vality.newway.handler.wrapper.payment;
+
+import dev.vality.newway.dao.invoicing.iface.PaymentDao;
+import dev.vality.newway.domain.tables.pojos.Payment;
+import dev.vality.newway.handler.wrapper.WrapperHandler;
+import dev.vality.newway.model.PaymentWrapper;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+@RequiredArgsConstructor
+@Component
+public class PaymentWrapperHandler implements WrapperHandler {
+
+ private final PaymentDao paymentDao;
+
+ @Override
+ public boolean accept(List wrappers) {
+ return wrappers.stream()
+ .map(PaymentWrapper::getPayment)
+ .anyMatch(Objects::nonNull);
+ }
+
+ @Override
+ public void saveBatch(List wrappers) {
+ List payments = wrappers.stream()
+ .map(PaymentWrapper::getPayment)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ paymentDao.saveBatch(payments);
+ }
+}
diff --git a/src/main/java/dev/vality/newway/mapper/AbstractInvoicingMapper.java b/src/main/java/dev/vality/newway/mapper/AbstractInvoicingMapper.java
deleted file mode 100644
index 66e90aab..00000000
--- a/src/main/java/dev/vality/newway/mapper/AbstractInvoicingMapper.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package dev.vality.newway.mapper;
-
-import dev.vality.damsel.payment_processing.InvoiceChange;
-import dev.vality.machinegun.eventsink.MachineEvent;
-
-public abstract class AbstractInvoicingMapper implements Mapper {
-}
diff --git a/src/main/java/dev/vality/newway/mapper/Mapper.java b/src/main/java/dev/vality/newway/mapper/Mapper.java
index cce261bd..931830c6 100644
--- a/src/main/java/dev/vality/newway/mapper/Mapper.java
+++ b/src/main/java/dev/vality/newway/mapper/Mapper.java
@@ -1,14 +1,15 @@
package dev.vality.newway.mapper;
+import dev.vality.damsel.payment_processing.InvoiceChange;
import dev.vality.geck.filter.Filter;
-import dev.vality.newway.handler.event.stock.LocalStorage;
+import dev.vality.machinegun.eventsink.MachineEvent;
-public interface Mapper {
- default boolean accept(C change) {
+public interface Mapper {
+ default boolean accept(InvoiceChange change) {
return getFilter().match(change);
}
- M map(C change, E event, Integer changeId, LocalStorage storage);
+ M map(InvoiceChange change, MachineEvent event, Integer changeId);
Filter getFilter();
}
diff --git a/src/main/java/dev/vality/newway/mapper/invoice/AbstractInvoicingInvoiceMapper.java b/src/main/java/dev/vality/newway/mapper/invoice/AbstractInvoicingInvoiceMapper.java
deleted file mode 100644
index bc9fd4f5..00000000
--- a/src/main/java/dev/vality/newway/mapper/invoice/AbstractInvoicingInvoiceMapper.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package dev.vality.newway.mapper.invoice;
-
-import dev.vality.geck.common.util.TypeUtil;
-import dev.vality.newway.domain.tables.pojos.Invoice;
-import dev.vality.newway.mapper.AbstractInvoicingMapper;
-import dev.vality.newway.model.InvoiceWrapper;
-
-public abstract class AbstractInvoicingInvoiceMapper extends AbstractInvoicingMapper {
- protected void setDefaultProperties(Invoice invoice, Long sequenceId, Integer changeId, String eventCreatedAt) {
- invoice.setId(null);
- invoice.setWtime(null);
- invoice.setCurrent(false);
- invoice.setChangeId(changeId);
- invoice.setSequenceId(sequenceId);
- invoice.setEventCreatedAt(TypeUtil.stringToLocalDateTime(eventCreatedAt));
- }
-}
diff --git a/src/main/java/dev/vality/newway/mapper/invoice/InvoiceCreatedMapper.java b/src/main/java/dev/vality/newway/mapper/invoice/InvoiceCreatedMapper.java
index 511cce96..f17a5687 100644
--- a/src/main/java/dev/vality/newway/mapper/invoice/InvoiceCreatedMapper.java
+++ b/src/main/java/dev/vality/newway/mapper/invoice/InvoiceCreatedMapper.java
@@ -12,14 +12,16 @@
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.newway.domain.enums.InvoiceStatus;
import dev.vality.newway.domain.tables.pojos.InvoiceCart;
+import dev.vality.newway.domain.tables.pojos.InvoiceStatusInfo;
import dev.vality.newway.exception.DaoException;
-import dev.vality.newway.handler.event.stock.LocalStorage;
+import dev.vality.newway.mapper.Mapper;
import dev.vality.newway.model.InvoiceWrapper;
import dev.vality.newway.util.JsonUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
+import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -27,38 +29,48 @@
@Slf4j
@Component
@RequiredArgsConstructor
-public class InvoiceCreatedMapper extends AbstractInvoicingInvoiceMapper {
+public class InvoiceCreatedMapper implements Mapper {
- private Filter filter = new PathConditionFilter(
+ private final Filter filter = new PathConditionFilter(
new PathConditionRule("invoice_created", new IsNullCondition().not())
);
@Override
- public InvoiceWrapper map(InvoiceChange invoiceChange, MachineEvent event, Integer changeId, LocalStorage storage)
+ public InvoiceWrapper map(InvoiceChange invoiceChange, MachineEvent event, Integer changeId)
throws DaoException {
Invoice invoice = invoiceChange.getInvoiceCreated().getInvoice();
long sequenceId = event.getEventId();
String invoiceId = event.getSourceId();
- log.info("Start invoice created mapping, sequenceId={}, invoiceId={}, partyId={}, shopId={}",
- sequenceId, invoiceId, invoice.getOwnerId(), invoice.getShopId());
+ log.info("Start invoice created mapping, sequenceId={}, changeId={}, invoiceId={}, partyId={}, shopId={}",
+ sequenceId, changeId, invoiceId, invoice.getOwnerId(), invoice.getShopId());
- dev.vality.newway.domain.tables.pojos.Invoice invoiceRecord =
- new dev.vality.newway.domain.tables.pojos.Invoice();
- setDefaultProperties(invoiceRecord, sequenceId, changeId, event.getCreatedAt());
+ InvoiceWrapper invoiceWrapper = new InvoiceWrapper();
+ LocalDateTime eventCreatedAt = TypeUtil.stringToLocalDateTime(event.getCreatedAt());
+ invoiceWrapper.setInvoice(getInvoice(invoice, sequenceId, changeId, eventCreatedAt));
+ invoiceWrapper.setInvoiceStatusInfo(getInvoiceStatusInfo(invoice, sequenceId, changeId, eventCreatedAt));
+ if (invoice.getDetails().isSetCart()) {
+ invoiceWrapper.setCarts(getInvoiceCarts(invoice, sequenceId, changeId, eventCreatedAt));
+ }
+ log.info("Invoice has been mapped, sequenceId={}, changeId={}, invoiceId={}, partyId={}, shopId={}",
+ sequenceId, changeId, invoiceId, invoice.getOwnerId(), invoice.getShopId());
+ return invoiceWrapper;
+ }
+
+ private dev.vality.newway.domain.tables.pojos.Invoice getInvoice(Invoice invoice,
+ Long sequenceId,
+ Integer changeId,
+ LocalDateTime eventCreatedAt) {
+ var invoiceRecord = new dev.vality.newway.domain.tables.pojos.Invoice();
+ invoiceRecord.setChangeId(changeId);
+ invoiceRecord.setSequenceId(sequenceId);
+ invoiceRecord.setEventCreatedAt(eventCreatedAt);
invoiceRecord.setInvoiceId(invoice.getId());
invoiceRecord.setExternalId(invoice.getExternalId());
invoiceRecord.setPartyId(invoice.getOwnerId());
invoiceRecord.setShopId(invoice.getShopId());
invoiceRecord.setPartyRevision(invoice.getPartyRevision());
invoiceRecord.setCreatedAt(TypeUtil.stringToLocalDateTime(invoice.getCreatedAt()));
- InvoiceStatus status = TBaseUtil.unionFieldToEnum(invoice.getStatus(), InvoiceStatus.class);
- invoiceRecord.setStatus(status);
- if (invoice.getStatus().isSetCancelled()) {
- invoiceRecord.setStatusCancelledDetails(invoice.getStatus().getCancelled().getDetails());
- } else if (invoice.getStatus().isSetFulfilled()) {
- invoiceRecord.setStatusFulfilledDetails(invoice.getStatus().getFulfilled().getDetails());
- }
invoiceRecord.setDetailsProduct(invoice.getDetails().getProduct());
invoiceRecord.setDetailsDescription(invoice.getDetails().getDescription());
invoiceRecord.setDue(TypeUtil.stringToLocalDateTime(invoice.getDue()));
@@ -67,25 +79,49 @@ public InvoiceWrapper map(InvoiceChange invoiceChange, MachineEvent event, Integ
invoiceRecord.setContext(invoice.getContext().getData());
invoiceRecord.setTemplateId(invoice.getTemplateId());
- InvoiceWrapper invoiceWrapper = new InvoiceWrapper();
- invoiceWrapper.setInvoice(invoiceRecord);
- if (invoice.getDetails().isSetCart()) {
- List invoiceCarts = invoice.getDetails().getCart().getLines().stream().map(il -> {
- InvoiceCart ic = new InvoiceCart();
- ic.setProduct(il.getProduct());
- ic.setQuantity(il.getQuantity());
- ic.setAmount(il.getPrice().getAmount());
- ic.setCurrencyCode(il.getPrice().getCurrency().getSymbolicCode());
- Map jsonNodeMap = il.getMetadata().entrySet().stream()
- .collect(Collectors.toMap(Map.Entry::getKey, e -> JsonUtil.thriftBaseToJsonNode(e.getValue())));
- ic.setMetadataJson(JsonUtil.objectToJsonString(jsonNodeMap));
- return ic;
- }).collect(Collectors.toList());
- invoiceWrapper.setCarts(invoiceCarts);
+ return invoiceRecord;
+ }
+
+ private InvoiceStatusInfo getInvoiceStatusInfo(Invoice invoice,
+ Long sequenceId,
+ Integer changeId,
+ LocalDateTime eventCreatedAt) {
+ InvoiceStatusInfo statusRecord = new InvoiceStatusInfo();
+ statusRecord.setInvoiceId(invoice.getId());
+ statusRecord.setStatus(TBaseUtil.unionFieldToEnum(invoice.getStatus(), InvoiceStatus.class));
+ if (invoice.getStatus().isSetCancelled()) {
+ statusRecord.setDetails(invoice.getStatus().getCancelled().getDetails());
+ } else if (invoice.getStatus().isSetFulfilled()) {
+ statusRecord.setDetails(invoice.getStatus().getFulfilled().getDetails());
}
- log.info("Invoice has been mapped, sequenceId={}, invoiceId={}, partyId={}, shopId={}",
- sequenceId, invoiceId, invoice.getOwnerId(), invoice.getShopId());
- return invoiceWrapper;
+ statusRecord.setEventCreatedAt(eventCreatedAt);
+ statusRecord.setChangeId(changeId);
+ statusRecord.setSequenceId(sequenceId);
+ statusRecord.setExternalId(invoice.getExternalId());
+
+ return statusRecord;
+ }
+
+ private List getInvoiceCarts(Invoice invoice,
+ Long sequenceId,
+ Integer changeId,
+ LocalDateTime eventCreatedAt) {
+ return invoice.getDetails().getCart().getLines().stream().map(il -> {
+ InvoiceCart ic = new InvoiceCart();
+ ic.setEventCreatedAt(eventCreatedAt);
+ ic.setInvoiceId(invoice.getId());
+ ic.setProduct(il.getProduct());
+ ic.setQuantity(il.getQuantity());
+ ic.setAmount(il.getPrice().getAmount());
+ ic.setCurrencyCode(il.getPrice().getCurrency().getSymbolicCode());
+ Map jsonNodeMap = il.getMetadata().entrySet().stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, e -> JsonUtil.thriftBaseToJsonNode(e.getValue())));
+ ic.setMetadataJson(JsonUtil.objectToJsonString(jsonNodeMap));
+ ic.setSequenceId(sequenceId);
+ ic.setChangeId(changeId);
+ return ic;
+ })
+ .collect(Collectors.toList());
}
@Override
diff --git a/src/main/java/dev/vality/newway/mapper/invoice/InvoiceStatusChangedMapper.java b/src/main/java/dev/vality/newway/mapper/invoice/InvoiceStatusChangedMapper.java
index 731267cc..72851590 100644
--- a/src/main/java/dev/vality/newway/mapper/invoice/InvoiceStatusChangedMapper.java
+++ b/src/main/java/dev/vality/newway/mapper/invoice/InvoiceStatusChangedMapper.java
@@ -3,16 +3,16 @@
import dev.vality.damsel.domain.InvoiceStatus;
import dev.vality.damsel.payment_processing.InvoiceChange;
import dev.vality.geck.common.util.TBaseUtil;
+import dev.vality.geck.common.util.TypeUtil;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
-import dev.vality.newway.domain.tables.pojos.Invoice;
+import dev.vality.newway.domain.tables.pojos.InvoiceStatusInfo;
import dev.vality.newway.exception.DaoException;
-import dev.vality.newway.handler.event.stock.LocalStorage;
+import dev.vality.newway.mapper.Mapper;
import dev.vality.newway.model.InvoiceWrapper;
-import dev.vality.newway.service.InvoiceWrapperService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -20,40 +20,40 @@
@Slf4j
@Component
@RequiredArgsConstructor
-public class InvoiceStatusChangedMapper extends AbstractInvoicingInvoiceMapper {
-
- private final InvoiceWrapperService invoiceWrapperService;
+public class InvoiceStatusChangedMapper implements Mapper {
private Filter filter = new PathConditionFilter(
new PathConditionRule("invoice_status_changed", new IsNullCondition().not()));
@Override
- public InvoiceWrapper map(InvoiceChange invoiceChange, MachineEvent event, Integer changeId, LocalStorage storage)
+ public InvoiceWrapper map(InvoiceChange invoiceChange, MachineEvent event, Integer changeId)
throws DaoException {
InvoiceStatus invoiceStatus = invoiceChange.getInvoiceStatusChanged().getStatus();
long sequenceId = event.getEventId();
String invoiceId = event.getSourceId();
- InvoiceWrapper invoiceWrapper = invoiceWrapperService.get(invoiceId, storage);
- Invoice invoiceSource = invoiceWrapper.getInvoice();
- log.info("Start invoice status changed mapping, sequenceId={}, invoiceId={}, partyId={}, shopId={}, status={}",
- sequenceId, invoiceId, invoiceSource.getPartyId(), invoiceSource.getShopId(),
- invoiceStatus.getSetField().getFieldName());
+ log.info("Start invoice status changed mapping, sequenceId={}, changeId={}, invoiceId={}, changeId={}, status={}",
+ sequenceId, changeId, invoiceId, changeId, invoiceStatus.getSetField().getFieldName());
- setDefaultProperties(invoiceSource, sequenceId, changeId, event.getCreatedAt());
- invoiceSource.setStatus(
- TBaseUtil.unionFieldToEnum(invoiceStatus, dev.vality.newway.domain.enums.InvoiceStatus.class));
+ InvoiceStatusInfo statusRecord = new InvoiceStatusInfo();
+ statusRecord.setInvoiceId(invoiceId);
+ statusRecord.setStatus(TBaseUtil.unionFieldToEnum(
+ invoiceStatus,
+ dev.vality.newway.domain.enums.InvoiceStatus.class
+ ));
if (invoiceStatus.isSetCancelled()) {
- invoiceSource.setStatusCancelledDetails(invoiceStatus.getCancelled().getDetails());
- invoiceSource.setStatusFulfilledDetails(null);
+ statusRecord.setDetails(invoiceStatus.getCancelled().getDetails());
} else if (invoiceStatus.isSetFulfilled()) {
- invoiceSource.setStatusCancelledDetails(null);
- invoiceSource.setStatusFulfilledDetails(invoiceStatus.getFulfilled().getDetails());
+ statusRecord.setDetails(invoiceStatus.getFulfilled().getDetails());
}
+ statusRecord.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
+ statusRecord.setChangeId(changeId);
+ statusRecord.setSequenceId(sequenceId);
- log.info("Invoice has been mapped, sequenceId={}, invoiceId={}, partyId={}, shopId={}, status={}",
- sequenceId, invoiceId, invoiceSource.getPartyId(), invoiceSource.getShopId(),
- invoiceStatus.getSetField().getFieldName());
+ log.info("Invoice has been mapped, sequenceId={}, changeId={}, invoiceId={}, changeId={}, status={}",
+ sequenceId, changeId, invoiceId, changeId, invoiceStatus.getSetField().getFieldName());
+ var invoiceWrapper = new InvoiceWrapper();
+ invoiceWrapper.setInvoiceStatusInfo(statusRecord);
return invoiceWrapper;
}
diff --git a/src/main/java/dev/vality/newway/mapper/payment/AbstractInvoicingPaymentMapper.java b/src/main/java/dev/vality/newway/mapper/payment/AbstractInvoicingPaymentMapper.java
deleted file mode 100644
index b289eb83..00000000
--- a/src/main/java/dev/vality/newway/mapper/payment/AbstractInvoicingPaymentMapper.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package dev.vality.newway.mapper.payment;
-
-import dev.vality.geck.common.util.TypeUtil;
-import dev.vality.newway.domain.tables.pojos.Payment;
-import dev.vality.newway.mapper.AbstractInvoicingMapper;
-import dev.vality.newway.model.PaymentWrapper;
-
-public abstract class AbstractInvoicingPaymentMapper extends AbstractInvoicingMapper {
-
- protected void setInsertProperties(Payment payment, Long sequenceId, Integer changeId, String eventCreatedAt) {
- payment.setId(null);
- payment.setWtime(null);
- payment.setChangeId(changeId);
- payment.setSequenceId(sequenceId);
- payment.setEventCreatedAt(TypeUtil.stringToLocalDateTime(eventCreatedAt));
- payment.setSessionPayloadTransactionBoundTrxExtraJson(null);
- payment.setTrxAdditionalInfoAcsUrl(null);
- payment.setTrxAdditionalInfoPareq(null);
- payment.setTrxAdditionalInfoMd(null);
- payment.setTrxAdditionalInfoTermUrl(null);
- payment.setTrxAdditionalInfoPares(null);
- payment.setTrxAdditionalInfoCavv(null);
- payment.setTrxAdditionalInfoXid(null);
- payment.setTrxAdditionalInfoCavvAlgorithm(null);
- payment.setTrxAdditionalInfoThreeDsVerification(null);
- }
-
- protected void setUpdateProperties(Payment payment, String eventCreatedAt) {
- payment.setWtime(null);
- payment.setEventCreatedAt(TypeUtil.stringToLocalDateTime(eventCreatedAt));
- }
-}
diff --git a/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentCaptureStartedMapper.java b/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentCaptureStartedMapper.java
index 96acf096..2c584552 100644
--- a/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentCaptureStartedMapper.java
+++ b/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentCaptureStartedMapper.java
@@ -1,70 +1,42 @@
package dev.vality.newway.mapper.payment;
import dev.vality.damsel.payment_processing.InvoiceChange;
-import dev.vality.damsel.payment_processing.InvoicePaymentCaptureData;
-import dev.vality.damsel.payment_processing.InvoicePaymentCaptureStarted;
-import dev.vality.damsel.payment_processing.InvoicePaymentChange;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
-import dev.vality.newway.domain.tables.pojos.Payment;
-import dev.vality.newway.handler.event.stock.LocalStorage;
+import dev.vality.newway.mapper.Mapper;
import dev.vality.newway.model.PaymentWrapper;
-import dev.vality.newway.service.PaymentWrapperService;
-import dev.vality.newway.util.JsonUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
-import java.util.stream.Collectors;
-
+/**
+ * We do not save InvoicePaymentCaptureStarted because it is first commit in two-phase transaction -
+ * processed -> captured status transition.
+ * InvoicePaymentCaptureStarted payload duplicates InvoicePaymentStatusChanged event
+ * with InvoicePaymentCaptured payload.
+ */
@Slf4j
@Component
@RequiredArgsConstructor
-public class InvoicePaymentCaptureStartedMapper extends AbstractInvoicingPaymentMapper {
-
- private final PaymentWrapperService paymentWrapperService;
+public class InvoicePaymentCaptureStartedMapper implements Mapper {
private final Filter filter = new PathConditionFilter(new PathConditionRule(
"invoice_payment_change.payload.invoice_payment_capture_started",
new IsNullCondition().not()));
@Override
- public PaymentWrapper map(InvoiceChange change, MachineEvent event, Integer changeId, LocalStorage storage) {
- InvoicePaymentChange invoicePaymentChange = change.getInvoicePaymentChange();
-
- long sequenceId = event.getEventId();
- String paymentId = invoicePaymentChange.getId();
- String invoiceId = event.getSourceId();
- log.info("Start payment capture started handling, sequenceId={}, invoiceId={}, paymentId={}", sequenceId,
- invoiceId, paymentId);
-
- PaymentWrapper paymentWrapper = paymentWrapperService.get(invoiceId, paymentId, sequenceId, changeId, storage);
- if (paymentWrapper == null) {
- return null;
- }
-
- Payment paymentSource = paymentWrapper.getPayment();
- setUpdateProperties(paymentSource, event.getCreatedAt());
- InvoicePaymentCaptureStarted invoicePaymentCaptureStarted =
- change.getInvoicePaymentChange().getPayload().getInvoicePaymentCaptureStarted();
- InvoicePaymentCaptureData data = invoicePaymentCaptureStarted.getData();
- if (data.isSetCash()) {
- paymentSource.setAmount(data.getCash().getAmount());
- paymentSource.setCurrencyCode(data.getCash().getCurrency().getSymbolicCode());
- }
- paymentSource.setStatusCapturedStartedReason(data.getReason());
- if (data.isSetCart()) {
- String cartsJson = JsonUtil.objectToJsonString(
- data.getCart().getLines().stream().map(JsonUtil::thriftBaseToJsonNode)
- .collect(Collectors.toList()));
- paymentSource.setCaptureStartedParamsCartJson(cartsJson);
- }
- log.info("Payment has been saved, sequenceId={}, invoiceId={}, paymentId={}", sequenceId, invoiceId,
- paymentSource.getId());
- return paymentWrapper;
+ public PaymentWrapper map(InvoiceChange change, MachineEvent event, Integer changeId) {
+ log.info("Receive InvoicePaymentCaptureStarted sequenceId={}, changeId={}, invoiceId={}, paymentId={}, payload={}",
+ event.getEventId(),
+ changeId,
+ change.getInvoicePaymentChange().getId(),
+ event.getSourceId(),
+ change.getInvoicePaymentChange().getPayload().getInvoicePaymentCaptureStarted()
+ );
+ return new PaymentWrapper();
}
@Override
diff --git a/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentCashFlowChangedMapper.java b/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentCashFlowChangedMapper.java
index 49699088..2472ce3f 100644
--- a/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentCashFlowChangedMapper.java
+++ b/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentCashFlowChangedMapper.java
@@ -3,63 +3,57 @@
import dev.vality.damsel.domain.FinalCashFlowPosting;
import dev.vality.damsel.payment_processing.InvoiceChange;
import dev.vality.damsel.payment_processing.InvoicePaymentChange;
+import dev.vality.geck.common.util.TypeUtil;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.newway.domain.enums.PaymentChangeType;
-import dev.vality.newway.domain.tables.pojos.CashFlow;
-import dev.vality.newway.domain.tables.pojos.Payment;
-import dev.vality.newway.handler.event.stock.LocalStorage;
+import dev.vality.newway.factory.cash.flow.CashFlowFactory;
+import dev.vality.newway.mapper.Mapper;
+import dev.vality.newway.model.CashFlowWrapper;
+import dev.vality.newway.model.InvoicingKey;
import dev.vality.newway.model.PaymentWrapper;
-import dev.vality.newway.service.PaymentWrapperService;
-import dev.vality.newway.util.CashFlowType;
-import dev.vality.newway.util.CashFlowUtil;
+import dev.vality.newway.factory.cash.flow.CashFlowLinkFactory;
+import dev.vality.newway.factory.invoice.payment.PaymentFeeFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
+import java.time.LocalDateTime;
import java.util.List;
-import java.util.Map;
@Slf4j
@Component
@RequiredArgsConstructor
-public class InvoicePaymentCashFlowChangedMapper extends AbstractInvoicingPaymentMapper {
-
- private final PaymentWrapperService paymentWrapperService;
+public class InvoicePaymentCashFlowChangedMapper implements Mapper {
private Filter filter = new PathConditionFilter(new PathConditionRule(
"invoice_payment_change.payload.invoice_payment_cash_flow_changed",
new IsNullCondition().not()));
@Override
- public PaymentWrapper map(InvoiceChange change, MachineEvent event, Integer changeId, LocalStorage storage) {
+ public PaymentWrapper map(InvoiceChange change, MachineEvent event, Integer changeId) {
InvoicePaymentChange invoicePaymentChange = change.getInvoicePaymentChange();
String invoiceId = event.getSourceId();
String paymentId = invoicePaymentChange.getId();
long sequenceId = event.getEventId();
- log.info("Start mapping payment cashflow change, sequenceId='{}', invoiceId='{}', paymentId='{}'", sequenceId,
- invoiceId, paymentId);
- PaymentWrapper paymentWrapper = paymentWrapperService.get(invoiceId, paymentId, sequenceId, changeId, storage);
- if (paymentWrapper == null) {
- return null;
- }
- paymentWrapper.setShouldInsert(true);
- Payment paymentSource = paymentWrapper.getPayment();
- setInsertProperties(paymentSource, sequenceId, changeId, event.getCreatedAt());
+ LocalDateTime eventCreatedAt = TypeUtil.stringToLocalDateTime(event.getCreatedAt());
+ log.info("Start mapping payment cashflow change, sequenceId='{}', changeId='{}', invoiceId='{}', paymentId='{}'",
+ sequenceId, changeId, invoiceId, paymentId);
List finalCashFlow =
invoicePaymentChange.getPayload().getInvoicePaymentCashFlowChanged().getCashFlow();
- List cashFlows = CashFlowUtil.convertCashFlows(finalCashFlow, null, PaymentChangeType.payment);
- paymentWrapper.setCashFlows(cashFlows);
- Map parsedCashFlow = CashFlowUtil.parseCashFlow(finalCashFlow);
- paymentSource.setFee(parsedCashFlow.getOrDefault(CashFlowType.FEE, 0L));
- paymentSource.setProviderFee(parsedCashFlow.getOrDefault(CashFlowType.PROVIDER_FEE, 0L));
- paymentSource.setExternalFee(parsedCashFlow.getOrDefault(CashFlowType.EXTERNAL_FEE, 0L));
- paymentSource.setGuaranteeDeposit(parsedCashFlow.getOrDefault(CashFlowType.GUARANTEE_DEPOSIT, 0L));
- log.info("Payment cashflow has been mapped, sequenceId='{}', invoiceId='{}', paymentId='{}'", sequenceId,
- invoiceId, paymentId);
+ PaymentWrapper paymentWrapper = new PaymentWrapper();
+ paymentWrapper.setKey(InvoicingKey.buildKey(invoiceId, paymentId));
+ paymentWrapper.setCashFlowWrapper(new CashFlowWrapper(
+ CashFlowLinkFactory.build(paymentId, invoiceId, eventCreatedAt, changeId, sequenceId),
+ CashFlowFactory.build(finalCashFlow, null, PaymentChangeType.payment)
+ ));
+ paymentWrapper.setPaymentFee(
+ PaymentFeeFactory.build(finalCashFlow, invoiceId, paymentId, eventCreatedAt, changeId, sequenceId));
+ log.info("Payment cashflow has been mapped, sequenceId='{}', changeId='{}', invoiceId='{}', paymentId='{}'",
+ sequenceId, changeId, invoiceId, paymentId);
return paymentWrapper;
}
@@ -67,4 +61,5 @@ public PaymentWrapper map(InvoiceChange change, MachineEvent event, Integer chan
public Filter getFilter() {
return filter;
}
+
}
diff --git a/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentCreatedMapper.java b/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentCreatedMapper.java
index f27dff49..c010f01c 100644
--- a/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentCreatedMapper.java
+++ b/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentCreatedMapper.java
@@ -11,174 +11,223 @@
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.newway.domain.enums.*;
-import dev.vality.newway.domain.tables.pojos.CashFlow;
-import dev.vality.newway.domain.tables.pojos.Invoice;
import dev.vality.newway.domain.tables.pojos.Payment;
-import dev.vality.newway.handler.event.stock.LocalStorage;
-import dev.vality.newway.model.InvoiceWrapper;
+import dev.vality.newway.domain.tables.pojos.PaymentPayerInfo;
+import dev.vality.newway.factory.cash.flow.CashFlowFactory;
+import dev.vality.newway.factory.cash.flow.CashFlowLinkFactory;
+import dev.vality.newway.factory.invoice.payment.*;
+import dev.vality.newway.mapper.Mapper;
+import dev.vality.newway.model.CashFlowWrapper;
import dev.vality.newway.model.InvoicingKey;
+import dev.vality.newway.model.PartyShop;
import dev.vality.newway.model.PaymentWrapper;
-import dev.vality.newway.service.InvoiceWrapperService;
-import dev.vality.newway.util.CashFlowType;
-import dev.vality.newway.util.CashFlowUtil;
-import dev.vality.newway.util.JsonUtil;
+import dev.vality.newway.service.PartyShopCacheService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
-import java.util.List;
-import java.util.Map;
+import java.time.LocalDateTime;
import java.util.Optional;
@Slf4j
@Component
@RequiredArgsConstructor
-public class InvoicePaymentCreatedMapper extends AbstractInvoicingPaymentMapper {
+public class InvoicePaymentCreatedMapper implements Mapper {
- private final InvoiceWrapperService invoiceWrapperService;
+ private final PartyShopCacheService partyShopCacheService;
private Filter filter = new PathConditionFilter(new PathConditionRule(
"invoice_payment_change.payload.invoice_payment_started",
new IsNullCondition().not()));
@Override
- public PaymentWrapper map(InvoiceChange invoiceChange, MachineEvent event, Integer changeId, LocalStorage storage) {
+ public PaymentWrapper map(InvoiceChange invoiceChange, MachineEvent event, Integer changeId) {
InvoicePaymentStarted invoicePaymentStarted = invoiceChange
.getInvoicePaymentChange()
.getPayload()
.getInvoicePaymentStarted();
- PaymentWrapper paymentWrapper = new PaymentWrapper();
- paymentWrapper.setShouldInsert(true);
- Payment payment = new Payment();
- paymentWrapper.setPayment(payment);
InvoicePayment invoicePayment = invoicePaymentStarted.getPayment();
long sequenceId = event.getEventId();
String invoiceId = event.getSourceId();
-
String paymentId = invoicePayment.getId();
- log.info("Start payment created mapping, sequenceId={}, invoiceId={}, paymentId={}", sequenceId, invoiceId,
- paymentId);
- paymentWrapper.setKey(InvoicingKey.buildKey(invoiceId, paymentId));
- setInsertProperties(payment, sequenceId, changeId, event.getCreatedAt());
- payment.setPaymentId(paymentId);
- payment.setCreatedAt(TypeUtil.stringToLocalDateTime(invoicePayment.getCreatedAt()));
- payment.setInvoiceId(invoiceId);
- payment.setExternalId(invoicePayment.getExternalId());
+ log.info("Start payment created mapping, sequenceId={}, changeId={}, invoiceId={}, paymentId={}",
+ sequenceId, changeId, invoiceId, paymentId);
- InvoiceWrapper invoiceWrapper = invoiceWrapperService.get(invoiceId, storage);
- if (invoiceWrapper == null) {
+ PartyShop partyShop = partyShopCacheService.get(invoiceId);
+ if (partyShop == null) {
+ log.info("PartyShop not found for invoiceId = {}", invoiceId);
return null;
}
- Invoice invoice = invoiceWrapper.getInvoice();
+ PaymentWrapper paymentWrapper = new PaymentWrapper();
+ paymentWrapper.setKey(InvoicingKey.buildKey(invoiceId, paymentId));
+ LocalDateTime eventCreatedAt = TypeUtil.stringToLocalDateTime(event.getCreatedAt());
+ paymentWrapper.setPayment(getPayment(
+ invoicePayment,
+ invoiceId,
+ paymentId,
+ partyShop,
+ eventCreatedAt,
+ changeId,
+ sequenceId
+ ));
+ paymentWrapper.setPaymentStatusInfo(PaymentStatusInfoFactory.build(
+ invoicePayment.getStatus(),
+ invoiceId,
+ paymentId,
+ eventCreatedAt,
+ changeId,
+ sequenceId
+ ));
+ paymentWrapper.setPaymentPayerInfo(getPayerPaymentInfo(
+ invoicePayment,
+ invoiceId,
+ paymentId,
+ eventCreatedAt,
+ changeId,
+ sequenceId
+ ));
+ if (invoicePaymentStarted.isSetRoute()) {
+ paymentWrapper.setPaymentRoute(PaymentRouteFactory.build(
+ invoicePaymentStarted.getRoute(),
+ invoiceId,
+ paymentId,
+ TypeUtil.stringToLocalDateTime(event.getCreatedAt()),
+ changeId,
+ sequenceId
+ ));
+ }
+ if (invoicePaymentStarted.isSetCashFlow()) {
+ paymentWrapper.setCashFlowWrapper(new CashFlowWrapper(
+ CashFlowLinkFactory.build(paymentId, invoiceId, eventCreatedAt, changeId, sequenceId),
+ CashFlowFactory.build(invoicePaymentStarted.getCashFlow(), null, PaymentChangeType.payment)
+ ));
+ paymentWrapper.setPaymentFee(PaymentFeeFactory.build(
+ invoicePaymentStarted.getCashFlow(),
+ invoiceId,
+ paymentId,
+ eventCreatedAt,
+ changeId,
+ sequenceId
+ ));
+ }
+ log.info("Payment has been mapped, sequenceId={}, changeId={}, invoiceId={}, paymentId={}",
+ sequenceId, changeId, invoiceId, paymentId);
+ return paymentWrapper;
+ }
- payment.setPartyId(invoice.getPartyId());
- payment.setShopId(invoice.getShopId());
+ private Payment getPayment(InvoicePayment invoicePayment,
+ String invoiceId,
+ String paymentId,
+ PartyShop partyShop,
+ LocalDateTime eventCreatedAt,
+ Integer changeId,
+ Long sequenceId) {
+ Payment payment = new Payment();
+ payment.setEventCreatedAt(eventCreatedAt);
+ payment.setPaymentId(paymentId);
+ payment.setInvoiceId(invoiceId);
+ payment.setCreatedAt(TypeUtil.stringToLocalDateTime(invoicePayment.getCreatedAt()));
+ payment.setPartyId(partyShop.getPartyId());
+ payment.setShopId(partyShop.getShopId());
payment.setDomainRevision(invoicePayment.getDomainRevision());
if (invoicePayment.isSetPartyRevision()) {
payment.setPartyRevision(invoicePayment.getPartyRevision());
}
- payment.setStatus(TBaseUtil.unionFieldToEnum(invoicePayment.getStatus(), PaymentStatus.class));
- if (invoicePayment.getStatus().isSetCancelled()) {
- payment.setStatusCancelledReason(invoicePayment.getStatus().getCancelled().getReason());
- } else if (invoicePayment.getStatus().isSetCaptured()) {
- payment.setStatusCapturedReason(invoicePayment.getStatus().getCaptured().getReason());
- } else if (invoicePayment.getStatus().isSetFailed()) {
- payment.setStatusFailedFailure(JsonUtil.thriftBaseToJsonString(invoicePayment.getStatus().getFailed()));
- }
payment.setAmount(invoicePayment.getCost().getAmount());
payment.setCurrencyCode(invoicePayment.getCost().getCurrency().getSymbolicCode());
- Payer payer = invoicePayment.getPayer();
- payment.setPayerType(TBaseUtil.unionFieldToEnum(payer, PayerType.class));
- if (payer.isSetPaymentResource()) {
- PaymentResourcePayer paymentResource = payer.getPaymentResource();
- fillPaymentTool(payment, paymentResource.getResource().getPaymentTool());
- fillContactInfo(payment, paymentResource.getContactInfo());
- if (paymentResource.getResource().isSetClientInfo()) {
- payment.setPayerIpAddress(paymentResource.getResource().getClientInfo().getIpAddress());
- payment.setPayerFingerprint(paymentResource.getResource().getClientInfo().getFingerprint());
- }
- } else if (payer.isSetCustomer()) {
- CustomerPayer customer = payer.getCustomer();
- payment.setPayerCustomerId(customer.getCustomerId());
- payment.setPayerCustomerBindingId(customer.getCustomerBindingId());
- payment.setPayerCustomerRecPaymentToolId(customer.getRecPaymentToolId());
- fillPaymentTool(payment, customer.getPaymentTool());
- fillContactInfo(payment, customer.getContactInfo());
- } else if (payer.isSetRecurrent()) {
- payment.setPayerRecurrentParentInvoiceId(payer.getRecurrent().getRecurrentParent().getInvoiceId());
- payment.setPayerRecurrentParentPaymentId(payer.getRecurrent().getRecurrentParent().getPaymentId());
- fillPaymentTool(payment, payer.getRecurrent().getPaymentTool());
- fillContactInfo(payment, payer.getRecurrent().getContactInfo());
+ if (invoicePayment.isSetMakeRecurrent()) {
+ payment.setMakeRecurrent(invoicePayment.isMakeRecurrent());
}
+ payment.setExternalId(invoicePayment.getExternalId());
payment.setPaymentFlowType(TBaseUtil.unionFieldToEnum(invoicePayment.getFlow(), PaymentFlowType.class));
if (invoicePayment.getFlow().isSetHold()) {
payment.setPaymentFlowHeldUntil(
TypeUtil.stringToLocalDateTime(invoicePayment.getFlow().getHold().getHeldUntil()));
payment.setPaymentFlowOnHoldExpiration(invoicePayment.getFlow().getHold().getOnHoldExpiration().name());
}
- if (invoicePaymentStarted.isSetRoute()) {
- payment.setRouteProviderId(invoicePaymentStarted.getRoute().getProvider().getId());
- payment.setRouteTerminalId(invoicePaymentStarted.getRoute().getTerminal().getId());
- }
- if (invoicePayment.isSetMakeRecurrent()) {
- payment.setMakeRecurrent(invoicePayment.isMakeRecurrent());
- }
+ payment.setSequenceId(sequenceId);
+ payment.setChangeId(changeId);
+ return payment;
+ }
- if (invoicePaymentStarted.isSetCashFlow()) {
- List cashFlowList =
- CashFlowUtil.convertCashFlows(invoicePaymentStarted.getCashFlow(), null, PaymentChangeType.payment);
- paymentWrapper.setCashFlows(cashFlowList);
- Map parsedCashFlow = CashFlowUtil.parseCashFlow(invoicePaymentStarted.getCashFlow());
- payment.setFee(parsedCashFlow.getOrDefault(CashFlowType.FEE, 0L));
- payment.setProviderFee(parsedCashFlow.getOrDefault(CashFlowType.PROVIDER_FEE, 0L));
- payment.setExternalFee(parsedCashFlow.getOrDefault(CashFlowType.EXTERNAL_FEE, 0L));
- payment.setGuaranteeDeposit(parsedCashFlow.getOrDefault(CashFlowType.GUARANTEE_DEPOSIT, 0L));
+ private PaymentPayerInfo getPayerPaymentInfo(InvoicePayment invoicePayment,
+ String invoiceId,
+ String paymentId,
+ LocalDateTime eventCreatedAt,
+ Integer changeId,
+ Long sequenceId) {
+ Payer payer = invoicePayment.getPayer();
+ PaymentPayerInfo payerInfo = new PaymentPayerInfo();
+ payerInfo.setInvoiceId(invoiceId);
+ payerInfo.setPaymentId(paymentId);
+ payerInfo.setEventCreatedAt(eventCreatedAt);
+ payerInfo.setPayerType(TBaseUtil.unionFieldToEnum(payer, PayerType.class));
+ if (payer.isSetPaymentResource()) {
+ PaymentResourcePayer paymentResource = payer.getPaymentResource();
+ fillPaymentTool(payerInfo, paymentResource.getResource().getPaymentTool());
+ fillContactInfo(payerInfo, paymentResource.getContactInfo());
+ if (paymentResource.getResource().isSetClientInfo()) {
+ payerInfo.setIpAddress(paymentResource.getResource().getClientInfo().getIpAddress());
+ payerInfo.setFingerprint(paymentResource.getResource().getClientInfo().getFingerprint());
+ }
+ } else if (payer.isSetCustomer()) {
+ CustomerPayer customer = payer.getCustomer();
+ payerInfo.setCustomerId(customer.getCustomerId());
+ payerInfo.setCustomerBindingId(customer.getCustomerBindingId());
+ payerInfo.setCustomerRecPaymentToolId(customer.getRecPaymentToolId());
+ fillPaymentTool(payerInfo, customer.getPaymentTool());
+ fillContactInfo(payerInfo, customer.getContactInfo());
+ } else if (payer.isSetRecurrent()) {
+ payerInfo.setRecurrentParentInvoiceId(payer.getRecurrent().getRecurrentParent().getInvoiceId());
+ payerInfo.setRecurrentParentPaymentId(payer.getRecurrent().getRecurrentParent().getPaymentId());
+ fillPaymentTool(payerInfo, payer.getRecurrent().getPaymentTool());
+ fillContactInfo(payerInfo, payer.getRecurrent().getContactInfo());
}
- log.info("Payment has been mapped, sequenceId={}, invoiceId={}, paymentId={}", sequenceId, invoiceId,
- paymentId);
- return paymentWrapper;
+ payerInfo.setSequenceId(sequenceId);
+ payerInfo.setChangeId(changeId);
+ return payerInfo;
}
- private void fillContactInfo(Payment payment, ContactInfo contactInfo) {
- payment.setPayerPhoneNumber(contactInfo.getPhoneNumber());
- payment.setPayerEmail(contactInfo.getEmail());
+ private void fillContactInfo(PaymentPayerInfo payerInfo, ContactInfo contactInfo) {
+ payerInfo.setPhoneNumber(contactInfo.getPhoneNumber());
+ payerInfo.setEmail(contactInfo.getEmail());
}
- private void fillPaymentTool(Payment payment, PaymentTool paymentTool) {
- payment.setPayerPaymentToolType(TBaseUtil.unionFieldToEnum(paymentTool, PaymentToolType.class));
+ private void fillPaymentTool(PaymentPayerInfo payerInfo, PaymentTool paymentTool) {
+ payerInfo.setPaymentToolType(TBaseUtil.unionFieldToEnum(paymentTool, PaymentToolType.class));
if (paymentTool.isSetBankCard()) {
BankCard bankCard = paymentTool.getBankCard();
- payment.setPayerBankCardToken(bankCard.getToken());
- payment.setPayerBankCardPaymentSystem(Optional.ofNullable(bankCard.getPaymentSystem())
+ payerInfo.setBankCardToken(bankCard.getToken());
+ payerInfo.setBankCardPaymentSystem(Optional.ofNullable(bankCard.getPaymentSystem())
.map(PaymentSystemRef::getId).orElse(null));
- payment.setPayerBankCardBin(bankCard.getBin());
- payment.setPayerBankCardMaskedPan(bankCard.getLastDigits());
- payment.setPayerBankName(bankCard.getBankName());
- payment.setPayerBankCardCardholderName(bankCard.getCardholderName());
+ payerInfo.setBankCardBin(bankCard.getBin());
+ payerInfo.setBankCardMaskedPan(bankCard.getLastDigits());
+ payerInfo.setBankName(bankCard.getBankName());
+ payerInfo.setBankCardCardholderName(bankCard.getCardholderName());
if (bankCard.isSetIssuerCountry()) {
- payment.setPayerIssuerCountry(bankCard.getIssuerCountry().name());
+ payerInfo.setIssuerCountry(bankCard.getIssuerCountry().name());
}
- payment.setPayerBankCardTokenProvider(Optional.ofNullable(bankCard.getPaymentToken())
+ payerInfo.setBankCardTokenProvider(Optional.ofNullable(bankCard.getPaymentToken())
.map(BankCardTokenServiceRef::getId).orElse(null));
} else if (paymentTool.isSetPaymentTerminal()) {
- payment.setPayerPaymentTerminalType(
+ payerInfo.setPaymentTerminalType(
Optional.ofNullable(paymentTool.getPaymentTerminal().getPaymentService())
.map(PaymentServiceRef::getId).orElse(null));
} else if (paymentTool.isSetDigitalWallet()) {
- payment.setPayerDigitalWalletId(paymentTool.getDigitalWallet().getId());
- payment.setPayerDigitalWalletProvider(
+ payerInfo.setDigitalWalletId(paymentTool.getDigitalWallet().getId());
+ payerInfo.setDigitalWalletProvider(
Optional.ofNullable(paymentTool.getDigitalWallet().getPaymentService())
.map(PaymentServiceRef::getId).orElse(null));
} else if (paymentTool.isSetCryptoCurrency()) {
- payment.setPayerCryptoCurrencyType(Optional.ofNullable(paymentTool.getCryptoCurrency())
+ payerInfo.setCryptoCurrencyType(Optional.ofNullable(paymentTool.getCryptoCurrency())
.map(CryptoCurrencyRef::getId).orElse(null));
} else if (paymentTool.isSetMobileCommerce()) {
- payment.setPayerMobileOperator(paymentTool.getMobileCommerce().getOperator().getId());
- payment.setPayerMobilePhoneCc(paymentTool.getMobileCommerce().getPhone().getCc());
- payment.setPayerMobilePhoneCtn(paymentTool.getMobileCommerce().getPhone().getCtn());
+ payerInfo.setMobileOperator(paymentTool.getMobileCommerce().getOperator().getId());
+ payerInfo.setMobilePhoneCc(paymentTool.getMobileCommerce().getPhone().getCc());
+ payerInfo.setMobilePhoneCtn(paymentTool.getMobileCommerce().getPhone().getCtn());
}
}
diff --git a/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentRecTokenAcquiredMapper.java b/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentRecTokenAcquiredMapper.java
index 924dc939..99c621be 100644
--- a/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentRecTokenAcquiredMapper.java
+++ b/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentRecTokenAcquiredMapper.java
@@ -2,15 +2,16 @@
import dev.vality.damsel.payment_processing.InvoiceChange;
import dev.vality.damsel.payment_processing.InvoicePaymentChange;
+import dev.vality.geck.common.util.TypeUtil;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
-import dev.vality.newway.domain.tables.pojos.Payment;
-import dev.vality.newway.handler.event.stock.LocalStorage;
+import dev.vality.newway.domain.tables.pojos.PaymentRecurrentInfo;
+import dev.vality.newway.mapper.Mapper;
+import dev.vality.newway.model.InvoicingKey;
import dev.vality.newway.model.PaymentWrapper;
-import dev.vality.newway.service.PaymentWrapperService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -18,32 +19,32 @@
@Slf4j
@Component
@RequiredArgsConstructor
-public class InvoicePaymentRecTokenAcquiredMapper extends AbstractInvoicingPaymentMapper {
-
- private final PaymentWrapperService paymentWrapperService;
+public class InvoicePaymentRecTokenAcquiredMapper implements Mapper {
private Filter filter = new PathConditionFilter(new PathConditionRule(
"invoice_payment_change.payload.invoice_payment_rec_token_acquired",
new IsNullCondition().not()));
@Override
- public PaymentWrapper map(InvoiceChange change, MachineEvent event, Integer changeId, LocalStorage storage) {
+ public PaymentWrapper map(InvoiceChange change, MachineEvent event, Integer changeId) {
InvoicePaymentChange invoicePaymentChange = change.getInvoicePaymentChange();
String invoiceId = event.getSourceId();
String paymentId = invoicePaymentChange.getId();
long sequenceId = event.getEventId();
- log.info("Start handling payment recurrent token acquired, sequenceId='{}', invoiceId='{}', paymentId='{}'",
- sequenceId, invoiceId, paymentId);
- PaymentWrapper paymentWrapper = paymentWrapperService.get(invoiceId, paymentId, sequenceId, changeId, storage);
- if (paymentWrapper == null) {
- return null;
- }
- Payment paymentSource = paymentWrapper.getPayment();
- setUpdateProperties(paymentSource, event.getCreatedAt());
- String token = invoicePaymentChange.getPayload().getInvoicePaymentRecTokenAcquired().getToken();
- paymentSource.setRecurrentIntentionToken(token);
- log.info("Payment recurrent token have been saved, sequenceId='{}', invoiceId='{}', paymentId='{}'", sequenceId,
- invoiceId, paymentId);
+ log.info("Start handling payment recurrent token acquired, sequenceId='{}', changeId='{}', invoiceId='{}', paymentId='{}'",
+ sequenceId, changeId, invoiceId, paymentId);
+ PaymentRecurrentInfo recurrentInfo = new PaymentRecurrentInfo();
+ recurrentInfo.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
+ recurrentInfo.setInvoiceId(invoiceId);
+ recurrentInfo.setPaymentId(paymentId);
+ recurrentInfo.setSequenceId(sequenceId);
+ recurrentInfo.setChangeId(changeId);
+ recurrentInfo.setToken(invoicePaymentChange.getPayload().getInvoicePaymentRecTokenAcquired().getToken());
+ log.info("Payment recurrent token have been saved, sequenceId='{}', changeId='{}', invoiceId='{}', paymentId='{}'",
+ sequenceId, changeId, invoiceId, paymentId);
+ PaymentWrapper paymentWrapper = new PaymentWrapper();
+ paymentWrapper.setKey(InvoicingKey.buildKey(invoiceId, paymentId));
+ paymentWrapper.setPaymentRecurrentInfo(recurrentInfo);
return paymentWrapper;
}
diff --git a/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentRiskScoreChangedMapper.java b/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentRiskScoreChangedMapper.java
index f4042e71..ec15befb 100644
--- a/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentRiskScoreChangedMapper.java
+++ b/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentRiskScoreChangedMapper.java
@@ -9,10 +9,10 @@
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
-import dev.vality.newway.domain.tables.pojos.Payment;
-import dev.vality.newway.handler.event.stock.LocalStorage;
+import dev.vality.newway.domain.tables.pojos.PaymentRiskData;
+import dev.vality.newway.mapper.Mapper;
+import dev.vality.newway.model.InvoicingKey;
import dev.vality.newway.model.PaymentWrapper;
-import dev.vality.newway.service.PaymentWrapperService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -20,37 +20,38 @@
@Slf4j
@Component
@RequiredArgsConstructor
-public class InvoicePaymentRiskScoreChangedMapper extends AbstractInvoicingPaymentMapper {
-
- private final PaymentWrapperService paymentWrapperService;
+public class InvoicePaymentRiskScoreChangedMapper implements Mapper {
private Filter filter = new PathConditionFilter(new PathConditionRule(
"invoice_payment_change.payload.invoice_payment_risk_score_changed",
new IsNullCondition().not()));
@Override
- public PaymentWrapper map(InvoiceChange change, MachineEvent event, Integer changeId, LocalStorage storage) {
+ public PaymentWrapper map(InvoiceChange change, MachineEvent event, Integer changeId) {
InvoicePaymentChange invoicePaymentChange = change.getInvoicePaymentChange();
String invoiceId = event.getSourceId();
String paymentId = invoicePaymentChange.getId();
long sequenceId = event.getEventId();
- log.info("Start mapping payment risk score change, sequenceId='{}', invoiceId='{}', paymentId='{}'", sequenceId,
- invoiceId, paymentId);
- PaymentWrapper paymentWrapper = paymentWrapperService.get(invoiceId, paymentId, sequenceId, changeId, storage);
- if (paymentWrapper == null) {
- return null;
- }
- Payment paymentSource = paymentWrapper.getPayment();
- setUpdateProperties(paymentSource, event.getCreatedAt());
+ log.info("Start mapping payment risk score change, sequenceId='{}', changeId='{}', invoiceId='{}', paymentId='{}'",
+ sequenceId, changeId, invoiceId, paymentId);
RiskScore riskScore = invoicePaymentChange.getPayload().getInvoicePaymentRiskScoreChanged().getRiskScore();
dev.vality.newway.domain.enums.RiskScore score =
TypeUtil.toEnumField(riskScore.name(), dev.vality.newway.domain.enums.RiskScore.class);
if (score == null) {
throw new IllegalArgumentException("Illegal risk score: " + riskScore);
}
- paymentSource.setRiskScore(score);
- log.info("Payment risk score have been mapped, sequenceId='{}', invoiceId='{}', paymentId='{}'", sequenceId,
- invoiceId, paymentId);
+ PaymentRiskData paymentRiskData = new PaymentRiskData();
+ paymentRiskData.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
+ paymentRiskData.setInvoiceId(invoiceId);
+ paymentRiskData.setPaymentId(paymentId);
+ paymentRiskData.setRiskScore(score);
+ paymentRiskData.setSequenceId(sequenceId);
+ paymentRiskData.setChangeId(changeId);
+ log.info("Payment risk score have been mapped, sequenceId='{}', changeId='{}', invoiceId='{}', paymentId='{}'",
+ sequenceId, changeId, invoiceId, paymentId);
+ PaymentWrapper paymentWrapper = new PaymentWrapper();
+ paymentWrapper.setKey(InvoicingKey.buildKey(invoiceId, paymentId));
+ paymentWrapper.setPaymentRiskData(paymentRiskData);
return paymentWrapper;
}
diff --git a/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentRouteChangedMapper.java b/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentRouteChangedMapper.java
index 31fd877b..51bf3b2e 100644
--- a/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentRouteChangedMapper.java
+++ b/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentRouteChangedMapper.java
@@ -1,17 +1,18 @@
package dev.vality.newway.mapper.payment;
-import dev.vality.damsel.domain.PaymentRoute;
import dev.vality.damsel.payment_processing.InvoiceChange;
import dev.vality.damsel.payment_processing.InvoicePaymentChange;
+import dev.vality.geck.common.util.TypeUtil;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
-import dev.vality.newway.domain.tables.pojos.Payment;
-import dev.vality.newway.handler.event.stock.LocalStorage;
+import dev.vality.newway.domain.tables.pojos.PaymentRoute;
+import dev.vality.newway.mapper.Mapper;
+import dev.vality.newway.model.InvoicingKey;
import dev.vality.newway.model.PaymentWrapper;
-import dev.vality.newway.service.PaymentWrapperService;
+import dev.vality.newway.factory.invoice.payment.PaymentRouteFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -19,33 +20,35 @@
@Slf4j
@Component
@RequiredArgsConstructor
-public class InvoicePaymentRouteChangedMapper extends AbstractInvoicingPaymentMapper {
-
- private final PaymentWrapperService paymentWrapperService;
+public class InvoicePaymentRouteChangedMapper implements Mapper {
private Filter filter = new PathConditionFilter(new PathConditionRule(
"invoice_payment_change.payload.invoice_payment_route_changed",
new IsNullCondition().not()));
@Override
- public PaymentWrapper map(InvoiceChange change, MachineEvent event, Integer changeId, LocalStorage storage) {
+ public PaymentWrapper map(InvoiceChange change, MachineEvent event, Integer changeId) {
InvoicePaymentChange invoicePaymentChange = change.getInvoicePaymentChange();
String invoiceId = event.getSourceId();
String paymentId = invoicePaymentChange.getId();
- PaymentRoute paymentRoute = invoicePaymentChange.getPayload().getInvoicePaymentRouteChanged().getRoute();
+ dev.vality.damsel.domain.PaymentRoute paymentRouteSource =
+ invoicePaymentChange.getPayload().getInvoicePaymentRouteChanged().getRoute();
long sequenceId = event.getEventId();
- log.info("Start mapping payment route change, route='{}', sequenceId='{}', invoiceId='{}', paymentId='{}'",
- paymentRoute, sequenceId, invoiceId, paymentId);
- PaymentWrapper paymentWrapper = paymentWrapperService.get(invoiceId, paymentId, sequenceId, changeId, storage);
- if (paymentWrapper == null) {
- return null;
- }
- Payment paymentSource = paymentWrapper.getPayment();
- setUpdateProperties(paymentSource, event.getCreatedAt());
- paymentSource.setRouteProviderId(paymentRoute.getProvider().getId());
- paymentSource.setRouteTerminalId(paymentRoute.getTerminal().getId());
- log.info("Payment route have been mapped, route='{}', sequenceId='{}', invoiceId='{}', paymentId='{}'",
- paymentRoute, sequenceId, invoiceId, paymentId);
+ log.info("Start mapping payment route change, route='{}', sequenceId='{}', changeId='{}', invoiceId='{}', paymentId='{}'",
+ paymentRouteSource, sequenceId, changeId, invoiceId, paymentId);
+ PaymentRoute paymentRoute = PaymentRouteFactory.build(
+ paymentRouteSource,
+ invoiceId,
+ paymentId,
+ TypeUtil.stringToLocalDateTime(event.getCreatedAt()),
+ changeId,
+ sequenceId
+ );
+ log.info("Payment route have been mapped, route='{}', sequenceId='{}', changeId='{}', invoiceId='{}', paymentId='{}'",
+ paymentRoute, sequenceId, changeId, invoiceId, paymentId);
+ PaymentWrapper paymentWrapper = new PaymentWrapper();
+ paymentWrapper.setKey(InvoicingKey.buildKey(invoiceId, paymentId));
+ paymentWrapper.setPaymentRoute(paymentRoute);
return paymentWrapper;
}
diff --git a/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentSessionChangeTransactionBoundMapper.java b/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentSessionChangeTransactionBoundMapper.java
index 99aec1a0..24b4d393 100644
--- a/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentSessionChangeTransactionBoundMapper.java
+++ b/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentSessionChangeTransactionBoundMapper.java
@@ -6,15 +6,16 @@
import dev.vality.damsel.payment_processing.InvoicePaymentChange;
import dev.vality.damsel.payment_processing.InvoicePaymentSessionChange;
import dev.vality.damsel.payment_processing.SessionChangePayload;
+import dev.vality.geck.common.util.TypeUtil;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
-import dev.vality.newway.domain.tables.pojos.Payment;
-import dev.vality.newway.handler.event.stock.LocalStorage;
+import dev.vality.newway.domain.tables.pojos.PaymentAdditionalInfo;
+import dev.vality.newway.mapper.Mapper;
+import dev.vality.newway.model.InvoicingKey;
import dev.vality.newway.model.PaymentWrapper;
-import dev.vality.newway.service.PaymentWrapperService;
import dev.vality.newway.util.JsonUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -25,60 +26,54 @@
@Slf4j
@Component
@RequiredArgsConstructor
-public class InvoicePaymentSessionChangeTransactionBoundMapper extends AbstractInvoicingPaymentMapper {
-
- private final PaymentWrapperService paymentWrapperService;
+public class InvoicePaymentSessionChangeTransactionBoundMapper implements Mapper {
private Filter filter = new PathConditionFilter(new PathConditionRule(
"invoice_payment_change.payload.invoice_payment_session_change.payload.session_transaction_bound",
new IsNullCondition().not()));
@Override
- public PaymentWrapper map(InvoiceChange change, MachineEvent event, Integer changeId, LocalStorage storage) {
+ public PaymentWrapper map(InvoiceChange change, MachineEvent event, Integer changeId) {
InvoicePaymentChange invoicePaymentChange = change.getInvoicePaymentChange();
String invoiceId = event.getSourceId();
String paymentId = invoicePaymentChange.getId();
long sequenceId = event.getEventId();
- log.info("Start mapping session change transaction info, sequenceId='{}', invoiceId='{}', paymentId='{}'",
- sequenceId, invoiceId, paymentId);
-
- PaymentWrapper paymentWrapper = paymentWrapperService.get(invoiceId, paymentId, sequenceId, changeId, storage);
- if (paymentWrapper == null) {
- return null;
- }
- Payment paymentSource = paymentWrapper.getPayment();
- setUpdateProperties(paymentSource, event.getCreatedAt());
+ log.info("Start mapping session change transaction info, sequenceId='{}', changeId='{}', invoiceId='{}', paymentId='{}'",
+ sequenceId, changeId, invoiceId, paymentId);
InvoicePaymentSessionChange sessionChange = invoicePaymentChange.getPayload().getInvoicePaymentSessionChange();
SessionChangePayload payload = sessionChange.getPayload();
TransactionInfo transactionInfo = payload.getSessionTransactionBound().getTrx();
- paymentSource.setSessionPayloadTransactionBoundTrxId(transactionInfo.getId());
- Map extra = transactionInfo.getExtra();
- if (extra.get("PaRes") != null) {
- extra.put("PaRes", null);
- }
- paymentSource.setSessionPayloadTransactionBoundTrxExtraJson(JsonUtil.objectToJsonString(extra));
+ PaymentAdditionalInfo additionalInfo = new PaymentAdditionalInfo();
+ additionalInfo.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
+ additionalInfo.setInvoiceId(invoiceId);
+ additionalInfo.setPaymentId(paymentId);
+ additionalInfo.setTransactionId(transactionInfo.getId());
+ Map extra = transactionInfo.getExtra();
+ extra.replace("PaRes", null);
+ additionalInfo.setExtraJson(JsonUtil.objectToJsonString(extra));
if (transactionInfo.isSetAdditionalInfo()) {
- AdditionalTransactionInfo additionalTransactionInfo = transactionInfo.getAdditionalInfo();
- paymentSource.setTrxAdditionalInfoRrn(additionalTransactionInfo.getRrn());
- paymentSource.setTrxAdditionalInfoApprovalCode(additionalTransactionInfo.getApprovalCode());
- paymentSource.setTrxAdditionalInfoAcsUrl(additionalTransactionInfo.getAcsUrl());
- //paymentSource.setTrxAdditionalInfoPareq(additionalTransactionInfo.getPareq());
- paymentSource.setTrxAdditionalInfoMd(additionalTransactionInfo.getMd());
- paymentSource.setTrxAdditionalInfoTermUrl(additionalTransactionInfo.getTermUrl());
- //paymentSource.setTrxAdditionalInfoPares(additionalTransactionInfo.getPares());
- paymentSource.setTrxAdditionalInfoEci(additionalTransactionInfo.getEci());
- paymentSource.setTrxAdditionalInfoCavv(additionalTransactionInfo.getCavv());
- paymentSource.setTrxAdditionalInfoXid(additionalTransactionInfo.getXid());
- paymentSource.setTrxAdditionalInfoCavvAlgorithm(additionalTransactionInfo.getCavvAlgorithm());
-
- if (additionalTransactionInfo.isSetThreeDsVerification()) {
- paymentSource.setTrxAdditionalInfoThreeDsVerification(
- additionalTransactionInfo.getThreeDsVerification().name());
+ AdditionalTransactionInfo additionalInfoSource = transactionInfo.getAdditionalInfo();
+ additionalInfo.setRrn(additionalInfoSource.getRrn());
+ additionalInfo.setApprovalCode(additionalInfoSource.getApprovalCode());
+ additionalInfo.setAcsUrl(additionalInfoSource.getAcsUrl());
+ additionalInfo.setMd(additionalInfoSource.getMd());
+ additionalInfo.setTermUrl(additionalInfoSource.getTermUrl());
+ additionalInfo.setEci(additionalInfoSource.getEci());
+ additionalInfo.setCavv(additionalInfoSource.getCavv());
+ additionalInfo.setXid(additionalInfoSource.getXid());
+ additionalInfo.setCavvAlgorithm(additionalInfoSource.getCavvAlgorithm());
+ if (additionalInfoSource.isSetThreeDsVerification()) {
+ additionalInfo.setThreeDsVerification(additionalInfoSource.getThreeDsVerification().name());
}
}
- log.info("Payment session transaction info has been mapped, sequenceId='{}', invoiceId='{}', paymentId='{}'",
- sequenceId, invoiceId, paymentId);
+ additionalInfo.setSequenceId(sequenceId);
+ additionalInfo.setChangeId(changeId);
+ log.info("Payment session transaction info has been mapped, sequenceId='{}', changeId='{}', invoiceId='{}', paymentId='{}'",
+ sequenceId, changeId, invoiceId, paymentId);
+ PaymentWrapper paymentWrapper = new PaymentWrapper();
+ paymentWrapper.setKey(InvoicingKey.buildKey(invoiceId, paymentId));
+ paymentWrapper.setPaymentAdditionalInfo(additionalInfo);
return paymentWrapper;
}
diff --git a/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentStatusChangedMapper.java b/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentStatusChangedMapper.java
index 0b8cbea5..c29015a4 100644
--- a/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentStatusChangedMapper.java
+++ b/src/main/java/dev/vality/newway/mapper/payment/InvoicePaymentStatusChangedMapper.java
@@ -1,20 +1,18 @@
package dev.vality.newway.mapper.payment;
-import dev.vality.damsel.domain.InvoicePaymentCaptured;
import dev.vality.damsel.domain.InvoicePaymentStatus;
import dev.vality.damsel.payment_processing.InvoiceChange;
-import dev.vality.geck.common.util.TBaseUtil;
+import dev.vality.geck.common.util.TypeUtil;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
-import dev.vality.newway.domain.enums.PaymentStatus;
-import dev.vality.newway.domain.tables.pojos.Payment;
-import dev.vality.newway.handler.event.stock.LocalStorage;
+import dev.vality.newway.domain.tables.pojos.PaymentStatusInfo;
+import dev.vality.newway.mapper.Mapper;
+import dev.vality.newway.model.InvoicingKey;
import dev.vality.newway.model.PaymentWrapper;
-import dev.vality.newway.service.PaymentWrapperService;
-import dev.vality.newway.util.JsonUtil;
+import dev.vality.newway.factory.invoice.payment.PaymentStatusInfoFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -22,53 +20,37 @@
@Slf4j
@Component
@RequiredArgsConstructor
-public class InvoicePaymentStatusChangedMapper extends AbstractInvoicingPaymentMapper {
+public class InvoicePaymentStatusChangedMapper implements Mapper {
- private final PaymentWrapperService paymentWrapperService;
-
- private Filter filter = new PathConditionFilter(
- new PathConditionRule("invoice_payment_change.payload.invoice_payment_status_changed",
- new IsNullCondition().not()));
+ private Filter filter = new PathConditionFilter(new PathConditionRule(
+ "invoice_payment_change.payload.invoice_payment_status_changed",
+ new IsNullCondition().not()
+ ));
@Override
- public PaymentWrapper map(InvoiceChange change, MachineEvent event, Integer changeId, LocalStorage storage) {
+ public PaymentWrapper map(InvoiceChange change, MachineEvent event, Integer changeId) {
InvoicePaymentStatus invoicePaymentStatus =
change.getInvoicePaymentChange().getPayload().getInvoicePaymentStatusChanged().getStatus();
long sequenceId = event.getEventId();
String invoiceId = event.getSourceId();
String paymentId = change.getInvoicePaymentChange().getId();
- log.info("Start payment status changed mapping, sequenceId={}, invoiceId={}, paymentId={}, status={}",
- sequenceId, invoiceId, paymentId, invoicePaymentStatus.getSetField().getFieldName());
-
- PaymentWrapper paymentWrapper = paymentWrapperService.get(invoiceId, paymentId, sequenceId, changeId, storage);
- if (paymentWrapper == null) {
- return null;
- }
- paymentWrapper.setShouldInsert(true);
- Payment paymentSource = paymentWrapper.getPayment();
- setInsertProperties(paymentSource, sequenceId, changeId, event.getCreatedAt());
- paymentSource.setStatus(TBaseUtil.unionFieldToEnum(invoicePaymentStatus, PaymentStatus.class));
- if (invoicePaymentStatus.isSetCancelled()) {
- paymentSource.setStatusCancelledReason(invoicePaymentStatus.getCancelled().getReason());
- paymentSource.setStatusCapturedReason(null);
- paymentSource.setStatusFailedFailure(null);
- } else if (invoicePaymentStatus.isSetCaptured()) {
- paymentSource.setStatusCancelledReason(null);
- InvoicePaymentCaptured invoicePaymentCaptured = invoicePaymentStatus.getCaptured();
- paymentSource.setStatusCapturedReason(invoicePaymentCaptured.getReason());
- if (invoicePaymentCaptured.isSetCost()) {
- paymentSource.setAmount(invoicePaymentCaptured.getCost().getAmount());
- paymentSource.setCurrencyCode(invoicePaymentCaptured.getCost().getCurrency().getSymbolicCode());
- }
- paymentSource.setStatusFailedFailure(null);
- } else if (invoicePaymentStatus.isSetFailed()) {
- paymentSource.setStatusCancelledReason(null);
- paymentSource.setStatusCapturedReason(null);
- paymentSource.setStatusFailedFailure(JsonUtil.thriftBaseToJsonString(invoicePaymentStatus.getFailed()));
- }
- log.info("Payment status has been mapped, sequenceId={}, invoiceId={}, paymentId={}, status={}",
- sequenceId, invoiceId, paymentId, invoicePaymentStatus.getSetField().getFieldName());
+ log.info("Start payment status changed mapping, sequenceId={}, changeId={}, invoiceId={}, paymentId={}, status={}",
+ sequenceId, changeId, invoiceId, paymentId, invoicePaymentStatus.getSetField().getFieldName());
+
+ PaymentStatusInfo statusInfo = PaymentStatusInfoFactory.build(
+ invoicePaymentStatus,
+ invoiceId,
+ paymentId,
+ TypeUtil.stringToLocalDateTime(event.getCreatedAt()),
+ changeId,
+ sequenceId
+ );
+ log.info("Payment status has been mapped, sequenceId={}, changeId={}, invoiceId={}, paymentId={}, status={}",
+ sequenceId, changeId, invoiceId, paymentId, invoicePaymentStatus.getSetField().getFieldName());
+ PaymentWrapper paymentWrapper = new PaymentWrapper();
+ paymentWrapper.setKey(InvoicingKey.buildKey(invoiceId, paymentId));
+ paymentWrapper.setPaymentStatusInfo(statusInfo);
return paymentWrapper;
}
diff --git a/src/main/java/dev/vality/newway/util/CashFlowType.java b/src/main/java/dev/vality/newway/model/CashFlowType.java
similarity index 95%
rename from src/main/java/dev/vality/newway/util/CashFlowType.java
rename to src/main/java/dev/vality/newway/model/CashFlowType.java
index 9a8f8a53..816e5ebe 100644
--- a/src/main/java/dev/vality/newway/util/CashFlowType.java
+++ b/src/main/java/dev/vality/newway/model/CashFlowType.java
@@ -1,4 +1,4 @@
-package dev.vality.newway.util;
+package dev.vality.newway.model;
import dev.vality.damsel.domain.*;
@@ -41,9 +41,9 @@ public enum CashFlowType {
CashFlowAccount.merchant(MerchantCashFlowAccount.guarantee)
);
- private List sources;
+ private final List sources;
- private List destinations;
+ private final List destinations;
CashFlowType(CashFlowAccount source, CashFlowAccount destination) {
this(Collections.singletonList(source), Collections.singletonList(destination));
diff --git a/src/main/java/dev/vality/newway/model/CashFlowWrapper.java b/src/main/java/dev/vality/newway/model/CashFlowWrapper.java
new file mode 100644
index 00000000..f7a0d85c
--- /dev/null
+++ b/src/main/java/dev/vality/newway/model/CashFlowWrapper.java
@@ -0,0 +1,17 @@
+package dev.vality.newway.model;
+
+import dev.vality.newway.domain.tables.pojos.CashFlow;
+import dev.vality.newway.domain.tables.pojos.CashFlowLink;
+import lombok.Data;
+import lombok.RequiredArgsConstructor;
+
+import java.util.List;
+
+@Data
+@RequiredArgsConstructor
+public class CashFlowWrapper {
+
+ private final CashFlowLink cashFlowLink;
+ private final List cashFlows;
+
+}
diff --git a/src/main/java/dev/vality/newway/model/InvoicePaymentEventIdHolder.java b/src/main/java/dev/vality/newway/model/InvoicePaymentEventIdHolder.java
new file mode 100644
index 00000000..2c408aea
--- /dev/null
+++ b/src/main/java/dev/vality/newway/model/InvoicePaymentEventIdHolder.java
@@ -0,0 +1,11 @@
+package dev.vality.newway.model;
+
+import lombok.Data;
+
+@Data
+public class InvoicePaymentEventIdHolder {
+ private final String invoiceId;
+ private final String paymentId;
+ private final Long sequenceId;
+ private final Integer changeId;
+}
diff --git a/src/main/java/dev/vality/newway/model/InvoiceWrapper.java b/src/main/java/dev/vality/newway/model/InvoiceWrapper.java
index 78b152ac..ebb90037 100644
--- a/src/main/java/dev/vality/newway/model/InvoiceWrapper.java
+++ b/src/main/java/dev/vality/newway/model/InvoiceWrapper.java
@@ -2,12 +2,11 @@
import dev.vality.newway.domain.tables.pojos.Invoice;
import dev.vality.newway.domain.tables.pojos.InvoiceCart;
+import dev.vality.newway.domain.tables.pojos.InvoiceStatusInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
-import org.springframework.beans.BeanUtils;
-import java.util.ArrayList;
import java.util.List;
@Data
@@ -15,22 +14,6 @@
@AllArgsConstructor
public class InvoiceWrapper {
private Invoice invoice;
+ private InvoiceStatusInfo invoiceStatusInfo;
private List carts;
-
- public InvoiceWrapper copy() {
- Invoice invoiceTarget = new Invoice();
- BeanUtils.copyProperties(invoice, invoiceTarget);
- InvoiceWrapper invoiceWrapperTarget = new InvoiceWrapper();
- invoiceWrapperTarget.setInvoice(invoiceTarget);
- if (carts != null) {
- List cartsTarget = new ArrayList<>();
- carts.forEach(c -> {
- InvoiceCart cartTarget = new InvoiceCart();
- BeanUtils.copyProperties(c, cartTarget);
- cartsTarget.add(cartTarget);
- });
- invoiceWrapperTarget.setCarts(cartsTarget);
- }
- return invoiceWrapperTarget;
- }
}
diff --git a/src/main/java/dev/vality/newway/model/PartyShop.java b/src/main/java/dev/vality/newway/model/PartyShop.java
new file mode 100644
index 00000000..471d0739
--- /dev/null
+++ b/src/main/java/dev/vality/newway/model/PartyShop.java
@@ -0,0 +1,12 @@
+package dev.vality.newway.model;
+
+import lombok.Data;
+
+@Data
+public class PartyShop {
+
+ private final String partyId;
+
+ private final String shopId;
+
+}
diff --git a/src/main/java/dev/vality/newway/model/PaymentWrapper.java b/src/main/java/dev/vality/newway/model/PaymentWrapper.java
index 8d7baeb9..e7336bdd 100644
--- a/src/main/java/dev/vality/newway/model/PaymentWrapper.java
+++ b/src/main/java/dev/vality/newway/model/PaymentWrapper.java
@@ -1,39 +1,22 @@
package dev.vality.newway.model;
-import dev.vality.newway.domain.tables.pojos.CashFlow;
-import dev.vality.newway.domain.tables.pojos.Payment;
+import dev.vality.newway.domain.tables.pojos.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
-import org.springframework.beans.BeanUtils;
-
-import java.util.ArrayList;
-import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PaymentWrapper {
private Payment payment;
- private List cashFlows;
- private boolean shouldInsert;
+ private PaymentStatusInfo paymentStatusInfo;
+ private PaymentPayerInfo paymentPayerInfo;
+ private PaymentAdditionalInfo paymentAdditionalInfo;
+ private PaymentRecurrentInfo paymentRecurrentInfo;
+ private PaymentRiskData paymentRiskData;
+ private PaymentFee paymentFee;
+ private PaymentRoute paymentRoute;
+ private CashFlowWrapper cashFlowWrapper;
private InvoicingKey key;
-
- public PaymentWrapper copy() {
- Payment paymentTarget = new Payment();
- BeanUtils.copyProperties(payment, paymentTarget);
- PaymentWrapper paymentWrapperTarget = new PaymentWrapper();
- paymentWrapperTarget.setKey(InvoicingKey.buildKey(this));
- paymentWrapperTarget.setPayment(paymentTarget);
- if (cashFlows != null) {
- List cashFlowsTarget = new ArrayList<>();
- cashFlows.forEach(c -> {
- CashFlow cartTarget = new CashFlow();
- BeanUtils.copyProperties(c, cartTarget);
- cashFlowsTarget.add(cartTarget);
- });
- paymentWrapperTarget.setCashFlows(cashFlowsTarget);
- }
- return paymentWrapperTarget;
- }
}
diff --git a/src/main/java/dev/vality/newway/service/CashFlowService.java b/src/main/java/dev/vality/newway/service/CashFlowService.java
index a767797d..18a6c771 100644
--- a/src/main/java/dev/vality/newway/service/CashFlowService.java
+++ b/src/main/java/dev/vality/newway/service/CashFlowService.java
@@ -3,17 +3,16 @@
import dev.vality.newway.dao.invoicing.iface.CashFlowDao;
import dev.vality.newway.domain.enums.PaymentChangeType;
import dev.vality.newway.domain.tables.pojos.CashFlow;
+import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import java.util.List;
+@RequiredArgsConstructor
@Component
public class CashFlowService {
- private final CashFlowDao cashFlowDao;
- public CashFlowService(CashFlowDao cashFlowDao) {
- this.cashFlowDao = cashFlowDao;
- }
+ private final CashFlowDao cashFlowDao;
public void save(Long objSourceId, Long objId, PaymentChangeType type) {
if (objId != null) {
diff --git a/src/main/java/dev/vality/newway/service/InvoiceBatchService.java b/src/main/java/dev/vality/newway/service/InvoiceBatchService.java
deleted file mode 100644
index 06222f47..00000000
--- a/src/main/java/dev/vality/newway/service/InvoiceBatchService.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package dev.vality.newway.service;
-
-import dev.vality.newway.dao.invoicing.iface.InvoiceDao;
-import dev.vality.newway.dao.invoicing.impl.InvoiceIdsGeneratorDaoImpl;
-import dev.vality.newway.model.InvoiceWrapper;
-import dev.vality.newway.model.InvoicingKey;
-import dev.vality.newway.model.InvoicingType;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Service;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.stream.Collectors;
-
-@Service
-@Slf4j
-@RequiredArgsConstructor
-public class InvoiceBatchService {
-
- private final InvoiceDao invoiceDao;
- private final InvoiceWrapperService invoiceWrapperService;
- private final InvoiceIdsGeneratorDaoImpl invoiceIdsGeneratorDao;
-
- public void process(List invoiceWrappers) {
- log.info("Start processing of invoice batch, size={}", invoiceWrappers.size());
- List ids = invoiceIdsGeneratorDao.get(invoiceWrappers.size());
- setIds(invoiceWrappers, ids);
- invoiceWrapperService.save(invoiceWrappers);
- Collection invoicingSwitchIds = invoiceWrappers.stream().collect(
- Collectors
- .groupingBy(i -> new InvoicingKey(i.getInvoice().getInvoiceId(), null, InvoicingType.INVOICE)))
- .keySet();
- log.info("Switch to current ids: {}", invoicingSwitchIds);
- invoiceDao.switchCurrent(invoicingSwitchIds);
- log.info("End processing of invoice batch");
- }
-
- private void setIds(List invoiceWrappers, List ids) {
- for (int i = 0; i < invoiceWrappers.size(); ++i) {
- InvoiceWrapper invoiceWrapper = invoiceWrappers.get(i);
- Long invId = ids.get(i);
- invoiceWrapper.getInvoice().setId(invId);
- if (invoiceWrapper.getCarts() != null) {
- invoiceWrapper.getCarts().forEach(c -> {
- c.setId(null);
- c.setInvId(invId);
- });
- }
- }
- }
-}
diff --git a/src/main/java/dev/vality/newway/service/InvoiceWrapperService.java b/src/main/java/dev/vality/newway/service/InvoiceWrapperService.java
index bfc34dcb..0a560669 100644
--- a/src/main/java/dev/vality/newway/service/InvoiceWrapperService.java
+++ b/src/main/java/dev/vality/newway/service/InvoiceWrapperService.java
@@ -1,55 +1,26 @@
package dev.vality.newway.service;
-import com.github.benmanes.caffeine.cache.Cache;
-import dev.vality.newway.dao.invoicing.iface.InvoiceCartDao;
-import dev.vality.newway.dao.invoicing.iface.InvoiceDao;
-import dev.vality.newway.domain.tables.pojos.Invoice;
-import dev.vality.newway.domain.tables.pojos.InvoiceCart;
-import dev.vality.newway.exception.DaoException;
-import dev.vality.newway.exception.NotFoundException;
-import dev.vality.newway.handler.event.stock.LocalStorage;
+import dev.vality.newway.handler.wrapper.WrapperHandler;
import dev.vality.newway.model.InvoiceWrapper;
-import dev.vality.newway.model.InvoicingKey;
-import dev.vality.newway.model.InvoicingType;
import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
-import java.util.Collection;
-import java.util.List;
-import java.util.stream.Collectors;
+import java.util.*;
+@Slf4j
@Service
@RequiredArgsConstructor
public class InvoiceWrapperService {
- private final InvoiceDao invoiceDao;
- private final InvoiceCartDao invoiceCartDao;
- private final Cache invoiceDataCache;
-
- public InvoiceWrapper get(String invoiceId, LocalStorage storage) throws DaoException, NotFoundException {
- InvoicingKey key = InvoicingKey.builder().invoiceId(invoiceId).type(InvoicingType.INVOICE).build();
- InvoiceWrapper invoiceWrapper = (InvoiceWrapper) storage.get(key);
- if (invoiceWrapper != null) {
- return invoiceWrapper.copy();
- }
- invoiceWrapper = invoiceDataCache.getIfPresent(key);
- if (invoiceWrapper != null) {
- return invoiceWrapper.copy();
- }
- Invoice invoice = invoiceDao.get(invoiceId);
- List carts = invoiceCartDao.getByInvId(invoice.getId());
- return new InvoiceWrapper(invoice, carts);
- }
+ private final List> invoiceWrapperHandlers;
public void save(List invoiceWrappers) {
- invoiceWrappers.forEach(i -> invoiceDataCache
- .put(InvoicingKey.builder().invoiceId(i.getInvoice().getInvoiceId()).type(InvoicingType.INVOICE)
- .build(), i));
- List invoices = invoiceWrappers.stream().map(InvoiceWrapper::getInvoice).collect(Collectors.toList());
- invoiceDao.saveBatch(invoices);
- List carts =
- invoiceWrappers.stream().filter(i -> i.getCarts() != null).map(InvoiceWrapper::getCarts)
- .flatMap(Collection::stream).collect(Collectors.toList());
- invoiceCartDao.save(carts);
+ log.info("Start saving of invoice batch, size={}", invoiceWrappers.size());
+ invoiceWrapperHandlers.stream()
+ .filter(handler -> handler.accept(invoiceWrappers))
+ .forEach(handler -> handler.saveBatch(invoiceWrappers));
+ log.info("Saved invoice batch");
}
+
}
diff --git a/src/main/java/dev/vality/newway/service/InvoicingService.java b/src/main/java/dev/vality/newway/service/InvoicingService.java
index 10bddda1..d1420fe6 100644
--- a/src/main/java/dev/vality/newway/service/InvoicingService.java
+++ b/src/main/java/dev/vality/newway/service/InvoicingService.java
@@ -3,11 +3,9 @@
import dev.vality.damsel.payment_processing.EventPayload;
import dev.vality.damsel.payment_processing.InvoiceChange;
import dev.vality.machinegun.eventsink.MachineEvent;
-import dev.vality.newway.handler.event.stock.LocalStorage;
import dev.vality.newway.handler.event.stock.impl.invoicing.InvoicingHandler;
-import dev.vality.newway.mapper.AbstractInvoicingMapper;
+import dev.vality.newway.mapper.Mapper;
import dev.vality.newway.model.InvoiceWrapper;
-import dev.vality.newway.model.InvoicingKey;
import dev.vality.newway.model.PaymentWrapper;
import dev.vality.sink.common.parser.impl.MachineEventParser;
import lombok.RequiredArgsConstructor;
@@ -18,6 +16,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
@Slf4j
@Service
@@ -25,71 +24,79 @@
public class InvoicingService {
private final List otherHandlers;
- private final List> invoiceMappers;
- private final List> paymentMappers;
- private final InvoiceBatchService invoiceBatchService;
- private final PaymentBatchService paymentBatchService;
+ private final List> invoiceMappers;
+ private final List> paymentMappers;
+ private final PartyShopCacheService partyShopCacheService;
+ private final InvoiceWrapperService invoiceWrapperService;
+ private final PaymentWrapperService paymentWrapperService;
private final MachineEventParser parser;
@Transactional(propagation = Propagation.REQUIRED)
public void handleEvents(List machineEvents) {
- LocalStorage storage = new LocalStorage();
List invoices = new ArrayList<>(machineEvents.size());
List payments = new ArrayList<>(machineEvents.size());
- machineEvents.forEach(me -> {
- EventPayload payload = parser.parse(me);
- if (payload.isSetInvoiceChanges()) {
- try {
- List invoiceChanges = payload.getInvoiceChanges();
- for (int i = 0; i < invoiceChanges.size(); i++) {
- InvoiceChange change = invoiceChanges.get(i);
- InvoiceWrapper invoiceWrapper = mapInvoice(change, me, i, storage);
- PaymentWrapper paymentWrapper = mapPayment(change, me, i, storage);
- if (invoiceWrapper != null) {
- invoices.add(invoiceWrapper);
- storage.put(InvoicingKey.buildKey(invoiceWrapper), invoiceWrapper);
- }
- if (paymentWrapper != null) {
- payments.add(paymentWrapper);
- storage.put(InvoicingKey.buildKey(paymentWrapper), paymentWrapper);
- }
- handleOtherEvent(change, me, i);
- }
- } catch (Throwable e) {
- log.error("Unexpected error while handling events; machineId: {}, eventId: {}", me.getSourceId(),
- me.getEventId(), e);
- throw e;
- }
- }
- });
+ machineEvents.forEach(me -> processMachineEvents(invoices, payments, me));
if (!invoices.isEmpty()) {
- invoiceBatchService.process(invoices);
+ invoiceWrapperService.save(invoices);
}
if (!payments.isEmpty()) {
- paymentBatchService.process(payments);
+ paymentWrapperService.save(payments);
}
}
- private void handleOtherEvent(InvoiceChange change, MachineEvent me, int i) {
+ private void processMachineEvents(List invoices,
+ List payments,
+ MachineEvent machineEvent) {
+ EventPayload payload = parser.parse(machineEvent);
+ if (payload.isSetInvoiceChanges()) {
+ try {
+ List invoiceChanges = payload.getInvoiceChanges();
+ for (int changeId = 0; changeId < invoiceChanges.size(); changeId++) {
+ InvoiceChange change = invoiceChanges.get(changeId);
+ handleInvoiceEvent(invoices, change, machineEvent, changeId);
+ handlePaymentEvent(payments, change, machineEvent, changeId);
+ handleOtherEvent(change, machineEvent, changeId);
+ }
+ } catch (Throwable e) {
+ log.error("Unexpected error while handling events; machineId: {}, eventId: {}",
+ machineEvent.getSourceId(), machineEvent.getEventId(), e);
+ throw e;
+ }
+ }
+ }
+
+ private void handleOtherEvent(InvoiceChange change, MachineEvent me, int changeId) {
otherHandlers.stream()
.filter(m -> m.accept(change))
.findFirst()
- .ifPresent(m -> m.handle(change, me, i));
+ .ifPresent(m -> m.handle(change, me, changeId));
}
- private PaymentWrapper mapPayment(InvoiceChange change, MachineEvent me, int i, LocalStorage storage) {
- return paymentMappers.stream()
- .filter(m -> m.accept(change))
- .findFirst()
- .map(m -> m.map(change, me, i, storage))
- .orElse(null);
+ private void handlePaymentEvent(List payments,
+ InvoiceChange change,
+ MachineEvent machineEvent,
+ int changeId) {
+ mapEntity(paymentMappers, change, machineEvent, changeId).ifPresent(payments::add);
+ }
+
+ private void handleInvoiceEvent(List invoices,
+ InvoiceChange change,
+ MachineEvent machineEvent,
+ int changeId) {
+ mapEntity(invoiceMappers, change, machineEvent, changeId)
+ .ifPresent(wrapper -> {
+ invoices.add(wrapper);
+ partyShopCacheService.put(wrapper);
+ });
}
- private InvoiceWrapper mapInvoice(InvoiceChange change, MachineEvent me, int i, LocalStorage storage) {
- return invoiceMappers.stream()
+ private Optional mapEntity(List> mappers,
+ InvoiceChange change,
+ MachineEvent machineEvent,
+ int changeId) {
+ return mappers.stream()
.filter(m -> m.accept(change))
.findFirst()
- .map(m -> m.map(change, me, i, storage))
- .orElse(null);
+ .map(m -> m.map(change, machineEvent, changeId));
}
}
diff --git a/src/main/java/dev/vality/newway/service/PartyShopCacheService.java b/src/main/java/dev/vality/newway/service/PartyShopCacheService.java
new file mode 100644
index 00000000..15336dfb
--- /dev/null
+++ b/src/main/java/dev/vality/newway/service/PartyShopCacheService.java
@@ -0,0 +1,49 @@
+package dev.vality.newway.service;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import dev.vality.newway.dao.invoicing.iface.InvoiceDao;
+import dev.vality.newway.domain.tables.pojos.Invoice;
+import dev.vality.newway.model.InvoiceWrapper;
+import dev.vality.newway.model.PartyShop;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@RequiredArgsConstructor
+@Service
+public class PartyShopCacheService {
+
+ private final InvoiceDao invoiceDao;
+ private final Cache partyShopDataCache;
+
+ public void put(InvoiceWrapper invoiceWrapper) {
+ if (invoiceWrapper.getInvoice() == null) {
+ return;
+ }
+ partyShopDataCache.put(
+ invoiceWrapper.getInvoice().getInvoiceId(),
+ new PartyShop(
+ invoiceWrapper.getInvoice().getPartyId(),
+ invoiceWrapper.getInvoice().getShopId()
+ )
+ );
+ }
+
+ public PartyShop get(String invoiceId) {
+ PartyShop partyShop = partyShopDataCache.getIfPresent(invoiceId);
+ if (partyShop != null) {
+ return new PartyShop(partyShop.getPartyId(), partyShop.getShopId());
+ }
+ log.info("Cache miss for invoiceId: {}", invoiceId);
+ Invoice invoice = invoiceDao.get(invoiceId);
+ if (invoice == null) {
+ log.warn("Invoice was not found for invoiceId: {}", invoiceId);
+ return null;
+ }
+ partyShop = new PartyShop(invoice.getPartyId(), invoice.getShopId());
+ partyShopDataCache.put(invoiceId, partyShop);
+ return partyShop;
+ }
+
+}
diff --git a/src/main/java/dev/vality/newway/service/PaymentBatchService.java b/src/main/java/dev/vality/newway/service/PaymentBatchService.java
deleted file mode 100644
index b3160315..00000000
--- a/src/main/java/dev/vality/newway/service/PaymentBatchService.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package dev.vality.newway.service;
-
-import dev.vality.newway.dao.invoicing.impl.PaymentIdsGeneratorDaoImpl;
-import dev.vality.newway.model.InvoicingKey;
-import dev.vality.newway.model.PaymentWrapper;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Service;
-import org.springframework.util.CollectionUtils;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.stream.Collectors;
-
-@Service
-@Slf4j
-@RequiredArgsConstructor
-public class PaymentBatchService {
-
- private final PaymentWrapperService paymentWrapperService;
- private final PaymentIdsGeneratorDaoImpl paymentIdsGeneratorDao;
- private final PaymentSquashService paymentSquashService;
-
- public void process(List paymentWrappers) {
- log.info("Start processing of payment batch, size={}", paymentWrappers.size());
- List ids = paymentIdsGeneratorDao.get(paymentWrappers.size());
- List squashedPaymentWrappers = paymentSquashService.squash(paymentWrappers, ids);
- log.info("After squash size={}", squashedPaymentWrappers.size());
- paymentWrapperService.save(squashedPaymentWrappers);
- Collection invoicingSwitchIds = squashedPaymentWrappers
- .stream()
- .filter(PaymentWrapper::isShouldInsert)
- .collect(Collectors.groupingBy(PaymentWrapper::getKey)).keySet();
- if (!CollectionUtils.isEmpty(invoicingSwitchIds)) {
- log.info("Switch to current ids: {}", invoicingSwitchIds);
- paymentWrapperService.switchCurrent(invoicingSwitchIds);
- }
- log.info("End processing of payment batch");
- }
-}
diff --git a/src/main/java/dev/vality/newway/service/PaymentSquashService.java b/src/main/java/dev/vality/newway/service/PaymentSquashService.java
deleted file mode 100644
index b55dce3e..00000000
--- a/src/main/java/dev/vality/newway/service/PaymentSquashService.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package dev.vality.newway.service;
-
-import dev.vality.newway.model.PaymentWrapper;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Service;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.stream.Collectors;
-
-@Slf4j
-@Service
-public class PaymentSquashService {
-
- public List squash(List wrappers, List ids) {
- var groupedMap = wrappers.stream()
- .collect(Collectors.groupingBy(PaymentWrapper::getKey, LinkedHashMap::new, Collectors.toList()));
- List result = new ArrayList<>();
- Iterator iterator = ids.iterator();
- groupedMap.forEach((key, pwList) -> {
- setIds(pwList, iterator);
- List squashedById = squashById(pwList);
- long count = squashedById.stream().filter(w -> !w.isShouldInsert()).count();
- if (count > 1) {
- throw new IllegalStateException("Must be less or equal than one update statements, " + pwList);
- }
- result.addAll(squashedById);
- });
- return result;
- }
-
- private List squashById(List pwList) {
- List result = new ArrayList<>();
- var groupedById =
- pwList.stream().collect(Collectors.groupingBy(this::getId, LinkedHashMap::new, Collectors.toList()));
- groupedById.forEach((id, ws) -> {
- boolean shouldInsert = ws.get(0).isShouldInsert();
- PaymentWrapper pwLast = ws.get(ws.size() - 1);
- pwLast.setShouldInsert(shouldInsert);
- result.add(pwLast);
- });
- return result;
- }
-
- private void setIds(List pwList, Iterator