Package com.opengamma.master.portfolio

Examples of com.opengamma.master.portfolio.ManageablePortfolioNode


    securityMaster.add(toAddDoc);
  }

  private void addPortfolioNode(final ManageablePortfolioNode rootNode, final Collection<FinancialSecurity> finSecurities, final String portfolioNodeName, BigDecimal quantity) {
    PositionMaster positionMaster = getToolContext().getPositionMaster();
    final ManageablePortfolioNode portfolioNode = new ManageablePortfolioNode(portfolioNodeName);
    for (final FinancialSecurity security : finSecurities) {
      storeFinancialSecurity(security);
      ManageablePosition position = new ManageablePosition(quantity, security.getExternalIdBundle());
      PositionDocument addedDoc = positionMaster.add(new PositionDocument(position));
      portfolioNode.addPosition(addedDoc.getUniqueId());
    }
    rootNode.addChildNode(portfolioNode);
  }
View Full Code Here


    final ManageablePosition position = makePositionAndTrade(security);
    final PositionDocument positionDoc = new PositionDocument(position);
    posMaster.add(positionDoc);
   
    ManageablePortfolio portfolio = new ManageablePortfolio(portfolioName);
    ManageablePortfolioNode rootNode = portfolio.getRootNode();
    rootNode.setName("Root");
    rootNode.addPosition(position.getUniqueId());
   
    PortfolioDocument portfolioDoc = new PortfolioDocument(portfolio);
    portMaster.add(portfolioDoc);

  }
View Full Code Here

    URI uri = addPosition(doc, positionId);
    return Response.created(uri).build();
  }

  private URI addPosition(PortfolioDocument doc, UniqueId positionId) {
    ManageablePortfolioNode node = data().getNode();
    URI uri = WebPortfolioNodeResource.uri(data())// lock URI before updating data()
    if (node.getPositionIds().contains(positionId) == false) {
      node.addPosition(positionId);
      doc = data().getPortfolioMaster().update(doc);
      data().setPortfolio(doc);
    }
    return uri;
  }
View Full Code Here

   * @return the output root data, not null
   */
  protected FlexiBean createRootData() {
    FlexiBean out = super.createRootData();
    PortfolioDocument doc = data().getPortfolio();
    ManageablePortfolioNode node = data().getNode();
    out.put("portfolioDoc", doc);
    out.put("portfolio", doc.getPortfolio());
    out.put("parentNode", data().getParentNode());
    out.put("node", node);
    out.put("childNodes", node.getChildNodes());
    out.put("deleted", !doc.isLatest());
    return out;
  }
View Full Code Here

    Security security = trade.getSecurityLink().resolve(_securitySource);
    // this slightly awkward approach is due to the portfolio master API. you can look up a node directly but in order
    // to save it you have to save the whole portfolio. this means you need to look up the node to find the portfolio
    // ID, look up the portfolio, find the node in the portfolio, modify that copy of the node and save the portfolio
    // TODO can use a portfolio search request and only hit the master once
    ManageablePortfolioNode node = _portfolioMaster.getNode(nodeId);
    ManageablePortfolio portfolio = _portfolioMaster.get(node.getPortfolioId()).getPortfolio();
    ManageablePortfolioNode portfolioNode = findNode(portfolio, nodeId);
    ManageablePosition position = findPosition(portfolioNode, security);
    if (position == null) {
      // no position in this security on the node, create a new position just for this trade
      ManageablePosition newPosition = new ManageablePosition(trade.getQuantity(), security.getExternalIdBundle());
      newPosition.addTrade(trade);
      ManageablePosition savedPosition = getPositionMaster().add(new PositionDocument(newPosition)).getPosition();
      portfolioNode.addPosition(savedPosition.getUniqueId());
      _portfolioMaster.update(new PortfolioDocument(portfolio));
      return savedPosition.getTrades().get(0).getUniqueId();
    } else {
      position.addTrade(trade);
      position.setQuantity(position.getQuantity().add(trade.getQuantity()));
View Full Code Here

  @Produces(MediaType.TEXT_HTML)
  public Response deleteHTML() {
    ObjectId positionId = ObjectId.parse(data().getUriPositionId());
    PortfolioDocument doc = data().getPortfolio();
    if (doc.isLatest()) {
      ManageablePortfolioNode node = data().getNode();
      if (node.getPositionIds().remove(positionId) == false) {
        throw new DataNotFoundException("Position id not found: " + positionId);
      }
      doc = data().getPortfolioMaster().update(doc);
    }
    return Response.seeOther(WebPortfolioNodeResource.uri(data())).build();
View Full Code Here

  @Produces(MediaType.APPLICATION_JSON)
  public Response deleteJSON() {
    ObjectId positionId = ObjectId.parse(data().getUriPositionId());
    PortfolioDocument doc = data().getPortfolio();
    if (doc.isLatest()) {
      ManageablePortfolioNode node = data().getNode();
      if (node.getPositionIds().remove(positionId) == false) {
        throw new DataNotFoundException("Position id not found: " + positionId);
      }
      doc = data().getPortfolioMaster().update(doc);
    }
    return Response.ok().build();
View Full Code Here

   * @param nodeId The node ID
   * @return The node with specified ID, not null
   * @throws DataNotFoundException If the node can't be found
   */
  /* package */ static ManageablePortfolioNode findNode(ManageablePortfolio portfolio, UniqueId nodeId) {
    ManageablePortfolioNode node = findNode(portfolio.getRootNode(), nodeId);
    if (node != null) {
      return node;
    } else {
      throw new DataNotFoundException("Node " + nodeId + " not found");
    }
View Full Code Here

  private static ManageablePortfolioNode findNode(ManageablePortfolioNode node, UniqueId nodeId) {
    if (node.getUniqueId().equalObjectId(nodeId)) {
      return node;
    }
    for (ManageablePortfolioNode childNode : node.getChildNodes()) {
      ManageablePortfolioNode node1 = findNode(childNode, nodeId);
      if (node1 != null) {
        return node1;
      }
    }
    return null;
View Full Code Here

    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();
  }
View Full Code Here

TOP

Related Classes of com.opengamma.master.portfolio.ManageablePortfolioNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.