@GET @Produces(APPLICATION_JSON) public Response getAccountByKey(@QueryParam(QUERY_EXTERNAL_KEY) final String externalKey, @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.createContext(request); final Account account = accountUserApi.getAccountByKey(externalKey, tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext); final AccountJson accountJson = getAccount(account, accountWithBalance, accountWithBalanceAndCBA, accountAuditLogs, tenantContext); return Response.status(Status.OK).entity(accountJson).build(); }
@GET @Path("/{accountId:" + UUID_PATTERN + "}") @Produces(APPLICATION_JSON) public Response getAccount(@PathParam("accountId") final String accountId, @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.createContext(request); final Account account = accountUserApi.getAccountById(UUID.fromString(accountId), tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext); final AccountJson accountJson = getAccount(account, accountWithBalance, accountWithBalanceAndCBA, accountAuditLogs, tenantContext); return Response.status(Status.OK).entity(accountJson).build(); }
@Override public AccountJson apply(final Account account) { final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext); return getAccount(account, accountWithBalance, accountWithBalanceAndCBA, accountAuditLogs, tenantContext); } },
@GET @Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENT_METHODS) @Produces(APPLICATION_JSON) public Response getPaymentMethods(@PathParam("accountId") final String accountId, @QueryParam(QUERY_PAYMENT_METHOD_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, PaymentApiException { final TenantContext tenantContext = context.createContext(request); final Account account = accountUserApi.getAccountById(UUID.fromString(accountId), tenantContext); final List<PaymentMethod> methods = paymentApi.getPaymentMethods(account, withPluginInfo, tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext); final List<PaymentMethodJson> json = new ArrayList<PaymentMethodJson>(Collections2.transform(methods, new Function<PaymentMethod, PaymentMethodJson>() { @Override public PaymentMethodJson apply(final PaymentMethod input) { return PaymentMethodJson.toPaymentMethodJson(account, input, accountAuditLogs); } })); return Response.status(Status.OK).entity(json).build(); }
@Override public AccountJson apply(final Account account) { final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext); return getAccount(account, accountWithBalance, accountWithBalanceAndCBA, accountAuditLogs, tenantContext); } },
@GET @Path("/{paymentMethodId:" + UUID_PATTERN + "}") @Produces(APPLICATION_JSON) public Response getPaymentMethod(@PathParam("paymentMethodId") final String paymentMethodId, @QueryParam(QUERY_PAYMENT_METHOD_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, PaymentApiException { final TenantContext tenantContext = context.createContext(request); final PaymentMethod paymentMethod = paymentApi.getPaymentMethodById(UUID.fromString(paymentMethodId), false, withPluginInfo, tenantContext); final Account account = accountUserApi.getAccountById(paymentMethod.getAccountId(), tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(paymentMethod.getAccountId(), auditMode.getLevel(), tenantContext); final PaymentMethodJson json = PaymentMethodJson.toPaymentMethodJson(account, paymentMethod, accountAuditLogs); return Response.status(Status.OK).entity(json).build(); }
@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, accountsAuditLogs.get().get(invoice.getAccountId())); } },
@GET @Path("/{invoiceId:" + UUID_PATTERN + "}/") @Produces(APPLICATION_JSON) public Response getInvoice(@PathParam("invoiceId") final String invoiceId, @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.createContext(request); final Invoice invoice = invoiceApi.getInvoice(UUID.fromString(invoiceId), tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(invoice.getAccountId(), auditMode.getLevel(), tenantContext); if (invoice == null) { throw new InvoiceApiException(ErrorCode.INVOICE_NOT_FOUND, invoiceId); } else { final InvoiceJson json = new InvoiceJson(invoice, withItems, accountAuditLogs); return Response.status(Status.OK).entity(json).build(); } }
@Override public BundleJson apply(final SubscriptionBundle bundle) { // Cache audit logs per account if (accountsAuditLogs.get().get(bundle.getAccountId()) == null) { accountsAuditLogs.get().put(bundle.getAccountId(), auditUserApi.getAccountAuditLogs(bundle.getAccountId(), auditMode.getLevel(), tenantContext)); } return new BundleJson(bundle, accountsAuditLogs.get().get(bundle.getAccountId())); } },
@GET @Path("/{invoiceNumber:" + NUMBER_PATTERN + "}/") @Produces(APPLICATION_JSON) public Response getInvoiceByNumber(@PathParam("invoiceNumber") final Integer invoiceNumber, @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.createContext(request); final Invoice invoice = invoiceApi.getInvoiceByNumber(invoiceNumber, tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(invoice.getAccountId(), auditMode.getLevel(), tenantContext); if (invoice == null) { throw new InvoiceApiException(ErrorCode.INVOICE_NOT_FOUND, invoiceNumber); } else { final InvoiceJson json = new InvoiceJson(invoice, withItems, accountAuditLogs); return Response.status(Status.OK).entity(json).build(); } }
@Override public BundleJson apply(final SubscriptionBundle bundle) { // Cache audit logs per account if (accountsAuditLogs.get().get(bundle.getAccountId()) == null) { accountsAuditLogs.get().put(bundle.getAccountId(), auditUserApi.getAccountAuditLogs(bundle.getAccountId(), auditMode.getLevel(), tenantContext)); } return new BundleJson(bundle, accountsAuditLogs.get().get(bundle.getAccountId())); } },
@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, accountsAuditLogs.get().get(invoice.getAccountId())); } },
@GET @Path("/{invoiceId:" + UUID_PATTERN + "}/" + PAYMENTS) @Produces(APPLICATION_JSON) public Response getPayments(@PathParam("invoiceId") final String invoiceId, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException { final TenantContext tenantContext = context.createContext(request); final List<Payment> payments = paymentApi.getInvoicePayments(UUID.fromString(invoiceId), tenantContext); final List<PaymentJson> result = new ArrayList<PaymentJson>(payments.size()); if (payments.size() == 0) { return Response.status(Status.OK).entity(result).build(); } final AccountAuditLogsForObjectType auditLogsForPayments = auditUserApi.getAccountAuditLogs(payments.get(0).getAccountId(), ObjectType.PAYMENT, auditMode.getLevel(), tenantContext); for (final Payment cur : payments) { result.add(new PaymentJson(cur, auditLogsForPayments.getAuditLogs(cur.getId()))); } return Response.status(Status.OK).entity(result).build(); }
@Override public PaymentJson apply(final Payment payment) { // Cache audit logs per account if (accountsAuditLogs.get().get(payment.getAccountId()) == null) { accountsAuditLogs.get().put(payment.getAccountId(), auditUserApi.getAccountAuditLogs(payment.getAccountId(), auditMode.getLevel(), tenantContext)); } return new PaymentJson(payment, accountsAuditLogs.get().get(payment.getAccountId()).getAuditLogsForPayment(payment.getId())); } },
@Override public PaymentJson apply(final Payment payment) { // Cache audit logs per account if (accountsAuditLogs.get().get(payment.getAccountId()) == null) { accountsAuditLogs.get().put(payment.getAccountId(), auditUserApi.getAccountAuditLogs(payment.getAccountId(), auditMode.getLevel(), tenantContext)); } return new PaymentJson(payment, accountsAuditLogs.get().get(payment.getAccountId()).getAuditLogsForPayment(payment.getId())); } },
protected Response getTags(final UUID accountId, final UUID taggedObjectId, final AuditMode auditMode, final boolean includeDeleted, final TenantContext context) throws TagDefinitionApiException { final List<Tag> tags = tagUserApi.getTagsForObject(taggedObjectId, getObjectType(), includeDeleted, context); final AccountAuditLogsForObjectType tagsAuditLogs = auditUserApi.getAccountAuditLogs(accountId, ObjectType.TAG, auditMode.getLevel(), context); final Map<UUID, TagDefinition> tagDefinitionsCache = new HashMap<UUID, TagDefinition>(); final Collection<TagJson> result = new LinkedList<TagJson>(); for (final Tag tag : tags) { if (tagDefinitionsCache.get(tag.getTagDefinitionId()) == null) { tagDefinitionsCache.put(tag.getTagDefinitionId(), tagUserApi.getTagDefinition(tag.getTagDefinitionId(), context)); } final TagDefinition tagDefinition = tagDefinitionsCache.get(tag.getTagDefinitionId()); final List<AuditLog> auditLogs = tagsAuditLogs.getAuditLogs(tag.getId()); result.add(new TagJson(tag, tagDefinition, auditLogs)); } return Response.status(Response.Status.OK).entity(result).build(); }
@Override public PaymentMethodJson apply(final PaymentMethod paymentMethod) { // Cache audit logs per account if (accountsAuditLogs.get().get(paymentMethod.getAccountId()) == null) { accountsAuditLogs.get().put(paymentMethod.getAccountId(), auditUserApi.getAccountAuditLogs(paymentMethod.getAccountId(), auditMode.getLevel(), tenantContext)); } // Lookup the associated account(s) if (accounts.get(paymentMethod.getAccountId()) == null) { final Account account; try { account = accountUserApi.getAccountById(paymentMethod.getAccountId(), tenantContext); accounts.put(paymentMethod.getAccountId(), account); } catch (final AccountApiException e) { log.warn("Unable to retrieve account", e); return null; } } return PaymentMethodJson.toPaymentMethodJson(accounts.get(paymentMethod.getAccountId()), paymentMethod, accountsAuditLogs.get().get(paymentMethod.getAccountId())); } },
@Override public PaymentMethodJson apply(final PaymentMethod paymentMethod) { // Cache audit logs per account if (accountsAuditLogs.get().get(paymentMethod.getAccountId()) == null) { accountsAuditLogs.get().put(paymentMethod.getAccountId(), auditUserApi.getAccountAuditLogs(paymentMethod.getAccountId(), auditMode.getLevel(), tenantContext)); } // Lookup the associated account(s) if (accounts.get(paymentMethod.getAccountId()) == null) { final Account account; try { account = accountUserApi.getAccountById(paymentMethod.getAccountId(), tenantContext); accounts.put(paymentMethod.getAccountId(), account); } catch (final AccountApiException e) { log.warn("Unable to retrieve account", e); return null; } } return PaymentMethodJson.toPaymentMethodJson(accounts.get(paymentMethod.getAccountId()), paymentMethod, accountsAuditLogs.get().get(paymentMethod.getAccountId())); } },
@Override public RefundJson apply(final Refund refund) { UUID kbAccountId = null; if (!AuditLevel.NONE.equals(auditMode.getLevel()) && paymentIdAccountIdMappings.get(refund.getPaymentId()) == null) { try { kbAccountId = paymentApi.getPayment(refund.getPaymentId(), false, tenantContext).getAccountId(); paymentIdAccountIdMappings.put(refund.getPaymentId(), kbAccountId); } catch (final PaymentApiException e) { log.warn("Unable to retrieve payment for id " + refund.getPaymentId()); } } // Cache audit logs per account if (accountsAuditLogs.get().get(kbAccountId) == null) { accountsAuditLogs.get().put(kbAccountId, auditUserApi.getAccountAuditLogs(kbAccountId, auditMode.getLevel(), tenantContext)); } final List<AuditLog> auditLogs = accountsAuditLogs.get().get(kbAccountId) == null ? null : accountsAuditLogs.get().get(kbAccountId).getAuditLogsForRefund(refund.getId()); return new RefundJson(refund, null, auditLogs); } },
@Override public RefundJson apply(final Refund refund) { UUID kbAccountId = null; if (!AuditLevel.NONE.equals(auditMode.getLevel()) && paymentIdAccountIdMappings.get(refund.getPaymentId()) == null) { try { kbAccountId = paymentApi.getPayment(refund.getPaymentId(), false, tenantContext).getAccountId(); paymentIdAccountIdMappings.put(refund.getPaymentId(), kbAccountId); } catch (final PaymentApiException e) { log.warn("Unable to retrieve payment for id " + refund.getPaymentId()); } } // Cache audit logs per account if (accountsAuditLogs.get().get(kbAccountId) == null) { accountsAuditLogs.get().put(kbAccountId, auditUserApi.getAccountAuditLogs(kbAccountId, auditMode.getLevel(), tenantContext)); } final List<AuditLog> auditLogs = accountsAuditLogs.get().get(kbAccountId) == null ? null : accountsAuditLogs.get().get(kbAccountId).getAuditLogsForRefund(refund.getId()); return new RefundJson(refund, null, auditLogs); } },