Assert.assertNull(search1.getNextOffset()); Assert.assertEquals(search1.getMaxNbRecords(), (Long) 2L); Assert.assertEquals(search1.getTotalNbRecords(), (Long) 2L); Assert.assertEquals(search2.getNextOffset(), (Long) 1L); Assert.assertEquals(search2.getMaxNbRecords(), (Long) 2L); Assert.assertEquals(search2.getTotalNbRecords(), (Long) 2L); Assert.assertNull(search3.getNextOffset()); Assert.assertEquals(search3.getMaxNbRecords(), (Long) 2L); Assert.assertEquals(search3.getTotalNbRecords(), (Long) 1L); Assert.assertNull(search4.getNextOffset()); Assert.assertNull(search5.getNextOffset());
@TimedResource @GET @Path("/" + PAGINATION) @Produces(APPLICATION_JSON) @ApiOperation(value = "List accounts", response = AccountJson.class, responseContainer = "List") @ApiResponses(value = {}) public Response getAccounts(@QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_ACCOUNT_WITH_BALANCE) @DefaultValue("false") final Boolean accountWithBalance, @QueryParam(QUERY_ACCOUNT_WITH_BALANCE_AND_CBA) @DefaultValue("false") final Boolean accountWithBalanceAndCBA, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException { final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Pagination<Account> accounts = accountUserApi.getAccounts(offset, limit, tenantContext); final URI nextPageUri = uriBuilder.nextPage(AccountResource.class, "getAccounts", accounts.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_ACCOUNT_WITH_BALANCE, accountWithBalance.toString(), QUERY_ACCOUNT_WITH_BALANCE_AND_CBA, accountWithBalanceAndCBA.toString(), QUERY_AUDIT, auditMode.getLevel().toString())); return buildStreamingPaginationResponse(accounts, new Function<Account, AccountJson>() { @Override public AccountJson apply(final Account account) { final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext); return getAccount(account, accountWithBalance, accountWithBalanceAndCBA, accountAuditLogs, tenantContext); } }, nextPageUri ); }
@TimedResource @GET @Path("/" + SEARCH + "/{searchKey:" + ANYTHING_PATTERN + "}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Search accounts", response = AccountJson.class, responseContainer = "List") @ApiResponses(value = {}) public Response searchAccounts(@PathParam("searchKey") final String searchKey, @QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_ACCOUNT_WITH_BALANCE) @DefaultValue("false") final Boolean accountWithBalance, @QueryParam(QUERY_ACCOUNT_WITH_BALANCE_AND_CBA) @DefaultValue("false") final Boolean accountWithBalanceAndCBA, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException { final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Pagination<Account> accounts = accountUserApi.searchAccounts(searchKey, offset, limit, tenantContext); final URI nextPageUri = uriBuilder.nextPage(AccountResource.class, "searchAccounts", accounts.getNextOffset(), limit, ImmutableMap.<String, String>of("searchKey", searchKey, QUERY_ACCOUNT_WITH_BALANCE, accountWithBalance.toString(), QUERY_ACCOUNT_WITH_BALANCE_AND_CBA, accountWithBalanceAndCBA.toString(), QUERY_AUDIT, auditMode.getLevel().toString())); return buildStreamingPaginationResponse(accounts, new Function<Account, AccountJson>() { @Override public AccountJson apply(final Account account) { final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext); return getAccount(account, accountWithBalance, accountWithBalanceAndCBA, accountAuditLogs, tenantContext); } }, nextPageUri ); }
.entity(json) .header(HDR_PAGINATION_CURRENT_OFFSET, entities.getCurrentOffset()) .header(HDR_PAGINATION_NEXT_OFFSET, entities.getNextOffset()) .header(HDR_PAGINATION_TOTAL_NB_RECORDS, entities.getTotalNbRecords()) .header(HDR_PAGINATION_MAX_NB_RECORDS, entities.getMaxNbRecords())
final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Pagination<Invoice> invoices = invoiceApi.searchInvoices(searchKey, offset, limit, tenantContext); final URI nextPageUri = uriBuilder.nextPage(InvoiceResource.class, "searchInvoices", invoices.getNextOffset(), limit, ImmutableMap.<String, String>of("searchKey", searchKey, QUERY_INVOICE_WITH_ITEMS, withItems.toString(), QUERY_AUDIT, auditMode.getLevel().toString()));
@TimedResource @GET @Path("/" + PAGINATION) @Produces(APPLICATION_JSON) @ApiOperation(value = "List custom fields", response = CustomFieldJson.class, responseContainer = "List") @ApiResponses(value = {}) public Response getCustomFields(@QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws CustomFieldApiException { final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Pagination<CustomField> customFields = customFieldUserApi.getCustomFields(offset, limit, tenantContext); final URI nextPageUri = uriBuilder.nextPage(CustomFieldResource.class, "getCustomFields", customFields.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_AUDIT, auditMode.getLevel().toString())); return buildStreamingPaginationResponse(customFields, new Function<CustomField, CustomFieldJson>() { @Override public CustomFieldJson apply(final CustomField customField) { // TODO Really slow - we should instead try to figure out the account id final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(customField.getId(), ObjectType.CUSTOM_FIELD, auditMode.getLevel(), tenantContext); return new CustomFieldJson(customField, auditLogs); } }, nextPageUri); }
@TimedResource @GET @Path("/" + SEARCH + "/{searchKey:" + ANYTHING_PATTERN + "}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Search custom fields", response = CustomFieldJson.class, responseContainer = "List") @ApiResponses(value = {}) public Response searchCustomFields(@PathParam("searchKey") final String searchKey, @QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws CustomFieldApiException { final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Pagination<CustomField> customFields = customFieldUserApi.searchCustomFields(searchKey, offset, limit, tenantContext); final URI nextPageUri = uriBuilder.nextPage(CustomFieldResource.class, "searchCustomFields", customFields.getNextOffset(), limit, ImmutableMap.<String, String>of("searchKey", searchKey, QUERY_AUDIT, auditMode.getLevel().toString())); return buildStreamingPaginationResponse(customFields, new Function<CustomField, CustomFieldJson>() { @Override public CustomFieldJson apply(final CustomField customField) { // TODO Really slow - we should instead try to figure out the account id final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(customField.getId(), ObjectType.CUSTOM_FIELD, auditMode.getLevel(), tenantContext); return new CustomFieldJson(customField, auditLogs); } }, nextPageUri); }
@TimedResource @GET @Path("/" + PAGINATION) @Produces(APPLICATION_JSON) @ApiOperation(value = "List invoices", response = InvoiceJson.class, responseContainer = "List") @ApiResponses(value = {}) public Response getInvoices(@QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_INVOICE_WITH_ITEMS) @DefaultValue("false") final Boolean withItems, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws InvoiceApiException { final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Pagination<Invoice> invoices = invoiceApi.getInvoices(offset, limit, tenantContext); final URI nextPageUri = uriBuilder.nextPage(InvoiceResource.class, "getInvoices", invoices.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_INVOICE_WITH_ITEMS, withItems.toString(), QUERY_AUDIT, auditMode.getLevel().toString())); final AtomicReference<Map<UUID, AccountAuditLogs>> accountsAuditLogs = new AtomicReference<Map<UUID, AccountAuditLogs>>(new HashMap<UUID, AccountAuditLogs>()); return buildStreamingPaginationResponse(invoices, new Function<Invoice, InvoiceJson>() { @Override public InvoiceJson apply(final Invoice invoice) { // Cache audit logs per account if (accountsAuditLogs.get().get(invoice.getAccountId()) == null) { accountsAuditLogs.get().put(invoice.getAccountId(), auditUserApi.getAccountAuditLogs(invoice.getAccountId(), auditMode.getLevel(), tenantContext)); } return new InvoiceJson(invoice, withItems, null, accountsAuditLogs.get().get(invoice.getAccountId())); } }, nextPageUri ); }
final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Pagination<SubscriptionBundle> bundles = subscriptionApi.getSubscriptionBundles(offset, limit, tenantContext); final URI nextPageUri = uriBuilder.nextPage(BundleResource.class, "getBundles", bundles.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_AUDIT, auditMode.getLevel().toString())); final AtomicReference<Map<UUID, AccountAuditLogs>> accountsAuditLogs = new AtomicReference<Map<UUID, AccountAuditLogs>>(new HashMap<UUID, AccountAuditLogs>()); return buildStreamingPaginationResponse(bundles,
final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Pagination<SubscriptionBundle> bundles = subscriptionApi.searchSubscriptionBundles(searchKey, offset, limit, tenantContext); final URI nextPageUri = uriBuilder.nextPage(BundleResource.class, "searchBundles", bundles.getNextOffset(), limit, ImmutableMap.<String, String>of("searchKey", searchKey, QUERY_AUDIT, auditMode.getLevel().toString())); final AtomicReference<Map<UUID, AccountAuditLogs>> accountsAuditLogs = new AtomicReference<Map<UUID, AccountAuditLogs>>(new HashMap<UUID, AccountAuditLogs>());
tags.getNextOffset(), limit, ImmutableMap.<String, String>of()); .entity(json) .header(HDR_PAGINATION_CURRENT_OFFSET, tags.getCurrentOffset()) .header(HDR_PAGINATION_NEXT_OFFSET, tags.getNextOffset()) .header(HDR_PAGINATION_TOTAL_NB_RECORDS, tags.getTotalNbRecords()) .header(HDR_PAGINATION_MAX_NB_RECORDS, tags.getMaxNbRecords())
final URI nextPageUri = uriBuilder.nextPage(PaymentResource.class, "getPayments", payments.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_PAYMENT_METHOD_PLUGIN_NAME, Strings.nullToEmpty(pluginName), QUERY_AUDIT, auditMode.getLevel().toString())); final AtomicReference<Map<UUID, AccountAuditLogs>> accountsAuditLogs = new AtomicReference<Map<UUID, AccountAuditLogs>>(new HashMap<UUID, AccountAuditLogs>());
final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Pagination<Tag> tags = tagUserApi.searchTags(searchKey, offset, limit, tenantContext); final URI nextPageUri = uriBuilder.nextPage(TagResource.class, "searchTags", tags.getNextOffset(), limit, ImmutableMap.<String, String>of("searchKey", searchKey, QUERY_AUDIT, auditMode.getLevel().toString())); final Map<UUID, TagDefinition> tagDefinitionsCache = new HashMap<UUID, TagDefinition>();
final URI nextPageUri = uriBuilder.nextPage(PaymentResource.class, "searchPayments", payments.getNextOffset(), limit, ImmutableMap.<String, String>of("searchKey", searchKey, QUERY_PAYMENT_METHOD_PLUGIN_NAME, Strings.nullToEmpty(pluginName), QUERY_AUDIT, auditMode.getLevel().toString()));
@TimedResource @GET @Path("/" + PAGINATION) @Produces(APPLICATION_JSON) @ApiOperation(value = "List tags", response = TagJson.class, responseContainer = "List") @ApiResponses(value = {}) public Response getTags(@QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagApiException { final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Pagination<Tag> tags = tagUserApi.getTags(offset, limit, tenantContext); final URI nextPageUri = uriBuilder.nextPage(TagResource.class, "getTags", tags.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_AUDIT, auditMode.getLevel().toString())); final Map<UUID, TagDefinition> tagDefinitionsCache = new HashMap<UUID, TagDefinition>(); for (final TagDefinition tagDefinition : tagUserApi.getTagDefinitions(tenantContext)) { tagDefinitionsCache.put(tagDefinition.getId(), tagDefinition); } return buildStreamingPaginationResponse(tags, new Function<Tag, TagJson>() { @Override public TagJson apply(final Tag tag) { final TagDefinition tagDefinition = tagDefinitionsCache.get(tag.getTagDefinitionId()); // TODO Really slow - we should instead try to figure out the account id final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(tag.getId(), ObjectType.TAG, auditMode.getLevel(), tenantContext); return new TagJson(tag, tagDefinition, auditLogs); } }, nextPageUri); }
final URI nextPageUri = uriBuilder.nextPage(PaymentMethodResource.class, "getPaymentMethods", paymentMethods.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_PAYMENT_METHOD_PLUGIN_NAME, Strings.nullToEmpty(pluginName), QUERY_AUDIT, auditMode.getLevel().toString()));
final URI nextPageUri = uriBuilder.nextPage(PaymentMethodResource.class, "searchPaymentMethods", paymentMethods.getNextOffset(), limit, ImmutableMap.<String, String>of("searchKey", searchKey, QUERY_PAYMENT_METHOD_PLUGIN_NAME, Strings.nullToEmpty(pluginName), QUERY_AUDIT, auditMode.getLevel().toString()));