public void testUpdateExisting() throws Exception {
    long pk = nextLong();

    BookmarksFolder newBookmarksFolder = _persistence.create(pk);

    newBookmarksFolder.setUuid(randomString());

    newBookmarksFolder.setGroupId(nextLong());

    newBookmarksFolder.setCompanyId(nextLong());

    newBookmarksFolder.setUserId(nextLong());

    newBookmarksFolder.setUserName(randomString());

    newBookmarksFolder.setCreateDate(nextDate());

    newBookmarksFolder.setModifiedDate(nextDate());

    newBookmarksFolder.setParentFolderId(nextLong());

    newBookmarksFolder.setName(randomString());

    newBookmarksFolder.setDescription(randomString());

    _persistence.update(newBookmarksFolder, false);

    BookmarksFolder existingBookmarksFolder =
        _persistence.findByPrimaryKey(newBookmarksFolder.getPrimaryKey());

    assertEquals(existingBookmarksFolder.getUuid(), newBookmarksFolder.getUuid());
    assertEquals(existingBookmarksFolder.getFolderId(), newBookmarksFolder.getFolderId());
    assertEquals(existingBookmarksFolder.getGroupId(), newBookmarksFolder.getGroupId());
    assertEquals(existingBookmarksFolder.getCompanyId(), newBookmarksFolder.getCompanyId());
    assertEquals(existingBookmarksFolder.getUserId(), newBookmarksFolder.getUserId());
    assertEquals(existingBookmarksFolder.getUserName(), newBookmarksFolder.getUserName());
    assertEquals(
        Time.getShortTimestamp(existingBookmarksFolder.getCreateDate()),
        Time.getShortTimestamp(newBookmarksFolder.getCreateDate()));
    assertEquals(
        Time.getShortTimestamp(existingBookmarksFolder.getModifiedDate()),
        Time.getShortTimestamp(newBookmarksFolder.getModifiedDate()));
    assertEquals(
        existingBookmarksFolder.getParentFolderId(), newBookmarksFolder.getParentFolderId());
    assertEquals(existingBookmarksFolder.getName(), newBookmarksFolder.getName());
    assertEquals(existingBookmarksFolder.getDescription(), newBookmarksFolder.getDescription());
  }
  public static boolean contains(
      PermissionChecker permissionChecker, BookmarksFolder folder, String actionId)
      throws PortalException {

    if (actionId.equals(ActionKeys.ADD_FOLDER)) {
      actionId = ActionKeys.ADD_SUBFOLDER;
    }

    Boolean hasPermission =
        StagingPermissionUtil.hasPermission(
            permissionChecker,
            folder.getGroupId(),
            BookmarksFolder.class.getName(),
            folder.getFolderId(),
            PortletKeys.BOOKMARKS,
            actionId);

    if (hasPermission != null) {
      return hasPermission.booleanValue();
    }

    if (actionId.equals(ActionKeys.VIEW) && PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE) {

      try {
        long folderId = folder.getFolderId();

        while (folderId != BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

          folder = BookmarksFolderLocalServiceUtil.getFolder(folderId);

          if (!_hasPermission(permissionChecker, folder, actionId)) {
            return false;
          }

          folderId = folder.getParentFolderId();
        }
      } catch (NoSuchFolderException nsfe) {
        if (!folder.isInTrash()) {
          throw nsfe;
        }
      }

      return BookmarksPermission.contains(permissionChecker, folder.getGroupId(), actionId);
    }

    return _hasPermission(permissionChecker, folder, actionId);
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, BookmarksFolder folder)
      throws Exception {

    if (folder.getParentFolderId() != BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

      exportStagedModel(portletDataContext, folder.getParentFolder());
    }

    Element folderElement = portletDataContext.getExportDataElement(folder);

    portletDataContext.addClassedModel(
        folderElement,
        ExportImportPathUtil.getModelPath(folder),
        folder,
        BookmarksPortletDataHandler.NAMESPACE);
  }
  @Override
  protected void doImportStagedModel(
      PortletDataContext portletDataContext, Element element, String path, BookmarksFolder folder)
      throws Exception {

    long userId = portletDataContext.getUserId(folder.getUserUuid());

    Map<Long, Long> folderIds =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(BookmarksFolder.class);

    long parentFolderId =
        MapUtil.getLong(folderIds, folder.getParentFolderId(), folder.getParentFolderId());

    if ((parentFolderId != BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID)
        && (parentFolderId == folder.getParentFolderId())) {

      String parentFolderPath =
          StagedModelPathUtil.getPath(
              portletDataContext, BookmarksFolder.class.getName(), parentFolderId);

      BookmarksFolder parentFolder =
          (BookmarksFolder) portletDataContext.getZipEntryAsObject(parentFolderPath);

      importStagedModel(portletDataContext, element, parentFolderPath, parentFolder);

      parentFolderId =
          MapUtil.getLong(folderIds, folder.getParentFolderId(), folder.getParentFolderId());
    }

    ServiceContext serviceContext =
        portletDataContext.createServiceContext(
            path, folder, BookmarksPortletDataHandler.NAMESPACE);

    BookmarksFolder importedFolder = null;

    if (portletDataContext.isDataStrategyMirror()) {
      BookmarksFolder existingFolder =
          BookmarksFolderUtil.fetchByUUID_G(folder.getUuid(), portletDataContext.getScopeGroupId());

      if (existingFolder == null) {
        serviceContext.setUuid(folder.getUuid());

        importedFolder =
            BookmarksFolderLocalServiceUtil.addFolder(
                userId, parentFolderId, folder.getName(), folder.getDescription(), serviceContext);
      } else {
        importedFolder =
            BookmarksFolderLocalServiceUtil.updateFolder(
                userId,
                existingFolder.getFolderId(),
                parentFolderId,
                folder.getName(),
                folder.getDescription(),
                false,
                serviceContext);
      }
    } else {
      importedFolder =
          BookmarksFolderLocalServiceUtil.addFolder(
              userId, parentFolderId, folder.getName(), folder.getDescription(), serviceContext);
    }

    portletDataContext.importClassedModel(
        folder, importedFolder, BookmarksPortletDataHandler.NAMESPACE);
  }