@Override public AuditLogsForInvoicePayments getAuditLogsForInvoicePayments( final List<InvoicePayment> invoicePayments, final AuditLevel auditLevel, final TenantContext context) { final Map<UUID, List<AuditLog>> invoicePaymentsAuditLogs = new HashMap<UUID, List<AuditLog>>(); for (final InvoicePayment invoicePayment : invoicePayments) { invoicePaymentsAuditLogs.put( invoicePayment.getId(), getAuditLogs(invoicePayment.getId(), ObjectType.INVOICE_PAYMENT, auditLevel, context)); } return new DefaultAuditLogsForInvoicePayments(invoicePaymentsAuditLogs); }
@GET @Path("/{accountId:" + UUID_PATTERN + "}/" + TIMELINE) @Produces(APPLICATION_JSON) public Response getAccountTimeline( @PathParam("accountId") final String accountIdString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, PaymentApiException, SubscriptionApiException { final TenantContext tenantContext = context.createContext(request); final UUID accountId = UUID.fromString(accountIdString); final Account account = accountUserApi.getAccountById(accountId, tenantContext); // Get the invoices final List<Invoice> invoices = invoiceApi.getInvoicesByAccount(account.getId(), tenantContext); final AuditLogsForInvoices invoicesAuditLogs = auditUserApi.getAuditLogsForInvoices(invoices, auditMode.getLevel(), tenantContext); // Get the payments final List<Payment> payments = paymentApi.getAccountPayments(accountId, tenantContext); final AuditLogsForPayments paymentsAuditLogs = auditUserApi.getAuditLogsForPayments(payments, auditMode.getLevel(), tenantContext); // Get the refunds final List<Refund> refunds = paymentApi.getAccountRefunds(account, tenantContext); final AuditLogsForRefunds refundsAuditLogs = auditUserApi.getAuditLogsForRefunds(refunds, auditMode.getLevel(), tenantContext); final Multimap<UUID, Refund> refundsByPayment = ArrayListMultimap.<UUID, Refund>create(); for (final Refund refund : refunds) { refundsByPayment.put(refund.getPaymentId(), refund); } // Get the chargebacks final List<InvoicePayment> chargebacks = invoicePaymentApi.getChargebacksByAccountId(accountId, tenantContext); final AuditLogsForInvoicePayments chargebacksAuditLogs = auditUserApi.getAuditLogsForInvoicePayments( chargebacks, auditMode.getLevel(), tenantContext); final Multimap<UUID, InvoicePayment> chargebacksByPayment = ArrayListMultimap.<UUID, InvoicePayment>create(); for (final InvoicePayment chargeback : chargebacks) { chargebacksByPayment.put(chargeback.getPaymentId(), chargeback); } // Get the bundles final List<SubscriptionBundle> bundles = subscriptionApi.getSubscriptionBundlesForAccountId(account.getId(), tenantContext); final AuditLogsForBundles bundlesAuditLogs = auditUserApi.getAuditLogsForBundles(bundles, auditMode.getLevel(), tenantContext); final AccountTimelineJson json = new AccountTimelineJson( account, invoices, payments, bundles, refundsByPayment, chargebacksByPayment, invoicesAuditLogs, paymentsAuditLogs, refundsAuditLogs, chargebacksAuditLogs, bundlesAuditLogs); return Response.status(Status.OK).entity(json).build(); }