review fix

This commit is contained in:
NPospolita 2020-08-13 13:52:57 +03:00
parent 8b7457bda7
commit adb4d1384d
6 changed files with 50 additions and 51 deletions

View File

@ -79,7 +79,7 @@
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>deanonimus-proto</artifactId>
<version>1.11-7cc0668</version>
<version>1.16-c0bbabe</version>
</dependency>
<!--spring-->
<dependency>

View File

@ -3,26 +3,25 @@ package com.rbkmoney.deanonimus.converter;
import com.rbkmoney.damsel.deanonimus.*;
import com.rbkmoney.geck.common.util.TypeUtil;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@Component
public class ContractConverter {
public Map<String, Contract> convert(List<com.rbkmoney.deanonimus.domain.Contract> contracts) {
if (CollectionUtils.isEmpty(contracts)) return Collections.emptyMap();
return contracts.stream()
return Optional.ofNullable(contracts).orElse(Collections.emptyList())
.stream()
.map(this::convertToEntity)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
private Map.Entry<String, Contract> convertToEntity(com.rbkmoney.deanonimus.domain.Contract contract) {
return new AbstractMap.SimpleEntry<>(contract.getId(), convertContract(contract));
return Map.entry(contract.getId(), convertContract(contract));
}
private Contract convertContract(com.rbkmoney.deanonimus.domain.Contract contractDomain) {
@ -31,12 +30,13 @@ public class ContractConverter {
convertStatus(contractDomain.getStatus()),
contractDomain.getTermsId()
);
contract.setContractorId(contractDomain.getContractorId());
if (contractDomain.getLegalAgreementId() != null) {
contract.setLegalAgreement(new LegalAgreement(
contractDomain.getLegalAgreementId()
));
}
contract.setContractorId(contractDomain.getContractorId());
if (contractDomain.getPaymentInstitutionId() != null) {
contract.setPaymentInstitutionId(contractDomain.getPaymentInstitutionId());
}
@ -58,7 +58,7 @@ public class ContractConverter {
case terminated:
return ContractStatus.terminated(new ContractTerminated());
default:
throw new RuntimeException("No such contractStatus");
throw new IllegalArgumentException("No such contractStatus: " + status);
}
}

View File

@ -3,26 +3,25 @@ package com.rbkmoney.deanonimus.converter;
import com.rbkmoney.damsel.deanonimus.*;
import com.rbkmoney.deanonimus.domain.Contractor;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@Component
public class ContractorConverter {
public Map<String, PartyContractor> convert(List<Contractor> contractors) {
if (CollectionUtils.isEmpty(contractors)) return Collections.emptyMap();
return contractors.stream()
return Optional.ofNullable(contractors).orElse(Collections.emptyList())
.stream()
.map(this::convertToEntity)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
private Map.Entry<String, PartyContractor> convertToEntity(Contractor contractor) {
return new AbstractMap.SimpleEntry<>(contractor.getId(), new PartyContractor(
return Map.entry(contractor.getId(), new PartyContractor(
contractor.getId(),
convertContractor(contractor)
));
@ -37,36 +36,36 @@ public class ContractorConverter {
case registered_user:
return com.rbkmoney.damsel.deanonimus.Contractor.registered_user(new RegisteredUser(contractor.getRegisteredUserEmail()));
default:
throw new RuntimeException("No such contractorType");
throw new IllegalArgumentException("No such contractorType: " + contractor.getType());
}
}
private LegalEntity convertLegalEntity(Contractor contractor) {
switch (contractor.getLegalEntity()) {
case international_legal_entity:
InternationalLegalEntity internationalLegalEntity = new InternationalLegalEntity();
internationalLegalEntity.setLegalName(contractor.getInternationalLegalEntityLegalName());
internationalLegalEntity.setTradingName(contractor.getInternationalLegalEntityTradingName());
internationalLegalEntity.setRegisteredAddress(contractor.getInternationalLegalEntityRegisteredAddress());
internationalLegalEntity.setActualAddress(contractor.getInternationalLegalEntityActualAddress());
internationalLegalEntity.setRegisteredNumber(contractor.getInternationalLegalEntityRegisteredNumber());
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();
russianLegalEntity.setRegisteredName(contractor.getRussianLegalEntityRegisteredName());
russianLegalEntity.setRegisteredNumber(contractor.getRussianLegalEntityRegisteredNumber());
russianLegalEntity.setInn(contractor.getRussianLegalEntityInn());
russianLegalEntity.setActualAddress(contractor.getRussianLegalEntityActualAddress());
russianLegalEntity.setPostAddress(contractor.getRussianLegalEntityPostAddress());
russianLegalEntity.setRussianBankAccount(new RussianBankAccount(
contractor.getRussianLegalEntityRussianBankAccount(),
contractor.getRussianLegalEntityRussianBankName(),
contractor.getRussianLegalEntityRussianBankPostAccount(),
contractor.getRussianLegalEntityRussianBankBik()
));
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);
default:
throw new RuntimeException("No such legalEntity");
throw new IllegalArgumentException("No such legalEntity " + contractor.getLegalEntity());
}
}
}

View File

@ -3,46 +3,46 @@ package com.rbkmoney.deanonimus.converter;
import com.rbkmoney.damsel.deanonimus.*;
import com.rbkmoney.deanonimus.util.EnumUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@Component
public class ShopConverter {
public Map<String, Shop> convert(List<com.rbkmoney.deanonimus.domain.Shop> shops) {
if (CollectionUtils.isEmpty(shops)) return Collections.emptyMap();
return shops.stream()
return Optional.ofNullable(shops).orElse(Collections.emptyList())
.stream()
.map(this::convertToEntity)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
private Map.Entry<String, Shop> convertToEntity(com.rbkmoney.deanonimus.domain.Shop shopDomain) {
return new AbstractMap.SimpleEntry<>(shopDomain.getId(), convertShop(shopDomain));
return Map.entry(shopDomain.getId(), convertShop(shopDomain));
}
private Shop convertShop(com.rbkmoney.deanonimus.domain.Shop shopDomain) {
Shop shop = new Shop();
shop.setId(shopDomain.getId());
setAccount(shopDomain, shop);
shop.setBlocking(EnumUtils.convertBlocking(shopDomain.getBlocking()));
shop.setSuspension(EnumUtils.convertSuspension(shopDomain.getSuspension()));
shop.setCategory(new CategoryRef(shopDomain.getCategoryId()));
shop.setContractId(shopDomain.getContractId());
shop.setDetails(new ShopDetails()
Shop shop = new Shop()
.setId(shopDomain.getId())
.setBlocking(EnumUtils.convertBlocking(shopDomain.getBlocking()))
.setSuspension(EnumUtils.convertSuspension(shopDomain.getSuspension()))
.setCategory(new CategoryRef(shopDomain.getCategoryId()))
.setContractId(shopDomain.getContractId())
.setDetails(new ShopDetails()
.setName(shopDomain.getDetailsName())
.setDescription(shopDomain.getDetailsDescription())
);
)
.setPayoutToolId(shopDomain.getPayoutToolId());
setAccount(shopDomain, shop);
ShopLocation shopLocation = new ShopLocation();
shopLocation.setUrl(shopDomain.getLocationUrl());
shop.setLocation(shopLocation);
shop.setPayoutToolId(shopDomain.getPayoutToolId());
if (shopDomain.getPayoutScheduleId() != null) {
shop.setPayoutSchedule(new BusinessScheduleRef(shopDomain.getPayoutScheduleId()));
}

View File

@ -11,7 +11,7 @@ public class EnumUtils {
case unblocked:
return Blocking.unblocked(new Unblocked());
default:
throw new RuntimeException("No such blocking state");
throw new IllegalArgumentException("No such blocking state " + blocking);
}
}
@ -22,7 +22,7 @@ public class EnumUtils {
case suspended:
return Suspension.suspended(new Suspended());
default:
throw new RuntimeException("No such suspension state");
throw new IllegalArgumentException("No such suspension state " + suspension);
}
}
}

View File

@ -169,7 +169,7 @@ public class ReadTest extends IntegrationTestBase {
Assert.assertFalse(searchHits.isEmpty());
Assert.assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getContracts().get(CONTRACT).getLegalAgreement().getLegalAgreementId().equals("ДГ-123432")));
.anyMatch(partySearchHit -> partySearchHit.getParty().getContracts().get(CONTRACT).getLegalAgreement().getId().equals("ДГ-123432")));
}
@Test