Search in sources :

Example 1 with DefaultPagination

use of org.killbill.billing.util.entity.DefaultPagination in project killbill by killbill.

the class PaymentRefresher method searchPayments.

public Pagination<Payment> searchPayments(final String searchKey, final Long offset, final Long limit, final String pluginName, final boolean withPluginInfo, final boolean withAttempts, final boolean isApiPayment, final Iterable<PluginProperty> properties, final TenantContext tenantContext, final InternalTenantContext internalTenantContext) throws PaymentApiException {
    final PaymentPluginApi pluginApi = getPaymentPluginApi(pluginName);
    final Pagination<PaymentTransactionInfoPlugin> paymentTransactionInfoPlugins;
    try {
        paymentTransactionInfoPlugins = pluginApi.searchPayments(searchKey, offset, limit, properties, tenantContext);
    } catch (final PaymentPluginApiException e) {
        throw new PaymentApiException(e, ErrorCode.PAYMENT_PLUGIN_SEARCH_PAYMENTS, pluginName, searchKey);
    }
    // Cannot easily stream here unfortunately, since we need to merge PaymentTransactionInfoPlugin into Payment (no order assumed)
    final Multimap<UUID, PaymentTransactionInfoPlugin> payments = HashMultimap.<UUID, PaymentTransactionInfoPlugin>create();
    for (final PaymentTransactionInfoPlugin paymentTransactionInfoPlugin : paymentTransactionInfoPlugins) {
        if (paymentTransactionInfoPlugin.getKbPaymentId() == null) {
            // Garbage from the plugin?
            log.debug("Plugin {} returned a payment without a kbPaymentId for searchKey {}", pluginName, searchKey);
        } else {
            payments.put(paymentTransactionInfoPlugin.getKbPaymentId(), paymentTransactionInfoPlugin);
        }
    }
    final Collection<Payment> results = new LinkedList<Payment>();
    for (final UUID paymentId : payments.keys()) {
        final Payment result = toPayment(paymentId, withPluginInfo ? payments.get(paymentId) : ImmutableList.<PaymentTransactionInfoPlugin>of(), withAttempts, isApiPayment, internalTenantContext);
        if (result != null) {
            results.add(result);
        }
    }
    return new DefaultPagination<Payment>(paymentTransactionInfoPlugins, limit, results.iterator());
}
Also used : PaymentPluginApi(org.killbill.billing.payment.plugin.api.PaymentPluginApi) DefaultPayment(org.killbill.billing.payment.api.DefaultPayment) Payment(org.killbill.billing.payment.api.Payment) PaymentPluginApiException(org.killbill.billing.payment.plugin.api.PaymentPluginApiException) PaymentTransactionInfoPlugin(org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException) DefaultPagination(org.killbill.billing.util.entity.DefaultPagination) UUID(java.util.UUID) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 UUID (java.util.UUID)1 DefaultPayment (org.killbill.billing.payment.api.DefaultPayment)1 Payment (org.killbill.billing.payment.api.Payment)1 PaymentApiException (org.killbill.billing.payment.api.PaymentApiException)1 PaymentPluginApi (org.killbill.billing.payment.plugin.api.PaymentPluginApi)1 PaymentPluginApiException (org.killbill.billing.payment.plugin.api.PaymentPluginApiException)1 PaymentTransactionInfoPlugin (org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin)1 DefaultPagination (org.killbill.billing.util.entity.DefaultPagination)1