add generic type (#32)

This commit is contained in:
Anatoly Karlov 2022-03-16 15:30:06 +07:00 committed by GitHub
parent 749ec26da1
commit 7051360868
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 30 deletions

View File

@ -41,10 +41,11 @@ public class PaymentMethodHandler extends AbstractDominantHandler<PaymentMethodO
.or(() -> PaymentMethodUtils.getPaymentMethodRefIdByPaymentTerminal(paymentMethod)) .or(() -> PaymentMethodUtils.getPaymentMethodRefIdByPaymentTerminal(paymentMethod))
.or(() -> PaymentMethodUtils.getPaymentMethodRefIdByDigitalWallet(paymentMethod)) .or(() -> PaymentMethodUtils.getPaymentMethodRefIdByDigitalWallet(paymentMethod))
.or(() -> PaymentMethodUtils.getPaymentMethodRefIdByCryptoCurrency(paymentMethod)) .or(() -> PaymentMethodUtils.getPaymentMethodRefIdByCryptoCurrency(paymentMethod))
.or(() -> PaymentMethodUtils.getPaymentMethodRefIdByMobile(paymentMethod)); .or(() -> PaymentMethodUtils.getPaymentMethodRefIdByMobile(paymentMethod))
.or(() -> PaymentMethodUtils.getPaymentMethodRefIdByGeneric(paymentMethod));
if (paymentMethodRefId.isEmpty()) { if (paymentMethodRefId.isEmpty()) {
throw new IllegalArgumentException("Unknown payment method: " + paymentMethod); throw new IllegalArgumentException("Unknown payment method: " + paymentMethod.get().get().getSetField());
} }
return getPaymentType(getTargetObject()) + SEPARATOR + paymentMethodRefId.get(); return getPaymentType(getTargetObject()) + SEPARATOR + paymentMethodRefId.get();

View File

@ -15,22 +15,22 @@ public class PaymentMethodUtils {
public static Optional<String> getPaymentMethodRefIdByBankCard( public static Optional<String> getPaymentMethodRefIdByBankCard(
Supplier<Optional<PaymentMethod>> paymentMethod) { Supplier<Optional<PaymentMethod>> paymentMethod) {
return paymentMethod.get() return paymentMethod.get()
.filter(dev.vality.damsel.domain.PaymentMethod::isSetBankCard) .filter(PaymentMethod::isSetBankCard)
.map(dev.vality.damsel.domain.PaymentMethod::getBankCard) .map(PaymentMethod::getBankCard)
.flatMap(bankCard -> PaymentSystemUtil.getPaymentSystemNameIfPresent( .flatMap(bankCard -> PaymentSystemUtil.getPaymentSystemNameIfPresent(
bankCard.getPaymentSystem(), bankCard.getPaymentSystem(),
bankCard.getPaymentSystemDeprecated())) bankCard.getPaymentSystemDeprecated()))
.or(() -> paymentMethod.get() .or(() -> paymentMethod.get()
.filter(dev.vality.damsel.domain.PaymentMethod::isSetBankCardDeprecated) .filter(PaymentMethod::isSetBankCardDeprecated)
.map(dev.vality.damsel.domain.PaymentMethod::getBankCardDeprecated) .map(PaymentMethod::getBankCardDeprecated)
.map(Enum::name)) .map(Enum::name))
.or(() -> paymentMethod.get() .or(() -> paymentMethod.get()
.filter(dev.vality.damsel.domain.PaymentMethod::isSetEmptyCvvBankCardDeprecated) .filter(PaymentMethod::isSetEmptyCvvBankCardDeprecated)
.map(dev.vality.damsel.domain.PaymentMethod::getEmptyCvvBankCardDeprecated) .map(PaymentMethod::getEmptyCvvBankCardDeprecated)
.map(legacyBankCardPaymentSystem -> EMPTY_CVV + legacyBankCardPaymentSystem.name())) .map(legacyBankCardPaymentSystem -> EMPTY_CVV + legacyBankCardPaymentSystem.name()))
.or(() -> paymentMethod.get() .or(() -> paymentMethod.get()
.filter(dev.vality.damsel.domain.PaymentMethod::isSetTokenizedBankCardDeprecated) .filter(PaymentMethod::isSetTokenizedBankCardDeprecated)
.map(dev.vality.damsel.domain.PaymentMethod::getTokenizedBankCardDeprecated) .map(PaymentMethod::getTokenizedBankCardDeprecated)
.flatMap(PaymentMethodUtils::getTokenizedBankCardId)); .flatMap(PaymentMethodUtils::getTokenizedBankCardId));
} }
@ -50,50 +50,59 @@ public class PaymentMethodUtils {
} }
public static Optional<String> getPaymentMethodRefIdByPaymentTerminal( public static Optional<String> getPaymentMethodRefIdByPaymentTerminal(
Supplier<Optional<dev.vality.damsel.domain.PaymentMethod>> paymentMethod) { Supplier<Optional<PaymentMethod>> paymentMethod) {
return paymentMethod.get() return paymentMethod.get()
.filter(dev.vality.damsel.domain.PaymentMethod::isSetPaymentTerminal) .filter(PaymentMethod::isSetPaymentTerminal)
.map(dev.vality.damsel.domain.PaymentMethod::getPaymentTerminal) .map(PaymentMethod::getPaymentTerminal)
.map(PaymentServiceRef::getId) .map(PaymentServiceRef::getId)
.or(() -> paymentMethod.get() .or(() -> paymentMethod.get()
.filter(dev.vality.damsel.domain.PaymentMethod::isSetPaymentTerminalDeprecated) .filter(PaymentMethod::isSetPaymentTerminalDeprecated)
.map(dev.vality.damsel.domain.PaymentMethod::getPaymentTerminalDeprecated) .map(PaymentMethod::getPaymentTerminalDeprecated)
.map(Enum::name)); .map(Enum::name));
} }
public static Optional<String> getPaymentMethodRefIdByDigitalWallet( public static Optional<String> getPaymentMethodRefIdByDigitalWallet(
Supplier<Optional<dev.vality.damsel.domain.PaymentMethod>> paymentMethod) { Supplier<Optional<PaymentMethod>> paymentMethod) {
return paymentMethod.get() return paymentMethod.get()
.filter(dev.vality.damsel.domain.PaymentMethod::isSetDigitalWallet) .filter(PaymentMethod::isSetDigitalWallet)
.map(dev.vality.damsel.domain.PaymentMethod::getDigitalWallet) .map(PaymentMethod::getDigitalWallet)
.map(PaymentServiceRef::getId) .map(PaymentServiceRef::getId)
.or(() -> paymentMethod.get() .or(() -> paymentMethod.get()
.filter(dev.vality.damsel.domain.PaymentMethod::isSetDigitalWalletDeprecated) .filter(PaymentMethod::isSetDigitalWalletDeprecated)
.map(dev.vality.damsel.domain.PaymentMethod::getDigitalWalletDeprecated) .map(PaymentMethod::getDigitalWalletDeprecated)
.map(Enum::name)); .map(Enum::name));
} }
public static Optional<String> getPaymentMethodRefIdByCryptoCurrency( public static Optional<String> getPaymentMethodRefIdByCryptoCurrency(
Supplier<Optional<dev.vality.damsel.domain.PaymentMethod>> paymentMethod) { Supplier<Optional<PaymentMethod>> paymentMethod) {
return paymentMethod.get() return paymentMethod.get()
.filter(dev.vality.damsel.domain.PaymentMethod::isSetCryptoCurrency) .filter(PaymentMethod::isSetCryptoCurrency)
.map(dev.vality.damsel.domain.PaymentMethod::getCryptoCurrency) .map(PaymentMethod::getCryptoCurrency)
.map(CryptoCurrencyRef::getId) .map(CryptoCurrencyRef::getId)
.or(() -> paymentMethod.get() .or(() -> paymentMethod.get()
.filter(dev.vality.damsel.domain.PaymentMethod::isSetCryptoCurrencyDeprecated) .filter(PaymentMethod::isSetCryptoCurrencyDeprecated)
.map(dev.vality.damsel.domain.PaymentMethod::getCryptoCurrencyDeprecated) .map(PaymentMethod::getCryptoCurrencyDeprecated)
.map(Enum::name)); .map(Enum::name));
} }
public static Optional<String> getPaymentMethodRefIdByMobile( public static Optional<String> getPaymentMethodRefIdByMobile(
Supplier<Optional<dev.vality.damsel.domain.PaymentMethod>> paymentMethod) { Supplier<Optional<PaymentMethod>> paymentMethod) {
return paymentMethod.get() return paymentMethod.get()
.filter(dev.vality.damsel.domain.PaymentMethod::isSetMobile) .filter(PaymentMethod::isSetMobile)
.map(dev.vality.damsel.domain.PaymentMethod::getMobile) .map(PaymentMethod::getMobile)
.map(MobileOperatorRef::getId) .map(MobileOperatorRef::getId)
.or(() -> paymentMethod.get() .or(() -> paymentMethod.get()
.filter(dev.vality.damsel.domain.PaymentMethod::isSetMobileDeprecated) .filter(PaymentMethod::isSetMobileDeprecated)
.map(dev.vality.damsel.domain.PaymentMethod::getMobileDeprecated) .map(PaymentMethod::getMobileDeprecated)
.map(Enum::name)); .map(Enum::name));
} }
public static Optional<String> getPaymentMethodRefIdByGeneric(
Supplier<Optional<PaymentMethod>> paymentMethod) {
return paymentMethod.get()
.filter(PaymentMethod::isSetGeneric)
.map(PaymentMethod::getGeneric)
.map(GenericPaymentMethod::getPaymentService)
.map(PaymentServiceRef::getId);
}
} }

View File

@ -0,0 +1,2 @@
ALTER TYPE nw.payment_method_type ADD VALUE 'generic';
ALTER TYPE nw.destination_resource_type ADD VALUE 'generic';