public RefundJson(final Refund refund, @Nullable final List<InvoiceItem> adjustments, @Nullable final List<AuditLog> auditLogs) { this(refund.getId().toString(), refund.getPaymentId().toString(), refund.getRefundAmount(), refund.getCurrency().toString(), refund.getRefundStatus().toString(), refund.isAdjusted(), refund.getEffectiveDate(), refund.getEffectiveDate(), adjustments == null ? null : ImmutableList.<InvoiceItemJson>copyOf(Collections2.transform(adjustments, new Function<InvoiceItem, InvoiceItemJson>() { @Override public InvoiceItemJson apply(@Nullable final InvoiceItem input) { return new InvoiceItemJson(input); } })), toAuditLogJson(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); } },
@GET @Path("/{refundId:" + UUID_PATTERN + "}") @Produces(APPLICATION_JSON) public Response getRefund(@PathParam("refundId") final String refundId, @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 Refund refund = paymentApi.getRefund(UUID.fromString(refundId), false, tenantContext); final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(refund.getId(), ObjectType.REFUND, auditMode.getLevel(), tenantContext); // TODO Return adjusted items return Response.status(Status.OK).entity(new RefundJson(refund, null, auditLogs)).build(); }
final Multimap<UUID, Refund> refundsByPayment = ArrayListMultimap.<UUID, Refund>create(); for (final Refund refund : refunds) { refundsByPayment.put(refund.getPaymentId(), refund);
@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); } },
return uriBuilder.buildResponse(RefundResource.class, "getRefund", result.getId(), uriInfo.getBaseUri().toString());
final List<RefundJson> refunds = new ArrayList<RefundJson>(); for (final Refund refund : refundsByPayment.get(payment.getId())) { final List<AuditLog> auditLogs = accountAuditLogs.getAuditLogsForRefund(refund.getId());