From 24e4ba387436d45452ff3c16e7e351d18c95af6b Mon Sep 17 00:00:00 2001 From: ggmaleva Date: Mon, 13 Dec 2021 18:00:01 +0300 Subject: [PATCH] fix review --- .../converter/ContractorConverter.java | 59 +++++++++++-------- .../ContractLegalAgreementBoundHandler.java | 10 ++-- ...ntractReportPreferencesChangedHandler.java | 2 +- .../listener/PartyManagementListener.java | 4 +- .../deanonimus/util/ContractUtil.java | 3 +- .../deanonimus/util/ContractorUtil.java | 17 +++--- 6 files changed, 49 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/rbkmoney/deanonimus/converter/ContractorConverter.java b/src/main/java/com/rbkmoney/deanonimus/converter/ContractorConverter.java index 624022a..fddfbc8 100644 --- a/src/main/java/com/rbkmoney/deanonimus/converter/ContractorConverter.java +++ b/src/main/java/com/rbkmoney/deanonimus/converter/ContractorConverter.java @@ -2,6 +2,7 @@ package com.rbkmoney.deanonimus.converter; import com.rbkmoney.damsel.deanonimus.*; import com.rbkmoney.deanonimus.domain.Contractor; +import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Component; import java.util.Collections; @@ -39,32 +40,38 @@ public class ContractorConverter { } private LegalEntity convertLegalEntity(Contractor contractor) { - switch (contractor.getLegalEntity()) { - case international_legal_entity -> { - InternationalLegalEntity internationalLegalEntity = new InternationalLegalEntity() - .setLegalName(contractor.getInternationalLegalEntityLegalName()) - .setTradingName(contractor.getInternationalLegalEntityTradingName()) - .setRegisteredAddress(contractor.getInternationalLegalEntityRegisteredAddress()) - .setActualAddress(contractor.getInternationalLegalEntityActualAddress()) - .setRegisteredNumber(contractor.getInternationalLegalEntityRegisteredNumber()); - return LegalEntity.international_legal_entity(internationalLegalEntity); - } - case russian_legal_entity -> { - RussianLegalEntity russianLegalEntity = new RussianLegalEntity() - .setRegisteredName(contractor.getRussianLegalEntityRegisteredName()) - .setRegisteredNumber(contractor.getRussianLegalEntityRegisteredNumber()) - .setInn(contractor.getRussianLegalEntityInn()) - .setActualAddress(contractor.getRussianLegalEntityActualAddress()) - .setPostAddress(contractor.getRussianLegalEntityPostAddress()) - .setRussianBankAccount(new RussianBankAccount( - contractor.getRussianLegalEntityRussianBankAccount(), - contractor.getRussianLegalEntityRussianBankName(), - contractor.getRussianLegalEntityRussianBankPostAccount(), - contractor.getRussianLegalEntityRussianBankBik() - )); - return LegalEntity.russian_legal_entity(russianLegalEntity); - } + return switch (contractor.getLegalEntity()) { + case international_legal_entity -> buildInternationalLegalEntity(contractor); + case russian_legal_entity -> buildRussianLegalEntity(contractor); default -> throw new IllegalArgumentException("No such legalEntity " + contractor.getLegalEntity()); - } + }; + } + + @NotNull + private LegalEntity buildInternationalLegalEntity(Contractor contractor) { + InternationalLegalEntity internationalLegalEntity = new InternationalLegalEntity() + .setLegalName(contractor.getInternationalLegalEntityLegalName()) + .setTradingName(contractor.getInternationalLegalEntityTradingName()) + .setRegisteredAddress(contractor.getInternationalLegalEntityRegisteredAddress()) + .setActualAddress(contractor.getInternationalLegalEntityActualAddress()) + .setRegisteredNumber(contractor.getInternationalLegalEntityRegisteredNumber()); + return LegalEntity.international_legal_entity(internationalLegalEntity); + } + + @NotNull + private LegalEntity buildRussianLegalEntity(Contractor contractor) { + RussianLegalEntity russianLegalEntity = new RussianLegalEntity() + .setRegisteredName(contractor.getRussianLegalEntityRegisteredName()) + .setRegisteredNumber(contractor.getRussianLegalEntityRegisteredNumber()) + .setInn(contractor.getRussianLegalEntityInn()) + .setActualAddress(contractor.getRussianLegalEntityActualAddress()) + .setPostAddress(contractor.getRussianLegalEntityPostAddress()) + .setRussianBankAccount(new RussianBankAccount( + contractor.getRussianLegalEntityRussianBankAccount(), + contractor.getRussianLegalEntityRussianBankName(), + contractor.getRussianLegalEntityRussianBankPostAccount(), + contractor.getRussianLegalEntityRussianBankBik() + )); + return LegalEntity.russian_legal_entity(russianLegalEntity); } } diff --git a/src/main/java/com/rbkmoney/deanonimus/kafka/handler/party/management/contract/ContractLegalAgreementBoundHandler.java b/src/main/java/com/rbkmoney/deanonimus/kafka/handler/party/management/contract/ContractLegalAgreementBoundHandler.java index e38f90a..68e57cf 100644 --- a/src/main/java/com/rbkmoney/deanonimus/kafka/handler/party/management/contract/ContractLegalAgreementBoundHandler.java +++ b/src/main/java/com/rbkmoney/deanonimus/kafka/handler/party/management/contract/ContractLegalAgreementBoundHandler.java @@ -46,13 +46,11 @@ public class ContractLegalAgreementBoundHandler extends AbstractClaimChangedHand String partyId = event.getSourceId(); log.info("Start contract legal agreement bound handling, sequenceId={}, partyId={}, contractId={}, changeId={}", sequenceId, partyId, contractId, changeId); - - Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId)); - - Contract contract = - party.getContractById(contractId).orElseThrow(() -> new ContractNotFoundException(contractId)); + Party party = partyRepository.findById(partyId) + .orElseThrow(() -> new PartyNotFoundException(partyId)); + Contract contract = party.getContractById(contractId) + .orElseThrow(() -> new ContractNotFoundException(contractId)); contract.setLegalAgreementId(legalAgreement.getLegalAgreementId()); - partyRepository.save(party); log.info("End contract legal agreement bound handling, sequenceId={}, partyId={}, contractId={}, changeId={}", diff --git a/src/main/java/com/rbkmoney/deanonimus/kafka/handler/party/management/contract/ContractReportPreferencesChangedHandler.java b/src/main/java/com/rbkmoney/deanonimus/kafka/handler/party/management/contract/ContractReportPreferencesChangedHandler.java index 713cfc8..1957b95 100644 --- a/src/main/java/com/rbkmoney/deanonimus/kafka/handler/party/management/contract/ContractReportPreferencesChangedHandler.java +++ b/src/main/java/com/rbkmoney/deanonimus/kafka/handler/party/management/contract/ContractReportPreferencesChangedHandler.java @@ -48,7 +48,7 @@ public class ContractReportPreferencesChangedHandler extends AbstractClaimChange log.info( """ Start contract report preferences changed handling, - "sequenceId={}, partyId={}, contractId={}, changeId={} + sequenceId={}, partyId={}, contractId={}, changeId={} """, sequenceId, partyId, contractId, changeId); diff --git a/src/main/java/com/rbkmoney/deanonimus/kafka/listener/PartyManagementListener.java b/src/main/java/com/rbkmoney/deanonimus/kafka/listener/PartyManagementListener.java index 37e6b5b..f09275f 100644 --- a/src/main/java/com/rbkmoney/deanonimus/kafka/listener/PartyManagementListener.java +++ b/src/main/java/com/rbkmoney/deanonimus/kafka/listener/PartyManagementListener.java @@ -29,7 +29,7 @@ public class PartyManagementListener { .collect(Collectors.toList()) ); ack.acknowledge(); - log.info("Batch partyManagement has been committed, size={}, {}", messages.size(), - LogUtil.toSummaryStringWithSinkEventValues(messages)); + log.info("Batch partyManagement has been committed, size={}, {}", + messages.size(), LogUtil.toSummaryStringWithSinkEventValues(messages)); } } \ No newline at end of file diff --git a/src/main/java/com/rbkmoney/deanonimus/util/ContractUtil.java b/src/main/java/com/rbkmoney/deanonimus/util/ContractUtil.java index 56d474b..76422d0 100644 --- a/src/main/java/com/rbkmoney/deanonimus/util/ContractUtil.java +++ b/src/main/java/com/rbkmoney/deanonimus/util/ContractUtil.java @@ -15,8 +15,7 @@ public class ContractUtil { public static void fillReportPreferences(Contract contract, ServiceAcceptanceActPreferences serviceAcceptanceActPreferences) { contract.setReportActSignerFullName(serviceAcceptanceActPreferences.getSigner().getFullName()); - final com.rbkmoney.damsel.domain.RepresentativeDocument document = - serviceAcceptanceActPreferences.getSigner().getDocument(); + var document = serviceAcceptanceActPreferences.getSigner().getDocument(); RepresentativeDocument reportActSignerDocument = TypeUtil.toEnumField(document.getSetField().getFieldName(), RepresentativeDocument.class); if (reportActSignerDocument == null) { diff --git a/src/main/java/com/rbkmoney/deanonimus/util/ContractorUtil.java b/src/main/java/com/rbkmoney/deanonimus/util/ContractorUtil.java index de646af..afba177 100644 --- a/src/main/java/com/rbkmoney/deanonimus/util/ContractorUtil.java +++ b/src/main/java/com/rbkmoney/deanonimus/util/ContractorUtil.java @@ -1,6 +1,7 @@ package com.rbkmoney.deanonimus.util; import com.rbkmoney.damsel.domain.InternationalLegalEntity; +import com.rbkmoney.damsel.domain.RussianBankAccount; import com.rbkmoney.damsel.domain.RussianLegalEntity; import com.rbkmoney.deanonimus.domain.Contractor; import com.rbkmoney.deanonimus.domain.ContractorType; @@ -30,20 +31,18 @@ public class ContractorUtil { contractor.setRussianLegalEntityInn(russianLegalEntity.getInn()); contractor.setRussianLegalEntityActualAddress(russianLegalEntity.getActualAddress()); contractor.setRussianLegalEntityPostAddress(russianLegalEntity.getPostAddress()); - contractor.setRussianLegalEntityRussianBankAccount( - russianLegalEntity.getRussianBankAccount().getAccount()); - contractor - .setRussianLegalEntityRussianBankName(russianLegalEntity.getRussianBankAccount().getBankName()); - contractor.setRussianLegalEntityRussianBankPostAccount( - russianLegalEntity.getRussianBankAccount().getBankPostAccount()); - contractor.setRussianLegalEntityRussianBankBik(russianLegalEntity.getRussianBankAccount().getBankBik()); + RussianBankAccount russianBankAccount = russianLegalEntity.getRussianBankAccount(); + contractor.setRussianLegalEntityRussianBankAccount(russianBankAccount.getAccount()); + contractor.setRussianLegalEntityRussianBankName(russianBankAccount.getBankName()); + contractor.setRussianLegalEntityRussianBankPostAccount(russianBankAccount.getBankPostAccount()); + contractor.setRussianLegalEntityRussianBankBik(russianBankAccount.getBankBik()); } else if (contractorSource.getLegalEntity().isSetInternationalLegalEntity()) { InternationalLegalEntity internationalLegalEntity = contractorSource.getLegalEntity().getInternationalLegalEntity(); contractor.setInternationalLegalEntityLegalName(internationalLegalEntity.getLegalName()); contractor.setInternationalLegalEntityTradingName(internationalLegalEntity.getTradingName()); - contractor - .setInternationalLegalEntityRegisteredAddress(internationalLegalEntity.getRegisteredAddress()); + contractor.setInternationalLegalEntityRegisteredAddress( + internationalLegalEntity.getRegisteredAddress()); contractor.setInternationalLegalEntityActualAddress(internationalLegalEntity.getActualAddress()); contractor.setInternationalLegalEntityRegisteredNumber(internationalLegalEntity.getRegisteredNumber()); }