mirror of
https://github.com/valitydev/newway.git
synced 2024-11-07 01:45:18 +00:00
NEW-28: saving deprecated contractor
This commit is contained in:
parent
f2e8743f64
commit
64570a9cf0
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>newway</artifactId>
|
||||
<version>1.0.12-SNAPSHOT</version>
|
||||
<version>1.0.13-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>newway</name>
|
||||
|
@ -4,16 +4,15 @@ import com.rbkmoney.damsel.payment_processing.ContractEffectUnit;
|
||||
import com.rbkmoney.damsel.payment_processing.Event;
|
||||
import com.rbkmoney.damsel.payment_processing.PartyChange;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractAdjustmentDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.ContractDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.PartyDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.PayoutToolDao;
|
||||
import com.rbkmoney.newway.dao.party.iface.*;
|
||||
import com.rbkmoney.newway.domain.enums.ContractStatus;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Contract;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Contractor;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Party;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.util.ContractUtil;
|
||||
import com.rbkmoney.newway.util.ContractorUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -21,6 +20,7 @@ import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
public class ContractCreatedHandler extends AbstractClaimChangedHandler {
|
||||
@ -28,12 +28,14 @@ public class ContractCreatedHandler extends AbstractClaimChangedHandler {
|
||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final ContractDao contractDao;
|
||||
private final ContractorDao contractorDao;
|
||||
private final PartyDao partyDao;
|
||||
private final ContractAdjustmentDao contractAdjustmentDao;
|
||||
private final PayoutToolDao payoutToolDao;
|
||||
|
||||
public ContractCreatedHandler(ContractDao contractDao, PartyDao partyDao, ContractAdjustmentDao contractAdjustmentDao, PayoutToolDao payoutToolDao) {
|
||||
public ContractCreatedHandler(ContractDao contractDao, ContractorDao contractorDao, PartyDao partyDao, ContractAdjustmentDao contractAdjustmentDao, PayoutToolDao payoutToolDao) {
|
||||
this.contractDao = contractDao;
|
||||
this.contractorDao = contractorDao;
|
||||
this.partyDao = partyDao;
|
||||
this.contractAdjustmentDao = contractAdjustmentDao;
|
||||
this.payoutToolDao = payoutToolDao;
|
||||
@ -85,9 +87,22 @@ public class ContractCreatedHandler extends AbstractClaimChangedHandler {
|
||||
if (contractCreated.isSetReportPreferences() && contractCreated.getReportPreferences().isSetServiceAcceptanceActPreferences()) {
|
||||
ContractUtil.fillReportPreferences(contract, contractCreated.getReportPreferences().getServiceAcceptanceActPreferences());
|
||||
}
|
||||
contract.setContractorId(contractCreated.getContractorId());
|
||||
|
||||
String contractorId = "";
|
||||
if (contractCreated.isSetContractorId()) {
|
||||
contractorId = contractCreated.getContractorId();
|
||||
} else if (contractCreated.isSetContractor()) {
|
||||
contractorId = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
contract.setContractorId(contractorId);
|
||||
long cntrctId = contractDao.save(contract);
|
||||
|
||||
if (contractCreated.isSetContractor()) {
|
||||
Contractor contractor = ContractorUtil.convertContractor(eventId, event.getCreatedAt(), partyId, partySource.getRevision(), contractCreated.getContractor(), contractorId);
|
||||
contractorDao.save(contractor);
|
||||
}
|
||||
|
||||
List<com.rbkmoney.newway.domain.tables.pojos.ContractAdjustment> adjustments = ContractUtil.convertContractAdjustments(contractCreated, cntrctId);
|
||||
contractAdjustmentDao.save(adjustments);
|
||||
|
||||
|
@ -17,6 +17,7 @@ import com.rbkmoney.newway.domain.tables.pojos.Contractor;
|
||||
import com.rbkmoney.newway.domain.tables.pojos.Party;
|
||||
import com.rbkmoney.newway.exception.NotFoundException;
|
||||
import com.rbkmoney.newway.poller.event_stock.impl.party_mngmnt.AbstractClaimChangedHandler;
|
||||
import com.rbkmoney.newway.util.ContractorUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -48,70 +49,17 @@ public class ContractorCreatedHandler extends AbstractClaimChangedHandler {
|
||||
String contractorId = contractorEffect.getId();
|
||||
String partyId = event.getSource().getPartyId();
|
||||
log.info("Start contractor created handling, eventId={}, partyId={}, contractorId={}", eventId, partyId, contractorId);
|
||||
Contractor contractor = new Contractor();
|
||||
contractor.setEventId(eventId);
|
||||
contractor.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
|
||||
Party partySource = partyDao.get(partyId);
|
||||
if (partySource == null) {
|
||||
throw new NotFoundException(String.format("Party not found, partyId='%s'", partyId));
|
||||
}
|
||||
contractor.setRevision(partySource.getRevision());
|
||||
contractor.setPartyId(partyId);
|
||||
contractor.setContractorId(contractorId);
|
||||
Contractor contractor = ContractorUtil.convertContractor(eventId, event.getCreatedAt(), partyId, partySource.getRevision(), contractorCreated, contractorId);
|
||||
contractor.setIdentificationalLevel(partyContractor.getStatus().name());
|
||||
ContractorType contractorType = TypeUtil.toEnumField(contractorCreated.getSetField().getFieldName(), ContractorType.class);
|
||||
if (contractorType == null) {
|
||||
throw new IllegalArgumentException("Illegal contractorType: " + contractorCreated);
|
||||
}
|
||||
contractor.setType(contractorType);
|
||||
if (contractorCreated.isSetRegisteredUser()) {
|
||||
contractor.setRegisteredUserEmail(contractorCreated.getRegisteredUser().getEmail());
|
||||
} else if (contractorCreated.isSetLegalEntity()) {
|
||||
LegalEntity legalEntity = TypeUtil.toEnumField(contractorCreated.getLegalEntity().getSetField().getFieldName(), LegalEntity.class);
|
||||
if (legalEntity == null) {
|
||||
throw new IllegalArgumentException("Unknown legal entity: " + contractor.getLegalEntity());
|
||||
}
|
||||
contractor.setLegalEntity(legalEntity);
|
||||
if (contractorCreated.getLegalEntity().isSetRussianLegalEntity()) {
|
||||
RussianLegalEntity russianLegalEntity = contractorCreated.getLegalEntity().getRussianLegalEntity();
|
||||
contractor.setRussianLegalEntityRegisteredName(russianLegalEntity.getRegisteredName());
|
||||
contractor.setRussianLegalEntityRegisteredNumber(russianLegalEntity.getRegisteredNumber());
|
||||
contractor.setRussianLegalEntityInn(russianLegalEntity.getInn());
|
||||
contractor.setRussianLegalEntityActualAddress(russianLegalEntity.getActualAddress());
|
||||
contractor.setRussianLegalEntityPostAddress(russianLegalEntity.getPostAddress());
|
||||
contractor.setRussianLegalEntityRepresentativePosition(russianLegalEntity.getRepresentativePosition());
|
||||
contractor.setRussianLegalEntityRepresentativeFullName(russianLegalEntity.getRepresentativeFullName());
|
||||
contractor.setRussianLegalEntityRepresentativeDocument(russianLegalEntity.getRepresentativeDocument());
|
||||
contractor.setRussianLegalEntityRussianBankAccount(russianLegalEntity.getRussianBankAccount().getAccount());
|
||||
contractor.setRussianLegalEntityRussianBankName(russianLegalEntity.getRussianBankAccount().getBankName());
|
||||
contractor.setRussianLegalEntityRussianBankPostAccount(russianLegalEntity.getRussianBankAccount().getBankPostAccount());
|
||||
contractor.setRussianLegalEntityRussianBankBik(russianLegalEntity.getRussianBankAccount().getBankBik());
|
||||
} else if (contractorCreated.getLegalEntity().isSetInternationalLegalEntity()) {
|
||||
InternationalLegalEntity internationalLegalEntity = contractorCreated.getLegalEntity().getInternationalLegalEntity();
|
||||
contractor.setInternationalLegalEntityLegalName(internationalLegalEntity.getLegalName());
|
||||
contractor.setInternationalLegalEntityTradingName(internationalLegalEntity.getTradingName());
|
||||
contractor.setInternationalLegalEntityRegisteredAddress(internationalLegalEntity.getRegisteredAddress());
|
||||
contractor.setInternationalLegalEntityActualAddress(internationalLegalEntity.getActualAddress());
|
||||
contractor.setInternationalLegalEntityRegisteredNumber(internationalLegalEntity.getRegisteredNumber());
|
||||
}
|
||||
} else if (contractorCreated.isSetPrivateEntity()) {
|
||||
PrivateEntity privateEntity = TypeUtil.toEnumField(contractorCreated.getPrivateEntity().getSetField().getFieldName(), PrivateEntity.class);
|
||||
if (privateEntity == null) {
|
||||
throw new IllegalArgumentException("Illegal private entity: " + contractor.getPrivateEntity());
|
||||
}
|
||||
contractor.setPrivateEntity(privateEntity);
|
||||
if (contractorCreated.getPrivateEntity().isSetRussianPrivateEntity()) {
|
||||
RussianPrivateEntity russianPrivateEntity = contractorCreated.getPrivateEntity().getRussianPrivateEntity();
|
||||
contractor.setRussianPrivateEntityFirstName(russianPrivateEntity.getFirstName());
|
||||
contractor.setRussianPrivateEntitySecondName(russianPrivateEntity.getSecondName());
|
||||
contractor.setRussianPrivateEntityMiddleName(russianPrivateEntity.getMiddleName());
|
||||
contractor.setRussianPrivateEntityPhoneNumber(russianPrivateEntity.getContactInfo().getPhoneNumber());
|
||||
contractor.setRussianPrivateEntityEmail(russianPrivateEntity.getContactInfo().getEmail());
|
||||
}
|
||||
}
|
||||
contractorDao.save(contractor);
|
||||
log.info("Contract contractor has been saved, eventId={}, partyId={}, contractorId={}", eventId, partyId, contractorId);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user