Exemplo n.º 1
0
  @Test
  public void testExportBudgetResultsModel() throws Exception {

    File file = File.createTempFile("budget", ".xml");
    file.deleteOnExit();

    Engine e =
        EngineFactory.bootLocalEngine(
            file.getName(), EngineFactory.DEFAULT, PASSWORD, DataStoreType.XML);
    CurrencyNode node = e.getDefaultCurrency();

    Account account1 = new Account(AccountType.EXPENSE, node);
    account1.setName("Expense 1");
    e.addAccount(e.getRootAccount(), account1);

    Account account2 = new Account(AccountType.EXPENSE, node);
    account2.setName("Expense 2");
    e.addAccount(e.getRootAccount(), account2);

    Budget budget = new Budget();
    budget.setName("My Budget");
    budget.setDescription("Test");
    budget.setBudgetPeriod(BudgetPeriod.MONTHLY);

    e.addBudget(budget);

    BudgetResultsModel model = new BudgetResultsModel(budget, 2012, node);

    BudgetResultsExport.exportBudgetResultsModel(
        new File(System.getProperty("java.io.tmpdir") + File.separator + "testworkbook.xls"),
        model);

    // file.delete();

    assertTrue(true);
  }
Exemplo n.º 2
0
  @SuppressWarnings({"unchecked", "ConstantConditions"})
  private void parseAccount(final XMLStreamReader reader) {

    assert reader.getAttributeCount() == 2;

    Map<String, Object> elementMap = new HashMap<>();

    /* still at start of the account.  Need to know when end is reached */
    QName parsingElement = reader.getName();

    String accountClass = reader.getAttributeValue(0);
    String accountId = reader.getAttributeValue(1);

    try {
      while (reader.hasNext()) {
        int event = reader.next();

        switch (event) {
          case XMLStreamConstants.START_ELEMENT:
            String element = reader.getLocalName();

            switch (element) {
              case "securities":
                logger.info("Parsing account securities");
                elementMap.put("securities", parseAccountSecurities(reader));
                break;
              case "amortize":
                logger.info("Parsing amortize object");
                elementMap.put("amortize", parseAmortizeObject(reader));
                break;
              case "locked":
                lockMap.put(accountId, Boolean.valueOf(reader.getElementText()));
                break;
              default:
                elementMap.put(element, reader.getElementText());
                break;
            }
            break;
          case XMLStreamConstants.END_ELEMENT:
            if (reader.getName().equals(parsingElement)) {
              logger.finest("Found the end of an Account");

              Account account = generateAccount(accountClass, elementMap);

              if (account != null) {
                accountMap.put(accountId, account);

                // do not put the root account into the parent map
                if (account.getAccountType() != AccountType.ROOT) {
                  parentMap.put(account, (String) elementMap.get("parentAccount"));
                }

                if (account.getAccountType() != AccountType.ROOT) {
                  Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);

                  engine.addAccount(engine.getRootAccount(), account);

                  if (account.getAccountType() == AccountType.LIABILITY) {
                    Map<String, String> amortizeObject =
                        (Map<String, String>) elementMap.get("amortize");

                    if (amortizeObject != null) {
                      AOThread t = new AOThread(account, amortizeObject);
                      workQueue.add(t);
                    }
                  }
                }
              }
              return;
            }
            break;
          default:
            break;
        }
      }
    } catch (XMLStreamException e) {
      logger.log(Level.SEVERE, "Error importing account id: {0}", accountId);
      logger.log(Level.SEVERE, e.toString(), e);
    }
  }