Exemplo n.º 1
0
  Object processInformation(Information info) {
    // -------------------------------------------

    Account acc = (Account) accounts.get(info.getAccountId());
    if (acc == null) return newProblem(ACCOUNT_NOT_FOUND);

    java.util.Date date = new java.util.Date();
    Operation op = new Operation(); // <-- Apply admin charge
    op.setType(ADMIN);
    op.setAmount(info.getType() == BALANCE ? BAL_CHARGE : OPER_CHARGE);
    acc.setBalance(acc.getBalance() - op.getAmount());
    op.setBalance(acc.getBalance());
    op.setAccountId(acc.getId());
    op.setDate(date);
    List l = (List) operations.get(acc.getId());
    l.add(op);
    operations.put(acc.getId(), l);

    if (info.getType() == BALANCE) return acc;
    if (info.getType() == OPERATIONS) return l;
    return null;
  }
Exemplo n.º 2
0
  Object processOperation(MakeOperation mo) {
    // -------------------------------------------

    Account acc = (Account) accounts.get(mo.getAccountId());
    if (acc == null) return newProblem(ACCOUNT_NOT_FOUND);
    if (mo.getAmount() <= 0) return newProblem(ILLEGAL_OPERATION);

    if (mo.getType() != DEPOSIT && mo.getType() != WITHDRAWAL) return null;
    if (mo.getType() == DEPOSIT) acc.setBalance(acc.getBalance() + mo.getAmount());
    else if (mo.getType() == WITHDRAWAL) {
      if (mo.getAmount() > acc.getBalance()) return newProblem(NOT_ENOUGH_MONEY);
      acc.setBalance(acc.getBalance() - mo.getAmount());
    }
    Operation op = new Operation();
    op.setType(mo.getType());
    op.setAmount(mo.getAmount());
    op.setAccountId(acc.getId());
    op.setDate(new java.util.Date());
    List l = (List) operations.get(acc.getId());
    l.add(op);
    operations.put(acc.getId(), l);
    return acc;
  }