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());
}
Aggregations