/**
   * Retrieves list of <code>OrderPayment</code>s associated with the specified gift certificate
   * grouped by their shipments.
   *
   * @param uidPk GiftCertificate uid.
   * @return map of shipments to their payments.
   */
  public Map<Order, Money> retrieveOrdersBalances(final long uidPk) {
    sanityCheck();

    final Map<Order, Money> ordersBalance =
        new TreeMap<Order, Money>(
            new Comparator<Order>() {
              public int compare(final Order order1, final Order order2) {
                return order1.getCreatedDate().compareTo(order2.getCreatedDate());
              }
            });

    List<Order> orders =
        getPersistenceEngine().retrieveByNamedQuery("ORDERS_BY_GIFT_CERTIFICATE", uidPk);
    for (Order order : orders) {
      List<GiftCertificateTransaction> transactions =
          getPersistenceEngine()
              .retrieveByNamedQuery(
                  "GIFT_CERTIFICATE_TRANSACTIONS_BY_ORDER_AND_GIFT_CERTIFICATE",
                  uidPk,
                  PaymentType.GIFT_CERTIFICATE,
                  order.getUidPk());
      BigDecimal amount =
          getGiftCertificateTransactionService().calcTransactionBalance(transactions);
      Money money = MoneyFactory.createMoney(amount, order.getCurrency());
      ordersBalance.put(order, money);
    }

    return ordersBalance;
  }
 private OrderEvent getSingleOrderEventFromOrder(final Order order) {
   Set<OrderEvent> orderEvents = order.getOrderEvents();
   assertEquals("Only one order event should be added.", 1, orderEvents.size());
   return orderEvents.iterator().next();
 }
 private Order createBlankOrderWithLocale() {
   Order order = new OrderImpl();
   order.setLocale(Locale.US);
   return order;
 }