From 74a201ad6d9558813b83d0842f0d6ad68b5889a5 Mon Sep 17 00:00:00 2001 From: vitaxa Date: Thu, 20 Jun 2019 18:09:56 +0300 Subject: [PATCH] Fix intent service (#8) * fix state mapping * exclude pan field --- pom.xml | 2 +- .../starter/exception/ValidationException.java | 15 +++++++++++++++ .../spring/boot/starter/model/AdapterState.java | 2 +- .../boot/starter/model/EntryStateModel.java | 2 ++ .../boot/starter/service/IntentService.java | 4 +--- .../boot/starter/service/IntentServiceImpl.java | 12 +++++++++--- .../starter/service/PayoutAdapterService.java | 4 ++-- 7 files changed, 31 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 1d11166..4183cb5 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.rbkmoney adapter-bank-payout-spring-boot-starter - 0.0.6-SNAPSHOT + 0.0.7-SNAPSHOT jar Adapter-bank-payout-spring-boot-starter diff --git a/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/exception/ValidationException.java b/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/exception/ValidationException.java index 1d699ce..dca2d35 100644 --- a/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/exception/ValidationException.java +++ b/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/exception/ValidationException.java @@ -1,4 +1,19 @@ package com.rbkmoney.adapter.bank.payout.spring.boot.starter.exception; public class ValidationException extends RuntimeException { + public ValidationException() { + super(); + } + + public ValidationException(String message) { + super(message); + } + + public ValidationException(String message, Throwable cause) { + super(message, cause); + } + + public ValidationException(Throwable cause) { + super(cause); + } } diff --git a/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/model/AdapterState.java b/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/model/AdapterState.java index 8eddffc..b7556c7 100644 --- a/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/model/AdapterState.java +++ b/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/model/AdapterState.java @@ -13,6 +13,6 @@ import java.time.Instant; @AllArgsConstructor public class AdapterState { private Step step; - private Instant maxDateTimePolling; + private Long maxTimePoolingMillis; private TransactionInfo trxInfo; } diff --git a/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/model/EntryStateModel.java b/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/model/EntryStateModel.java index 1a5832f..54dd868 100644 --- a/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/model/EntryStateModel.java +++ b/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/model/EntryStateModel.java @@ -1,6 +1,7 @@ package com.rbkmoney.adapter.bank.payout.spring.boot.starter.model; import lombok.Data; +import lombok.ToString; import java.util.Map; @@ -9,6 +10,7 @@ public class EntryStateModel { private String withdrawalId; private Long amount; private String currencyCode; + @ToString.Exclude private String pan; private Map options; diff --git a/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/service/IntentService.java b/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/service/IntentService.java index 4784818..91ccc75 100644 --- a/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/service/IntentService.java +++ b/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/service/IntentService.java @@ -4,11 +4,9 @@ import com.rbkmoney.adapter.bank.payout.spring.boot.starter.model.EntryStateMode import com.rbkmoney.adapter.bank.payout.spring.boot.starter.model.ExitStateModel; import com.rbkmoney.damsel.withdrawals.provider_adapter.Intent; -import java.time.Instant; - public interface IntentService { Intent getFailure(ExitStateModel exitStateModel); Intent getSuccess(ExitStateModel exitStateModel); Intent getSleep(ExitStateModel exitStateModel); - Instant getMaxDateTimeInstant(EntryStateModel entryStateModel); + Long getMaxDateTimeInstant(EntryStateModel entryStateModel); } diff --git a/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/service/IntentServiceImpl.java b/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/service/IntentServiceImpl.java index 4df7c3f..d9cfca3 100644 --- a/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/service/IntentServiceImpl.java +++ b/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/service/IntentServiceImpl.java @@ -31,15 +31,21 @@ public class IntentServiceImpl implements IntentService { } public Intent getSleep(ExitStateModel exitStateModel) { - if (exitStateModel.getNextState().getMaxDateTimePolling().getEpochSecond() < Instant.now().getEpochSecond()) { + if (exitStateModel.getNextState().getMaxTimePoolingMillis() == null) { + throw new IllegalArgumentException("Need to specify 'maxTimePoolingMillis' before sleep"); + } + if (exitStateModel.getNextState().getMaxTimePoolingMillis() < Instant.now().toEpochMilli()) { + final Failure failure = new Failure("Sleep timeout"); + failure.setReason("Max time pool limit reached"); return Intent.finish(new FinishIntent(FinishStatus.failure(new Failure()))); } + int timerPollingDelay = OptionsExtractors.extractPollingDelay(exitStateModel.getEntryStateModel().getOptions(), timerProperties.getPollingDelay()); return Intent.sleep(new SleepIntent(new Timer(Timer.timeout(timerPollingDelay)))); } - public Instant getMaxDateTimeInstant(EntryStateModel entryStateModel) { + public Long getMaxDateTimeInstant(EntryStateModel entryStateModel) { int maxTimePolling = extractMaxTimePolling(entryStateModel.getOptions(), timerProperties.getMaxTimePolling()); - return Instant.now().plus(maxTimePolling, ChronoUnit.MINUTES); + return Instant.now().plus(maxTimePolling, ChronoUnit.MINUTES).toEpochMilli(); } } diff --git a/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/service/PayoutAdapterService.java b/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/service/PayoutAdapterService.java index d7b950d..efabe79 100644 --- a/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/service/PayoutAdapterService.java +++ b/src/main/java/com/rbkmoney/adapter/bank/payout/spring/boot/starter/service/PayoutAdapterService.java @@ -27,7 +27,7 @@ public class PayoutAdapterService withdrawalToEntryStateConverter; private final ExitStateToProcessResultConverter exitStateToProcessResultConverter; private final List> handlers; - private final StepResolver resolver; + private final StepResolver resolver; private final WithdrawalValidator validator; @Override @@ -43,4 +43,4 @@ public class PayoutAdapterService