}
@Override
public void run() {
PortfolioDocument portfolioDocument = getPortfolioMaster().get(_portfolioId, VersionCorrection.LATEST);
s_logger.debug("Updating portfolio {} with {}", portfolioDocument.getUniqueId(), _trade);
ManageablePortfolio portfolio = portfolioDocument.getPortfolio();
ManageablePortfolioNode root = portfolio.getRootNode();
ManageablePosition position = new ManageablePosition();
position.getSecurityLink().setExternalId(_trade.getSecurityLink().getExternalId());
position.setQuantity(_trade.getQuantity());
String providerIdStr = _trade.getAttributes().get(getProviderIdName());
ManageableTrade manageableTrade = new ManageableTrade(_trade);
if (providerIdStr != null) {
ExternalId providerId = ExternalId.parse(providerIdStr);
position.setProviderId(providerId);
manageableTrade.setProviderId(providerId);
}
position.addTrade(manageableTrade);
PositionDocument addedPosition = getPositionMaster().add(new PositionDocument(position));
root.addPosition(addedPosition.getUniqueId());
PortfolioDocument currentPortfolio = getPortfolioMaster().update(new PortfolioDocument(portfolio));
s_logger.info("Portfolio ID {} updated", currentPortfolio.getUniqueId());
restartViewCalculation();
}