From 60eab70aa1243b06665b036424e8adf54c2b2df0 Mon Sep 17 00:00:00 2001 From: Anatolii Karlov Date: Thu, 11 Jul 2024 11:09:32 +0700 Subject: [PATCH] fix error mapping, bump libs (#73) * fix error mapping, bump libs * remove deprecated --- pom.xml | 32 ++++++------- .../common/damsel/DomainPackageCreators.java | 24 ---------- .../damsel/ProxyProviderPackageCreators.java | 7 --- .../ProxyProviderPackageExtractors.java | 46 ------------------- .../adapter/common/mapper/ErrorMapping.java | 20 +++----- .../common/mapper/ErrorMappingTest.java | 7 ++- 6 files changed, 23 insertions(+), 113 deletions(-) diff --git a/pom.xml b/pom.xml index 603916c..f02fa17 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ adapter-common-lib - 2.0.0 + 2.0.1 jar adapter-common-lib @@ -107,19 +107,7 @@ org.projectlombok lombok - 1.18.24 - provided - - - javax.servlet - javax.servlet-api - 4.0.1 - provided - - - javax.validation - validation-api - 2.0.1.Final + 1.18.32 provided @@ -187,31 +175,37 @@ dev.vality damsel - 1.563-d384c12 + 1.641-6051aa9 provided dev.vality cds-proto - 1.66-01353ce + 1.71-b3db02c provided dev.vality.woody woody-thrift - 1.0.4 + 2.0.1 provided dev.vality bender-proto - 1.20-be9cdeb + 1.27-753b935 + provided + + + dev.vality + msgpack-proto + 1.17-7481bb4 provided dev.vality.geck serializer - 0.0.1 + 1.0.1 provided diff --git a/src/main/java/dev/vality/adapter/common/damsel/DomainPackageCreators.java b/src/main/java/dev/vality/adapter/common/damsel/DomainPackageCreators.java index 577d2e9..10ffaf9 100644 --- a/src/main/java/dev/vality/adapter/common/damsel/DomainPackageCreators.java +++ b/src/main/java/dev/vality/adapter/common/damsel/DomainPackageCreators.java @@ -43,30 +43,6 @@ public class DomainPackageCreators { return new Cash(amount, currency); } - @Deprecated - public static BankCard createBankCardWithExpDate(String bin, - String token, - LegacyBankCardPaymentSystem bankCardPaymentSystem, - String month, - String year, - String cardholderName) { - return createBankCard(bin, token, bankCardPaymentSystem, createBankCardExpDate(month, year), cardholderName); - } - - @Deprecated - public static BankCard createBankCard(String bin, - String token, - LegacyBankCardPaymentSystem bankCardPaymentSystem, - BankCardExpDate bankCardExpDate, - String cardholderName) { - return new BankCard() - .setBin(bin) - .setToken(token) - .setPaymentSystemDeprecated(bankCardPaymentSystem) - .setExpDate(bankCardExpDate) - .setCardholderName(cardholderName); - } - public static BankCard createBankCard(String month, String year, String cardholderName) { return new BankCard().setExpDate(createBankCardExpDate(month, year)).setCardholderName(cardholderName); } diff --git a/src/main/java/dev/vality/adapter/common/damsel/ProxyProviderPackageCreators.java b/src/main/java/dev/vality/adapter/common/damsel/ProxyProviderPackageCreators.java index 021ed2a..1f096f4 100644 --- a/src/main/java/dev/vality/adapter/common/damsel/ProxyProviderPackageCreators.java +++ b/src/main/java/dev/vality/adapter/common/damsel/ProxyProviderPackageCreators.java @@ -381,13 +381,6 @@ public class ProxyProviderPackageCreators { return BrowserHTTPRequest.get_request(new BrowserGetRequest(url)); } - @Deprecated - public static BankCard createBankCardWithToken(BankCard bankCard, - LegacyBankCardTokenProvider bankCardTokenProvider) { - bankCard.setTokenProviderDeprecated(bankCardTokenProvider); - return bankCard; - } - public static TransactionInfo extractTransactionInfo(PaymentContext context) { return context.getPaymentInfo().getPayment().getTrx(); } diff --git a/src/main/java/dev/vality/adapter/common/damsel/ProxyProviderPackageExtractors.java b/src/main/java/dev/vality/adapter/common/damsel/ProxyProviderPackageExtractors.java index c532ec4..aa22126 100644 --- a/src/main/java/dev/vality/adapter/common/damsel/ProxyProviderPackageExtractors.java +++ b/src/main/java/dev/vality/adapter/common/damsel/ProxyProviderPackageExtractors.java @@ -115,30 +115,6 @@ public class ProxyProviderPackageExtractors { return context.getPaymentInfo().getPayment().getTrx(); } - @Deprecated - public static LegacyBankCardPaymentSystem extractBankCardPaymentSystem(PaymentResource paymentResource) { - if (paymentResource.isSetDisposablePaymentResource()) { - return extractBankCardPaymentSystem(paymentResource.getDisposablePaymentResource()); - } - return extractBankCardPaymentSystem(paymentResource.getRecurrentPaymentResource()); - } - - @Deprecated - public static LegacyBankCardPaymentSystem extractBankCardPaymentSystem(PaymentContext context) { - return extractBankCardPaymentSystem(extractPaymentResource(context)); - } - - @Deprecated - public static LegacyBankCardPaymentSystem extractBankCardPaymentSystem(RecurrentPaymentResource paymentResource) { - return paymentResource.getPaymentTool().getBankCard().getPaymentSystemDeprecated(); - } - - @Deprecated - public static LegacyBankCardPaymentSystem extractBankCardPaymentSystem(DisposablePaymentResource paymentResource) { - return paymentResource.getPaymentTool().getBankCard().getPaymentSystemDeprecated(); - } - - public static String extractTargetInvoicePaymentStatus(PaymentContext paymentContext) { return extractTargetInvoicePaymentStatus(paymentContext.getSession().getTarget()); } @@ -165,26 +141,4 @@ public class ProxyProviderPackageExtractors { } throw new RuntimeException("Unknown Payment Resource"); } - - @Deprecated - public static LegacyBankCardTokenProvider extractBankCardTokenProvider(PaymentContext context) { - PaymentResource paymentResource = context.getPaymentInfo().getPayment().getPaymentResource(); - if (paymentResource.isSetDisposablePaymentResource()) { - PaymentTool paymentTool = paymentResource.getDisposablePaymentResource().getPaymentTool(); - if (paymentTool.isSetBankCard() && paymentTool.getBankCard().isSetTokenProviderDeprecated()) { - return paymentTool.getBankCard().getTokenProviderDeprecated(); - } - } - return null; - } - - @Deprecated - public static LegacyBankCardTokenProvider extractBankCardTokenProvider(RecurrentTokenContext context) { - PaymentTool paymentTool = context.getTokenInfo().getPaymentTool().getPaymentResource().getPaymentTool(); - if (paymentTool.isSetBankCard() && paymentTool.getBankCard().isSetTokenProviderDeprecated()) { - return paymentTool.getBankCard().getTokenProviderDeprecated(); - } - return null; - } - } diff --git a/src/main/java/dev/vality/adapter/common/mapper/ErrorMapping.java b/src/main/java/dev/vality/adapter/common/mapper/ErrorMapping.java index f1fcfdf..bc48d89 100644 --- a/src/main/java/dev/vality/adapter/common/mapper/ErrorMapping.java +++ b/src/main/java/dev/vality/adapter/common/mapper/ErrorMapping.java @@ -9,7 +9,8 @@ import dev.vality.adapter.common.mapper.model.Error; import dev.vality.adapter.common.mapper.model.MappingExceptions; import dev.vality.damsel.domain.Failure; import dev.vality.geck.serializer.kit.tbase.TErrorUtil; -import dev.vality.woody.api.flow.error.*; +import dev.vality.woody.api.flow.error.WUnavailableResultException; +import dev.vality.woody.api.flow.error.WUndefinedResultException; import java.io.IOException; import java.io.InputStream; @@ -78,7 +79,8 @@ public class ErrorMapping { private Error findError(String code, String description, String state) { return findErrorInConfig(code, description, state) - .orElseThrow(() -> getUnexpectedError(code, description, state)); + .orElseThrow(() -> new ErrorMappingException( + String.format("Error not found. Code %s, description %s, state %s", code, description, state))); } private Optional findErrorInConfig(String code, String description, String state) { @@ -128,17 +130,9 @@ public class ErrorMapping { throw new WUnavailableResultException( String.format("Unavailable result %s, code = %s, description = %s", error, code, description)); } else if (MappingExceptions.RESULT_UNEXPECTED.getMappingException().equals(error.getMapping())) { - throw getUnexpectedError(code, description, null); + throw new RuntimeException( + String.format("Unexpected error %s, code = %s, description = %s", error, code, description) + ); } } - - private WRuntimeException getUnexpectedError(String code, String description, String state) { - String errorMessage = String.format("Unexpected result, code = %s, description = %s, state = %s", - code, description, state); - - var errorDefinition = new WErrorDefinition(WErrorSource.INTERNAL); - errorDefinition.setErrorType(WErrorType.UNEXPECTED_ERROR); - errorDefinition.setErrorReason(errorMessage); - return new WRuntimeException(errorMessage, errorDefinition); - } } diff --git a/src/test/java/dev/vality/adapter/common/mapper/ErrorMappingTest.java b/src/test/java/dev/vality/adapter/common/mapper/ErrorMappingTest.java index b64af64..96a4017 100644 --- a/src/test/java/dev/vality/adapter/common/mapper/ErrorMappingTest.java +++ b/src/test/java/dev/vality/adapter/common/mapper/ErrorMappingTest.java @@ -1,7 +1,6 @@ package dev.vality.adapter.common.mapper; import dev.vality.adapter.common.mapper.model.Error; -import dev.vality.woody.api.flow.error.WRuntimeException; import org.junit.jupiter.api.Test; import java.util.List; @@ -21,8 +20,8 @@ public class ErrorMappingTest { error1.setCodeRegex("00002"); error1.setDescriptionRegex("Invalid Merchant Name"); var errorMapping = new ErrorMapping("'%s' - '%s'", List.of(error, error1)); - assertThrows(WRuntimeException.class, () -> errorMapping.mapFailure("unknown")); - assertThrows(WRuntimeException.class, () -> errorMapping.mapFailure("00001")); + assertThrows(RuntimeException.class, () -> errorMapping.mapFailure("unknown")); + assertThrows(RuntimeException.class, () -> errorMapping.mapFailure("00001")); var error2 = new Error(); error2.setMapping("authorization_failed:insufficient_funds"); @@ -40,7 +39,7 @@ public class ErrorMappingTest { error.setDescriptionRegex("desc"); error.setMapping("authorization_failed:unknown"); var errorMapping = new ErrorMapping("'%s' - '%s'", List.of(error)); - assertThrows(WRuntimeException.class, () -> errorMapping.mapFailure("01")); + assertThrows(RuntimeException.class, () -> errorMapping.mapFailure("01")); error.setDescriptionRegex(null); assertNotNull(errorMapping.mapFailure("01"));