Exemple #1
0
  @Override
  public int getTrashContainerModelsCount(long classPK) throws PortalException, SystemException {

    BookmarksFolder folder = BookmarksFolderLocalServiceUtil.getFolder(classPK);

    return BookmarksFolderLocalServiceUtil.getFoldersCount(folder.getGroupId(), classPK);
  }
  @Override
  public boolean hasPermission(PermissionChecker permissionChecker, long classPK, String actionId)
      throws Exception {

    BookmarksFolder folder = BookmarksFolderLocalServiceUtil.getFolder(classPK);

    return BookmarksFolderPermission.contains(permissionChecker, folder, actionId);
  }
  public static void addPortletBreadcrumbEntries(
      long folderId, HttpServletRequest request, RenderResponse renderResponse) throws Exception {

    if (folderId == BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
      return;
    }

    BookmarksFolder folder = BookmarksFolderLocalServiceUtil.getFolder(folderId);

    addPortletBreadcrumbEntries(folder, request, renderResponse);
  }
  @Override
  public AssetRenderer getAssetRenderer(long classPK, int type) throws PortalException {

    BookmarksFolder folder = BookmarksFolderLocalServiceUtil.getFolder(classPK);

    BookmarksFolderAssetRenderer bookmarksFolderAssetRenderer =
        new BookmarksFolderAssetRenderer(folder);

    bookmarksFolderAssetRenderer.setAssetRendererType(type);

    return bookmarksFolderAssetRenderer;
  }
  public static boolean contains(
      PermissionChecker permissionChecker, long groupId, long folderId, String actionId)
      throws PortalException {

    if (folderId == BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
      return BookmarksPermission.contains(permissionChecker, groupId, actionId);
    } else {
      BookmarksFolder folder = BookmarksFolderLocalServiceUtil.getBookmarksFolder(folderId);

      return contains(permissionChecker, folder, actionId);
    }
  }
Exemple #6
0
  @Override
  public List<TrashRenderer> getTrashContainerModelTrashRenderers(long classPK, int start, int end)
      throws PortalException, SystemException {

    List<TrashRenderer> trashRenderers = new ArrayList<TrashRenderer>();

    BookmarksFolder folder = BookmarksFolderLocalServiceUtil.getFolder(classPK);

    List<BookmarksFolder> folders =
        BookmarksFolderLocalServiceUtil.getFolders(folder.getGroupId(), classPK, start, end);

    for (BookmarksFolder curFolder : folders) {
      TrashHandler trashHandler =
          TrashHandlerRegistryUtil.getTrashHandler(BookmarksFolder.class.getName());

      TrashRenderer trashRenderer = trashHandler.getTrashRenderer(curFolder.getPrimaryKey());

      trashRenderers.add(trashRenderer);
    }

    return trashRenderers;
  }
  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);
  }
Exemple #8
0
  @Override
  public List<ContainerModel> getContainerModels(
      long classPK, long parentContainerModelId, int start, int end)
      throws PortalException, SystemException {

    BookmarksFolder folder = getBookmarksFolder(classPK);

    List<BookmarksFolder> folders =
        BookmarksFolderLocalServiceUtil.getFolders(
            folder.getGroupId(), parentContainerModelId, start, end);

    List<ContainerModel> containerModels = new ArrayList<ContainerModel>(folders.size());

    for (BookmarksFolder curFolder : folders) {
      containerModels.add(curFolder);
    }

    return containerModels;
  }
  protected void reindexFolders(long companyId) throws Exception {
    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            BookmarksFolder.class, PortalClassLoaderUtil.getClassLoader());

    Projection minFolderIdProjection = ProjectionFactoryUtil.min("folderId");
    Projection maxFolderIdProjection = ProjectionFactoryUtil.max("folderId");

    ProjectionList projectionList = ProjectionFactoryUtil.projectionList();

    projectionList.add(minFolderIdProjection);
    projectionList.add(maxFolderIdProjection);

    dynamicQuery.setProjection(projectionList);

    addReindexCriteria(dynamicQuery, companyId);

    List<Object[]> results = BookmarksFolderLocalServiceUtil.dynamicQuery(dynamicQuery);

    Object[] minAndMaxFolderIds = results.get(0);

    if ((minAndMaxFolderIds[0] == null) || (minAndMaxFolderIds[1] == null)) {

      return;
    }

    long minFolderId = (Long) minAndMaxFolderIds[0];
    long maxFolderId = (Long) minAndMaxFolderIds[1];

    long startFolderId = minFolderId;
    long endFolderId = startFolderId + DEFAULT_INTERVAL;

    while (startFolderId <= maxFolderId) {
      reindexFolders(companyId, startFolderId, endFolderId);

      startFolderId = endFolderId;
      endFolderId += DEFAULT_INTERVAL;
    }
  }
  public static String getTitleText(Locale locale, String className, long classPK, String title)
      throws PortalException, SystemException {

    if (Validator.isNotNull(title)) {
      return title;
    }

    if (className.equals(BlogsEntry.class.getName())) {
      title = "Blog at ";
    } else if (className.equals(BookmarksFolder.class.getName())) {
      BookmarksFolder bookmarksFolder = BookmarksFolderLocalServiceUtil.getBookmarksFolder(classPK);

      return bookmarksFolder.getName();
    } else if (className.equals(Layout.class.getName())) {
      Layout layout = LayoutLocalServiceUtil.getLayout(classPK);

      return layout.getName(locale);
    } else if (className.equals(MBCategory.class.getName())) {
      title = "Message Board at ";
    } else if (className.equals(WikiNode.class.getName())) {
      WikiNode wikiNode = WikiNodeLocalServiceUtil.getWikiNode(classPK);

      return wikiNode.getName();
    }

    try {
      Group group = GroupLocalServiceUtil.getGroup(classPK);

      title += group.getDescriptiveName(locale);
    } catch (Exception e) {
    }

    if (Validator.isNull(title)) {
      title = String.valueOf(classPK);
    }

    return title;
  }
  protected void reindexFolders(long companyId, long startFolderId, long endFolderId)
      throws Exception {

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            BookmarksFolder.class, PortalClassLoaderUtil.getClassLoader());

    Property property = PropertyFactoryUtil.forName("folderId");

    dynamicQuery.add(property.ge(startFolderId));
    dynamicQuery.add(property.lt(endFolderId));

    addReindexCriteria(dynamicQuery, companyId);

    List<BookmarksFolder> folders = BookmarksFolderLocalServiceUtil.dynamicQuery(dynamicQuery);

    for (BookmarksFolder folder : folders) {
      long groupId = folder.getGroupId();
      long folderId = folder.getFolderId();

      reindexEntries(companyId, groupId, folderId);
    }
  }
  @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);
  }
Exemple #13
0
  @Override
  public ContainerModel getContainerModel(long containerModelId)
      throws PortalException, SystemException {

    return BookmarksFolderLocalServiceUtil.getFolder(containerModelId);
  }