OtcTradeBuilder extends AbstractTradeBuilder { @SuppressWarnings("deprecation") UniqueId addTrade(BeanDataSource tradeData, BeanDataSource securityData, BeanDataSource underlyingData, UniqueId nodeId) { ManageableSecurity underlying = buildUnderlying(underlyingData); ManageableSecurity security; if (underlying == null) { security = BlotterUtils.buildSecurity(securityData); } else { ManageableSecurity savedUnderlying = getSecurityMaster().add(new SecurityDocument(underlying)).getSecurity(); security = buildSecurity(securityData, savedUnderlying); } ManageableSecurity savedSecurity = getSecurityMaster().add(new SecurityDocument(security)).getSecurity(); ManageableTrade trade = buildTrade(tradeData); trade.setSecurityLink(new ManageableSecurityLink(savedSecurity.getUniqueId())); ManageablePosition position = new ManageablePosition(); position.setQuantity(BigDecimal.ONE); position.setSecurityLink(new ManageableSecurityLink(trade.getSecurityLink())); position.setTrades(Lists.newArrayList(trade)); ManageablePosition savedPosition = getPositionMaster().add(new PositionDocument(position)).getPosition(); ManageableTrade savedTrade = savedPosition.getTrades().get(0); PortfolioSearchRequest searchRequest = new PortfolioSearchRequest(); searchRequest.addNodeObjectId(nodeId.getObjectId()); PortfolioSearchResult searchResult = getPortfolioMaster().search(searchRequest); ManageablePortfolio portfolio = searchResult.getSinglePortfolio(); ManageablePortfolioNode node = findNode(portfolio, nodeId); node.addPosition(savedPosition.getUniqueId()); getPortfolioMaster().update(new PortfolioDocument(portfolio)); return savedTrade.getUniqueId(); } OtcTradeBuilder(PositionMaster positionMaster,
                                PortfolioMaster portfoioMaster,
                                SecurityMaster securityMaster,
                                Set<MetaBean> metaBeans,
                                StringConvert stringConvert);   }
@Test public void newSecurityWithNoUnderlying() { UniqueId tradeId = _builder.addTrade(createTradeData(), BlotterTestUtils.FX_FORWARD_DATA_SOURCE, null, _nodeId); ManageableTrade trade = _positionMaster.getTrade(tradeId); UniqueId positionId = trade.getParentPositionId(); ManageablePosition position = _positionMaster.get(positionId).getPosition(); assertEquals(BigDecimal.ONE, trade.getQuantity()); assertEquals(BigDecimal.ONE, position.getQuantity()); ManageableSecurity security = _securityMaster.get(trade.getSecurityLink().getObjectId(), VersionCorrection.LATEST).getSecurity(); assertNotNull(security); security.setUniqueId(null); assertEquals(BlotterTestUtils.FX_FORWARD, security); assertEquals(COUNTERPARTY_ID, trade.getCounterpartyExternalId()); assertEquals(PREMIUM, trade.getPremium()); assertEquals(Currency.GBP, trade.getPremiumCurrency()); assertEquals(PREMIUM_DATE, trade.getPremiumDate()); assertEquals(TRADE_DATE, trade.getTradeDate()); assertEquals(PREMIUM_TIME, trade.getPremiumTime()); assertEquals(TRADE_TIME, trade.getTradeTime()); assertEquals(ATTRIBUTES, trade.getAttributes()); ManageablePortfolioNode loadedRoot = _portfolioMaster.get(_savedPortfolio.getUniqueId()).getPortfolio().getRootNode(); ManageablePortfolioNode loadedNode = loadedRoot.getChildNodes().get(0); assertEquals(1, loadedNode.getPositionIds().size()); assertEquals(positionId.getObjectId(), loadedNode.getPositionIds().get(0)); }