public static <T> Pagination<T> build(final Long offset, final Long limit, final Collection<T> elements) { return build(offset, limit, elements.size(), elements); }
@Override public Pagination<Account> getAccounts(final Long offset, final Long limit, final TenantContext context) { return DefaultPagination.<Account>build(offset, limit, accounts); }
@Override public Pagination<M> get(final Long offset, final Long limit, final InternalTenantContext context) { return DefaultPagination.<M>build(offset, limit, ImmutableList.<M>copyOf(getAll(context))); }
@Test(groups = "fast", description = "Test Util: Pagination builder tests") public void testDefaultPaginationBuilder() throws Exception { Assert.assertEquals(DefaultPagination.<Integer>build(0L, 0L, ImmutableList.<Integer>of()), expectedOf(0L, 0L, 0L, ImmutableList.<Integer>of())); Assert.assertEquals(DefaultPagination.<Integer>build(0L, 10L, ImmutableList.<Integer>of()), expectedOf(0L, 0L, 0L, ImmutableList.<Integer>of())); Assert.assertEquals(DefaultPagination.<Integer>build(10L, 0L, ImmutableList.<Integer>of()), expectedOf(10L, 0L, 0L, ImmutableList.<Integer>of())); Assert.assertEquals(DefaultPagination.<Integer>build(10L, 10L, ImmutableList.<Integer>of()), expectedOf(10L, 0L, 0L, ImmutableList.<Integer>of())); Assert.assertEquals(DefaultPagination.<Integer>build(0L, 0L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(0L, 0L, 5L, ImmutableList.<Integer>of())); Assert.assertEquals(DefaultPagination.<Integer>build(0L, 10L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(0L, 5L, 5L, ImmutableList.<Integer>of(1, 2, 3, 4, 5))); Assert.assertEquals(DefaultPagination.<Integer>build(4L, 10L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(4L, 1L, 5L, ImmutableList.<Integer>of(5))); Assert.assertEquals(DefaultPagination.<Integer>build(0L, 3L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(0L, 3L, 5L, ImmutableList.<Integer>of(1, 2, 3))); Assert.assertEquals(DefaultPagination.<Integer>build(1L, 3L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(1L, 3L, 5L, ImmutableList.<Integer>of(2, 3, 4))); Assert.assertEquals(DefaultPagination.<Integer>build(2L, 3L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(2L, 3L, 5L, ImmutableList.<Integer>of(3, 4, 5))); Assert.assertEquals(DefaultPagination.<Integer>build(3L, 3L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(3L, 2L, 5L, ImmutableList.<Integer>of(4, 5))); Assert.assertEquals(DefaultPagination.<Integer>build(4L, 3L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(4L, 1L, 5L, ImmutableList.<Integer>of(5))); Assert.assertEquals(DefaultPagination.<Integer>build(5L, 3L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(5L, 0L, 5L, ImmutableList.<Integer>of())); }
@Override public Pagination<SubscriptionBundleModelDao> searchSubscriptionBundles(final String searchKey, final Long offset, final Long limit, final InternalTenantContext context) { final List<SubscriptionBundleModelDao> results = new LinkedList<SubscriptionBundleModelDao>(); int maxNbRecords = 0; for (final SubscriptionBundleModelDao bundleModelDao : getAll(context)) { maxNbRecords++; if (bundleModelDao.getId().toString().equals(searchKey) || bundleModelDao.getExternalKey().equals(searchKey) || bundleModelDao.getAccountId().toString().equals(searchKey)) { results.add(bundleModelDao); } } return DefaultPagination.<SubscriptionBundleModelDao>build(offset, limit, maxNbRecords, results); }
@Override public Pagination<Account> searchAccounts(final String searchKey, final Long offset, final Long limit, final TenantContext tenantContext) { final List<Account> results = new LinkedList<Account>(); for (final Account account : accounts) { if ((account.getName() != null && account.getName().contains(searchKey)) || (account.getEmail() != null && account.getEmail().contains(searchKey)) || (account.getExternalKey() != null && account.getExternalKey().contains(searchKey)) || (account.getCompanyName() != null && account.getCompanyName().contains(searchKey))) { results.add(account); } } return DefaultPagination.<Account>build(offset, limit, accounts.size(), results); }
@Override public Pagination<AccountModelDao> searchAccounts(final String searchKey, final Long offset, final Long limit, final InternalTenantContext context) { final Collection<AccountModelDao> results = new LinkedList<AccountModelDao>(); int maxNbRecords = 0; for (final AccountModelDao account : getAll(context)) { maxNbRecords++; if ((account.getName() != null && account.getName().contains(searchKey)) || (account.getEmail() != null && account.getEmail().contains(searchKey)) || (account.getExternalKey() != null && account.getExternalKey().contains(searchKey)) || (account.getCompanyName() != null && account.getCompanyName().contains(searchKey))) { results.add(account); } } return DefaultPagination.<AccountModelDao>build(offset, limit, maxNbRecords, results); }
public static <T> Pagination<T> build(final Long offset, final Long limit, final Collection<T> elements) { return build(offset, limit, elements.size(), elements); }
@Override public Pagination<Account> getAccounts(final Long offset, final Long limit, final TenantContext context) { return DefaultPagination.<Account>build(offset, limit, accounts); }
@Override public Pagination<M> get(final Long offset, final Long limit, final InternalTenantContext context) { return DefaultPagination.<M>build(offset, limit, ImmutableList.<M>copyOf(getAll(context))); }
@Test(groups = "fast", description = "Test Util: Pagination builder tests") public void testDefaultPaginationBuilder() throws Exception { Assert.assertEquals(DefaultPagination.<Integer>build(0L, 0L, ImmutableList.<Integer>of()), expectedOf(0L, 0L, 0L, ImmutableList.<Integer>of())); Assert.assertEquals(DefaultPagination.<Integer>build(0L, 10L, ImmutableList.<Integer>of()), expectedOf(0L, 0L, 0L, ImmutableList.<Integer>of())); Assert.assertEquals(DefaultPagination.<Integer>build(10L, 0L, ImmutableList.<Integer>of()), expectedOf(10L, 0L, 0L, ImmutableList.<Integer>of())); Assert.assertEquals(DefaultPagination.<Integer>build(10L, 10L, ImmutableList.<Integer>of()), expectedOf(10L, 0L, 0L, ImmutableList.<Integer>of())); Assert.assertEquals(DefaultPagination.<Integer>build(0L, 0L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(0L, 0L, 5L, ImmutableList.<Integer>of())); Assert.assertEquals(DefaultPagination.<Integer>build(0L, 10L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(0L, 5L, 5L, ImmutableList.<Integer>of(1, 2, 3, 4, 5))); Assert.assertEquals(DefaultPagination.<Integer>build(4L, 10L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(4L, 1L, 5L, ImmutableList.<Integer>of(5))); Assert.assertEquals(DefaultPagination.<Integer>build(0L, 3L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(0L, 3L, 5L, ImmutableList.<Integer>of(1, 2, 3))); Assert.assertEquals(DefaultPagination.<Integer>build(1L, 3L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(1L, 3L, 5L, ImmutableList.<Integer>of(2, 3, 4))); Assert.assertEquals(DefaultPagination.<Integer>build(2L, 3L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(2L, 3L, 5L, ImmutableList.<Integer>of(3, 4, 5))); Assert.assertEquals(DefaultPagination.<Integer>build(3L, 3L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(3L, 2L, 5L, ImmutableList.<Integer>of(4, 5))); Assert.assertEquals(DefaultPagination.<Integer>build(4L, 3L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(4L, 1L, 5L, ImmutableList.<Integer>of(5))); Assert.assertEquals(DefaultPagination.<Integer>build(5L, 3L, ImmutableList.<Integer>of(1, 2, 3, 4, 5)), expectedOf(5L, 0L, 5L, ImmutableList.<Integer>of())); }
@Override public Pagination<PaymentMethodPlugin> searchPaymentMethods(final String searchKey, final Long offset, final Long limit, final Iterable<PluginProperty> properties, final TenantContext tenantContext) throws PaymentPluginApiException { updateLastThreadState(); final ImmutableList<PaymentMethodPlugin> results = ImmutableList.<PaymentMethodPlugin>copyOf(Iterables.<PaymentMethodPlugin>filter(paymentMethods.values(), new Predicate<PaymentMethodPlugin>() { @Override public boolean apply(final PaymentMethodPlugin input) { if (input.getProperties() != null) { for (PluginProperty cur : input.getProperties()) { if (cur.getValue().equals(searchKey)) { return true; } } } return (input.getKbPaymentMethodId().toString().equals(searchKey)); } })); return DefaultPagination.<PaymentMethodPlugin>build(offset, limit, paymentMethods.size(), results); }
@Override public Pagination<PaymentTransactionInfoPlugin> searchPayments(final String searchKey, final Long offset, final Long limit, final Iterable<PluginProperty> properties, final TenantContext tenantContext) throws PaymentPluginApiException { updateLastThreadState(); final ImmutableList<PaymentTransactionInfoPlugin> results = ImmutableList.<PaymentTransactionInfoPlugin>copyOf(Iterables.<PaymentTransactionInfoPlugin>filter(Iterables.<PaymentTransactionInfoPlugin>concat(paymentTransactions.values()), new Predicate<PaymentTransactionInfoPlugin>() { @Override public boolean apply(final PaymentTransactionInfoPlugin input) { if (input.getProperties() != null) { for (final PluginProperty cur : input.getProperties()) { if (cur.getValue().equals(searchKey)) { return true; } } } return (input.getKbPaymentId().toString().equals(searchKey)); } })); return DefaultPagination.<PaymentTransactionInfoPlugin>build(offset, limit, paymentTransactions.size(), results); }
@Override public Pagination<SubscriptionBundleModelDao> searchSubscriptionBundles(final String searchKey, final Long offset, final Long limit, final InternalTenantContext context) { final List<SubscriptionBundleModelDao> results = new LinkedList<SubscriptionBundleModelDao>(); int maxNbRecords = 0; for (final SubscriptionBundleModelDao bundleModelDao : getAll(context)) { maxNbRecords++; if (bundleModelDao.getId().toString().equals(searchKey) || bundleModelDao.getExternalKey().equals(searchKey) || bundleModelDao.getAccountId().toString().equals(searchKey)) { results.add(bundleModelDao); } } return DefaultPagination.<SubscriptionBundleModelDao>build(offset, limit, maxNbRecords, results); }
@Override public Pagination<InvoiceModelDao> searchInvoices(final String searchKey, final Long offset, final Long limit, final InternalTenantContext context) { final List<InvoiceModelDao> results = new LinkedList<InvoiceModelDao>(); int maxNbRecords = 0; for (final InvoiceModelDao invoice : getAll(context)) { maxNbRecords++; if (invoice.getId().toString().equals(searchKey) || invoice.getAccountId().toString().equals(searchKey) || invoice.getInvoiceNumber().toString().equals(searchKey) || invoice.getCurrency().toString().equals(searchKey)) { results.add(invoice); } } return DefaultPagination.<InvoiceModelDao>build(offset, limit, maxNbRecords, results); }
@Override public Pagination<Account> searchAccounts(final String searchKey, final Long offset, final Long limit, final TenantContext tenantContext) { final List<Account> results = new LinkedList<Account>(); for (final Account account : accounts) { if ((account.getName() != null && account.getName().contains(searchKey)) || (account.getEmail() != null && account.getEmail().contains(searchKey)) || (account.getExternalKey() != null && account.getExternalKey().contains(searchKey)) || (account.getCompanyName() != null && account.getCompanyName().contains(searchKey))) { results.add(account); } } return DefaultPagination.<Account>build(offset, limit, accounts.size(), results); }