public static SecurityPerformanceSnapshot create( Client client, CurrencyConverter converter, ReportingPeriod period) { Map<Security, SecurityPerformanceRecord> transactions = initRecords(client); for (Account account : client.getAccounts()) extractSecurityRelatedAccountTransactions(account, period, transactions); for (Portfolio portfolio : client.getPortfolios()) { extractSecurityRelatedPortfolioTransactions(portfolio, period, transactions); addPseudoValuationTansactions(portfolio, converter, period, transactions); } return doCreateSnapshot(client, converter, transactions, period); }
@Override public boolean performFinish() { Object exportItem = exportPage.getExportItem(); Class<?> exportClass = exportPage.getExportClass(); File file = getFile(exportItem); try { // account transactions if (exportItem == AccountTransaction.class) { new CSVExporter().exportAccountTransactions(file, client.getAccounts()); } else if (exportClass == AccountTransaction.class) { new CSVExporter().exportAccountTransactions(file, (Account) exportItem); } // portfolio transactions else if (exportItem == PortfolioTransaction.class) { new CSVExporter().exportPortfolioTransactions(file, client.getPortfolios()); } else if (exportClass == PortfolioTransaction.class) { new CSVExporter().exportPortfolioTransactions(file, (Portfolio) exportItem); } // master data else if (exportItem == Security.class) { new CSVExporter() .exportSecurityMasterData( new File(file, Messages.ExportWizardSecurityMasterData + ".csv"), client.getSecurities()); // $NON-NLS-1$ } else if (exportClass == Security.class) { if (Messages.ExportWizardSecurityMasterData.equals(exportItem)) new CSVExporter().exportSecurityMasterData(file, client.getSecurities()); else if (Messages.ExportWizardMergedSecurityPrices.equals(exportItem)) new CSVExporter().exportMergedSecurityPrices(file, client.getSecurities()); } // historical quotes else if (exportItem == SecurityPrice.class) { new CSVExporter().exportSecurityPrices(file, client.getSecurities()); } else if (exportClass == SecurityPrice.class) { new CSVExporter().exportSecurityPrices(file, (Security) exportItem); } else { throw new UnsupportedOperationException( MessageFormat.format(Messages.ExportWizardUnsupportedExport, exportClass, exportItem)); } } catch (IOException e) { PortfolioPlugin.log(e); MessageDialog.openError(getShell(), Messages.ExportWizardErrorExporting, e.getMessage()); } return true; }
public static ClientSnapshot create(Client client, Date time) { ClientSnapshot snapshot = new ClientSnapshot(client, time); for (Account account : client.getAccounts()) snapshot.accounts.add(AccountSnapshot.create(account, time)); for (Portfolio portfolio : client.getPortfolios()) snapshot.portfolios.add(PortfolioSnapshot.create(portfolio, time)); if (snapshot.portfolios.isEmpty()) snapshot.jointPortfolio = PortfolioSnapshot.create(new Portfolio(), time); else if (snapshot.portfolios.size() == 1) snapshot.jointPortfolio = snapshot.portfolios.get(0); else snapshot.jointPortfolio = PortfolioSnapshot.merge(snapshot.portfolios); return snapshot; }
private static void collectPortfolioTransactions( Client client, Date start, Date end, List<Transaction> transactions) { for (Portfolio portfolio : client.getPortfolios()) { for (PortfolioTransaction t : portfolio.getTransactions()) { if (t.getDate().getTime() > start.getTime() && t.getDate().getTime() <= end.getTime()) { switch (t.getType()) { case TRANSFER_IN: case TRANSFER_OUT: case DELIVERY_INBOUND: case DELIVERY_OUTBOUND: transactions.add(t); break; case BUY: case SELL: break; default: throw new UnsupportedOperationException(); } } } } }