}
return securities;
}
private void persistToPortfolio(final Collection<Collection<FinancialSecurity>> subPortfolios, final Collection<String> names, final String portfolioName) {
final PortfolioMaster portfolioMaster = getToolContext().getPortfolioMaster();
final PositionMaster positionMaster = getToolContext().getPositionMaster();
final SecurityMaster securityMaster = getToolContext().getSecurityMaster();
final ManageablePortfolioNode rootNode = new ManageablePortfolioNode(portfolioName);
final ManageablePortfolio portfolio = new ManageablePortfolio(portfolioName, rootNode);
final PortfolioDocument portfolioDoc = new PortfolioDocument();
portfolioDoc.setPortfolio(portfolio);
final Iterator<Collection<FinancialSecurity>> iter1 = subPortfolios.iterator();
final Iterator<String> iter2 = names.iterator();
final Random random = new Random(2349);
while (iter1.hasNext()) {
final Collection<FinancialSecurity> securities = iter1.next();
final String name = iter2.next();
final ManageablePortfolioNode subNode = new ManageablePortfolioNode(name);
final ManageablePortfolio subPortfolio = new ManageablePortfolio(name, subNode);
final PortfolioDocument subPortfolioDoc = new PortfolioDocument();
subPortfolioDoc.setPortfolio(subPortfolio);
for (final FinancialSecurity security : securities) {
final SecurityDocument securityToAddDoc = new SecurityDocument();
securityToAddDoc.setSecurity(security);
securityMaster.add(securityToAddDoc);
BigDecimal trades;
if (security instanceof FutureSecurity) {
trades = new BigDecimal(1 + (random.nextInt(150) - 75));
} else {
trades = BigDecimal.ONE;
}
final ManageablePosition securityPosition = new ManageablePosition(trades, security.getExternalIdBundle());
final PositionDocument addedDoc = positionMaster.add(new PositionDocument(securityPosition));
subNode.addPosition(addedDoc.getUniqueId());
}
portfolioMaster.add(subPortfolioDoc);
rootNode.addChildNode(subNode);
}
portfolioMaster.add(portfolioDoc);
}