Package com.wesabe.xmlson

Examples of com.wesabe.xmlson.XmlsonObject


      assertThat(representation.getString("uri"), is("/account-groups/checking"));
    }
   
    @Test
    public void itHasTheGroupsAccountsAsReferences() throws Exception {
      final XmlsonObject representation = presenter.present(group, USD, Locale.KOREA);
     
      final XmlsonArray accounts = (XmlsonArray) representation.get("accounts");
      assertThat(accounts.getMembers().size(), is(1));
     
      final XmlsonObject account = (XmlsonObject) accounts.getMembers().get(0);
      assertThat(account.getString("uri"), is("/accounts/20"));
    }
View Full Code Here


    @Test
    public void itDoesListATotalIfAnAccountHasABalance() throws Exception {
      when(account.hasBalance()).thenReturn(true);
      when(accountList.getTotal(USD, exchangeRateMap)).thenReturn(money("345.12", USD));
     
      final XmlsonObject representation = presenter.present(group, USD, Locale.KOREA);
     
      final XmlsonObject total = (XmlsonObject) representation.get("total");
      assertThat(total.getString("display"), is("US$345.12"));
      assertThat(total.getString("value"), is("345.12"));
    }
View Full Code Here

    super(moneyPresenter, financialInstPresenter);
    this.investmentPositionPresenter = investmentPositionPresenter;
  }

  public XmlsonObject present(InvestmentAccount account, Locale locale) {
    final XmlsonObject result = super.present(account, locale);
    final XmlsonArray positions = new XmlsonArray("investment-positions");
    for (InvestmentPosition position : account.getCurrentInvestmentPositions()) {
      positions.add(investmentPositionPresenter.present(position, locale));
    }
    result.add(positions);
   
    result.add(moneyPresenter.present("market-value", account.getMarketValue(), locale));
   
    final InvestmentAccountBalance balance = account.getCurrentInvestmentAccountBalance();
    final String nodeName = "investment-balance";
    if (balance != null) {
      final XmlsonObject balanceNode = new XmlsonObject(nodeName);
      if (balance.getAvailableCash() != null) {
        balanceNode.add(moneyPresenter.present("available-cash", balance.getAvailableCash(), locale));
      }
      if (balance.getMarginBalance() != null) {
        balanceNode.add(moneyPresenter.present("margin-balance", balance.getMarginBalance(), locale));
      }
      if (balance.getShortBalance() != null) {
        balanceNode.add(moneyPresenter.present("short-balance", balance.getShortBalance(), locale));
      }
      if (balance.getBuyingPower() != null) {
        balanceNode.add(moneyPresenter.present("buying-power", balance.getBuyingPower(), locale));
      }
      result.add(balanceNode);
    } else {
      result.addNullProperty(nodeName);
    }
View Full Code Here

*
*/
public class AccountReferencePresenter {
  public XmlsonObject present(Account account) {
    // REVIEW coda@wesabe.com -- May 21, 2009: Replace account URI building once AccountResource is written
    final XmlsonObject root = new XmlsonObject("account");
    root.addProperty("uri", String.format("/accounts/%d", account.getRelativeId()));
    return root;
  }
View Full Code Here

*/
public class FinancialInstPresenter {
  public FinancialInstPresenter() {}

  public XmlsonObject present(FinancialInst financialInst) {
    final XmlsonObject result = new XmlsonObject("financial-institution");
    result.addProperty("name", financialInst.getName());
    result.addProperty("id", financialInst.getWesabeId());
    return result;
  }
View Full Code Here

  public InvestmentTxactionListPresenter(MoneyPresenter moneyPresenter, InvestmentTxactionPresenter investmentTxactionPresenter) {
    this.investmentTxactionPresenter = investmentTxactionPresenter;
  }

  public XmlsonObject present(InvestmentTxactionList investmentTxactions, Locale locale) {
    final XmlsonObject root = new XmlsonObject("investment-transaction-list");

    root.add(new XmlsonObject("count").addProperty("total", investmentTxactions.getTotalCount()));

    final XmlsonArray list = new XmlsonArray("investment-transactions");
    for (InvestmentTxactionListItem item : investmentTxactions) {
      final XmlsonObject investmentTxaction = investmentTxactionPresenter.present(item.getInvestmentTxaction(), locale);
      list.add(investmentTxaction);
    }
    root.add(list);

    return root;
View Full Code Here

  public IntervalSummaryPresenter(SumOfMoneyPresenter moneyPresenter) {
    this.sumOfMoneyPresenter = moneyPresenter;
  }
 
  public XmlsonObject present(ImmutableMap<Interval, MonetarySummaryWithSplits> summaries, Locale locale) {
    final XmlsonObject root = new XmlsonObject("interval-summary");
    final XmlsonArray array = new XmlsonArray("summaries");
   
    for (Map.Entry<Interval, MonetarySummaryWithSplits> summary : summaries.entrySet()) {
      final XmlsonObject item = new XmlsonObject("summary");
     
      final XmlsonObject interval = new XmlsonObject("interval");
      interval.addProperty("start", ISO_BASIC.print(summary.getKey().getStart()));
      interval.addProperty("end", ISO_BASIC.print(summary.getKey().getEnd()));
      item.add(interval);
      item.add(sumOfMoneyPresenter.present("spending", summary.getValue().getSpending(), locale));
      item.add(sumOfMoneyPresenter.present("earnings", summary.getValue().getEarnings(), locale));
      item.add(sumOfMoneyPresenter.present("net", summary.getValue().getNet(), locale));
     
      final XmlsonArray splits = new XmlsonArray("splits");
      for (Entry<Tag, MonetarySummary> entry : summary.getValue().getSplitSummaries().entrySet()) {
        final XmlsonObject splitsSummary = new XmlsonObject("split");
       
        final XmlsonObject tagName = new XmlsonObject("tag");
        tagName.addProperty("name", entry.getKey().toString());
        splitsSummary.add(tagName);
       
        splitsSummary.add(sumOfMoneyPresenter.present("spending", entry.getValue().getSpending(), locale));
        splitsSummary.add(sumOfMoneyPresenter.present("earnings", entry.getValue().getEarnings(), locale));
        splitsSummary.add(sumOfMoneyPresenter.present("net", entry.getValue().getNet(), locale));
View Full Code Here

  public XmlsonObject present(Txaction txaction, Locale locale) {
    return presentWithTransfer(txaction, locale);
  }

  private XmlsonObject presentWithTransfer(Txaction txaction, Locale locale) {
    final XmlsonObject root = presentWithoutTransfer("transaction", txaction, locale);
   
    if (txaction.isPairedTransfer()) {
      root.add(presentWithoutTransfer("transfer", txaction.getTransferTxaction(), locale));
    } else if (txaction.isTransfer()) {
      root.addProperty("transfer", true);
    } else {
      root.addNullProperty("transfer");
    }
   
    return root;
  }
View Full Code Here

   
    return root;
  }

  private XmlsonObject presentWithoutTransfer(String name, Txaction txaction, Locale locale) {
    final XmlsonObject root = new XmlsonObject(name);
    root.addProperty("id", txaction.getId());
    root.addProperty("uri", String.format("/transactions/%d", txaction.getId()));
    root.add(accountPresenter.present(txaction.getAccount()));
    root.addProperty("date", ISO_BASIC.print(txaction.getDatePosted()));
    root.addProperty("original-date", ISO_BASIC.print(txaction.getOriginalDatePosted()));
    root.add(moneyPresenter.present("amount", txaction.getAmount(), locale));

    if (txaction.getMerchant() != null) {
      root.add(merchantPresenter.present(txaction.getMerchant()));
    } else {
      root.addNullProperty("merchant");
    }
   
    if (txaction.getCheckNumber() != null) {
      root.addProperty("check-number", txaction.getCheckNumber());
    } else {
      root.addNullProperty("check-number");
    }
   
    if (!txaction.getAttachments().isEmpty()) {
      final XmlsonArray attachments = new XmlsonArray("attachments");
      for (Attachment attachment : txaction.getAttachments()) {
        attachments.add(attachmentPresenter.present(attachment));
      }
      root.add(attachments);
    }
   
    root.addProperty("unedited-name", txaction.getUneditedName());
    root.addProperty("note", txaction.getNote());
   
    final XmlsonArray taggedAmounts = new XmlsonArray("tags");
    for (TaggedAmount taggedAmount : txaction.getTaggedAmounts()) {
      taggedAmounts.add(taggedAmountPresenter.present(taggedAmount, locale));
    }
    root.add(taggedAmounts);
    return root;
  }
View Full Code Here

* @author coda
*
*/
public class AccountBriefPresenter {
  public XmlsonObject present(Account account) {
    final XmlsonObject root = new XmlsonObject("account");
    root.addProperty("id", account.getRelativeId());
    root.addProperty("uri", String.format("/accounts/%d", account.getRelativeId()));
    root.addProperty("type", account.getAccountType().toString());
    return root;
  }
View Full Code Here

TOP

Related Classes of com.wesabe.xmlson.XmlsonObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.