@Override
  public PortfolioDocument update(PortfolioDocument document) {
    ArgumentChecker.notNull(document, "document");
    ArgumentChecker.notNull(document.getUniqueId(), "document.uniqueId");
    ArgumentChecker.notNull(document.getPortfolio(), "document.portfolio");

    final UniqueId uniqueId = document.getUniqueId();
    final Instant now = Instant.now();
    final PortfolioDocument storedDocument = _store.get(uniqueId.getObjectId());
    if (storedDocument == null) {
      throw new DataNotFoundException("Portfolio not found: " + uniqueId);
    }

    final PortfolioDocument clonedDoc = clonePortfolioDocument(document);
    removeNodes(storedDocument.getPortfolio().getRootNode());

    setVersionTimes(document, clonedDoc, now, null, now, null);

    if (_store.replace(uniqueId.getObjectId(), storedDocument, clonedDoc) == false) {
      throw new IllegalArgumentException("Concurrent modification");
    }
    storeNodes(
        clonedDoc.getPortfolio().getRootNode(),
        document.getPortfolio().getRootNode(),
        uniqueId,
        null);
    _changeManager.entityChanged(
        ChangeType.CHANGED,
        document.getObjectId(),
        document.getVersionFromInstant(),
        document.getVersionToInstant(),
        now);
    updateCaches(storedDocument, clonedDoc);
    return document;
  }
  // -------------------------------------------------------------------------
  @Override
  public PortfolioDocument correct(final PortfolioDocument document) {
    ArgumentChecker.notNull(document, "document");
    ArgumentChecker.notNull(document.getPortfolio(), "document.portfolio");
    ArgumentChecker.notNull(document.getUniqueId(), "document.uniqueId");

    URI uri = DataPortfolioResource.uriVersion(getBaseUri(), document.getUniqueId());
    return accessRemote(uri).put(PortfolioDocument.class, document);
  }
 @DELETE
 @Produces(MediaType.APPLICATION_JSON)
 public Response deleteJSON() {
   PortfolioDocument doc = data().getPortfolio();
   if (doc.isLatest()) {
     data().getPortfolioMaster().remove(doc.getUniqueId());
   }
   return Response.ok().build();
 }
 // -------------------------------------------------------------------------
 @DELETE
 @Produces(MediaType.TEXT_HTML)
 public Response deleteHTML() {
   PortfolioDocument doc = data().getPortfolio();
   if (doc.isLatest() == false) {
     return Response.status(Status.FORBIDDEN).entity(getHTML()).build();
   }
   data().getPortfolioMaster().remove(doc.getUniqueId());
   URI uri = WebPortfolioResource.uri(data());
   return Response.seeOther(uri).build();
 }