Merge pull request #5 from rbkmoney/fx/NEW-7/using_party_id

Fx/new 7/using party
This commit is contained in:
Inal Arsanukaev 2018-08-31 12:50:29 +03:00 committed by GitHub
commit c7887226a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 210 additions and 125 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>newway</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>
<packaging>jar</packaging>
<name>newway</name>

View File

@ -2,8 +2,9 @@ package com.rbkmoney.newway.config;
import com.rbkmoney.eventstock.client.EventPublisher;
import com.rbkmoney.eventstock.client.poll.PollingEventPublisherBuilder;
import com.rbkmoney.newway.poller.handler.InvoicingEventStockHandler;
import com.rbkmoney.newway.poller.handler.PayoutEventStockHandler;
import com.rbkmoney.newway.poller.handler.ProcessingEventStockHandler;
import com.rbkmoney.newway.poller.handler.PartyManagementEventStockHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -15,8 +16,8 @@ import java.io.IOException;
public class EventStockConfig {
@Bean
public EventPublisher processingEventPublisher(
ProcessingEventStockHandler processingEventStockHandler,
public EventPublisher partyManagementEventPublisher(
PartyManagementEventStockHandler partyManagementEventStockHandler,
@Value("${bm.processing.url}") Resource resource,
@Value("${bm.processing.polling.delay}") int pollDelay,
@Value("${bm.processing.polling.retryDelay}") int retryDelay,
@ -24,7 +25,24 @@ public class EventStockConfig {
) throws IOException {
return new PollingEventPublisherBuilder()
.withURI(resource.getURI())
.withEventHandler(processingEventStockHandler)
.withEventHandler(partyManagementEventStockHandler)
.withMaxPoolSize(maxPoolSize)
.withEventRetryDelay(retryDelay)
.withPollDelay(pollDelay)
.build();
}
@Bean
public EventPublisher invoicingEventPublisher(
InvoicingEventStockHandler invoicingEventStockHandler,
@Value("${bm.processing.url}") Resource resource,
@Value("${bm.processing.polling.delay}") int pollDelay,
@Value("${bm.processing.polling.retryDelay}") int retryDelay,
@Value("${bm.processing.polling.maxPoolSize}") int maxPoolSize
) throws IOException {
return new PollingEventPublisherBuilder()
.withURI(resource.getURI())
.withEventHandler(invoicingEventStockHandler)
.withMaxPoolSize(maxPoolSize)
.withEventRetryDelay(retryDelay)
.withPollDelay(pollDelay)

View File

@ -6,6 +6,6 @@ import com.rbkmoney.newway.exception.DaoException;
public interface ContractDao extends GenericDao {
Long save(Contract contract) throws DaoException;
Contract get(String contractId) throws DaoException;
void updateNotCurrent(String contractId) throws DaoException;
Contract get(String partyId, String contractId) throws DaoException;
void updateNotCurrent(String partyId, String contractId) throws DaoException;
}

View File

@ -6,6 +6,6 @@ import com.rbkmoney.newway.exception.DaoException;
public interface ContractorDao extends GenericDao {
Long save(Contractor contractor) throws DaoException;
Contractor get(String contractorId) throws DaoException;
void updateNotCurrent(String contractorId) throws DaoException;
Contractor get(String partyId, String contractorId) throws DaoException;
void updateNotCurrent(String partyId, String contractorId) throws DaoException;
}

View File

@ -6,6 +6,6 @@ import com.rbkmoney.newway.exception.DaoException;
public interface ShopDao extends GenericDao {
Long save(Shop shop) throws DaoException;
Shop get(String shopId) throws DaoException;
void updateNotCurrent(String shopId) throws DaoException;
Shop get(String partyId, String shopId) throws DaoException;
void updateNotCurrent(String partyId, String shopId) throws DaoException;
}

View File

@ -35,17 +35,17 @@ public class ContractDaoImpl extends AbstractGenericDao implements ContractDao {
}
@Override
public Contract get(String contractId) throws DaoException {
public Contract get(String partyId, String contractId) throws DaoException {
Query query = getDslContext().selectFrom(CONTRACT)
.where(CONTRACT.CONTRACT_ID.eq(contractId).and(CONTRACT.CURRENT));
.where(CONTRACT.PARTY_ID.eq(partyId).and(CONTRACT.CONTRACT_ID.eq(contractId)).and(CONTRACT.CURRENT));
return fetchOne(query, contractRowMapper);
}
@Override
public void updateNotCurrent(String contractId) throws DaoException {
public void updateNotCurrent(String partyId, String contractId) throws DaoException {
Query query = getDslContext().update(CONTRACT).set(CONTRACT.CURRENT, false)
.where(CONTRACT.CONTRACT_ID.eq(contractId).and(CONTRACT.CURRENT));
.where(CONTRACT.PARTY_ID.eq(partyId).and(CONTRACT.CONTRACT_ID.eq(contractId)).and(CONTRACT.CURRENT));
executeOne(query);
}
}

View File

@ -35,17 +35,17 @@ public class ContractorDaoImpl extends AbstractGenericDao implements ContractorD
}
@Override
public Contractor get(String contractorId) throws DaoException {
public Contractor get(String partyId, String contractorId) throws DaoException {
Query query = getDslContext().selectFrom(CONTRACTOR)
.where(CONTRACTOR.CONTRACTOR_ID.eq(contractorId).and(CONTRACTOR.CURRENT));
.where(CONTRACTOR.PARTY_ID.eq(partyId).and(CONTRACTOR.CONTRACTOR_ID.eq(contractorId)).and(CONTRACTOR.CURRENT));
return fetchOne(query, contractorRowMapper);
}
@Override
public void updateNotCurrent(String contractId) throws DaoException {
public void updateNotCurrent(String partyId, String contractId) throws DaoException {
Query query = getDslContext().update(CONTRACTOR).set(CONTRACTOR.CURRENT, false)
.where(CONTRACTOR.CONTRACTOR_ID.eq(contractId).and(CONTRACTOR.CURRENT));
.where(CONTRACTOR.PARTY_ID.eq(partyId).and(CONTRACTOR.CONTRACTOR_ID.eq(contractId)).and(CONTRACTOR.CURRENT));
executeOne(query);
}
}

View File

@ -35,17 +35,17 @@ public class ShopDaoImpl extends AbstractGenericDao implements ShopDao {
}
@Override
public Shop get(String shopId) throws DaoException {
public Shop get(String partyId, String shopId) throws DaoException {
Query query = getDslContext().selectFrom(SHOP)
.where(SHOP.SHOP_ID.eq(shopId).and(SHOP.CURRENT));
.where(SHOP.PARTY_ID.eq(partyId).and(SHOP.SHOP_ID.eq(shopId)).and(SHOP.CURRENT));
return fetchOne(query, shopRowMapper);
}
@Override
public void updateNotCurrent(String shopId) throws DaoException {
public void updateNotCurrent(String partyId, String shopId) throws DaoException {
Query query = getDslContext().update(SHOP).set(SHOP.CURRENT, false)
.where(SHOP.SHOP_ID.eq(shopId).and(SHOP.CURRENT));
.where(SHOP.PARTY_ID.eq(partyId).and(SHOP.SHOP_ID.eq(shopId)).and(SHOP.CURRENT));
executeOne(query);
}
}

View File

@ -5,8 +5,9 @@ import com.rbkmoney.eventstock.client.EventConstraint;
import com.rbkmoney.eventstock.client.EventPublisher;
import com.rbkmoney.eventstock.client.SubscriberConfig;
import com.rbkmoney.eventstock.client.poll.EventFlowFilter;
import com.rbkmoney.newway.service.InvoicingService;
import com.rbkmoney.newway.service.PayoutService;
import com.rbkmoney.newway.service.ProcessingService;
import com.rbkmoney.newway.service.PartyManagementService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
@ -16,30 +17,37 @@ import java.util.Optional;
@Component
public class OnStart implements ApplicationListener<ApplicationReadyEvent> {
private final EventPublisher processingEventPublisher;
private final EventPublisher partyManagementEventPublisher;
private final EventPublisher invoicingEventPublisher;
private final EventPublisher payoutEventPublisher;
private final ProcessingService processingService;
private final PartyManagementService partyManagementService;
private final InvoicingService invoicingService;
private final PayoutService payoutService;
@Value("${bm.pollingEnabled}")
private boolean pollingEnabled;
public OnStart(EventPublisher processingEventPublisher,
public OnStart(EventPublisher partyManagementEventPublisher,
EventPublisher invoicingEventPublisher,
EventPublisher payoutEventPublisher,
ProcessingService processingService,
PartyManagementService partyManagementService,
InvoicingService invoicingService,
PayoutService payoutService) {
this.processingEventPublisher = processingEventPublisher;
this.partyManagementEventPublisher = partyManagementEventPublisher;
this.invoicingEventPublisher = invoicingEventPublisher;
this.payoutEventPublisher = payoutEventPublisher;
this.processingService = processingService;
this.partyManagementService = partyManagementService;
this.invoicingService = invoicingService;
this.payoutService = payoutService;
}
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
if (pollingEnabled) {
processingEventPublisher.subscribe(buildSubscriberConfig(processingService.getLastEventId()));
partyManagementEventPublisher.subscribe(buildSubscriberConfig(partyManagementService.getLastEventId()));
invoicingEventPublisher.subscribe(buildSubscriberConfig(invoicingService.getLastEventId()));
payoutEventPublisher.subscribe(buildSubscriberConfig(payoutService.getLastEventId()));
}
}

View File

@ -0,0 +1,53 @@
package com.rbkmoney.newway.poller.handler;
import com.rbkmoney.damsel.event_stock.StockEvent;
import com.rbkmoney.damsel.payment_processing.Event;
import com.rbkmoney.damsel.payment_processing.EventPayload;
import com.rbkmoney.eventstock.client.EventAction;
import com.rbkmoney.eventstock.client.EventHandler;
import com.rbkmoney.newway.poller.handler.impl.invoicing.AbstractInvoicingHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Component
public class InvoicingEventStockHandler implements EventHandler<StockEvent> {
private final Logger log = LoggerFactory.getLogger(this.getClass());
private final List<AbstractInvoicingHandler> invoicingHandlers;
public InvoicingEventStockHandler(List<AbstractInvoicingHandler> invoicingHandlers) {
this.invoicingHandlers = invoicingHandlers;
}
@Override
public EventAction handle(StockEvent stockEvent, String subsKey) {
Event processingEvent = stockEvent.getSourceEvent().getProcessingEvent();
EventPayload payload = processingEvent.getPayload();
try {
handleEvents(processingEvent, payload);
} catch (RuntimeException e) {
log.error("Error when polling invoicing event with id={}", processingEvent.getId(), e);
return EventAction.DELAYED_RETRY;
}
return EventAction.CONTINUE;
}
@Transactional(propagation = Propagation.REQUIRED)
public void handleEvents(Event processingEvent, EventPayload payload) {
if (payload.isSetInvoiceChanges()) {
payload.getInvoiceChanges().forEach(cc -> invoicingHandlers.forEach(ph -> {
if (ph.accept(cc)) {
ph.handle(cc, processingEvent);
}
}));
}
}
}

View File

@ -5,7 +5,6 @@ import com.rbkmoney.damsel.payment_processing.Event;
import com.rbkmoney.damsel.payment_processing.EventPayload;
import com.rbkmoney.eventstock.client.EventAction;
import com.rbkmoney.eventstock.client.EventHandler;
import com.rbkmoney.newway.poller.handler.impl.invoicing.AbstractInvoicingHandler;
import com.rbkmoney.newway.poller.handler.impl.party_mngmnt.AbstractPartyManagementHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -16,15 +15,13 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Component
public class ProcessingEventStockHandler implements EventHandler<StockEvent> {
public class PartyManagementEventStockHandler implements EventHandler<StockEvent> {
private final Logger log = LoggerFactory.getLogger(this.getClass());
private final List<AbstractInvoicingHandler> invoicingHandlers;
private final List<AbstractPartyManagementHandler> partyManagementHandlers;
public ProcessingEventStockHandler(List<AbstractInvoicingHandler> invoicingHandlers, List<AbstractPartyManagementHandler> partyManagementHandlers) {
this.invoicingHandlers = invoicingHandlers;
public PartyManagementEventStockHandler(List<AbstractPartyManagementHandler> partyManagementHandlers) {
this.partyManagementHandlers = partyManagementHandlers;
}
@ -36,7 +33,7 @@ public class ProcessingEventStockHandler implements EventHandler<StockEvent> {
try {
handleEvents(processingEvent, payload);
} catch (RuntimeException e) {
log.error("Error when polling processing event with id={}", processingEvent.getId(), e);
log.error("Error when polling party management event with id={}", processingEvent.getId(), e);
return EventAction.DELAYED_RETRY;
}
return EventAction.CONTINUE;
@ -44,15 +41,7 @@ public class ProcessingEventStockHandler implements EventHandler<StockEvent> {
@Transactional(propagation = Propagation.REQUIRED)
public void handleEvents(Event processingEvent, EventPayload payload) {
if (payload.isSetInvoiceChanges()) {
payload.getInvoiceChanges().forEach(cc -> {
invoicingHandlers.forEach(ih -> {
if (ih.accept(cc)) {
ih.handle(cc, processingEvent);
}
});
});
} else if (payload.isSetPartyChanges()) {
if (payload.isSetPartyChanges()) {
payload.getPartyChanges().forEach(cc -> partyManagementHandlers.forEach(ph -> {
if (ph.accept(cc)) {
ph.handle(cc, processingEvent);

View File

@ -48,7 +48,7 @@ public class ContractAdjustmentCreatedHandler extends AbstractClaimChangedHandle
String contractId = contractEffectUnit.getContractId();
String partyId = event.getSource().getPartyId();
log.info("Start contract adjustment created handling, eventId={}, partyId={}, contractId={}", eventId, partyId, contractId);
Contract contractSource = contractDao.get(contractId);
Contract contractSource = contractDao.get(partyId, contractId);
if (contractSource == null) {
throw new NotFoundException(String.format("Contract not found, contractId='%s'", contractId));
}
@ -57,7 +57,7 @@ public class ContractAdjustmentCreatedHandler extends AbstractClaimChangedHandle
contractSource.setWtime(null);
contractSource.setEventId(eventId);
contractSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
contractDao.updateNotCurrent(contractId);
contractDao.updateNotCurrent(partyId, contractId);
long cntrctId = contractDao.save(contractSource);
List<ContractAdjustment> adjustments = new ArrayList<>(contractAdjustmentDao.getByCntrctId(contractSourceId));

View File

@ -46,7 +46,7 @@ public class ContractContractorIDChangedHandler extends AbstractClaimChangedHand
String contractId = contractEffectUnit.getContractId();
String partyId = event.getSource().getPartyId();
log.info("Start contract contractorChanged changed handling, eventId={}, partyId={}, contractId={}", eventId, partyId, contractId);
Contract contractSource = contractDao.get(contractId);
Contract contractSource = contractDao.get(partyId, contractId);
if (contractSource == null) {
throw new NotFoundException(String.format("Contract not found, contractId='%s'", contractId));
}
@ -56,7 +56,7 @@ public class ContractContractorIDChangedHandler extends AbstractClaimChangedHand
contractSource.setEventId(eventId);
contractSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
contractSource.setContractorId(contractorChanged);
contractDao.updateNotCurrent(contractId);
contractDao.updateNotCurrent(partyId, contractId);
long cntrctId = contractDao.save(contractSource);
List<ContractAdjustment> adjustments = contractAdjustmentDao.getByCntrctId(contractSourceId);

View File

@ -48,7 +48,7 @@ public class ContractLegalAgreementBoundHandler extends AbstractClaimChangedHand
String contractId = contractEffectUnit.getContractId();
String partyId = event.getSource().getPartyId();
log.info("Start contract legal agreement bound handling, eventId={}, partyId={}, contractId={}", eventId, partyId, contractId);
Contract contractSource = contractDao.get(contractId);
Contract contractSource = contractDao.get(partyId, contractId);
if (contractSource == null) {
throw new NotFoundException(String.format("Contract not found, contractId='%s'", contractId));
}
@ -58,7 +58,7 @@ public class ContractLegalAgreementBoundHandler extends AbstractClaimChangedHand
contractSource.setEventId(eventId);
contractSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
ContractUtil.fillContractLegalAgreementFields(contractSource, legalAgreementBound);
contractDao.updateNotCurrent(contractId);
contractDao.updateNotCurrent(partyId, contractId);
long cntrctId = contractDao.save(contractSource);
List<ContractAdjustment> adjustments = contractAdjustmentDao.getByCntrctId(contractSourceId);

View File

@ -48,7 +48,7 @@ public class ContractPayoutToolCreatedHandler extends AbstractClaimChangedHandle
String contractId = contractEffectUnit.getContractId();
String partyId = event.getSource().getPartyId();
log.info("Start contract payouttool created handling, eventId={}, partyId={}, contractId={}", eventId, partyId, contractId);
Contract contractSource = contractDao.get(contractId);
Contract contractSource = contractDao.get(partyId, contractId);
if (contractSource == null) {
throw new NotFoundException(String.format("Contract not found, contractId='%s'", contractId));
}
@ -57,7 +57,7 @@ public class ContractPayoutToolCreatedHandler extends AbstractClaimChangedHandle
contractSource.setWtime(null);
contractSource.setEventId(eventId);
contractSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
contractDao.updateNotCurrent(contractId);
contractDao.updateNotCurrent(partyId, contractId);
long cntrctId = contractDao.save(contractSource);
List<ContractAdjustment> adjustments = contractAdjustmentDao.getByCntrctId(contractSourceId);

View File

@ -48,7 +48,7 @@ public class ContractReportPreferencesChangedHandler extends AbstractClaimChange
String contractId = contractEffectUnit.getContractId();
String partyId = event.getSource().getPartyId();
log.info("Start contract report preferences changed handling, eventId={}, partyId={}, contractId={}", eventId, partyId, contractId);
Contract contractSource = contractDao.get(contractId);
Contract contractSource = contractDao.get(partyId, contractId);
if (contractSource == null) {
throw new NotFoundException(String.format("Contract not found, contractId='%s'", contractId));
}
@ -58,7 +58,7 @@ public class ContractReportPreferencesChangedHandler extends AbstractClaimChange
contractSource.setEventId(eventId);
contractSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
ContractUtil.fillReportPreferences(contractSource, reportPreferencesChanged.getServiceAcceptanceActPreferences());
contractDao.updateNotCurrent(contractId);
contractDao.updateNotCurrent(partyId, contractId);
long cntrctId = contractDao.save(contractSource);
List<ContractAdjustment> adjustments = contractAdjustmentDao.getByCntrctId(contractSourceId);

View File

@ -47,7 +47,7 @@ public class ContractStatusChangedHandler extends AbstractClaimChangedHandler {
String contractId = contractEffectUnit.getContractId();
String partyId = event.getSource().getPartyId();
log.info("Start contractSource status changed handling, eventId={}, partyId={}, contractId={}", eventId, partyId, contractId);
Contract contractSource = contractDao.get(contractId);
Contract contractSource = contractDao.get(partyId, contractId);
if (contractSource == null) {
throw new NotFoundException(String.format("Contract not found, contractId='%s'", contractId));
}
@ -64,7 +64,7 @@ public class ContractStatusChangedHandler extends AbstractClaimChangedHandler {
if (statusChanged.isSetTerminated()) {
contractSource.setStatusTerminatedAt(TypeUtil.stringToLocalDateTime(statusChanged.getTerminated().getTerminatedAt()));
}
contractDao.updateNotCurrent(contractId);
contractDao.updateNotCurrent(partyId, contractId);
long cntrctId = contractDao.save(contractSource);
List<ContractAdjustment> adjustments = contractAdjustmentDao.getByCntrctId(contractSourceId);

View File

@ -37,7 +37,7 @@ public class ContractorIdentificationalLevelChangedHandler extends AbstractClaim
String contractorId = contractorEffect.getId();
String partyId = event.getSource().getPartyId();
log.info("Start identificational level changed handling, eventId={}, partyId={}, contractorId={}", eventId, partyId, contractorId);
Contractor contractorSource = contractorDao.get(contractorId);
Contractor contractorSource = contractorDao.get(partyId, contractorId);
if (contractorSource == null) {
throw new NotFoundException(String.format("Contractor not found, contractorId='%s'", contractorId));
}
@ -46,7 +46,7 @@ public class ContractorIdentificationalLevelChangedHandler extends AbstractClaim
contractorSource.setEventId(eventId);
contractorSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
contractorSource.setIdentificationalLevel(identificationLevelChanged.name());
contractorDao.updateNotCurrent(contractorId);
contractorDao.updateNotCurrent(partyId, contractorId);
contractorDao.save(contractorSource);
log.info("Contract identificational level has been saved, eventId={}, contractorId={}", eventId, contractorId);
});

View File

@ -39,7 +39,7 @@ public class ShopAccountCreatedHandler extends AbstractClaimChangedHandler {
String shopId = shopEffect.getShopId();
String partyId = event.getSource().getPartyId();
log.info("Start shop accountCreated handling, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
Shop shopSource = shopDao.get(shopId);
Shop shopSource = shopDao.get(partyId, shopId);
if (shopSource == null) {
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
}
@ -49,7 +49,7 @@ public class ShopAccountCreatedHandler extends AbstractClaimChangedHandler {
shopSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
ShopUtil.fillShopAccount(shopSource, accountCreated);
shopDao.updateNotCurrent(shopId);
shopDao.updateNotCurrent(partyId, shopId);
shopDao.save(shopSource);
log.info("Shop accountCreated has been saved, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
});

View File

@ -42,7 +42,7 @@ public class ShopBlockingHandler extends AbstractPartyManagementHandler {
String shopId = change.getShopBlocking().getShopId();
String partyId = event.getSource().getPartyId();
log.info("Start shop blocking handling, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
Shop shopSource = shopDao.get(shopId);
Shop shopSource = shopDao.get(partyId, shopId);
if (shopSource == null) {
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
}
@ -66,7 +66,7 @@ public class ShopBlockingHandler extends AbstractPartyManagementHandler {
shopSource.setBlockingBlockedReason(blocking.getBlocked().getReason());
shopSource.setBlockingBlockedSince(TypeUtil.stringToLocalDateTime(blocking.getBlocked().getSince()));
}
shopDao.updateNotCurrent(shopId);
shopDao.updateNotCurrent(partyId, shopId);
shopDao.save(shopSource);
log.info("Shop blocking has been saved, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
}

View File

@ -36,7 +36,7 @@ public class ShopCategoryChangedHandler extends AbstractClaimChangedHandler {
String shopId = shopEffect.getShopId();
String partyId = event.getSource().getPartyId();
log.info("Start shop categoryId changed handling, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
Shop shopSource = shopDao.get(shopId);
Shop shopSource = shopDao.get(partyId, shopId);
if (shopSource == null) {
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
}
@ -45,7 +45,7 @@ public class ShopCategoryChangedHandler extends AbstractClaimChangedHandler {
shopSource.setEventId(eventId);
shopSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
shopSource.setCategoryId(categoryId);
shopDao.updateNotCurrent(shopId);
shopDao.updateNotCurrent(partyId, shopId);
shopDao.save(shopSource);
log.info("Shop categoryId has been saved, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
});

View File

@ -38,7 +38,7 @@ public class ShopContractChangedHandler extends AbstractClaimChangedHandler {
String shopId = shopEffect.getShopId();
String partyId = event.getSource().getPartyId();
log.info("Start shop contractChanged handling, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
Shop shopSource = shopDao.get(shopId);
Shop shopSource = shopDao.get(partyId, shopId);
if (shopSource == null) {
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
}
@ -48,7 +48,7 @@ public class ShopContractChangedHandler extends AbstractClaimChangedHandler {
shopSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
shopSource.setContractId(contractChanged.getContractId());
shopSource.setPayoutToolId(contractChanged.getPayoutToolId());
shopDao.updateNotCurrent(shopId);
shopDao.updateNotCurrent(partyId, shopId);
shopDao.save(shopSource);
log.info("Shop contractChanged has been saved, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
});

View File

@ -38,7 +38,7 @@ public class ShopDetailsChangedHandler extends AbstractClaimChangedHandler {
String shopId = shopEffect.getShopId();
String partyId = event.getSource().getPartyId();
log.info("Start shop detailsChanged handling, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
Shop shopSource = shopDao.get(shopId);
Shop shopSource = shopDao.get(partyId, shopId);
if (shopSource == null) {
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
}
@ -48,7 +48,7 @@ public class ShopDetailsChangedHandler extends AbstractClaimChangedHandler {
shopSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
shopSource.setDetailsName(detailsChanged.getName());
shopSource.setDetailsDescription(detailsChanged.getDescription());
shopDao.updateNotCurrent(shopId);
shopDao.updateNotCurrent(partyId, shopId);
shopDao.save(shopSource);
log.info("Shop detailsChanged has been saved, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
});

View File

@ -38,7 +38,7 @@ public class ShopLocationChangedHandler extends AbstractClaimChangedHandler {
String shopId = shopEffect.getShopId();
String partyId = event.getSource().getPartyId();
log.info("Start shop locationChanged handling, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
Shop shopSource = shopDao.get(shopId);
Shop shopSource = shopDao.get(partyId, shopId);
if (shopSource == null) {
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
}
@ -51,7 +51,7 @@ public class ShopLocationChangedHandler extends AbstractClaimChangedHandler {
} else {
throw new IllegalArgumentException("Illegal shop location " + locationChanged);
}
shopDao.updateNotCurrent(shopId);
shopDao.updateNotCurrent(partyId, shopId);
shopDao.save(shopSource);
log.info("Shop locationChanged has been saved, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
});

View File

@ -37,7 +37,7 @@ public class ShopPayoutScheduleChangedHandler extends AbstractClaimChangedHandle
String shopId = shopEffect.getShopId();
String partyId = event.getSource().getPartyId();
log.info("Start shop payoutScheduleChanged handling, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
Shop shopSource = shopDao.get(shopId);
Shop shopSource = shopDao.get(partyId, shopId);
if (shopSource == null) {
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
}
@ -50,7 +50,7 @@ public class ShopPayoutScheduleChangedHandler extends AbstractClaimChangedHandle
} else {
shopSource.setPayoutScheduleId(null);
}
shopDao.updateNotCurrent(shopId);
shopDao.updateNotCurrent(partyId, shopId);
shopDao.save(shopSource);
log.info("Shop payoutScheduleChanged has been saved, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
});

View File

@ -37,7 +37,7 @@ public class ShopPayoutToolChangedHandler extends AbstractClaimChangedHandler {
String shopId = shopEffect.getShopId();
String partyId = event.getSource().getPartyId();
log.info("Start shop payoutToolChanged handling, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
Shop shopSource = shopDao.get(shopId);
Shop shopSource = shopDao.get(partyId, shopId);
if (shopSource == null) {
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
}
@ -46,7 +46,7 @@ public class ShopPayoutToolChangedHandler extends AbstractClaimChangedHandler {
shopSource.setEventId(eventId);
shopSource.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
shopSource.setPayoutToolId(payoutToolChanged);
shopDao.updateNotCurrent(shopId);
shopDao.updateNotCurrent(partyId, shopId);
shopDao.save(shopSource);
log.info("Shop payoutToolChanged has been saved, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
});

View File

@ -41,7 +41,7 @@ public class ShopSuspensionHandler extends AbstractPartyManagementHandler {
String shopId = change.getShopSuspension().getShopId();
String partyId = event.getSource().getPartyId();
log.info("Start shop suspension handling, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
Shop shopSource = shopDao.get(shopId);
Shop shopSource = shopDao.get(partyId, shopId);
if (shopSource == null) {
throw new NotFoundException(String.format("Shop not found, shopId='%s'", shopId));
}
@ -61,7 +61,7 @@ public class ShopSuspensionHandler extends AbstractPartyManagementHandler {
shopSource.setSuspensionActiveSince(null);
shopSource.setSuspensionSuspendedSince(TypeUtil.stringToLocalDateTime(suspension.getSuspended().getSince()));
}
shopDao.updateNotCurrent(shopId);
shopDao.updateNotCurrent(partyId, shopId);
shopDao.save(shopSource);
log.info("Shop suspension has been saved, eventId={}, partyId={}, shopId={}", eventId, partyId, shopId);
}

View File

@ -0,0 +1,28 @@
package com.rbkmoney.newway.service;
import com.rbkmoney.newway.dao.invoicing.iface.InvoiceDao;
import com.rbkmoney.newway.dao.party.iface.PartyDao;
import com.rbkmoney.newway.exception.DaoException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.Optional;
@Service
public class InvoicingService {
private final Logger log = LoggerFactory.getLogger(this.getClass());
private final InvoiceDao invoiceDao;
public InvoicingService(InvoiceDao invoiceDao) {
this.invoiceDao = invoiceDao;
}
public Optional<Long> getLastEventId() throws DaoException {
Optional<Long> lastEventId = Optional.ofNullable(invoiceDao.getLastEventId());
log.info("Last invoicing eventId={}", lastEventId);
return lastEventId;
}
}

View File

@ -0,0 +1,27 @@
package com.rbkmoney.newway.service;
import com.rbkmoney.newway.dao.party.iface.PartyDao;
import com.rbkmoney.newway.exception.DaoException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.Optional;
@Service
public class PartyManagementService {
private final Logger log = LoggerFactory.getLogger(this.getClass());
private final PartyDao partyDao;
public PartyManagementService(PartyDao partyDao) {
this.partyDao = partyDao;
}
public Optional<Long> getLastEventId() throws DaoException {
Optional<Long> lastEventId = Optional.ofNullable(partyDao.getLastEventId());
log.info("Last party management eventId={}", lastEventId);
return lastEventId;
}
}

View File

@ -1,38 +0,0 @@
package com.rbkmoney.newway.service;
import com.rbkmoney.newway.dao.invoicing.iface.InvoiceDao;
import com.rbkmoney.newway.dao.party.iface.PartyDao;
import com.rbkmoney.newway.exception.DaoException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.Optional;
@Service
public class ProcessingService {
private final Logger log = LoggerFactory.getLogger(this.getClass());
private final PartyDao partyDao;
private final InvoiceDao invoiceDao;
public ProcessingService(PartyDao partyDao, InvoiceDao invoiceDao) {
this.partyDao = partyDao;
this.invoiceDao = invoiceDao;
}
public Optional<Long> getLastEventId() throws DaoException {
Long partyLastEventId = partyDao.getLastEventId();
Long invLastEventId = invoiceDao.getLastEventId();
Long max = partyLastEventId;
if (partyLastEventId == null) {
max = invLastEventId;
} else if (invLastEventId != null) {
max = Math.max(partyLastEventId, invLastEventId);
}
Optional<Long> lastEventId = Optional.ofNullable(max);
log.info("Last processing eventId={}", lastEventId);
return lastEventId;
}
}

View File

@ -19,9 +19,9 @@ public class ContractDaoImplTest extends AbstractIntegrationTest {
Contract contract = random(Contract.class);
contract.setCurrent(true);
contractDao.save(contract);
Contract contractGet = contractDao.get(contract.getContractId());
Contract contractGet = contractDao.get(contract.getPartyId(), contract.getContractId());
assertEquals(contract, contractGet);
contractDao.updateNotCurrent(contract.getContractId());
assertNull(contractDao.get(contract.getContractId()));
contractDao.updateNotCurrent(contract.getPartyId(), contract.getContractId());
assertNull(contractDao.get(contract.getPartyId(), contract.getContractId()));
}
}

View File

@ -19,9 +19,9 @@ public class ContractorDaoImplTest extends AbstractIntegrationTest {
Contractor contractor = random(Contractor.class);
contractor.setCurrent(true);
contractorDao.save(contractor);
Contractor contractorGet = contractorDao.get(contractor.getContractorId());
Contractor contractorGet = contractorDao.get(contractor.getPartyId(), contractor.getContractorId());
assertEquals(contractor, contractorGet);
contractorDao.updateNotCurrent(contractor.getContractorId());
assertNull(contractorDao.get(contractor.getContractorId()));
contractorDao.updateNotCurrent(contractor.getPartyId(), contractor.getContractorId());
assertNull(contractorDao.get(contractor.getPartyId(), contractor.getContractorId()));
}
}

View File

@ -19,9 +19,9 @@ public class ShopDaoImplTest extends AbstractIntegrationTest {
Shop shop = random(Shop.class);
shop.setCurrent(true);
shopDao.save(shop);
Shop shopGet = shopDao.get(shop.getShopId());
Shop shopGet = shopDao.get(shop.getPartyId(), shop.getShopId());
assertEquals(shop, shopGet);
shopDao.updateNotCurrent(shop.getShopId());
assertNull(shopDao.get(shop.getShopId()));
shopDao.updateNotCurrent(shop.getPartyId(), shop.getShopId());
assertNull(shopDao.get(shop.getPartyId(), shop.getShopId()));
}
}